File size: 3,003 Bytes
6b97273 d2d1068 6b97273 f82abe2 6b97273 0c22e14 6b97273 8c38d8c 6b97273 d81609f 6b97273 0c22e14 40b3fef 6b97273 8c38d8c 6b97273 |
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 |
import json
import os
import datasets
import ast
# Metadata and descriptions for the dataset
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {Test Repo Dataset},
author={huggingface, Inc.},
year={2020}
}
"""
_DESCRIPTION = """\
The Test Repo dataset includes multiple choice questions tailored for NLP research and testing.
"""
_HOMEPAGE = "https://huggingface.co/datasets/anand-s/test_repo"
_LICENSE = "Apache License 2.0"
# Define URLs for different parts of the dataset if applicable
_URLS = {
"mcq_domain": "https://huggingface.co/datasets/anand-s/test_repo/resolve/main/train_mcq.zip",
}
class TestRepo(datasets.GeneratorBasedBuilder):
"""Dataset for multiple choice questions from Test Repo."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="mcq_domain", version=VERSION, description="This configuration covers multiple choice questions."),
]
DEFAULT_CONFIG_NAME = "mcq_domain"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"prompt": datasets.Value("string"),
"question": datasets.Value("string"),
"options": datasets.Value("string"),
"answer": datasets.Value("string"),
"context": datasets.Value("string"), # Assuming all data includes context
"num_options": datasets.Value("string"),
"question_type": datasets.Value("string"),
}),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
# Download and extract all the files in the directory
data_dir = dl_manager.download_and_extract(_URLS[self.config.name])
print(data_dir)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"directory": data_dir, "split": "train"},
),
]
def _generate_examples(self, directory, split):
# Iterate over each file in the directory
for filename in os.listdir(directory):
filepath = os.path.join(directory, filename)
if filepath.endswith(".jsonl"):
with open(filepath, encoding="utf-8") as f:
for key, row in enumerate(f):
data = json.loads(row)
yield key, {
"prompt": data.get("prompt", ""),
"question": data["question"],
"options": ast.literal_eval(data["options"]),
"answer": data.get("answer", ""),
"context": data.get("context", ""),
"num_options": data.get("num_options", ""),
"question_type": data.get("question_type", ""),
}
|