Skip to content
Discussion options

You must be logged in to vote

The method on the Doc object isn't present in v2 but you can create custom spans and set the .ents property.

import spacy

nlp = spacy.blank("en")

text = "My name is John Smith and I live in Paris"
entities = [
    ("Employee", 11, 21),  # John Smith
    ("Location", 36, 41),  # Paris
]

doc = nlp(text)

ents = []
for ee in entities:
    ents.append(doc.char_span(ee[1], ee[2], ee[0]))

doc.ents = ents

for ent in doc.ents:
    print(ent, ent.label_, sep="\t")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThR3742
Comment options

Answer selected by ines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / visualizers Feature: Built-in displaCy and other visualizers
2 participants