Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- flair
|
4 |
+
- entity-mention-linker
|
5 |
+
---
|
6 |
+
|
7 |
+
## bioasyn-sapbert-bc2gn-gene
|
8 |
+
|
9 |
+
Biomedical Entity Mention Linking for gene:
|
10 |
+
|
11 |
+
- Model: [dmis-lab/biosyn-sapbert-bc2gn](https://huggingface.co/dmis-lab/biosyn-sapbert-bc2gn)
|
12 |
+
- Dictionary: [NCBI Gene](https://www.ncbi.nlm.nih.gov/gene) ([Homo_sapiens.gene_info.gz](https://ftp.ncbi.nih.gov/gene/DATA/GENE_INFO/Mammalia/))
|
13 |
+
|
14 |
+
NOTE: This model variant does not perform abbreviation resolution via [A3bP](https://github.com/ncbi-nlp/Ab3P)
|
15 |
+
|
16 |
+
### Demo: How to use in Flair
|
17 |
+
|
18 |
+
Requires:
|
19 |
+
|
20 |
+
- **[Flair](https://github.com/flairNLP/flair/)>=0.14.0** (`pip install flair` or `pip install git+https://github.com/flairNLP/flair.git`)
|
21 |
+
|
22 |
+
```python
|
23 |
+
from flair.data import Sentence
|
24 |
+
from flair.models import Classifier, EntityMentionLinker
|
25 |
+
from flair.tokenization import SciSpacyTokenizer
|
26 |
+
|
27 |
+
sentence = Sentence(
|
28 |
+
"The mutation in the ABCD1 gene causes X-linked adrenoleukodystrophy, "
|
29 |
+
"a neurodegenerative disease, which is exacerbated by exposure to high "
|
30 |
+
"levels of mercury in dolphin populations.",
|
31 |
+
use_tokenizer=SciSpacyTokenizer()
|
32 |
+
)
|
33 |
+
|
34 |
+
# load hunflair to detect the entity mentions we want to link.
|
35 |
+
tagger = Classifier.load("hunflair-gene")
|
36 |
+
tagger.predict(sentence)
|
37 |
+
|
38 |
+
# load the linker and dictionary
|
39 |
+
linker = EntityMentionLinker.load("gene-linker")
|
40 |
+
linker.predict(sentence)
|
41 |
+
|
42 |
+
# print the results for each entity mention:
|
43 |
+
for span in sentence.get_spans(tagger.label_type):
|
44 |
+
for link in span.get_labels(linker.label_type):
|
45 |
+
print(f"{span.text} -> {link.value}")
|
46 |
+
```
|
47 |
+
|
48 |
+
As an alternative to downloading the already precomputed model (much storage). You can also build the model
|
49 |
+
and compute the embeddings for the dataset using:
|
50 |
+
|
51 |
+
```python
|
52 |
+
linker = EntityMentionLinker.build("dmis-lab/biosyn-sapbert-bc2gn", dictionary_name_or_path="ncbi-gene", hybrid_search=False)
|
53 |
+
```
|
54 |
+
|
55 |
+
This will reduce the download requirements, at the cost of computation.
|