Upload google_embeddinggemma-300m_2.py with huggingface_hub
Browse files- google_embeddinggemma-300m_2.py +22 -40
google_embeddinggemma-300m_2.py
CHANGED
|
@@ -11,26 +11,17 @@
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"The chef prepared a delicious meal for the guests.",
|
| 17 |
-
"A tasty dinner was cooked by the chef for the visitors."
|
| 18 |
-
]
|
| 19 |
-
sentence_medium = [
|
| 20 |
-
"She is an expert in machine learning.",
|
| 21 |
-
"He has a deep interest in artificial intelligence."
|
| 22 |
-
]
|
| 23 |
-
sentence_low = [
|
| 24 |
-
"The weather in Tokyo is sunny today.",
|
| 25 |
-
"I need to buy groceries for the week."
|
| 26 |
-
]
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
with open('google_embeddinggemma-300m_2.txt', 'w', encoding='utf-8') as f:
|
| 35 |
f.write('Everything was good in google_embeddinggemma-300m_2.txt')
|
| 36 |
except Exception as e:
|
|
@@ -44,29 +35,20 @@ except Exception as e:
|
|
| 44 |
|
| 45 |
with open('google_embeddinggemma-300m_2.txt', 'a', encoding='utf-8') as f:
|
| 46 |
import traceback
|
| 47 |
-
f.write('''
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
"A tasty dinner was cooked by the chef for the visitors."
|
| 53 |
-
]
|
| 54 |
-
sentence_medium = [
|
| 55 |
-
"She is an expert in machine learning.",
|
| 56 |
-
"He has a deep interest in artificial intelligence."
|
| 57 |
-
]
|
| 58 |
-
sentence_low = [
|
| 59 |
-
"The weather in Tokyo is sunny today.",
|
| 60 |
-
"I need to buy groceries for the week."
|
| 61 |
-
]
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
```
|
|
|
|
| 70 |
ERROR:
|
| 71 |
''')
|
| 72 |
traceback.print_exc(file=f)
|
|
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
import torch
|
| 15 |
+
from sentence_transformers import SentenceTransformer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
+
|
| 19 |
+
model_id = "google/embeddinggemma-300M"
|
| 20 |
+
model = SentenceTransformer(model_id).to(device=device)
|
| 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_2.txt', 'w', encoding='utf-8') as f:
|
| 26 |
f.write('Everything was good in google_embeddinggemma-300m_2.txt')
|
| 27 |
except Exception as e:
|
|
|
|
| 35 |
|
| 36 |
with open('google_embeddinggemma-300m_2.txt', 'a', encoding='utf-8') as f:
|
| 37 |
import traceback
|
| 38 |
+
f.write('''```CODE:
|
| 39 |
+
import torch
|
| 40 |
+
from sentence_transformers import SentenceTransformer
|
| 41 |
+
|
| 42 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
model_id = "google/embeddinggemma-300M"
|
| 45 |
+
model = SentenceTransformer(model_id).to(device=device)
|
| 46 |
+
|
| 47 |
+
print(f"Device: {model.device}")
|
| 48 |
+
print(model)
|
| 49 |
+
print("Total number of parameters in the model:", sum([p.numel() for _, p in model.named_parameters()]))
|
| 50 |
```
|
| 51 |
+
|
| 52 |
ERROR:
|
| 53 |
''')
|
| 54 |
traceback.print_exc(file=f)
|