File size: 1,716 Bytes
473d731 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
---
tags:
- flair
- entity-mention-linker
---
## biobert-bc2gn-gene
Biomedical Entity Mention Linking for gene
### Demo: How to use in Flair
Requires:
- **[Flair](https://github.com/flairNLP/flair/)>=0.14.0** (`pip install flair` or `pip install git+https://github.com/flairNLP/flair.git`)
```python
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-biobert-bc2gn-gene")
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:
```python
linker = EntityMentionLinker.build("dmis-lab/biosyn-biobert-bc2gn", "gene", dictionary_name_or_path="ncbi-gene", hybrid_search=False, entity_type="gene-eml")
```
This will reduce the download requirements, at the cost of computation.
This EntityMentionLinker uses [https://huggingface.co/dmis-lab/biosyn-biobert-bc2gn](dmis-lab/biosyn-biobert-bc2gn) as embeddings for linking mentions to candidates.
|