Datasets:
Tasks:
Question Answering
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10M - 100M
DOI:
File size: 4,375 Bytes
25673f8 c9db5fd 25673f8 81768e5 25673f8 81768e5 25673f8 81768e5 e5ecd3d |
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 |
---
task_categories:
- question-answering
language:
- en
tags:
- TREC-RAG
- RAG
- MSMARCO
- MSMARCOV2.1
- Snowflake
- arctic
- arctic-embed
pretty_name: TREC-RAG-Embedding-Baseline
size_categories:
- 100M<n<1B
configs:
- config_name: corpus
data_files:
- split: train
path: corpus/*
---
# Snowflake Arctic Embed L Embeddings for MSMARCO V2.1 for TREC-RAG
This dataset contains the embeddings for the MSMARCO-V2.1 dataset which is used as the corpora for [TREC RAG](https://trec-rag.github.io/)
All embeddings are created using [Snowflake's Arctic Embed L](https://huggingface.co/Snowflake/snowflake-arctic-embed-l) and are intended to serve as a simple baseline for dense retrieval-based methods.
## Retrieval Performance
Retrieval performance for the TREC DL21-23, MSMARCOV2-Dev and Raggy Queries can be found below with BM25 as a baseline. For both systems retrieval is at the segment level and Doc Score = Max (passage score).
Retrieval is done via dot product and happens in BF16.
### NDCG@10
| Dataset | BM25 | Snowflake Arctic Embed L |
|---|---|---|
| Deep Learning 2021 | 0.5778 | 0.70682 |
| Deep Learning 2022 | 0.3576 | 0.5444 |
| Deep Learning 2023 | 0.3356 | 0.47372 |
| msmarcov2-dev | N/A | 0.35844 |
| msmarcov2-dev2 | N/A | 0.35821 |
| Raggy Queries | 0.4227 | 0.57759 |
### Recall@100
| Dataset | BM25 | Snowflake Arctic Embed L |
|---|---|---|
| Deep Learning 2021 | 0.3811 | 0.41361 |
| Deep Learning 2022 | 0.233 | 0.31351 |
| Deep Learning 2023 | 0.3049 | 0.34793 |
| msmarcov2-dev | 0.6683 | 0.85131 |
| msmarcov2-dev2 | 0.6771 | 0.84767 |
| Raggy Queries | 0.2807 | 0.36228 |
### Recall@1000
| Dataset | BM25 | Snowflake Arctic Embed L |
|---|---|---|
| Deep Learning 2021 | 0.7115 | 0.7193 |
| Deep Learning 2022 | 0.479 | 0.54566 |
| Deep Learning 2023 | 0.5852 | 0.59577 |
| msmarcov2-dev | 0.8528 | 0.93966 |
| msmarcov2-dev2 | 0.8577 | 0.93947 |
| Raggy Queries | 0.5745 | 0.63092 |
## Loading the dataset
### Loading the document embeddings
You can either load the dataset like this:
```python
from datasets import load_dataset
docs = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-l", split="train")
```
Or you can also stream it without downloading it before:
```python
from datasets import load_dataset
docs = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-l", split="train", streaming=True)
for doc in docs:
doc_id = j['docid']
url = doc['url']
text = doc['text']
emb = doc['embedding']
```
Note, The full dataset corpus is ~ 620GB so it will take a while to download and may not fit on some devices/
## Search
A full search example (on the first 1,000 paragraphs):
```python
from datasets import load_dataset
import torch
from transformers import AutoModel, AutoTokenizer
import numpy as np
top_k = 100
docs_stream = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-l",split="train", streaming=True)
docs = []
doc_embeddings = []
for doc in docs_stream:
docs.append(doc)
doc_embeddings.append(doc['embedding'])
if len(docs) >= top_k:
break
doc_embeddings = np.asarray(doc_embeddings)
tokenizer = AutoTokenizer.from_pretrained('Snowflake/snowflake-arctic-embed-l')
model = AutoModel.from_pretrained('Snowflake/snowflake-arctic-embed-l', add_pooling_layer=False)
model.eval()
query_prefix = 'Represent this sentence for searching relevant passages: '
queries = ['how do you clean smoke off walls']
queries_with_prefix = ["{}{}".format(query_prefix, i) for i in queries]
query_tokens = tokenizer(queries_with_prefix, padding=True, truncation=True, return_tensors='pt', max_length=512)
# Compute token embeddings
with torch.no_grad():
query_embeddings = model(**query_tokens)[0][:, 0]
# normalize embeddings
query_embeddings = torch.nn.functional.normalize(query_embeddings, p=2, dim=1)
doc_embeddings = torch.nn.functional.normalize(doc_embeddings, p=2, dim=1)
# Compute dot score between query embedding and document embeddings
dot_scores = np.matmul(query_embeddings, doc_embeddings.transpose())[0]
top_k_hits = np.argpartition(dot_scores, -top_k)[-top_k:].tolist()
# Sort top_k_hits by dot score
top_k_hits.sort(key=lambda x: dot_scores[x], reverse=True)
# Print results
print("Query:", queries[0])
for doc_id in top_k_hits:
print(docs[doc_id]['doc_id'])
print(docs[doc_id]['text'])
print(docs[doc_id]['url'], "\n")
``` |