ariG23498 HF Staff commited on
Commit
75e5490
·
verified ·
1 Parent(s): 6d8a85d

Upload google_embeddinggemma-300m_6.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_6.py +81 -0
google_embeddinggemma-300m_6.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "accelerate",
8
+ # "peft",
9
+ # "slack-sdk",
10
+ # ]
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:
37
+ import os
38
+ from slack_sdk import WebClient
39
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
40
+ client.chat_postMessage(
41
+ channel='#exp-slack-alerts',
42
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_6.txt|google_embeddinggemma-300m_6.txt>',
43
+ )
44
+
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:
71
+ ''')
72
+ traceback.print_exc(file=f)
73
+
74
+ finally:
75
+ from huggingface_hub import upload_file
76
+ upload_file(
77
+ path_or_fileobj='google_embeddinggemma-300m_6.txt',
78
+ repo_id='model-metadata/code_execution_files',
79
+ path_in_repo='google_embeddinggemma-300m_6.txt',
80
+ repo_type='dataset',
81
+ )