Datasets:
Tasks:
Text Retrieval
Modalities:
Text
Formats:
parquet
Sub-tasks:
document-retrieval
Languages:
Swahili
Size:
1K - 10K
License:
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
annotations_creators:
|
3 |
+
- expert-generated
|
4 |
+
|
5 |
+
language:
|
6 |
+
- sw
|
7 |
+
|
8 |
+
multilinguality:
|
9 |
+
- multilingual
|
10 |
+
|
11 |
+
pretty_name: MIRACL-corpus
|
12 |
+
size_categories: []
|
13 |
+
source_datasets: []
|
14 |
+
tags: []
|
15 |
+
|
16 |
+
task_categories:
|
17 |
+
- text-retrieval
|
18 |
+
|
19 |
+
license:
|
20 |
+
- apache-2.0
|
21 |
+
|
22 |
+
task_ids:
|
23 |
+
- document-retrieval
|
24 |
+
---
|
25 |
+
|
26 |
+
# MIRACL (SW) embedded with cohere.ai `multilingual-22-12` encoder
|
27 |
+
|
28 |
+
We encoded the [MIRACL dataset](https://huggingface.co/miracl) using the [cohere.ai](https://txt.cohere.ai/multilingual/) `multilingual-22-12` embedding model.
|
29 |
+
|
30 |
+
The query embeddings can be found in [Cohere/miracl-sw-queries-22-12](https://huggingface.co/datasets/Cohere/miracl-sw-queries-22-12) and the corpus embeddings can be found in [Cohere/miracl-sw-corpus-22-12](https://huggingface.co/datasets/Cohere/miracl-sw-corpus-22-12).
|
31 |
+
|
32 |
+
For the orginal datasets, see [miracl/miracl](https://huggingface.co/datasets/miracl/miracl) and [miracl/miracl-corpus](https://huggingface.co/datasets/miracl/miracl-corpus).
|
33 |
+
|
34 |
+
|
35 |
+
Dataset info:
|
36 |
+
> MIRACL 🌍🙌🌏 (Multilingual Information Retrieval Across a Continuum of Languages) is a multilingual retrieval dataset that focuses on search across 18 different languages, which collectively encompass over three billion native speakers around the world.
|
37 |
+
>
|
38 |
+
> The corpus for each language is prepared from a Wikipedia dump, where we keep only the plain text and discard images, tables, etc. Each article is segmented into multiple passages using WikiExtractor based on natural discourse units (e.g., `\n\n` in the wiki markup). Each of these passages comprises a "document" or unit of retrieval. We preserve the Wikipedia article title of each passage.
|
39 |
+
|
40 |
+
## Embeddings
|
41 |
+
We compute for `title+" "+text` the embeddings using our `multilingual-22-12` embedding model, a state-of-the-art model that works for semantic search in 100 languages. If you want to learn more about this model, have a look at [cohere.ai multilingual embedding model](https://txt.cohere.ai/multilingual/).
|
42 |
+
|
43 |
+
|
44 |
+
## Loading the dataset
|
45 |
+
|
46 |
+
You can either load the dataset like this:
|
47 |
+
```python
|
48 |
+
from datasets import load_dataset
|
49 |
+
docs = load_dataset(f"Cohere/miracl-sw-corpus-22-12", split="train")
|
50 |
+
```
|
51 |
+
|
52 |
+
Or you can also stream it without downloading it before:
|
53 |
+
```python
|
54 |
+
from datasets import load_dataset
|
55 |
+
docs = load_dataset(f"Cohere/miracl-sw-corpus-22-12", split="train", streaming=True)
|
56 |
+
|
57 |
+
for doc in docs:
|
58 |
+
docid = doc['docid']
|
59 |
+
title = doc['title']
|
60 |
+
text = doc['text']
|
61 |
+
emb = doc['emb']
|
62 |
+
```
|
63 |
+
|
64 |
+
## Search
|
65 |
+
|
66 |
+
Have a look at [miracl-sw-queries-22-12](https://huggingface.co/datasets/Cohere/miracl-sw-queries-22-12) where we provide also the query embeddings for the MIRACL dataset.
|
67 |
+
|
68 |
+
To search in the documents, you must use **dot-product**.
|
69 |
+
|
70 |
+
|
71 |
+
And then compare this query embeddings either with a vector database (recommended) or directly computing the dot product.
|
72 |
+
|
73 |
+
A full search example:
|
74 |
+
```python
|
75 |
+
# Attention! For large datasets, this requires a lot of memory to store
|
76 |
+
# all document embeddings and to compute the dot product scores.
|
77 |
+
# Only use this for smaller datasets. For large datasets, use a vector DB
|
78 |
+
|
79 |
+
from datasets import load_dataset
|
80 |
+
import torch
|
81 |
+
|
82 |
+
#Load documents + embeddings
|
83 |
+
docs = load_dataset(f"Cohere/miracl-sw-corpus-22-12", split="train")
|
84 |
+
doc_embeddings = torch.tensor(docs['emb'])
|
85 |
+
|
86 |
+
# Load queries
|
87 |
+
queries = load_dataset(f"Cohere/miracl-sw-queries-22-12", split="dev")
|
88 |
+
|
89 |
+
# Select the first query as example
|
90 |
+
qid = 0
|
91 |
+
query = queries[qid]
|
92 |
+
query_embedding = torch.tensor(queries['emb'])
|
93 |
+
|
94 |
+
# Compute dot score between query embedding and document embeddings
|
95 |
+
dot_scores = torch.mm(query_embedding, doc_embeddings.transpose(0, 1))
|
96 |
+
top_k = torch.topk(dot_scores, k=3)
|
97 |
+
|
98 |
+
# Print results
|
99 |
+
print("Query:", query['query'])
|
100 |
+
for doc_id in top_k.indices[0].tolist():
|
101 |
+
print(docs[doc_id]['title'])
|
102 |
+
print(docs[doc_id]['text'])
|
103 |
+
```
|
104 |
+
|
105 |
+
You can get embeddings for new queries using our API:
|
106 |
+
```python
|
107 |
+
#Run: pip install cohere
|
108 |
+
import cohere
|
109 |
+
co = cohere.Client(f"{api_key}") # You should add your cohere API Key here :))
|
110 |
+
texts = ['my search query']
|
111 |
+
response = co.embed(texts=texts, model='multilingual-22-12')
|
112 |
+
query_embedding = response.embeddings[0] # Get the embedding for the first text
|
113 |
+
```
|
114 |
+
|
115 |
+
## Performance
|
116 |
+
|
117 |
+
In the following table we provide the nDCG@10 scores for the cohere multilingual-22-12 model in comparison to BM25 lexical search and mDPR (as provided in the [MIRACL paper](https://arxiv.org/abs/2210.09984))
|
118 |
+
|
119 |
+
| Model | cohere multilingual-22-12 | BM25 lexical search | mDPR |
|
120 |
+
|-------|---------------------------|--------------------|------|
|
121 |
+
| miracl-ar | **64.2** | 48.1 | 49.9 |
|
122 |
+
| miracl-bn | **61.5** | 50.8 | 44.3 |
|
123 |
+
| miracl-es | **47.0** | 31.9 | 47.8 |
|
124 |
+
| miracl-fa | **44.8** | 33.3 | 48 |
|
125 |
+
| miracl-fi | **63.7** | 55.1 | 47.2 |
|
126 |
+
| miracl-fr | **46.8** | 18.3 | 43.5 |
|
127 |
+
| miracl-hi | **50.7** | 45.8 | 38.3 |
|
128 |
+
| miracl-id | 44.8 | **44.9** | 27.2 |
|
129 |
+
| miracl-ja | **49.0** | 36.9 | 43.9 |
|
130 |
+
| miracl-ko | **50.9** | 41.9 | 41.9 |
|
131 |
+
| miracl-ru | **49.2** | 33.4 | 40.7 |
|
132 |
+
| miracl-sw | **61.4** | 38.3 | 29.9 |
|
133 |
+
| miracl-te | **67.8** | 49.4 | 35.6 |
|
134 |
+
| miracl-th | **60.2** | 48.4 | 35.8 |
|
135 |
+
| miracl-zh | 43.8 | 18 | **51.2** |
|
136 |
+
| **Avg** | **53.7** | 39.6 | 41.7 |
|
137 |
+
|