|
import json |
|
import datasets |
|
|
|
_CITATION = """\ |
|
@inproceedings{your_citation, |
|
title={Hindi_Trec_Covid}, |
|
author={Arkadeep Acharya}, |
|
year={2025}, |
|
url={https://huggingface.co/datasets/AIhnIndicRag/Hindi_Trec_Covid} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Your dataset description goes here. |
|
""" |
|
|
|
_HOMEPAGE = "https://your-dataset-homepage" |
|
|
|
|
|
_URLs = { |
|
"default": "https://huggingface.co/datasets/AIhnIndicRag/Hindi_Trec_Covid/resolve/main/qrels/test.tsv", |
|
"corpus": "https://huggingface.co/datasets/AIhnIndicRag/Hindi_Trec_Covid/resolve/main/corpus.jsonl", |
|
"queries": "https://huggingface.co/datasets/AIhnIndicRag/Hindi_Trec_Covid/resolve/main/queries.jsonl", |
|
} |
|
|
|
class MyDataset(datasets.GeneratorBasedBuilder): |
|
"""My custom dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="default", version=VERSION, description="Default configuration"), |
|
datasets.BuilderConfig(name="corpus", version=VERSION, description="Corpus configuration"), |
|
datasets.BuilderConfig(name="queries", version=VERSION, description="Queries configuration"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "default" |
|
|
|
def _info(self): |
|
if self.config.name == "default": |
|
features = datasets.Features({ |
|
"query-id": datasets.Value("string"), |
|
"corpus-id": datasets.Value("string"), |
|
"score": datasets.Value("float64"), |
|
}) |
|
elif self.config.name == "queries": |
|
features = datasets.Features({ |
|
"_id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
}) |
|
elif self.config.name == "corpus": |
|
features = datasets.Features({ |
|
"_id": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"metadata": { |
|
"url": datasets.Value("string"), |
|
"pubmed_id": datasets.Value("string"), |
|
}, |
|
}) |
|
else: |
|
raise ValueError(f"Unknown config name: {self.config.name}") |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
if self.config.name not in _URLs: |
|
raise ValueError(f"Unknown config name: {self.config.name}") |
|
|
|
|
|
data_file = dl_manager.download_and_extract(_URLs[self.config.name]) |
|
|
|
|
|
split_name = datasets.Split.TEST if self.config.name == "default" else self.config.name |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=split_name, |
|
gen_kwargs={"file_path": data_file}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, file_path): |
|
if self.config.name == "default": |
|
with open(file_path, encoding="utf-8") as f: |
|
next(f) |
|
for id_, line in enumerate(f): |
|
query_id, corpus_id, score = line.strip().split("\t") |
|
yield id_, { |
|
"query-id": query_id, |
|
"corpus-id": corpus_id, |
|
"score": float(score), |
|
} |
|
else: |
|
with open(file_path, encoding="utf-8") as f: |
|
for id_, line in enumerate(f): |
|
data = json.loads(line) |
|
if self.config.name == "corpus": |
|
yield id_, { |
|
"_id": data["_id"], |
|
"title": data["title"], |
|
"text": data["text"], |
|
"metadata": { |
|
"url": data.get("metadata", {}).get("url", ""), |
|
"pubmed_id": data.get("metadata", {}).get("pubmed_id", ""), |
|
}, |
|
} |
|
elif self.config.name == "queries": |
|
yield id_, { |
|
"_id": data["_id"], |
|
"text": data["text"], |
|
} |
|
|