Skip to content

use custom NER webservice to set_entities in doc #9535

Discussion options

You must be logged in to vote

Hi @aakashb95 !

You can use char_span so that you can slice through character indices.
Also, the character offsets are incorrect: for start it should be the index of the first character, but for end, it must be the last character after the span:

import spacy

data = [
    ("John Snow", "PERSON", (0, 9)),  # last character after the span
]

nlp = spacy.blank("en")
for text, label, (start, end) in data:
    doc = nlp(text)
    span = doc.char_span(start, end, label=label)
    doc.ents = [span]  

Usually, you'd have multiple entities in a given document, that's why we pass a list to doc.ents. You can adapt the snippet above to fit your use-case 👍 Also, you can check the char_span docs for mo…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@aakashb95
Comment options

@ljvmiranda921
Comment options

@aakashb95
Comment options

@ljvmiranda921
Comment options

Answer selected by svlandeg
Comment options

You must be logged in to vote
2 replies
@ljvmiranda921
Comment options

@aakashb95
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / ner Feature: Named Entity Recognizer
2 participants