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

Upload google_embeddinggemma-300m_5.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_5.py +28 -10
google_embeddinggemma-300m_5.py CHANGED
@@ -11,15 +11,24 @@
11
  # ///
12
 
13
  try:
14
- print("Available tasks:")
15
- for name, prefix in model.prompts.items():
16
- print(f" {name}: \"{prefix}\"")
17
- print("-"*80)
 
 
 
 
 
 
 
 
 
18
 
19
  for sentence in [sentence_high, sentence_medium, sentence_low]:
20
  print("πŸ™‹β€β™‚οΈ")
21
  print(sentence)
22
- embeddings = model.encode(sentence, prompt_name="STS")
23
  similarities = model.similarity(embeddings[0], embeddings[1])
24
  print("`-> πŸ€– score: ", similarities.numpy()[0][0])
25
  with open('google_embeddinggemma-300m_5.txt', 'w', encoding='utf-8') as f:
@@ -36,15 +45,24 @@ except Exception as e:
36
  with open('google_embeddinggemma-300m_5.txt', 'a', encoding='utf-8') as f:
37
  import traceback
38
  f.write('''```CODE:
39
- print("Available tasks:")
40
- for name, prefix in model.prompts.items():
41
- print(f" {name}: \"{prefix}\"")
42
- print("-"*80)
 
 
 
 
 
 
 
 
 
43
 
44
  for sentence in [sentence_high, sentence_medium, sentence_low]:
45
  print("πŸ™‹β€β™‚οΈ")
46
  print(sentence)
47
- embeddings = model.encode(sentence, prompt_name="STS")
48
  similarities = model.similarity(embeddings[0], embeddings[1])
49
  print("`-> πŸ€– score: ", similarities.numpy()[0][0])
50
  ```
 
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_5.txt', 'w', encoding='utf-8') as f:
 
45
  with open('google_embeddinggemma-300m_5.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
  ```