# Build a Large Language Model (From Scratch)
This repository contains the code for developing, pretraining, and finetuning a GPT-like LLM and is the official code repository for the book [Build a Large Language Model (From Scratch)](http://mng.bz/orYv).
<br>
<br>
<a href="http://mng.bz/orYv"><img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/cover.jpg?123" width="250px"></a>
<br>
In [*Build a Large Language Model (From Scratch)*](http://mng.bz/orYv), you'll learn and understand how large language models (LLMs) work from the inside out by coding them from the ground up, step by step. In this book, I'll guide you through creating your own LLM, explaining each stage with clear text, diagrams, and examples.
The method described in this book for training and developing your own small-but-functional model for educational purposes mirrors the approach used in creating large-scale foundational models such as those behind ChatGPT. In addition, this book includes code for loading the weights of larger pretrained models for finetuning.
- Link to the official [source code repository](https://github.com/rasbt/LLMs-from-scratch)
- [Link to the book at Manning](http://mng.bz/orYv)
- [Link to the book page on Amazon](https://www.amazon.com/gp/product/1633437167)
- ISBN 9781633437166
<a href="http://mng.bz/orYv#reviews"><img src="https://sebastianraschka.com//images/LLMs-from-scratch-images/other/reviews.png" width="220px"></a>
<br>
<br>
To download a copy of this repository, click on the [Download ZIP](https://github.com/rasbt/LLMs-from-scratch/archive/refs/heads/main.zip) button or execute the following command in your terminal:
```bash
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git
```
<br>
(If you downloaded the code bundle from the Manning website, please consider visiting the official code repository on GitHub at [https://github.com/rasbt/LLMs-from-scratch](https://github.com/rasbt/LLMs-from-scratch) for the latest updates.)
<br>
<br>
# Table of Contents
Please note that this `README.md` file is a Markdown (`.md`) file. If you have downloaded this code bundle from the Manning website and are viewing it on your local computer, I recommend using a Markdown editor or previewer for proper viewing. If you haven't installed a Markdown editor yet, [MarkText](https://www.marktext.cc) is a good free option.
You can alternatively view this and other files on GitHub at [https://github.com/rasbt/LLMs-from-scratch](https://github.com/rasbt/LLMs-from-scratch) in your browser, which renders Markdown automatically.
<br>
<br>
<!-- -->
> [!TIP]
> If you're seeking guidance on installing Python and Python packages and setting up your code environment, I suggest reading the [README.md](setup/README.md) file located in the [setup](setup) directory.
<br>
<br>
[![Code tests (Linux)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-linux.yml/badge.svg)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-linux.yml)
[![Code tests (Windows)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-windows.yml/badge.svg)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-windows.yml)
[![Code tests (macOS)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-macos.yml/badge.svg)](https://github.com/rasbt/LLMs-from-scratch/actions/workflows/basic-tests-macos.yml)
<br>
| Chapter Title | Main Code (for Quick Access) | All Code + Supplementary |
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| [Setup recommendations](setup) | - | - |
| Ch 1: Understanding Large Language Models | No code | - |
| Ch 2: Working with Text Data | - [ch02.ipynb](ch02/01_main-chapter-code/ch02.ipynb)<br/>- [dataloader.ipynb](ch02/01_main-chapter-code/dataloader.ipynb) (summary)<br/>- [exercise-solutions.ipynb](ch02/01_main-chapter-code/exercise-solutions.ipynb) | [./ch02](./ch02) |
| Ch 3: Coding Attention Mechanisms | - [ch03.ipynb](ch03/01_main-chapter-code/ch03.ipynb)<br/>- [multihead-attention.ipynb](ch03/01_main-chapter-code/multihead-attention.ipynb) (summary) <br/>- [exercise-solutions.ipynb](ch03/01_main-chapter-code/exercise-solutions.ipynb)| [./ch03](./ch03) |
| Ch 4: Implementing a GPT Model from Scratch | - [ch04.ipynb](ch04/01_main-chapter-code/ch04.ipynb)<br/>- [gpt.py](ch04/01_main-chapter-code/gpt.py) (summary)<br/>- [exercise-solutions.ipynb](ch04/01_main-chapter-code/exercise-solutions.ipynb) | [./ch04](./ch04) |
| Ch 5: Pretraining on Unlabeled Data | - [ch05.ipynb](ch05/01_main-chapter-code/ch05.ipynb)<br/>- [gpt_train.py](ch05/01_main-chapter-code/gpt_train.py) (summary) <br/>- [gpt_generate.py](ch05/01_main-chapter-code/gpt_generate.py) (summary) <br/>- [exercise-solutions.ipynb](ch05/01_main-chapter-code/exercise-solutions.ipynb) | [./ch05](./ch05) |
| Ch 6: Finetuning for Text Classification | - [ch06.ipynb](ch06/01_main-chapter-code/ch06.ipynb) <br/>- [gpt_class_finetune.py](ch06/01_main-chapter-code/gpt_class_finetune.py) <br/>- [exercise-solutions.ipynb](ch06/01_main-chapter-code/exercise-solutions.ipynb) | [./ch06](./ch06) |
| Ch 7: Finetuning to Follow Instructions | - [ch07.ipynb](ch07/01_main-chapter-code/ch07.ipynb)<br/>- [gpt_instruction_finetuning.py](ch07/01_main-chapter-code/gpt_instruction_finetuning.py) (summary)<br/>- [ollama_evaluate.py](ch07/01_main-chapter-code/ollama_evaluate.py) (summary)<br/>- [exercise-solutions.ipynb](ch07/01_main-chapter-code/exercise-solutions.ipynb) | [./ch07](./ch07) |
| Appendix A: Introduction to PyTorch | - [code-part1.ipynb](appendix-A/01_main-chapter-code/code-part1.ipynb)<br/>- [code-part2.ipynb](appendix-A/01_main-chapter-code/code-part2.ipynb)<br/>- [DDP-script.py](appendix-A/01_main-chapter-code/DDP-script.py)<br/>- [exercise-solutions.ipynb](appendix-A/01_main-chapter-code/exercise-solutions.ipynb) | [./appendix-A](./appendix-A) |
| Appendix B: References and Further Reading | No code | - |
| Appendix C: Exercise Solutions | No code | - |
| Appendix D: Adding Bells and Whistles to the Training Loop | - [appendix-D.ipynb](appendix-D/01_main-chapter-code/appendix-D.ipynb) | [./appendix-D](./appendix-D) |
| Appendix E: Parameter-efficient Finetuning with LoRA | - [appendix-E.ipynb](appendix-E/01_main-chapter-code/appendix-E.ipynb) | [./appendix-E](./appendix-E) |
<br>
The mental model below summarizes the contents covered in this book.
<img src="https://sebastianraschka.com/images/LLMs-from-scratch-images/mental-model.jpg" width="650px">
<br>
## Hardware Requirements
The code in the main chapters of this book is d
没有合适的资源?快使用搜索试试~ 我知道了~
Machine Learning From Scratch
共187个文件
py:55个
md:44个
ipynb:42个
需积分: 5 0 下载量 95 浏览量
2024-10-21
21:51:19
上传
评论
收藏 1.75MB ZIP 举报
温馨提示
About Python implementations of some of the fundamental Machine Learning models and algorithms from scratch. The purpose of this project is not to produce as optimized and computationally efficient algorithms as possible but rather to present the inner workings of them in a transparent and accessible way.
资源推荐
资源详情
资源评论
收起资源包目录
Machine Learning From Scratch (187个子文件)
vocab.bpe 446KB
Dockerfile 327B
.gitignore 7KB
mha-implementations.ipynb 340KB
converting-llama2-to-llama3.ipynb 213KB
dpo-from-scratch.ipynb 181KB
ch06.ipynb 141KB
ch05.ipynb 138KB
appendix-D.ipynb 135KB
ch07.ipynb 127KB
ch04.ipynb 87KB
converting-gpt-to-llama2.ipynb 86KB
appendix-E.ipynb 81KB
ch03.ipynb 68KB
ch02.ipynb 55KB
reflection-gpt4.ipynb 42KB
standalone-llama32.ipynb 41KB
exercise-solutions.ipynb 37KB
correlation-analysis.ipynb 34KB
exercise-solutions.ipynb 32KB
code-part1.ipynb 31KB
understanding-buffers.ipynb 30KB
llama3-ollama.ipynb 29KB
memory-efficient-state-dict.ipynb 26KB
llm-instruction-eval-ollama.ipynb 23KB
create-preference-data-ollama.ipynb 21KB
llm-instruction-eval-openai.ipynb 20KB
flops-analysis.ipynb 19KB
embeddings-and-linear-layers.ipynb 13KB
multihead-attention.ipynb 13KB
exercise-solutions.ipynb 12KB
code-part2.ipynb 12KB
create-passive-voice-entries.ipynb 12KB
compare-bpe-tiktoken.ipynb 11KB
weight-loading-hf-transformers.ipynb 10KB
exercise-solutions.ipynb 10KB
dataloader-intuition.ipynb 10KB
exercise-solutions.ipynb 9KB
load-finetuned-model.ipynb 8KB
sklearn-baseline.ipynb 8KB
load-finetuned-model.ipynb 6KB
dataloader.ipynb 6KB
exercise-solutions.ipynb 5KB
exercise-solutions.ipynb 5KB
python_environment_check.ipynb 2KB
encoder.json 1018KB
instruction-data-with-preference.json 378KB
instruction-data.json 199KB
instruction-examples-modified.json 54KB
instruction-examples.json 38KB
eval-example-data.json 36KB
instruction-data-with-response.json 29KB
instruction-data-llama3-7b.json 10KB
gpt4-model-1-response.json 445B
devcontainer.json 433B
gpt4-model-2-response.json 408B
llama3-8b-model-1-response.json 402B
llama3-8b-model-2-response.json 393B
extensions.json 292B
config.json 123B
config.json 115B
config.json 115B
config.json 111B
README.md 12KB
README.md 11KB
README.md 10KB
README.md 6KB
README.md 6KB
README.md 4KB
README.md 4KB
README.md 3KB
README.md 3KB
README.md 2KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1022B
README.md 952B
README.md 938B
README.md 878B
README.md 728B
README.md 717B
README.md 690B
README.md 645B
README.md 579B
README.md 545B
README.md 510B
README.md 506B
README.md 488B
README.md 437B
README.md 409B
README.md 392B
README.md 366B
README.md 345B
README.md 307B
README.md 291B
ask-a-question.md 290B
README.md 283B
共 187 条
- 1
- 2
资源评论
jackl的科研日常
- 粉丝: 541
- 资源: 346
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于深度学习的所有权分心驾驶(行为疲劳+行为危险)预警系统采用YOLOv5+Deepsort实现所有权的危险驾驶行为的预警监测.zip
- 411jsp心理健康测试咨询网站毕业课程源码设计+论文资料
- 基于yolo的csgo AI.zip
- 基于javaWeb实现学生选课管理系统源码+数据库文件+文档说明
- 安卓逆向分析工具集合:包含baksmali-2.5.2.jar、classes-dex2jar.jar、jadx-gui-1.2.0-no-jre-win.exe
- 基于JavaWeb的大学生选课管理系统源码+数据库(毕业设计项目)
- 基于yolov7的姿势检测.zip
- java毕业设计-基于SSM的公租房维保系统【代码+论文+PPT】
- 基于yolov5识别算法实现的DNF自动脚本.zip
- 410asp电子政务网站设计毕业课程源码设计+论文资料+开题报告+答辩ppt资料全
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功