Free learning / 45-minute Model 101 lab
Model 101: from learned patterns to generated text
Understand parameters, context and inference before building an agent. Train a tiny inspectable model, follow token selection and change one cause at a time.
No account needed. Use your own copy for writing and keep the original as a reference.
Engineering lab library / Run locally
See what the model actually learned
Inspect the learned table and each token decision. Change sampling and training separately, then explain why a fluent result still needs evidence.
Real training and generation in a tiny word-bigram model. It is not an LLM: no neural network, attention, provider call or GPU. All phrases are fictional.
Start here / Python 3.11+ · Standard library
Train and inspect a tiny language model
Compare learned counts, token probabilities, generated text and parameter fingerprints.
Python 3.11+ standard library · No GPU, network or account
An original 45-minute lesson for an engineer meeting language models for the first time. Start with the explanation, follow the visual, predict a result, then inspect a small program. The maintenance phrases below are fictional text, not advice about equipment.
1. Understand the model before building the agent
A large language model (LLM) is a trained neural network: software whose many numerical parameters were adjusted using data. A language-generating model uses those numbers and its current input to calculate scores for possible next tokens. A token is a unit of encoded content; it need not be a whole word. The surrounding program chooses a token, adds it to the working sequence and continues until a stopping condition. A model is neither a programming language nor an agent framework.
That surrounding program includes a provider's serving runtime: when you call an API, your application may set supported generation options while the service performs token selection. You do not need to implement the decoding loop yourself to use a hosted model.
Think of a function with two inputs: a saved parameter set and this request's working context. Training changes the parameter set. Ordinary inference uses it to calculate an output. Giving the function a different request can change the output without rewriting the saved parameters. This analogy does not mean the model is a database lookup or that its output has been verified.
| Name | What it does | What it does not establish |
|---|---|---|
| Parameters / weights | Learned numbers used by the network's calculations | An approved, current company procedure |
| Context | Instructions, messages and evidence supplied for this request | A permanent update to the model's weights |
| Inference | Calculates outputs using a trained model | Truth, permission or completed business work |
| Decoding | Selects output tokens from the model's scores | Whether the generated statement is supported |
| Training / fine-tuning | Updates learned parameters from examples and an objective | That every future response will be correct |
| Agent application | Gives the model tools and enforces the working loop | Unlimited permission to act |
An FDE needs these distinctions to diagnose the right part of a system. A stale procedure may require better retrieval and source checks. An output limit may need a smaller task. Neither observation alone demonstrates a need to retrain a model. Provider logging, retention and any later training use are separate service policies; “inference does not update these weights” is not a privacy promise.
UNDERSTAND THE SYSTEM
What changes when a model writes the next word?
Follow an inspectable word-bigram model. Training counts adjacent words; inference uses the learned table. This original teaching model is not an LLM: it sees only one prior word and has no neural network or attention. The downloadable program performs these calculations locally.
Watch one example, step by step.
Read the full worked example
- 01Learn from examples
Training counts adjacent words. After needs, inspection occurred three times and repair twice. These learned counts stay fixed during the following inference calls.
TRAINING: 3 inspection + 2 repair → a learned table
- 02Supply this request
The prompt is the pump needs. At temperature 1, the learned needs row gives inspection 3/5 and repair 2/5. A new prompt is an input, not an update to the model's parameters.
INFERENCE: Input changes · learned table stays fixed
- 03Choose the largest
Greedy decoding selects inspection. The next step selects the end marker. The completed continuation does not establish what a real machine needs.
GREEDY: inspection · end-token · parameters unchanged
- 04Sample another continuation
With the same learned table and input, seed 0 draws about 0.844. Inspection occupies the first 0.6 of the interval; the draw lands on repair. One model can produce different outputs.
SAMPLED: repair · end-token · parameters unchanged
- 05Lower the temperature
Temperature 0.5 makes the normalized masses 9/13 and 4/13. Repair becomes less likely, but the same draw still selects it. Lower temperature does not verify a claim or erase every alternative.
COOLER: repair probability: 0.4 → about 0.308
- 06Change an earlier word
The prompt now says the valve needs. This toy uses only the last word needs, so its trace matches the pump prompt. That is a limitation of this one-word conditional model, not evidence that a Transformer ignores earlier context.
EARLIER CONTEXT: Different prompt · same last word · same trace
- 07Stop at the output limit
With one step allowed, the model selects inspection and reaches its limit before selecting the end marker. The visible word matches greedy, but the completion evidence differs. Do not invent the missing end-token observation or assume a larger limit will fix an unrelated failure.
OUTPUT LIMIT: inspection · token-limit · no end token selected
- 08Find no learned transition
The prompt ends with compressor, which has no learned row. The program produces an empty trace and stops before token selection. A modern LLM can instead generate fluent unsupported content on unfamiliar input; this toy's explicit unseen-context stop is not a general safety property of language models.
UNSEEN CONTEXT: Empty trace · unseen-context · no token selected
- 09Train a different model
Four additional repair examples create a separate learned table with counts 3 and 6. Greedy now chooses repair from the same prompt. The model differs from the base; this inference call still leaves its own parameters unchanged.
RETRAINED: New training data → new table → changed prediction
Read the connections in plain English
- 01Training examples → Learned table
The learning procedure creates the model's parameters from examples.
- 02Learned table → Next-token probabilities
Inference reads the saved values without updating them in this exercise.
- 03Request context → Next-token probabilities
The toy selects the row for the last word; a Transformer computes representations from its permitted context.
- 04Next-token probabilities → Token selection
The decoding strategy operates on the computed distribution.
- 05Token selection → Generated text
A selected word joins the working context for the next step; the end token or limit stops generation.
Check your understanding: If the output changes, must the model have been retrained?
No. Context, decoding settings and sampled choices can change an output while parameters remain fixed. Inspect the actual model/version, request, settings and result. A low temperature is not a correctness check.
2. Meet a model small enough to inspect
The lab trains a word-bigram model. “Bigram” means a pair of successive tokens. It counts which word follows another in five fictional phrases, then turns those counts into a probability distribution. It splits on spaces and uses a special <end> marker. Real LLM tokenizers use richer vocabularies.
Its entire training collection is:
the pump needs inspection
the pump needs inspection
the pump needs inspection
the pump needs repair
the valve needs repairAfter needs, the learned table has three inspection occurrences and two repair occurrences. At temperature 1, these become 3/5 and 2/5. A probability distribution allocates a total of 1 across possible next tokens. It describes this model's next-token calculation, not confidence that a real pump needs work.
This is an actual small statistical model, not an LLM or a miniature Transformer. It remembers only the immediately previous word; it has no neural layers, attention, embeddings, instruction following or factual reasoning. A generative Transformer computes with learned neural weights and representations of a much larger permitted context. Causal attention lets positions use earlier context positions; it does not grant access to an external database. The toy isolates training, prediction and selection so you can explain those jobs before studying the larger architecture.
In an autoregressive Transformer, token IDs first map to learned vector representations. Neural layers combine information from allowed positions and transform the representations into next-token scores, often called logits. Decoding turns those scores into a choice under the serving policy. The representations and attention calculations depend on this request; they can change while the learned weights stay fixed. An inference key-value cache also holds computed working state, not a new training update. None of these computations automatically reads the current company procedure from an external system.
3. Predict and run seven cases
Download fde-model-first-inference.py into your practice folder. Use Python 3.11 or later; no packages, model download, GPU, key or account are required. The program runs in memory, writes no files and makes no network calls.
python3 --version
python3 fde-model-first-inference.py compare
python3 fde-model-first-inference.py sampledBefore running, predict the continuation, stop reason and whether the model's parameters changed. Then compare your prediction with trace, parameters_before, parameters_after and model_changed_from_base.
| Case | What changes | Expected observation |
|---|---|---|
greedy | Pick the largest next-token probability | inspection, then <end> |
sampled | Draw from the same distribution, seed 0 | repair, then <end>; weights unchanged |
cooler | Sampling temperature becomes 0.5, same seed | repair still appears; its first-step probability drops from 0.4 to about 0.308 |
earlier-context | Replace pump with valve in the prompt | Still inspection: this toy sees only the last word needs |
output-limit | Allow just one generation step | inspection with token-limit, without observing <end> |
unseen | End the prompt with compressor | Empty continuation and unseen-context |
retrained | Train a separate model with four extra repair phrases | Counts become 3:6; greedy chooses repair; the model fingerprint differs from the base |
The fingerprint summarizes the learned count table to make equality visible. It is not a credential or security attestation. Each inference result should show identical before/after fingerprints, including inference on the separately retrained model. Training changes a model; generation does not mutate it here.
4. Follow one prediction through the program
Read the train, distribution and generate functions in that order.
traincounts adjacent word pairs. Repeated examples affect the table.distributionturns the relevant row into probabilities. At temperature 1, these are the relative counts. The code uses logarithms and softmax, which converts scores into nonnegative values that sum to 1.generateeither selects the largest probability (greedy decoding) or takes a pseudo-random draw from the distribution (sampling).- The chosen word becomes the next context word. The loop stops on
<end>, an absent transition or the explicit step limit.
For sampling, temperature rescales scores before normalization. A smaller positive temperature concentrates mass on stronger candidates; it does not verify a claim or make all other tokens impossible. The lab's temperature 0.5 turns the 3:2 counts into normalized 9:4 masses. With seed 0 the first draw is about 0.844, so it still lands on repair. Greedy is a separate mode; do not divide by zero. Production parameter names, supported settings and repeatability depend on the selected model and serving system.
The earlier-context and unseen cases reveal limitations of this specific toy. Do not conclude that a modern LLM ignores all but one word or always refuses unfamiliar input. It may instead generate a fluent but unsupported answer.
5. Change one cause at a time
Make a copy of the file before editing. Keep predictions and actual results.
Change A — selection without training. Change SAMPLE_SEED = 0 to SAMPLE_SEED = 1 and run sampled. The continuation becomes inspection. The counts, probabilities and parameter fingerprint stay the same. Explain why two outputs do not require two models. Restore the seed before the next edit.
Change B — training without changing the prompt. Change EXTRA_REPAIR_EXAMPLES = 4 to EXTRA_REPAIR_EXAMPLES = 0 and run retrained. The learned table now equals the base model; model_changed_from_base is false and the greedy continuation returns to inspection. Explain which data changed the earlier prediction. Repetition here is a transparent teaching input, not a recommended production fine-tuning strategy.
Do not judge a model from these seven examples. This experiment verifies the specified mechanics, not language quality, reliability or workplace performance.
6. Carry the distinction into an FDE design
Your fictional assistant receives a new approved procedure: P-17 revision 3 requires a human review before a draft is sent. A generated draft omits that review. First draw where P-17 enters context, which model/version is called, where the output is checked and which application code controls sending.
Choose an observation before proposing a change:
- If P-17 never entered the request, inspect retrieval and context construction.
- If P-17 was present but the draft contradicts it, retain the case and evaluate the prompt/model combination. A low temperature is not a factuality control.
- If the draft ends early, inspect the recorded completion reason and allowance.
- If text proposes sending, the application still has to enforce permission and review. A model's words do not execute that action.
Compare repairs without teaching to the test
Use the failing case to find a hypothesis, then choose an experiment that could disprove it. This is an authored design exercise, not a result of the toy program.
| Observation | First comparison to justify |
|---|---|
| P-17 is absent or stale in the actual request | Repair the selected context while holding the model and settings fixed |
| Current P-17 is present but contradicted | Compare one prompt or model change against the original on relevant cases |
| The result stops at its output limit | Inspect the allowance and task size; compare supported completion, not just a longer answer |
| The draft proposes bypassing review | Test the application's review and sending controls independently of the model |
For a training experiment, keep fitting examples separate from development examples used to choose a candidate, and reserve a final held-out evaluation. Held out means those cases were not used to fit or select the candidate. Repeatedly tuning against a final test set makes it part of development, even if its filename still says “test.” Avoid duplicated or near-identical cases across the comparison, and include tasks that reflect the actual intended use.
Keep the original request, source revision, model/version, supported settings, output and stop reason for each case, under the appropriate data-handling policy. Count missed review requirements and unsupported instructions alongside successful drafts; include the work a person needs to check and correct them. Define what would reject the candidate before inspecting its results. A seven-case mechanic exercise cannot establish generalization or a suitable evaluation sample size.
Fine-tuning may help a persistent behavioral gap with suitable authorized examples. It is not a replacement for fresh source access, and it cannot grant permission to send. Keep the approved review requirement in trusted application code regardless of how convincing a model's output looks.
Produce a one-page explanation with the parameter set, context, decoding choice, observed result and application boundary. State what evidence would justify a training experiment and how you would compare it on held-out tasks. “We trained it” is not a substitute for evaluation.
7. Keep the work and go deeper
Keep your seven predictions, actual traces, both changed-copy outputs and the one-page design. Explain the same mechanism to a colleague without running the program. They should be able to point to what changed and what stayed fixed.
Continue with real tokenization and request budgeting, then context construction and agent engineering. The protected Model 101 lesson adds Explain/Debug/Design rehearsals, knowledge checks and a transfer discussion under existing Academy access.
Primary references, checked 25 October 2026:
- Google's language-model introduction for n-grams, tokens and context.
- Google's Transformer introduction for neural parameters and attention.
- Hugging Face generation strategies for greedy decoding and sampling.
- Google: training, validation and test sets for separating fitting, candidate selection and final evaluation.
The lesson and lab are original LockedIn Labs instruction. These references provide deeper study; they do not imply a vendor partnership or certification.