vesteinn commited on
Commit
d9ccd26
1 Parent(s): b8336f2

Initial commit

Browse files
Files changed (2) hide show
  1. README.md +24 -0
  2. icelandic-qa-NQiI.py +118 -0
README.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: NQiI
3
+ annotations_creators:
4
+ - curated
5
+ language_creators:
6
+ - curated
7
+ languages:
8
+ - is
9
+ licenses:
10
+ - cc-by-sa-4.0
11
+ multilinguality:
12
+ - monolingual
13
+ source_datasets:
14
+ - original
15
+ task_categories:
16
+ - question-answering
17
+ task_ids:
18
+ - open-domain-qa
19
+ - extractive-qa
20
+ paperswithcode_id: nqii
21
+ ---
22
+
23
+ # Natural Questions in Icelandic
24
+
icelandic-qa-NQiI.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adapted from the SQuAD dataset file
2
+
3
+ import json
4
+
5
+ import datasets
6
+ from datasets.tasks import QuestionAnsweringExtractive
7
+
8
+
9
+ _CITATION = """\
10
+ """
11
+
12
+ _DESCRIPTION = """\
13
+ """
14
+
15
+ _URL = "https://repository.clarin.is/repository/xmlui/bitstream/handle/20.500.12537/143/"
16
+ _URLS = {
17
+ "train": _URL + "nqii_train_squad_format_tok.json",
18
+ "dev": _URL + "nqii_dev_squad_format_tok.json",
19
+ "test": _URL + "nqii_test_squad_format_tok.json"
20
+ }
21
+
22
+
23
+ class NQiIConfig(datasets.BuilderConfig):
24
+ """BuilderConfig."""
25
+
26
+ def __init__(self, **kwargs):
27
+ """BuilderConfig.
28
+
29
+ Args:
30
+ **kwargs: keyword arguments forwarded to super.
31
+ """
32
+ super(NQiIConfig, self).__init__(**kwargs)
33
+
34
+
35
+ class NQiI(datasets.GeneratorBasedBuilder):
36
+
37
+ BUILDER_CONFIGS = [
38
+ NQiIConfig(name="icelandic-qa-NQiI", version=datasets.Version("1.0.0"), description=""),
39
+ ]
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ # This is the description that will appear on the datasets page.
44
+ description=_DESCRIPTION,
45
+ # datasets.features.FeatureConnectors
46
+ features=datasets.Features(
47
+ {
48
+ "id": datasets.Value("string"),
49
+ "title": datasets.Value("string"),
50
+ "context": datasets.Value("string"),
51
+ "question": datasets.Value("string"),
52
+ "answers": datasets.features.Sequence(
53
+ {
54
+ "text": datasets.Value("string"),
55
+ "answer_start": datasets.Value("int32"),
56
+ }
57
+ ),
58
+ # These are the features of your dataset like images, labels ...
59
+ }
60
+ ),
61
+ # If there's a common (input, target) tuple from the features,
62
+ # specify them here. They'll be used if as_supervised=True in
63
+ # builder.as_dataset.
64
+ supervised_keys=None,
65
+ # Homepage of the dataset for documentation
66
+ homepage="https://vesteinn.is/qa/",
67
+ citation=_CITATION,
68
+ task_templates=[
69
+ QuestionAnsweringExtractive(
70
+ question_column="question", context_column="context", answers_column="answers"
71
+ )
72
+ ],
73
+ )
74
+
75
+ def _split_generators(self, dl_manager):
76
+ """Returns SplitGenerators."""
77
+ # TODO(squad_v2): Downloads the data and defines the splits
78
+ # dl_manager is a datasets.download.DownloadManager that can be used to
79
+ # download and extract URLs
80
+ urls_to_download = _URLS
81
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
82
+
83
+ return [
84
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
85
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
86
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
87
+
88
+ ]
89
+
90
+ def _generate_examples(self, filepath):
91
+ """Yields examples."""
92
+ # TODO(squad_v2): Yields (key, example) tuples from the dataset
93
+ with open(filepath, encoding="utf-8") as f:
94
+ squad = json.load(f)
95
+ for example in squad["data"]:
96
+ title = example.get("title", "")
97
+ for paragraph in example["paragraphs"]:
98
+ context = paragraph["context"] # do not strip leading blank spaces GH-2585
99
+ for qa in paragraph["qas"]:
100
+ question = qa["question"]
101
+ id_ = qa["id"]
102
+
103
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
104
+ answers = [answer["text"] for answer in qa["answers"]]
105
+
106
+ # Features currently used are "context", "question", and "answers".
107
+ # Others are extracted here for the ease of future expansions.
108
+ yield id_, {
109
+ "title": title,
110
+ "context": context,
111
+ "question": question,
112
+ "id": id_,
113
+ "answers": {
114
+ "answer_start": answer_starts,
115
+ "text": answers,
116
+ },
117
+ }
118
+