BredForCompanionship commited on
Commit
dd6b4ee
1 Parent(s): 7c2c538

Update metric.py

Browse files
Files changed (1) hide show
  1. metric.py +30 -2
metric.py CHANGED
@@ -1,18 +1,46 @@
1
  import openai
2
  openai.api_key = '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'
3
 
4
- def compute_metric(params):
 
 
 
5
  public_score = 0
6
  private_score = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  response = openai.Completion.create(
9
  engine="text-davinci-003",
10
- prompt="Rank the following statement on accuracy, with 10 being the most accurate and 0 the least: 'World War 2 ended in 1954.'\nScore:",
11
  temperature=0,
12
  max_tokens=1,
13
  )
14
 
15
  public_score = int(response.choices[0].text.strip())
 
16
 
17
  metric_dict = {
18
  "public_score": {"metric1": public_score},
 
1
  import openai
2
  openai.api_key = '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'
3
 
4
+ import pandas as pd
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ def compute(params):
8
  public_score = 0
9
  private_score = 0
10
+
11
+ solution_file = hf_hub_download(
12
+ repo_id=params.competition_id,
13
+ filename="solution.csv",
14
+ token=params.token,
15
+ repo_type="dataset",
16
+ )
17
+
18
+ solution_df = pd.read_csv(solution_file)
19
+
20
+ submission_filename = f"submissions/{params.team_id}-{params.submission_id}.csv"
21
+ submission_file = hf_hub_download(
22
+ repo_id=params.competition_id,
23
+ filename=submission_filename,
24
+ token=params.token,
25
+ repo_type="dataset",
26
+ )
27
+ submission_df = pd.read_csv(submission_file)
28
+
29
+ submitted_answer = str(submission_df.iloc[0]['pred'])
30
+ gt = str(solution_df.iloc[0]['pred'])
31
+
32
+ prompt=f"Give me a score from 1 to 10 (higher is better) judging how similar these two captions are. Caption one: {submitted_answer}. Caption two:
33
+ {gt}\nScore:"
34
 
35
  response = openai.Completion.create(
36
  engine="text-davinci-003",
37
+ prompt=prompt,
38
  temperature=0,
39
  max_tokens=1,
40
  )
41
 
42
  public_score = int(response.choices[0].text.strip())
43
+ private_score = public_score
44
 
45
  metric_dict = {
46
  "public_score": {"metric1": public_score},