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ARDRetrieval
|
| 13 |
+
config: default
|
| 14 |
+
split: test
|
| 15 |
+
revision: 8c492add6a14ac188f2debdaf6cbdfb406fd6be3
|
| 16 |
+
metrics:
|
| 17 |
+
- type: recall_at_100
|
| 18 |
+
value: 0.0
|
| 19 |
+
name: recall_at_100
|
| 20 |
+
source:
|
| 21 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 22 |
+
name: MTEB
|
| 23 |
+
- task:
|
| 24 |
+
type: translation
|
| 25 |
+
name: BitextMining
|
| 26 |
+
dataset:
|
| 27 |
+
name: BornholmBitextMining (default)
|
| 28 |
+
type: mteb/BornholmBitextMining
|
| 29 |
+
config: default
|
| 30 |
+
split: test
|
| 31 |
+
revision: 5b02048bd75e79275aa91a1fce6cdfd3f4a391cb
|
| 32 |
+
metrics:
|
| 33 |
+
- type: f1
|
| 34 |
+
value: 0.2968132161955691
|
| 35 |
+
name: f1
|
| 36 |
+
source:
|
| 37 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 38 |
+
name: MTEB
|
| 39 |
+
- task:
|
| 40 |
+
type: sentence-similarity
|
| 41 |
+
name: STS
|
| 42 |
+
dataset:
|
| 43 |
+
name: STS22 (ar)
|
| 44 |
+
type: mteb/sts22-crosslingual-sts
|
| 45 |
+
config: ar
|
| 46 |
+
split: test
|
| 47 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 48 |
+
metrics:
|
| 49 |
+
- type: cosine_spearman
|
| 50 |
+
value: 0.2263866797712348
|
| 51 |
+
name: cosine_spearman
|
| 52 |
+
source:
|
| 53 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 54 |
+
name: MTEB
|
| 55 |
+
- task:
|
| 56 |
+
type: sentence-similarity
|
| 57 |
+
name: STS
|
| 58 |
+
dataset:
|
| 59 |
+
name: STS22 (de)
|
| 60 |
+
type: mteb/sts22-crosslingual-sts
|
| 61 |
+
config: de
|
| 62 |
+
split: test
|
| 63 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 64 |
+
metrics:
|
| 65 |
+
- type: cosine_spearman
|
| 66 |
+
value: 0.31044353994772356
|
| 67 |
+
name: cosine_spearman
|
| 68 |
+
source:
|
| 69 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 70 |
+
name: MTEB
|
| 71 |
+
- task:
|
| 72 |
+
type: sentence-similarity
|
| 73 |
+
name: STS
|
| 74 |
+
dataset:
|
| 75 |
+
name: STS22 (de-en)
|
| 76 |
+
type: mteb/sts22-crosslingual-sts
|
| 77 |
+
config: de-en
|
| 78 |
+
split: test
|
| 79 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 80 |
+
metrics:
|
| 81 |
+
- type: cosine_spearman
|
| 82 |
+
value: 0.44038685024247604
|
| 83 |
+
name: cosine_spearman
|
| 84 |
+
source:
|
| 85 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 86 |
+
name: MTEB
|
| 87 |
+
- task:
|
| 88 |
+
type: sentence-similarity
|
| 89 |
+
name: STS
|
| 90 |
+
dataset:
|
| 91 |
+
name: STS22 (de-fr)
|
| 92 |
+
type: mteb/sts22-crosslingual-sts
|
| 93 |
+
config: de-fr
|
| 94 |
+
split: test
|
| 95 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 96 |
+
metrics:
|
| 97 |
+
- type: cosine_spearman
|
| 98 |
+
value: 0.3006758748207823
|
| 99 |
+
name: cosine_spearman
|
| 100 |
+
source:
|
| 101 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 102 |
+
name: MTEB
|
| 103 |
+
- task:
|
| 104 |
+
type: sentence-similarity
|
| 105 |
+
name: STS
|
| 106 |
+
dataset:
|
| 107 |
+
name: STS22 (de-pl)
|
| 108 |
+
type: mteb/sts22-crosslingual-sts
|
| 109 |
+
config: de-pl
|
| 110 |
+
split: test
|
| 111 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 112 |
+
metrics:
|
| 113 |
+
- type: cosine_spearman
|
| 114 |
+
value: 0.04927056559940413
|
| 115 |
+
name: cosine_spearman
|
| 116 |
+
source:
|
| 117 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 118 |
+
name: MTEB
|
| 119 |
+
- task:
|
| 120 |
+
type: sentence-similarity
|
| 121 |
+
name: STS
|
| 122 |
+
dataset:
|
| 123 |
+
name: STS22 (en)
|
| 124 |
+
type: mteb/sts22-crosslingual-sts
|
| 125 |
+
config: en
|
| 126 |
+
split: test
|
| 127 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 128 |
+
metrics:
|
| 129 |
+
- type: cosine_spearman
|
| 130 |
+
value: 0.6721465212910986
|
| 131 |
+
name: cosine_spearman
|
| 132 |
+
source:
|
| 133 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 134 |
+
name: MTEB
|
| 135 |
+
- task:
|
| 136 |
+
type: sentence-similarity
|
| 137 |
+
name: STS
|
| 138 |
+
dataset:
|
| 139 |
+
name: STS22 (es)
|
| 140 |
+
type: mteb/sts22-crosslingual-sts
|
| 141 |
+
config: es
|
| 142 |
+
split: test
|
| 143 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 144 |
+
metrics:
|
| 145 |
+
- type: cosine_spearman
|
| 146 |
+
value: 0.5477772552456677
|
| 147 |
+
name: cosine_spearman
|
| 148 |
+
source:
|
| 149 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 150 |
+
name: MTEB
|
| 151 |
+
- task:
|
| 152 |
+
type: sentence-similarity
|
| 153 |
+
name: STS
|
| 154 |
+
dataset:
|
| 155 |
+
name: STS22 (es-en)
|
| 156 |
+
type: mteb/sts22-crosslingual-sts
|
| 157 |
+
config: es-en
|
| 158 |
+
split: test
|
| 159 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 160 |
+
metrics:
|
| 161 |
+
- type: cosine_spearman
|
| 162 |
+
value: 0.5341895837272506
|
| 163 |
+
name: cosine_spearman
|
| 164 |
+
source:
|
| 165 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 166 |
+
name: MTEB
|
| 167 |
+
- task:
|
| 168 |
+
type: sentence-similarity
|
| 169 |
+
name: STS
|
| 170 |
+
dataset:
|
| 171 |
+
name: STS22 (es-it)
|
| 172 |
+
type: mteb/sts22-crosslingual-sts
|
| 173 |
+
config: es-it
|
| 174 |
+
split: test
|
| 175 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 176 |
+
metrics:
|
| 177 |
+
- type: cosine_spearman
|
| 178 |
+
value: 0.44269936659450304
|
| 179 |
+
name: cosine_spearman
|
| 180 |
+
source:
|
| 181 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 182 |
+
name: MTEB
|
| 183 |
+
- task:
|
| 184 |
+
type: sentence-similarity
|
| 185 |
+
name: STS
|
| 186 |
+
dataset:
|
| 187 |
+
name: STS22 (fr)
|
| 188 |
+
type: mteb/sts22-crosslingual-sts
|
| 189 |
+
config: fr
|
| 190 |
+
split: test
|
| 191 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 192 |
+
metrics:
|
| 193 |
+
- type: cosine_spearman
|
| 194 |
+
value: 0.7700398643056744
|
| 195 |
+
name: cosine_spearman
|
| 196 |
+
source:
|
| 197 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 198 |
+
name: MTEB
|
| 199 |
+
- task:
|
| 200 |
+
type: sentence-similarity
|
| 201 |
+
name: STS
|
| 202 |
+
dataset:
|
| 203 |
+
name: STS22 (fr-pl)
|
| 204 |
+
type: mteb/sts22-crosslingual-sts
|
| 205 |
+
config: fr-pl
|
| 206 |
+
split: test
|
| 207 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 208 |
+
metrics:
|
| 209 |
+
- type: cosine_spearman
|
| 210 |
+
value: 0.50709255283711
|
| 211 |
+
name: cosine_spearman
|
| 212 |
+
source:
|
| 213 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 214 |
+
name: MTEB
|
| 215 |
+
- task:
|
| 216 |
+
type: sentence-similarity
|
| 217 |
+
name: STS
|
| 218 |
+
dataset:
|
| 219 |
+
name: STS22 (it)
|
| 220 |
+
type: mteb/sts22-crosslingual-sts
|
| 221 |
+
config: it
|
| 222 |
+
split: test
|
| 223 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 224 |
+
metrics:
|
| 225 |
+
- type: cosine_spearman
|
| 226 |
+
value: 0.6039610834515271
|
| 227 |
+
name: cosine_spearman
|
| 228 |
+
source:
|
| 229 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 230 |
+
name: MTEB
|
| 231 |
+
- task:
|
| 232 |
+
type: sentence-similarity
|
| 233 |
+
name: STS
|
| 234 |
+
dataset:
|
| 235 |
+
name: STS22 (pl)
|
| 236 |
+
type: mteb/sts22-crosslingual-sts
|
| 237 |
+
config: pl
|
| 238 |
+
split: test
|
| 239 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 240 |
+
metrics:
|
| 241 |
+
- type: cosine_spearman
|
| 242 |
+
value: 0.26768906191975933
|
| 243 |
+
name: cosine_spearman
|
| 244 |
+
source:
|
| 245 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 246 |
+
name: MTEB
|
| 247 |
+
- task:
|
| 248 |
+
type: sentence-similarity
|
| 249 |
+
name: STS
|
| 250 |
+
dataset:
|
| 251 |
+
name: STS22 (pl-en)
|
| 252 |
+
type: mteb/sts22-crosslingual-sts
|
| 253 |
+
config: pl-en
|
| 254 |
+
split: test
|
| 255 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 256 |
+
metrics:
|
| 257 |
+
- type: cosine_spearman
|
| 258 |
+
value: 0.32797912957778136
|
| 259 |
+
name: cosine_spearman
|
| 260 |
+
source:
|
| 261 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 262 |
+
name: MTEB
|
| 263 |
+
- task:
|
| 264 |
+
type: sentence-similarity
|
| 265 |
+
name: STS
|
| 266 |
+
dataset:
|
| 267 |
+
name: STS22 (ru)
|
| 268 |
+
type: mteb/sts22-crosslingual-sts
|
| 269 |
+
config: ru
|
| 270 |
+
split: test
|
| 271 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 272 |
+
metrics:
|
| 273 |
+
- type: cosine_spearman
|
| 274 |
+
value: 0.14721380413194854
|
| 275 |
+
name: cosine_spearman
|
| 276 |
+
source:
|
| 277 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 278 |
+
name: MTEB
|
| 279 |
+
- task:
|
| 280 |
+
type: sentence-similarity
|
| 281 |
+
name: STS
|
| 282 |
+
dataset:
|
| 283 |
+
name: STS22 (tr)
|
| 284 |
+
type: mteb/sts22-crosslingual-sts
|
| 285 |
+
config: tr
|
| 286 |
+
split: test
|
| 287 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 288 |
+
metrics:
|
| 289 |
+
- type: cosine_spearman
|
| 290 |
+
value: 0.3369451080773859
|
| 291 |
+
name: cosine_spearman
|
| 292 |
+
source:
|
| 293 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 294 |
+
name: MTEB
|
| 295 |
+
- task:
|
| 296 |
+
type: sentence-similarity
|
| 297 |
+
name: STS
|
| 298 |
+
dataset:
|
| 299 |
+
name: STS22 (zh)
|
| 300 |
+
type: mteb/sts22-crosslingual-sts
|
| 301 |
+
config: zh
|
| 302 |
+
split: test
|
| 303 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 304 |
+
metrics:
|
| 305 |
+
- type: cosine_spearman
|
| 306 |
+
value: 0.4492964024177277
|
| 307 |
+
name: cosine_spearman
|
| 308 |
+
source:
|
| 309 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 310 |
+
name: MTEB
|
| 311 |
+
- task:
|
| 312 |
+
type: sentence-similarity
|
| 313 |
+
name: STS
|
| 314 |
+
dataset:
|
| 315 |
+
name: STS22 (zh-en)
|
| 316 |
+
type: mteb/sts22-crosslingual-sts
|
| 317 |
+
config: zh-en
|
| 318 |
+
split: test
|
| 319 |
+
revision: de9d86b3b84231dc21f76c7b7af1f28e2f57f6e3
|
| 320 |
+
metrics:
|
| 321 |
+
- type: cosine_spearman
|
| 322 |
+
value: 0.41643997417444484
|
| 323 |
+
name: cosine_spearman
|
| 324 |
+
source:
|
| 325 |
+
url: https://github.com/embeddings-benchmark/mteb/
|
| 326 |
+
name: MTEB
|
| 327 |
+
---
|
| 328 |
+
# all-MiniLM-L6-v2
|
| 329 |
+
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
| 330 |
+
|
| 331 |
+
## Usage (Sentence-Transformers)
|
| 332 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
| 333 |
+
|
| 334 |
+
```
|
| 335 |
+
pip install -U sentence-transformers
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
Then you can use the model like this:
|
| 339 |
+
```python
|
| 340 |
+
from sentence_transformers import SentenceTransformer
|
| 341 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
| 342 |
+
|
| 343 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 344 |
+
embeddings = model.encode(sentences)
|
| 345 |
+
print(embeddings)
|
| 346 |
+
```
|
| 347 |
+
|
| 348 |
+
## Usage (HuggingFace Transformers)
|
| 349 |
+
Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
|
| 350 |
+
|
| 351 |
+
```python
|
| 352 |
+
from transformers import AutoTokenizer, AutoModel
|
| 353 |
+
import torch
|
| 354 |
+
import torch.nn.functional as F
|
| 355 |
+
|
| 356 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
| 357 |
+
def mean_pooling(model_output, attention_mask):
|
| 358 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
| 359 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
| 360 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
# Sentences we want sentence embeddings for
|
| 364 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
| 365 |
+
|
| 366 |
+
# Load model from HuggingFace Hub
|
| 367 |
+
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
| 368 |
+
model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
| 369 |
+
|
| 370 |
+
# Tokenize sentences
|
| 371 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 372 |
+
|
| 373 |
+
# Compute token embeddings
|
| 374 |
+
with torch.no_grad():
|
| 375 |
+
model_output = model(**encoded_input)
|
| 376 |
+
|
| 377 |
+
# Perform pooling
|
| 378 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 379 |
+
|
| 380 |
+
# Normalize embeddings
|
| 381 |
+
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
| 382 |
+
|
| 383 |
+
print("Sentence embeddings:")
|
| 384 |
+
print(sentence_embeddings)
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
## Evaluation Results
|
| 388 |
+
|
| 389 |
+
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=sentence-transformers/all-MiniLM-L6-v2)
|
| 390 |
+
|
| 391 |
+
------
|
| 392 |
+
|
| 393 |
+
## Background
|
| 394 |
+
|
| 395 |
+
The project aims to train sentence embedding models on very large sentence level datasets using a self-supervised
|
| 396 |
+
contrastive learning objective. We used the pretrained [`nreimers/MiniLM-L6-H384-uncased`](https://huggingface.co/nreimers/MiniLM-L6-H384-uncased) model and fine-tuned in on a
|
| 397 |
+
1B sentence pairs dataset. We use a contrastive learning objective: given a sentence from the pair, the model should predict which out of a set of randomly sampled other sentences, was actually paired with it in our dataset.
|
| 398 |
+
|
| 399 |
+
We developed this model during the
|
| 400 |
+
[Community week using JAX/Flax for NLP & CV](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104),
|
| 401 |
+
organized by Hugging Face. We developed this model as part of the project:
|
| 402 |
+
[Train the Best Sentence Embedding Model Ever with 1B Training Pairs](https://discuss.huggingface.co/t/train-the-best-sentence-embedding-model-ever-with-1b-training-pairs/7354). We benefited from efficient hardware infrastructure to run the project: 7 TPUs v3-8, as well as intervention from Googles Flax, JAX, and Cloud team member about efficient deep learning frameworks.
|
| 403 |
+
|
| 404 |
+
## Intended uses
|
| 405 |
+
|
| 406 |
+
Our model is intended to be used as a sentence and short paragraph encoder. Given an input text, it outputs a vector which captures
|
| 407 |
+
the semantic information. The sentence vector may be used for information retrieval, clustering or sentence similarity tasks.
|
| 408 |
+
|
| 409 |
+
By default, input text longer than 256 word pieces is truncated.
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
## Training procedure
|
| 413 |
+
|
| 414 |
+
### Pre-training
|
| 415 |
+
|
| 416 |
+
We use the pretrained [`nreimers/MiniLM-L6-H384-uncased`](https://huggingface.co/nreimers/MiniLM-L6-H384-uncased) model. Please refer to the model card for more detailed information about the pre-training procedure.
|
| 417 |
+
|
| 418 |
+
### Fine-tuning
|
| 419 |
+
|
| 420 |
+
We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pairs from the batch.
|
| 421 |
+
We then apply the cross entropy loss by comparing with true pairs.
|
| 422 |
+
|
| 423 |
+
#### Hyper parameters
|
| 424 |
+
|
| 425 |
+
We trained our model on a TPU v3-8. We train the model during 100k steps using a batch size of 1024 (128 per TPU core).
|
| 426 |
+
We use a learning rate warm up of 500. The sequence length was limited to 128 tokens. We used the AdamW optimizer with
|
| 427 |
+
a 2e-5 learning rate. The full training script is accessible in this current repository: `train_script.py`.
|
| 428 |
+
|
| 429 |
+
#### Training data
|
| 430 |
+
|
| 431 |
+
We use the concatenation from multiple datasets to fine-tune our model. The total number of sentence pairs is above 1 billion sentences.
|
| 432 |
+
We sampled each dataset given a weighted probability which configuration is detailed in the `data_config.json` file.
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
| Dataset | Paper | Number of training tuples |
|
| 436 |
+
|--------------------------------------------------------|:----------------------------------------:|:--------------------------:|
|
| 437 |
+
| [Reddit comments (2015-2018)](https://github.com/PolyAI-LDN/conversational-datasets/tree/master/reddit) | [paper](https://arxiv.org/abs/1904.06472) | 726,484,430 |
|
| 438 |
+
| [S2ORC](https://github.com/allenai/s2orc) Citation pairs (Abstracts) | [paper](https://aclanthology.org/2020.acl-main.447/) | 116,288,806 |
|
| 439 |
+
| [WikiAnswers](https://github.com/afader/oqa#wikianswers-corpus) Duplicate question pairs | [paper](https://doi.org/10.1145/2623330.2623677) | 77,427,422 |
|
| 440 |
+
| [PAQ](https://github.com/facebookresearch/PAQ) (Question, Answer) pairs | [paper](https://arxiv.org/abs/2102.07033) | 64,371,441 |
|
| 441 |
+
| [S2ORC](https://github.com/allenai/s2orc) Citation pairs (Titles) | [paper](https://aclanthology.org/2020.acl-main.447/) | 52,603,982 |
|
| 442 |
+
| [S2ORC](https://github.com/allenai/s2orc) (Title, Abstract) | [paper](https://aclanthology.org/2020.acl-main.447/) | 41,769,185 |
|
| 443 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title, Body) pairs | - | 25,316,456 |
|
| 444 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title+Body, Answer) pairs | - | 21,396,559 |
|
| 445 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title, Answer) pairs | - | 21,396,559 |
|
| 446 |
+
| [MS MARCO](https://microsoft.github.io/msmarco/) triplets | [paper](https://doi.org/10.1145/3404835.3462804) | 9,144,553 |
|
| 447 |
+
| [GOOAQ: Open Question Answering with Diverse Answer Types](https://github.com/allenai/gooaq) | [paper](https://arxiv.org/pdf/2104.08727.pdf) | 3,012,496 |
|
| 448 |
+
| [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Title, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 1,198,260 |
|
| 449 |
+
| [Code Search](https://huggingface.co/datasets/code_search_net) | - | 1,151,414 |
|
| 450 |
+
| [COCO](https://cocodataset.org/#home) Image captions | [paper](https://link.springer.com/chapter/10.1007%2F978-3-319-10602-1_48) | 828,395|
|
| 451 |
+
| [SPECTER](https://github.com/allenai/specter) citation triplets | [paper](https://doi.org/10.18653/v1/2020.acl-main.207) | 684,100 |
|
| 452 |
+
| [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Question, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 681,164 |
|
| 453 |
+
| [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Title, Question) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 659,896 |
|
| 454 |
+
| [SearchQA](https://huggingface.co/datasets/search_qa) | [paper](https://arxiv.org/abs/1704.05179) | 582,261 |
|
| 455 |
+
| [Eli5](https://huggingface.co/datasets/eli5) | [paper](https://doi.org/10.18653/v1/p19-1346) | 325,475 |
|
| 456 |
+
| [Flickr 30k](https://shannon.cs.illinois.edu/DenotationGraph/) | [paper](https://transacl.org/ojs/index.php/tacl/article/view/229/33) | 317,695 |
|
| 457 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (titles) | | 304,525 |
|
| 458 |
+
| AllNLI ([SNLI](https://nlp.stanford.edu/projects/snli/) and [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/) | [paper SNLI](https://doi.org/10.18653/v1/d15-1075), [paper MultiNLI](https://doi.org/10.18653/v1/n18-1101) | 277,230 |
|
| 459 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (bodies) | | 250,519 |
|
| 460 |
+
| [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (titles+bodies) | | 250,460 |
|
| 461 |
+
| [Sentence Compression](https://github.com/google-research-datasets/sentence-compression) | [paper](https://www.aclweb.org/anthology/D13-1155/) | 180,000 |
|
| 462 |
+
| [Wikihow](https://github.com/pvl/wikihow_pairs_dataset) | [paper](https://arxiv.org/abs/1810.09305) | 128,542 |
|
| 463 |
+
| [Altlex](https://github.com/chridey/altlex/) | [paper](https://aclanthology.org/P16-1135.pdf) | 112,696 |
|
| 464 |
+
| [Quora Question Triplets](https://quoradata.quora.com/First-Quora-Dataset-Release-Question-Pairs) | - | 103,663 |
|
| 465 |
+
| [Simple Wikipedia](https://cs.pomona.edu/~dkauchak/simplification/) | [paper](https://www.aclweb.org/anthology/P11-2117/) | 102,225 |
|
| 466 |
+
| [Natural Questions (NQ)](https://ai.google.com/research/NaturalQuestions) | [paper](https://transacl.org/ojs/index.php/tacl/article/view/1455) | 100,231 |
|
| 467 |
+
| [SQuAD2.0](https://rajpurkar.github.io/SQuAD-explorer/) | [paper](https://aclanthology.org/P18-2124.pdf) | 87,599 |
|
| 468 |
+
| [TriviaQA](https://huggingface.co/datasets/trivia_qa) | - | 73,346 |
|
| 469 |
+
| **Total** | | **1,170,060,424** |
|