Spaces:
Sleeping
Sleeping
Expand demo corpus
Browse files
data/tiny_shakespeare_excerpt.txt
CHANGED
|
@@ -8,3 +8,62 @@ The model does not know the world yet.
|
|
| 8 |
It learns by watching one symbol follow another.
|
| 9 |
Attention lets every token ask the past what matters now.
|
| 10 |
Small code can still carry a large idea.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
It learns by watching one symbol follow another.
|
| 9 |
Attention lets every token ask the past what matters now.
|
| 10 |
Small code can still carry a large idea.
|
| 11 |
+
|
| 12 |
+
Now is the winter of our discontent
|
| 13 |
+
Made glorious summer by this sun of York.
|
| 14 |
+
|
| 15 |
+
All the world's a stage,
|
| 16 |
+
And all the men and women merely players.
|
| 17 |
+
They have their exits and their entrances,
|
| 18 |
+
And one person in a time plays many parts.
|
| 19 |
+
|
| 20 |
+
Some are born great, some achieve greatness,
|
| 21 |
+
And some have greatness thrust upon them.
|
| 22 |
+
|
| 23 |
+
The fault is not in our stars,
|
| 24 |
+
But in ourselves, that we are underlings.
|
| 25 |
+
|
| 26 |
+
This above all: to thine own self be true,
|
| 27 |
+
And it must follow, as the night the day,
|
| 28 |
+
Thou canst not then be false to any person.
|
| 29 |
+
|
| 30 |
+
A tiny transformer is a small language model.
|
| 31 |
+
It reads a window of tokens and predicts the next token.
|
| 32 |
+
The token embedding gives each symbol a learned vector.
|
| 33 |
+
The position embedding tells the model where the symbol appears.
|
| 34 |
+
Self-attention lets each token compare itself with earlier tokens.
|
| 35 |
+
A causal mask blocks the future so the model cannot cheat.
|
| 36 |
+
The feed-forward network transforms each position after attention.
|
| 37 |
+
Layer normalization keeps the hidden states stable.
|
| 38 |
+
Residual connections help gradients move through the network.
|
| 39 |
+
|
| 40 |
+
During training, the model sees many short slices of text.
|
| 41 |
+
For every character in a slice, it tries to predict the next character.
|
| 42 |
+
The loss is cross entropy between predicted logits and true next tokens.
|
| 43 |
+
AdamW updates the weights so likely next tokens become more likely.
|
| 44 |
+
|
| 45 |
+
During generation, the model starts from a prompt.
|
| 46 |
+
It predicts one token, appends it, and predicts again.
|
| 47 |
+
Temperature controls how bold the sampling is.
|
| 48 |
+
Top-k sampling keeps only the most likely choices.
|
| 49 |
+
Low temperature makes the model conservative.
|
| 50 |
+
Higher temperature makes the model more surprising.
|
| 51 |
+
|
| 52 |
+
This project builds the pieces directly in PyTorch.
|
| 53 |
+
It includes tokenization, batching, causal attention, training,
|
| 54 |
+
checkpointing, generation, a heatmap export, and a hosted demo.
|
| 55 |
+
|
| 56 |
+
To be, or not to be, that is the question.
|
| 57 |
+
Whether the model should speak with order,
|
| 58 |
+
Or drift through noise and stumble into symbols,
|
| 59 |
+
Depends on data, training, and sampling.
|
| 60 |
+
|
| 61 |
+
Attention asks the past what matters now.
|
| 62 |
+
The present token looks backward through the sequence.
|
| 63 |
+
Some earlier words become bright with importance.
|
| 64 |
+
Other earlier words fade into the background.
|
| 65 |
+
|
| 66 |
+
The small model does not know the whole world.
|
| 67 |
+
It knows only the training text it has seen.
|
| 68 |
+
But even a small model can reveal the core idea:
|
| 69 |
+
language is prediction shaped by context.
|