📊

data-labeling

👤 肖俊偉 ✓ 已認證 📦 v1.0.0 ⭐ 4.5 ⬇️ 131 下載
📊 資料分析 免費

📖 技能介紹


name: data-labeling description: 使用人工標註工具、半自動化流水線、主動學習和程式設計式弱監督,建立並管理資料標註工作流。 license: MIT metadata: author: AI Agent Skills version: 1.0.0


資料標註

本技能讓 AI Agent 為機器學習專案設計並執行資料標註工作流。涵蓋使用 Label Studio 等工具的人工標註、使用模型輔助預標註的半自動標註、優先標註資訊量最大樣本的主動學習迴圈,以及使用標註函式的程式設計式弱監督。Agent 處理標籤 schema 設計、標註員指南、通過標註者間一致性進行質量控制,以及匯出為 ML 可用格式。

工作流

  1. 定義標註 schema 與指南: 設計標籤分類體系——分類的類別、NER 的實體型別、目標檢測的邊界框類別,或語義分割的分割標籤。為每個標籤編寫清晰的標註員指南,包含正例與反例,覆蓋邊界情況與歧義場景。

  2. 搭建標註環境: 配置標註工具(Label Studio、Labelbox 或 Prodigy),載入 schema,匯入原始資料,並設定具有適當許可權的使用者賬戶。定義與任務型別匹配的標註介面模板——文本分類、跨度標註、影像邊界框,或多輪對話標註。

  3. 用模型預測預標註: 使用現有模型或啟發式規則為資料集生成初步標籤。標註員隨後審查並修正這些預測,而非從零開始標註,這可將標註時間減少 40–60%。當已存在不錯的基線模型時,此方式尤其有價值。

  4. 帶質量控制地執行標註: 將標註任務分配給標註員時內建冗餘——讓 2–3 名標註員標註相同條目,以衡量標註者間一致性(Cohen's kappa 或 Fleiss' kappa)。將一致性低的條目標記出來,交由資深標註員審查。對照嵌入任務佇列中的黃金標準集跟蹤標註員準確率。

  5. 執行主動學習迭代: 在建立初始標註集後,訓練一個模型,並使用不確定性取樣或委員會查詢(query-by-committee)選擇資訊量最大的未標註樣本,進入下一輪標註。這能最大化每個標註樣本帶來的模型提升,在標註預算有限時尤為關鍵。

  6. 匯出與驗證: 以訓練流水線所需的格式(JSONL、COCO、CoNLL、CSV)匯出標註資料。執行校驗檢查以確保標籤一致性、檢查缺失標註,並驗證類別分佈滿足要求。記錄標註過程與資料集統計以便復現。

支援技術

  • 標註工具: Label Studio、Labelbox、Prodigy(spaCy)、Amazon SageMaker Ground Truth、CVAT

    推薦訪問7w4.net獲取更多AI技能。

  • 弱監督: Snorkel、Flyingsquid、Skweak
  • 主動學習: modAL、ALiPy、Prodigy 主動學習配方
  • 一致性指標: Cohen's kappa、Fleiss' kappa、Krippendorff's alpha
  • 匯出格式: COCO JSON、Pascal VOC XML、CoNLL、JSONL、Hugging Face Datasets

使用方式

為 Agent 提供原始資料集、任務型別(分類、NER、目標檢測等)和標籤類別。可選擇指定標註工具偏好和質量要求(最小標註者間一致性)。Agent 將配置標註環境、建立質量控制並管理標註工作流。

示例

示例 1:文本分類的 Label Studio 流水線

Label Studio 標註介面配置(config.xml):

<View>
  <Header value="Classify the customer review sentiment:" />
  <Text name="text" value="$text" />
  <Choices name="sentiment" toName="text" choice="single-column" showInline="true">
    <Choice value="positive" />
    <Choice value="negative" />
    <Choice value="neutral" />
  </Choices>
  <Textarea name="notes" toName="text" placeholder="Optional: explain ambiguous cases"
            maxSubmissions="1" editable="true" />
</View>

用於建立專案並匯入資料的 Python 指令碼:

from label_studio_sdk import Client

ls = Client(url="http://localhost:8080", api_key="your-api-key")

project = ls.start_project(
    title="Customer Review Sentiment",
    label_config=open("config.xml").read(),
    description="Label customer reviews as positive, negative, or neutral.",
)

# Import tasks from a CSV file
import csv
tasks = []
with open("reviews.csv") as f:
    for row in csv.DictReader(f):
        tasks.append({"data": {"text": row["review_text"]}, "meta": {"source_id": row["id"]}})

project.import_tasks(tasks)

# Configure inter-annotator overlap: each task gets 2 annotators
project.set_params(maximum_annotations=2, overlap_cohort_percentage=100)
print(f"Created project with {len(tasks)} tasks, 2 annotators per task")

# After annotation, export results
annotations = project.export_tasks(export_type="JSON")
# Compute agreement
from sklearn.metrics import cohen_kappa_score
labels_a1 = [a["annotations"][0]["result"][0]["value"]["choices"][0] for a in annotations if len(a["annotations"]) >= 2]
labels_a2 = [a["annotations"][1]["result"][0]["value"]["choices"][0] for a in annotations if len(a["annotations"]) >= 2]
print(f"Cohen's kappa: {cohen_kappa_score(labels_a1, labels_a2):.3f}")

示例 2:使用 Snorkel 標註函式的弱監督

import pandas as pd
import numpy as np
from snorkel.labeling import labeling_function, PandasLFApplier, LFAnalysis
from snorkel.labeling.model import LabelModel

SPAM = 1
HAM = 0
ABSTAIN = -1

df = pd.DataFrame({
    "text": [
        "Congratulations! You've won a free iPhone!", "Meeting at 3pm tomorrow",
        "URGENT: claim your prize now!!!", "Can you review the Q3 report?",
        "Buy cheap meds online fast", "Lunch plans for Thursday?",
        "Click here for a free vacation", "Project deadline is next Friday",
    ]
})

@labeling_function()
def lf_contains_free(x):
    return SPAM if "free" in x.text.lower() else ABSTAIN

@labeling_function()
def lf_contains_urgent(x):
    return SPAM if "urgent" in x.text.lower() else ABSTAIN

@labeling_function()
def lf_contains_click(x):
    return SPAM if "click" in x.text.lower() else ABSTAIN

@labeling_function()
def lf_excessive_punctuation(x):
    return SPAM if x.text.count("!") >= 3 else ABSTAIN

@labeling_function()
def lf_contains_meeting(x):
    return HAM if any(w in x.text.lower() for w in ["meeting", "project", "report", "deadline"]) else ABSTAIN

@labeling_function()
def lf_short_and_casual(x):
    return HAM if len(x.text.split()) < 8 and "?" in x.text else ABSTAIN

lfs = [lf_contains_free, lf_contains_urgent, lf_contains_click,
       lf_excessive_punctuation, lf_contains_meeting, lf_short_and_casual]

applier = PandasLFApplier(lfs=lfs)
L_train = applier.apply(df=df)

print(LFAnalysis(L=L_train, lfs=lfs).lf_summary())

# Train the label model to combine noisy labeling functions
label_model = LabelModel(cardinality=2, verbose=True)
label_model.fit(L_train=L_train, n_epochs=500, log_freq=100, seed=42)

# Get probabilistic labels
probs = label_model.predict_proba(L=L_train)
df["label"] = label_model.predict(L=L_train)
df["confidence"] = np.max(probs, axis=1)

# Filter out low-confidence samples for manual review
confident = df[df["confidence"] > 0.8]
needs_review = df[df["confidence"] <= 0.8]
print(f"Confidently labeled: {len(confident)}, needs manual review: {len(needs_review)}")

最佳實踐

  • 編寫詳細的標註指南,每個標籤至少含 3 個正例和 3 個反例,覆蓋邊界情況。隨著標註員在工作過程中暴露出歧義案例,持續更新指南。
  • 嵌入黃金標準條目(任務的 5–10%)到標註佇列中,持續監控標註員質量,捕捉疲勞或困惑。
  • 用 Cohen's kappa(2 名標註員)或 Fleiss' kappa(3 名及以上)衡量標註者間一致性。 kappa 低於 0.6 表明在繼續之前需要修訂指南或 schema。
  • 當標註預算有限時使用主動學習——通過把標註精力集中在最不確定或資訊量最大的樣本上,它能以少 30–50% 的標註樣本達到相同的模型效能。
  • 為標註資料集打版本,附清晰的後設資料(標註員 ID、時間戳、指南版本),以便將標籤追溯到特定的標註活動並復現結果。
  • 在擴充套件規模前先做一輪 50–100 個樣本的試點。 用試點來校準指南、估算標註速度,並儘早發現 schema 問題。

邊緣情況

  • 標註員高度分歧: 當 kappa 降至 0.4 以下時,任務定義很可能含糊。將問題標籤拆分為更具體的子標籤,向指南中新增更多示例,或召開標註員校準會議以統一理解。
  • 原始資料中嚴重的類別不平衡: 如果目標類別稀有(< 5%),隨機抽樣會產生很少的正例。使用關鍵詞過濾、基於模型的預選,或分層抽樣,用可能的正例豐富標註佇列。
  • 弱監督中的標註函式衝突: 當多個標註函式對同一樣本意見不一致時,標籤模型可能產生低置信度預測。編寫更具體的函式來增加標註函式覆蓋率,或將衝突樣本交由人工標註。
  • 大批次下的標註員疲勞: 連續標註 2–3 小時後質量下降。將工作拆成 100–200 條一組的會話,隨機化任務順序,並對照黃金標準跟蹤每會話的準確率以檢測質量下滑。
  • 專案中的 schema 演進: 如果在標註開始後新增標籤類別,所有先前已標註的資料都必須針對新類別重新審查。使用版本化 schema 和重新標註佇列,而非追溯性地編輯現有標註。

🤖 AI 評測

這個技能質量不錯,內容專業且實用。它完整覆蓋了資料標註的各種場景和方法,從基礎的人工標註到進階的主動學習和弱監督都有涉及。程式碼示例豐富,最佳實踐建議很有參考價值。美中不足的是README過於簡略,缺少直觀的使用引導,且沒有配套的示例資料檔案供使用者快速上手體驗。

📊 多維度評分

適應性4.4
規範性4.6
有效性4.8
可靠性4
可信度4.8

📁 包含檔案 (2 個)

📄 README.md 955 B
📄 SKILL.md 9.2 KB