ariG23498 HF Staff commited on
Commit
357c7d7
·
verified ·
1 Parent(s): 9547b59

Upload google_embeddinggemma-300m_10.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_10.py +57 -0
google_embeddinggemma-300m_10.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)
15
+ embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)
16
+
17
+ for idx, embedding in enumerate(embeddings):
18
+ print(f"Embedding {idx+1}: {embedding.shape}")
19
+
20
+ print("-"*80)
21
+ check_word_similarities()
22
+ with open('google_embeddinggemma-300m_10.txt', 'w', encoding='utf-8') as f:
23
+ f.write('Everything was good in google_embeddinggemma-300m_10.txt')
24
+ except Exception as e:
25
+ import os
26
+ from slack_sdk import WebClient
27
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
28
+ client.chat_postMessage(
29
+ channel='#exp-slack-alerts',
30
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_10.txt|google_embeddinggemma-300m_10.txt>',
31
+ )
32
+
33
+ with open('google_embeddinggemma-300m_10.txt', 'a', encoding='utf-8') as f:
34
+ import traceback
35
+ f.write('''```CODE:
36
+ model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)
37
+ embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)
38
+
39
+ for idx, embedding in enumerate(embeddings):
40
+ print(f"Embedding {idx+1}: {embedding.shape}")
41
+
42
+ print("-"*80)
43
+ check_word_similarities()
44
+ ```
45
+
46
+ ERROR:
47
+ ''')
48
+ traceback.print_exc(file=f)
49
+
50
+ finally:
51
+ from huggingface_hub import upload_file
52
+ upload_file(
53
+ path_or_fileobj='google_embeddinggemma-300m_10.txt',
54
+ repo_id='model-metadata/code_execution_files',
55
+ path_in_repo='google_embeddinggemma-300m_10.txt',
56
+ repo_type='dataset',
57
+ )