New: Boardroom MCP Engine!

Ready to put this into action?

Get the complete AI Integration PlaybookPractical AI implementation guide — prompt engineering, workflow automation, and ROI frameworks.

Article 101 · Part 10

Understand Neural Networks, Transformers, and Model Training

Follow the numbers from an input to a prediction, then see what learning changes.

By Randy Salars · Published

On this page
  1. Meet a model with two adjustable numbers
  2. Make one training update
  3. Add layers and nonlinear behavior
  4. Understand loss, optimization, and overfitting
  5. Turn text into numerical inputs
  6. See what attention contributes
  7. Separate pretraining, adaptation, and inference
  8. Connect the mechanism to everyday limitations
  9. A reusable prompt
  10. For students: trace the change yourself
  11. Practice: explain training and inference

Follow the numbers from an input to a prediction, then see what learning changes.

You ask a language model to rewrite a paragraph. It does. You correct its tone, and the next version sounds better. Did the model just retrain itself? Did its permanent knowledge change? Or did the conversation supply new information for the next response?

These questions become easier once you separate a model’s parameters from the information supplied during use. Training adjusts parameters. Ordinary inference uses a trained model to produce an output from an input. A conversation can change the input and the application’s stored context without necessarily changing the model’s weights.

You do not need advanced mathematics to understand that distinction. Begin with a model small enough to calculate on paper.

Meet a model with two adjustable numbers

Our teaching model predicts a number using:

Prediction = weight × input + bias.

The input is a value provided for the current example. The weight and bias are parameters. The prediction is the output. A training label supplies the desired output for a training example.

Suppose the input is 2, the desired output is 4, the weight is 1, and the bias is 0. The model predicts 2. It misses the target by −2.

We need a way to measure that miss. For this example, define loss as half the squared error:

Loss = ½ × (prediction − target)².

The initial loss is ½ × (2 − 4)² = 2. This is a deliberately simple training objective. It does not represent every kind of model or every practical definition of success.

Make one training update

For this model and loss, the weight gradient is error multiplied by input, and the bias gradient is the error. They are −4 and −2.

Using a learning rate of 0.1, subtract the learning rate times each gradient:

New weight = 1 − 0.1 × (−4) = 1.4.
New bias = 0 − 0.1 × (−2) = 0.2.

The new prediction for input 2 is 1.4 × 2 + 0.2 = 3. The loss is now ½ × (3 − 4)² = 0.5.

The update reduced loss on this training example. It did not establish that the model learned the right relationship for every possible input. One point admits many possible relationships, and a model can improve on training data while generalizing poorly.

Here is the complete calculation in Python:

x, target = 2.0, 4.0
weight, bias = 1.0, 0.0
learning_rate = 0.1

prediction = weight * x + bias
error = prediction - target
loss_before = 0.5 * error ** 2

weight_gradient = error * x
bias_gradient = error
weight -= learning_rate * weight_gradient
bias -= learning_rate * bias_gradient

prediction_after = weight * x + bias
loss_after = 0.5 * (prediction_after - target) ** 2
print(round(weight, 3), round(bias, 3))
print(round(prediction_after, 3))
print(round(loss_before, 3), round(loss_after, 3))
print("Inference for input 3:", round(weight * 3 + bias, 3))

The outputs are weight 1.4, bias 0.2, prediction 3.0, losses 2.0 and 0.5, and a prediction of 4.4 for input 3. That last line performs inference. It changes neither parameter.

Add layers and nonlinear behavior

A neural network combines many adjustable calculations. A layer receives values and produces new values. Hidden layers create intermediate representations used by later layers.

Nonlinear activation functions let a network represent relationships that a stack of purely linear operations could not express on its own. A simple example is ReLU: it returns zero for negative inputs and leaves positive inputs unchanged. Google’s activation-functions lesson explains common choices and their role.

Consider a tiny unit: max(0, 2 × input − 3). At input 1 it returns 0. At input 2 it returns 1. At input 3 it returns 3. The threshold-like change is different from one straight-line response across the entire range.

Networks learn their parameter values from data under a training objective. An intermediate feature may be useful without corresponding neatly to a human-named concept. Avoid assuming that every unit has one stable meaning or that a diagram of connected circles is a literal account of a biological brain.

Understand loss, optimization, and overfitting

Loss defines what the training procedure tries to reduce. Optimization is the process of adjusting parameters to improve that objective. Backpropagation efficiently computes gradients through the network’s operations; an optimizer uses those gradients to make updates.

The objective can differ from the user’s real goal. A model may improve a prediction loss without making a downstream workflow useful. The evaluation must therefore include measures appropriate to the intended task.

Training and validation performance can diverge. If the model fits peculiarities of its training examples rather than relationships that transfer, it may perform poorly on new data. More training is not automatically an improvement.

Keep the roles from Article 100 in mind: training fits, validation guides development, and an appropriate independent test supports a final evaluation. A larger architecture does not remove the need for those boundaries.

Turn text into numerical inputs

A language model typically processes tokens rather than whole sentences as indivisible objects. Depending on the tokenizer, a token can correspond to a word, part of a word, punctuation, or another text unit. Token boundaries vary across languages and encodings.

An embedding maps a token or other item to a vector of numbers. The model then transforms those representations using the surrounding context and its learned parameters.

A vector is not a dictionary definition stored in a numbered slot. It is part of a learned representation system. Similarity between vectors can be useful while still failing to capture a distinction that matters to a human reader.

For a conceptual account of transformer models, pretraining, and adaptation, see Hugging Face’s How do Transformers work?. Use such introductions to understand the mechanism, then inspect the documentation for the actual model you use.

See what attention contributes

Attention combines information from different positions according to weights computed from their representations. The original transformer paper describes query, key, and value transformations and scaled dot-product attention. It also includes feed-forward layers and other components; “attention” is not the entire architecture. See Vaswani and colleagues, Attention Is All You Need.

For a separate arithmetic illustration, suppose attention assigns weights 0.25 and 0.75 to two scalar values, 2 and 10. Their weighted combination is:

0.25 × 2 + 0.75 × 10 = 8.

Real attention uses vectors and learned transformations, often in multiple heads and layers. This two-number example only explains weighted combination. It does not reproduce a transformer or reveal what a model “thinks.”

In an autoregressive text model, a causal mask prevents a position from attending to later target tokens in the ordinary next-token setup. Position information also matters because word order changes meaning. During generation, the model repeatedly produces a distribution for a next token using the available context.

Attention weights should not automatically be treated as a complete explanation of a model’s decision. Other transformations and interactions contribute to the output.

Separate pretraining, adaptation, and inference

Pretraining develops parameters from a broad training objective and dataset. Later training or adaptation can change behavior for particular tasks or preferences. Fine-tuning updates parameters; retrieving a document and adding it to the current context is a different operation.

During ordinary inference, the model uses its current parameters and supplied context to generate an output. The application may retain conversation history or other state, but application memory is not synonymous with changed model weights.

A useful distinction is:

ItemWhat it represents
WeightsParameters learned through training
Training exampleData used in a fitting or adaptation procedure
Current inputInformation supplied for this inference task
ContextInformation available within the model’s current processing window
Retrieved recordExternal information added through an application workflow
OutputThe generated result, which still needs task-appropriate checking

Actual services can have different data-use and retention policies. Check those separately when they matter. The computational distinction above does not itself establish a provider’s policy.

Connect the mechanism to everyday limitations

A language model learns patterns that support useful generation. That does not make every generated statement true. A plausible continuation can include a wrong date, invented reference, or unsupported assumption.

Context is finite, and including information does not guarantee that the model will use it correctly. A longer prompt can add relevant evidence or bury the important point among distractions.

Different generation settings can change outputs. Even repeatable outputs would not establish correctness by themselves. Evaluate the task: source accuracy for research, behavior for code, and measured outcomes for a predictive system.

Knowing the mechanism helps you ask better questions. Instead of “Does it know everything in this file?” ask what content entered the context, what was retrieved, what was omitted, and how the answer was checked.

A reusable prompt

Explain this model from inputs to outputs. Distinguish parameters, training examples, loss, optimization, current context, and inference. Use one small numerical calculation and identify which parts are simplified. Explain tokens, embeddings, and attention without treating them as human understanding or guaranteed factual reasoning. Ask me to predict an output or parameter change before revealing the calculation.

For students: trace the change yourself

Calculate the single training update by hand before running the Python example. Circle the values that change during training and underline the values used only for the current example.

Beginning students can explain the table of terms. Mathematics students can derive the gradients. Computing students can add a second training example and observe whether improving one example affects another.

Write one paragraph explaining why correcting a chatbot’s tone in a conversation does not, by itself, prove that its permanent model weights changed. Keep the distinction between model behavior and application data policy clear.

Practice: explain training and inference

Use the two-parameter model to reproduce the update and losses. Then hold weight 1.4 and bias 0.2 fixed and calculate predictions for inputs 0, 1, and 3. Explain why those predictions do not constitute additional training.

Describe what would be required to judge whether the learned relationship generalizes. Add a plain-language explanation of the two-value attention calculation and its limits.

Completion check: You obtain losses 2.0 and 0.5, updated parameters 1.4 and 0.2, and fixed-parameter predictions 0.2, 1.6, and 4.4. You distinguish weights from context and do not treat fluent generation or attention weights as proof of truth.

Stretch: Implement a tiny nonlinear unit with max(0, weight × input + bias). Change one parameter, predict the affected outputs, and compare the results. Label the exercise as a small network component rather than a trained language model.

Get the AI Dispatch

Weekly insights on ai & technology — delivered to your inbox. No spam, unsubscribe any time.

Want to choose specific topics? Customize your interests