Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.1%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: ua-datalab
  • License: other
  • Language: Jupyter Notebook
  • Default Branch: main
  • Size: 13.2 MB
Statistics
  • Stars: 1
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

{A cloned repository from Sebastian Raschka with the same name (12/08/2024).}

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.

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 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 Title | Main Code (for Quick Access) | All Code + Supplementary | |------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------| | Setup recommendations | - | - | | Ch 1: Understanding Large Language Models | No 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
- gptclassfinetune.py
- exercise-solutions.ipynb | ./ch06 | | Ch 7: Finetuning to Follow Instructions | - ch07.ipynb
- gptinstructionfinetuning.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 Reading | No code | - | | Appendix C: Exercise Solutions | No code | - | | 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.


 

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

 

Bonus Material

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


 

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:

@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} }

Owner

  • Name: University of Arizona Data Lab
  • Login: ua-datalab
  • Kind: organization
  • Location: United States of America

The University of Arizona Data Science Lab @ Data Science Institute

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this book or its accompanying code, please cite it as follows."
title: "Build A Large Language Model (From Scratch), Published by Manning, ISBN 978-1633437166"
abstract: "This book provides a comprehensive, step-by-step guide to implementing a ChatGPT-like large language model from scratch in PyTorch."
date-released: 2024-09-12
authors:
  - family-names: "Raschka"
    given-names: "Sebastian"
license: "Apache-2.0"
url: "https://www.manning.com/books/build-a-large-language-model-from-scratch"
repository-code: "https://github.com/rasbt/LLMs-from-scratch"
keywords:
  - large language models
  - natural language processing
  - artificial intelligence
  - PyTorch
  - machine learning
  - deep learning

GitHub Events

Total
  • Watch event: 1
  • Member event: 3
  • Public event: 1
  • Push event: 2
  • Gollum event: 16
  • Create event: 1
Last Year
  • Watch event: 1
  • Member event: 3
  • Public event: 1
  • Push event: 2
  • Gollum event: 16
  • Create event: 1

Dependencies

.github/workflows/basic-tests-linux.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/basic-tests-macos.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/basic-tests-old-pytorch.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/basic-tests-windows.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/check-links.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/check-spelling-errors.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/pep8-linter.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
setup/03_optional-docker-environment/.devcontainer/Dockerfile docker
  • pytorch/pytorch 2.5.0-cuda12.4-cudnn9-runtime build
ch02/02_bonus_bytepair-encoder/requirements-extra.txt pypi
  • requests *
  • tqdm *
  • transformers >=4.33.2
ch04/02_performance-analysis/requirements-extra.txt pypi
  • thop *
ch05/06_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
ch05/07_gpt_to_llama/requirements-extra.txt pypi
  • blobfile >=3.0.0
  • huggingface_hub >=0.24.7
  • ipywidgets >=8.1.2
  • safetensors >=0.4.4
  • sentencepiece >=0.1.99
ch05/07_gpt_to_llama/tests/test-requirements-extra.txt pypi
  • pytest >=8.1.1 test
  • transformers >=4.44.2 test
ch06/03_bonus_imdb-classification/requirements-extra.txt pypi
  • scikit-learn >=1.3.0
  • transformers >=4.33.2
ch06/04_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
ch07/02_dataset-utilities/requirements-extra.txt pypi
  • openai >=1.30.3
  • scikit-learn >=1.3.1
  • tqdm >=4.65.0
ch07/03_model-evaluation/requirements-extra.txt pypi
  • openai >=1.30.3
  • tqdm >=4.65.0
ch07/05_dataset-generation/requirements-extra.txt pypi
  • openai >=1.30.3
  • tqdm >=4.65.0
ch07/06_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
requirements.txt pypi
  • jupyterlab >=4.0
  • matplotlib >=3.7.1
  • numpy >=1.25,<2.0
  • pandas >=2.2.1
  • psutil >=5.9.5
  • tensorflow >=2.15.0
  • tiktoken >=0.5.1
  • torch >=2.0.1
  • tqdm >=4.66.1