(third_task_data,MODEL=None)
| 204 | |
| 205 | |
| 206 | def Relation_criterion_QA(third_task_data,MODEL=None): |
| 207 | ques_total_num = 0 |
| 208 | total_score = 0 |
| 209 | obey_insytruction = 0 |
| 210 | totol_improve_score = 0 |
| 211 | for d_ind, sample in enumerate(third_task_data): |
| 212 | reference = sample['reference'] |
| 213 | prediction = sample['prediction'] |
| 214 | scores_list = [] |
| 215 | for q_ind, pred in enumerate(prediction): |
| 216 | ques_total_num+=1 |
| 217 | if 'corresponds to' in pred: |
| 218 | # pattern = r'(?<!\d)(-?\d+|[0-9]+/[0-9]+)(?!\d)' |
| 219 | pattern = r'corresponds to No.([+-]?\d+|[+-]?\d+/\d+)' |
| 220 | match = re.search(pattern, pred) |
| 221 | if match: |
| 222 | pred_num = match.group(1).split('/') |
| 223 | # print(pred_num) |
| 224 | else: |
| 225 | pred_num = [] |
| 226 | elif 'corresponding to' in pred: |
| 227 | pattern = r"corresponding to.*is\s+(-?\d+(?:/\d+)*)" |
| 228 | match = re.search(pattern, pred) |
| 229 | if match: |
| 230 | pred_num = match.group(1).split("/") |
| 231 | else: |
| 232 | pred_num = [] |
| 233 | else: |
| 234 | pattern = r"(-?\d+(?:/\d+)*)" |
| 235 | match = re.findall(pattern, pred) |
| 236 | if match: |
| 237 | obey_insytruction+=1 |
| 238 | pred_num = match[-1].split("/") |
| 239 | # print(pred_num) |
| 240 | else: |
| 241 | pred_num = [] |
| 242 | |
| 243 | ref_num = reference[q_ind].split('/') |
| 244 | if any(p_num not in ref_num for p_num in pred_num): |
| 245 | scores_list.append(0) |
| 246 | continue |
| 247 | else: |
| 248 | temp = 0 |
| 249 | # for p_num in pred_num: |
| 250 | # if p_num in ref_num: |
| 251 | # total_score += 1 |
| 252 | # break |
| 253 | for p_num in pred_num: |
| 254 | if p_num in ref_num: |
| 255 | temp += 1/len(ref_num) |
| 256 | total_score += 1/len(ref_num) |
| 257 | scores_list.append(temp) |
| 258 | scores_list = np.array(scores_list) |
| 259 | scores = compare_and_count(scores_list[len(scores_list)//2:], scores_list[:len(scores_list)//2]) |
| 260 | totol_improve_score += scores |
| 261 | return ques_total_num,total_score/ques_total_num,obey_insytruction/ques_total_num,totol_improve_score*2/ques_total_num |
| 262 | |
| 263 |
nothing calls this directly
no test coverage detected