mzasada commited on
Commit
1b3739d
1 Parent(s): ceeb44c

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. poquad-dev.json +0 -0
  3. poquad-train.json +3 -0
  4. poquad_v2.py +137 -0
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ poquad-train.json filter=lfs diff=lfs merge=lfs -text
poquad-dev.json ADDED
The diff for this file is too large to render. See raw diff
 
poquad-train.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1ac3acabb49fedb7bb7db0de0690ddb22585d6419321589cc1bb0a8068a4ff9
3
+ size 47183344
poquad_v2.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FROM SQUAD_V2"""
2
+
3
+
4
+ import json
5
+
6
+ import datasets
7
+ from datasets.tasks import QuestionAnsweringExtractive
8
+
9
+
10
+ # TODO(squad_v2): BibTeX citation
11
+ _CITATION = """\
12
+ Tuora, R., Zawadzka-Paluektau, N., Klamra, C., Zwierzchowska, A., Kobyliński, Ł. (2022).
13
+ Towards a Polish Question Answering Dataset (PoQuAD).
14
+ In: Tseng, YH., Katsurai, M., Nguyen, H.N. (eds) From Born-Physical to Born-Virtual: Augmenting Intelligence in Digital Libraries. ICADL 2022.
15
+ Lecture Notes in Computer Science, vol 13636. Springer, Cham.
16
+ https://doi.org/10.1007/978-3-031-21756-2_16
17
+ """
18
+
19
+ _DESCRIPTION = """\
20
+ PoQuaD description
21
+ """
22
+
23
+
24
+ _URLS = {
25
+ "train": "poquad-train.json",
26
+ "dev": "poquad-dev.json",
27
+ }
28
+
29
+
30
+ class SquadV2Config(datasets.BuilderConfig):
31
+ """BuilderConfig for SQUAD."""
32
+
33
+ def __init__(self, **kwargs):
34
+ """BuilderConfig for SQUADV2.
35
+ Args:
36
+ **kwargs: keyword arguments forwarded to super.
37
+ """
38
+ super(SquadV2Config, self).__init__(**kwargs)
39
+
40
+
41
+ class SquadV2(datasets.GeneratorBasedBuilder):
42
+ """TODO(squad_v2): Short description of my dataset."""
43
+
44
+ # TODO(squad_v2): Set up version.
45
+ BUILDER_CONFIGS = [
46
+ SquadV2Config(name="poquad", version=datasets.Version("1.0.0"), description="PoQuaD plaint text"),
47
+ ]
48
+
49
+ def _info(self):
50
+ # TODO(squad_v2): Specifies the datasets.DatasetInfo object
51
+ return datasets.DatasetInfo(
52
+ # This is the description that will appear on the datasets page.
53
+ description=_DESCRIPTION,
54
+ # datasets.features.FeatureConnectors
55
+ features=datasets.Features(
56
+ {
57
+ "id": datasets.Value("string"),
58
+ "title": datasets.Value("string"),
59
+ "context": datasets.Value("string"),
60
+ "question": datasets.Value("string"),
61
+ # "is_impossible": datasets.Value("bool"),
62
+ "answers": datasets.features.Sequence(
63
+ {
64
+ "text": datasets.Value("string"),
65
+ "answer_start": datasets.Value("int32"),
66
+ # "generative_answer": datasets.Value("string"),
67
+ }
68
+ ),
69
+ # These are the features of your dataset like images, labels ...
70
+ }
71
+ ),
72
+ # If there's a common (input, target) tuple from the features,
73
+ # specify them here. They'll be used if as_supervised=True in
74
+ # builder.as_dataset.
75
+ supervised_keys=None,
76
+ # Homepage of the dataset for documentation
77
+ homepage="https://rajpurkar.github.io/SQuAD-explorer/",
78
+ citation=_CITATION,
79
+ task_templates=[
80
+ QuestionAnsweringExtractive(
81
+ question_column="question", context_column="context", answers_column="answers"
82
+ )
83
+ ],
84
+ )
85
+
86
+ def _split_generators(self, dl_manager):
87
+ """Returns SplitGenerators."""
88
+ # TODO(squad_v2): Downloads the data and defines the splits
89
+ # dl_manager is a datasets.download.DownloadManager that can be used to
90
+ # download and extract URLs
91
+ urls_to_download = _URLS
92
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
93
+
94
+ return [
95
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
96
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
97
+ ]
98
+
99
+ def _generate_examples(self, filepath):
100
+ """Yields examples."""
101
+ # TODO(squad_v2): Yields (key, example) tuples from the dataset
102
+ with open(filepath, encoding="utf-8") as f:
103
+ squad = json.load(f)
104
+ id_ = 0
105
+ for example in squad["data"]:
106
+ title = example.get("title", "")
107
+ # paragraph_id = example["id"]
108
+ for paragraph in example["paragraphs"]:
109
+ context = paragraph["context"] # do not strip leading blank spaces GH-2585
110
+ for qa in paragraph["qas"]:
111
+ question = qa["question"]
112
+ is_impossible = qa["is_impossible"]
113
+
114
+ answers = []
115
+ answer_starts = []
116
+ generative_answers = []
117
+
118
+ check_ans = "answers"
119
+ if is_impossible is False:
120
+ answer_starts = [answer["answer_start"] for answer in qa[check_ans]]
121
+ answers = [answer["text"] for answer in qa[check_ans]]
122
+ generative_answers = [answer["generative_answer"] for answer in qa[check_ans]]
123
+ id_ += 1
124
+ yield str(id_), {
125
+ "id": str(id_),
126
+ "title": title,
127
+ "context": context,
128
+ "question": question,
129
+ #"is_impossible" : is_impossible,
130
+ # "paragraph_id": paragraph_id,
131
+ "answers": {
132
+ "answer_start": answer_starts,
133
+ #"answer_end": answer_ends,
134
+ "text": answers,
135
+ #"generative_answer": generative_answers,
136
+ },
137
+ }