chemicals-exact-match
Biomedical Entity Mention Linking for chemical
Demo: How to use in Flair
Requires:
- Flair>=0.14.0 (
pip install flair
orpip install git+https://github.com/flairNLP/flair.git
)
from flair.data import Sentence
from flair.models import Classifier, EntityMentionLinker
sentence = Sentence("Behavioral abnormalities in the Fmr1 KO2 Mouse Model of Fragile X Syndrome")
# load hunflair to detect the entity mentions we want to link.
tagger = Classifier.load("hunflair")
tagger.predict(sentence)
# load the linker and dictionary
linker = EntityMentionLinker.load("helpmefindaname/flair-eml-chemicals-exact-match")
dictionary = linker.dictionary
# find then candidates for the mentions
linker.predict(sentence)
# print the results for each entity mention:
for span in sentence.get_spans(linker.entity_label_type):
print(f"Span: {span.text}")
for candidate_label in span.get_labels(linker.label_type):
candidate = dictionary[candidate_label.value]
print(f"Candidate: {candidate.concept_name}")
As an alternative to downloading the already precomputed model (much storage). You can also build the model and compute the embeddings for the dataset using:
linker = EntityMentionLinker.build("exact-string-match", "chemical", dictionary_name_or_path="ctd-chemicals", hybrid_search=False, entity_type="chemical-eml")
This will reduce the download requirements, at the cost of computation.
This EntityMentionLinker uses https://huggingface.co/exact-string-match as embeddings for linking mentions to candidates.
- Downloads last month
- 4