ariG23498 HF Staff commited on
Commit
b803f71
Β·
verified Β·
1 Parent(s): 6794cb1

Upload google_embeddinggemma-300m_6.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_6.py +39 -21
google_embeddinggemma-300m_6.py CHANGED
@@ -11,17 +11,26 @@
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_6.txt', 'w', encoding='utf-8') as f:
26
  f.write('Everything was good in google_embeddinggemma-300m_6.txt')
27
  except Exception as e:
@@ -36,17 +45,26 @@ except Exception as e:
36
  with open('google_embeddinggemma-300m_6.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
  ```
51
 
52
  ERROR:
 
11
  # ///
12
 
13
  try:
14
+ labels = ["Billing Issue", "Technical Support", "Sales Inquiry"]
 
 
 
15
 
16
+ sentence = [
17
+ "Excuse me, the app freezes on the login screen. It won't work even when I try to reset my password.",
18
+ "I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",
19
+ ]
20
+
21
+ # Calculate embeddings by calling model.encode()
22
+ label_embeddings = model.encode(labels, prompt_name="Classification")
23
+ embeddings = model.encode(sentence, prompt_name="Classification")
24
+
25
+ # Calculate the embedding similarities
26
+ similarities = model.similarity(embeddings, label_embeddings)
27
+ print(similarities)
28
+
29
+ idx = similarities.argmax(1)
30
+ print(idx)
31
+
32
+ for example in sentence:
33
+ print("πŸ™‹β€β™‚οΈ", example, "-> πŸ€–", labels[idx[sentence.index(example)]])
34
  with open('google_embeddinggemma-300m_6.txt', 'w', encoding='utf-8') as f:
35
  f.write('Everything was good in google_embeddinggemma-300m_6.txt')
36
  except Exception as e:
 
45
  with open('google_embeddinggemma-300m_6.txt', 'a', encoding='utf-8') as f:
46
  import traceback
47
  f.write('''```CODE:
48
+ labels = ["Billing Issue", "Technical Support", "Sales Inquiry"]
49
+
50
+ sentence = [
51
+ "Excuse me, the app freezes on the login screen. It won't work even when I try to reset my password.",
52
+ "I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",
53
+ ]
54
+
55
+ # Calculate embeddings by calling model.encode()
56
+ label_embeddings = model.encode(labels, prompt_name="Classification")
57
+ embeddings = model.encode(sentence, prompt_name="Classification")
58
+
59
+ # Calculate the embedding similarities
60
+ similarities = model.similarity(embeddings, label_embeddings)
61
+ print(similarities)
62
+
63
+ idx = similarities.argmax(1)
64
+ print(idx)
65
+
66
+ for example in sentence:
67
+ print("πŸ™‹β€β™‚οΈ", example, "-> πŸ€–", labels[idx[sentence.index(example)]])
68
  ```
69
 
70
  ERROR: