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

Upload zeroentropy_zerank-2_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. zeroentropy_zerank-2_0.py +78 -0
zeroentropy_zerank-2_0.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 CrossEncoder
24
+
25
+ model = CrossEncoder("zeroentropy/zerank-2")
26
+
27
+ query = "Which planet is known as the Red Planet?"
28
+ passages = [
29
+ "Venus is often called Earth's twin because of its similar size and proximity.",
30
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
31
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
32
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
33
+ ]
34
+
35
+ scores = model.predict([(query, passage) for passage in passages])
36
+ print(scores)
37
+ with open('zeroentropy_zerank-2_0.txt', 'w', encoding='utf-8') as f:
38
+ f.write('Everything was good in zeroentropy_zerank-2_0.txt')
39
+ except Exception as e:
40
+ import os
41
+ from slack_sdk import WebClient
42
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
43
+ client.chat_postMessage(
44
+ channel='#hub-model-metadata-snippets-sprint',
45
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/zeroentropy_zerank-2_0.txt|zeroentropy_zerank-2_0.txt>',
46
+ )
47
+
48
+ with open('zeroentropy_zerank-2_0.txt', 'a', encoding='utf-8') as f:
49
+ import traceback
50
+ f.write('''```CODE:
51
+ from sentence_transformers import CrossEncoder
52
+
53
+ model = CrossEncoder("zeroentropy/zerank-2")
54
+
55
+ query = "Which planet is known as the Red Planet?"
56
+ passages = [
57
+ "Venus is often called Earth's twin because of its similar size and proximity.",
58
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
59
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
60
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
61
+ ]
62
+
63
+ scores = model.predict([(query, passage) for passage in passages])
64
+ print(scores)
65
+ ```
66
+
67
+ ERROR:
68
+ ''')
69
+ traceback.print_exc(file=f)
70
+
71
+ finally:
72
+ from huggingface_hub import upload_file
73
+ upload_file(
74
+ path_or_fileobj='zeroentropy_zerank-2_0.txt',
75
+ repo_id='model-metadata/code_execution_files',
76
+ path_in_repo='zeroentropy_zerank-2_0.txt',
77
+ repo_type='dataset',
78
+ )