AI Tools
Single-Head Language Model
Building a language model from scratch and testing what improved its predictions.
Latest local checkpoint: 5.5125 validation loss and 16.58% next-token accuracy after 75,000 training steps.
I built a 2.13M-parameter language model in PyTorch to understand how it learns to predict text. After publishing the first 30,000-step checkpoint, I investigated training duration, learning rates and residual connections through seven experiments.
Technologies
Model and evaluation
I started with a small next-token predictor: a model that uses the preceding text to predict the next token. My aim was to build the components myself and investigate how changes in training and architecture affected its predictions.
The model uses a custom byte-pair encoding (BPE) tokenizer, token and positional embeddings, and one causal self-attention head. I implemented it in PyTorch and trained it with AdamW. The residual version adds the input embeddings to the attention output without introducing extra trainable parameters.
I evaluated checkpoints on the same fixed benchmark of 131,072 next-token predictions. The graphs distinguish sampled validation checks during training from the separate fixed-benchmark scores used for checkpoint comparisons.
- Parameters
- 2.13 million
- Vocabulary
- 16,384 tokens
- Context
- 128 tokens
- Built with
- Python · PyTorch · AdamW
Experiments
The published checkpoint was my starting point. I first investigated whether more training helped, then tested the learning rate and a residual connection. The retrofit and from-scratch experiments let me examine the same architectural change under different starting conditions.
Experiment 01
An uncontrolled comparison of training duration
I first compared the published 30k model with a separately trained 40k model. I wanted to find out whether additional training improved next-token prediction. The 40k model had higher validation loss: 6.2334 versus 6.0398.
The runs started with different random weights and training batches. I could not attribute the difference to training duration, so I repeated the comparison within a single continuous run.
Experiment 02
More training helped within the same run
I trained one model continuously with seed 42 and saved checkpoints at 30k and 40k steps. Fixed-benchmark validation loss fell from 6.0119 to 5.9059.

Figure 1. Training averages and sampled validation checks during the continuous run. The 30k and 40k fixed-benchmark scores are separate checkpoint evaluations. Open full-size chartAdditional training improved this model. The curve was still falling, although progress had slowed and the validation checks fluctuated. That led me to test whether a smaller learning rate would help.
Experiment 03
A lower learning rate improved loss less
I continued two copies of the same 40k checkpoint for another 10k steps, using learning rates of 3e-4 and 1e-4. Reducing the learning rate was intended to test whether finer weight updates would help as progress slowed.
The 3e-4 branch reached a fixed-benchmark loss of 5.8260. The 1e-4 branch reached 5.8671.

Figure 2. Sampled validation loss during the two learning-rate continuations. These curve endpoints differ from the fixed-benchmark scores in the text. Open full-size chartThe smaller learning rate did not achieve lower loss over the same additional training budget. The fluctuations had suggested a possible optimization issue, but this test did not support reducing the learning rate.
Experiment 04
Retrofitting a residual connection did not lower loss
I next investigated an architectural change that would preserve a direct path from the input embeddings to the attention output without adding parameters. I added a residual connection to the pretrained 50k model and continued training to 55k, alongside the unchanged model.
The modified model initially showed a sharp increase in loss, then recovered. At 55k, its fixed-benchmark loss was 5.8030, compared with 5.7932 for the original model.

Figure 3. Sampled validation loss after the residual connection was added at 50k. The initial spike was followed by recovery over the next 5k steps. Open full-size chartThe retrofit did not achieve lower validation loss within the additional 5k steps. Because the existing weights had learned without the connection, this did not settle whether the architecture would help when trained from the beginning.
Experiment 05
The residual connection helped when trained from scratch
To separate the architecture from the effects of changing a pretrained model, I trained original and residual versions from scratch for 20k steps. I matched the initial weights, training batches and hyperparameters.
The original model reached a fixed-benchmark loss of 6.1692; the residual model reached 5.9657, with no additional trainable parameters.

Figure 4. Sampled validation checks every 500 steps during matched training from scratch. The fixed-benchmark endpoint scores were evaluated separately. Open full-size chartThis matched experiment supported using the residual connection at 20k steps. Its loss was still decreasing, so I continued training the residual model.
Experiment 06
The residual model continued improving to 50k
I continued the residual model from 20k to 50k steps. Fixed-benchmark validation loss fell from 5.9657 to 5.6317, and remained below the historical original checkpoints at matching step counts.

Figure 5. Fixed-benchmark loss at matching step counts. The 20k experiment matched training conditions; later historical runs used different batch sequences. Open full-size chartThe later runs did not use identical training-batch sequences. They showed continued improvement, but the full 50k difference was not a fully controlled architectural comparison.
Experiment 07
Training to 75k brought smaller, continuing gains
Before adding another architectural component, I tested whether the existing residual model still benefited from more training. I continued from 50k to 75k with the architecture and learning rate unchanged.
Fixed-benchmark loss fell from 5.6317 at 50k to 5.5759 at 60k, 5.5324 at 70k and 5.5125 at 75k.

Figure 6. Training and validation loss from 50k to 75k. The fixed-benchmark scores in the text were evaluated separately. Open full-size chartFixed-benchmark evaluation — residual model
- 50k steps
- Validation loss ↓
- 5.6317
- Perplexity ↓
- 279.14
- Accuracy ↑
- 15.91%
- 60k steps
- Validation loss ↓
- 5.5759
- Perplexity ↓
- 263.98
- Accuracy ↑
- 16.25%
- 70k steps
- Validation loss ↓
- 5.5324
- Perplexity ↓
- 252.74
- Accuracy ↑
- 16.42%
- 75k steps
- Validation loss ↓
- 5.5125
- Perplexity ↓
- 247.78
- Accuracy ↑
- 16.58%
Change from 50k to 75k
- Loss reduction
- 2.12%
- Perplexity reduction
- 11.23%
- Accuracy gain
- +0.67 pp
The model continued to improve, with diminishing returns. These results had not established a need for another architectural change.
Results
These checkpoints have different training budgets: 50k steps for the original model and 75k for the residual model. Both use the same fixed benchmark of 131,072 next-token predictions. The comparison shows overall project progress, not the isolated effect of residual connections.
- Validation loss Lower is better
- Original · 50k steps5.8260Residual · 75k steps5.5125
- Measures how well the model predicts unseen text. Lower loss means it assigns more probability to the actual next token.
- Perplexity Lower is better
- Original · 50k steps339.01Residual · 75k steps247.78
- Another way to express prediction uncertainty, derived from loss. A lower value means the model is less uncertain.
- Top-1 accuracy Higher is better
- Original · 50k steps14.34%Residual · 75k steps16.58%
- The share of predictions where the model's first choice is the actual next token.
Discussion and limitations
The matched 20k experiment supports the residual connection under those training conditions. The later historical runs used different training-batch sequences, so they do not isolate the architectural effect over the full training run. The current model remains a small next-token predictor. Before adding more Transformer components, I want to investigate its remaining limitations. The best residual checkpoint is local; the public Hugging Face release is the older 30k model.
Initial release and source
What I learned
The independent 30k and 40k runs changed how I evaluated the project. A longer run had a worse score, but I had changed more than training duration. From then on, I used the previous result to decide what to test next and paid closer attention to which conditions each comparison actually held constant.