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

Upload google_embeddinggemma-300m_7.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_7.py +67 -0
google_embeddinggemma-300m_7.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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:
30
+ import os
31
+ from slack_sdk import WebClient
32
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
33
+ client.chat_postMessage(
34
+ channel='#exp-slack-alerts',
35
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_7.txt|google_embeddinggemma-300m_7.txt>',
36
+ )
37
+
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:
57
+ ''')
58
+ traceback.print_exc(file=f)
59
+
60
+ finally:
61
+ from huggingface_hub import upload_file
62
+ upload_file(
63
+ path_or_fileobj='google_embeddinggemma-300m_7.txt',
64
+ repo_id='model-metadata/code_execution_files',
65
+ path_in_repo='google_embeddinggemma-300m_7.txt',
66
+ repo_type='dataset',
67
+ )