Views
No views yet
pip install flair or pip install git+https://github.com/flairNLP/flair.git)1from flair.data import Sentence
2from flair.nn import Classifier
3from flair.tokenization import SciSpacyTokenizer
4
5# load tagger
6tagger = Classifier.load("regel-corpus/hunflair2-regel-tissue")
7
8# make example sentence
9sentence = Sentence("TNF-like factor that is both produced by osteoblasts, mesenchymal cells, "
10 "and activated T cells and required for osteoclast maturation and survival."
11 use_tokenizer=SciSpacyTokenizer())
12
13# predict NER tags
14tagger.predict(sentence)
15
16# print sentence
17print(sentence)
18
19# print predicted NER spans
20print('The following NER tags are found:')
21
22# iterate over entities and print
23for entity in sentence.get_spans('ner'):
24 print(entity)