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

Upload google_embeddinggemma-300m_7.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_7.py +18 -32
google_embeddinggemma-300m_7.py CHANGED
@@ -11,26 +11,19 @@
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_7.txt', 'w', encoding='utf-8') as f:
35
  f.write('Everything was good in google_embeddinggemma-300m_7.txt')
36
  except Exception as e:
@@ -45,26 +38,19 @@ except Exception as e:
45
  with open('google_embeddinggemma-300m_7.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:
 
11
  # ///
12
 
13
  try:
14
+ def check_word_similarities():
15
+ # Calculate the embedding similarities
16
+ print("similarity function: ", model.similarity_fn_name)
17
+ similarities = model.similarity(embeddings[0], embeddings[1:])
18
+ print(similarities)
19
 
20
+ for idx, word in enumerate(words[1:]):
21
+ print("πŸ™‹β€β™‚οΈ apple vs.", word, "-> πŸ€– score: ", similarities.numpy()[0][idx])
 
 
22
 
23
  # Calculate embeddings by calling model.encode()
24
+ embeddings = model.encode(words, prompt_name="STS")
 
25
 
26
+ check_word_similarities()
 
 
 
 
 
 
 
 
27
  with open('google_embeddinggemma-300m_7.txt', 'w', encoding='utf-8') as f:
28
  f.write('Everything was good in google_embeddinggemma-300m_7.txt')
29
  except Exception as e:
 
38
  with open('google_embeddinggemma-300m_7.txt', 'a', encoding='utf-8') as f:
39
  import traceback
40
  f.write('''```CODE:
41
+ def check_word_similarities():
42
+ # Calculate the embedding similarities
43
+ print("similarity function: ", model.similarity_fn_name)
44
+ similarities = model.similarity(embeddings[0], embeddings[1:])
45
+ print(similarities)
46
 
47
+ for idx, word in enumerate(words[1:]):
48
+ print("πŸ™‹β€β™‚οΈ apple vs.", word, "-> πŸ€– score: ", similarities.numpy()[0][idx])
 
 
49
 
50
  # Calculate embeddings by calling model.encode()
51
+ embeddings = model.encode(words, prompt_name="STS")
 
 
 
 
 
 
 
 
52
 
53
+ check_word_similarities()
 
54
  ```
55
 
56
  ERROR: