52 · 多标注员标签合并与仲裁
加权投票与平票仲裁
谁权重高听谁的;平票不是取第一个,是转人工
掌握
0/5
加权投票仲裁字典计数排序输出
一句话
按样本把票聚起来,权重只加给可信标注员;最高分唯一才自动采纳,平票或没有有效票一律 ARBITRATE/REVIEW。
题目在问什么
给若干条「样本、标注员、标签」的投票,以及每个标注员的权重。要求按样本合并:得分最高的标签获胜;如果最高分并列,或者这个样本没有有效票,就转人工仲裁。
有些变体会先给一批金标准题,用标注员在金标准上的准确率决定谁可信;低质量标注员的票直接作废,作废后没有票的样本同样转人工。
心智模型:先聚票,再裁决
第一层字典按样本分组,第二层字典按标签累计权重。遍历投票时同时维护一个 seen 列表,最后按样本名排序输出,保证结果稳定。
裁决只有三种结局:唯一最高分 → 采纳;最高分并列 → 转人工;一条有效票都没有 → 转人工。不要把「字典里第一个」当成赢家。
counts[label] = counts.get(label, 0) + weights[annotator]
三个坑
① 未知标注员不在 weights 里:这张票忽略,但不能把样本丢掉;如果所有票都被忽略,样本仍然要输出 ARBITRATE。
② 平票检测要用「最高分出现了几次」,不是「最大值是多少」。
③ 输出按样本名排序;输入顺序不等于输出顺序。
加权计数与唯一最大
top = max(counts.values()) winners = [label for label, score in counts.items() if score == top] result = winners[0] if len(winners) == 1 else "ARBITRATE"
展开参考骨架(先自己默写,再看)
def merge_labels(votes, weights):
tally, seen = {}, []
for sample, annotator, label in votes:
if sample not in tally:
tally[sample] = {}
seen.append(sample)
if annotator not in weights:
continue
counts = tally[sample]
counts[label] = counts.get(label, 0) + weights[annotator]
result = []
for sample in sorted(seen):
counts = tally[sample]
if not counts:
result.append([sample, "ARBITRATE"])
continue
top = max(counts.values())
winners = [label for label, score in counts.items() if score == top]
result.append([sample, winners[0] if len(winners) == 1 else "ARBITRATE"])
return result三个坑
平票取第一个
✗ winners[0] 直接返回
✓ len(winners) == 1 才采纳,否则 ARBITRATE
丢掉无效样本
✗ 没有有效票就不输出
✓ 仍然输出 [sample, "ARBITRATE"]
输出顺序
✗ 按输入顺序返回
✓ 按样本名 sorted 后返回