Skip to content

Instantly share code, notes, and snippets.

@ToshihikoSakai
Last active March 7, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToshihikoSakai/072fdce2ae7dce55578df5a0f24dcaa2 to your computer and use it in GitHub Desktop.
Save ToshihikoSakai/072fdce2ae7dce55578df5a0f24dcaa2 to your computer and use it in GitHub Desktop.
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