spaCy visualizers render named entities into HTML or SVG. Is there any easy way to get quick debug output in plaintext that looks good? I'm using spaCy 3.7.2 and python 3.11.
How to display spaCy named entities in plain text?
54 Views Asked by dfrankow At
2
There are 2 best solutions below
0
On
You can iterate on entities and display text and label:
import spacy
from spacy import displacy
text = "When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously."
nlp = spacy.load("en_core_web_sm")
doc = nlp(text)
for ent in doc.ents:
print(f"{ent.text} => {ent.label_}")
output :
Sebastian Thrun => PERSON
Google => ORG
2007 => DATE
For more informations see EntityRecognizer documentation
I ended up making a simple utility function:
Example output: