biocreative_gene_mention / biocreative_gene_mention.py
enoriega's picture
Initial commit
eb3fbac
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