Math for AI course · Lesson 1 of 180

Variables, Values, and the Three Roles Inside an AI Model

Learn to read model equations by separating variable names from their current values, then trace inputs, parameters, and outputs through a tiny scoring model.

Share this article

An AI model can contain millions or billions of stored numbers, receive a new set of numbers for every request, and produce yet another set of numbers as its answer. The first skill needed to read the mathematics is surprisingly small: learn to distinguish a name from the value currently attached to that name.

By the end of this lesson, you will be able to read a short model equation, identify its inputs, parameters, and outputs, substitute their values, and explain which quantities can change for different reasons.

The Mathematics for Machine Learning book begins by treating mathematics as a precise language for expressing machine learning ideas. Variables are part of that language. They let us describe one rule that works for many examples instead of writing a separate calculation for every example.

A name can outlive its current value

Suppose a tiny model gives an item a score:

s=wx+b.s = wx + b.

The four letters are variables. Each is a name with a role:

  • xx is the input feature supplied for the current item;
  • ww is a weight controlling how strongly the feature affects the score;
  • bb is a bias shifting every score by the same amount; and
  • ss is the model’s output score.

For one item, the current values might be

x=3,w=1.5,b=1.x = 3, \qquad w = 1.5, \qquad b = -1.

Substitution replaces the names with these values for this calculation:

s=wx+b=(1.5)(3)+(1)=4.51=3.5.\begin{aligned} s &= wx + b \\ &= (1.5)(3) + (-1) \\ &= 4.5 - 1 \\ &= 3.5. \end{aligned}

The value of ss is now 3.53.5. The symbol ss has not permanently become 3.53.5; another input or another set of model parameters can produce a different value.

Change a value while the variable names keep their roles. This tiny model calculates s = wx + b.
Inputx = 3.0changes with the example
Weightw = 1.5learned parameter
Biasb = -1.0learned parameter
Scores = 3.503.0 × 1.5 + -1.0

The intermediate product is 4.50. The names x, w, b, and s do not change when their current values change.

The interactive model exposes an important separation. Moving the xx control changes the example presented to the model. Moving ww or bb changes the model itself. Both actions change ss, but for different reasons.

Inputs, parameters, and outputs are different jobs

In machine learning, variables are often grouped by how their values are obtained.

RoleWhere its value comes fromWhen it normally changesTiny-model symbol
InputThe current data exampleBetween examples or requestsxx
ParameterValues learned during trainingWhen the optimizer updates the modelww, bb
OutputThe model’s calculationWhenever inputs or parameters changess

This distinction prevents a common reading error. If you see

si=wxi+b,s_i = wx_i + b,

the subscript ii says that xix_i and sis_i belong to example ii. The same parameters ww and bb are reused. For three inputs, a single model can produce three scores:

Example iiInput xix_iCalculationOutput sis_i
111(1.5)(1)1(1.5)(1)-10.50.5
233(1.5)(3)1(1.5)(3)-13.53.5
32-2(1.5)(2)1(1.5)(-2)-14-4

The row changes because the example changes. The rule remains the same.

Training changes parameters, not the meaning of the symbols

Before training, a model might have w=0.2w=0.2 and b=0b=0. After seeing data, an optimizer might update them to w=1.5w=1.5 and b=1b=-1. The symbols still name the same roles, but their stored values have changed.

This is the simplest view of training:

  1. choose current parameter values;
  2. calculate outputs for some inputs;
  3. measure the model’s error;
  4. update the parameter values; and
  5. repeat.

Later lessons will make every step precise. For now, notice why variables are essential. The expression s=wx+bs=wx+b describes the calculation before training, during training, and after training. Only the assigned values record the model’s current state.

In code, the same separation appears in function arguments and stored values:

def score(x, weight, bias):
    return weight * x + bias

weight = 1.5
bias = -1.0

first_score = score(x=1.0, weight=weight, bias=bias)
second_score = score(x=3.0, weight=weight, bias=bias)

x, weight, bias, and the returned score are names. The numbers bound to them are values. Python names and mathematical variables are not identical in every technical detail, but the comparison is useful: both let us express a general operation and then evaluate it with a particular state.

A boundary: a letter does not reveal its role by itself

There is no universal rule saying xx must be an input or ww must be a weight. Authors choose notation and should define it. In another equation, xx might be a parameter to optimize, or ww might be observed data.

Another boundary is type. A variable need not hold a single real number. It can name a list, matrix, image, token sequence, probability distribution, or even a function. The name-versus-value distinction still applies. Upcoming lessons will give precise language for those richer objects.

Check your understanding

Question 1

In s = wx + b, which symbols are parameters if x is supplied by the current request?

Show the step-by-step solution

The request supplies xx, so xx is the input. The learned or stored quantities are ww and bb, making them the parameters. The equation calculates ss, so ss is the output.

The classification is therefore:

input: x,parameters: w,b,output: s.\text{input: }x, \qquad \text{parameters: }w,b, \qquad \text{output: }s.

Question 2

Calculate the score when x = 4, w = -0.5, and b = 3. Show every substitution step.

Show the step-by-step solution

Start with the model rule:

s=wx+b.s=wx+b.

Substitute the three current values:

s=(0.5)(4)+3=2+3=1.\begin{aligned} s &= (-0.5)(4)+3 \\ &= -2+3 \\ &= 1. \end{aligned}

The output variable ss therefore has the value 11 for this model state and this input.

Question 3

The input changes from x = 2 to x = 5 while w and b stay fixed. Did the model change? Explain.

Show the step-by-step solution

No. The parameters defining the model rule stayed fixed, so the model did not change. A different example was evaluated.

The output will normally change because xx appears in s=wx+bs=wx+b, but output change alone does not tell us whether the model changed. We must ask which underlying value changed: an input value or a parameter value.

Question 4

A training step changes w from 1.5 to 1.4. What stayed constant, and what changed?

Show the step-by-step solution

The symbol ww and its role as a model weight stayed constant. Its assigned value changed from 1.51.5 to 1.41.4.

If xx and bb are held fixed, the output change is

Δs=(1.4x+b)(1.5x+b)=0.1x.\Delta s = (1.4x+b)-(1.5x+b) = -0.1x.

This also shows that the effect of the parameter update depends on the current input value.

Question 5

Why is it unsafe to assume that a symbol named x is always an input?

Show the step-by-step solution

Mathematical symbols acquire meaning from their definitions, not from the letter itself. Many authors use xx for an input, but another problem can define xx as a parameter, an unknown solution, or a random variable.

A safe reading process is:

  1. locate the sentence defining the symbol;
  2. record its allowed type or set;
  3. identify whether it is observed, chosen, learned, or calculated; and
  4. use that contract consistently in the following equations.

Sources

  1. Mathematics for Machine Learning companion website
  2. Mathematics for Machine Learning book PDF