[735bb5]: / doc / figures / introduction / ner_example.py

Download this file

17 lines (12 with data), 370 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# %%
import spacy
from spacy import displacy
from pathlib import Path
nlp = spacy.load("en_core_web_sm")
sentence_nlp = nlp(
"'Don Quixote' is a tragedy written by William Shakespeare sometime between 1599 and 1601."
)
html = displacy.render(sentence_nlp, style="ent", page=True, jupyter=False)
with open("ner_hamlet.html", "w") as fin:
fin.write(html)
# %%