文字分類資料集 Template

    用於訓練自訂文字分類和標記 AI 模型的資料集範本

    Classification

    Overview

    文字分類是將預定義類別指派給文字文件的基礎 NLP 任務。應用範圍包括電子郵件分類(垃圾郵件、主要、促銷、社群)、支援工單分類(帳單、技術、帳戶、功能請求)、內容審核(安全、標記、需要審查)、文件分類(合約、發票、報告、信函),以及對話式 AI 中的意圖偵測。一個建構良好的文字分類資料集能使組織以高準確率自動化這些分類任務。

    文字分類的靈活性使資料集設計變得至關重要。類別的分類法必須有明確定義、互斥(對於單標籤分類)或明確指定(對於多標籤),並且足夠全面以涵蓋所有預期的輸入。模糊的類別邊界是分類效能不佳的主要原因——如果人工標註者無法一致地就正確標籤達成共識,模型也無法做到。

    文字分類資料集可以為不同的建模方法進行結構化。對於傳統機器學習或基於編碼器的模型(BERT、DeBERTa),資料集由文字-標籤對組成。對於基於 LLM 的分類,資料集使用指令格式,提示模型分類文字並解釋其推理。LLM 方法的優勢在於能在預測旁產出解釋,但代價是更高的推論延遲。選擇與您部署需求相符的方法。

    Dataset Schema

    typescript
    // Single-label classification
    interface TextClassificationExample {
      text: string;
      label: string;
      confidence?: number;
      metadata?: {
        source: string;
        annotator_agreement: number;
        word_count: number;
      };
    }
    
    // Multi-label classification
    interface MultiLabelExample {
      text: string;
      labels: string[];
      metadata?: {
        source: string;
        primary_label: string;
      };
    }
    
    // LLM instruction format for classification with explanation
    interface LLMClassificationExample {
      instruction: string;
      input: string;
      output: string;  // Contains both label and reasoning
    }
    單標籤、多標籤和基於 LLM 文字分類的結構定義變體

    Sample Data

    json
    [
      {
        "text": "I can't log into my account even after resetting my password three times. The reset email comes through but the new password doesn't work. I've tried different browsers and clearing cookies.",
        "label": "technical_issue",
        "confidence": 0.95,
        "metadata": {"source": "support_tickets", "annotator_agreement": 1.0, "word_count": 36}
      },
      {
        "text": "Can you explain the difference between the Pro and Enterprise plans? We're a team of 50 and need to understand what additional features we'd get with the upgrade.",
        "label": "sales_inquiry",
        "confidence": 0.92,
        "metadata": {"source": "support_tickets", "annotator_agreement": 0.9, "word_count": 30}
      },
      {
        "text": "I was charged $49.99 on March 3rd but I cancelled my subscription on February 28th. Please process a refund for this charge.",
        "label": "billing_issue",
        "confidence": 0.97,
        "metadata": {"source": "support_tickets", "annotator_agreement": 1.0, "word_count": 25}
      },
      {
        "text": "It would be really helpful if the dashboard had a dark mode option. Several people on our team work late hours and the bright interface causes eye strain.",
        "label": "feature_request",
        "confidence": 0.91,
        "metadata": {"source": "support_tickets", "annotator_agreement": 0.85, "word_count": 29}
      },
      {
        "text": "Just wanted to say thanks to your support team — Sarah resolved my issue in under 5 minutes. Great service!",
        "label": "positive_feedback",
        "confidence": 0.98,
        "metadata": {"source": "support_tickets", "annotator_agreement": 1.0, "word_count": 21}
      }
    ]
    五種類別的支援工單分類範例,包含標註者一致性分數

    Data Collection Guide

    首先透過分析現有資料定義您的類別分類法。匯出 500-1,000 份文件樣本,讓領域專家手動將其分為自然類別,並迭代分類法直到類別清晰且全面。常見的錯誤包括建立太多細粒度的類別(導致標註混淆和稀疏的訓練資料)或太少的寬泛類別(限制分類的實用性)。大多數應用在 5-20 個類別時效果良好。

    撰寫詳細的標註指南,包含清楚的定義、多個範例,以及對邊緣案例的明確指導。對於每個類別,提供 3-5 個清楚的範例和 2-3 個邊界範例,並解釋為什麼它們屬於該類別。記錄當文字可能合理地適合多個類別時應指派哪個類別(決策優先規則)。在擴展到完整資料集之前,讓 3-5 位標註者標記相同的 100 份文件並衡量一致性來測試您的指南。

    對於基於 LLM 的分類,將您的標記範例轉換為指令格式。指令描述分類任務並列出可用的類別。輸入包含要分類的文字。輸出包含預測的標籤和 2-3 句解釋推理。讓領域專家為初始範例撰寫推理,以建立資料集的解釋品質標準。

    Quality Criteria

    標註者間一致性(兩位標註者用 Cohen's kappa 衡量,三位或以上用 Fleiss' kappa 衡量)應超過 0.80,資料集才能被視為高品質。一致性較低的類別應予以重新檢視——要麼指南需要澄清,要麼類別需要合併或拆分。追蹤每個類別的一致性以識別特定的分類法問題。

    類別平衡顯著影響模型效能。雖然完美的平衡很少是可實現或可取的(它可能不反映真實世界的分佈),但極端的不平衡(一個類別有 5,000 個範例而另一個只有 50 個)會導致模型在少數類別上表現不佳。要麼為代表不足的類別收集額外範例、應用過取樣技術,或在訓練中使用類別加權損失。目標是沒有任何類別少於 100-200 個範例。

    移除或重新標記即使標註指南也無法明確指出正確類別的模糊範例。這些範例在不提供有用訊號的情況下為訓練資料增加雜訊。3,000 個明確的範例優於 5,000 個包含 30% 雜訊的範例。

    Using This Template with Ertas

    將您的原始文字文件匯入 Ertas Data Suite 進行個資遮蔽——支援工單和客戶通訊經常包含姓名、帳號和聯絡資訊。遮蔽後,匯出進行標註,然後重新匯入已標記的資料集進行最終品質檢查和格式轉換。

    根據您的模型架構以 JSONL 或 CSV 格式匯出。對於基於編碼器的分類,包含 text 和 label 欄的 CSV 效果良好。對於基於 LLM 的分類,以 Alpaca 格式匯出,包含 instruction-input-output 結構。Ertas Studio 處理這兩種訓練方法,並具有自動格式驗證功能。

    Recommended Model

    對於高吞吐量需求的生產文字分類,微調 BERT 系列的編碼器模型(DeBERTa-v3-base 或 RoBERTa-base)。這些模型在 CPU 上 5-10 毫秒內即可分類文字,適用於每分鐘處理數千份文件的即時應用。

    對於帶解釋的分類或分類法可能經常變動的情況,微調一個 7B 的生成式模型。指令遵循能力允許您透過提示變更修改分類法而無需重新訓練,以更高的推論延遲為代價提供靈活性。以 Q4_K_M 量化的 GGUF 匯出可保持大多數批量處理工作流程足夠快的推論速度。

    Related Resources

    Ship AI that runs on your users' devices.

    Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.