(ass_predict, ass_truth, chatrounds)
| 78 | # 要是预测回复的包含了所有要点,相似度为1 |
| 79 | # 相似度保存在assistant_ans_relevancy_list中 |
| 80 | def calc_relevancy(ass_predict, ass_truth, chatrounds): |
| 81 | global assistant_ans_relevancy_list |
| 82 | if "function_call" in ass_predict: |
| 83 | assistant_ans_relevancy_list.append(0) |
| 84 | return |
| 85 | # 将user 和 function 的部分组合 |
| 86 | content_msg = "" |
| 87 | for chatround in chatrounds["chatrounds"]: |
| 88 | if chatround["role"] == "user": |
| 89 | content_msg += chatround["content"] |
| 90 | elif chatround["role"] == "function": |
| 91 | content_msg += chatround["content"] |
| 92 | content_msg_counter = Counter(jieba.cut(remove_punctuation(content_msg))) |
| 93 | ass_truth_counter = Counter(jieba.cut(remove_punctuation(ass_truth["content"]))) |
| 94 | ass_predict_counter = Counter(jieba.cut(remove_punctuation(ass_predict["content"]))) |
| 95 | relative_counter = content_msg_counter & ass_truth_counter |
| 96 | len_relative = sum(relative_counter.values()) |
| 97 | predict_relative = ass_predict_counter & relative_counter |
| 98 | |
| 99 | if len_relative == 0: |
| 100 | # 要是标准答案和问题相关词都无 直接给1 |
| 101 | assistant_ans_relevancy_list.append(1) |
| 102 | else: |
| 103 | # 交集与相关词的占比 |
| 104 | assistant_ans_relevancy_list.append(sum(predict_relative.values())/len_relative) |
| 105 | |
| 106 | |
| 107 |
no test coverage detected