File size: 2,241 Bytes
ba722a9
 
 
 
 
 
 
 
 
 
 
 
 
 
aaad96c
ba722a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f646d74
ba722a9
 
 
 
 
 
 
 
 
 
 
 
512ba11
 
ba722a9
 
 
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
53
54
55
56
57
58
---
tags:
  - flair
  - entity-mention-linker
---

## sapbert-ncbi-taxonomy-no-ab3p

Biomedical Entity Mention Linking for UMLS.
We use this model for species since NCBI Taxonomy is contained in UMLS:

- Model:  [cambridgeltl/SapBERT-from-PubMedBERT-fulltext](https://huggingface.co/cambridgeltl/SapBERT-from-PubMedBERT-fulltext)
- Dictionary: [NCBI Taxonomy](https://www.ncbi.nlm.nih.gov/taxonomy) (See [FTP](https://ftp.ncbi.nih.gov/pub/taxonomy/new_taxdump/))

NOTE: This model variant does not perform abbreviation resolution via [A3bP](https://github.com/ncbi-nlp/Ab3P)

### 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
from flair.tokenization import SciSpacyTokenizer

sentence = Sentence(
    "The mutation in the ABCD1 gene causes X-linked adrenoleukodystrophy, "
    "a neurodegenerative disease, which is exacerbated by exposure to high "
    "levels of mercury in dolphin populations.",
    use_tokenizer=SciSpacyTokenizer()
)

# load hunflair to detect the entity mentions we want to link.
tagger = Classifier.load("hunflair-species")
tagger.predict(sentence)

# load the linker and dictionary
linker = EntityMentionLinker.load("species-linker-no-abbres")
linker.predict(sentence)

# print the results for each entity mention:
for span in sentence.get_spans(tagger.label_type):
    for link in span.get_labels(linker.label_type):
      print(f"{span.text} -> {link.value}")
```

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
from flair.models.entity_mention_linking import BioSynEntityPreprocessor
linker = EntityMentionLinker.build("cambridgeltl/SapBERT-from-PubMedBERT-fulltext", dictionary_name_or_path="ncbi-taxonomy", entity_type="species", preprocessor=BioSynEntityPreprocessor(), hybrid_search=False)
```

This will reduce the download requirements, at the cost of computation. Note `hybrid_search=False` as SapBERT unlike BioSyn is trained only for dense retrieval.