Delete pquad_public.py
Browse files- pquad_public.py +0 -94
pquad_public.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import datasets
|
| 3 |
-
_CITATION = """\
|
| 4 |
-
@article{darvishi2022pquad,
|
| 5 |
-
title={PQuAD: A Persian Question Answering Dataset},
|
| 6 |
-
author={Darvishi, Kasra and Shahbodagh, Newsha and Abbasiantaeb, Zahra and Momtazi, Saeedeh},
|
| 7 |
-
journal={arXiv preprint arXiv:2202.06219},
|
| 8 |
-
year={2022}
|
| 9 |
-
}
|
| 10 |
-
"""
|
| 11 |
-
_DESCRIPTION = """\\\\
|
| 12 |
-
ParSQuAD: Persian Question Answering Dataset based on Machine Translation of SQuAD 2.0
|
| 13 |
-
"""
|
| 14 |
-
_URL = "https://raw.githubusercontent.com/vassef/pquad_public/main/"
|
| 15 |
-
_URLS = {
|
| 16 |
-
"train": _URL + "train_samples.json",
|
| 17 |
-
"validation":_URL + "validation_samples.json",
|
| 18 |
-
"test": _URL + "test_samples.json",
|
| 19 |
-
}
|
| 20 |
-
class pquad_public_Config(datasets.BuilderConfig):
|
| 21 |
-
"""BuilderConfig for PQuAD."""
|
| 22 |
-
def __init__(self, **kwargs):
|
| 23 |
-
"""BuilderConfig for PQuAD.
|
| 24 |
-
Args:
|
| 25 |
-
**kwargs: keyword arguments forwarded to super.
|
| 26 |
-
"""
|
| 27 |
-
super(pquad_public_Config, self).__init__(**kwargs)
|
| 28 |
-
class pquad_public(datasets.GeneratorBasedBuilder):
|
| 29 |
-
BUILDER_CONFIGS = [
|
| 30 |
-
pquad_public_Config(name="pquad_public", version=datasets.Version("1.0.0"), description="PQuAD plaint text version 2"),
|
| 31 |
-
]
|
| 32 |
-
def _info(self):
|
| 33 |
-
return datasets.DatasetInfo(
|
| 34 |
-
# This is the description that will appear on the datasets page.
|
| 35 |
-
description=_DESCRIPTION,
|
| 36 |
-
# datasets.features.FeatureConnectors
|
| 37 |
-
features=datasets.Features(
|
| 38 |
-
{
|
| 39 |
-
"id": datasets.Value("string"),
|
| 40 |
-
"title": datasets.Value("string"),
|
| 41 |
-
"context": datasets.Value("string"),
|
| 42 |
-
"question": datasets.Value("string"),
|
| 43 |
-
"answers": datasets.features.Sequence(
|
| 44 |
-
{
|
| 45 |
-
"text": datasets.Value("string"),
|
| 46 |
-
"answer_start": datasets.Value("int32"),
|
| 47 |
-
}
|
| 48 |
-
),
|
| 49 |
-
}
|
| 50 |
-
),
|
| 51 |
-
supervised_keys=None,
|
| 52 |
-
# Homepage of the dataset for documentation
|
| 53 |
-
homepage="https://github.com/vassef/pquad_public/",
|
| 54 |
-
citation=_CITATION,
|
| 55 |
-
)
|
| 56 |
-
def _split_generators(self, dl_manager):
|
| 57 |
-
"""Returns SplitGenerators."""
|
| 58 |
-
# TODO(persian_qa): Downloads the data and defines the splits
|
| 59 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
| 60 |
-
# download and extract URLs
|
| 61 |
-
urls_to_download = _URLS
|
| 62 |
-
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 63 |
-
return [
|
| 64 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 65 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}),
|
| 66 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]})
|
| 67 |
-
]
|
| 68 |
-
def _generate_examples(self, filepath):
|
| 69 |
-
"""Yields examples."""
|
| 70 |
-
# TODO(persian_qa): Yields (key, example) tuples from the dataset
|
| 71 |
-
with open(filepath, encoding="utf-8") as f:
|
| 72 |
-
print(filepath)
|
| 73 |
-
squad = json.load(f)
|
| 74 |
-
for example in squad["data"]:
|
| 75 |
-
title = example.get("title", "").strip()
|
| 76 |
-
for paragraph in example["paragraphs"]:
|
| 77 |
-
context = paragraph["context"].strip()
|
| 78 |
-
for qa in paragraph["qas"]:
|
| 79 |
-
question = qa["question"].strip()
|
| 80 |
-
id_ = qa["id"]
|
| 81 |
-
answer_starts = [answer["answer_start"] for answer in qa["answers"]]
|
| 82 |
-
answers = [answer["text"].strip() for answer in qa["answers"]]
|
| 83 |
-
# Features currently used are "context", "question", and "answers".
|
| 84 |
-
# Others are extracted here for the ease of future expansions.
|
| 85 |
-
yield id_, {
|
| 86 |
-
"title": title,
|
| 87 |
-
"context": context,
|
| 88 |
-
"question": question,
|
| 89 |
-
"id": id_,
|
| 90 |
-
"answers": {
|
| 91 |
-
"answer_start": answer_starts,
|
| 92 |
-
"text": answers,
|
| 93 |
-
},
|
| 94 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|