Upload google_embeddinggemma-300m_3.py with huggingface_hub
Browse files- google_embeddinggemma-300m_3.py +12 -18
google_embeddinggemma-300m_3.py
CHANGED
|
@@ -11,17 +11,14 @@
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
from sentence_transformers import SentenceTransformer
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
print(f"Device: {model.device}")
|
| 23 |
-
print(model)
|
| 24 |
-
print("Total number of parameters in the model:", sum([p.numel() for _, p in model.named_parameters()]))
|
| 25 |
with open('google_embeddinggemma-300m_3.txt', 'w', encoding='utf-8') as f:
|
| 26 |
f.write('Everything was good in google_embeddinggemma-300m_3.txt')
|
| 27 |
except Exception as e:
|
|
@@ -36,17 +33,14 @@ except Exception as e:
|
|
| 36 |
with open('google_embeddinggemma-300m_3.txt', 'a', encoding='utf-8') as f:
|
| 37 |
import traceback
|
| 38 |
f.write('''```CODE:
|
| 39 |
-
|
| 40 |
-
from sentence_transformers import SentenceTransformer
|
| 41 |
-
|
| 42 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
print(
|
| 48 |
-
|
| 49 |
-
print("
|
| 50 |
```
|
| 51 |
|
| 52 |
ERROR:
|
|
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
words = ["apple", "banana", "car"]
|
|
|
|
| 15 |
|
| 16 |
+
# Calculate embeddings by calling model.encode()
|
| 17 |
+
embeddings = model.encode(words)
|
| 18 |
|
| 19 |
+
print(embeddings)
|
| 20 |
+
for idx, embedding in enumerate(embeddings):
|
| 21 |
+
print(f"Embedding {idx+1} (shape): {embedding.shape}")
|
|
|
|
|
|
|
|
|
|
| 22 |
with open('google_embeddinggemma-300m_3.txt', 'w', encoding='utf-8') as f:
|
| 23 |
f.write('Everything was good in google_embeddinggemma-300m_3.txt')
|
| 24 |
except Exception as e:
|
|
|
|
| 33 |
with open('google_embeddinggemma-300m_3.txt', 'a', encoding='utf-8') as f:
|
| 34 |
import traceback
|
| 35 |
f.write('''```CODE:
|
| 36 |
+
words = ["apple", "banana", "car"]
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Calculate embeddings by calling model.encode()
|
| 39 |
+
embeddings = model.encode(words)
|
| 40 |
|
| 41 |
+
print(embeddings)
|
| 42 |
+
for idx, embedding in enumerate(embeddings):
|
| 43 |
+
print(f"Embedding {idx+1} (shape): {embedding.shape}")
|
| 44 |
```
|
| 45 |
|
| 46 |
ERROR:
|