Datasets:
Commit
·
d4b59cd
1
Parent(s):
9f0b37f
Create parashoot.py
Browse files- parashoot.py +134 -0
parashoot.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
from datasets.tasks import QuestionAnsweringExtractive
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
logger = datasets.logging.get_logger(__name__)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
_CITATION = """\
|
| 14 |
+
@inproceedings{keren2021parashoot,
|
| 15 |
+
title={ParaShoot: A Hebrew Question Answering Dataset},
|
| 16 |
+
author={Keren, Omri and Levy, Omer},
|
| 17 |
+
booktitle={Proceedings of the 3rd Workshop on Machine Reading for Question Answering},
|
| 18 |
+
pages={106--112},
|
| 19 |
+
year={2021}
|
| 20 |
+
}
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
_DESCRIPTION = """
|
| 24 |
+
A Hebrew question and answering dataset in the style of SQuAD, based on articles scraped from Wikipedia. The dataset contains a few thousand crowdsource-annotated pairs of questions and answers, in a setting suitable for few-shot learning.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
_URLS = {
|
| 28 |
+
"train": "data/train.tar.gz",
|
| 29 |
+
"validation": "data/dev.tar.gz",
|
| 30 |
+
"test": "data/test.tar.gz",
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class ParashootConfig(datasets.BuilderConfig):
|
| 35 |
+
"""BuilderConfig for Parashoot."""
|
| 36 |
+
|
| 37 |
+
def __init__(self, **kwargs):
|
| 38 |
+
"""BuilderConfig for Parashoot.
|
| 39 |
+
Args:
|
| 40 |
+
**kwargs: keyword arguments forwarded to super.
|
| 41 |
+
"""
|
| 42 |
+
super(ParashootConfig, self).__init__(**kwargs)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Parashoot(datasets.GeneratorBasedBuilder):
|
| 46 |
+
"""Parashoot: The Hebrew Question Answering Dataset. Version 1.1."""
|
| 47 |
+
|
| 48 |
+
BUILDER_CONFIGS = [
|
| 49 |
+
ParashootConfig(
|
| 50 |
+
version=datasets.Version("1.1.0", ""),
|
| 51 |
+
description=_DESCRIPTION,
|
| 52 |
+
),
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
def _info(self):
|
| 56 |
+
return datasets.DatasetInfo(
|
| 57 |
+
description=_DESCRIPTION,
|
| 58 |
+
features=datasets.Features(
|
| 59 |
+
{
|
| 60 |
+
"id": datasets.Value("string"),
|
| 61 |
+
"title": datasets.Value("string"),
|
| 62 |
+
"context": datasets.Value("string"),
|
| 63 |
+
"question": datasets.Value("string"),
|
| 64 |
+
"answers": datasets.features.Sequence(
|
| 65 |
+
{
|
| 66 |
+
"text": datasets.Value("string"),
|
| 67 |
+
"answer_start": datasets.Value("int32"),
|
| 68 |
+
}
|
| 69 |
+
),
|
| 70 |
+
}
|
| 71 |
+
),
|
| 72 |
+
# No default supervised_keys (as we have to pass both question
|
| 73 |
+
# and context as input).
|
| 74 |
+
supervised_keys=None,
|
| 75 |
+
homepage="https://github.com/omrikeren/ParaShoot",
|
| 76 |
+
citation=_CITATION,
|
| 77 |
+
task_templates=[
|
| 78 |
+
QuestionAnsweringExtractive(
|
| 79 |
+
question_column="question",
|
| 80 |
+
context_column="context",
|
| 81 |
+
answers_column="answers",
|
| 82 |
+
)
|
| 83 |
+
],
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
def _split_generators(self, dl_manager):
|
| 87 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
| 88 |
+
|
| 89 |
+
return [
|
| 90 |
+
datasets.SplitGenerator(
|
| 91 |
+
name=datasets.Split.TRAIN,
|
| 92 |
+
gen_kwargs={
|
| 93 |
+
"filepath": downloaded_files["train"],
|
| 94 |
+
"basename": "train.jsonl",
|
| 95 |
+
},
|
| 96 |
+
),
|
| 97 |
+
datasets.SplitGenerator(
|
| 98 |
+
name=datasets.Split.VALIDATION,
|
| 99 |
+
gen_kwargs={
|
| 100 |
+
"filepath": downloaded_files["validation"],
|
| 101 |
+
"basename": "dev.jsonl",
|
| 102 |
+
},
|
| 103 |
+
),
|
| 104 |
+
datasets.SplitGenerator(
|
| 105 |
+
name=datasets.Split.TEST,
|
| 106 |
+
gen_kwargs={
|
| 107 |
+
"filepath": downloaded_files["test"],
|
| 108 |
+
"basename": "test.jsonl",
|
| 109 |
+
},
|
| 110 |
+
),
|
| 111 |
+
]
|
| 112 |
+
|
| 113 |
+
def _generate_examples(self, filepath, basename):
|
| 114 |
+
"""This function returns the examples in the raw (text) form."""
|
| 115 |
+
logger.info("generating examples from = %s", filepath)
|
| 116 |
+
key = 0
|
| 117 |
+
with open(os.path.join(filepath, basename), encoding="utf-8") as f:
|
| 118 |
+
for line in f:
|
| 119 |
+
article = json.loads(line)
|
| 120 |
+
title = article.get("title", "")
|
| 121 |
+
context = article["context"]
|
| 122 |
+
answer_starts = article["answers"]["answer_start"]
|
| 123 |
+
answers = article["answers"]["text"]
|
| 124 |
+
yield key, {
|
| 125 |
+
"title": title,
|
| 126 |
+
"context": context,
|
| 127 |
+
"question": article["question"],
|
| 128 |
+
"id": article["id"],
|
| 129 |
+
"answers": {
|
| 130 |
+
"answer_start": answer_starts,
|
| 131 |
+
"text": answers,
|
| 132 |
+
},
|
| 133 |
+
}
|
| 134 |
+
key += 1
|