{
  "schema_version": "1.0",
  "id": "T-9b33b94dfce1",
  "url": "https://gpuatlas.top/articles/T-9b33b94dfce1/",
  "title": "想训练自己的分词器，会怎样影响后面的模型训练？",
  "summary": "分词器决定token ID、序列长度和模型词表接口，自训后应固定版本，不能直接替换已有模型的配套分词器。",
  "language": "zh-Hans",
  "category": {
    "id": "c-21",
    "name": "从零训练与继续预训练",
    "url": "https://gpuatlas.top/categories/c-21/"
  },
  "topics": [
    {
      "id": "task-796e01d5af",
      "name": "训练",
      "kind": "task",
      "description": "模型训练时的资源占用与推理不同。查看优化器、激活值、并行策略和中断恢复相关问题。",
      "url": "https://gpuatlas.top/topics/task-796e01d5af/"
    }
  ],
  "body_text": "自训分词器会改变后续数据和模型接口，应该在大规模分词和预训练前定版。它决定文本如何变成token ID，也影响词表、嵌入层、输出头及特殊符号；不是随时可以替换的独立配件。\n\n先区分从零训练和继续使用预训练权重。新模型可以围绕自己的词表设计；已有模型的嵌入和输出已经对应原token ID，直接换一套分词器并不能保留这些含义。扩词或改接口需要另行设计与训练验证，不能只把词表大小改成一样。\n\n训练分词器时，选择代表目标语言和代码的语料，记录归一化、预切分、词表大小及特殊token。更大词表可能缩短一些输入，也可能增加模型词表相关参数，不能只按压缩率选方案。\n\n用独立语料检查token长度分布、未知符号、数字、空白、代码和往返解码，确认特殊符号及其ID稳定。保存完整分词器文件、规则和语料版本，再生成可追溯的分词数据。模型配置、截断和打包长度按实际token重新检查。\n\n最后用小模型跑通训练、保存恢复和生成。中途更换分词器会改变数据与检查点接口，旧loss和每秒token也未必还能直接比较。词表大小应由覆盖、长度效率和模型成本共同决定，而不是挑一个看起来越大越好的数字。",
  "published_at": null,
  "modified_at": "2026-11-26T15:17:38.690397+00:00",
  "evidence": {
    "type": "documentation_and_conditional_estimates",
    "hardware_tested": false,
    "note": "资料解释与条件估算，非硬件实测。"
  },
  "sources": [
    {
      "id": "hf-tokenizer-training",
      "url": "https://huggingface.co/docs/tokenizers/quicktour",
      "retrieved_at": "2026-11-25T15:58:33.081746+00:00"
    },
    {
      "id": "transformers-causal-training",
      "url": "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/tasks/language_modeling.md",
      "retrieved_at": "2026-11-25T10:51:53.600205+00:00"
    },
    {
      "id": "hf-dataset-split",
      "url": "https://huggingface.co/docs/datasets/process",
      "retrieved_at": "2026-11-25T15:58:33.081746+00:00"
    }
  ],
  "revision_note": "完善阅读结构；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-9b33b94dfce1/",
    "json": "https://gpuatlas.top/data/articles/T-9b33b94dfce1.json",
    "markdown": "https://gpuatlas.top/data/articles/T-9b33b94dfce1.md"
  }
}
