Datasets:

Modalities:
Text
Formats:
parquet
Languages:
English
Libraries:
Datasets
Dask
License:
system HF staff commited on
Commit
d4cca19
0 Parent(s):

Update files from the datasets library (from 1.0.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.0.0

Files changed (3) hide show
  1. .gitattributes +27 -0
  2. dataset_infos.json +1 -0
  3. natural_questions.py +201 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"default": {"description": "\nThe NQ corpus contains questions from real users, and it requires QA systems to\nread and comprehend an entire Wikipedia article that may or may not contain the\nanswer to the question. The inclusion of real user questions, and the\nrequirement that solutions should read an entire page to find the answer, cause\nNQ to be a more realistic and challenging task than prior QA datasets.\n", "citation": "\n@article{47761,\ntitle\t= {Natural Questions: a Benchmark for Question Answering Research},\nauthor\t= {Tom Kwiatkowski and Jennimaria Palomaki and Olivia Redfield and Michael Collins and Ankur Parikh and Chris Alberti and Danielle Epstein and Illia Polosukhin and Matthew Kelcey and Jacob Devlin and Kenton Lee and Kristina N. Toutanova and Llion Jones and Ming-Wei Chang and Andrew Dai and Jakob Uszkoreit and Quoc Le and Slav Petrov},\nyear\t= {2019},\njournal\t= {Transactions of the Association of Computational Linguistics}\n}\n", "homepage": "https://ai.google.com/research/NaturalQuestions/dataset", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "document": {"title": {"dtype": "string", "id": null, "_type": "Value"}, "url": {"dtype": "string", "id": null, "_type": "Value"}, "html": {"dtype": "string", "id": null, "_type": "Value"}, "tokens": {"feature": {"token": {"dtype": "string", "id": null, "_type": "Value"}, "is_html": {"dtype": "bool", "id": null, "_type": "Value"}}, "length": -1, "id": null, "_type": "Sequence"}}, "question": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "annotations": {"feature": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "long_answer": {"start_token": {"dtype": "int64", "id": null, "_type": "Value"}, "end_token": {"dtype": "int64", "id": null, "_type": "Value"}, "start_byte": {"dtype": "int64", "id": null, "_type": "Value"}, "end_byte": {"dtype": "int64", "id": null, "_type": "Value"}}, "short_answers": {"feature": {"start_token": {"dtype": "int64", "id": null, "_type": "Value"}, "end_token": {"dtype": "int64", "id": null, "_type": "Value"}, "start_byte": {"dtype": "int64", "id": null, "_type": "Value"}, "end_byte": {"dtype": "int64", "id": null, "_type": "Value"}, "text": {"dtype": "string", "id": null, "_type": "Value"}}, "length": -1, "id": null, "_type": "Sequence"}, "yes_no_answer": {"num_classes": 2, "names": ["NO", "YES"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "length": -1, "id": null, "_type": "Sequence"}}, "supervised_keys": null, "builder_name": "natural_questions", "config_name": "default", "version": {"version_str": "0.0.2", "description": null, "datasets_version_to_prepare": null, "major": 0, "minor": 0, "patch": 2}, "splits": {"train": {"name": "train", "num_bytes": 97445142568, "num_examples": 307373, "dataset_name": "natural_questions"}, "validation": {"name": "validation", "num_bytes": 2353975312, "num_examples": 7830, "dataset_name": "natural_questions"}}, "download_checksums": {"https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-00.jsonl.gz": {"num_bytes": 858728609, "checksum": "fb63ed2a5af2921898d566a4e8e514ed17bd079735f5a37f9b0c5e83ce087106"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-01.jsonl.gz": {"num_bytes": 891498165, "checksum": "bbccdbc261ced6ee6351ede78c8be5af43d1024c72a60070ea658767d4c3023a"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-02.jsonl.gz": {"num_bytes": 885374316, "checksum": "923afd3c645b0bd887f7b6a43c03889936226708ec7a66d83e5e5fa9cee98f4e"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-03.jsonl.gz": {"num_bytes": 885313666, "checksum": "272b2fcdc37cf23ab4bcdf831a84e3b755da066ad4727cdded57a383a18f45de"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-04.jsonl.gz": {"num_bytes": 890873425, "checksum": "8a9eb2dcf818ab7a44c4fa4b73112547e7f250ec85bdf83d2a3f32542fc3e8c2"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-05.jsonl.gz": {"num_bytes": 873023109, "checksum": "2566560a3ad89300552385c3aba0cb51f9968083f01f04c494623542619cdaca"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-06.jsonl.gz": {"num_bytes": 866509301, "checksum": "8ae5491a1d86fea5025e9ec27fed574fe5886fb36a7b3567ab0dba498603728d"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-07.jsonl.gz": {"num_bytes": 838940867, "checksum": "7d1ee955d5a8dee1dc024e7b6a278314c85514f046d40d56ad5f1c2bb1fd794a"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-08.jsonl.gz": {"num_bytes": 902610214, "checksum": "233ab07737289b4122d0fd2d2278dd4d7de3ef44d5b7d7e2e5abb79dbae55541"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-09.jsonl.gz": {"num_bytes": 883494801, "checksum": "a1e546ee7db94117804c41c5fe80af91c78ee5b10878fc2714adb5322f56bb9b"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-10.jsonl.gz": {"num_bytes": 876311133, "checksum": "0d27b7682c4ebc655e18eb9f8dcbb800ae1d5b09ef1183e29faa10168a015724"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-11.jsonl.gz": {"num_bytes": 878127326, "checksum": "9b457cc0d4021da388c1322538b2b2140f0b2439c8eb056b5247c39ecb0de198"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-12.jsonl.gz": {"num_bytes": 889257016, "checksum": "e3078d51686869be12343e1d02ae656577b290355d540870a370c58baeb89bc6"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-13.jsonl.gz": {"num_bytes": 891769129, "checksum": "ff898b89d8423e4b5c9b35996fed80c8e1ddcc5f8a57c9af2a760d408bfa5df4"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-14.jsonl.gz": {"num_bytes": 892523839, "checksum": "7f28f63e565bfa3b9013a62000da6e070c2cdd2aa6f9fc5cfb14365a1a98ab0f"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-15.jsonl.gz": {"num_bytes": 910660095, "checksum": "64db3145b5021e52611f8aedf49bbd0b5f648fef43acc8b1a4481b3dfe96c248"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-16.jsonl.gz": {"num_bytes": 878177689, "checksum": "c12de70e57943288511596b5ebbf5c914a5f99e8fb50d74286274021e8a18fb7"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-17.jsonl.gz": {"num_bytes": 872805189, "checksum": "2beb6c9f24c650c60354b6b513634e1a209cba28c6f204df4e9e2efc8b7ca59e"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-18.jsonl.gz": {"num_bytes": 875275428, "checksum": "2420b73b47cfbb04bca2b1352371dc893879634956b98446bdbde3090556556c"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-19.jsonl.gz": {"num_bytes": 862034169, "checksum": "c514885fc1bff8f4e6291813debbc3a9568b538781eb17e273ac9e88b0b16f80"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-20.jsonl.gz": {"num_bytes": 887586358, "checksum": "59cd4abad74a38265d8e506afd29e3ea498e2f39fe0ee70e9b733810286b3959"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-21.jsonl.gz": {"num_bytes": 890472815, "checksum": "c8d0b1f4cdf78fd658185e92bf1ece16fd16cdde4d27da5221d1a37688ee935e"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-22.jsonl.gz": {"num_bytes": 888396337, "checksum": "6e1ca3851f138e75cc0bab36f5cad83db2e6ae126fac7c6fdc4ce71ad8f410ca"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-23.jsonl.gz": {"num_bytes": 900331594, "checksum": "d34bd25d0b7b8af8aa27b6b9fad8b7febdca6f0c4c1f5779dfc9b4ccbbec6ed2"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-24.jsonl.gz": {"num_bytes": 871216444, "checksum": "40972a44f50c460bcd8fa90a9a0794a2bc169504dc04dbee2a4896c88536f51d"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-25.jsonl.gz": {"num_bytes": 871166814, "checksum": "7028865d9a77d8f0b4b06a1291ff75a488578879ba87e9e679b2d68e8e1accd4"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-26.jsonl.gz": {"num_bytes": 903385811, "checksum": "e4fd4bdc5c63fa1d1310c0ab573601ca87b3809ce1346fc912b398a6bed7f205"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-27.jsonl.gz": {"num_bytes": 842966594, "checksum": "54b8cccea4799351259c3264d077b8df1f291332c0b93f08e66aa78f83a58d18"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-28.jsonl.gz": {"num_bytes": 876393409, "checksum": "a8ee205427dcf3be03759d44de276741f855892d76338ca26a72c76bc07cd3c4"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-29.jsonl.gz": {"num_bytes": 872982425, "checksum": "cb3c96df23bbb9097b61ce1a524c3eb375165404da72d9f0a51eff9744d75643"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-30.jsonl.gz": {"num_bytes": 899739217, "checksum": "e64447543e83b66b725686af6c753f8b08bb6bc9adbe8db36ab31cba11bfcd5b"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-31.jsonl.gz": {"num_bytes": 875703668, "checksum": "7f6195da4b45887d56563924a8741d9db64b4cca32cf50c9d07f8836a761ab09"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-32.jsonl.gz": {"num_bytes": 895840703, "checksum": "5c6574f0f8a157d585bef31fb79a53b1e1b37fdf638b475c92adbb83812b64db"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-33.jsonl.gz": {"num_bytes": 874713497, "checksum": "4d75fd17b0b6ee3133b405b7a90867b0b0b49a51659a5e1eb8bd1d70d0181473"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-34.jsonl.gz": {"num_bytes": 872620262, "checksum": "b70c517e40b7283f10b291f44e6a61a9c9f6dacb9de89ae37e2a7e92a96eec01"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-35.jsonl.gz": {"num_bytes": 854439473, "checksum": "c6e3615fb8753dd3ffe0890a99793847c99b364b50136c8e0430007023bd5506"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-36.jsonl.gz": {"num_bytes": 866233094, "checksum": "dbf6f9227c3558e5195690ace9ec1ccfc84c705eecdd2557d7ead73b88e264ff"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-37.jsonl.gz": {"num_bytes": 894411832, "checksum": "bcbf932a71ef07f0217a2620ec395854c2f200e18829c2f28400e52ad9799aaf"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-38.jsonl.gz": {"num_bytes": 879967719, "checksum": "6518d41f6a205a4551358a154e16e795a40d4d0cd164fa6556f367a7652e3a0d"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-39.jsonl.gz": {"num_bytes": 887056754, "checksum": "f82ba5c7bd19c853e34b2dfdee9c458ef7e9b55f022aed08c3753ebf93034293"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-40.jsonl.gz": {"num_bytes": 873720601, "checksum": "9a6a19e4c408858935bd5456d08e155b9418aa2c1e4fe5ea81d227e57bd6517f"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-41.jsonl.gz": {"num_bytes": 880452966, "checksum": "c3d3ba79c0f6bb718fa58e473dbc70b2064c8168fc59e3b8ef8df2dbea6bfa37"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-42.jsonl.gz": {"num_bytes": 856217171, "checksum": "1d6921d56ff4143e3c189c95e4ab506b70dc569fa4d91f94f9cf29052d253eb6"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-43.jsonl.gz": {"num_bytes": 908184635, "checksum": "595a069528f5988b4808821d1dc81bb8c6dfbd672e69f991bd4004b9e1c02736"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-44.jsonl.gz": {"num_bytes": 891701874, "checksum": "9a290d4d9c9c9507aeec304e1340a3a02e969f17021f02c969aa90b30a970a0d"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-45.jsonl.gz": {"num_bytes": 870559738, "checksum": "40f16e923391fca5f1a30eeacc39ca6c87fc522b9d7b86b7308683ed39c51d5d"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-46.jsonl.gz": {"num_bytes": 883791796, "checksum": "0a5425ac0b9800fb492f0199f358846fd63a10a377a80b7ce784fb715a1d5f90"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-47.jsonl.gz": {"num_bytes": 882109720, "checksum": "65c230069c85c8c74d1ff562c62c443e69e1e93869ecbdb0a2c673faaf4a184e"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-48.jsonl.gz": {"num_bytes": 882241605, "checksum": "df613f0496b7d5f7a49d837b914d1ea80e15c925bb3cf91720ec5b2a25710245"}, "https://storage.googleapis.com/natural_questions/v1.0/train/nq-train-49.jsonl.gz": {"num_bytes": 863247626, "checksum": "ff023c8380d2e9a8c23a1babb24ab6fe2eb5c174f35d74e025bbe0961ea706ec"}, "https://storage.googleapis.com/natural_questions/v1.0/dev/nq-dev-00.jsonl.gz": {"num_bytes": 219593373, "checksum": "78a7f7899aa7d0bc9a29878cdb90daabbeda21a93e3730d8861f20ec736790b2"}, "https://storage.googleapis.com/natural_questions/v1.0/dev/nq-dev-01.jsonl.gz": {"num_bytes": 200209706, "checksum": "9cebaa5eb69cf4ce067079370456b2939d4154a17da88faf73844d8c418cfb9e"}, "https://storage.googleapis.com/natural_questions/v1.0/dev/nq-dev-02.jsonl.gz": {"num_bytes": 210446574, "checksum": "7b82aa74a35025ed91f514ad21e05c4a66cdec56ac1f6b77767a578156ff3bfc"}, "https://storage.googleapis.com/natural_questions/v1.0/dev/nq-dev-03.jsonl.gz": {"num_bytes": 216859801, "checksum": "c7d45bb464bda3da7788c985b07def313ab5bed69bcc258acbe6f0918050bf6e"}, "https://storage.googleapis.com/natural_questions/v1.0/dev/nq-dev-04.jsonl.gz": {"num_bytes": 220929521, "checksum": "00969275e9fb6a5dcc7e20ec9589c23ac00de61c979c8b957f4180b5b9a3043a"}}, "download_size": 45069199013, "dataset_size": 99799117880, "size_in_bytes": 144868316893}}
natural_questions.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Natural Questions: A Benchmark for Question Answering Research."""
18
+
19
+ from __future__ import absolute_import, division, print_function
20
+
21
+ import json
22
+ import re
23
+
24
+ import apache_beam as beam
25
+ import six
26
+
27
+ import datasets
28
+
29
+
30
+ if six.PY2:
31
+ import HTMLParser as html_parser # pylint:disable=g-import-not-at-top
32
+
33
+ html_unescape = html_parser.HTMLParser().unescape
34
+ else:
35
+ import html # pylint:disable=g-import-not-at-top
36
+
37
+ html_unescape = html.unescape
38
+
39
+ _CITATION = """
40
+ @article{47761,
41
+ title = {Natural Questions: a Benchmark for Question Answering Research},
42
+ author = {Tom Kwiatkowski and Jennimaria Palomaki and Olivia Redfield and Michael Collins and Ankur Parikh and Chris Alberti and Danielle Epstein and Illia Polosukhin and Matthew Kelcey and Jacob Devlin and Kenton Lee and Kristina N. Toutanova and Llion Jones and Ming-Wei Chang and Andrew Dai and Jakob Uszkoreit and Quoc Le and Slav Petrov},
43
+ year = {2019},
44
+ journal = {Transactions of the Association of Computational Linguistics}
45
+ }
46
+ """
47
+
48
+ _DESCRIPTION = """
49
+ The NQ corpus contains questions from real users, and it requires QA systems to
50
+ read and comprehend an entire Wikipedia article that may or may not contain the
51
+ answer to the question. The inclusion of real user questions, and the
52
+ requirement that solutions should read an entire page to find the answer, cause
53
+ NQ to be a more realistic and challenging task than prior QA datasets.
54
+ """
55
+
56
+ _URL = "https://ai.google.com/research/NaturalQuestions/dataset"
57
+
58
+ _BASE_DOWNLOAD_URL = "https://storage.googleapis.com/natural_questions/v1.0"
59
+ _DOWNLOAD_URLS = {
60
+ "train": ["%s/train/nq-train-%02d.jsonl.gz" % (_BASE_DOWNLOAD_URL, i) for i in range(50)],
61
+ "validation": ["%s/dev/nq-dev-%02d.jsonl.gz" % (_BASE_DOWNLOAD_URL, i) for i in range(5)],
62
+ }
63
+
64
+
65
+ class NaturalQuestions(datasets.BeamBasedBuilder):
66
+ """Natural Questions: A Benchmark for Question Answering Research."""
67
+
68
+ VERSION = datasets.Version("0.0.2")
69
+ SUPPORTED_VERSIONS = [datasets.Version("0.0.1")]
70
+
71
+ def _info(self):
72
+ return datasets.DatasetInfo(
73
+ description=_DESCRIPTION,
74
+ features=datasets.Features(
75
+ {
76
+ "id": datasets.Value("string"),
77
+ "document": {
78
+ "title": datasets.Value("string"),
79
+ "url": datasets.Value("string"),
80
+ "html": datasets.Value("string"),
81
+ "tokens": datasets.features.Sequence(
82
+ {"token": datasets.Value("string"), "is_html": datasets.Value("bool")}
83
+ ),
84
+ },
85
+ "question": {
86
+ "text": datasets.Value("string"),
87
+ "tokens": datasets.features.Sequence(datasets.Value("string")),
88
+ },
89
+ "annotations": datasets.features.Sequence(
90
+ {
91
+ "id": datasets.Value("string"),
92
+ "long_answer": {
93
+ "start_token": datasets.Value("int64"),
94
+ "end_token": datasets.Value("int64"),
95
+ "start_byte": datasets.Value("int64"),
96
+ "end_byte": datasets.Value("int64"),
97
+ },
98
+ "short_answers": datasets.features.Sequence(
99
+ {
100
+ "start_token": datasets.Value("int64"),
101
+ "end_token": datasets.Value("int64"),
102
+ "start_byte": datasets.Value("int64"),
103
+ "end_byte": datasets.Value("int64"),
104
+ "text": datasets.Value("string"),
105
+ }
106
+ ),
107
+ "yes_no_answer": datasets.features.ClassLabel(
108
+ names=["NO", "YES"]
109
+ ), # Can also be -1 for NONE.
110
+ }
111
+ ),
112
+ }
113
+ ),
114
+ supervised_keys=None,
115
+ homepage=_URL,
116
+ citation=_CITATION,
117
+ )
118
+
119
+ def _split_generators(self, dl_manager, pipeline):
120
+ """Returns SplitGenerators."""
121
+
122
+ files = dl_manager.download(_DOWNLOAD_URLS)
123
+ if not pipeline.is_local():
124
+ files = dl_manager.ship_files_with_pipeline(files, pipeline)
125
+
126
+ return [
127
+ datasets.SplitGenerator(
128
+ name=datasets.Split.TRAIN,
129
+ gen_kwargs={"filepaths": files["train"]},
130
+ ),
131
+ datasets.SplitGenerator(
132
+ name=datasets.Split.VALIDATION,
133
+ gen_kwargs={"filepaths": files["validation"]},
134
+ ),
135
+ ]
136
+
137
+ def _build_pcollection(self, pipeline, filepaths):
138
+ """Build PCollection of examples."""
139
+
140
+ def _parse_example(line):
141
+ """Parse a single json line and emit an example dict."""
142
+ ex_json = json.loads(line)
143
+ html_bytes = ex_json["document_html"].encode("utf-8")
144
+
145
+ def _parse_short_answer(short_ans):
146
+ """"Extract text of short answer."""
147
+ ans_bytes = html_bytes[short_ans["start_byte"] : short_ans["end_byte"]]
148
+ # Remove non-breaking spaces.
149
+ ans_bytes = ans_bytes.replace(b"\xc2\xa0", b" ")
150
+ text = ans_bytes.decode("utf-8")
151
+ # Remove HTML markup.
152
+ text = re.sub("<([^>]*)>", "", html_unescape(text))
153
+ # Replace \xa0 characters with spaces.
154
+ return {
155
+ "start_token": short_ans["start_token"],
156
+ "end_token": short_ans["end_token"],
157
+ "start_byte": short_ans["start_byte"],
158
+ "end_byte": short_ans["end_byte"],
159
+ "text": text,
160
+ }
161
+
162
+ def _parse_annotation(an_json):
163
+ return {
164
+ # Convert to str since some IDs cannot be represented by datasets.Value('int64').
165
+ "id": str(an_json["annotation_id"]),
166
+ "long_answer": {
167
+ "start_token": an_json["long_answer"]["start_token"],
168
+ "end_token": an_json["long_answer"]["end_token"],
169
+ "start_byte": an_json["long_answer"]["start_byte"],
170
+ "end_byte": an_json["long_answer"]["end_byte"],
171
+ },
172
+ "short_answers": [_parse_short_answer(ans) for ans in an_json["short_answers"]],
173
+ "yes_no_answer": (-1 if an_json["yes_no_answer"] == "NONE" else an_json["yes_no_answer"]),
174
+ }
175
+
176
+ beam.metrics.Metrics.counter("nq", "examples").inc()
177
+ # Convert to str since some IDs cannot be represented by datasets.Value('int64').
178
+ id_ = str(ex_json["example_id"])
179
+ return (
180
+ id_,
181
+ {
182
+ "id": id_,
183
+ "document": {
184
+ "title": ex_json["document_title"],
185
+ "url": ex_json["document_url"],
186
+ "html": ex_json["document_html"],
187
+ "tokens": [
188
+ {"token": t["token"], "is_html": t["html_token"]} for t in ex_json["document_tokens"]
189
+ ],
190
+ },
191
+ "question": {"text": ex_json["question_text"], "tokens": ex_json["question_tokens"]},
192
+ "annotations": [_parse_annotation(an_json) for an_json in ex_json["annotations"]],
193
+ },
194
+ )
195
+
196
+ return (
197
+ pipeline
198
+ | beam.Create(filepaths)
199
+ | beam.io.ReadAllFromText(compression_type=beam.io.textio.CompressionTypes.GZIP)
200
+ | beam.Map(_parse_example)
201
+ )