y0oshi/text-llm-training-from-scratch — explained in plain English
Analysis updated 2026-05-18
Learn exactly how a language model is trained by reading a full, unhidden implementation.
Train a small demonstration language model on the included tiny sample text corpus.
Experiment with fine tuning and preference based alignment techniques like DPO on your own data.
Reproduce a 17 million parameter model trained on short story text and compare results.
| y0oshi/text-llm-training-from-scratch | av2xn/doan | chandar-lab/semantic-wm | |
|---|---|---|---|
| Stars | 30 | 30 | 30 |
| Language | Python | Python | Python |
| Setup difficulty | moderate | hard | hard |
| Complexity | 4/5 | 5/5 | 5/5 |
| Audience | developer | developer | researcher |
Figures from each repo's GitHub metadata at analysis time.
Requires Python 3.10+ and PyTorch 2.1+, a CUDA GPU speeds things up but CPU and Apple Silicon also work.
This project builds an entire text generating AI system from the ground up, in Python, without relying on the popular libraries that usually hide the details. Instead of using ready made frameworks like transformers, it writes every piece of the training process itself, so someone learning how these systems work can read through the code stage by stage and understand what is actually happening at each step. The pipeline covers four main phases: turning text into a numbered vocabulary the model can read, training the model to predict the next piece of text over and over, teaching it to follow instructions through supervised fine tuning, and then refining its behavior further using preference based methods that reward better responses over worse ones. The underlying model is a modern text transformer built with the same kinds of components used in current well known models, and it runs on a regular CPU, an Apple Silicon Mac, or an Nvidia GPU without needing separate code for each. Once installed, the project gives you a single command called llm that can train a tokenizer, prepare training data, pretrain a model, generate text from it, and more. It even includes a small sample text dataset so you can run through the whole process quickly, and an interactive menu that walks you through every step by arrow keys, always showing you the exact command it is about to run. As a concrete demonstration, the repo includes a ready made configuration for a small 17 million parameter model trained on a dataset of short children's stories, and shows a real sample of the coherent short stories that model can produce after training. The tokenizer works at the level of raw text bytes, so it can handle any language without ever failing to recognize a character, and training data is stored efficiently on disk so datasets larger than your computer's memory can still be used. This project is best suited for people who want to genuinely understand how language models are trained rather than just use one, and it is released under the MIT license.
A from scratch, code first walkthrough of how to build and train a text generating AI model, step by step, in plain PyTorch.
Mainly Python. The stack also includes Python, PyTorch, NumPy.
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.