在 Potato 中逐步解决标注者分歧
运行 Potato 的裁定示例,了解八条评论各自进入队列的原因,记录最终标签,并导出决定用于分析。
从多位标注者处收集标签的研究者,可以按照本教程,用 Potato 2.14.0 的裁定队列解决标注者之间的分歧。裁定是指审核者阅读每位标注者在某个条目上的答案,并记录一个最终标签的步骤。本教程使用 Potato 自带的裁定示例,这是一个针对八条简短评论的情感任务,由三位模拟标注者给出答案,答案由一个设置脚本写入磁盘。你将了解每条评论进入队列的原因,为三条评论记录最终标签,并导出这些决定。裁定与分歧处理介绍何时裁定、何时改用聚合标签,裁定参考页列出了全部选项。
运行裁定示例
示例位于 Potato 仓库的 examples/advanced/adjudication 下,包含一个配置文件、一个含八条评论的数据文件,以及名为 setup_demo.py 的脚本。请克隆 2.14.0 标签处的仓库,安装同一版本,写入三位标注者的答案,然后启动服务器:
git clone --branch v2.14.0 --depth 1 https://github.com/davidjurgens/potato.git
pip install potato-annotation==2.14.0
cd potato/examples/advanced/adjudication
python setup_demo.py
potato start config.yaml -p 8000setup_demo.py 会在 annotation_output/ 下为 user_1、user_2 和 user_3 各写入一个 user_state.json 文件。sentiment 方案是一个单选问题,标签为 positive、negative、neutral 和 mixed。第二个方案 topics 是一个多选问题,选项为 food、service、price、ambiance 和 recommendation。打开 http://localhost:8000,用你选定的密码注册用户名 adjudicator,然后访问 http://localhost:8000/adjudicate。之后运行 python setup_demo.py --clean 会重置标注者的答案,并删除已保存的决定。
示例配置中的 adjudication 配置块如下,其中省略了显示选项:
adjudication:
enabled: true
adjudicator_users:
- "adjudicator"
min_annotations: 2
agreement_threshold: 0.75
show_all_items: true
require_confidence: true
error_taxonomy:
- "ambiguous_text"
- "guideline_gap"
- "annotator_error"
- "edge_case"
- "subjective_disagreement"adjudicator_users 按用户名列出允许进入队列的账户。min_annotations: 2 让条目在两位标注者回答之前不进入队列,agreement_threshold: 0.75 则把一致性达到或高于 0.75 的条目挡在队列之外。show_all_items: true 会跳过一致性检查,require_confidence: true 则为每项决定加入一个置信度选择器。
本页中的队列、标记、文件和命令输出,都来自在 v2.14.0 标签处运行该示例的结果。测试运行向裁定页面自己的路由发送了三项决定和一次跳过,请求体与页面脚本构造的一致。引用输出中的时间戳已替换为 <timestamp>。
八条评论各自进入队列的原因
Potato 对每条评论逐方案计算成对百分比一致性。有三位标注者时,每个方案有三对标注者。两位标注者一致的方案得 0.33,三位全部一致的方案得 1.00。topics 方案只有在两位标注者勾选了完全相同的主题集合时,才把这一对算作一致,没有勾选任何主题的标注者不计入 topics 得分。每条评论的整体一致性,是有得分的各方案的平均值。
队列按下表的顺序返回八条评论,整体一致性最低的排在最前:
| 条目 | 评论(节选) | user_1 | user_2 | user_3 | Sentiment | Topics | 整体 |
|---|---|---|---|---|---|---|---|
| item_001 | "amazing food but terrible service" | mixed; food, service | positive; food | negative; service | 0.00 | 0.00 | 0.00 |
| item_004 | "The pasta was decent but overpriced." | negative; food, price | neutral; food | mixed; food, price | 0.00 | 0.33 | 0.17 |
| item_005 | "The staff was rude and the food was cold." | negative; food, service | negative; service | positive; food, service | 0.33 | 0.33 | 0.33 |
| item_006 | "The hotel room was clean" | positive; ambiance | positive; ambiance | negative; price | 0.33 | 0.33 | 0.33 |
| item_007 | "Nothing special but gets the job done." | neutral | neutral | positive; recommendation | 0.33 | 无得分 | 0.33 |
| item_003 | "The movie was okay." | neutral; ambiance | negative | positive; ambiance | 0.00 | 1.00 | 0.50 |
| item_002 | "Highly recommend!" | positive; recommendation | positive; recommendation | neutral; recommendation | 0.33 | 1.00 | 0.67 |
| item_008 | "The customer service team was incredibly helpful" | positive; service | positive; service | negative; service | 0.33 | 1.00 | 0.67 |
每条评论的得分都低于示例的 agreement_threshold 0.75,最高的整体一致性是 0.67,出现在 item_002 和 item_008 上。在示例数据上,show_all_items: true 没有任何影响,因为八条评论仅凭一致性就已进入队列。侧边栏把每个得分显示为徽章,从 item_001 的 "0% agree" 到 item_002 和 item_008 的 "67% agree"。
表中有两个得分值得再看一眼。在 item_003 上,user_2 没有勾选任何主题,topics 得分 1.00 只比较了 user_1 和 user_3。这两位标注者都在一条电影评论上勾选了 ambiance,满分的 topics 得分掩盖了一个存疑的标签。在 item_007 上,只有 user_3 勾选了主题。topics 方案在这里没有得分,整体一致性等于 sentiment 得分 0.33。
标注者标记
打开一个条目会并排显示每位标注者的答案,被服务器标记的标注者旁带有徽章。示例的用时和修改数据是特意写成会触发这些标记的。示例把 fast_decision_warning_ms 设为 2,000,而 user_2 在六条评论上各只花了 700 到 1,500 毫秒。页面把这六个答案标为 "fast decision on this item"。Potato 会把修改超过五次的答案标为 "many edits on this item"。编辑标记出现在 user_2 的 item_004(7 次修改)和 item_008(8 次修改)上,以及 user_3 的 item_001(6 次修改)和 item_004(9 次修改)上。
user_3 在全部八条评论上都带有 "low agreement across all items" 标记。Potato 把每位标注者的 sentiment 答案与入队条目上的严格多数标签相比较,并标记在不到 40% 的条目上与多数意见一致的标注者。user_3 在八条评论上一次都没有与多数一致,该标记的提示文字为 "Agreement rate with consensus: 0%"。MACE 无需审核者,就能根据同一类答案估计每位标注者的能力和一个最佳猜测标签。2.14.0 的裁定页面不显示 MACE 的预测标签。
为三条评论记录决定
在标注者的答案下方,页面为每个方案构建一个决定表单。sentiment 表单列出四个标签,并在每个标签旁为选择了该标签的每位标注者放一个标签,topics 表单则用复选框做同样的事。表单下方依次是置信度选择器(High、Medium 和 Low)、示例 error_taxonomy 中的五个错误类别、一个备注框,以及一个把条目标记为需要更新指南的复选框。**提交并继续(Submit and continue)**保存决定并打开下一个条目,**跳过(Skip)**则把条目标记为已跳过。
测试运行记录了三项决定,并跳过了 item_007:
- item_001。 Sentiment 为
mixed,主题为 food 和 service,置信度为 High,错误类别为 "Annotator Error"。这条评论称赞了食物,又抱怨要等 45 分钟。user_1给出了相同的答案,user_2和user_3则各自只抓住了评论的一半。 - item_004。 Sentiment 为
mixed,主题为 food 和 price,置信度为 Medium,错误类别为 "Guideline Gap" 和 "Subjective Disagreement"。该决定还带有一个指南标记,询问mixed是否涵盖对一件事不温不火、对另一件事持否定态度的评论。 - item_003。 Sentiment 为
mixed,置信度为 Low,错误类别为 "Ambiguous Text",没有 topics 决定。没有做出决定的方案不会进入该决定,存疑的 ambiance 标签也就从未成为最终标签。
没有置信度的决定会被拒绝。页面会阻止提交并要求填写置信度,而不带置信度、直接发给服务器的请求会返回 HTTP 400 和下面的消息:
{"error": "A confidence value is required for this task (require_confidence)."}在这三项决定和一次跳过之后,/adjudicate/api/stats 报告 8 个条目中有 3 个已完成、4 个待处理、1 个已跳过。
decisions.json 为每项决定存储什么
Potato 在决定提交时就把它写入 annotation_output/adjudication/decisions.json。测试运行为 item_004 写入了下面的条目:
{
"instance_id": "item_004",
"adjudicator_id": "adjudicator",
"timestamp": "<timestamp>",
"label_decisions": {
"sentiment": "mixed",
"topics": {"food": true, "price": true}
},
"span_decisions": [],
"source": {"sentiment": "adjudicator", "topics": "adjudicator"},
"confidence": "medium",
"notes": "Decent pasta, high price, and the writer says they are unsure.",
"error_taxonomy": ["guideline_gap", "subjective_disagreement"],
"guideline_update_flag": true,
"guideline_update_notes": "Say whether mixed covers a review that is lukewarm about one thing and negative about another.",
"time_spent_ms": 63000,
"source_origins": {}
}单选决定把所选标签存为字符串,多选决定则把勾选的主题存为取值为 true 的映射。2.14.0 的页面把每个单选和多选决定的 source 都记录为 adjudicator。item_001 的决定与 user_1 的答案一致,但两个方案仍然记录为 adjudicator。
用 adjudication 格式导出决定
adjudication 导出格式只写出决定。请在示例的文件夹中运行导出:
python -m potato.export -c config.yaml -f adjudication -o exports/该命令打印了下面的摘要:
Loading config from: config.yaml
Loaded 8 items, 24 annotations
Exporting to adjudication format...
Export successful!
Files written:
exports/adjudicated.csv
exports/adjudication_log.jsonl
Statistics:
n_decisions: 3
n_resolved_labels: 5
n_items: 3
n_span_decisions: 0
n_schemas: 2exports/adjudicated.csv 的每个条目和方案占一行,给出最终值、该值的来源、裁定者、置信度和决定时间。三项决定产生了五行,因为 item_003 没有 topics 决定:
instance_id,schema,value,source,adjudicator_id,confidence,timestamp
item_001,sentiment,mixed,adjudicator,adjudicator,high,<timestamp>
item_001,topics,"{""food"": true, ""service"": true}",adjudicator,adjudicator,high,<timestamp>
item_004,sentiment,mixed,adjudicator,adjudicator,medium,<timestamp>
item_004,topics,"{""food"": true, ""price"": true}",adjudicator,adjudicator,medium,<timestamp>
item_003,sentiment,mixed,adjudicator,adjudicator,low,<timestamp>exports/adjudication_log.jsonl 每项决定占一行,包含备注、错误类别、指南标记和花费的时间。csv、jsonl 和 parquet 导出格式读取的是每位标注者自己的标签,因此裁定之后用这三种格式中任何一种导出,得到的仍然是分歧本身,而不是最终标签。
potato.adjudication_export 命令的用途是把决定与标注者意见一致的条目合并,得到一个最终数据集。在 2.14.0 中,python -m potato.adjudication_export 会在读取任何数据之前就停止,并报错 'str' object has no attribute 'config_file',维护者已经收到通知。在后续版本修复该命令之前,请像上面的运行一样使用 python -m potato.export -f adjudication。导出裁定后的标签介绍了这两个命令。
服务器重启之后的队列
Potato 在服务器启动时重新加载已保存的决定,重建后的队列不再包含重启前已做出决定的条目。在测试运行中,重启后队列里剩下 5 个条目,全部待处理,进度计数从 0/5 已完成重新开始。被跳过的 item_007 被 Potato 重新放回队列,状态为待处理。之前的三项决定仍保留在 decisions.json 中,重启之后运行的 adjudication 导出仍然写出了全部三项。
Potato 2.14.0 中的限制
把示例改用到你自己的研究时,Potato 2.14.0 的下列三种行为需要注意:
- 盲审只停留在屏幕上。 设置
show_annotator_names: false后,队列和条目视图会把用户名替换为 "Annotator 1" 这样的别名。在列表最后一个条目上提交或跳过之后,页面会向/adjudicate/api/next路由请求下一个条目,而该路由的响应中带有真实的用户名。任何打开浏览器开发者工具的人都能在响应中读到这些用户名。 - 置信度选择器需要
require_confidence: true。 示例设置了这个选项,true同时也是默认值。设为require_confidence: false时,页面不显示选择器,每项决定存储的置信度都为空。 - 相似度搜索需要
precompute_on_start: true。 示例配置中有一个被注释掉的similarity配置块,启用该配置块需要sentence-transformers包。当precompute_on_start: false时,2.14.0 的服务器不嵌入任何条目,页面只能在之前某次运行留在磁盘上的嵌入缓存中查找相似条目。
在真实数据上运行裁定之前,请把 num_annotators_per_item 设为 2 或更大,并删除 show_all_items: true。没有 show_all_items 时,队列只包含一致性低于 agreement_threshold 的条目。