Skip to content

Instantly share code, notes, and snippets.

@ToshihikoSakai
Last active March 7, 2022 13:32
Embed
What would you like to do?
Display NER tags with SpaCy displacy
import spacy
from spacy import displacy
nlp = spacy.blank('ja')
raw_text = "私は東京に行きます。その後、千葉にも行きます。"
doc = nlp.make_doc(raw_text)
spans = [[2,4,"LOC"],[14,16,"LOC"]]
ents = []
for span_start, span_end, label in spans:
ent = doc.char_span(span_start, span_end, label=label)
if ent is None:
continue
ents.append(ent)
doc.ents = ents
displacy.render(doc, style="ent", jupyter=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment