Residual + MLP 75k — Single-Head Language Model
A next-token language model built in PyTorch. It uses one causal self-attention head, a residual connection, and a two-layer MLP. This model continues text. It is not a chat model.
The checkpoint was trained for 75,000 steps.
Model
| Setting | Value |
|---|---|
| Vocabulary | 16,384 |
| Context length | 128 tokens |
| Embedding / head size | 64 / 64 |
| Attention heads | 1 |
| Architecture | Single-head attention with residual connection and MLP |
Token embeddings + learned position embeddings → Q/K/V → masked attention → residual addition → 4× MLP with GELU → residual addition → LM head.
The residual paths are:
x = x + attention(x)
x = x + mlp(x)
The model code is in attention.py. The tokenizer is in tokenizer.py. Pre-tokenization is in pretokenizer.py.
Language-model training
The residual-only model and the residual+MLP model used the same seed, initialization, and sampled batches. Both ran for 75,000 steps with AdamW and a learning rate of 3e-4. The objective was next-token cross-entropy.
This graph compares validation loss for both models during training. The residual+MLP model had lower sampled validation loss across most of the run.

Fixed-window evaluation at 75,000 steps:
| Metric | Result |
|---|---|
| Validation loss | 5.4414 |
| Perplexity | 230.77 |
| Top-1 accuracy | 17.07% |
The residual-only model had a validation loss of 5.5106 in the same evaluation. The residual+MLP model has more parameters.
The next two graphs show earlier residual-only experiments. They provide context for the model series. They do not show the 75,000-step residual+MLP run.
This graph compares a baseline model with a residual model trained from scratch. At 20,000 steps, validation loss was 6.1692 for the baseline and 5.9657 for the residual model.

This graph shows sampled training and validation loss for the residual-only model from 20,000 to 50,000 steps.

Run
From the release folder:
pip install torch regex
python generate.py
generate.py loads model/exp08_residual_mlp_75k.pt and the included tokenizer. Enter a prompt to continue it. Type exit to quit. The script uses CUDA when available. Otherwise, it uses the CPU.
The model has a short context window. It is not instruction-tuned. Its output may be incoherent.
License
This release uses the MIT License. See LICENSE.
Release files
generate.py— interactive generation.LICENSE— MIT license for the release files.model/exp08_residual_mlp_75k.pt— trained checkpoint.tokenizer_model.json— tokenizer vocabulary and merge data.attention.py,tokenizer.py,pretokenizer.py— model and tokenizer code.graphs/— training graphs for the model series.