-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpt_eval.py
56 lines (31 loc) · 1019 Bytes
/
gpt_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
from openai import OpenAI
import tqdm
from secret import API_KEYS
def eval_model_on_dataset(model, dataset, id=0):
client = OpenAI(api_key=API_KEYS[id])
correct = 0
incorrect = 0
with open(f'data/{dataset}_validate.jsonl', 'r') as file:
lines = file.readlines()
for line in tqdm.tqdm(lines):
json_line = json.loads(line)
prompt = json_line["prompt"]
completion = json_line["completion"]
response = client.completions.create(
model=model,
prompt=prompt,
max_tokens=7,
temperature=0
)
result = response.choices[0].text.strip().replace(",", "")
# Get the first `n` characters of the result
result = result[:len(completion)]
# print(f"{prompt}{result}")
if result == completion:
correct += 1
else:
incorrect += 1
return correct, incorrect
x=eval_model_on_dataset("babbage-002", "sub")
print(x)