BorisAlbar
commited on
Commit
·
8993e9b
1
Parent(s):
94f9fd0
Dataset that yield squad_v2 compatible data
Browse files- frenchQA.py +115 -0
frenchQA.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""FrenchQA: One French QA Dataset to rule them all"""
|
2 |
+
|
3 |
+
|
4 |
+
import csv
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
from datasets.tasks import QuestionAnsweringExtractive
|
8 |
+
|
9 |
+
|
10 |
+
# TODO(squad_v2): BibTeX citation
|
11 |
+
_CITATION = """\
|
12 |
+
"""
|
13 |
+
|
14 |
+
_DESCRIPTION = """\
|
15 |
+
One French QA Dataset to rule them all, One French QA Dataset to find them, One French QA Dataset to bring them all, and in the darkness bind them.
|
16 |
+
"""
|
17 |
+
|
18 |
+
_URLS = {
|
19 |
+
"train": "train.csv",
|
20 |
+
"dev": "valid.csv",
|
21 |
+
"test": "test.csv"
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
class FrenchQAConfig(datasets.BuilderConfig):
|
26 |
+
"""BuilderConfig for frenchQA."""
|
27 |
+
|
28 |
+
def __init__(self, **kwargs):
|
29 |
+
"""BuilderConfig for FrenchQA.
|
30 |
+
Args:
|
31 |
+
**kwargs: keyword arguments forwarded to super.
|
32 |
+
"""
|
33 |
+
super(FrenchQAConfig, self).__init__(**kwargs)
|
34 |
+
|
35 |
+
|
36 |
+
class FrenchQA(datasets.GeneratorBasedBuilder):
|
37 |
+
"""TODO(squad_v2): Short description of my dataset."""
|
38 |
+
|
39 |
+
# TODO(squad_v2): Set up version.
|
40 |
+
BUILDER_CONFIGS = [
|
41 |
+
FrenchQAConfig(name="frenchQA", version=datasets.Version("1.0.0"), description="frenchQA"),
|
42 |
+
]
|
43 |
+
|
44 |
+
def _info(self):
|
45 |
+
# TODO(squad_v2): Specifies the datasets.DatasetInfo object
|
46 |
+
return datasets.DatasetInfo(
|
47 |
+
# This is the description that will appear on the datasets page.
|
48 |
+
description=_DESCRIPTION,
|
49 |
+
# datasets.features.FeatureConnectors
|
50 |
+
features=datasets.Features(
|
51 |
+
{
|
52 |
+
"id": datasets.Value("string"),
|
53 |
+
"title": datasets.Value("string"),
|
54 |
+
"context": datasets.Value("string"),
|
55 |
+
"question": datasets.Value("string"),
|
56 |
+
"answers": datasets.features.Sequence(
|
57 |
+
{
|
58 |
+
"text": datasets.Value("string"),
|
59 |
+
"answer_start": datasets.Value("int32"),
|
60 |
+
}
|
61 |
+
),
|
62 |
+
# These are the features of your dataset like images, labels ...
|
63 |
+
}
|
64 |
+
),
|
65 |
+
# If there's a common (input, target) tuple from the features,
|
66 |
+
# specify them here. They'll be used if as_supervised=True in
|
67 |
+
# builder.as_dataset.
|
68 |
+
supervised_keys=None,
|
69 |
+
# Homepage of the dataset for documentation
|
70 |
+
homepage="",
|
71 |
+
citation=_CITATION,
|
72 |
+
task_templates=[
|
73 |
+
QuestionAnsweringExtractive(
|
74 |
+
question_column="question", context_column="context", answers_column="answers"
|
75 |
+
)
|
76 |
+
],
|
77 |
+
)
|
78 |
+
|
79 |
+
def _split_generators(self, dl_manager):
|
80 |
+
"""Returns SplitGenerators."""
|
81 |
+
# TODO(squad_v2): Downloads the data and defines the splits
|
82 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to
|
83 |
+
# download and extract URLs
|
84 |
+
urls_to_download = _URLS
|
85 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
86 |
+
|
87 |
+
return [
|
88 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
89 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
90 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
91 |
+
]
|
92 |
+
|
93 |
+
def _generate_examples(self, filepath):
|
94 |
+
"""Yields examples."""
|
95 |
+
# TODO(squad_v2): Yields (key, example) tuples from the dataset
|
96 |
+
with open(filepath, encoding="utf-8") as f:
|
97 |
+
squad = csv.DictReader(f, delimiter = ";")
|
98 |
+
for id_, row in enumerate(squad):
|
99 |
+
answer_start = []
|
100 |
+
text = []
|
101 |
+
|
102 |
+
if row["answer_start"] != "-1":
|
103 |
+
answer_start = [row["answer_start"]]
|
104 |
+
text = [row["answer"]]
|
105 |
+
|
106 |
+
yield id_, {
|
107 |
+
"title": row["dataset"],
|
108 |
+
"context": row["context"],
|
109 |
+
"question": row["question"],
|
110 |
+
"id": id_,
|
111 |
+
"answers": {
|
112 |
+
"answer_start": answer_start,
|
113 |
+
"text": text,
|
114 |
+
},
|
115 |
+
}
|