# 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"], }