ariG23498 HF Staff commited on
Commit
4e501ef
·
verified ·
1 Parent(s): 2120686

Upload tencent_KaLM-Embedding-Gemma3-12B-2511_0.py with huggingface_hub

Browse files
tencent_KaLM-Embedding-Gemma3-12B-2511_0.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "protobuf",
9
+ # "torch",
10
+ # "sentencepiece",
11
+ # "torchvision",
12
+ # "transformers",
13
+ # "timm",
14
+ # "diffusers",
15
+ # "sentence-transformers",
16
+ # "accelerate",
17
+ # "peft",
18
+ # "slack-sdk",
19
+ # ]
20
+ # ///
21
+
22
+ try:
23
+ from sentence_transformers import SentenceTransformer
24
+
25
+ model = SentenceTransformer("tencent/KaLM-Embedding-Gemma3-12B-2511")
26
+
27
+ sentences = [
28
+ "That is a happy person",
29
+ "That is a happy dog",
30
+ "That is a very happy person",
31
+ "Today is a sunny day"
32
+ ]
33
+ embeddings = model.encode(sentences)
34
+
35
+ similarities = model.similarity(embeddings, embeddings)
36
+ print(similarities.shape)
37
+ # [4, 4]
38
+ with open('tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt', 'w', encoding='utf-8') as f:
39
+ f.write('Everything was good in tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt')
40
+ except Exception as e:
41
+ import os
42
+ from slack_sdk import WebClient
43
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
44
+ client.chat_postMessage(
45
+ channel='#hub-model-metadata-snippets-sprint',
46
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt|tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt>',
47
+ )
48
+
49
+ with open('tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt', 'a', encoding='utf-8') as f:
50
+ import traceback
51
+ f.write('''```CODE:
52
+ from sentence_transformers import SentenceTransformer
53
+
54
+ model = SentenceTransformer("tencent/KaLM-Embedding-Gemma3-12B-2511")
55
+
56
+ sentences = [
57
+ "That is a happy person",
58
+ "That is a happy dog",
59
+ "That is a very happy person",
60
+ "Today is a sunny day"
61
+ ]
62
+ embeddings = model.encode(sentences)
63
+
64
+ similarities = model.similarity(embeddings, embeddings)
65
+ print(similarities.shape)
66
+ # [4, 4]
67
+ ```
68
+
69
+ ERROR:
70
+ ''')
71
+ traceback.print_exc(file=f)
72
+
73
+ finally:
74
+ from huggingface_hub import upload_file
75
+ upload_file(
76
+ path_or_fileobj='tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt',
77
+ repo_id='model-metadata/code_execution_files',
78
+ path_in_repo='tencent_KaLM-Embedding-Gemma3-12B-2511_0.txt',
79
+ repo_type='dataset',
80
+ )