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
| 6 |
+
tags:
|
| 7 |
+
- TREC-RAG
|
| 8 |
+
- RAG
|
| 9 |
+
- MSMARCO
|
| 10 |
+
- MSMARCOV2.1
|
| 11 |
+
- Snowflake
|
| 12 |
+
- arctic
|
| 13 |
+
- arctic-embed
|
| 14 |
+
- arctic-embed-m-v2.0
|
| 15 |
+
- MRL
|
| 16 |
+
pretty_name: TREC-RAG-Embedding-Baseline
|
| 17 |
+
size_categories:
|
| 18 |
+
- 100M<n<1B
|
| 19 |
+
configs:
|
| 20 |
+
- config_name: corpus
|
| 21 |
+
data_files:
|
| 22 |
+
- split: train
|
| 23 |
+
path: corpus/*
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
# Snowflake Arctic Embed M V2.0 Embeddings for MSMARCO V2.1 for TREC-RAG
|
| 27 |
+
|
| 28 |
+
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/)
|
| 29 |
+
All embeddings are created using [Snowflake's Arctic Embed M v2.0](https://huggingface.co/Snowflake/snowflake-arctic-embed-m-v2.0) and are intended to serve as a simple baseline for dense retrieval-based methods.
|
| 30 |
+
Note, that the embeddings are not normalized so you will need to normalize them before usage.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## Retrieval Performance
|
| 34 |
+
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).
|
| 35 |
+
Retrieval is done via a dot product and happens in BF16.
|
| 36 |
+
|
| 37 |
+
### NDCG@10
|
| 38 |
+
| Dataset | BM25 | Arctic-M-V2.0 (768 Dimensions) |
|
| 39 |
+
|---|---|---|
|
| 40 |
+
| Deep Learning 2021 | 0.5778 | |
|
| 41 |
+
| Deep Learning 2022 | 0.3576 | |
|
| 42 |
+
| Deep Learning 2023 | 0.3356 ||
|
| 43 |
+
| msmarcov2-dev | N/A | |
|
| 44 |
+
| msmarcov2-dev2 | N/A | |
|
| 45 |
+
| Raggy Queries | 0.4227 | |
|
| 46 |
+
| RAG 2024 | | |
|
| 47 |
+
### Recall@100
|
| 48 |
+
| Dataset | BM25 | Arctic-M-V2.0 (768 Dimensions) |
|
| 49 |
+
|---|---|---|
|
| 50 |
+
| Deep Learning 2021 | 0.3811 ||
|
| 51 |
+
| Deep Learning 2022 | 0.233 | |
|
| 52 |
+
| Deep Learning 2023 | 0.3049 | |
|
| 53 |
+
| msmarcov2-dev | 0.6683 | |
|
| 54 |
+
| msmarcov2-dev2 | 0.6771 | |
|
| 55 |
+
| Raggy Queries | 0.2807 | |
|
| 56 |
+
| RAG 2024 | | |
|
| 57 |
+
|
| 58 |
+
### Recall@1000
|
| 59 |
+
| Dataset | BM25 | Arctic-M-V2.0 (768 Dimensions) |
|
| 60 |
+
|---|---|---|
|
| 61 |
+
| Deep Learning 2021 | 0.7115 | |
|
| 62 |
+
| Deep Learning 2022 | 0.479 | |
|
| 63 |
+
| Deep Learning 2023 | 0.5852 | |
|
| 64 |
+
| msmarcov2-dev | 0.8528 | |
|
| 65 |
+
| msmarcov2-dev2 | 0.8577 | |
|
| 66 |
+
| Raggy Queries | 0.5745 | |
|
| 67 |
+
| RAG 2024 | | |
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## Loading the dataset
|
| 71 |
+
|
| 72 |
+
### Loading the document embeddings
|
| 73 |
+
|
| 74 |
+
You can either load the dataset like this:
|
| 75 |
+
```python
|
| 76 |
+
from datasets import load_dataset
|
| 77 |
+
docs = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-m-v2.0", split="train")
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
Or you can also stream it without downloading it before:
|
| 81 |
+
```python
|
| 82 |
+
from datasets import load_dataset
|
| 83 |
+
docs = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-m-v2.0", split="train", streaming=True)
|
| 84 |
+
for doc in docs:
|
| 85 |
+
doc_id = j['docid']
|
| 86 |
+
url = doc['url']
|
| 87 |
+
text = doc['text']
|
| 88 |
+
emb = doc['embedding']
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
Note, The full dataset corpus is ~ 620GB so it will take a while to download and may not fit on some devices/
|
| 93 |
+
|
| 94 |
+
## Search
|
| 95 |
+
A full search example (on the first 1,000 paragraphs):
|
| 96 |
+
```python
|
| 97 |
+
from datasets import load_dataset
|
| 98 |
+
import torch
|
| 99 |
+
from transformers import AutoModel, AutoTokenizer
|
| 100 |
+
import numpy as np
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
top_k = 100
|
| 104 |
+
docs_stream = load_dataset("Snowflake/msmarco-v2.1-snowflake-arctic-embed-m-v2.0",split="train", streaming=True)
|
| 105 |
+
|
| 106 |
+
docs = []
|
| 107 |
+
doc_embeddings = []
|
| 108 |
+
|
| 109 |
+
for doc in docs_stream:
|
| 110 |
+
docs.append(doc)
|
| 111 |
+
doc_embeddings.append(doc['embedding'])
|
| 112 |
+
if len(docs) >= top_k:
|
| 113 |
+
break
|
| 114 |
+
|
| 115 |
+
doc_embeddings = np.asarray(doc_embeddings)
|
| 116 |
+
|
| 117 |
+
tokenizer = AutoTokenizer.from_pretrained('Snowflake/snowflake-arctic-embed-m-v2.0')
|
| 118 |
+
model = AutoModel.from_pretrained('Snowflake/snowflake-arctic-embed-m-v2.0', add_pooling_layer=False)
|
| 119 |
+
model.eval()
|
| 120 |
+
|
| 121 |
+
query_prefix = 'Represent this sentence for searching relevant passages: '
|
| 122 |
+
queries = ['how do you clean smoke off walls']
|
| 123 |
+
queries_with_prefix = ["{}{}".format(query_prefix, i) for i in queries]
|
| 124 |
+
query_tokens = tokenizer(queries_with_prefix, padding=True, truncation=True, return_tensors='pt', max_length=512)
|
| 125 |
+
|
| 126 |
+
# Compute token embeddings
|
| 127 |
+
with torch.no_grad():
|
| 128 |
+
query_embeddings = model(**query_tokens)[0][:, 0]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
# normalize embeddings
|
| 132 |
+
query_embeddings = torch.nn.functional.normalize(query_embeddings, p=2, dim=1)
|
| 133 |
+
doc_embeddings = torch.nn.functional.normalize(doc_embeddings, p=2, dim=1)
|
| 134 |
+
|
| 135 |
+
# Compute dot score between query embedding and document embeddings
|
| 136 |
+
dot_scores = np.matmul(query_embeddings, doc_embeddings.transpose())[0]
|
| 137 |
+
top_k_hits = np.argpartition(dot_scores, -top_k)[-top_k:].tolist()
|
| 138 |
+
|
| 139 |
+
# Sort top_k_hits by dot score
|
| 140 |
+
top_k_hits.sort(key=lambda x: dot_scores[x], reverse=True)
|
| 141 |
+
|
| 142 |
+
# Print results
|
| 143 |
+
print("Query:", queries[0])
|
| 144 |
+
for doc_id in top_k_hits:
|
| 145 |
+
print(docs[doc_id]['doc_id'])
|
| 146 |
+
print(docs[doc_id]['text'])
|
| 147 |
+
print(docs[doc_id]['url'], "\n")
|
| 148 |
+
```
|