continual pretraining domain knowledge injection

持续预训练实践:让开源模型学会领域知识

什么是持续预训练 持续预训练(Continual Pre-Training, CPT)是在已有的预训练模型基础上,用领域数据继续训练,让模型"学会"领域知识。与 SFT 不同,CPT 的目标不是学习特定任务格式,而是注入知识本身。 预训练 (PT) 持续预训练 (CPT) 监督微调 (SFT) 通用语料 ──→ 基础模型 ──→ 领域模型 ──→ 任务模型 (万亿token) (百亿token) (万级样本) 1. 数据工程 数据来源与采集 class CPTDataCollector: def __init__(self, domain: str): self.domain = domain def collect(self) -> dict: sources = { "medical": self._collect_medical, "legal": self._collect_legal, "finance": self._collect_finance, "code": self._collect_code, } return sources.get(self.domain, self._collect_general)() def _collect_medical(self): return { "academic_papers": "PubMed Central 全文", "textbooks": "医学教材电子版", "clinical_guidelines": "各国临床指南", "drug_labels": "FDA/NMPA 药品说明书", "medical_encyclopedia": "医学百科全书", "estimated_tokens": "约 50B tokens" } def _collect_legal(self): return { "laws_regulations": "法律法规数据库", "court_cases": "裁判文书网", "legal_commentary": "法学期刊", "legal_textbooks": "法学教材", "contracts": "合同模板库", "estimated_tokens": "约 30B tokens" } 数据配比:最关键的超参数 数据配比决定了模型在领域知识和通用能力之间的平衡。 class DataMixer: def __init__(self): # 2026 年推荐配比(基于实验) self.ratios = { "domain_heavy": { # 重度领域适配 "domain": 0.7, "general": 0.2, "code": 0.05, "math": 0.05 }, "domain_balanced": { # 平衡适配(推荐) "domain": 0.5, "general": 0.35, "code": 0.1, "math": 0.05 }, "domain_light": { # 轻度适配 "domain": 0.3, "general": 0.55, "code": 0.1, "math": 0.05 } } def mix(self, domain_data: list, general_data: list, strategy: str = "domain_balanced"): ratio = self.ratios[strategy] total_tokens = 10_000_000_000 # 10B tokens domain_tokens = int(total_tokens * ratio["domain"]) general_tokens = int(total_tokens * ratio["general"]) mixed = [] mixed.extend(self._sample(domain_data, domain_tokens)) mixed.extend(self._sample(general_data, general_tokens)) # 打乱 random.shuffle(mixed) return mixed 配比实验结果 配比策略 领域任务 通用任务 代码 数学 灾难性遗忘 100% 领域 88% 42% 35% 38% 严重 ❌ 70% 领域 85% 68% 52% 55% 中等 ⚠️ 50% 领域 82% 75% 68% 65% 轻微 ✅ 30% 领域 76% 82% 72% 70% 无 ✅ 0% (baseline) 65% 85% 75% 72% 无 ✅ 结论:50% 领域数据是最佳平衡点。 ...

2026-06-28 · 4 min · 849 words · 硅基 AGI 探索者
鲁ICP备2026018361号