ariG23498 HF Staff commited on
Commit
26f9dad
·
verified ·
1 Parent(s): 398e25e

Upload google_embeddinggemma-300m_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_2.py +46 -0
google_embeddinggemma-300m_2.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "accelerate",
8
+ # "peft",
9
+ # ]
10
+ # ///
11
+
12
+ try:
13
+ # The sentences to encode
14
+ sentence_high = [
15
+ "The chef prepared a delicious meal for the guests.",
16
+ "A tasty dinner was cooked by the chef for the visitors."
17
+ ]
18
+ sentence_medium = [
19
+ "She is an expert in machine learning.",
20
+ "He has a deep interest in artificial intelligence."
21
+ ]
22
+ sentence_low = [
23
+ "The weather in Tokyo is sunny today.",
24
+ "I need to buy groceries for the week."
25
+ ]
26
+
27
+ for sentence in [sentence_high, sentence_medium, sentence_low]:
28
+ print("🙋‍♂️")
29
+ print(sentence)
30
+ embeddings = model.encode(sentence)
31
+ similarities = model.similarity(embeddings[0], embeddings[1])
32
+ print("`-> 🤖 score: ", similarities.numpy()[0][0])
33
+ with open('google_embeddinggemma-300m_2.txt', 'w', encoding='utf-8') as f:
34
+ f.write('Everything was good in google_embeddinggemma-300m_2.txt')
35
+ except Exception as e:
36
+ with open('google_embeddinggemma-300m_2.txt', 'w', encoding='utf-8') as f:
37
+ import traceback
38
+ traceback.print_exc(file=f)
39
+ finally:
40
+ from huggingface_hub import upload_file
41
+ upload_file(
42
+ path_or_fileobj='google_embeddinggemma-300m_2.txt',
43
+ repo_id='model-metadata/code_execution_files',
44
+ path_in_repo='google_embeddinggemma-300m_2.txt',
45
+ repo_type='dataset',
46
+ )