hugo commited on
Commit
f0c3bef
1 Parent(s): 5119e67

Initial commit

Browse files
Files changed (1) hide show
  1. boolq.py +88 -0
boolq.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Based on https://huggingface.co/datasets/boolq/blob/main/boolq.py
2
+
3
+ import json
4
+
5
+ import datasets
6
+
7
+
8
+ # TODO(boolq): BibTeX citation
9
+ _CITATION = """\
10
+ @inproceedings{clark2019boolq,
11
+ title = {BoolQ: Exploring the Surprising Difficulty of Natural Yes/No Questions},
12
+ author = {Clark, Christopher and Lee, Kenton and Chang, Ming-Wei, and Kwiatkowski, Tom and Collins, Michael, and Toutanova, Kristina},
13
+ booktitle = {NAACL},
14
+ year = {2019},
15
+ }
16
+ """
17
+
18
+ # TODO(boolq):
19
+ _DESCRIPTION = """\
20
+ BoolQ is a question answering dataset for yes/no questions containing 15942 examples. These questions are naturally
21
+ occurring ---they are generated in unprompted and unconstrained settings.
22
+ Each example is a triplet of (question, passage, answer), with the title of the page as optional additional context.
23
+ The text-pair classification setup is similar to existing natural language inference tasks.
24
+ """
25
+
26
+ _URL = "https://storage.googleapis.com/boolq/"
27
+ _URLS = {
28
+ "train": _URL + "train.jsonl",
29
+ "dev": _URL + "dev.jsonl",
30
+ }
31
+
32
+
33
+ class Boolq(datasets.GeneratorBasedBuilder):
34
+ """TODO(boolq): Short description of my dataset."""
35
+
36
+ # TODO(boolq): Set up version.
37
+ VERSION = datasets.Version("0.1.0")
38
+
39
+ def _info(self):
40
+ # TODO(boolq): Specifies the datasets.DatasetInfo object
41
+ return datasets.DatasetInfo(
42
+ # This is the description that will appear on the datasets page.
43
+ description=_DESCRIPTION,
44
+ # datasets.features.FeatureConnectors
45
+ features=datasets.Features(
46
+ {
47
+ "question": datasets.Value("string"),
48
+ "answer": datasets.Value("bool"),
49
+ "passage": datasets.Value("string")
50
+ # These are the features of your dataset like images, labels ...
51
+ }
52
+ ),
53
+ # If there's a common (input, target) tuple from the features,
54
+ # specify them here. They'll be used if as_supervised=True in
55
+ # builder.as_dataset.
56
+ supervised_keys=None,
57
+ # Homepage of the dataset for documentation
58
+ homepage="https://github.com/google-research-datasets/boolean-questions",
59
+ citation=_CITATION,
60
+ )
61
+
62
+ def _split_generators(self, dl_manager):
63
+ """Returns SplitGenerators."""
64
+ # TODO(boolq): Downloads the data and defines the splits
65
+ # dl_manager is a datasets.download.DownloadManager that can be used to
66
+ # download and extract URLs
67
+ urls_to_download = _URLS
68
+ downloaded_files = dl_manager.download(urls_to_download)
69
+
70
+ return [
71
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
72
+ datasets.SplitGenerator(
73
+ name=datasets.Split.VALIDATION,
74
+ gen_kwargs={"filepath": downloaded_files["dev"]},
75
+ ),
76
+ ]
77
+
78
+ def _generate_examples(self, filepath):
79
+ """Yields examples."""
80
+ # TODO(boolq): Yields (key, example) tuples from the dataset
81
+ with open(filepath, encoding="utf-8") as f:
82
+ for id_, row in enumerate(f):
83
+ data = json.loads(row)
84
+ question = data["question"]
85
+ answer = data["answer"]
86
+ passage = data["passage"]
87
+ title = data["title"]
88
+ yield id_, {"question": question, "answer": answer, "passage": passage, "title": title}