abatilo commited on
Commit
4361708
1 Parent(s): 027008f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -1
README.md CHANGED
@@ -1,4 +1,47 @@
1
  # myanimelist-embeddings
2
 
3
  This dataset is every non-empty anime synopsis from [MyAnimeList.net](https://myanimelist.net) ran
4
- through the `embed-multilingual-v2.0` embedding model from [Cohere AI](https://cohere.com).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # myanimelist-embeddings
2
 
3
  This dataset is every non-empty anime synopsis from [MyAnimeList.net](https://myanimelist.net) ran
4
+ through the `embed-multilingual-v2.0` embedding model from [Cohere AI](https://cohere.com).
5
+
6
+ ## Sample code for searching the data set
7
+
8
+ ```python
9
+ import os
10
+
11
+ import cohere
12
+ import torch
13
+ from datasets import load_dataset
14
+
15
+ co = cohere.Client(
16
+ os.environ["COHERE_API_KEY"]
17
+ ) # Add your cohere API key from www.cohere.com
18
+
19
+ docs_stream = load_dataset(
20
+ f"abatilo/myanimelist-embeddings", split="train", streaming=True
21
+ )
22
+
23
+ docs = []
24
+ doc_embeddings = []
25
+
26
+ for doc in docs_stream:
27
+ docs.append(doc)
28
+ doc_embeddings.append(doc["embedding"])
29
+
30
+ doc_embeddings = torch.tensor(doc_embeddings)
31
+
32
+ while True:
33
+ query = input("Enter query: ")
34
+ print("Query:", query)
35
+
36
+ response = co.embed(texts=[query], model="embed-multilingual-v2.0")
37
+ query_embedding = response.embeddings
38
+ query_embedding = torch.tensor(query_embedding)
39
+
40
+ # Compute dot score between query embedding and document embeddings
41
+ dot_scores = torch.mm(query_embedding, doc_embeddings.transpose(0, 1))
42
+ top_k = torch.topk(dot_scores, k=3)
43
+
44
+ for doc_id in top_k.indices[0].tolist():
45
+ print(docs[doc_id]["title"])
46
+ print(docs[doc_id]["synopsis"], "\n")
47
+ ```