nreimers commited on
Commit
c7d7614
1 Parent(s): a530823

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +138 -0
README.md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - expert-generated
4
+
5
+ language:
6
+ - bn
7
+
8
+ multilinguality:
9
+ - multilingual
10
+
11
+ size_categories: []
12
+ source_datasets: []
13
+ tags: []
14
+
15
+ task_categories:
16
+ - text-retrieval
17
+
18
+ license:
19
+ - apache-2.0
20
+
21
+ task_ids:
22
+ - document-retrieval
23
+ ---
24
+
25
+ # MIRACL (bn) embedded with cohere.ai `multilingual-22-12` encoder
26
+
27
+ We encoded the [MIRACL dataset](https://huggingface.co/miracl) using the [cohere.ai](https://txt.cohere.ai/multilingual/) `multilingual-22-12` embedding model.
28
+
29
+ The query embeddings can be found in [Cohere/miracl-bn-queries-22-12](https://huggingface.co/datasets/Cohere/miracl-bn-queries-22-12) and the corpus embeddings can be found in [Cohere/miracl-bn-corpus-22-12](https://huggingface.co/datasets/Cohere/miracl-bn-corpus-22-12).
30
+
31
+ For the orginal datasets, see [miracl/miracl](https://huggingface.co/datasets/miracl/miracl) and [miracl/miracl-corpus](https://huggingface.co/datasets/miracl/miracl-corpus).
32
+
33
+
34
+ Dataset info:
35
+ > 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.
36
+ >
37
+ > 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.
38
+
39
+ ## Embeddings
40
+ 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/).
41
+
42
+
43
+ ## Loading the dataset
44
+
45
+ In {miracl-bn-corpus-22-12](https://huggingface.co/datasets/Cohere/miracl-bn-corpus-22-12) we provide the corpus embeddings. Note, depending on the selected split, the respective files can be quite large.
46
+
47
+ You can either load the dataset like this:
48
+ ```python
49
+ from datasets import load_dataset
50
+ docs = load_dataset(f"Cohere/miracl-bn-corpus-22-12", split="train")
51
+ ```
52
+
53
+ Or you can also stream it without downloading it before:
54
+ ```python
55
+ from datasets import load_dataset
56
+ docs = load_dataset(f"Cohere/miracl-bn-corpus-22-12", split="train", streaming=True)
57
+
58
+ for doc in docs:
59
+ docid = doc['docid']
60
+ title = doc['title']
61
+ text = doc['text']
62
+ emb = doc['emb']
63
+ ```
64
+
65
+ ## Search
66
+
67
+ Have a look at [miracl-bn-queries-22-12](https://huggingface.co/datasets/Cohere/miracl-bn-queries-22-12) where we provide the query embeddings for the MIRACL dataset.
68
+
69
+ To search in the documents, you must use **dot-product**.
70
+
71
+
72
+ And then compare this query embeddings either with a vector database (recommended) or directly computing the dot product.
73
+
74
+ A full search example:
75
+ ```python
76
+ # Attention! For large datasets, this requires a lot of memory to store
77
+ # all document embeddings and to compute the dot product scores.
78
+ # Only use this for smaller datasets. For large datasets, use a vector DB
79
+
80
+ from datasets import load_dataset
81
+ import torch
82
+
83
+ #Load documents + embeddings
84
+ docs = load_dataset(f"Cohere/miracl-bn-corpus-22-12", split="train")
85
+ doc_embeddings = torch.tensor(docs['emb'])
86
+
87
+ # Load queries
88
+ queries = load_dataset(f"Cohere/miracl-bn-queries-22-12", split="dev")
89
+
90
+ # Select the first query as example
91
+ qid = 0
92
+ query = queries[qid]
93
+ query_embedding = torch.tensor(queries['emb'])
94
+
95
+ # Compute dot score between query embedding and document embeddings
96
+ dot_scores = torch.mm(query_embedding, doc_embeddings.transpose(0, 1))
97
+ top_k = torch.topk(dot_scores, k=3)
98
+
99
+ # Print results
100
+ print("Query:", query['query'])
101
+ for doc_id in top_k.indices[0].tolist():
102
+ print(docs[doc_id]['title'])
103
+ print(docs[doc_id]['text'])
104
+ ```
105
+
106
+ You can get embeddings for new queries using our API:
107
+ ```python
108
+ #Run: pip install cohere
109
+ import cohere
110
+ co = cohere.Client(f"{api_key}") # You should add your cohere API Key here :))
111
+ texts = ['my search query']
112
+ response = co.embed(texts=texts, model='multilingual-22-12')
113
+ query_embedding = response.embeddings[0] # Get the embedding for the first text
114
+ ```
115
+
116
+ ## Performance
117
+
118
+ 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))
119
+
120
+ | Model | cohere multilingual-22-12 | BM25 lexical search | mDPR |
121
+ |-------|---------------------------|--------------------|------|
122
+ | miracl-ar | **64.2** | 48.1 | 49.9 |
123
+ | miracl-bn | **61.5** | 50.8 | 44.3 |
124
+ | miracl-es | **47.0** | 31.9 | 47.8 |
125
+ | miracl-fa | **44.8** | 33.3 | 48 |
126
+ | miracl-fi | **63.7** | 55.1 | 47.2 |
127
+ | miracl-fr | **46.8** | 18.3 | 43.5 |
128
+ | miracl-hi | **50.7** | 45.8 | 38.3 |
129
+ | miracl-id | 44.8 | **44.9** | 27.2 |
130
+ | miracl-ja | **49.0** | 36.9 | 43.9 |
131
+ | miracl-ko | **50.9** | 41.9 | 41.9 |
132
+ | miracl-ru | **49.2** | 33.4 | 40.7 |
133
+ | miracl-sw | **61.4** | 38.3 | 29.9 |
134
+ | miracl-te | **67.8** | 49.4 | 35.6 |
135
+ | miracl-th | **60.2** | 48.4 | 35.8 |
136
+ | miracl-zh | 43.8 | 18 | **51.2** |
137
+ | **Avg** | **53.7** | 39.6 | 41.7 |
138
+