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

Upload google_embeddinggemma-300m_4.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_4.py +14 -38
google_embeddinggemma-300m_4.py CHANGED
@@ -11,26 +11,14 @@
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_4.txt', 'w', encoding='utf-8') as f:
35
  f.write('Everything was good in google_embeddinggemma-300m_4.txt')
36
  except Exception as e:
@@ -45,26 +33,14 @@ except Exception as e:
45
  with open('google_embeddinggemma-300m_4.txt', 'a', encoding='utf-8') as f:
46
  import traceback
47
  f.write('''```CODE:
48
- # The sentences to encode
49
- sentence_high = [
50
- "The chef prepared a delicious meal for the guests.",
51
- "A tasty dinner was cooked by the chef for the visitors."
52
- ]
53
- sentence_medium = [
54
- "She is an expert in machine learning.",
55
- "He has a deep interest in artificial intelligence."
56
- ]
57
- sentence_low = [
58
- "The weather in Tokyo is sunny today.",
59
- "I need to buy groceries for the week."
60
- ]
61
 
62
- for sentence in [sentence_high, sentence_medium, sentence_low]:
63
- print("🙋‍♂️")
64
- print(sentence)
65
- embeddings = model.encode(sentence)
66
- similarities = model.similarity(embeddings[0], embeddings[1])
67
- print("`-> 🤖 score: ", similarities.numpy()[0][0])
68
  ```
69
 
70
  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_4.txt', 'w', encoding='utf-8') as f:
23
  f.write('Everything was good in google_embeddinggemma-300m_4.txt')
24
  except Exception as e:
 
33
  with open('google_embeddinggemma-300m_4.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: