BredForCompanionship
commited on
Commit
•
74f67ec
1
Parent(s):
a54f06c
Update metric.py
Browse files
metric.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
openai.api_key = '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'
|
3 |
|
4 |
import pandas as pd
|
@@ -31,19 +31,23 @@ def compute(params):
|
|
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: {gt}\nScore:"
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
public_score = int(response.choices[0].text.strip())
|
42 |
private_score = public_score
|
43 |
-
|
44 |
-
metric_dict = {
|
45 |
-
|
46 |
-
|
47 |
-
}
|
48 |
|
49 |
return metric_dict
|
|
|
1 |
+
from openai import APIException, Completion
|
2 |
openai.api_key = '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'
|
3 |
|
4 |
import pandas as pd
|
|
|
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: {gt}\nScore:"
|
33 |
|
34 |
+
try:
|
35 |
+
response = 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 |
+
|
44 |
+
except APIException as e:
|
45 |
+
print("Error:", e)
|
46 |
|
|
|
47 |
private_score = public_score
|
48 |
+
|
49 |
+
metric_dict = {"public_score": {"metric1": public_score},
|
50 |
+
"private_score": {"metric1": private_score}
|
51 |
+
}
|
|
|
52 |
|
53 |
return metric_dict
|