tsuberim/merlin-corpus-v1
收藏资源简介:
--- license: other language: - en tags: - code - pretraining - agentic size_categories: - 10B<n<100B --- # Merlin Corpus v1 Pretraining corpus for [Merlin](https://github.com/tsuberim/merlin) — a small language model purpose-built for agentic coding on Apple Silicon. Target: 3B parameters, 6K context, fast local inference. Two scales are provided: | Scale | Path | Tokens | Chunks | Use | |---|---|---|---|---| | Experiment | `experiment/` | ~7B | ~570K | Rapid iteration, ablations | | Full | `full/` | ~88B | ~7.2M | Production pretraining run | Both use identical format, tokenizer, and source mix — only the per-source document cap differs. --- ## Format Binary files, one per split: ``` experiment/corpus_train.bin # 90% of shuffled documents experiment/corpus_val.bin # 10% of shuffled documents full/corpus_train.bin full/corpus_val.bin ``` Each file is a flat array of **uint16** tokens packed into fixed-length **6144-token** chunks: ```python import numpy as np train = np.fromfile("experiment/corpus_train.bin", dtype=np.uint16).reshape(-1, 6144) val = np.fromfile("experiment/corpus_val.bin", dtype=np.uint16).reshape(-1, 6144) # train.shape → (N, 6144) ``` - **dtype**: `uint16` — vocab fits comfortably in 16 bits (vocab size 32,016) - **packing**: documents are concatenated greedily; no padding — ~100% token utilisation - **document separator**: `<|eos|>` (token ID 1) marks every document boundary - **train/val split**: 90/10 at document level, shuffled with `seed=42` ### Loading a batch ```python import numpy as np import torch data = np.fromfile("experiment/corpus_train.bin", dtype=np.uint16).reshape(-1, 6144) idx = np.random.randint(0, len(data), size=batch_size) x = torch.from_numpy(data[idx].astype(np.int32)) # (B, 6144) ``` ### Attention masking across document boundaries Documents are packed contiguously, so a block-diagonal causal mask is needed at training time to prevent cross-document attention: ```python EOS_ID = 1 is_eos = (x == EOS_ID) doc_id = torch.cat([torch.zeros_like(is_eos[:, :1]), is_eos[:, :-1].cumsum(dim=1)], dim=1) mask = (doc_id.unsqueeze(2) == doc_id.unsqueeze(1)) & causal_mask # (B, 1, T, T) ``` --- ## Tokenizer [tsuberim/merlin-tokenizer-v0](https://huggingface.co/tsuberim/merlin-tokenizer-v0) - BPE, 32,016 tokens (32K base + 16 special tokens for agent protocol + `<|bos|>` / `<|eos|>`) - Trained on Python, Bash, Markdown, shell traces, and agent protocol examples - `<|bos|>` = 0, `<|eos|>` = 1 --- ## Sources ~88B tokens across code, technical NL, math, and instruction data (experiment scale uses ~7B via per-source document caps). ### Code (~54%) | Source | Dataset | Token budget | |---|---|---| | The Stack v2 — Python | `bigcode/the-stack-v2-dedup` | 20B | | The Stack v2 — TypeScript | `bigcode/the-stack-v2-dedup` | 5B | | The Stack v2 — Go | `bigcode/the-stack-v2-dedup` | 3B | | The Stack v2 — Rust | `bigcode/the-stack-v2-dedup` | 2B | | The Stack v2 — Bash/Shell | `bigcode/the-stack-v2-dedup` | 2B | | The Stack v2 — YAML | `bigcode/the-stack-v2-dedup` | 2B | | The Stack v2 — Dockerfile | `bigcode/the-stack-v2-dedup` | 0.3B | | The Stack v2 — SQL | `bigcode/the-stack-v2-dedup` | 3B | | The Stack v2 — Markdown | `bigcode/the-stack-v2-dedup` | 5B | | Jupyter notebooks (executed) | `codeparrot/github-jupyter-parsed` | 10B | | PyPI package READMEs | `codeparrot/pypi-data` | 0.3B | | GitHub commits | `bigcode/commitpackft` | 0.75B | | GitHub issues | `bigcode/the-stack-github-issues` | 0.75B | | Rosetta Code | `codeef/rosetta-code` | 0.2B | | Papers with Code | `J0nasW/paperswithcode` | 0.5B | ### Q&A (~5%) | Source | Dataset | Token budget | |---|---|---| | Stack Overflow | `bigcode/the-stack-v2-dedup` (SO subset) | 1B | | Code Review / Unix.SE / ServerFault / AskUbuntu / SoftEng / DevOps / DataSci SE | Stack Exchange dump | ~4B | ### Reference (~2%) | Source | Token budget | |---|---| | Full man pages | 0.1B | | Python stdlib docs + tutorial | 0.3B | | PEPs | 0.05B | | Pro Git book + Docker docs + Bash manual | 0.5B | | RFCs (HTTP, JSON, UNIX subset) | 0.1B | | Library docs (NumPy, Pandas, scikit-learn, matplotlib, requests) | 0.1B | | tldr-pages | 0.3B | ### Pedagogical (~3%) | Source | Token budget | |---|---| | Wikibooks — Computing/Programming | 0.7B | | Python Data Science Handbook | 0.2B | | Fast.ai course notebooks | 0.2B | | SICP | 0.05B | ### NL / General Knowledge (~11%) | Source | Dataset | Token budget | |---|---|---| | FineWeb-Edu (education score ≥4) | `HuggingFaceFW/fineweb-edu` | 7B | | ArXiv CS | `togethercomputer/RedPajama-Data-1T` | 3B | | Wikipedia (CS/computing/math) | `wikimedia/wikipedia` | 0.8B | ### Instruction Following (~5%) | Source | Dataset | Token budget | |---|---|---| | FLAN v2 (code + reasoning subsets) | `Muennighoff/flan` | 3B | | Natural Instructions v2 | `Muennighoff/natural-instructions` | 1.5B | | OpenHermes 2.5 | `teknium/OpenHermes-2.5` | 1B | | NL2Bash | Dropbox archive | 0.01B | ### Math (~6%) | Source | Dataset | Token budget | |---|---|---| | NuminaMath | `AI-MO/NuminaMath-CoT` | 1.5B | | DeepMind Mathematics | `math-ai/orca-math-word-problems-200k` | 1.5B | | Proof-Pile 2 (subset) | `EleutherAI/proof-pile-2` | 3B | | MetaMathQA | `meta-math/MetaMathQA` | ~0.4B | ### What's not here - **Synthetic agentic traces** (15B target): generated in a later pipeline stage (milestone 3b) — not yet available - **Dev.to / HashNode** (2B target): no public dataset - **Exercism**: only ~133 examples on HF — negligible, omitted --- ## Quality strategy - **Stack v2**: BigCode already license-filtered, deduplicated, and curated. Filters: `is_generated=false`, `is_vendor=false`. - **Q&A**: accepted answers only, score threshold, domain filter. - **No NC-licensed content** — safe for commercial use. - **Document-level shuffle** before packing; reproducible with `seed=42`. --- ## Pipeline Built with [DataTrove](https://github.com/huggingface/datatrove) + custom adapters. Source: [`tsuberim/merlin`](https://github.com/tsuberim/merlin), `data/pipeline/`.
--- 许可证:其他 语言: - 英语 标签: - 代码 - 预训练 - 智能体编程(agentic) 规模类别: - 100亿 < Token数 < 1000亿 --- # 默林语料库v1(Merlin Corpus v1) 专为苹果硅(Apple Silicon)平台上的智能体编程(agentic coding)打造的小型语言模型**默林(Merlin)**的预训练语料库。其目标参数规模为30亿,上下文长度达6000 Token,支持快速本地推理。 本次发布提供两个规模版本: | 规模 | 路径 | Token数 | 块数 | 用途 | |---|---|---|---|---| | 实验版 | `experiment/` | 约70亿 | 约57万 | 快速迭代与消融实验 | | 完整版 | `full/` | 约880亿 | 约720万 | 生产级预训练任务 | 两个版本采用完全一致的格式、分词器与数据源混合策略,仅各数据源的文档上限存在差异。 --- ## 数据格式 采用二进制文件存储,每个拆分对应一个文件: experiment/corpus_train.bin # 打乱后文档的90% experiment/corpus_val.bin # 打乱后文档的10% full/corpus_train.bin full/corpus_val.bin 每个文件为**uint16**类型的Token扁平数组,被打包为固定长度的**6144-Token**块: python import numpy as np train = np.fromfile("experiment/corpus_train.bin", dtype=np.uint16).reshape(-1, 6144) val = np.fromfile("experiment/corpus_val.bin", dtype=np.uint16).reshape(-1, 6144) # train.shape → (N, 6144) - **数据类型**:`uint16` — 词表可完全适配16位存储(词表大小为32016) - **打包方式**:文档按贪心策略拼接,无填充Token — Token利用率达~100% - **文档分隔符**:`<|eos|>`(Token ID为1)标记每个文档的边界 - **训练/验证拆分**:按文档级别以90:10拆分,使用`seed=42`进行打乱 ### 批量加载示例 python import numpy as np import torch data = np.fromfile("experiment/corpus_train.bin", dtype=np.uint16).reshape(-1, 6144) idx = np.random.randint(0, len(data), size=batch_size) x = torch.from_numpy(data[idx].astype(np.int32)) # (B, 6144) ### 跨文档边界的注意力掩码 由于文档是连续打包的,训练时需要使用分块对角因果掩码以避免跨文档注意力计算: python EOS_ID = 1 is_eos = (x == EOS_ID) doc_id = torch.cat([torch.zeros_like(is_eos[:, :1]), is_eos[:, :-1].cumsum(dim=1)], dim=1) mask = (doc_id.unsqueeze(2) == doc_id.unsqueeze(1)) & causal_mask # (B, 1, T, T) --- ## 分词器 [默林分词器v0(tsuberim/merlin-tokenizer-v0)](https://huggingface.co/tsuberim/merlin-tokenizer-v0) - 采用字节对编码(BPE),共32016个Token(32K基础词表 + 16个智能体协议专用特殊Token + `<|bos|>` / `<|eos|>`) - 在Python代码、Bash脚本、Markdown文档、Shell轨迹与智能体协议示例上训练得到 - `<|bos|>`对应Token ID为0,`<|eos|>`对应Token ID为1 --- ## 数据源 总Token数约880亿,涵盖代码、技术自然语言、数学与指令跟随数据(实验版通过各数据源文档上限控制在约70亿Token)。 ### 代码数据(占比约54%) | 数据源 | 数据集 | Token配额 | |---|---|---| | The Stack v2 — Python代码 | `bigcode/the-stack-v2-dedup` | 200亿 | | The Stack v2 — TypeScript代码 | `bigcode/the-stack-v2-dedup` | 50亿 | | The Stack v2 — Go代码 | `bigcode/the-stack-v2-dedup` | 30亿 | | The Stack v2 — Rust代码 | `bigcode/the-stack-v2-dedup` | 20亿 | | The Stack v2 — Bash/Shell脚本 | `bigcode/the-stack-v2-dedup` | 20亿 | | The Stack v2 — YAML配置 | `bigcode/the-stack-v2-dedup` | 20亿 | | The Stack v2 — Dockerfile | `bigcode/the-stack-v2-dedup` | 3亿 | | The Stack v2 — SQL代码 | `bigcode/the-stack-v2-dedup` | 30亿 | | The Stack v2 — Markdown文档 | `bigcode/the-stack-v2-dedup` | 50亿 | | 已解析Jupyter笔记本 | `codeparrot/github-jupyter-parsed` | 100亿 | | PyPI包README文档 | `codeparrot/pypi-data` | 3亿 | | GitHub提交记录 | `bigcode/commitpackft` | 7.5亿 | | GitHub议题 | `bigcode/the-stack-github-issues` | 7.5亿 | | Rosetta Code | `codeef/rosetta-code` | 2亿 | | Papers with Code | `J0nasW/paperswithcode` | 5亿 | ### 问答数据(占比约5%) | 数据源 | 数据集 | Token配额 | |---|---|---| | Stack Overflow | `bigcode/the-stack-v2-dedup`(SO子集) | 10亿 | | Code Review / Unix.SE / ServerFault / AskUbuntu / SoftEng / DevOps / DataSci SE | Stack Exchange转储数据 | 约40亿 | ### 参考文档(占比约2%) | 数据源 | Token配额 | |---|---| | 完整手册页 | 1亿 | | Python标准库文档 + 官方教程 | 3亿 | | Python增强提案(PEPs) | 0.5亿 | | Pro Git书籍 + Docker文档 + Bash手册 | 5亿 | | RFC文档(HTTP、JSON、UNIX子集) | 1亿 | | 库文档(NumPy、Pandas、scikit-learn、matplotlib、requests) | 1亿 | | tldr-pages | 3亿 | ### 教学资料(占比约3%) | 数据源 | Token配额 | |---|---| | Wikibooks — 计算/编程板块 | 7亿 | | Python数据科学手册 | 2亿 | | Fast.ai课程笔记本 | 2亿 | | 计算机程序的构造和解释(SICP) | 0.5亿 | ### 自然语言/通用知识(占比约11%) | 数据源 | 数据集 | Token配额 | |---|---|---| | FineWeb-Edu(教育评分≥4) | `HuggingFaceFW/fineweb-edu` | 70亿 | | ArXiv计算机科学论文 | `togethercomputer/RedPajama-Data-1T` | 30亿 | | 维基百科(计算机/数学板块) | `wikimedia/wikipedia` | 8亿 | ### 指令跟随(占比约5%) | 数据源 | 数据集 | Token配额 | |---|---|---| | FLAN v2(代码+推理子集) | `Muennighoff/flan` | 30亿 | | Natural Instructions v2 | `Muennighoff/natural-instructions` | 15亿 | | OpenHermes 2.5 | `teknium/OpenHermes-2.5` | 10亿 | | NL2Bash | Dropbox存档 | 0.1亿 | ### 数学数据(占比约6%) | 数据源 | 数据集 | Token配额 | |---|---|---| | NuminaMath | `AI-MO/NuminaMath-CoT` | 15亿 | | DeepMind数学数据集 | `math-ai/orca-math-word-problems-200k` | 15亿 | | Proof-Pile 2(子集) | `EleutherAI/proof-pile-2` | 30亿 | | MetaMathQA | `meta-math/MetaMathQA` | 约4亿 | ### 未包含的数据源 - **智能体合成轨迹(目标150亿Token)**:将在后续流水线阶段生成(里程碑3b),暂未发布 - **Dev.to / HashNode(目标20亿Token)**:暂无公开数据集 - **Exercism**:Hugging Face平台上仅约133个示例,占比可忽略,故未纳入 --- ## 质量控制策略 - **Stack v2数据集**:已由BigCode完成许可证过滤、去重与整理。过滤规则:`is_generated=false`、`is_vendor=false`。 - **问答数据**:仅保留已采纳的回答,设置分数阈值与领域过滤条件。 - **无NC许可证内容**:确保可安全用于商业用途。 - **文档级打乱**:打包前对文档进行洗牌,使用`seed=42`保证可复现性。 --- ## 数据流水线 基于[DataTrove](https://github.com/huggingface/datatrove)与自定义适配器构建。 源代码仓库:[`tsuberim/merlin`](https://github.com/tsuberim/merlin),流水线脚本位于`data/pipeline/`目录下。



