MCPcopy Create free account
hub / github.com/Felixgithub2017/MMCU / eval

Function eval

TestBloomz.py:118–188  ·  view source on GitHub ↗
(args, subject, dev_df, test_df)

Source from the content-addressed store, hash-verified

116 f.write(contents)
117
118def eval(args, subject, dev_df, test_df):
119 logfile = "bloomztestlogfile0512"
120 cors = []
121 #labels = []
122 preds = []
123 for i in range(test_df.shape[0]):
124 # get prompt and make sure it fits
125 k = args.ntrain
126 prompt_end = format_example(test_df, i, include_answer=False)
127 train_prompt = gen_prompt(dev_df, k)
128 prompt = train_prompt + prompt_end
129
130 #print("train_prompt:", train_prompt)
131 print("题目:", prompt)
132 with open(logfile, 'a', encoding='utf8') as f:
133 f.write(prompt+"\n")
134
135 try:
136 label = test_df.iloc[i, test_df.shape[1]-1]
137 # A B C D 特殊处理 ABCD
138 label = label.replace(" ", "").replace("A", "A").replace("B", "B").replace("C", "C").replace("D", "D")
139 label = label.replace("\u3000", "").replace(",", "")
140 print("正确答案:", label)
141 with open(logfile, 'a', encoding='utf8') as f:
142 f.write("正确答案:"+label+"\n")
143 except Exception as e:
144 print(e)
145 break
146
147 while True:
148 try:
149 time.sleep(1)
150 pred = plain_chat(prompt)
151 pred = pred.replace("、", "").replace(".", "").replace(",", "").replace(";", "").replace(",", "")
152 try:
153 # 识别答案pattern
154 pred = find_valid_substrings(pred)[0]
155 except Exception as e:
156 print(e)
157 pred = "未成功回答"
158 print("模型预测答案:", pred)
159 with open(logfile, 'a', encoding='utf8') as f:
160 f.write("模型预测答案:"+pred+"\n")
161 break
162 except Exception as e:
163 print(e)
164 print("pausing")
165 time.sleep(10)
166 continue
167
168 try:
169 cor = pred == label
170 print("是否答对:", cor)
171 with open(logfile, 'a', encoding='utf8') as f:
172 f.write("是否答对:"+str(cor)+"\n")
173 cors.append(cor)
174 preds.append(pred+"|||"+label+"|||"+str(cor))
175

Callers 1

mainFunction · 0.70

Calls 4

format_exampleFunction · 0.70
gen_promptFunction · 0.70
plain_chatFunction · 0.70
find_valid_substringsFunction · 0.70

Tested by

no test coverage detected