Update README.md
Browse files
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 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
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 |
```
|