大模型训练数据治理:从数据采集到质量评估的全链路
数据:大模型能力的源头 “Garbage in, garbage out"在LLM时代被放大了1000倍。一个7B模型用高质量数据训练可以超越用低质量数据训练的70B模型。数据治理是决定模型能力上限的第一道关卡。 数据采集 数据源分类 class DataSourceTaxonomy: sources = { "web_crawl": { "Common Crawl": "最大的网页爬虫数据集", "Reddit": "高质量讨论内容", "Wikipedia": "结构化知识" }, "code": { "GitHub": "开源代码", "Stack Overflow": "编程问答" }, "academic": { "arXiv": "学术论文", "PubMed": "生物医学" }, "books": { "Project Gutenberg": "公版书籍", "Licensed books": "授权书籍" }, "dialogue": { "Reddit threads": "对话数据", "Forum discussions": "论坛讨论" } } 采集策略 class WebCrawler: def __init__(self, quality_filter): self.filter = quality_filter def crawl(self, url): # 1. 抓取页面 html = self._fetch(url) # 2. 正文提取(去除导航、广告等) content = self._extract_main_content(html) # 3. 质量初筛 quality_score = self.filter.assess(content) if quality_score < 0.3: return None # 质量太低,跳过 # 4. 语言检测 lang = detect_language(content) # 5. 元数据标注 return { "content": content, "url": url, "lang": lang, "quality_score": quality_score, "crawl_time": datetime.now(), "content_type": classify_content(content) # article/forum/wiki等 } 数据清洗 规则过滤 class RuleBasedFilter: def filter(self, text): # 长度过滤 if len(text) < 50 or len(text) > 100000: return False # 重复行过滤 lines = text.split('\n') unique_ratio = len(set(lines)) / len(lines) if unique_ratio < 0.5: return False # 特殊字符比例 special_ratio = sum(1 for c in text if not c.isalnum() and c not in ' \n.,!?;:\'"-()') / len(text) if special_ratio > 0.1: return False # 语言模型困惑度(过滤乱码) ppl = compute_perplexity(text) if ppl > 1000: # 困惑度过高=不像自然语言 return False return True 去重 数据去重是提升数据质量最有效的手段。研究表明,去重可以将模型性能提升3-5个点。 ...


