TensoriumInterview preparation
← Home

Tensorium onboarding flow

From “the cat …” to a language model

A self-paced introduction for technical people new to LLMs. Read each chapter’s explanation first, then explore its visuals one step at a time. Follow the same sentence through text, representations, a Transformer, generation and learning.

12 chapters · 59 short scenes · optional practice · no locked steps

An explanation you can defend

Learn the mechanism, then explain the trade-off.

First follow one sentence through a small Transformer. Then use optional teach-backs, experiments, and short coding exercises to make the explanation your own. Nothing locks the next chapter.

  1. Distinguish a Transformer from attention alone.
  2. Trace tokens, states, block operations, and logits.
  3. Derive attention and detect future-token leakage.
  4. Separate training updates from inference.
  5. Compare model changes by benefit, cost, and evidence.
Already know the basics? Explore GPT-2 → DeepSeek-V3 → Kimi K2 design trade-offs

Viewing a chapter is not proof of understanding. Teach-backs use self-review; code checks validate small examples, not overall mastery.

Read chapter 9: Training supplies examples and a loss

Where does the model get the answers it learns from?

After this chapter: Explain target shifting, teacher forcing, and cross-entropy without future leakage.

During generation, we ask the model to continue incomplete text. During training, we already have a complete example: “the cat sat on the mat”. That sentence supplies its own next-token targets.

After “the”, the observed next token is “cat”. After “the cat”, it is “sat”. Pair input “the cat sat on the” with target “cat sat on the mat”. Each target is one position ahead of its corresponding input.

Training supplies the example’s actual earlier tokens rather than waiting for generated ones. This is called teacher forcing. The causal mask still prevents any position from using later tokens, including its own future target. The model can compute the positions in parallel within each layer without allowing that shortcut.

The model assigns probabilities, and we measure the probability it gave the observed target. Cross-entropy loss for one target is minus the natural logarithm of that probability. A lower target probability produces a larger penalty. In our example, a target probability of 0.65 gives a loss of about 0.431.

This does not mean every alternative continuation is invalid. It measures performance on the observed training example. We average the losses over the scored positions to obtain the sentence’s mean token loss.

A batch is a group of examples used for an optimizer update. An epoch is one complete pass through the dataset. In our illustration, four examples are processed in two batches: two examples per batch, one update per batch, and two updates in the epoch. We will open the update calculation next.

Keep this idea

Training uses existing text to create examples, targets, and a numerical measure of error.

Now explore the visual

Align each input position with the token immediately after it. Then follow the examples into batches and distinguish a batch from an epoch.

Use Next step below to move at your own pace. You can reopen this explanation from any scene in the chapter.

Next, we will use that loss to work out how the stored parameters should change.

Chapter 9 / 12 · Training supplies examples and a loss

Shift a real example

Chapter scene 1 of 7 · Next step controls this detailed explanation

Our recurring sentence: the cat sat on the mat
thecatsatonthemat
position 0input: theavailable: the↓ predict nexttarget: cat
position 1input: catavailable: the cat↓ predict nexttarget: sat
position 2input: satavailable: the cat sat↓ predict nexttarget: on
position 3input: onavailable: the cat sat on↓ predict nexttarget: the
position 4input: theavailable: the cat sat on the↓ predict nexttarget: mat

The last input “the” has observed target “mat”. All five input positions are supplied together.

Play advances within this chapter every 14 seconds. Pause to inspect; Next never requires an answer.

Place remembered on this device. Chapters are directly linkable; use the address bar to share the current scene. Keyboard: left/right arrows when outside a control.

Make this chapter your own · optional practice

Read and explore first. Then explain it without looking, compare the worked answer, and try a changed example. You can leave and return without losing your draft in this browser.

Explain it in your own words

Explain target shifting, teacher forcing, and cross-entropy without future leakage. Try aloud first, then write your explanation. Compare it with a worked explanation, not a keyword score.

No reference consulted yet.
Change the situation: If targets are accidentally identical to inputs, why might a low loss be misleading?

The network is being rewarded for reproducing the current token rather than predicting the next one. Low loss would measure the wrong objective.

Draft and self-review saved in this browser, not to your account. Do not enter confidential information on a shared device.

Show the model details and provenance

Deterministic teaching trace v1, vocabulary IDs permuted to distinguish identity from position; each word retains its original embedding and next-token probabilities. The numerical model has 8 vocabulary entries, 4 features, 2 attention heads of 2 features, one pre-LayerNorm block, 8 GELU hidden units, learned-position tables, final LayerNorm (epsilon 0.00001), and an untied output head. Parameters are hand-authored, not learned from a corpus. The output head is calibrated by a four-equation solve to give the next token 65% and each of seven alternatives 5% on four demonstration prefixes. All later activations, probabilities, losses and local derivatives are computed from these same parameters. The output-head gradient is analytic; earlier embedding, query-weight and feed-forward-bias slopes are explicitly labelled central-finite-difference estimates. The Word2Vec map and the standalone SGD/AdamW examples are separately labelled illustrations. Source: src/lib/llmJourney/{numbers,model,training}.js. No actual LLM is called or downloaded.

{
  "attentionOutputProjection": [
    [
      0.14641127923648062,
      -0.2694030992674085,
      -0.28534247505748717,
      0.12225196631435749
    ],
    [
      -0.3499898627155085,
      0.304777848091882,
      -0.17851121408531348,
      0.00477013728751681
    ],
    [
      0.1512332961032762,
      -0.3304774710513706,
      0.31472392260927506,
      -0.11326800780012626
    ],
    [
      0.22137536557939866,
      0.3456861375716631,
      0.12671029797581895,
      -0.21809629998076752
    ]
  ],
  "feedforward": {
    "up": "4 × 8",
    "activation": "GELU (tanh approximation)",
    "down": "8 × 4"
  },
  "layerNorm": {
    "epsilon": 0.00001,
    "scale": 1,
    "offset": 0
  }
}
Show the code structure
# Architecture pseudocode, not an executable training script
x = token_table[token_ids] + position_table[positions]
x = x + attention(layer_norm_1(x), causal_mask=True)
x = x + linear_down(gelu(linear_up(layer_norm_2(x))))
state = final_layer_norm(x)
logits = output_projection(state)
probabilities = softmax(logits, vocabulary_axis)
# Training only: loss = mean(-log(P(observed_next_token)))
# backward computes gradients; optimizer changes parameters
# Inference only: select token, append, run again

Executable deterministic calculation and focused tests are maintained with this course; no external LLM service is used.

Primary references