nreimers commited on
Commit
85c2eca
1 Parent(s): a150759

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +104 -0
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - expert-generated
4
+
5
+ language:
6
+ - en
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
+ # Wikipedia (en) embedded with cohere.ai `multilingual-22-12` encoder
26
+
27
+ We encoded [Wikipedia (en)](https://en.wikipedia.org) using the [cohere.ai](https://txt.cohere.ai/multilingual/) `multilingual-22-12` embedding model.
28
+
29
+ To get an overview how this dataset was created and pre-processed, have a look at [Cohere/wikipedia-22-12](https://huggingface.co/datasets/Cohere/wikipedia-22-12).
30
+
31
+
32
+ ## Embeddings
33
+ 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/).
34
+
35
+ ## Further languages
36
+ We provide embeddings of Wikipedia in many different languages:
37
+ [ar](https://huggingface.co/datasets/Cohere/wikipedia-22-12-ar-embeddings), [de](https://huggingface.co/datasets/Cohere/wikipedia-22-12-de-embeddings), [en](https://huggingface.co/datasets/Cohere/wikipedia-22-12-en-embeddings), [es](https://huggingface.co/datasets/Cohere/wikipedia-22-12-es-embeddings), [fr](https://huggingface.co/datasets/Cohere/wikipedia-22-12-fr-embeddings), [hi](https://huggingface.co/datasets/Cohere/wikipedia-22-12-hi-embeddings), [it](https://huggingface.co/datasets/Cohere/wikipedia-22-12-it-embeddings), [ja](https://huggingface.co/datasets/Cohere/wikipedia-22-12-ja-embeddings), [ko](https://huggingface.co/datasets/Cohere/wikipedia-22-12-ko-embeddings), [simple english](https://huggingface.co/datasets/Cohere/wikipedia-22-12-simple-embeddings), [zh](https://huggingface.co/datasets/Cohere/wikipedia-22-12-zh-embeddings),
38
+
39
+ You can find the Wikipedia datasets without embeddings at [Cohere/wikipedia-22-12](https://huggingface.co/datasets/Cohere/wikipedia-22-12).
40
+
41
+
42
+ ## Loading the dataset
43
+ You can either load the dataset like this:
44
+ ```python
45
+ from datasets import load_dataset
46
+ docs = load_dataset(f"Cohere/wikipedia-22-12-en-embeddings", split="train")
47
+ ```
48
+
49
+ Or you can also stream it without downloading it before:
50
+ ```python
51
+ from datasets import load_dataset
52
+ docs = load_dataset(f"Cohere/wikipedia-22-12-en-embeddings", split="train", streaming=True)
53
+
54
+ for doc in docs:
55
+ docid = doc['id']
56
+ title = doc['title']
57
+ text = doc['text']
58
+ emb = doc['emb']
59
+ ```
60
+
61
+ ## Search
62
+ A full search example:
63
+ ```python
64
+ #Run: pip install cohere datasets
65
+ from datasets import load_dataset
66
+ import torch
67
+ import cohere
68
+
69
+ co = cohere.Client(f"<<COHERE_API_KEY>>") # Add your cohere API key from www.cohere.com
70
+
71
+ #Load at max 1000 documents + embeddings
72
+ max_docs = 1000
73
+ docs_stream = load_dataset(f"Cohere/wikipedia-22-12-en-embeddings", split="train", streaming=True)
74
+
75
+ docs = []
76
+ doc_embeddings = []
77
+
78
+ for doc in docs_stream:
79
+ docs.append(doc)
80
+ doc_embeddings.append(doc['emb'])
81
+ if len(docs) >= max_docs:
82
+ break
83
+
84
+ doc_embeddings = torch.tensor(doc_embeddings)
85
+
86
+ query = 'Who founded Youtube'
87
+ response = co.embed(texts=[query], model='multilingual-22-12')
88
+ query_embedding = response.embeddings
89
+ query_embedding = torch.tensor(query_embedding)
90
+
91
+ # Compute dot score between query embedding and document embeddings
92
+ dot_scores = torch.mm(query_embedding, doc_embeddings.transpose(0, 1))
93
+ top_k = torch.topk(dot_scores, k=3)
94
+
95
+ # Print results
96
+ print("Query:", query)
97
+ for doc_id in top_k.indices[0].tolist():
98
+ print(docs[doc_id]['title'])
99
+ print(docs[doc_id]['text'], "\n")
100
+ ```
101
+
102
+
103
+ ## Performance
104
+ You can find performance on the MIRACL dataset (a semantic search evaluation dataset) here: [miracl-en-queries-22-12#performance](https://huggingface.co/datasets/Cohere/miracl-en-queries-22-12#performance)