Datasets:
Tasks:
Token Classification
Modalities:
Text
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
10K - 100K
License:
chintagunta85
commited on
Commit
·
8d3c877
1
Parent(s):
fade8fe
Upload bc2gm_test.py
Browse files- bc2gm_test.py +124 -0
bc2gm_test.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
|
3 |
+
logger = datasets.logging.get_logger(__name__)
|
4 |
+
|
5 |
+
|
6 |
+
_CITATION = """\
|
7 |
+
@article{smith2008overview,
|
8 |
+
title={Overview of BioCreative II gene mention recognition},
|
9 |
+
author={Smith, Larry and Tanabe, Lorraine K and nee Ando, Rie Johnson and Kuo, Cheng-Ju and Chung, I-Fang and Hsu, Chun-Nan and Lin, Yu-Shi and Klinger, Roman and Friedrich, Christoph M and Ganchev, Kuzman and others},
|
10 |
+
journal={Genome biology},
|
11 |
+
volume={9},
|
12 |
+
number={S2},
|
13 |
+
pages={S2},
|
14 |
+
year={2008},
|
15 |
+
publisher={Springer}
|
16 |
+
}"""
|
17 |
+
|
18 |
+
_DESCRIPTION = """\
|
19 |
+
Nineteen teams presented results for the Gene Mention Task at the BioCreative II Workshop.
|
20 |
+
In this task participants designed systems to identify substrings in sentences corresponding to gene name mentions.
|
21 |
+
A variety of different methods were used and the results varied with a highest achieved F1 score of 0.8721.
|
22 |
+
Here we present brief descriptions of all the methods used and a statistical analysis of the results.
|
23 |
+
We also demonstrate that, by combining the results from all submissions, an F score of 0.9066 is feasible,
|
24 |
+
and furthermore that the best result makes use of the lowest scoring submissions.
|
25 |
+
For more details, see: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2559986/
|
26 |
+
The original dataset can be downloaded from: https://biocreative.bioinformatics.udel.edu/resources/corpora/biocreative-ii-corpus/
|
27 |
+
This dataset has been converted to CoNLL format for NER using the following tool: https://github.com/spyysalo/standoff2conll
|
28 |
+
"""
|
29 |
+
|
30 |
+
_HOMEPAGE = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2559986/"
|
31 |
+
_URL = "https://github.com/spyysalo/bc2gm-corpus/raw/master/conll/"
|
32 |
+
_TRAINING_FILE = "train.tsv"
|
33 |
+
_DEV_FILE = "devel.tsv"
|
34 |
+
_TEST_FILE = "test.tsv"
|
35 |
+
|
36 |
+
|
37 |
+
class Bc2gmCorpusConfig(datasets.BuilderConfig):
|
38 |
+
"""BuilderConfig for Bc2gmCorpus"""
|
39 |
+
|
40 |
+
def __init__(self, **kwargs):
|
41 |
+
"""BuilderConfig for Bc2gmCorpus.
|
42 |
+
Args:
|
43 |
+
**kwargs: keyword arguments forwarded to super.
|
44 |
+
"""
|
45 |
+
super(Bc2gmCorpusConfig, self).__init__(**kwargs)
|
46 |
+
|
47 |
+
class Bc2gmCorpus(datasets.GeneratorBasedBuilder):
|
48 |
+
"""Bc2gmCorpus dataset."""
|
49 |
+
|
50 |
+
BUILDER_CONFIGS = [
|
51 |
+
Bc2gmCorpusConfig(name="bc2gm_corpus", version=datasets.Version("1.0.0"), description="bc2gm corpus"),
|
52 |
+
]
|
53 |
+
|
54 |
+
def _info(self):
|
55 |
+
|
56 |
+
custom_names = ['O','B-GENE','I-GENE','B-CHEMICAL','I-CHEMICAL','B-DISEASE','I-DISEASE',
|
57 |
+
'B-DNA', 'I-DNA', 'B-RNA', 'I-RNA', 'B-CELL_LINE', 'I-CELL_LINE', 'B-CELL_TYPE', 'I-CELL_TYPE',
|
58 |
+
'B-PROTEIN', 'I-PROTEIN', 'B-SPECIES', 'I-SPECIES']
|
59 |
+
|
60 |
+
return datasets.DatasetInfo(
|
61 |
+
description=_DESCRIPTION,
|
62 |
+
features=datasets.Features(
|
63 |
+
{
|
64 |
+
"id": datasets.Value("string"),
|
65 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
66 |
+
"ner_tags": datasets.Sequence(
|
67 |
+
datasets.features.ClassLabel(
|
68 |
+
names=custom_names
|
69 |
+
)
|
70 |
+
),
|
71 |
+
}
|
72 |
+
),
|
73 |
+
supervised_keys=None,
|
74 |
+
homepage=_HOMEPAGE,
|
75 |
+
citation=_CITATION,
|
76 |
+
)
|
77 |
+
|
78 |
+
def _split_generators(self, dl_manager):
|
79 |
+
"""Returns SplitGenerators."""
|
80 |
+
urls_to_download = {
|
81 |
+
"train": f"{_URL}{_TRAINING_FILE}",
|
82 |
+
"dev": f"{_URL}{_DEV_FILE}",
|
83 |
+
"test": f"{_URL}{_TEST_FILE}",
|
84 |
+
}
|
85 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
86 |
+
|
87 |
+
return [
|
88 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
89 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
90 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
91 |
+
]
|
92 |
+
|
93 |
+
def _generate_examples(self, filepath):
|
94 |
+
shift = 0
|
95 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
96 |
+
with open(filepath, encoding="utf-8") as f:
|
97 |
+
guid = 0
|
98 |
+
tokens = []
|
99 |
+
ner_tags = []
|
100 |
+
for line in f:
|
101 |
+
if line == "" or line == "\n":
|
102 |
+
if tokens:
|
103 |
+
yield guid, {
|
104 |
+
"id": str(guid),
|
105 |
+
"tokens": tokens,
|
106 |
+
"ner_tags": ner_tags,
|
107 |
+
}
|
108 |
+
guid += 1
|
109 |
+
tokens = []
|
110 |
+
ner_tags = []
|
111 |
+
else:
|
112 |
+
# tokens are tab separated
|
113 |
+
splits = line.split("\t")
|
114 |
+
tokens.append(splits[0])
|
115 |
+
ner_tags.append(str(int(splits[1].rstrip()+shift)))
|
116 |
+
# last example
|
117 |
+
yield guid, {
|
118 |
+
"id": str(guid),
|
119 |
+
"tokens": tokens,
|
120 |
+
"ner_tags": ner_tags,
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
# Bc2gmCorpus()
|