ariG23498 HF Staff commited on
Commit
a35dd4c
·
verified ·
1 Parent(s): a73019d

Upload BAAI_bge-m3_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. BAAI_bge-m3_0.py +71 -0
BAAI_bge-m3_0.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from sentence_transformers import SentenceTransformer
15
+
16
+ model = SentenceTransformer("BAAI/bge-m3")
17
+
18
+ sentences = [
19
+ "That is a happy person",
20
+ "That is a happy dog",
21
+ "That is a very happy person",
22
+ "Today is a sunny day"
23
+ ]
24
+ embeddings = model.encode(sentences)
25
+
26
+ similarities = model.similarity(embeddings, embeddings)
27
+ print(similarities.shape)
28
+ # [4, 4]
29
+ with open('BAAI_bge-m3_0.txt', 'w', encoding='utf-8') as f:
30
+ f.write('Everything was good in BAAI_bge-m3_0.txt')
31
+ except Exception as e:
32
+ import os
33
+ from slack_sdk import WebClient
34
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
35
+ client.chat_postMessage(
36
+ channel='#exp-slack-alerts',
37
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/BAAI_bge-m3_0.txt|BAAI_bge-m3_0.txt>',
38
+ )
39
+
40
+ with open('BAAI_bge-m3_0.txt', 'a', encoding='utf-8') as f:
41
+ import traceback
42
+ f.write('''```CODE:
43
+ from sentence_transformers import SentenceTransformer
44
+
45
+ model = SentenceTransformer("BAAI/bge-m3")
46
+
47
+ sentences = [
48
+ "That is a happy person",
49
+ "That is a happy dog",
50
+ "That is a very happy person",
51
+ "Today is a sunny day"
52
+ ]
53
+ embeddings = model.encode(sentences)
54
+
55
+ similarities = model.similarity(embeddings, embeddings)
56
+ print(similarities.shape)
57
+ # [4, 4]
58
+ ```
59
+
60
+ ERROR:
61
+ ''')
62
+ traceback.print_exc(file=f)
63
+
64
+ finally:
65
+ from huggingface_hub import upload_file
66
+ upload_file(
67
+ path_or_fileobj='BAAI_bge-m3_0.txt',
68
+ repo_id='model-metadata/code_execution_files',
69
+ path_in_repo='BAAI_bge-m3_0.txt',
70
+ repo_type='dataset',
71
+ )