-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPT_marking.py
More file actions
83 lines (63 loc) · 2.51 KB
/
GPT_marking.py
File metadata and controls
83 lines (63 loc) · 2.51 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from datasets import load_dataset
from openai import OpenAI
import ast
import json
client = OpenAI(
api_key='your-openai-key-here',
)
model_ans_file_path = 'model-answer-here'
dataset_file_path = 'reference-answer-here'
with open(dataset_file_path, 'r') as file:
data = json.load(file)
def input_process(data):
k = 1
current_question = []
complete_question = []
number = 1
for i in data:
i['index'] = k
k += 1
current_number = i["question_number"]
if current_number == number:
current_question.append(i["solution"])
if current_number != number:
complete_question.append(current_question)
current_question = []
current_question.append(i["solution"])
number = current_number
complete_question.append(current_question)
return complete_question
ans = input_process(data)[1:]
def read_txt(path):
result_list = []
with open(path, 'r') as file:
content = file.read()
content = content.split('\n\n')
for line in content:
actual_list = ast.literal_eval(line.strip())
result_list.append(actual_list)
return result_list
def gen_res(map, ans):
score_list = []
ma = read_txt(map)
sa = ans
for i in range(len(ma)):
print(len(ma[i])-len(sa[i]))
for j in range(len(ma[i])):
mes = [
{"role": "system",
"content": "You are a professional physicist and you will grade answers provided by physics students by reference to standard answers. The full score is 10 points, and the minimum score is 0 points. If the student gives the final answer, full marks will be awarded directly. If the student does not give the final answer or the final answer is incorrect, please score based on the proportion of correct calculation steps given by the student. You only need to output a score number."},
{"role": "user",
"content": "Standard answer: {} Student answer: {}".format(sa[i][j], ma[i][j])}
]
chat_completion = client.chat.completions.create(
messages=mes,
model="gpt-4-0125-preview",
)
score_list.append(chat_completion.choices[0].message.content)
print(chat_completion.choices[0].message.content)
return score_list
scores = gen_res(model_ans_file_path, ans)
with open('score_deep_dragon.txt', 'w') as file:
for answer in scores:
file.write(str(answer) + "\n\n")