QuaeroFrenchMed / QuaeroFrenchMed.py
mnaguib's picture
fix : back to dl_manager
d60d054
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pandas as pd
import datasets
from huggingface_hub import snapshot_download
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """
@article{neveol2014quaero,
title={The QUAERO French medical corpus: A ressource for medical entity recognition and normalization},
author={N{\'e}v{\'e}ol, Aur{\'e}lie and Grouin, Cyril and Leixa, Jeremy and Rosset, Sophie and Zweigenbaum, Pierre},
journal={Proc of BioTextMining Work},
pages={24--30},
year={2014}
}
"""
# You can copy an official description
_DESCRIPTION = """\
The QUAEROFrenchMed is a manually annotated corpus developed as a resource for named entity named recognition and normalization.
"""
_URLS = {
"EMEA": "https://huggingface.co/datasets/meczifho/QuaeroFrenchMed/tree/main/data",
"MEDLINE": "https://huggingface.co/datasets/meczifho/QuaeroFrenchMed/tree/main/data"
}
_HOMEPAGE = "https://quaerofrenchmed.limsi.fr/"
class QuaeroFrenchMed(datasets.GeneratorBasedBuilder):
"""
The QUAERO French Medical Corpus has been initially developed as a resource for named entity recognition and normalization [1]. It was then improved with the purpose of creating a gold standard set of normalized entities for French biomedical text, that was used in the CLEF eHealth evaluation lab [2][3].
A selection of MEDLINE titles and EMEA documents were manually annotated. The annotation process was guided by concepts in the Unified Medical Language System (UMLS):
1. Ten types of clinical entities, as defined by the following UMLS Semantic Groups (Bodenreider and McCray 2003) were annotated: Anatomy (ANAT), Chemical and Drugs (CHEM), Devices (DEVI), Disorders (DISO), Geographic Areas (GEOG), Living Beings (LIVB), Objects (OBJC), Phenomena (PHEN), Physiology (PHYS), Procedures (PROC).
2. The annotations were made in a comprehensive fashion, so that nested entities were marked, and entities could be mapped to more than one UMLS concept. In particular: (a) If a mention can refer to more than one Semantic Group, all the relevant Semantic Groups should be annotated. For instance, the mention “récidive” (recurrence) in the phrase “prévention des récidives” (recurrence prevention) should be annotated with the category “DISORDER” (CUI C2825055) and the category “PHENOMENON” (CUI C0034897); (b) If a mention can refer to more than one UMLS concept within the same Semantic Group, all the relevant concepts should be annotated. For instance, the mention “maniaques” (obsessive) in the phrase “patients maniaques” (obsessive patients) should be annotated with CUIs C0564408 and C0338831 (category “DISORDER”); (c) Entities which span overlaps with that of another entity should still be annotated. For instance, in the phrase “infarctus du myocarde” (myocardial infarction), the mention “myocarde” (myocardium) should be annotated with category “ANATOMY” (CUI C0027061) and the mention “infarctus du myocarde” should be annotated with category “DISORDER” (CUI C0027051)
"""
VERSION = datasets.Version("1.1.0")
# You will be able to load one or the other configurations in the following list with
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="EMEA", version=VERSION, description="information on marketed drugs from the European Medicines Agency (EMEA)"),
datasets.BuilderConfig(name="MEDLINE", version=VERSION, description="The titles of MEDLINE-indexed articles"),
]
DEFAULT_CONFIG_NAME = "MEDLINE"
def _info(self):
if self.config.name == "EMEA": # This is the name of the configuration selected in BUILDER_CONFIGS above
features = datasets.Features(
{
"docid": datasets.Value("string"),
"words": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(datasets.Value("int32")),
# These are the features of your dataset like images, labels ...
}
)
else:
features = datasets.Features(
{
"docid": datasets.Value("string"),
"words": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(datasets.Value("int32")),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=("words", "ner_tags"),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
train_pq = dl_manager.download_and_extract('https://huggingface.co/datasets/meczifho/QuaeroFrenchMed/resolve/main/data/train.parquet')
test_pq = dl_manager.download_and_extract('https://huggingface.co/datasets/meczifho/QuaeroFrenchMed/resolve/main/data/test.parquet')
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": train_pq,
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": test_pq,
"split": "test"
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, split):
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
#read the parquet file
df = pd.read_parquet(filepath)
if self.config.name == "EMEA":
df = df[df['docid'].str.split("_").str[0].str.len() < 4]
else:
df = df[df['docid'].str.split("_").str[0].str.len() >= 4]
for key, row in df.iterrows():
yield key, {
"docid": row["docid"],
"words": row["words"],
"ner_tags": row["ner_tags"],
}