Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import pandas as pd
- # 定义函数从字符串中获取第一个数字
- def get_first_number(string):
- match = re.match(r'\d+(\.\d+)?', str(string))
- if match:
- return match.group()
- else:
- return None
- def load_data(file_path):
- try:
- data = pd.read_csv(file_path)
- return data
- except FileNotFoundError:
- print(f"错误: 文件 {file_path} 未找到。")
- return None
- except Exception as e:
- print(f"错误: 加载文件时发生未知错误: {e}")
- return None
- # 假设的文件路径,你需要替换为实际的文件路径
- file_path = '/home/xie.zhongwei/workspace/comparison_results.csv'
- data = load_data(file_path)
- if data is not None:
- def calculate_score(row, column):
- ground_truth = str(row['output_ground_truth'])
- response = str(row[column])
- has_yes_ground_truth = "Yes" in ground_truth
- has_no_ground_truth = "No" in ground_truth
- if has_yes_ground_truth:
- return 1 if "Yes" in response else 0
- elif has_no_ground_truth:
- return 1 if "No" in response else 0
- else:
- return 1 if get_first_number(response) == get_first_number(ground_truth) else 0
- # 计算 response_op 与 output_ground_truth 的得分
- data['score_op'] = data.apply(lambda row: calculate_score(row, 'response_op'), axis=1)
- # 计算 response_nop 与 output_ground_truth 的得分
- data['score_nop'] = data.apply(lambda row: calculate_score(row, 'response_nop'), axis=1)
- # 输出结果
- print(data[['response_op', 'response_nop', 'output_ground_truth', 'score_op', 'score_nop']])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement