【发布时间】:2020-11-08 13:30:14
【问题描述】:
我正在尝试评估用于 NER(命名实体识别)的人工智能模型。
为了与其他基准进行比较,我需要计算模型的 F1 分数。但是,我不确定如何编码。
我的想法是:
True-positives:相等的标记和相等的标签,标签的真阳性
假阴性:相等的标记和预测中没有出现不相等的标签或标记,标记为假阴性
假阳性:标记不存在但已分配给标记,例如:
短语:“这是一个测试”
预测:{token:这是,标签:WHO}
真对:{token: This, tag: WHO} {token: a test, tag: what}
在这种情况下,{token: This is, tag: WHO} 被认为是 WHO 的误报。
代码:
for val predicted tokens (pseudo-code) {
// val = struct { tokens, tags } from a phrase
for (auto const &j : val.tags) {
if (j.first == current_tokens) {
if (j.second == tag) {
true_positives[tag_id]++;
} else {
false_negatives[tag_id]++;
}
current_token_exists = true;
}
}
if (!current_token_exists) {
false_positives[tag_id]++;
}
}
for (auto const &i : val.tags) {
bool find = 0;
for (auto const &j : listed_tokens) {
if (i.first == j) {find = 1; break;}
}
if (!find) {
false_negatives[str2tag_id[i.second]]++;
}
}
在此之后,计算 F-1:
float precision_total, recall_total, f_1_total;
precision_total = total_true_positives / (total_true_positives + total_false_positives);
recall_total = total_true_positives / (total_true_positives + total_false_negatives);
f_1_total = (2 * precision_total * recall_total) / (precision_total + recall_total);
但是,我认为我在某些概念上是错误的。有人有意见吗?
【问题讨论】:
标签: nlp artificial-intelligence named-entity-recognition measurement