This small teaching project shows how text moves through a neural network and a simplified ChatGPT-style transformer.
-
lewis_carroll_transformer_lab.html
Standalone interactive browser demo. Open it directly in a modern web browser. -
lewis_carroll_5_layer_neural_net.xlsx
Interactive Excel workbook showing tokenization, embeddings, weights, biases, weighted sums, activations, and a five-layer neural network. -
lewis_carroll_5_layer_net.py
PyTorch version of the five-layer teaching model. It prints each phase of the forward pass and includes an interactive command mode.
The examples use compact excerpts from:
- Alice's Adventures in Wonderland
- Through the Looking-Glass
by Lewis Carroll.
The examples are intentionally small so the calculations remain visible and understandable.
Open:
lewis_carroll_transformer_lab.html
Try changing the prompt, softmax temperature, MLP activation, and attention block.
The flow is:
text → tokens → token IDs → embeddings → Q/K/V attention → transformer blocks → logits → softmax → next token
Open:
lewis_carroll_5_layer_neural_net.xlsx
Useful sheets include:
- Playground — change the input word and see the full forward pass.
- Tokenization — see text become a token ID and embedding.
- Embeddings — inspect and edit embedding values.
- Weights — edit weights, biases, and activation functions.
- Calculations — see every
input × weight, bias, weighted sum, and activation.
Yellow cells are intended to be edited.
The core neuron calculation is:
z = Σ(weight × input) + bias
followed by:
a = activation(z)
That activation becomes an input to the next layer.
Requires Python and PyTorch.
Run:
python lewis_carroll_5_layer_net.py --input aliceInteractive mode:
python lewis_carroll_5_layer_net.py --input kitten --interactiveUseful interactive commands:
input rabbit
activation 1 relu
weight 1 0 2 0.75
bias 3 1 -0.25
embedding alice 0 1.5
forward
show 1
train 250
quit
Softmax converts arbitrary output scores, called logits, into positive values that add up to 1:
p_i = exp(z_i / T) / Σ exp(z_j / T)
where T is temperature.
- Lower temperature makes the highest-probability choices more dominant.
- Higher temperature makes the distribution flatter and more varied.
Softmax is used inside attention to create attention weights, and again at the output to create next-token probabilities.
These are educational models, not replicas of ChatGPT.
Real large language models use much larger vocabularies, embeddings with thousands of dimensions, many transformer layers, many attention heads, and billions of learned parameters.
The goal here is to make the underlying calculations visible and editable.