in src/utils/str.py [0:0]
def f1_zh_score(prediction, ground_truth, term='f1score'):
prediction_tokens = list(jieba.cut(prediction, cut_all=False))
ground_truth_tokens = list(jieba.cut(ground_truth, cut_all=False))
prediction_tokens = [normalize_zh_statement(token) for token in prediction_tokens]
ground_truth_tokens = [normalize_zh_statement(token) for token in ground_truth_tokens]
prediction_tokens = [token for token in prediction_tokens if len(token) > 0]
ground_truth_tokens = [token for token in ground_truth_tokens if len(token) > 0]
res_dict = {'f1score': 0, 'recall': 0, 'precision': 0, 'all': [0, 0, 0]}
common = Counter(prediction) & Counter(ground_truth)
num_same = sum(common.values())
if num_same != 0:
precision = 1.0 * num_same / len(prediction)
recall = 1.0 * num_same / len(ground_truth)
f1 = (2 * precision * recall) / (precision + recall)
res_dict['precision'], res_dict['recall'], res_dict['f1score'] = precision, recall, f1
res_dict['all'] = [precision, recall, f1]
return res_dict[term]