File size: 19,778 Bytes
a318cb0 6198f4f a318cb0 6198f4f a318cb0 9587f3f 8694702 61a1d07 8694702 61a1d07 8694702 33afb25 8694702 33afb25 8694702 61a1d07 a535051 61a1d07 a535051 61a1d07 a535051 9587f3f a318cb0 9587f3f a318cb0 9587f3f a318cb0 9587f3f a318cb0 |
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
---
configs:
- config_name: arguana-corpus
data_files:
- split: train
path: arguana/corpus/*
- config_name: arguana-queries
data_files:
- split: test
path: arguana/queries/test.parquet
- config_name: arguana-qrels
data_files:
- split: test
path: arguana/qrels/test.parquet
- config_name: bioasq-corpus
data_files:
- split: train
path: bioasq/corpus/*
- config_name: bioasq-queries
data_files:
- split: train
path: bioasq/queries/train.parquet
- split: test
path: bioasq/queries/test.parquet
- config_name: bioasq-qrels
data_files:
- split: train
path: bioasq/qrels/train.parquet
- split: test
path: bioasq/qrels/test.parquet
- config_name: climate-fever-corpus
data_files:
- split: train
path: climate-fever/corpus/*
- config_name: climate-fever-queries
data_files:
- split: test
path: climate-fever/queries/test.parquet
- config_name: climate-fever-qrels
data_files:
- split: test
path: climate-fever/qrels/test.parquet
- config_name: cqadupstack-android-corpus
data_files:
- split: train
path: cqadupstack-android/corpus/*
- config_name: cqadupstack-android-queries
data_files:
- split: test
path: cqadupstack-android/queries/test.parquet
- config_name: cqadupstack-android-qrels
data_files:
- split: test
path: cqadupstack-android/qrels/test.parquet
- config_name: cqadupstack-english-corpus
data_files:
- split: train
path: cqadupstack-english/corpus/*
- config_name: cqadupstack-english-queries
data_files:
- split: test
path: cqadupstack-english/queries/test.parquet
- config_name: cqadupstack-english-qrels
data_files:
- split: test
path: cqadupstack-english/qrels/test.parquet
- config_name: cqadupstack-gaming-corpus
data_files:
- split: train
path: cqadupstack-gaming/corpus/*
- config_name: cqadupstack-gaming-queries
data_files:
- split: test
path: cqadupstack-gaming/queries/test.parquet
- config_name: cqadupstack-gaming-qrels
data_files:
- split: test
path: cqadupstack-gaming/qrels/test.parquet
- config_name: cqadupstack-gis-corpus
data_files:
- split: train
path: cqadupstack-gis/corpus/*
- config_name: cqadupstack-gis-queries
data_files:
- split: test
path: cqadupstack-gis/queries/test.parquet
- config_name: cqadupstack-gis-qrels
data_files:
- split: test
path: cqadupstack-gis/qrels/test.parquet
- config_name: cqadupstack-mathematica-corpus
data_files:
- split: train
path: cqadupstack-mathematica/corpus/*
- config_name: cqadupstack-mathematica-queries
data_files:
- split: test
path: cqadupstack-mathematica/queries/test.parquet
- config_name: cqadupstack-mathematica-qrels
data_files:
- split: test
path: cqadupstack-mathematica/qrels/test.parquet
- config_name: cqadupstack-physics-corpus
data_files:
- split: train
path: cqadupstack-physics/corpus/*
- config_name: cqadupstack-physics-queries
data_files:
- split: test
path: cqadupstack-physics/queries/test.parquet
- config_name: cqadupstack-physics-qrels
data_files:
- split: test
path: cqadupstack-physics/qrels/test.parquet
- config_name: cqadupstack-programmers-corpus
data_files:
- split: train
path: cqadupstack-programmers/corpus/*
- config_name: cqadupstack-programmers-queries
data_files:
- split: test
path: cqadupstack-programmers/queries/test.parquet
- config_name: cqadupstack-programmers-qrels
data_files:
- split: test
path: cqadupstack-programmers/qrels/test.parquet
- config_name: cqadupstack-stats-corpus
data_files:
- split: train
path: cqadupstack-stats/corpus/*
- config_name: cqadupstack-stats-queries
data_files:
- split: test
path: cqadupstack-stats/queries/test.parquet
- config_name: cqadupstack-stats-qrels
data_files:
- split: test
path: cqadupstack-stats/qrels/test.parquet
- config_name: cqadupstack-text-corpus
data_files:
- split: train
path: cqadupstack-text/corpus/*
- config_name: cqadupstack-text-queries
data_files:
- split: test
path: cqadupstack-text/queries/test.parquet
- config_name: cqadupstack-text-qrels
data_files:
- split: test
path: cqadupstack-text/qrels/test.parquet
- config_name: cqadupstack-unix-corpus
data_files:
- split: train
path: cqadupstack-unix/corpus/*
- config_name: cqadupstack-unix-queries
data_files:
- split: test
path: cqadupstack-unix/queries/test.parquet
- config_name: cqadupstack-unix-qrels
data_files:
- split: test
path: cqadupstack-unix/qrels/test.parquet
- config_name: cqadupstack-webmasters-corpus
data_files:
- split: train
path: cqadupstack-webmasters/corpus/*
- config_name: cqadupstack-webmasters-queries
data_files:
- split: test
path: cqadupstack-webmasters/queries/test.parquet
- config_name: cqadupstack-webmasters-qrels
data_files:
- split: test
path: cqadupstack-webmasters/qrels/test.parquet
- config_name: cqadupstack-wordpress-corpus
data_files:
- split: train
path: cqadupstack-wordpress/corpus/*
- config_name: cqadupstack-wordpress-queries
data_files:
- split: test
path: cqadupstack-wordpress/queries/test.parquet
- config_name: cqadupstack-wordpress-qrels
data_files:
- split: test
path: cqadupstack-wordpress/qrels/test.parquet
- config_name: fever-corpus
data_files:
- split: train
path: fever/corpus/*
- config_name: fever-queries
data_files:
- split: train
path: fever/queries/train.parquet
- split: dev
path: fever/queries/dev.parquet
- split: test
path: fever/queries/test.parquet
- config_name: fever-qrels
data_files:
- split: train
path: fever/qrels/train.parquet
- split: dev
path: fever/qrels/dev.parquet
- split: test
path: fever/qrels/test.parquet
- config_name: fiqa-corpus
data_files:
- split: train
path: fiqa/corpus/*
- config_name: fiqa-queries
data_files:
- split: train
path: fiqa/queries/train.parquet
- split: dev
path: fiqa/queries/dev.parquet
- split: all
path: fiqa/queries/all.parquet
- split: test
path: fiqa/queries/test.parquet
- config_name: fiqa-qrels
data_files:
- split: train
path: fiqa/qrels/train.parquet
- split: dev
path: fiqa/qrels/dev.parquet
- split: all
path: fiqa/qrels/all.parquet
- split: test
path: fiqa/qrels/test.parquet
- config_name: hotpotqa-corpus
data_files:
- split: train
path: hotpotqa/corpus/*
- config_name: hotpotqa-queries
data_files:
- split: train
path: hotpotqa/queries/train.parquet
- split: dev
path: hotpotqa/queries/dev.parquet
- split: test
path: hotpotqa/queries/test.parquet
- config_name: hotpotqa-qrels
data_files:
- split: train
path: hotpotqa/qrels/train.parquet
- split: dev
path: hotpotqa/qrels/dev.parquet
- split: test
path: hotpotqa/qrels/test.parquet
- config_name: msmarco-corpus
data_files:
- split: train
path: msmarco/corpus/*
- config_name: msmarco-queries
data_files:
- split: train
path: msmarco/queries/train.parquet
- split: dev
path: msmarco/queries/dev.parquet
- config_name: msmarco-qrels
data_files:
- split: train
path: msmarco/qrels/train.parquet
- split: dev
path: msmarco/qrels/dev.parquet
- config_name: nfcorpus-corpus
data_files:
- split: train
path: nfcorpus/corpus/*
- config_name: nfcorpus-queries
data_files:
- split: train
path: nfcorpus/queries/train.parquet
- split: dev
path: nfcorpus/queries/dev.parquet
- split: test
path: nfcorpus/queries/test.parquet
- config_name: nfcorpus-qrels
data_files:
- split: train
path: nfcorpus/qrels/train.parquet
- split: dev
path: nfcorpus/qrels/dev.parquet
- split: test
path: nfcorpus/qrels/test.parquet
- config_name: nq-corpus
data_files:
- split: train
path: nq/corpus/*
- config_name: nq-queries
data_files:
- split: test
path: nq/queries/test.parquet
- config_name: nq-qrels
data_files:
- split: test
path: nq/qrels/test.parquet
- config_name: quora-corpus
data_files:
- split: train
path: quora/corpus/*
- config_name: quora-queries
data_files:
- split: dev
path: quora/queries/dev.parquet
- split: test
path: quora/queries/test.parquet
- config_name: quora-qrels
data_files:
- split: dev
path: quora/qrels/dev.parquet
- split: test
path: quora/qrels/test.parquet
- config_name: robust04-corpus
data_files:
- split: train
path: robust04/corpus/*
- config_name: robust04-queries
data_files:
- split: test
path: robust04/queries/test.parquet
- config_name: robust04-qrels
data_files:
- split: test
path: robust04/qrels/test.parquet
- config_name: scidocs-corpus
data_files:
- split: train
path: scidocs/corpus/*
- config_name: scidocs-queries
data_files:
- split: test
path: scidocs/queries/test.parquet
- config_name: scidocs-qrels
data_files:
- split: test
path: scidocs/qrels/test.parquet
- config_name: scifact-corpus
data_files:
- split: train
path: scifact/corpus/*
- config_name: scifact-queries
data_files:
- split: train
path: scifact/queries/train.parquet
- split: test
path: scifact/queries/test.parquet
- config_name: scifact-qrels
data_files:
- split: train
path: scifact/qrels/train.parquet
- split: test
path: scifact/qrels/test.parquet
- config_name: signal1m-corpus
data_files:
- split: train
path: signal1m/corpus/*
- config_name: signal1m-queries
data_files:
- split: test
path: signal1m/queries/test.parquet
- config_name: signal1m-qrels
data_files:
- split: test
path: signal1m/qrels/test.parquet
- config_name: trec-covid-corpus
data_files:
- split: train
path: trec-covid/corpus/*
- config_name: trec-covid-queries
data_files:
- split: test
path: trec-covid/queries/test.parquet
- config_name: trec-covid-qrels
data_files:
- split: test
path: trec-covid/qrels/test.parquet
- config_name: trec-news-corpus
data_files:
- split: train
path: trec-news/corpus/*
- config_name: trec-news-queries
data_files:
- split: test
path: trec-news/queries/test.parquet
- config_name: trec-news-qrels
data_files:
- split: test
path: trec-news/qrels/test.parquet
- config_name: webis-touche2020-corpus
data_files:
- split: train
path: webis-touche2020/corpus/*
- config_name: webis-touche2020-queries
data_files:
- split: test
path: webis-touche2020/queries/test.parquet
- config_name: webis-touche2020-qrels
data_files:
- split: test
path: webis-touche2020/qrels/test.parquet
---
# BEIR embeddings with Cohere embed-english-v3.0 model
This datasets contains all query & document embeddings for [BEIR](https://github.com/beir-cellar/beir), embedded with the [Cohere embed-english-v3.0](https://huggingface.co/Cohere/Cohere-embed-english-v3.0) embedding model.
## Overview of datasets
This repository hosts all 18 datasets from BEIR, including query and document embeddings. The following table gives an overview of the available datasets.
See the next section how to load the individual datasets.
| Dataset | nDCG@10 | #Documents
| --- | --- | --- |
| arguana | 53.98 | 8,674 |
| bioasq | 45.66 | 14,914,603 |
| climate-fever | 25.90 | 5,416,593 |
| cqadupstack-android | 50.01 | 22,998 |
| cqadupstack-english | 49.09 | 40,221 |
| cqadupstack-gaming | 60.50 | 45,301 |
| cqadupstack-gis | 39.17 | 37,637 |
| cqadupstack-mathematica | 30.38 | 16,705 |
| cqadupstack-physics | 43.82 | 38,316 |
| cqadupstack-programmers | 43.67 | 32,176 |
| cqadupstack-stats | 35.23 | 42,269 |
| cqadupstack-text | 30.84 | 68,184 |
| cqadupstack-unix | 40.59 | 47,382 |
| cqadupstack-webmasters | 40.68 | 17,405 |
| cqadupstack-wordpress | 34.26 | 48,605 |
| fever | 89.00 | 5,416,568 |
| fiqa | 42.14 | 57,638 |
| hotpotqa | 70.72 | 5,233,329 |
| msmarco | 42.86 | 8,841,823 |
| nfcorpus | 38.63 | 3,633 |
| nq | 61.62 | 2,681,468 |
| quora | 88.72 | 522,931 |
| robust04 | 54.06 | 528,155 |
| scidocs | 20.34 | 25,657 |
| scifact | 71.81 | 5,183 |
| signal1m | 26.32 | 2,866,316 |
| trec-covid | 81.78 | 171,332 |
| trec-news | 50.42 | 594,977 |
| webis-touche2020 | 32.64 | 382,545 |
Notes:
- arguana: The task of arguana is to find for a given argument (e.g. `Being vegetarian helps the environment ...`), an argument that refutes it (e.g. `Vegetarian doesn't have an impact on the environment`). Naturally, embedding models work by finding the most similar texts, hence for the given argument it would find similar arguments first that support that `vegetarian helps the environment`, which would be treated as non-relevant. By embedding model prompting, the model can be steered to find arguments that refute the query. This will improve the nDCG@10 score from 53.98 to 61.5.
- climate-fever: The task is to find evidence that support or refute a claim. As with arguana, with the default mode, the model will find the evidence primarily supporting the claim. By embedding model prompting, we can tell the model to find support and contra evidence for a claim. This improves the nDCG@10 score to 38.4.
- Quora: As the corpus consists of questions, they have been encoded with the `input_type='search_query'` in order to find similar/duplicate questions.
- cqadupstack: The datasets consists of several sub-datasets, where the nDCG@10 scores will be averaged in BEIR.
- bioasq/robust04/trec-news/signal1m: For these datasets we just provide the IDs and the embeddings, but not title/text fields. See the [BEIR repository](https://github.com/beir-cellar/beir) how to obtain the respective text corpora. You can still evaluate search quality on these datasets.
## Loading the dataset
### Loading the document embeddings
The `corpus` split contains all document embeddings of the corpus.
You can either load the dataset like this:
```python
from datasets import load_dataset
dataset_name = "hotpotqa"
docs = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-corpus", split="train")
```
Or you can also stream it without downloading it before:
```python
from datasets import load_dataset
dataset_name = "hotpotqa"
docs = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-corpus", split="train", streaming=True)
for doc in docs:
doc_id = doc['_id']
title = doc['title']
text = doc['text']
emb = doc['emb']
```
Note, depending on the dataset size, the corpus split can be quite large.
### Loading the query embeddings
The `queries` split contains all query embeddings. There might be up to three splits: `train`, `dev`, and `test`, depending which splits are available in BEIR. Evaluation is performed on the `test` split.
You can load the dataset like this:
```python
from datasets import load_dataset
dataset_name = "hotpotqa"
queries = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-queries", split="test")
for query in queries:
query_id = query['_id']
text = query['text']
emb = query['emb']
```
### Loading the qrels
The `qrels` split contains the query relevance annotation, i.e., it contains the relevance score for (query, document) pairs.
You can load the dataset like this:
```python
from datasets import load_dataset
dataset_name = "hotpotqa"
qrels = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-qrels", split="test")
for qrel in qrels:
query_id = qrel['query_id']
corpus_id = qrel['corpus_id']
score = qrel['score']
```
## Search
The following shows an example, how the dataset can be used to build a semantic search application.
Get your API key from [cohere.com](https://cohere.com) and start using this dataset.
```python
#Run: pip install cohere datasets torch
from datasets import load_dataset
import torch
import cohere
dataset_name = "hotpotqa"
co = cohere.Client("<<COHERE_API_KEY>>") # Add your cohere API key from www.cohere.com
#Load at max 1000 documents + embeddings
max_docs = 1000
docs_stream = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-corpus", split="train", streaming=True)
docs = []
doc_embeddings = []
for doc in docs_stream:
docs.append(doc)
doc_embeddings.append(doc['emb'])
if len(docs) >= max_docs:
break
doc_embeddings = torch.tensor(doc_embeddings)
query = 'What is an abstract' #Your query
response = co.embed(texts=[query], model='embed-english-v3.0', input_type='search_query')
query_embedding = response.embeddings
query_embedding = torch.tensor(query_embedding)
# Compute dot score between query embedding and document embeddings
dot_scores = torch.mm(query_embedding, doc_embeddings.transpose(0, 1))
top_k = torch.topk(dot_scores, k=3)
# Print results
print("Query:", query)
for doc_id in top_k.indices[0].tolist():
print(docs[doc_id]['title'])
print(docs[doc_id]['text'], "\n")
```
## Running evaluations
This dataset allows to reproduce the [BEIR](https://github.com/beir-cellar/beir) performance results and to compute nDCG@10, Recall@10, and Accuracy@3.
You must have `beir`, `faiss`, `numpy`, and `datasets` installed. The following scripts loads all files, runs search and computes the search quality metrices.
```python
import numpy as np
import faiss
from beir.retrieval.evaluation import EvaluateRetrieval
import time
from datasets import load_dataset
def faiss_search(index, queries_emb, k=[10, 100]):
start_time = time.time()
faiss_scores, faiss_doc_ids = index.search(queries_emb, max(k))
print(f"Search took {(time.time()-start_time):.2f} sec")
query2id = {idx: qid for idx, qid in enumerate(query_ids)}
doc2id = {idx: cid for idx, cid in enumerate(docs_ids)}
faiss_results = {}
for idx in range(0, len(faiss_scores)):
qid = query2id[idx]
doc_scores = {doc2id[doc_id]: score.item() for doc_id, score in zip(faiss_doc_ids[idx], faiss_scores[idx])}
faiss_results[qid] = doc_scores
ndcg, map_score, recall, precision = EvaluateRetrieval.evaluate(qrels, faiss_results, k)
acc = EvaluateRetrieval.evaluate_custom(qrels, faiss_results, [3, 5, 10], metric="acc")
print(ndcg)
print(recall)
print(acc)
dataset_name = "<<DATASET_NAME>>"
dataset_split = "test"
num_dim = 1024
#Load qrels
df = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-qrels", split=dataset_split)
qrels = {}
for row in df:
qid = row['query_id']
cid = row['corpus_id']
if row['score'] > 0:
if qid not in qrels:
qrels[qid] = {}
qrels[qid][cid] = row['score']
#Load queries
df = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-queries", split=dataset_split)
query_ids = df['_id']
query_embs = np.asarray(df['emb'])
print("Query embeddings:", query_embs.shape)
#Load corpus
df = load_dataset("Cohere/beir-embed-english-v3", f"{dataset_name}-corpus", split="train")
docs_ids = df['_id']
#Build index
print("Build index. This might take some time")
index = faiss.IndexFlatIP(num_dim)
index.add(np.asarray(df.to_pandas()['emb'].tolist()))
#Run and evaluate search
print("Seach on index")
faiss_search(index, query_embs)
```
## Notes
- This dataset was created with `datasets==2.15.0`. Make sure to use this or a newer version of the datasets library.
|