File size: 3,423 Bytes
6d00b84 373bc02 5fc5450 6d00b84 |
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 |
# 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.
"""MedWiki."""
import os
import datasets
import pandas as pd
_CITATION = """\
@article{corbeil2024iryonlp,
title={IryoNLP at MEDIQA-CORR 2024: Tackling the Medical Error Detection & Correction Task On the Shoulders of Medical Agents},
author={Jean-Philippe Corbeil},
journal={arXiv preprint arXiv:2404.15488},
year={2024}
}
"""
_DESCRIPTION = """\
This is a filtered version of the `Cohere/wikipedia-22-12` on medical topic articles using `MaartenGr/BERTopic_Wikipedia`. Keep note that some articles in the viewer might seem off topic, but usually they are related in some way (e.g. World War I is linked to the Spanish Flu). This is artefacts of some noise in the topic modelling.
"""
_HOMEPAGE = ""
_LICENSE = "CC-BY-SA"
_URLS = {
"first_domain": "Cohere/wikipedia-22-12",
}
class MedWikiDataset(datasets.GeneratorBasedBuilder):
"""Medical Wikipedia Articles."""
VERSION = datasets.Version("0.0.1")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
]
DEFAULT_CONFIG_NAME = "first_domain"
def _info(self):
features = datasets.Features(
{
"wiki_id": datasets.Value("int32"),
"title": datasets.Value("string"),
"text": datasets.Value("string"),
"paragraph_id": datasets.Value("int32"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URLS[self.config.name]
dataset = datasets.load_dataset(urls, "en", trust_remote_code=True, cache_dir="/Users/jcorbeil/Documents/datasets/TEMP")
path = dl_manager.download_and_extract("https://huggingface.co/datasets/jpcorb20/medical_wikipedia/resolve/main/med_topics.csv")
df = pd.read_csv(path)
med_wiki_ids = set(df["wiki_id"].values.tolist())
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"dataset": dataset["train"],
"med_wiki_ids": med_wiki_ids,
},
),
]
def _generate_examples(self, dataset, med_wiki_ids):
count = -1
for data in dataset:
if data["wiki_id"] in med_wiki_ids:
count += 1
yield count, {
"wiki_id": data["wiki_id"],
"title": data["title"],
"text": data["text"],
"paragraph_id": data["paragraph_id"],
}
|