File size: 7,143 Bytes
84ab954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bacdae8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ab954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bacdae8
 
be6e04e
84ab954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bacdae8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ab954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
license: cc-by-sa-3.0
language:
- en
task_categories:
- text-retrieval
- question-answering
size_categories:
- 100K<n<1M
source_datasets:
- extended|natural_questions
tags:
- generative-retrieval
- dsi
- nci
- ripor
- semantic-id
configs:
- config_name: corpus
  data_files:
  - split: corpus
    path: data/corpus.jsonl
- config_name: pairs
  data_files:
  - split: train
    path: data/train.jsonl
  - split: validation
    path: data/valid.jsonl
dataset_info:
- config_name: corpus
  features:
  - name: docid
    dtype: int64
  - name: document
    dtype: string
  splits:
  - name: corpus
    num_examples: 109650
- config_name: pairs
  features:
  - name: query
    dtype: string
  - name: docid
    dtype: int64
  - name: nq_id
    dtype: string             # IMPORTANT: string, not int – uint64 IDs overflow signed int64
  - name: url
    dtype: string
  - name: title
    dtype: string
  - name: long_answer
    dtype: string
  - name: short_answer
    dtype: string
  splits:
  - name: train
    num_examples: 307373
  - name: validation
    num_examples: 7830
---

# NQ320K (NCI-style preprocessing)

A reproduction of the **NQ320K** corpus used by generative-retrieval papers
(DSI, NCI, GenRet, RIPOR, Ultron, LTRGR, …) built directly from the
Hugging Face `google-research-datasets/natural_questions` snapshot.

## At a glance

| Split            | Rows         |
|------------------|--------------|
| `corpus`         | 109,650 |
| `train` pairs    | 307,373  |
| `validation` pairs | 7,830 |

* Train pairs with non-empty `long_answer`:  **152,148 / 307,373** (49.5%)
* Train pairs with non-empty `short_answer`: **106,926 / 307,373** (34.8%)
* Date built: 2026-05-06

## Schema

### `corpus.jsonl`

```json
{"docid": 0, "document": "<NCI doc_tac string, ~5K-50K chars>"}
```

### `train.jsonl` / `valid.jsonl`

```json
{
  "query": "when is the last episode of season 8 of the walking dead",
  "docid": 0,
  "nq_id": "5225754983651766092",
  "url": "https://en.wikipedia.org//w/index.php?title=The_Walking_Dead_(season_8)&oldid=...",
  "title": "The Walking Dead (season 8)",
  "long_answer": "List of The Walking Dead episodes ...",
  "short_answer": ""
}
```

`docid` is a stable integer that **joins** to `corpus.jsonl`. To materialise
a (query, document) pair:

```python
from datasets import load_dataset
corpus = load_dataset("<your-username>/NQ320K-NCI", "corpus", split="corpus")
pairs  = load_dataset("<your-username>/NQ320K-NCI", "pairs",  split="train")

doc_lookup = {r["docid"]: r["document"] for r in corpus}
for p in pairs:
    document = doc_lookup[p["docid"]]
    # ... feed (p["query"], document) to your model
```

## Preprocessing

Faithful port of the official NCI notebook
([Wang et al., NeurIPS 2022](https://arxiv.org/abs/2206.02743),
[Data_process/NQ_dataset/NQ_dataset_Process.ipynb](https://github.com/solidsea98/Neural-Corpus-Indexer-NCI/blob/main/Data_process/NQ_dataset/NQ_dataset_Process.ipynb)
in the released code). Each NQ row produces one record:

1. Reconstruct `document_text = " ".join(document.tokens.token)`
   (HTML tags appear as their own tokens).
2. `title  = document.title`
3. `abs    = document_text[<P>+3 : </P>]`**HTML tags inside `<P>` are kept**, matching NCI.
4. `content = document_text[</P>+4 : second-to-last </Ul>]`,
   then HTML stripped, `\n` deleted, multiple spaces collapsed.
5. `doc_tac = title + abs + content`**no separators**.
6. `long_answer` / `short_answer`: token-span slices from the
   first annotator (`annotations[0]`), HTML stripped.

Documents are de-duplicated by their **BERT-uncased-tokenizer-normalised
title** (`tokenizer.tokenize(title) → convert_to_ids → decode`), exactly as
in NCI's released notebook. Concatenating `train + validation` and dropping
duplicates yields **109,650** unique documents (NCI reports 109,739; the
~80-doc delta comes from a slightly newer Hugging Face snapshot of NQ).

## Known formatting characteristics

These are **inherited from NCI's preprocessing** and intentional:

* **Token-joined whitespace**: `"AMC ,"` instead of `"AMC,"`. NCI's `doc_tac`
  is built by `" ".join(tokens)`, leaving a space before every punctuation
  mark. NCI's downstream BERT/T5 tokenizer absorbs these correctly; you may
  want to detokenize when feeding into other encoders.
* **HTML tags inside `abs`**: e.g. `"<Table><Tr>…<P>The eighth season…</P>"`.
  Only `content` has its tags stripped. This is the canonical NCI format.
* **Non-detokenized hyphenation**: `"post - apocalyptic"`, `"Spider - Man"`.

## Caveat: `nq_id` is a string

NQ's original `example_id` is a **uint64**, and roughly half of the IDs
exceed `2^63 = 9.22 × 10^18`. They fit unsigned but overflow signed int64.

`nq_id` is therefore stored as a **string**, exactly as Google publishes it.
**Do not auto-cast it to int64** — about 50% of the values would silently
wrap to negative numbers. If you load with pandas:

```python
import pandas as pd
df = pd.read_json("train.jsonl", lines=True, dtype={"nq_id": str})
```

If you load with `datasets`, the typed `dataset_info` in this card already
enforces `string`, so you don't need to do anything extra:

```python
from datasets import load_dataset
ds = load_dataset("<your-username>/NQ320K-NCI", "pairs")
print(ds["train"].features["nq_id"])  # Value(dtype='string', id=None)
```

## License & attribution

This dataset is a derivative of the Natural Questions dataset by Google
([Kwiatkowski et al., TACL 2019](https://aclanthology.org/Q19-1026/)),
released under **CC BY-SA 3.0**. This derivative dataset is therefore also
released under **CC BY-SA 3.0** (ShareAlike).

The preprocessing recipe is from
[Neural Corpus Indexer (Wang et al., NeurIPS 2022)](https://arxiv.org/abs/2206.02743);
see their released
[notebook](https://github.com/solidsea98/Neural-Corpus-Indexer-NCI/blob/main/Data_process/NQ_dataset/NQ_dataset_Process.ipynb).

## Citation

If you use this dataset, please cite:

```bibtex
@article{kwiatkowski2019natural,
  author    = {Kwiatkowski, Tom and Palomaki, Jennimaria and Redfield, Olivia
               and Collins, Michael and Parikh, Ankur and Alberti, Chris and
               Epstein, Danielle and Polosukhin, Illia and Devlin, Jacob and
               Lee, Kenton and Toutanova, Kristina and Jones, Llion and Kelcey,
               Matthew and Chang, Ming-Wei and Dai, Andrew and Uszkoreit, Jakob
               and Le, Quoc and Petrov, Slav},
  title     = {Natural Questions: a Benchmark for Question Answering Research},
  journal   = {Transactions of the Association for Computational Linguistics},
  year      = {2019}
}

@inproceedings{wang2022neural,
  author    = {Wang, Yujing and Hou, Yingyan and Wang, Haonan and Miao, Ziming
               and Wu, Shibin and Sun, Hao and Chen, Qi and Xia, Yuqing and
               Chi, Chengmin and Zhao, Guoshuai and Liu, Zheng and Xie, Xing
               and Sun, Hao Allen and Deng, Weiwei and Zhang, Qi and Yang,
               Mao},
  title     = {A Neural Corpus Indexer for Document Retrieval},
  booktitle = {Advances in Neural Information Processing Systems (NeurIPS)},
  year      = {2022}
}
```