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
3
4sentence = Sentence("Behavioral abnormalities in the Fmr1 KO2 Mouse Model of Fragile X Syndrome")
5
6# load hunflair to detect the entity mentions we want to link.
7tagger = Classifier.load("hunflair")
8tagger.predict(sentence)
9
10# load the linker and dictionary
11linker = EntityMentionLinker.load("helpmefindaname/flair-eml-sapbert-bc2gn-gene")
12dictionary = linker.dictionary
13
14# find then candidates for the mentions
15linker.predict(sentence)
16
17# print the results for each entity mention:
18for span in sentence.get_spans(linker.entity_label_type):
19 print(f"Span: {span.text}")
20 for candidate_label in span.get_labels(linker.label_type):
21 candidate = dictionary[candidate_label.value]
22 print(f"Candidate: {candidate.concept_name}")linker = EntityMentionLinker.build("dmis-lab/biosyn-sapbert-bc2gn", "gene", dictionary_name_or_path="ncbi-gene", hybrid_search=False, entity_type="gene-eml")