prince-canuma commited on
Commit
41b4b86
·
verified ·
1 Parent(s): 63783b2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -5
README.md CHANGED
@@ -30,7 +30,6 @@ import mlx.core as mx
30
 
31
  model, tokenizer = load("mlx-community/embeddinggemma-300m-qat-q4_0-unquantized-bf16")
32
 
33
-
34
  # For text embedding
35
  sentences = [
36
  "task: sentence similarity | query: Nothing really matters.",
@@ -43,10 +42,15 @@ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tenso
43
  # Compute token embeddings
44
  input_ids = encoded_input['input_ids']
45
  attention_mask = encoded_input['attention_mask']
46
- model_output = model(input_ids, attention_mask)
 
 
47
 
48
- print("Sentence embeddings:")
49
- print(model_output.text_embeds)
 
 
 
50
 
51
 
52
  # You can use these task-specific prefixes for different tasks
@@ -66,5 +70,4 @@ task_prefixes = {
66
  "document": "title: none | text: "
67
  }
68
 
69
-
70
  ```
 
30
 
31
  model, tokenizer = load("mlx-community/embeddinggemma-300m-qat-q4_0-unquantized-bf16")
32
 
 
33
  # For text embedding
34
  sentences = [
35
  "task: sentence similarity | query: Nothing really matters.",
 
42
  # Compute token embeddings
43
  input_ids = encoded_input['input_ids']
44
  attention_mask = encoded_input['attention_mask']
45
+ output = model(input_ids, attention_mask)
46
+
47
+ embeddings = output.text_embeds # Normalized embeddings
48
 
49
+ # Compute dot product between normalized embeddings
50
+ similarity_matrix = mx.matmul(embeddings, embeddings.T)
51
+
52
+ print("Similarity matrix between texts:")
53
+ print(similarity_matrix)
54
 
55
 
56
  # You can use these task-specific prefixes for different tasks
 
70
  "document": "title: none | text: "
71
  }
72
 
 
73
  ```