explosion / spacy-streamlit

👑 spaCy building blocks and visualizers for Streamlit apps
https://share.streamlit.io/ines/spacy-streamlit-demo/master/app.py
MIT License
794 stars 114 forks source link

Visualization of nested spans #42

Open phlobo opened 2 years ago

phlobo commented 2 years ago

Dear all,

I'm trying to use the new span visualizer to display some custom, nested spans predicted by spancat. This is my code:

MODEL_PATH = # ...
DEFAULT_TEXT = """Cetuximab ist ein monoklonaler Antikörper, der gegen den epidermalen Wachstumsfaktorrezeptor (EGFR) gerichtet ist und \
    dient zur Therapie des fortgeschrittenen kolorektalen Karzinoms zusammen mit Irinotecan oder in Kombination mit FOLFOX bzw. \
    allein nach Versagen einer Behandlung mit Oxaliplatin und Irinotecan."""

st.set_page_config(layout="wide")

text = st.text_area("Text to analyze", DEFAULT_TEXT)
doc = process_text(MODEL_PATH, text)

visualize_spans(doc, spans_key="snomed", displacy_options=
    {"colors": {
        "Clinical_Drug": "#99FF99", "External_Substance" : "#CCFFCC", "Nutrient_or_Body_Substance" : "#E5FFCC", 
        "Therapeutic" : "#66B2FF", "Diagnostic" : "#CCE5FF",
        "Other_Finding" : "#FFE5CC", "Diagnosis_or_Pathology" : "#FFCCCC"}} )

myapp

The nested spans are all shown on the same line, which makes it very hard to read. I learned from the feature on LinkedIn, where a video was shown with nested spans nicely displayed.

demo

How can I achieve this behavior? Do I need to pass some other options?