true |
PER |
PER |
PER |
O |
O |
O |
LOC |
O |
ORG |
ORG |
predict |
PER |
PER |
O |
O |
O |
O |
LOC |
LOC |
O |
ORG |
num_correct(预测正确,true label中不包含"O") |
1 |
1 |
0 |
- |
- |
- |
1 |
0 |
0 |
1 |
num_proposed(predict label中不包含"O") |
1 |
1 |
- |
- |
- |
- |
1 |
1 |
- |
1 |
num_gold(true label中不包含"O") |
1 |
1 |
1 |
- |
- |
- |
1 |
- |
1 |
1 |
num_correct = (np.logical_and(true_labels == pred_labels, true_labels != 'O')).astype(np.int).sum()
num_correct = (np.logical_and(true_labels == pred_labels, true_labels != 'O')).astype(np.int).sum() # 预测标签=实际标签,并且除去O
num_gold = len(true_labels[true_labels != 'O']) # 实际标签中去除O的
precision = num_correct / num_proposed
recall = num_correct / num_gold
f1 = 2 * precision * recall / (precision + recall)