distilabel 完整教學

Repository: https://github.com/argilla-io/distilabel Stars: 3248 | Tags: LLM, synthetic-data, AI-feedback License: Apache-2.0 | Language: Python | Requires: Python 3.9+ Homepage: https://distilabel.argilla.io Topics: ai, huggingface, llms, openai, python, rlaif, rlhf, synthetic-data, synthetic-dataset-generation

2. 核心架構

2.1 整體架構圖


graph TB
    subgraph Input["Input Layer (輸入層)"]
        HF["HuggingFace Dataset
HuggingFace 資料集"] CSV["CSV / JSON / JSONL"] GEN["GeneratorStep
生成器步驟"] end subgraph Pipeline["Pipeline Engine (管線引擎)"] direction TB DAG["DAG Scheduler
有向無環圖排程器"] BM["BatchManager
批次管理器"] SW["StepWrapper
步驟包裝器"] WB["WriteBuffer
寫入緩衝區"] DAG --> BM BM --> SW SW --> WB end subgraph Models["Models Layer (模型層)"] direction TB LLM["LLM Integrations
15+ providers"] EMB["Embedding Models
嵌入模型"] IMG["Image Generation
圖像生成"] end subgraph Steps["Steps Layer (步驟層)"] direction TB TASK["Task Steps
任務步驟"] PROC["Processing Steps
處理步驟"] FILT["Filtering Steps
過濾步驟"] FMT["Formatting Steps
格式化步驟"] end subgraph Tasks["Built-in Tasks (內建任務)"] TG["TextGeneration
文本生成"] UF["UltraFeedback
多維度評分"] EI["EvolInstruct
指令進化"] SI["SelfInstruct
自我指令"] PM["PrometheusEval
評估"] CL["CLAIR
修訂回饋"] MG["Magpie
合成對話"] SG["StructuredGeneration
結構化生成"] end subgraph Output["Output Layer (輸出層)"] DS["Distiset
distilabel 資料集"] ARG["Argilla Export
Argilla 標注平台"] PUSH["Push to HF Hub
推送到 HuggingFace"] end Input --> Pipeline Models --> Steps Steps --> Pipeline Tasks --> TASK Pipeline --> Output style Input fill:#e1f5fe,stroke:#0288d1 style Pipeline fill:#fff3e0,stroke:#f57c00 style Models fill:#f3e5f5,stroke:#7b1fa2 style Steps fill:#e8f5e9,stroke:#388e3c style Tasks fill:#fce4ec,stroke:#c62828 style Output fill:#f1f8e9,stroke:#558b2f

2.2 模組結構

distilabel 的原始碼組織如下:

模組路徑用途
models/src/distilabel/models/LLM、Embedding (嵌入)、Image Generation (圖像生成) 的統一介面
pipeline/src/distilabel/pipeline/DAG 排程、BatchManager、local/Ray 執行引擎
steps/src/distilabel/steps/所有可組合的步驟:tasks、clustering、filtering、formatting
steps/tasks/src/distilabel/steps/tasks/論文實作:UltraFeedback、EvolInstruct、Magpie、CLAIR 等
cli/src/distilabel/cli/命令列介面,支援 pipeline 執行與管理
distiset.pysrc/distilabel/distiset.py輸出資料集格式,整合 HuggingFace datasets

2.3 Pipeline 執行流程


sequenceDiagram
    participant U as User Code
使用者程式碼 participant P as Pipeline
管線 participant DAG as DAG Scheduler
排程器 participant BM as BatchManager
批次管理器 participant S as Step/Task
步驟/任務 participant LLM as LLM Provider
語言模型 participant DS as Distiset
輸出資料集 U->>P: pipeline.run(dataset) P->>DAG: 解析步驟依賴關係 DAG->>BM: 建立批次佇列 loop 每個 Batch (批次) BM->>S: 派發批次資料 S->>LLM: 呼叫 LLM API LLM-->>S: 回傳生成結果 S->>S: 後處理 + 驗證 S-->>BM: 回傳處理後資料 end BM->>P: 所有批次完成 P->>DS: 封裝為 Distiset DS-->>U: 回傳結果 / 推送 HF Hub

2.4 支援的 LLM Providers

distilabel 透過 extras (額外套件) 支援 15+ 種 LLM 供應商:

Provider類別Extra 名稱
OpenAI雲端 APIopenai
Anthropic (Claude)雲端 APIanthropic
Mistral AI雲端 APImistralai
Cohere雲端 APIcohere
Groq雲端 APIgroq
Google Vertex AI雲端 APIvertexai
HuggingFace Inference Endpoints雲端推論hf-inference-endpoints
HuggingFace Transformers本地推論hf-transformers
vLLM本地高效推論vllm
Ollama本地推論ollama
llama.cpp本地推論llama-cpp
LiteLLM統一代理litellm
MLXApple Silicon 推論mlx
Together AI雲端 APIopenai (相容)
Azure OpenAI雲端 APIopenai (相容)

2.5 內建論文實作

distilabel 內建了多篇合成資料研究論文的完整實作:

論文 / 方法用途對應模組
UltraFeedback多維度 AI 回饋評分(helpfulness、honesty、truthfulness、instruction-following)steps/tasks/ultrafeedback.py
EvolInstruct (WizardLM)指令複雜度漸進式進化steps/tasks/evol_instruct/
EvolQuality回應品質漸進式進化steps/tasks/evol_quality/
DEITA資料效率指令調優(品質 + 複雜度自動篩選)steps/deita.py
Self-InstructLLM 自我生成指令steps/tasks/self_instruct.py
Instruction Backtranslation從回應反向生成指令steps/tasks/instruction_backtranslation.py
Prometheus基於 rubric (評分標準) 的細粒度 AI 評估steps/tasks/prometheus_eval.py
CLAIR基於修訂的對比學習回饋steps/tasks/clair.py
MagpieLLM 自發性合成對話steps/tasks/magpie/
Genstruct從原始文本生成結構化指令steps/tasks/genstruct.py
Math Shepherd數學推理過程驗證steps/tasks/math_shepherd/
APIGenAPI 呼叫資料合成steps/tasks/apigen/

3. 安裝與設定

3.1 基本安裝

1# 基本安裝(僅核心功能)
2pip install distilabel --upgrade
3
4# 建議使用 uv 建立隔離環境
5uv venv .venv-distilabel --python 3.11
6source .venv-distilabel/bin/activate
7uv pip install distilabel

3.2 依 Provider 安裝 Extras

 1# 使用 OpenAI(最常見)
 2pip install "distilabel[openai]"
 3
 4# 使用 Anthropic Claude
 5pip install "distilabel[anthropic]"
 6
 7# 使用本地 vLLM 推論
 8pip install "distilabel[vllm]"
 9
10# 使用 HuggingFace Transformers 本地推論
11pip install "distilabel[hf-transformers]"
12
13# 使用 Ollama 本地推論
14pip install "distilabel[ollama]"
15
16# 結構化輸出
17pip install "distilabel[outlines]"
18pip install "distilabel[instructor]"
19
20# 使用 Ray 分散式擴展
21pip install "distilabel[ray]"
22
23# 使用 Argilla 標注平台
24pip install "distilabel[argilla]"
25
26# 組合安裝(醫療 SDG 推薦組合)
27pip install "distilabel[openai,anthropic,hf-inference-endpoints,instructor,argilla]"

3.3 環境變數設定

 1# OpenAI
 2export OPENAI_API_KEY="sk-..."
 3
 4# Anthropic
 5export ANTHROPIC_API_KEY="sk-ant-..."
 6
 7# HuggingFace
 8export HF_TOKEN="hf_..."
 9
10# Argilla(如需標注平台)
11export ARGILLA_API_URL="https://your-argilla-instance.com"
12export ARGILLA_API_KEY="your-argilla-key"

3.4 驗證安裝

1# 確認安裝版本
2python -c "import distilabel; print(distilabel.__version__)"
3
4# 確認 CLI 可用
5python -m distilabel --help

4. 使用方式與程式碼範例

4.1 範例一:醫療 Q&A 合成資料生成

這個範例展示如何使用 distilabel 從醫療領域的 seed questions (種子問題) 生成高品質的 QA (問答) 訓練資料,並使用 UltraFeedback 進行多維度品質評分。

 1"""
 2醫療 Q&A 合成資料生成 Pipeline
 3使用 TextGeneration + UltraFeedback 產出帶品質分數的訓練資料
 4"""
 5from datasets import Dataset
 6
 7from distilabel.models import OpenAILLM
 8from distilabel.pipeline import Pipeline
 9from distilabel.steps import KeepColumns, StepInput, step
10from distilabel.steps.tasks import TextGeneration, UltraFeedback
11
12# === 1. 定義 Seed Data (種子資料) ===
13seed_questions = [
14    {"instruction": "Explain the mechanism of action of PD-1 checkpoint inhibitors in treating renal cell carcinoma."},
15    {"instruction": "What are the key differences between ADC (antibody-drug conjugate) and traditional chemotherapy in terms of targeted delivery?"},
16    {"instruction": "Describe the standard pre-IND pharmacokinetics studies required by FDA for a biologic drug candidate."},
17    {"instruction": "How does CRISPR-Cas9 gene editing differ from traditional gene therapy approaches in treating genetic diseases?"},
18    {"instruction": "Explain the role of tumor microenvironment in immune evasion and its implications for immunotherapy."},
19]
20
21seed_dataset = Dataset.from_list(seed_questions)
22
23# === 2. 定義 LLM 模型 ===
24# 生成模型:負責生成回答
25generator_llm = OpenAILLM(
26    model="gpt-4o",
27    generation_kwargs={
28        "temperature": 0.7,
29        "max_new_tokens": 1024,
30    },
31)
32
33# 評判模型:負責品質評分
34judge_llm = OpenAILLM(
35    model="gpt-4o",
36    generation_kwargs={
37        "temperature": 0.0,  # 評判用低溫度確保一致性
38        "max_new_tokens": 512,
39    },
40)
41
42# === 3. 建構 Pipeline ===
43with Pipeline(name="medical-qa-sdg") as pipeline:
44
45    # Step 1: 文本生成 — 生成醫療問題的回答
46    generate = TextGeneration(
47        name="medical_answer_generation",
48        llm=generator_llm,
49        num_generations=3,  # 每個問題生成 3 個不同回答
50        system_prompt=(
51            "You are a senior biomedical researcher with expertise in "
52            "pharmacology, immunology, and regulatory science. "
53            "Provide detailed, accurate, and well-structured answers "
54            "suitable for training medical AI systems. "
55            "Include relevant citations format when applicable."
56        ),
57    )
58
59    # Step 2: UltraFeedback — 多維度 AI 品質評分
60    evaluate = UltraFeedback(
61        name="quality_evaluation",
62        llm=judge_llm,
63        aspect="overall-rating",  # 可選: helpfulness, honesty, truthfulness, instruction-following
64    )
65
66    # Step 3: 保留需要的欄位
67    keep = KeepColumns(
68        name="select_columns",
69        columns=[
70            "instruction",
71            "generation",
72            "ratings",
73            "rationales",
74        ],
75    )
76
77    # 連接步驟(>> 運算子定義依賴關係)
78    generate >> evaluate >> keep
79
80# === 4. 執行 Pipeline ===
81if __name__ == "__main__":
82    distiset = pipeline.run(dataset=seed_dataset)
83
84    # 查看結果
85    ds = distiset["default"]["train"]
86    print(f"生成 {len(ds)} 筆帶評分的醫療 QA 資料")
87    print(ds[0])
88
89    # 推送至 HuggingFace Hub
90    # distiset.push_to_hub("your-org/medical-qa-synthetic")

4.2 範例二:EvolInstruct 指令複雜度漸進進化

這個範例展示如何將簡單的醫療指令自動「進化」成更複雜、更具深度的指令,適合訓練更強的 domain-specific LLM (領域專用語言模型)。

 1"""
 2醫療指令漸進進化 Pipeline
 3使用 EvolInstruct 將簡單指令自動升級為複雜多步驟指令
 4"""
 5from datasets import Dataset
 6
 7from distilabel.models import InferenceEndpointsLLM
 8from distilabel.pipeline import Pipeline
 9from distilabel.steps import KeepColumns
10from distilabel.steps.tasks import EvolInstruct, EvolComplexity
11
12# === 1. 簡單的醫療 Seed Instructions (種子指令) ===
13simple_instructions = Dataset.from_list([
14    {"instruction": "What is an ADC drug?"},
15    {"instruction": "How does immunotherapy work?"},
16    {"instruction": "What is a pre-IND meeting?"},
17    {"instruction": "Explain pharmacokinetics."},
18    {"instruction": "What is a Phase 1 clinical trial?"},
19    {"instruction": "Describe CRISPR technology."},
20    {"instruction": "What are biomarkers?"},
21    {"instruction": "How do monoclonal antibodies work?"},
22])
23
24# === 2. 使用 HuggingFace Inference Endpoints ===
25llm = InferenceEndpointsLLM(
26    model_id="meta-llama/Meta-Llama-3.1-70B-Instruct",
27    generation_kwargs={
28        "temperature": 0.8,
29        "max_new_tokens": 512,
30    },
31)
32
33# === 3. 建構 EvolInstruct Pipeline ===
34with Pipeline(name="medical-evol-instruct") as pipeline:
35
36    # EvolInstruct: 每個指令進化 3 輪
37    # 進化策略包含:增加約束條件、增加推理步驟、深化複雜度、
38    # 加入具體化描述、混合多個子問題
39    evol = EvolInstruct(
40        name="evolve_medical_instructions",
41        llm=llm,
42        num_evolutions=3,          # 進化輪數
43        store_evolutions=True,     # 保留每一輪的進化結果
44        generate_answers=True,     # 同時生成進化後指令的回答
45    )
46
47    # 評估進化後指令的複雜度
48    complexity = EvolComplexity(
49        name="score_complexity",
50        llm=llm,
51    )
52
53    keep = KeepColumns(
54        name="select_output",
55        columns=[
56            "instruction",       # 原始指令
57            "evolved_instruction",  # 最終進化指令
58            "answer",            # 進化指令的回答
59            "model_name",
60        ],
61    )
62
63    evol >> complexity >> keep
64
65# === 4. 執行並檢視進化結果 ===
66if __name__ == "__main__":
67    distiset = pipeline.run(dataset=simple_instructions)
68    ds = distiset["default"]["train"]
69
70    # 展示進化前後對比
71    for row in ds.select(range(3)):
72        print("=" * 60)
73        print(f"[原始] {row['instruction']}")
74        print(f"[進化] {row['evolved_instruction']}")
75        print(f"[回答] {row['answer'][:200]}...")
76        print()
77
78    # 典型進化結果範例:
79    # [原始] What is an ADC drug?
80    # [進化] Compare the payload delivery mechanisms of three FDA-approved
81    #        ADC drugs (T-DXd, enfortumab vedotin, sacituzumab govitecan),
82    #        analyzing how linker chemistry and DAR (drug-to-antibody ratio)
83    #        affect their therapeutic indices across different tumor types.
84    #        Include a discussion of the bystander effect and its clinical
85    #        implications for heterogeneous tumors.

4.3 範例三:Structured Generation 生成結構化醫療標注資料

這個範例展示如何使用 distilabel 的 Structured Generation (結構化生成) 功能,產出符合特定 schema (結構) 的醫療標注資料,例如 NER (Named Entity Recognition; 命名實體辨識) 訓練資料。

 1"""
 2結構化醫療 NER 標注資料生成
 3使用 Instructor 確保 LLM 輸出符合 Pydantic schema
 4"""
 5from typing import List
 6
 7from datasets import Dataset
 8from pydantic import BaseModel, Field
 9
10from distilabel.models import OpenAILLM
11from distilabel.pipeline import Pipeline
12from distilabel.steps import KeepColumns
13from distilabel.steps.tasks import TextGeneration
14
15# === 1. 定義輸出 Schema (結構) ===
16class MedicalEntity(BaseModel):
17    """醫療命名實體"""
18    text: str = Field(description="Entity text span")
19    entity_type: str = Field(
20        description="Entity type",
21        enum=["DRUG", "DISEASE", "GENE", "PROTEIN", "PATHWAY", "DOSAGE", "BIOMARKER"]
22    )
23    start: int = Field(description="Start character offset")
24    end: int = Field(description="End character offset")
25
26class MedicalNERAnnotation(BaseModel):
27    """醫療文本 NER 標注"""
28    text: str = Field(description="Original clinical text")
29    entities: List[MedicalEntity] = Field(description="Extracted entities")
30    complexity: str = Field(
31        description="Text complexity level",
32        enum=["simple", "moderate", "complex"]
33    )
34
35# === 2. Seed Contexts (種子上下文) — 提供主題方向 ===
36seed_contexts = Dataset.from_list([
37    {"instruction": "Generate a synthetic clinical note about a patient with advanced NSCLC receiving pembrolizumab combination therapy. Include drug names, dosages, biomarker results (PD-L1, TMB), and disease progression notes."},
38    {"instruction": "Generate a synthetic pharmacovigilance report documenting adverse events of trastuzumab deruxtecan (T-DXd) in HER2-low breast cancer, including ILD grading and management."},
39    {"instruction": "Generate a synthetic clinical trial eligibility criteria section for a Phase 2 study of a novel bispecific antibody targeting CD3/CD20 in relapsed/refractory DLBCL."},
40])
41
42# === 3. 建構 Structured Generation Pipeline ===
43
44llm = OpenAILLM(
45    model="gpt-4o",
46    generation_kwargs={"temperature": 0.6, "max_new_tokens": 2048},
47    structured_output={
48        "format": "json",
49        "schema": MedicalNERAnnotation.model_json_schema(),
50    },
51)
52
53with Pipeline(name="medical-ner-sdg") as pipeline:
54
55    generate = TextGeneration(
56        name="generate_annotated_text",
57        llm=llm,
58        system_prompt=(
59            "You are a clinical NLP annotation expert. "
60            "Generate realistic synthetic clinical text and annotate all "
61            "medical entities with precise character offsets. "
62            "Ensure entity spans are accurate and non-overlapping. "
63            "The generated text should be realistic enough to train "
64            "a medical NER model."
65        ),
66    )
67
68    keep = KeepColumns(
69        name="select_output",
70        columns=["instruction", "generation", "model_name"],
71    )
72
73    generate >> keep
74
75# === 4. 執行 ===
76if __name__ == "__main__":
77    distiset = pipeline.run(dataset=seed_contexts)
78    ds = distiset["default"]["train"]
79
80    import json
81    for row in ds.select(range(2)):
82        parsed = json.loads(row["generation"])
83        print(f"Text: {parsed['text'][:100]}...")
84        print(f"Entities: {len(parsed['entities'])} found")
85        for ent in parsed["entities"][:5]:
86            print(f"  - [{ent['entity_type']}] \"{ent['text']}\"")
87        print()

5. 在醫療 LLM / 文本 SDG 生態系中的定位

5.1 Domain 6 生態系定位

在 Bio-SDG Domain 6「醫療 LLM 與文本 SDG」的 15 個專案中,distilabel 屬於 Sub-domain B: LLM-driven SDG Frameworks (LLM 驅動的合成資料生成框架),是該子領域中功能最完整、社群最活躍的框架。


graph LR
    subgraph DomainB["Sub-domain B: LLM-driven SDG Frameworks"]
        DL["distilabel
完整 pipeline 框架
★3248 | 論文驗證"] HZ["hitsz-ids/SDG
文本分類 SDG
小型工具"] SH["sdg_hub
SDG 技術聚合
教學導向"] VS["verbalized-sampling
LLM 多樣性取樣
研究性質"] end subgraph DomainA["Sub-domain A: Medical LLM Training"] MG["MedicalGPT
完整訓練管線"] BG["BioGPT
微軟研究"] BM["BioMedLM
Stanford"] end subgraph DomainC["Sub-domain C: Radiology Report Gen"] R2["R2GenGPT"] RF["RadFact"] LR["LLM-RG4"] FT["FORTE"] end DL -->|"生成訓練資料"| MG DL -->|"生成訓練資料"| BG DL -->|"品質評分"| DomainC DL -->|"技術基底"| HZ DL -->|"資源彙整"| SH style DL fill:#ff9800,stroke:#e65100,color:#fff,font-weight:bold style DomainB fill:#fff3e0,stroke:#f57c00 style DomainA fill:#e1f5fe,stroke:#0288d1 style DomainC fill:#f3e5f5,stroke:#7b1fa2

5.2 與其他 Sub-domain 的協作關係

協作方向說明
distilabel → MedicalGPT / BioGPT用 distilabel 生成 SFT (Supervised Fine-Tuning; 監督式微調) 與 DPO (Direct Preference Optimization; 直接偏好最佳化) 訓練資料,供醫療 LLM 訓練管線使用
distilabel → Radiology Report用 UltraFeedback / PrometheusEval 自動評估放射報告生成模型的輸出品質
distilabel → GEML-MDG用 EvolInstruct 將簡單醫療對話場景進化為複雜多輪對話
distilabel ← Clinical Text以臨床文本為 seed data,透過 Self-Instruct / Genstruct 反向生成指令-回答對

5.3 醫療 SDG 的 Blue Ocean (藍海機會)

distilabel 在以下醫療文本 SDG 場景中尤其有價值,且目前競爭者稀少:

  1. Clinical Notes SDG (臨床筆記合成):利用 Structured Generation 產出符合 HL7 FHIR 格式的合成臨床筆記,解決真實臨床資料的 PHI (Protected Health Information; 受保護健康資訊) 隱私限制
  2. Regulatory Document SDG (法規文件合成):用 EvolInstruct 從 FDA Guidance 文件生成 pre-IND submission 的 QA 訓練資料
  3. EHR Narrative SDG (電子病歷敘述合成):結合 domain-specific LLM 與 distilabel 的 Magpie 方法,生成醫病對話 → 轉換為結構化 EHR 記錄
  4. Pharmacovigilance SDG (藥物安全監控合成):產出不良反應報告訓練資料,包含 MedDRA 編碼對應

6. 與其他工具的整合

6.1 與 AIKT Pipeline 的整合

distilabel 可以與 AI-Knowledge Template (AIKT) pipeline 的多個 Layer 無縫整合:

AIKT Layer整合方式
Layer 9: paper-search用 paper-search 蒐集醫療論文 → 以論文全文作為 distilabel seed data 的知識來源
Layer 10: paper-qa-lite用 paper-qa-lite 驗證 distilabel 生成的醫療回答是否與文獻一致
Layer 8: docling用 docling 解析 FDA Guidance PDF → 作為 distilabel 的 seed instructions
Layer 19: tu-plan-generator用 ToolUniverse 的 ChEMBL / PubChem 查詢結果注入 distilabel 的 system prompt,確保生成資料的分子描述準確

6.2 與 HuggingFace 生態系整合

 1# 從 HuggingFace 載入 seed 資料
 2from datasets import load_dataset
 3seed = load_dataset("bigbio/med_qa", split="train[:100]")
 4
 5# 執行 distilabel pipeline
 6distiset = pipeline.run(dataset=seed)
 7
 8# 推送到 HuggingFace Hub
 9distiset.push_to_hub(
10    repo_id="your-org/medical-sdg-output",
11    private=True,
12    token="hf_..."
13)

6.3 與 Argilla 標注平台整合

distilabel 內建與 Argilla 的整合步驟,可將生成的資料直接推送到 Argilla 進行人工審核與修正:

 1from distilabel.steps.argilla import TextGenerationToArgilla
 2
 3# 在 pipeline 中加入 Argilla 匯出步驟
 4export_to_argilla = TextGenerationToArgilla(
 5    name="export_to_argilla",
 6    dataset_name="medical-sdg-review",
 7    dataset_workspace="biomedical",
 8    api_url="https://your-argilla.com",
 9    api_key="your-key",
10)

6.4 與 vLLM / Ollama 本地推論整合

對於處理敏感醫療資料(如含 PHI 的臨床筆記),可完全在本地執行:

 1from distilabel.models import vLLM, OllamaLLM
 2
 3# 選項 A: vLLM(高吞吐量)
 4local_llm = vLLM(
 5    model="meta-llama/Meta-Llama-3.1-8B-Instruct",
 6    extra_kwargs={"tensor_parallel_size": 2},
 7)
 8
 9# 選項 B: Ollama(輕量部署)
10local_llm = OllamaLLM(
11    model="llama3.1:8b",
12    host="http://localhost:11434",
13)

6.5 使用 Ray 進行分散式擴展

1from distilabel.pipeline import Pipeline
2
3# 只需變更 Pipeline 的 with_ray 參數即可擴展
4with Pipeline(name="medical-sdg-at-scale").ray() as pipeline:
5    # pipeline 定義完全相同
6    # Ray 自動處理分散式排程與容錯
7    ...

7. 優缺點分析

7.1 優點

面向優點說明
學術驗證內建 8+ 篇論文實作UltraFeedback、EvolInstruct、DEITA、Prometheus 等,不需自行重現研究方法
Provider 中立15+ LLM 供應商統一 API同一 pipeline 可輕鬆切換 provider,不被供應商鎖定
工程品質DAG 排程 + BatchManager真正的 pipeline 工程,不是簡單的 for-loop wrapper
容錯機制Caching + CheckpointPipeline 中斷可從斷點續跑,節省 API 費用
可擴展本地到 Ray 叢集程式碼不變,僅切換執行引擎即可水平擴展
結構化輸出Outlines + Instructor 整合確保 LLM 輸出符合 Pydantic schema,適合生成結構化醫療標注
生態整合HuggingFace + Argilla從資料來源到標注平台的完整鏈路
可組合性Step / Task 模組化設計可自由組合生成、評估、過濾、格式化步驟

7.2 缺點

面向缺點影響與緩解
社群狀態原始作者已離開,由社群接手長期維護穩定性存在不確定性;但 develop branch 仍活躍
醫療領域特化不足無內建醫療 domain 的 prompt template需自行設計醫療領域的 system prompt 與 evaluation rubric;可用 Prometheus 的 custom rubric 功能
學習曲線概念多(Step、Task、Pipeline、Distiset)需要理解 DAG、BatchManager 等概念才能有效除錯
API 成本多步驟 pipeline 累積 API 呼叫費用num_generations 控制生成數量;用本地模型(vLLM / Ollama)替代雲端 API
Debug 困難Pipeline 錯誤追蹤不直覺建議先用小資料集(10-20 筆)驗證 pipeline 正確性,再擴大規模
文件更新部分文件與最新 API 不同步以 source code (原始碼) 中的 docstring 為準,配合 examples/ 目錄
無 GUI純 CLI + Python API不適合非工程背景使用者;需搭配 Argilla 才有視覺化標注介面

7.3 與同 Sub-domain 工具的比較

特性distilabelhitsz-ids/SDGsdg_hubverbalized-sampling
Pipeline 架構完整 DAG簡單流程教學範例單一方法
LLM 支援15+ providersOpenAI 為主多種1-2 種
論文實作8+ 篇1-2 篇概念整合1 篇
分散式擴展Ray 支援
結構化輸出Outlines + Instructor
社群活躍度高(3248 stars)
醫療特化通用(需自訂)文本分類通用通用

7.4 適用場景建議

場景推薦度說明
產出 SFT / DPO 訓練資料給醫療 LLM★★★★★核心使用場景,UltraFeedback + EvolInstruct 組合最強
生成結構化醫療標注(NER、RE)★★★★☆搭配 Instructor 效果佳,需注意 entity offset 準確性
臨床筆記合成(去識別化替代方案)★★★★☆搭配本地 vLLM 確保隱私,需人工審核品質
小規模快速原型(< 100 筆)★★★☆☆Pipeline 架構對小規模有過度工程之嫌,直接呼叫 LLM API 可能更快
醫療對話系統訓練資料★★★★☆Magpie 方法適合生成多輪對話,需搭配醫療知識驗證
放射報告品質評估★★★★☆Prometheus 的 custom rubric 功能可定義放射學特定評分標準

一句話總結:distilabel 是目前最成熟的 LLM 合成資料框架,以論文驗證方法論 + DAG pipeline 工程 + 15+ provider 支援為核心優勢,適合需要大規模、高品質醫療訓練資料的團隊,但需自行設計醫療 domain-specific 的 prompt 與 evaluation rubric。