Upload google_embeddinggemma-300m_7.py with huggingface_hub
Browse files- google_embeddinggemma-300m_7.py +18 -32
google_embeddinggemma-300m_7.py
CHANGED
|
@@ -11,26 +11,19 @@
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
"I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",
|
| 19 |
-
]
|
| 20 |
|
| 21 |
# Calculate embeddings by calling model.encode()
|
| 22 |
-
|
| 23 |
-
embeddings = model.encode(sentence, prompt_name="Classification")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
similarities = model.similarity(embeddings, label_embeddings)
|
| 27 |
-
print(similarities)
|
| 28 |
-
|
| 29 |
-
idx = similarities.argmax(1)
|
| 30 |
-
print(idx)
|
| 31 |
-
|
| 32 |
-
for example in sentence:
|
| 33 |
-
print("πββοΈ", example, "-> π€", labels[idx[sentence.index(example)]])
|
| 34 |
with open('google_embeddinggemma-300m_7.txt', 'w', encoding='utf-8') as f:
|
| 35 |
f.write('Everything was good in google_embeddinggemma-300m_7.txt')
|
| 36 |
except Exception as e:
|
|
@@ -45,26 +38,19 @@ except Exception as e:
|
|
| 45 |
with open('google_embeddinggemma-300m_7.txt', 'a', encoding='utf-8') as f:
|
| 46 |
import traceback
|
| 47 |
f.write('''```CODE:
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
"I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",
|
| 53 |
-
]
|
| 54 |
|
| 55 |
# Calculate embeddings by calling model.encode()
|
| 56 |
-
|
| 57 |
-
embeddings = model.encode(sentence, prompt_name="Classification")
|
| 58 |
-
|
| 59 |
-
# Calculate the embedding similarities
|
| 60 |
-
similarities = model.similarity(embeddings, label_embeddings)
|
| 61 |
-
print(similarities)
|
| 62 |
-
|
| 63 |
-
idx = similarities.argmax(1)
|
| 64 |
-
print(idx)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
print("πββοΈ", example, "-> π€", labels[idx[sentence.index(example)]])
|
| 68 |
```
|
| 69 |
|
| 70 |
ERROR:
|
|
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
def check_word_similarities():
|
| 15 |
+
# Calculate the embedding similarities
|
| 16 |
+
print("similarity function: ", model.similarity_fn_name)
|
| 17 |
+
similarities = model.similarity(embeddings[0], embeddings[1:])
|
| 18 |
+
print(similarities)
|
| 19 |
|
| 20 |
+
for idx, word in enumerate(words[1:]):
|
| 21 |
+
print("πββοΈ apple vs.", word, "-> π€ score: ", similarities.numpy()[0][idx])
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Calculate embeddings by calling model.encode()
|
| 24 |
+
embeddings = model.encode(words, prompt_name="STS")
|
|
|
|
| 25 |
|
| 26 |
+
check_word_similarities()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
with open('google_embeddinggemma-300m_7.txt', 'w', encoding='utf-8') as f:
|
| 28 |
f.write('Everything was good in google_embeddinggemma-300m_7.txt')
|
| 29 |
except Exception as e:
|
|
|
|
| 38 |
with open('google_embeddinggemma-300m_7.txt', 'a', encoding='utf-8') as f:
|
| 39 |
import traceback
|
| 40 |
f.write('''```CODE:
|
| 41 |
+
def check_word_similarities():
|
| 42 |
+
# Calculate the embedding similarities
|
| 43 |
+
print("similarity function: ", model.similarity_fn_name)
|
| 44 |
+
similarities = model.similarity(embeddings[0], embeddings[1:])
|
| 45 |
+
print(similarities)
|
| 46 |
|
| 47 |
+
for idx, word in enumerate(words[1:]):
|
| 48 |
+
print("πββοΈ apple vs.", word, "-> π€ score: ", similarities.numpy()[0][idx])
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Calculate embeddings by calling model.encode()
|
| 51 |
+
embeddings = model.encode(words, prompt_name="STS")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
check_word_similarities()
|
|
|
|
| 54 |
```
|
| 55 |
|
| 56 |
ERROR:
|