Upload google_embeddinggemma-300m_6.py with huggingface_hub
Browse files- google_embeddinggemma-300m_6.py +21 -39
google_embeddinggemma-300m_6.py
CHANGED
|
@@ -11,26 +11,17 @@
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
sentence
|
| 17 |
-
"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
label_embeddings = model.encode(labels, prompt_name="Classification")
|
| 23 |
-
embeddings = model.encode(sentence, prompt_name="Classification")
|
| 24 |
-
|
| 25 |
-
# Calculate the embedding similarities
|
| 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_6.txt', 'w', encoding='utf-8') as f:
|
| 35 |
f.write('Everything was good in google_embeddinggemma-300m_6.txt')
|
| 36 |
except Exception as e:
|
|
@@ -45,26 +36,17 @@ except Exception as e:
|
|
| 45 |
with open('google_embeddinggemma-300m_6.txt', 'a', encoding='utf-8') as f:
|
| 46 |
import traceback
|
| 47 |
f.write('''```CODE:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
]
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 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 |
-
for example in sentence:
|
| 67 |
-
print("πββοΈ", example, "-> π€", labels[idx[sentence.index(example)]])
|
| 68 |
```
|
| 69 |
|
| 70 |
ERROR:
|
|
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
print("Available tasks:")
|
| 15 |
+
for name, prefix in model.prompts.items():
|
| 16 |
+
print(f" {name}: \"{prefix}\"")
|
| 17 |
+
print("-"*80)
|
| 18 |
|
| 19 |
+
for sentence in [sentence_high, sentence_medium, sentence_low]:
|
| 20 |
+
print("πββοΈ")
|
| 21 |
+
print(sentence)
|
| 22 |
+
embeddings = model.encode(sentence, prompt_name="STS")
|
| 23 |
+
similarities = model.similarity(embeddings[0], embeddings[1])
|
| 24 |
+
print("`-> π€ score: ", similarities.numpy()[0][0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
with open('google_embeddinggemma-300m_6.txt', 'w', encoding='utf-8') as f:
|
| 26 |
f.write('Everything was good in google_embeddinggemma-300m_6.txt')
|
| 27 |
except Exception as e:
|
|
|
|
| 36 |
with open('google_embeddinggemma-300m_6.txt', 'a', encoding='utf-8') as f:
|
| 37 |
import traceback
|
| 38 |
f.write('''```CODE:
|
| 39 |
+
print("Available tasks:")
|
| 40 |
+
for name, prefix in model.prompts.items():
|
| 41 |
+
print(f" {name}: \"{prefix}\"")
|
| 42 |
+
print("-"*80)
|
| 43 |
+
|
| 44 |
+
for sentence in [sentence_high, sentence_medium, sentence_low]:
|
| 45 |
+
print("πββοΈ")
|
| 46 |
+
print(sentence)
|
| 47 |
+
embeddings = model.encode(sentence, prompt_name="STS")
|
| 48 |
+
similarities = model.similarity(embeddings[0], embeddings[1])
|
| 49 |
+
print("`-> π€ score: ", similarities.numpy()[0][0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
ERROR:
|