กลับไปหน้า Tools

GetNotes Tools

rasbt/LLMs-from-scratch

Tool นี้คืออะไร

repository นี้มีโค้ดสำหรับพัฒนา, pretrain และ finetune LLM แบบ GPT-like ซึ่งเป็นโค้ดอย่างเป็นทางการสำหรับหนังสือ "Build a Large Language Model (From Scratch)" เหมาะสำหรับนักพัฒนาและผู้ที่ต้องการเรียนรู้การทำงานของ LLM จากภายในสู่ภายนอก โดยมีประโยชน์ในการสร้างโมเดล LLM ขนาดเล็กที่ใช้งานได้จริงและเข้าใจแนวคิดเบื้องหลังโมเดลขนาดใหญ่.

ข้อมูลโปรเจกต์

ดาว

100.1K

Forks

15.4K

License

ไม่ระบุ

อัปเดต GitHub ล่าสุด

27 ก.ค. 2569

เพิ่มใน GetNotes

14 ก.ค. 2569

Repository

rasbt/LLMs-from-scratch

เหมาะกับงาน

AI และ Agents

Ecosystem

Jupyter Notebook

แปลและเรียบเรียงโดย AI

เนื้อหาฉบับภาษาไทย

ใช้อ่านเพื่อทำความเข้าใจเบื้องต้น โปรดตรวจสอบรายละเอียดสำคัญกับเอกสารต้นฉบับด้านล่าง

สร้าง Large Language Model (ตั้งแต่เริ่มต้น)

repository นี้มีโค้ดสำหรับพัฒนา, pretrain และ finetune LLM แบบ GPT-like และเป็น repository โค้ดอย่างเป็นทางการสำหรับหนังสือ Build a Large Language Model (From Scratch).

ในหนังสือ Build a Large Language Model (From Scratch) คุณจะได้เรียนรู้และทำความเข้าใจว่า Large Language Model (LLM) ทำงานอย่างไรจากภายในสู่ภายนอก โดยการเขียนโค้ดตั้งแต่เริ่มต้นทีละขั้นตอน ในหนังสือเล่มนี้ ผมจะแนะนำคุณตลอดการสร้าง LLM ของคุณเอง โดยอธิบายแต่ละขั้นตอนด้วยข้อความ แผนภาพ และตัวอย่างที่ชัดเจน

วิธีการที่อธิบายไว้ในหนังสือเล่มนี้สำหรับการฝึกและพัฒนาโมเดลขนาดเล็กแต่ใช้งานได้จริงเพื่อวัตถุประสงค์ทางการศึกษา สะท้อนแนวทางที่ใช้ในการสร้างโมเดลพื้นฐานขนาดใหญ่ เช่น โมเดลที่อยู่เบื้องหลัง ChatGPT นอกจากนี้ หนังสือเล่มนี้ยังรวมโค้ดสำหรับการโหลดน้ำหนักของโมเดลที่ pretrained ขนาดใหญ่ขึ้นเพื่อการ finetuning.

หากต้องการดาวน์โหลดสำเนาของ repository นี้ ให้คลิกที่ปุ่ม Download ZIP หรือรันคำสั่งต่อไปนี้ใน terminal ของคุณ:

bash
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git

(หากคุณดาวน์โหลดชุดโค้ดจากเว็บไซต์ Manning โปรดพิจารณาเยี่ยมชม repository โค้ดอย่างเป็นทางการบน GitHub ที่ https://github.com/rasbt/LLMs-from-scratch เพื่อรับการอัปเดตล่าสุด)

สารบัญ

โปรดทราบว่าไฟล์ README.md นี้เป็นไฟล์ Markdown (.md) หากคุณดาวน์โหลดชุดโค้ดนี้จากเว็บไซต์ Manning และกำลังดูอยู่บนคอมพิวเตอร์ของคุณ ผมแนะนำให้ใช้โปรแกรมแก้ไขหรือโปรแกรมดู Markdown เพื่อการแสดงผลที่เหมาะสม หากคุณยังไม่ได้ติดตั้งโปรแกรมแก้ไข Markdown, Ghostwriter เป็นตัวเลือกฟรีที่ดี

คุณสามารถดูไฟล์นี้และไฟล์อื่นๆ บน GitHub ที่ https://github.com/rasbt/LLMs-from-scratch ในเบราว์เซอร์ของคุณ ซึ่งจะแสดงผล Markdown โดยอัตโนมัติ

เคล็ดลับ: หากคุณกำลังมองหาคำแนะนำในการติดตั้ง Python และแพ็กเกจ Python รวมถึงการตั้งค่าสภาพแวดล้อมโค้ดของคุณ ผมแนะนำให้อ่านไฟล์ README.md ที่อยู่ในไดเรกทอรี setup.

Code tests Linux Code tests Windows Code tests macOS

ชื่อบทโค้ดหลัก (สำหรับเข้าถึงด่วน)โค้ดทั้งหมด + ส่วนเสริม
คำแนะนำในการตั้งค่า วิธีอ่านหนังสือเล่มนี้ให้ดีที่สุด--
บทที่ 1: ทำความเข้าใจ Large Language Modelsไม่มีโค้ด-
บทที่ 2: การทำงานกับข้อมูลข้อความ- ch02.ipynb- dataloader.ipynb (สรุป)- exercise-solutions.ipynb./ch02
บทที่ 3: การเขียนโค้ดกลไก Attention- ch03.ipynb- multihead-attention.ipynb (สรุป) - exercise-solutions.ipynb./ch03
บทที่ 4: การนำ GPT Model ไปใช้ตั้งแต่เริ่มต้น- ch04.ipynb- gpt.py (สรุป)- exercise-solutions.ipynb./ch04
บทที่ 5: การ Pretraining บนข้อมูลที่ไม่มีป้ายกำกับ- ch05.ipynb- gpt_train.py (สรุป) - gpt_generate.py (สรุป) - exercise-solutions.ipynb./ch05
บทที่ 6: การ Finetuning สำหรับการจัดหมวดหมู่ข้อความ- ch06.ipynb - gpt_class_finetune.py - exercise-solutions.ipynb./ch06
บทที่ 7: การ Finetuning เพื่อทำตามคำสั่ง- ch07.ipynb- gpt_instruction_finetuning.py (สรุป)- ollama_evaluate.py (สรุป)- exercise-solutions.ipynb./ch07
ภาคผนวก A: บทนำสู่ PyTorch- code-part1.ipynb- code-part2.ipynb- DDP-script.py- exercise-solutions.ipynb./appendix-A
ภาคผนวก B: เอกสารอ้างอิงและการอ่านเพิ่มเติมไม่มีโค้ด./appendix-B
ภาคผนวก C: เฉลยแบบฝึกหัด- รายการเฉลยแบบฝึกหัด./appendix-C
ภาคผนวก D: การเพิ่มคุณสมบัติเสริมให้กับ Training Loop- appendix-D.ipynb./appendix-D
ภาคผนวก E: การ Finetuning ที่มีประสิทธิภาพด้านพารามิเตอร์ด้วย LoRA- appendix-E.ipynb./appendix-E

โมเดลแนวคิดด้านล่างนี้สรุปเนื้อหาที่ครอบคลุมในหนังสือเล่มนี้

ข้อกำหนดเบื้องต้น

ข้อกำหนดเบื้องต้นที่สำคัญที่สุดคือพื้นฐานที่แข็งแกร่งในการเขียนโปรแกรม Python ด้วยความรู้นี้ คุณจะพร้อมเป็นอย่างดีที่จะสำรวจโลกที่น่าสนใจของ LLM และทำความเข้าใจแนวคิดและตัวอย่างโค้ดที่นำเสนอในหนังสือเล่มนี้

หากคุณมีประสบการณ์กับโครงข่ายประสาทเทียมเชิงลึก (deep neural networks) คุณอาจพบว่าแนวคิดบางอย่างคุ้นเคยมากขึ้น เนื่องจาก LLM สร้างขึ้นบนสถาปัตยกรรมเหล่านี้

หนังสือเล่มนี้ใช้ PyTorch เพื่อเขียนโค้ดตั้งแต่เริ่มต้นโดยไม่ใช้ไลบรารี LLM ภายนอกใดๆ แม้ว่าความเชี่ยวชาญใน PyTorch จะไม่ใช่ข้อกำหนดเบื้องต้น แต่ความคุ้นเคยกับพื้นฐานของ PyTorch ก็มีประโยชน์อย่างแน่นอน หากคุณยังใหม่กับ PyTorch ภาคผนวก A มีบทนำ PyTorch ที่กระชับ หรืออีกทางหนึ่ง คุณอาจพบว่าหนังสือของฉัน PyTorch in One Hour: From Tensors to Training Neural Networks on Multiple GPUs มีประโยชน์สำหรับการเรียนรู้สิ่งจำเป็น

ข้อกำหนดด้านฮาร์ดแวร์

โค้ดในบทหลักของหนังสือเล่มนี้ออกแบบมาให้ทำงานบนแล็ปท็อปทั่วไปได้ภายในระยะเวลาที่เหมาะสม และไม่จำเป็นต้องใช้ฮาร์ดแวร์พิเศษ วิธีการนี้ช่วยให้ผู้อ่านจำนวนมากสามารถเข้าถึงเนื้อหาได้ นอกจากนี้ โค้ดยังใช้ GPU โดยอัตโนมัติหากมี (โปรดดูเอกสาร setup สำหรับคำแนะนำเพิ่มเติม)

คอร์สวิดีโอ

คอร์สวิดีโอประกอบความยาว 17 ชั่วโมง 15 นาที ที่ผมเขียนโค้ดไปพร้อมกับแต่ละบทของหนังสือ คอร์สนี้จัดระเบียบเป็นบทและส่วนต่างๆ ที่สะท้อนโครงสร้างของหนังสือ เพื่อให้สามารถใช้เป็นทางเลือกแทนหนังสือแบบเดี่ยวๆ หรือเป็นแหล่งข้อมูลเสริมสำหรับการเขียนโค้ดตาม

หนังสือคู่มือ / ภาคต่อ

Build A Reasoning Model (From Scratch) แม้จะเป็นหนังสือแบบเดี่ยวๆ แต่ก็สามารถถือเป็นภาคต่อของ Build A Large Language Model (From Scratch) ได้

หนังสือเล่มนี้เริ่มต้นด้วยโมเดลที่ได้รับการฝึกฝนล่วงหน้า (pretrained model) และนำวิธีการให้เหตุผลที่แตกต่างกันมาใช้ รวมถึงการปรับขนาดเวลาอนุมาน (inference-time scaling), การเรียนรู้แบบเสริมกำลัง (reinforcement learning) และ

เนื้อหาโบนัสเพิ่มเติมจาก Reasoning From Scratch repository:

  • **พื้นฐาน Qwen3 (จากศูนย์)**- [Qwen3 Source Code Walkthrough](https://github.com/rasbt/reasoning-from-scratch/blob/main/chC/01_main-chapter-code/chC_main.ipynb) - [Optimized Qwen3](https://github.com/rasbt/reasoning-from-scratch/tree/main/ch02/03_optimized-LLM)
  • **การประเมินผล**- [Verifier-Based Evaluation (MATH-500)](https://github.com/rasbt/reasoning-from-scratch/tree/main/ch03) - [Multiple-Choice Evaluation (MMLU)](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/02_mmlu) - [LLM Leaderboard Evaluation](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/03_leaderboards) - [LLM-as-a-Judge Evaluation](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/04_llm-judge)
  • **การปรับขนาด Inference**- [Self-Consistency](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch04/01_main-chapter-code/ch04_main.ipynb) - [Self-Refinement](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch05/01_main-chapter-code/ch05_main.ipynb)
  • **Reinforcement Learning** (RL)- [RLVR with GRPO From Scratch](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch06/01_main-chapter-code/ch06_main.ipynb)

คำถาม, ข้อเสนอแนะ และการมีส่วนร่วมใน Repository นี้

ผมยินดีรับฟังข้อเสนอแนะทุกประเภท ซึ่งสามารถแบ่งปันได้ดีที่สุดผ่าน Manning Forum หรือ GitHub Discussions เช่นกัน หากคุณมีคำถามใด ๆ หรือต้องการแลกเปลี่ยนความคิดเห็นกับผู้อื่น โปรดอย่าลังเลที่จะโพสต์สิ่งเหล่านี้ในฟอรัมด้วย

โปรดทราบว่าเนื่องจาก repository นี้มีโค้ดที่สอดคล้องกับหนังสือฉบับพิมพ์ ผมจึงไม่สามารถรับการมีส่วนร่วมที่จะขยายเนื้อหาของโค้ดบทหลักได้ในขณะนี้ เนื่องจากจะทำให้เกิดความคลาดเคลื่อนจากหนังสือจริง การรักษาความสอดคล้องกันช่วยให้มั่นใจได้ถึงประสบการณ์ที่ราบรื่นสำหรับทุกคน

การอ้างอิง

หากคุณพบว่าหนังสือหรือโค้ดนี้มีประโยชน์สำหรับการวิจัยของคุณ โปรดพิจารณาอ้างอิงถึง

การอ้างอิงสไตล์ Chicago:

Raschka, Sebastian. Build A Large Language Model (From Scratch). Manning, 2024. ISBN: 978-1633437166.

รายการ BibTeX:

code
@book{build-llms-from-scratch-book,
  author       = {Sebastian Raschka},
  title        = {Build A Large Language Model (From Scratch)},
  publisher    = {Manning},
  year         = {2024},
  isbn         = {978-1633437166},
  url          = {https://www.manning.com/books/build-a-large-language-model-from-scratch},
  github       = {https://github.com/rasbt/LLMs-from-scratch}
}

เอกสารโปรเจกต์

อ่านเอกสารต้นฉบับ

README วิธีติดตั้ง วิธีใช้งาน และข้อกำหนดจาก repository ต้นฉบับ

ดูไฟล์บน GitHub

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).

In Build a Large Language Model (From Scratch), 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.

To download a copy of this repository, click on the Download ZIP button or execute the following command in your terminal:

bash
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git

(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 for the latest updates.)

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, Ghostwriter is a good free option.

You can alternatively view this and other files on GitHub at https://github.com/rasbt/LLMs-from-scratch in your browser, which renders Markdown automatically.

Tip: If you're seeking guidance on installing Python and Python packages and setting up your code environment, I suggest reading the README.md file located in the setup directory.

Code tests Linux Code tests Windows Code tests macOS

Chapter TitleMain Code (for Quick Access)All Code + Supplementary
Setup recommendations How to best read this book--
Ch 1: Understanding Large Language ModelsNo code-
Ch 2: Working with Text Data- ch02.ipynb- dataloader.ipynb (summary)- exercise-solutions.ipynb./ch02
Ch 3: Coding Attention Mechanisms- ch03.ipynb- multihead-attention.ipynb (summary) - exercise-solutions.ipynb./ch03
Ch 4: Implementing a GPT Model from Scratch- ch04.ipynb- gpt.py (summary)- exercise-solutions.ipynb./ch04
Ch 5: Pretraining on Unlabeled Data- ch05.ipynb- gpt_train.py (summary) - gpt_generate.py (summary) - exercise-solutions.ipynb./ch05
Ch 6: Finetuning for Text Classification- ch06.ipynb - gpt_class_finetune.py - exercise-solutions.ipynb./ch06
Ch 7: Finetuning to Follow Instructions- ch07.ipynb- gpt_instruction_finetuning.py (summary)- ollama_evaluate.py (summary)- exercise-solutions.ipynb./ch07
Appendix A: Introduction to PyTorch- code-part1.ipynb- code-part2.ipynb- DDP-script.py- exercise-solutions.ipynb./appendix-A
Appendix B: References and Further ReadingNo code./appendix-B
Appendix C: Exercise Solutions- list of exercise solutions./appendix-C
Appendix D: Adding Bells and Whistles to the Training Loop- appendix-D.ipynb./appendix-D
Appendix E: Parameter-efficient Finetuning with LoRA- appendix-E.ipynb./appendix-E

The mental model below summarizes the contents covered in this book.

Prerequisites

The most important prerequisite is a strong foundation in Python programming. With this knowledge, you will be well prepared to explore the fascinating world of LLMs and understand the concepts and code examples presented in this book.

If you have some experience with deep neural networks, you may find certain concepts more familiar, as LLMs are built upon these architectures.

This book uses PyTorch to implement the code from scratch without using any external LLM libraries. While proficiency in PyTorch is not a prerequisite, familiarity with PyTorch basics is certainly useful. If you are new to PyTorch, Appendix A provides a concise introduction to PyTorch. Alternatively, you may find my book, PyTorch in One Hour: From Tensors to Training Neural Networks on Multiple GPUs, helpful for learning about the essentials.

Hardware Requirements

The code in the main chapters of this book is designed to run on conventional laptops within a reasonable timeframe and does not require specialized hardware. This approach ensures that a wide audience can engage with the material. Additionally, the code automatically utilizes GPUs if they are available. (Please see the setup doc for additional recommendations.)

 

Video Course

A 17-hour and 15-minute companion video course where I code through each chapter of the book. The course is organized into chapters and sections that mirror the book's structure so that it can be used as a standalone alternative to the book or complementary code-along resource.

 

Companion Book / Sequel

Build A Reasoning Model (From Scratch), while a standalone book, can be considered as a sequel to Build A Large Language Model (From Scratch).

It starts with a pretrained model and implements different reasoning approaches, including inference-time scaling, reinforcement learning, and distillation, to improve the model's reasoning capabilities.

Similar to Build A Large Language Model (From Scratch), Build A Reasoning Model (From Scratch) takes a hands-on approach implementing these methods from scratch.

 

Exercises

Each chapter of the book includes several exercises. The solutions are summarized in Appendix C, and the corresponding code notebooks are available in the main chapter folders of this repository (for example, ./ch02/01_main-chapter-code/exercise-solutions.ipynb.

In addition to the code exercises, you can download a free 170-page PDF titled Test Yourself On Build a Large Language Model (From Scratch) from the Manning website. It contains approximately 30 quiz questions and solutions per chapter to help you test your understanding.

 

Bonus Material

Several folders contain optional materials as a bonus for interested readers:

  • **Setup**- [Python Setup Tips](https://github.com/rasbt/LLMs-from-scratch/blob/main/setup/01_optional-python-setup-preferences) - [Installing Python Packages and Libraries Used in This Book](https://github.com/rasbt/LLMs-from-scratch/blob/main/setup/02_installing-python-libraries) - [Docker Environment Setup Guide](https://github.com/rasbt/LLMs-from-scratch/blob/main/setup/03_optional-docker-environment)
  • **Chapter 2: Working With Text Data**- [Byte Pair Encoding (BPE) Tokenizer From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/05_bpe-from-scratch/bpe-from-scratch-simple.ipynb) - [Comparing Various Byte Pair Encoding (BPE) Implementations](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/02_bonus_bytepair-encoder) - [Understanding the Difference Between Embedding Layers and Linear Layers](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/03_bonus_embedding-vs-matmul) - [Dataloader Intuition With Simple Numbers](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/04_bonus_dataloader-intuition)
  • **Chapter 3: Coding Attention Mechanisms**- [Comparing Efficient Multi-Head Attention Implementations](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch03/02_bonus_efficient-multihead-attention/mha-implementations.ipynb) - [Understanding PyTorch Buffers](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch03/03_understanding-buffers/understanding-buffers.ipynb)
  • **Chapter 4: Implementing a GPT Model From Scratch**- [FLOPs Analysis](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/02_performance-analysis/flops-analysis.ipynb) - [KV Cache](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/03_kv-cache) - [Attention Alternatives](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/#attention-alternatives) - [Grouped-Query Attention](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/04_gqa) - [Multi-Head Latent Attention](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/05_mla) - [Sliding Window Attention](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/06_swa) - [Gated DeltaNet](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/08_deltanet) - [DeepSeek Sparse Attention (DSA)](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/09_dsa) - [Cross-Layer KV Sharing](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/10_kv-sharing) - [Mixture-of-Experts (MoE)](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch04/07_moe)
  • **Chapter 5: Pretraining on Unlabeled Data**- [Alternative Weight Loading Methods](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/02_alternative_weight_loading/) - [Pretraining GPT on the Project Gutenberg Dataset](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/03_bonus_pretraining_on_gutenberg) - [Adding Bells and Whistles to the Training Loop](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/04_learning_rate_schedulers) - [Optimizing Hyperparameters for Pretraining](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/05_bonus_hparam_tuning) - [Building a User Interface to Interact With the Pretrained LLM](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/06_user_interface) - [Converting GPT to Llama](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/07_gpt_to_llama) - [Memory-efficient Model Weight Loading](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/08_memory_efficient_weight_loading/memory-efficient-state-dict.ipynb) - [Extending the Tiktoken BPE Tokenizer with New Tokens](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/09_extending-tokenizers/extend-tiktoken.ipynb) - [PyTorch Performance Tips for Faster LLM Training](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/10_llm-training-speed) - [LLM Architectures](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/#llm-architectures-from-scratch) - [Llama 3.2 From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/07_gpt_to_llama/standalone-llama32.ipynb) - [Qwen3 Dense and Mixture-of-Experts (MoE) From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/11_qwen3/) - [Gemma 3 From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/12_gemma3/) - [Olmo 3 From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/13_olmo3/) - [Tiny Aya From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/15_tiny-aya/) - [Qwen3.5 From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/16_qwen3.5/) - [Gemma 4 E2B and E4B From Scratch](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/17_gemma4/) - [Chapter 5 with other LLMs as Drop-In Replacement (e.g., Llama 3, Qwen 3)](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch05/14_ch05_with_other_llms/)
  • **Chapter 6: Finetuning for classification**- [Additional Experiments Finetuning Different Layers and Using Larger Models](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch06/02_bonus_additional-experiments) - [Finetuning Different Models on the 50k IMDb Movie Review Dataset](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch06/03_bonus_imdb-classification) - [Building a User Interface to Interact With the GPT-based Spam Classifier](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch06/04_user_interface)
  • **Chapter 7: Finetuning to follow instructions**- [Dataset Utilities for Finding Near Duplicates and Creating Passive Voice Entries](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/02_dataset-utilities) - [Evaluating Instruction Responses Using the OpenAI API and Ollama](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/03_model-evaluation) - [Generating a Dataset for Instruction Finetuning](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/05_dataset-generation/llama3-ollama.ipynb) - [Improving a Dataset for Instruction Finetuning](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/05_dataset-generation/reflection-gpt4.ipynb) - [Generating a Preference Dataset With Llama 3.1 70B and Ollama](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/04_preference-tuning-with-dpo/create-preference-data-ollama.ipynb) - [Direct Preference Optimization (DPO) for LLM Alignment](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/04_preference-tuning-with-dpo/dpo-from-scratch.ipynb) - [Building a User Interface to Interact With the Instruction-Finetuned GPT Model](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch07/06_user_interface)

More bonus material from the Reasoning From Scratch repository:

  • **Qwen3 (From Scratch) Basics**- [Qwen3 Source Code Walkthrough](https://github.com/rasbt/reasoning-from-scratch/blob/main/chC/01_main-chapter-code/chC_main.ipynb) - [Optimized Qwen3](https://github.com/rasbt/reasoning-from-scratch/tree/main/ch02/03_optimized-LLM)
  • **Evaluation**- [Verifier-Based Evaluation (MATH-500)](https://github.com/rasbt/reasoning-from-scratch/tree/main/ch03) - [Multiple-Choice Evaluation (MMLU)](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/02_mmlu) - [LLM Leaderboard Evaluation](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/03_leaderboards) - [LLM-as-a-Judge Evaluation](https://github.com/rasbt/reasoning-from-scratch/blob/main/chF/04_llm-judge)
  • **Inference Scaling**- [Self-Consistency](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch04/01_main-chapter-code/ch04_main.ipynb) - [Self-Refinement](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch05/01_main-chapter-code/ch05_main.ipynb)
  • **Reinforcement Learning** (RL)- [RLVR with GRPO From Scratch](https://github.com/rasbt/reasoning-from-scratch/blob/main/ch06/01_main-chapter-code/ch06_main.ipynb)

Questions, Feedback, and Contributing to This Repository

I welcome all sorts of feedback, best shared via the Manning Forum or GitHub Discussions. Likewise, if you have any questions or just want to bounce ideas off others, please don't hesitate to post these in the forum as well.

Please note that since this repository contains the code corresponding to a print book, I currently cannot accept contributions that would extend the contents of the main chapter code, as it would introduce deviations from the physical book. Keeping it consistent helps ensure a smooth experience for everyone.

 

Citation

If you find this book or code useful for your research, please consider citing it.

Chicago-style citation:

Raschka, Sebastian. Build A Large Language Model (From Scratch). Manning, 2024. ISBN: 978-1633437166.

BibTeX entry:

code
@book{build-llms-from-scratch-book,
  author       = {Sebastian Raschka},
  title        = {Build A Large Language Model (From Scratch)},
  publisher    = {Manning},
  year         = {2024},
  isbn         = {978-1633437166},
  url          = {https://www.manning.com/books/build-a-large-language-model-from-scratch},
  github       = {https://github.com/rasbt/LLMs-from-scratch}
}
#ai#artificial-intelligence#attention-mechanism#deep-learning#finetuning#from-scratch#generative-ai#gpt#instruction-tuning#language-model#large-language-models#llm