Module 1 · Foundations of Artificial Intelligence

Inside AI: weights, layers and prediction

Lesson 3 of 12 8 min lesson Updated on October 30, 2026
Progress in the course25%

In this lesson

AI turns knobs to make fewer mistakes.

On the inside, almost every AI is made of input numbers, adjustable knobs and a measure of error. You will do the math of one neuron by hand and see why correcting the assistant in the chat does not teach it.

The simplest part: add up and decide

The smallest part of an AI multiplies each input by a weight, adds everything up and compares the total with a cutoff. A weight is how much each input counts in the decision.

Example: a spam filter with three inputs. The word "free" counts +2. Lots of capital letters count +1. A sender who is in your contacts counts −3. The cutoff is 1.5. An email with "free" and capital letters, from a stranger, adds up to 3. It went over the cutoff: spam.

Learning means turning the knobs

Nobody writes the weights. Each weight is like a knob on a mixing desk. The machine sees an example that comes with the right answer, compares it with what it said and turns the knobs a tiny bit to make fewer mistakes. It repeats this millions of times, with millions of examples. That is training.

A single layer is not enough for things that look very much alike. That is why layers are stacked. In an image network, the first layer usually sees edges, the next one joins edges into shapes, and the last ones recognize parts of objects. Nobody taught it that order: it comes out of the adjusting.

Training, testing and use

PhaseWhat happensDo the weights change?
TrainingExamples with answers; the error adjusts the knobsYes
TestingNew examples, only to measure the errorNo
UseThe finished model answers youNo

The goal is to get right what the machine has never seen. If it memorizes the training examples and fails the test, that is overfitting. It is the student who memorizes last year's exam and does badly on this year's. So when you hear "it is 95% accurate", ask: on which examples?

The assistant predicts the next piece

To the machine, text is numbers. It cuts words into pieces called tokens. The Portuguese word "inteligência" may become two or three. That is why the assistant sometimes gets it wrong when counting letters: it does not see letters, it sees pieces.

After that, it does just one thing: it gives a probability to each token that could come next. In "The sky is", "blue" has a high probability and "green" almost zero. The answer is that choice repeated, piece by piece. Attention, an idea from the 2017 Transformer, helps decide which earlier words weigh the most. In "the bank closed because the river rose", "bank" looks at "river" and understands riverside, not money.

Correcting in the chat is not training

The weights only change during training. When you correct the assistant, the correction goes into the context: the text of the conversation, which it reads again for every answer. It looks like it learned, but it is the same model. Open a new conversation and the mistake can come back.

What the pros know

People who build a spam filter do not just choose to "get more right". The two kinds of mistake do not cost the same. Marking a real email as spam is worse than letting a spam email through, because you may miss an important notice. Back in 1998, the researchers' filter only marked an email as junk above 99.9% certainty. A professional always asks which mistake costs more and sets the cutoff by that, not just by the average.

Be careful with the average

Training measures the average error. A group with few examples weighs little in that average. In 2018, a study tested commercial systems that guess gender from photos: the error reached 34.7% for darker-skinned women, against at most 0.8% for lighter-skinned men. The average was hiding the difference.

Practice · 5 min

  1. Take ten of your own emails, five spam and five legitimate. For each one, mark 1 or 0 for the three inputs of the filter.
  2. Work out the total with the weights +2, +1 and −3. Above 1.5 is spam. Count how many it got right.
  3. Change one weight by 0.5 and count again. Did it get better or worse?

Summary

Sources

Read on October 30, 2026.

  1. LeCun, Bengio and Hinton. Deep learning (Nature, 2015): weights, training and layers.
  2. Sahami et al. A Bayesian Approach to Filtering Junk E-Mail (1998).
  3. Vaswani et al. Attention Is All You Need (2017).
  4. Buolamwini and Gebru. Gender Shades (2018).

Lesson quiz

Three situations to apply what you learned.

Lesson 3 of 12

Before moving on to the next lesson

Put what you saw into practice. The boxes stay checked in this browser, so you can come back later.

Have a question about this lesson? The IV Help team answers personally on WhatsApp.

Ask on WhatsApp