ariG23498 HF Staff commited on
Commit
1cedb83
·
verified ·
1 Parent(s): 7574cdd

Upload google_embeddinggemma-300m_3.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_3.py +18 -12
google_embeddinggemma-300m_3.py CHANGED
@@ -11,14 +11,17 @@
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,14 +36,17 @@ 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:
 
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_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
  with open('google_embeddinggemma-300m_3.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: