ALL INTELLIGENCE
GitHub Trending AIT2·Open Source

LLMs-from-scratch Hits 106k Stars: Build GPT from Scratch

By rasbtOriginal title: ⭐ rasbt/LLMs-from-scratch (106169 stars)
68AI Score

Sebastian Raschka's open-source project LLMs-from-scratch has surpassed 106,000 GitHub stars, establishing itself as a benchmark resource for understanding LLM internals. The repository accompanies the book of the same name, providing end-to-end code for data preprocessing, Transformer implementation, pretraining, and fine-tuning to help developers grasp how large language models work by building them from scratch.

Full Report

从零构建大语言模型

本仓库包含开发、预训练和微调类 GPT 大语言模型(LLM)的代码,是书籍《Build a Large Language Model (From Scratch)》的官方代码仓库。

<br> <br>

<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/cover.jpg?123" width="250px">

<br>

在《Build a Large Language Model (From Scratch)》一书中,你将通过从零开始、逐步编写代码的方式,由内而外地学习并理解大型语言模型(LLM)的工作原理。在这本书中,我将指导你创建自己的 LLM,并通过清晰的文字、图表和示例解释每个阶段。

本书介绍的用于训练和开发你自己的小型但功能完备的教育用模型的方法,与创建 ChatGPT 背后的大规模基础模型所采用的方法一致。此外,本书还包含了加载更大规模预训练模型权重以进行微调的代码。

<img src="https://sebastianraschka.com//images/LLMs-from-scratch-images/other/reviews.png" width="220px">

<br> <br>

要下载此仓库的副本,请点击 Download ZIP 按钮,或在终端中执行以下命令:

BASH
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git
<br>

(如果你是从 Manning 网站下载的代码包,建议访问 GitHub 上的官方代码仓库 https://github.com/rasbt/LLMs-from-scratch 以获取最新更新。)

<br> <br>

目录

请注意,此 README.md 文件是一个 Markdown (.md) 文件。如果你从 Manning 网站下载了此代码包并在本地计算机上查看,建议使用 Markdown 编辑器或预览器以获得正确的显示效果。如果你尚未安装 Markdown 编辑器,Ghostwriter 是一个不错的免费选择。

你也可以在 GitHub 上通过浏览器查看此文件及其他文件,地址为 https://github.com/rasbt/LLMs-from-scratch,GitHub 会自动渲染 Markdown。

<br> <br>

提示: 如果你需要关于安装 Python 和 Python 包以及配置代码环境的指导,建议阅读位于 setup 目录中的 README.md 文件。

<br> <br>
章节标题主要代码(快速访问)全部代码 + 补充材料
设置建议 <br/>如何最佳阅读本书--
第 1 章:理解大型语言模型无代码-
第 2 章:处理文本数据- ch02.ipynb<br/>- dataloader.ipynb (摘要)<br/>- exercise-solutions.ipynb./ch02
第 3 章:编码注意力机制- ch03.ipynb<br/>- multihead-attention.ipynb (摘要) <br/>- exercise-solutions.ipynb./ch03
第 4 章:从零实现 GPT 模型- ch04.ipynb<br/>- gpt.py (摘要)<br/>- exercise-solutions.ipynb./ch04
第 5 章:在无标签数据上进行预训练- ch05.ipynb<br/>- gpt_train.py (摘要) <br/>- gpt_generate.py (摘要) <br/>- exercise-solutions.ipynb./ch05
第 6 章:文本分类微调- ch06.ipynb <br/>- gpt_class_finetune.py <br/>- exercise-solutions.ipynb./ch06
第 7 章:指令跟随微调- ch07.ipynb<br/>- gpt_instruction_finetuning.py(摘要)<br/>- ollama_evaluate.py(摘要)<br/>- exercise-solutions.ipynb./ch07
附录 A:PyTorch 入门- code-part1.ipynb<br/>- code-part2.ipynb<br/>- DDP-script.py<br/>- exercise-solutions.ipynb./appendix-A
附录 B:参考文献与延伸阅读无代码

[注:本文篇幅超长,以上为核心前篇精译,后续内容保留原文呈现]

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)