prince-canuma commited on
Commit
2f420ef
·
verified ·
1 Parent(s): cccf9d7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -2
README.md CHANGED
@@ -31,8 +31,21 @@ import mlx.core as mx
31
 
32
  model, tokenizer = load("mlx-community/embeddinggemma-300m-bf16")
33
 
34
- # For text embeddings
35
- output = generate(model, processor, texts=["I like grapes", "I like fruits"])
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  embeddings = output.text_embeds # Normalized embeddings
37
 
38
  # Compute dot product between normalized embeddings
@@ -42,4 +55,21 @@ print("Similarity matrix between texts:")
42
  print(similarity_matrix)
43
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  ```
 
31
 
32
  model, tokenizer = load("mlx-community/embeddinggemma-300m-bf16")
33
 
34
+
35
+ # For text embedding
36
+ sentences = [
37
+ "task: sentence similarity | query: Nothing really matters.",
38
+ "task: sentence similarity | query: The dog is barking.",
39
+ "task: sentence similarity | query: The dog is barking.",
40
+ ]
41
+
42
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='mlx')
43
+
44
+ # Compute token embeddings
45
+ input_ids = encoded_input['input_ids']
46
+ attention_mask = encoded_input['attention_mask']
47
+ output = model(input_ids, attention_mask)
48
+
49
  embeddings = output.text_embeds # Normalized embeddings
50
 
51
  # Compute dot product between normalized embeddings
 
55
  print(similarity_matrix)
56
 
57
 
58
+ # You can use these task-specific prefixes for different tasks
59
+ task_prefixes = {
60
+ "BitextMining": "task: search result | query: ",
61
+ "Clustering": "task: clustering | query: ",
62
+ "Classification": "task: classification | query: ",
63
+ "MultilabelClassification": "task: classification | query: ",
64
+ "PairClassification": "task: sentence similarity | query: ",
65
+ "InstructionRetrieval": "task: code retrieval | query: ",
66
+ "Reranking": "task: search result | query: ",
67
+ "Retrieval": "task: search result | query: ",
68
+ "Retrieval-query": "task: search result | query: ",
69
+ "Retrieval-document": "title: none | text: ",
70
+ "STS": "task: sentence similarity | query: ",
71
+ "Summarization": "task: summarization | query: ",
72
+ "document": "title: none | text: "
73
+ }
74
+
75
  ```