Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to programmatically get the NER of a word? #3261

Closed
AngledLuffa opened this issue Jun 9, 2023 · 4 comments
Closed

[Question]: How to programmatically get the NER of a word? #3261

AngledLuffa opened this issue Jun 9, 2023 · 4 comments
Labels
question Further information is requested

Comments

@AngledLuffa
Copy link

Question

In the sample NER, you suggest doing the following:

# make example sentence
# use_tokenizer means split on whitespace?
sentence = Sentence("George Washington went to Washington", use_tokenizer=False)

# predict NER tags
tagger.predict(sentence)

# print sentence
print(sentence)

Is there a good way to get the NER of a specific word, such as the first word, George? The closest I can figure out is to look at the spans and their tokens, which have an idx field. Still, it would be much easier to look at the members sentence, say sentence[0], and somehow get the NER off it... sentence[0].ner does not exist, though

Thanks!

@AngledLuffa AngledLuffa added the question Further information is requested label Jun 9, 2023
@AngledLuffa
Copy link
Author

This is a flair.data.Label:

sentence[0].get_label('ner')

but it doesn't actually have anything on it

This is also a Label:

entity = sentence.get_spans('ner')[0]
entity.get_label('ner')
label.value    # this is PER
entity.tokens[0].idx    # this is 1, representing George, index in the array + 1

I think the NER documentation would benefit from an example of how to access it programmatically, and if there's an easier way, it would be good to hear about it. Thanks!

@helpmefindaname
Copy link
Collaborator

Hi @AngledLuffa ,
we are currently restructuring our docs and try to set them up in a more complete way soon.
However in the specific case, you have the answer to your question documented here

@AngledLuffa
Copy link
Author

AngledLuffa commented Jun 9, 2023 via email

@nikhilcms
Copy link

Hi,

Can you pls provide a solution how to get actual start and end indices such that using this indices I can extract detected entity like spacy ner model provides ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants