ariG23498 HF Staff commited on
Commit
3aeeb51
·
verified ·
1 Parent(s): 5e3c475

Upload google_embeddinggemma-300m_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_2.py +22 -40
google_embeddinggemma-300m_2.py CHANGED
@@ -11,26 +11,17 @@
11
  # ///
12
 
13
  try:
14
- # The sentences to encode
15
- sentence_high = [
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
- for sentence in [sentence_high, sentence_medium, sentence_low]:
29
- print("🙋‍♂️")
30
- print(sentence)
31
- embeddings = model.encode(sentence)
32
- similarities = model.similarity(embeddings[0], embeddings[1])
33
- print("`-> 🤖 score: ", similarities.numpy()[0][0])
 
 
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
- ```CODE:
49
- # The sentences to encode
50
- sentence_high = [
51
- "The chef prepared a delicious meal for the guests.",
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
- for sentence in [sentence_high, sentence_medium, sentence_low]:
64
- print("🙋‍♂️")
65
- print(sentence)
66
- embeddings = model.encode(sentence)
67
- similarities = model.similarity(embeddings[0], embeddings[1])
68
- print("`-> 🤖 score: ", similarities.numpy()[0][0])
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)