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-species")
14tagger.predict(sentence)
15
16# load the linker and dictionary
17linker = EntityMentionLinker.load("species-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("cambridgeltl/SapBERT-from-PubMedBERT-fulltext", dictionary_name_or_path="ncbi-taxonomy", entity_type="species", hybrid_search=False)hybrid_search=False as SapBERT unlike BioSyn is trained only for dense retrieval.