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 "The mutation in the ABCD1 gene causes X-linked adrenoleukodystrophy, "
7 "a neurodegenerative disease, which is exacerbated by exposure to high "
8 "levels of mercury in dolphin populations.",
9 use_tokenizer=SciSpacyTokenizer()
10)
11
12# load hunflair to detect the entity mentions we want to link.
13tagger = Classifier.load("hunflair-disease")
14tagger.predict(sentence)
15
16# load the linker and dictionary
17linker = EntityMentionLinker.load("disease-linker")
18linker.predict(sentence)
19
20# print the results for each entity mention:
21for span in sentence.get_spans(tagger.label_type):
22 for link in span.get_labels(linker.label_type):
23 print(f"{span.text} -> {link.value}")linker = EntityMentionLinker.build("dmis-lab/biosyn-sapbert-bc5cdr-disease", dictionary_name_or_path="ctd-diseases", hybrid_search=True)