Views
No views yet
pip install flair or pip install git+https://github.com/flairNLP/flair.git)1from flair.data import Sentence
2from flair.models import Classifier, EntityMentionLinker
3from flair.tokenization import SciSpacyTokenizer
4
5sentence = Sentence(
6 "TNF-like factor that is both produced by osteoblasts, mesenchymal cells, ",
7 "and activated T cells and required for osteoclast maturation and survival."
8 use_tokenizer=SciSpacyTokenizer()
9)
10
11# load hunflair to detect the entity mentions we want to link.
12tagger = Classifier.load("regel-corpus/hunflair2-regel-tissue")
13tagger.predict(sentence)
14
15# load the linker and dictionary
16linker = EntityMentionLinker.load("regel-corpus/biosyn-sapbert-regel-bto")
17linker.predict(sentence)
18
19# print the results for each entity mention:
20for span in sentence.get_spans(tagger.label_type):
21 for link in span.get_labels(linker.label_type):
22 print(f"{span.text} -> {link.value}")