From Zero to Model: A Complete Course in AI Development
Capstone · Module 7 of 7

Build Your Own Model

Everything in this course — the training loop, data and tokenization, the architecture, scaling, fine-tuning — is about to run in your browser. You are going to train a real language model from scratch, watch its loss fall in real time, and generate text from what it learned. No libraries. No cloud. Just you, some nursery rhyme text, and gradient descent.

By the end of this capstone you will have

What You Are Building

You are going to train a character-level language model: a small neural network that learns, from a short training corpus, which character is likely to follow any given sequence of characters. Given the sequence "mar", a trained model should assign high probability to "y", because that pattern appears in the training text.

The model is a simple two-layer neural network: an input layer that encodes the last three characters as a one-hot vector, a hidden layer with 64 neurons and a tanh activation, and an output layer that produces a probability distribution over the entire vocabulary. It has about 5,700 parameters. A frontier language model has hundreds of billions. The mathematics, however, are identical: forward pass, loss calculation, backward pass, weight update. What you are training is a miniature version of the same process that produced the models you use every day.

3context window (chars)
64hidden neurons
~5.7Ktotal parameters
600training epochs

The Training Corpus

The model will train on a short nursery rhyme: "Mary Had a Little Lamb" (traditional, public domain). The full text is 228 characters long. Every character — letters and spaces — is a token. The model sees three characters at a time and predicts the next one. This connects directly to Module 3: every training example is a (context, target) pair derived from the corpus.

loading...

How the Training Loop Runs

When you click Start Training, the browser runs 600 epochs of full-batch gradient descent. Each epoch is one complete pass through all the training examples. For every example, the model makes a prediction (forward pass), the loss measures how wrong it was, and backpropagation computes how each weight contributed to the error. Then every weight is nudged in the direction that reduces the loss. After 600 epochs, you should see the loss fall from around 3.0 (random guessing over the vocabulary) to below 1.4 — the model has learned the character patterns in the training text.

The loss curve below is drawn in real time as training progresses. Watch it fall. When it flattens, the model has largely converged: the easy patterns have been learned and further gains require more data or a bigger model. That flattening is the same phenomenon you read about in Module 5 — it just happens much faster at this scale.

Live Training — Character-Level Language Model Ready

Click Start to train the model. The loss curve updates every 20 epochs. Training takes 3 to 6 seconds depending on your device. After training completes, the text generator will appear.

Epoch 0 / 600
Training loss over epochs — directional illustration of gradient descent convergence on this corpus
Generate text from your trained model
Temperature: 0.8
Your generated text will appear here.

Lower temperature = more predictable. Higher = more varied. The model learned character patterns only from the training text above.

What Just Happened

If you watched the loss fall and then generated some text, you just ran every major concept from this course in sequence:

The whole pipeline in one browser tab A corpus gives you data. Tokenization converts that data into sequences the model can process. The training loop optimises the model's weights to predict those sequences. Evaluation (loss) tells you how well the model is doing. The trained model can then generate new sequences by sampling from what it learned. You have now seen every step. The only difference between this model and a frontier language model is scale.
Capstone Quiz · 4 Questions
1. In the model you just trained, what did the loss of approximately 3.0 at the start of training represent?
2. The model you trained uses the last three characters to predict the next one. Why would a Transformer architecture produce better results on the same corpus?
3. Your model trained on 228 characters of nursery rhyme text. Why would adding more training text (while keeping the model size the same) improve the model's generated output?
4. Suppose you wanted to adapt your trained model to generate text in a specific rhyming style. Which approach best describes what you would do, and why?
← Module 6: Fine-tuning and Alignment Course Home →