Skip to content

ICL 標註

AI 輔助的上下文學習與人工驗證,實現可擴充套件的標註。

Potato 的 ICL(上下文學習)標註功能通過使用高置信度的人工標註作為上下文示例來引導 LLM 標註剩餘資料,實現 AI 輔助標註。系統追蹤 LLM 置信度並將預測路由回人工進行驗證。

概述

ICL 標註系統:

  1. 收集高置信度示例:識別標註者一致的實例(例如 80%+ 一致率)
  2. 使用 LLM 標註:使用示例提示 LLM 標註未標註的實例
  3. 追蹤置信度:記錄每個預測的 LLM 置信度分數
  4. 驗證準確性:將 LLM 標註實例的樣本路由給人工進行盲審驗證
  5. 報告指標:根據驗證結果計算並顯示 LLM 準確率

功能

自動示例收集

系統自動識別多個標註者一致的高置信度示例:

  • 可配置的一致率閾值(預設:80%)
  • 最少標註者數量要求(預設:2)
  • 可配置間隔的自動重新整理
  • 按模式分組的示例池

帶限制的 LLM 標註

為實現迭代改進而非批次標註:

  • 最大總標籤數:限制 LLM 預測的總數
  • 最大未標註比例:只標註剩餘資料的一定百分比
  • 準確率過低時暫停:當準確率低於閾值時自動暫停

盲審驗證

驗證使用"盲標註"方式——標註者將實例視為普通任務,不知道 LLM 的預測:

  • 可配置的取樣率(預設:LLM 標籤的 20%)
  • 多種選擇策略:low_confidencerandommixed
  • 驗證任務自然混入常規分配

配置

ICL 標註需要啟用 ai_support

yaml
# AI endpoint configuration (required)
ai_support:
  enabled: true
  endpoint_type: "openai"
  ai_config:
    model: "gpt-4o-mini"
    api_key: "${OPENAI_API_KEY}"
 
# ICL labeling configuration
icl_labeling:
  enabled: true
 
  # Example selection settings
  example_selection:
    min_agreement_threshold: 0.8      # 80% annotators must agree
    min_annotators_per_instance: 2    # Minimum annotations for consensus
    max_examples_per_schema: 10       # Max examples per schema in prompt
    refresh_interval_seconds: 300     # How often to refresh examples
 
  # LLM labeling settings
  llm_labeling:
    batch_size: 20
    trigger_threshold: 5              # Min examples before LLM labeling starts
    confidence_threshold: 0.7         # Min confidence to accept prediction
    batch_interval_seconds: 600
    max_total_labels: 100             # Max instances to label total
    max_unlabeled_ratio: 0.5          # Max portion of unlabeled to label
    pause_on_low_accuracy: true
    min_accuracy_threshold: 0.7
 
  # Human verification settings
  verification:
    enabled: true
    sample_rate: 0.2                  # 20% of LLM labels verified
    selection_strategy: "low_confidence"
    mix_with_regular_assignments: true
    assignment_mix_rate: 0.2

選擇策略

  • low_confidence:優先驗證 LLM 最不確定的預測
  • random:從所有預測中隨機取樣
  • mixed:50% 低置信度 + 50% 隨機

管理員 API

狀態端點

http
GET /admin/api/icl/status

返回 ICL 標註器的整體狀態,包括每個模式的示例數、已做出的預測數、驗證佇列大小和準確率指標。

示例端點

http
GET /admin/api/icl/examples?schema=sentiment

返回高置信度示例,可按模式過濾。

準確率端點

http
GET /admin/api/icl/accuracy?schema=sentiment

返回基於人工驗證結果的準確率指標。

手動觸發端點

http
POST /admin/api/icl/trigger
Content-Type: application/json
 
{"schema_name": "sentiment"}

手動觸發特定模式的批次標註。

使用工作流

1. 配置項目

yaml
ai_support:
  enabled: true
  endpoint_type: "openai"
  ai_config:
    model: "gpt-4o-mini"
    api_key: "${OPENAI_API_KEY}"
 
icl_labeling:
  enabled: true
  example_selection:
    min_agreement_threshold: 0.8
  llm_labeling:
    max_total_labels: 50  # Start small
  verification:
    enabled: true
    sample_rate: 0.3  # Verify 30% initially

2. 收集人工標註

讓標註者正常標註資料。當他們達成共識(80%+ 一致率)時,這些實例將作為示例可用。

3. 監控進度

bash
curl http://localhost:8000/admin/api/icl/status

4. 檢查準確率

bash
curl http://localhost:8000/admin/api/icl/accuracy

5. 迭代

根據準確率:

  • 如果準確率高(>80%),增加 max_total_labels
  • 如果準確率低,在繼續之前新增更多人工示例

最佳實踐

  1. 從小規模開始:以保守的限制開始(max_total_labels: 50),在擴大規模前評估準確率

  2. 儘早驗證:初期使用更高的 sample_rate(0.3-0.5)以獲得有信心的準確率估計

  3. 積極監控:通過管理員 API 定期檢查準確率指標

  4. 調整閾值:如果 LLM 準確率低:

    • 提高 min_agreement_threshold 以獲得更乾淨的示例
    • 提高 trigger_threshold 以在標註前獲得更多示例
    • 降低 confidence_threshold 以拒絕不確定的預測
  5. 使用選擇策略

    • low_confidence:最適合識別有問題的類別
    • random:最適合無偏準確率估計
    • mixed:平衡方法

故障排除

LLM 未在標註

  1. 檢查 ai_support 是否正確配置
  2. 驗證是否有足夠的高置信度示例
  3. 檢查標註是否因限制或低準確率而暫停

準確率低

  1. 提高 min_agreement_threshold 以獲得更乾淨的示例
  2. 新增更多標註指南/說明
  3. 檢查正在使用的示例(/admin/api/icl/examples

驗證任務未出現

  1. 驗證 verification.enabled 為 true
  2. 檢查 mix_with_regular_assignments 為 true
  3. 驗證佇列中是否有待驗證項

延伸閱讀

有關實現細節,請參閱原始碼文件