File size: 6,946 Bytes
eb3fbac |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
import csv
import os
from collections import defaultdict
import datasets
from datasets import Sequence, Value
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@article{cite-key,
Abstract = {Nineteen teams presented results for the Gene Mention Task at the BioCreative II Workshop. In this task participants designed systems to identify substrings in sentences corresponding to gene name mentions. A variety of different methods were used and the results varied with a highest achieved F1 score of 0.8721. Here we present brief descriptions of all the methods used and a statistical analysis of the results. We also demonstrate that, by combining the results from all submissions, an F score of 0.9066 is feasible, and furthermore that the best result makes use of the lowest scoring submissions.},
Author = {Smith, Larry and Tanabe, Lorraine K. and Ando, Rie Johnson nee 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 Torii, Manabu and Liu, Hongfang and Haddow, Barry and Struble, Craig A. and Povinelli, Richard J. and Vlachos, Andreas and Baumgartner, William A. and Hunter, Lawrence and Carpenter, Bob and Tsai, Richard Tzong-Han and Dai, Hong-Jie and Liu, Feng and Chen, Yifei and Sun, Chengjie and Katrenko, Sophia and Adriaans, Pieter and Blaschke, Christian and Torres, Rafael and Neves, Mariana and Nakov, Preslav and Divoli, Anna and Ma{\~n}a-L{\'o}pez, Manuel and Mata, Jacinto and Wilbur, W. John},
Da = {2008/09/01},
Date-Added = {2022-04-15 17:35:45 -0700},
Date-Modified = {2022-04-15 17:35:45 -0700},
Doi = {10.1186/gb-2008-9-s2-s2},
Id = {Smith2008},
Isbn = {1474-760X},
Journal = {Genome Biology},
Number = {2},
Pages = {S2},
Title = {Overview of BioCreative II gene mention recognition},
Ty = {JOUR},
Url = {https://doi.org/10.1186/gb-2008-9-s2-s2},
Volume = {9},
Year = {2008},
Bdsk-Url-1 = {https://doi.org/10.1186/gb-2008-9-s2-s2}}
"""
# You can copy an official description
_DESCRIPTION = """\
Training and validation datasets for the BioCreative II gene mention task.
The data has been tokenized with [processors](https://github.com/clulab/processors)
## Features:
- __tokens__: Input token sequence
- __folded_tokens__: Same as tokens, but case-folded
- __tags__: POS tags of the input sequence tokens
- __labels__: BIO sequence tags
"""
_HOMEPAGE = "https://biocreative.bioinformatics.udel.edu/resources/corpora/biocreative-ii-corpus/"
class BioCreativeBIODataset(datasets.GeneratorBasedBuilder):
"""
BioCreative dataset processed to BIO tags
"""
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
'tokens': Sequence(Value('string')),
'folded_tokens': Sequence(Value('string')),
'tags': Sequence(datasets.features.ClassLabel(
names=['WRB',
'WP',
'DT',
"''",
'#',
'JJS',
" '' ",
'NN',
'JJ',
'VBZ',
'VBP',
'FW',
'RBR',
'MD',
'VBG',
'.',
',',
'PRP$',
'PRP',
' `` ',
'IN',
'VBD',
'VB',
'WP$',
'TO',
'RP',
'RB',
'NNPS',
'VBN',
'LS',
'CC',
'RBS',
'PDT',
'WDT',
'POS',
'NNS',
'NNP',
'EX',
'SYM',
'CD',
':',
'JJR',
'$']
)),
'labels': Sequence(
datasets.features.ClassLabel(
names=['B-Gene_or_gene_product', 'I-Gene_or_gene_product', 'O']
)
)
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# # License for the dataset if available
# license=_LICENSE,
# # Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.download_and_extract("bc2geneMention.zip")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, "bc2geneMention", "IOB", "train.iob.txt"),
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, "bc2geneMention", "IOB", "dev.iob.txt"),
"split": "dev",
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, split, ipdb=None):
current = defaultdict(list)
col_names = "tokens tags folded_tokens labels".split()
key = 0
# Parse the file contents
with open(filepath) as f:
reader = csv.reader(f, delimiter=' ')
for row in reader:
if len(row) == 0:
yield key, current
key += 1
current = defaultdict(list)
else:
if len(row) == 2:
row = [row[0], row[0], row[0], row[1]]
for k, v in zip(col_names, row):
current[k].append(v)
# Corner case
if len(row) > 0:
yield key, current
|