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]: Get NER text and labels separately (and lack of API documentation) #3584

Closed
alxgrh opened this issue Dec 18, 2024 · 1 comment
Closed
Labels
question Further information is requested

Comments

@alxgrh
Copy link

alxgrh commented Dec 18, 2024

Question

Hello Flair team,
and thank you for your great project!

I'm trying to use Flair for named entity recognition task. I need to get text and associated label separately. Unfortunately documentation examples contain only code for printing entire NER.
So far I've come to this solution

for entity in sentence.get_spans('ner'):
    text = ' '.join([token.text for token in entity.annotation_layers['ner'][0].data_point.tokens])
    label = entity.annotation_layers['ner'][0].value
    print(text, '->', label)

Is there some more elegant API usage option? Like in spacy-nlp for example

doc = nlp(text)
for ent in doc.ents:
    print(ent.text, '->', ent.label_)
@alxgrh alxgrh added the question Further information is requested label Dec 18, 2024
@helpmefindaname
Copy link
Member

Hi @alxgrh
I think your question is answered in this tutorial or by using get_labels

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

2 participants