Skip to content

Visualization

Let's see how to display the output of a pipeline on a single text.

import edsnlp, edsnlp.pipes as eds

nlp = edsnlp.blank("eds")
nlp.add_pipe(eds.normalizer())
nlp.add_pipe(eds.sentences())
nlp.add_pipe(eds.covid())
nlp.add_pipe(eds.negation())
nlp.add_pipe(eds.hypothesis())
nlp.add_pipe(eds.family())

txt = "Le patient a le covid."

Visualize entities in a document

To print a text and highlight the entities in it, you can use spacy.displacy.

from spacy import displacy

doc = nlp(txt)
options = {
    # Optional colors

    # "colors": {
    #     "covid": "orange",
    #     "respiratoire": "steelblue",
    # },
}
displacy.render(doc, style="ent", options=options)

will render like this:

Le patient a le covid covid .

Visualize entities as a table

To quickly visualize the output of a pipeline on a document, including the annotated extensions/qualifiers, you can convert the output to a DataFrame and display it.

nlp.pipe([txt]).to_pandas(
    converter="ents",
    # Add any extension you want to display
    span_attributes=["negation", "hypothesis", "family"],
    # Shows the entities in doc.ents by default
    # span_getter=["ents"]
)
note_id start end label lexical_variant span_type negation hypothesis family
None 16 21 covid covid ents False False False