NohTow commited on
Commit
c6f94d3
·
verified ·
1 Parent(s): a53cf3f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +242 -0
README.md CHANGED
@@ -142,3 +142,245 @@ configs:
142
  - split: trivia
143
  path: scores/trivia-*
144
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  - split: trivia
143
  path: scores/trivia-*
144
  ---
145
+
146
+
147
+ ## Overview
148
+
149
+ This dataset is composed of high quality data sources with mined hard negatives. It can be used to train a strong retrieval model by itself but is better used after a large-scale contrastive pre-training, for example using this [dataset](https://huggingface.co/datasets/lightonai/embeddings-pre-training) or its [curated version](https://huggingface.co/datasets/lightonai/mgte-en).
150
+ This dataset has originally been created to follow the nv-retrieve setup, that mines the closest negatives to the query in a dataset and filter false negatives if their bi-encoder similarity is higher than a percentage of the query-positive similarity score.
151
+ To allow the exploration of various threshold and sampling methods, we decided, as for our pre-training datasets, to be the least destructive possible. Thus, instead of giving the final filtered samples given a method/threshold, we share all of the data, including all the (2048) mined negatives alongside their scores so anyone can apply their own strategy before training easily.
152
+ The mined datasets are FiQa, NaturalQuestion, HotpotQA, MSMARCO, FEVER, SquadV2 and TriviaQA, for a total of 1.88M queries with 2048 mined negatives and their scores, alongside the positive. The model used for mining is [gte-modernbert](https://huggingface.co/Alibaba-NLP/gte-modernbert-base)
153
+
154
+ For more information, please refer to our [blogpost.](https://huggingface.co/blog/lightonai/lateon)
155
+
156
+ ## How to use
157
+
158
+ If you want to directly use the data as contrastive data with nv-retrieve filtering in either [sentence-transformers](https://www.sbert.net) or [PyLate](https://lightonai.github.io/pylate/), you can simply map it to the `(query, positive, negative_1, negative_2, ..., negative_n)` like so:
159
+
160
+
161
+
162
+
163
+ <details>
164
+ <summary>
165
+ Python code to cast to contrastive format
166
+ </summary>
167
+
168
+
169
+ ```python
170
+ import datasets
171
+ import os
172
+ class KDToContrastive:
173
+ """Dataset processing class for converting a KD dataset into a contrastive one.
174
+
175
+ Parameters
176
+ ----------
177
+ queries
178
+ Queries dataset.
179
+ documents
180
+ Documents dataset.
181
+ split
182
+ Split to use for the queries and documents datasets. Used only if the queries and documents are of type `datasets.DatasetDict`.
183
+ num_negatives
184
+ Number of negatives to keep.
185
+ nv_threshold
186
+ Threshold for the nv-embed filtering
187
+ """
188
+
189
+ def __init__(
190
+ self,
191
+ queries: datasets.Dataset | datasets.DatasetDict,
192
+ documents: datasets.Dataset | datasets.DatasetDict,
193
+ split: str = "train",
194
+ num_negatives: int = 32,
195
+ nv_threshold: float = 0.95,
196
+ ) -> None:
197
+ if isinstance(queries, datasets.DatasetDict):
198
+ self.queries = queries[split]
199
+ else:
200
+ self.queries = queries
201
+
202
+ if isinstance(documents, datasets.DatasetDict):
203
+ self.documents = documents[split]
204
+ else:
205
+ self.documents = documents
206
+
207
+ self.num_negatives = num_negatives
208
+ self.nv_threshold = nv_threshold
209
+
210
+ self.queries_index = {
211
+ query_id: i for i, query_id in enumerate(iterable=self.queries["query_id"])
212
+ }
213
+
214
+ self.documents_index = {
215
+ document_id: i
216
+ for i, document_id in enumerate(iterable=self.documents["document_id"])
217
+ }
218
+
219
+ def has_enough_negatives(self, example):
220
+ """Check if example has at least 50 valid negatives"""
221
+ scores = example["scores"]
222
+ positive_score = scores[0]
223
+
224
+ count = sum(
225
+ 1 for score in scores[1:] if score < self.nv_threshold * positive_score
226
+ )
227
+ return count >= self.num_negatives
228
+
229
+ def map_to_query_positive_negatives(self, example):
230
+ """
231
+ Maps a scores example to the desired format:
232
+ query, positive, negative_0, negative_1, ..., negative_49
233
+ """
234
+ query_id = example["query_id"]
235
+ document_ids = example["document_ids"]
236
+ scores = example["scores"]
237
+
238
+ # Get query text
239
+ query_text = self.queries[self.queries_index[query_id]]
240
+
241
+ # First document_id is the positive
242
+ positive_id = document_ids[0]
243
+
244
+ positive_text = self.documents[self.documents_index[positive_id]]
245
+ positive_score = scores[0]
246
+
247
+ # Create the row
248
+ row = {"query": query_text, "positive": positive_text}
249
+
250
+ # Add negatives (starting from index 1)
251
+ total_negatives = 0
252
+ for i in range(1, len(document_ids)):
253
+ if scores[i] < self.nv_threshold * positive_score:
254
+ negative_id = document_ids[i]
255
+ row[f"negative_{total_negatives}"] = self.documents[
256
+ self.documents_index[negative_id]
257
+ ]
258
+ total_negatives += 1
259
+ if total_negatives >= self.num_negatives:
260
+ break
261
+
262
+ return row
263
+
264
+
265
+ def load_train_datasets():
266
+ """Load all available splits from raphael data, with caching"""
267
+ cache_dir = "nv_retrieve_99_50_cached"
268
+ os.makedirs(cache_dir, exist_ok=True)
269
+ train_dataset = datasets.DatasetDict()
270
+ splits = ["trivia", "hotpotqa", "nq", "msmarco", "fever", "squadv2", "fiqa"]
271
+
272
+ for split in splits:
273
+ try:
274
+ dataset = datasets.Dataset.load_from_disk(f"{cache_dir}/{split}")
275
+ print("Loaded dataset from disk")
276
+ except FileNotFoundError:
277
+ print("Creating dataset")
278
+ dataset = datasets.load_dataset(
279
+ "lightonai/nv-embed-supervised-distill-dedup",
280
+ name="scores",
281
+ num_proc=144,
282
+ split=split,
283
+ )
284
+ queries = datasets.load_dataset(
285
+ "lightonai/nv-embed-supervised-distill-dedup",
286
+ name="queries",
287
+ num_proc=144,
288
+ split=split,
289
+ )
290
+ documents = datasets.load_dataset(
291
+ "lightonai/nv-embed-supervised-distill-dedup",
292
+ name="documents",
293
+ num_proc=144,
294
+ split=split,
295
+ )
296
+ processor = KDToContrastive(
297
+ queries, documents, num_negatives=50, nv_threshold=0.99
298
+ )
299
+ dataset = dataset.filter(
300
+ processor.has_enough_negatives,
301
+ desc="Filtering examples with <50 negatives",
302
+ ).map(
303
+ processor.map_to_query_positive_negatives,
304
+ remove_columns=dataset.column_names,
305
+ desc="Creating query-positive-negatives dataset",
306
+ )
307
+ dataset.save_to_disk(f"{cache_dir}/{split}")
308
+
309
+ train_dataset[split] = dataset
310
+ return train_dataset
311
+ ```
312
+ </details>
313
+
314
+
315
+ ## Dataset structure
316
+
317
+ The dataset is composed of 7 high quality datasets, defined by the `splits` parameters.
318
+ Each split contains 3 `subsets`, one containing the queries, one containing the documents and one joining tables also containing the corresponding pairwise query-documents scores.
319
+
320
+ ### Documents
321
+
322
+ | Column | Type | Description |
323
+ |---------------|--------|--------------------------------------------------------------|
324
+ | `document_id` | int64 | Unique identifier of the document within the split. |
325
+ | `document` | string | Raw text of the document/passage. |
326
+
327
+ | Split | Rows |
328
+ |----------|-------:|
329
+ | fiqa | 57.6k |
330
+ | nq | 10.1M |
331
+ | hotpotqa | 5.22M |
332
+ | msmarco | 8.84M |
333
+ | fever | 5.38M |
334
+ | squadv2 | 19k |
335
+ | trivia | 21M |
336
+ | **Total**| **50.64M** |
337
+
338
+ ### Queries
339
+
340
+ | Column | Type | Description |
341
+ |------------|--------|------------------------------------------------------|
342
+ | `query_id` | int64 | Unique identifier of the query within the split. |
343
+ | `query` | string | Raw text of the query. |
344
+
345
+
346
+ | Split | Rows |
347
+ |----------|-------:|
348
+ | fiqa | 5.5k |
349
+ | nq | 307k |
350
+ | hotpotqa | 85k |
351
+ | msmarco | 503k |
352
+ | fever | 110k |
353
+ | squadv2 | 130k |
354
+ | trivia | 78.8k |
355
+ | **Total**| **1.22M** |
356
+
357
+ ### Scores
358
+
359
+
360
+ | Column | Type | Description |
361
+ |----------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
362
+ | `query_id` | int64 | Identifier joining back to the corresponding row in `queries`. |
363
+ | `document_ids` | list[int64] | List of document IDs (joining back to `documents`). The first element is the positive document, followed by the top-2048 mined for the query. |
364
+ | `scores` | list[float] | Relevance scores for each document w.r.t the query. The first element is the positive document, followed by the top-2048 mined for the query. Can be used for nv-retrieve filtering or knowledge distillation. |
365
+
366
+ | Split | Rows |
367
+ |----------|-------:|
368
+ | fiqa | 14.2k |
369
+ | hotpotqa | 170k |
370
+ | nq | 152k |
371
+ | msmarco | 533k |
372
+ | fever | 140k |
373
+ | squadv2 | 130k |
374
+ | trivia | 741k |
375
+ | **Total**| **1.88M** |
376
+
377
+
378
+ ## Citation
379
+ If you are using this dataset, please consider citing our work
380
+ ```bibtex
381
+ @misc{sourty2025denseonlateon,
382
+ title={DenseOn with LateOn: Open State-of-the-Art Single and Multi-Vector Models},
383
+ author={Sourty, Raphael and Chaffin, Antoine and Weller, Orion and Demoura, Paulo and Chatelain, Amelie},
384
+ year={2026},
385
+ howpublished={\url{https://huggingface.co/blog/lightonai/denseon-lateon}},
386
+ }```