在 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 的條目。