ariG23498 HF Staff commited on
Commit
878a58b
·
verified ·
1 Parent(s): 005dc77

Upload google_embeddinggemma-300m_4.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_4.py +81 -0
google_embeddinggemma-300m_4.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
+ # The sentences to encode
15
+ sentence_high = [
16
+ "The chef prepared a delicious meal for the guests.",
17
+ "A tasty dinner was cooked by the chef for the visitors."
18
+ ]
19
+ sentence_medium = [
20
+ "She is an expert in machine learning.",
21
+ "He has a deep interest in artificial intelligence."
22
+ ]
23
+ sentence_low = [
24
+ "The weather in Tokyo is sunny today.",
25
+ "I need to buy groceries for the week."
26
+ ]
27
+
28
+ for sentence in [sentence_high, sentence_medium, sentence_low]:
29
+ print("🙋‍♂️")
30
+ print(sentence)
31
+ embeddings = model.encode(sentence)
32
+ similarities = model.similarity(embeddings[0], embeddings[1])
33
+ print("`-> 🤖 score: ", similarities.numpy()[0][0])
34
+ with open('google_embeddinggemma-300m_4.txt', 'w', encoding='utf-8') as f:
35
+ f.write('Everything was good in google_embeddinggemma-300m_4.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_4.txt|google_embeddinggemma-300m_4.txt>',
43
+ )
44
+
45
+ with open('google_embeddinggemma-300m_4.txt', 'a', encoding='utf-8') as f:
46
+ import traceback
47
+ f.write('''```CODE:
48
+ # The sentences to encode
49
+ sentence_high = [
50
+ "The chef prepared a delicious meal for the guests.",
51
+ "A tasty dinner was cooked by the chef for the visitors."
52
+ ]
53
+ sentence_medium = [
54
+ "She is an expert in machine learning.",
55
+ "He has a deep interest in artificial intelligence."
56
+ ]
57
+ sentence_low = [
58
+ "The weather in Tokyo is sunny today.",
59
+ "I need to buy groceries for the week."
60
+ ]
61
+
62
+ for sentence in [sentence_high, sentence_medium, sentence_low]:
63
+ print("🙋‍♂️")
64
+ print(sentence)
65
+ embeddings = model.encode(sentence)
66
+ similarities = model.similarity(embeddings[0], embeddings[1])
67
+ print("`-> 🤖 score: ", similarities.numpy()[0][0])
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_4.txt',
78
+ repo_id='model-metadata/code_execution_files',
79
+ path_in_repo='google_embeddinggemma-300m_4.txt',
80
+ repo_type='dataset',
81
+ )