Flair: Grabbing NER tags from tagged text?

Created on 18 Jul 2019  路  1Comment  路  Source: flairNLP/flair

I am trying to use flair to create an annotation of a document using IOB tags.
I am using the pretrained ner-ontonotes model.
I used the to_tagged_string() function where it produces the following output:

A 35 percent increase in tuberculosis in 1989 in Newark, N.J. ....

My question is, is there a library function to grab those words and their tags?
My goal is to produce this kind of annotation text file

A O
35 B-PERCENT
percent I-PERCENT
....

I am newbie, so forgive me if I came across as vague.

question

Most helpful comment

@TheArowanaDude there are several ways to do this. You could for instance iterate over all tokens in a sentence and print out the fields that you need:

for token in sentence:
     print(f'{token.text} {token.get_tag('ner')}')

You could also iterate over full NER tags if that is helpful:

for ner in sentence.get_spans('ner):
     print(ner)

>All comments

@TheArowanaDude there are several ways to do this. You could for instance iterate over all tokens in a sentence and print out the fields that you need:

for token in sentence:
     print(f'{token.text} {token.get_tag('ner')}')

You could also iterate over full NER tags if that is helpful:

for ner in sentence.get_spans('ner):
     print(ner)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefan-it picture stefan-it  路  3Comments

jannenev picture jannenev  路  3Comments

mittalsuraj18 picture mittalsuraj18  路  3Comments

ChessMateK picture ChessMateK  路  3Comments

Aditya715 picture Aditya715  路  3Comments