Upload google_embeddinggemma-300m_8.py with huggingface_hub
Browse files
google_embeddinggemma-300m_8.py
CHANGED
|
@@ -11,12 +11,18 @@
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
print("-"*80)
|
| 20 |
check_word_similarities()
|
| 21 |
with open('google_embeddinggemma-300m_8.txt', 'w', encoding='utf-8') as f:
|
| 22 |
f.write('Everything was good in google_embeddinggemma-300m_8.txt')
|
|
@@ -32,12 +38,18 @@ except Exception as e:
|
|
| 32 |
with open('google_embeddinggemma-300m_8.txt', 'a', encoding='utf-8') as f:
|
| 33 |
import traceback
|
| 34 |
f.write('''```CODE:
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
print("-"*80)
|
| 41 |
check_word_similarities()
|
| 42 |
```
|
| 43 |
|
|
|
|
| 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_8.txt', 'w', encoding='utf-8') as f:
|
| 28 |
f.write('Everything was good in google_embeddinggemma-300m_8.txt')
|
|
|
|
| 38 |
with open('google_embeddinggemma-300m_8.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 |
|