AI Learning Courses
AI Learning Courses › Tutorials › Tutorial 15
AI TUTORIAL 15 · 10 MIN READ

What is a neuron in AI and how does it work? Artificial neurons explained step by step

Every AI model, from face unlock to ChatGPT, is built from one tiny part: the artificial neuron. Learn its five parts, work one out by hand with real numbers, see how it learns from mistakes and what neurons really do inside image AI and ChatGPT, and run one yourself in Python.

Turn on JavaScript to watch the animated lesson. The full tutorial text is below.

What is a neuron in AI? Watch

In AI, a neuron (also called an artificial neuron, a node or a unit) is the smallest building block of a neural network. It is a tiny piece of maths: some numbers go in, one number comes out.

The name was borrowed from the nerve cells in our brain, but an AI neuron is not a living cell. It is a small calculation that a computer repeats millions of times a second. Connect millions of them in layers and you get the engine inside today's AI.

Inputs are multiplied by weights, added up with a bias, and passed through an activation to give the output.
Inputs are multiplied by weights, added up with a bias, and passed through an activation to give the output.

The five parts of an AI neuron Watch

The idea is not new: in 1958, Frank Rosenblatt built the perceptron, a machine with artificial neurons that learned from examples. Today's neurons work almost the same way, in five parts:

  1. Inputs (x): numbers that come in, like the brightness of a pixel or a fact written as 1 for yes and 0 for no.
  2. Weights (w): one number per input that says how much it matters. A big weight means important; a negative weight means "this pushes against".
  3. Weighted sum: multiply each input by its weight and add them all up.
  4. Bias (b): one extra number added at the end. It sets how easily the neuron fires, like a threshold.
  5. Activation: a small function that turns the sum into the output, for example a number between 0 and 1.

In one line: output = activation(w1 × x1 + w2 × x2 + w3 × x3 + b). That is all one neuron does: multiply, add, decide.

Worked example: should I take an umbrella? Watch

Let us build one neuron that decides whether to take an umbrella. It gets three inputs, each with a weight:

InputTodayWeightWhy this weight
x1: dark clouds? (1 yes, 0 no)12clouds are a strong sign of rain
x2: rain chance in the weather app0.73the forecast matters most
x3: sunny right now? (1 yes, 0 no)0-1.5sunshine pushes against rain
Biasnone-2.5do not carry an umbrella without a good reason
  1. Multiply: 1 × 2 = 2, then 0.7 × 3 = 2.1, then 0 × -1.5 = 0.
  2. Add, with the bias: 2 + 2.1 + 0 - 2.5 = 1.6.
  3. Activation: the sigmoid function turns 1.6 into 0.83.
  4. Answer: 0.83 means 83 percent sure. Take the umbrella!

On a sunny day, with no clouds, a 10 percent forecast and sunshine, the sum is 0 + 0.3 - 1.5 - 2.5 = -3.7, and the output is only 0.02: leave the umbrella at home. The same neuron gives a different answer because the inputs changed.

Activation: the neuron's on-off switch Watch

Without an activation, a neuron could only draw straight lines, and even a thousand layers would act like one. The activation adds the bend that lets networks learn complex patterns. Three common ones:

How a neuron learns from its mistakes Watch

A new neuron starts with random weights, so its first answers are guesses. Learning means adjusting the weights, one example at a time:

  1. Guess: on a day with dark clouds it says 0.4, only 40 percent sure of rain.
  2. Check: it did rain, so the right answer was 1. The error is 1 - 0.4 = 0.6.
  3. Adjust: new weight = old weight + learning rate × error × input. With a clouds weight of 0.5 and a learning rate of 0.1: 0.5 + 0.1 × 0.6 × 1 = 0.56.
  4. Repeat: do this for thousands of examples. Slowly the weights settle on values that give good answers.

Notice: if an input was 0, its weight does not change, because it played no part in the mistake. And the learning rate keeps every step small, so one odd day does not undo everything. In big networks the same idea, spread back through all the layers, is called backpropagation.

What a neuron does inside a real AI Watch

In an image AI, the inputs of a first-layer neuron are pixel brightness values, from 0 for black to 1 for white. Here is one neuron that looks at four pixels in a row, with weights -1, -1, +1 and +1, a bias of 0 and the ReLU activation:

This neuron fires only where a dark area turns bright: it has become an edge detector.
This neuron fires only where a dark area turns bright: it has become an edge detector.

Nobody types these weights in. During training, many first-layer neurons in image models turn into edge and colour detectors like this one by themselves. Neurons in deeper layers take those outputs as their inputs and respond to curves, then to eyes and wheels, then to whole faces.

In a chatbot like ChatGPT, the inputs are not pixels but the long lists of numbers that stand for each token. GPT-3, for example, has 96 layers, and each layer has about 49,000 neurons, each one looking at 12,288 numbers at once.

From one neuron to a whole network Watch

One neuron can only split things with a straight line. In 1969, Marvin Minsky and Seymour Papert showed it cannot even learn "one or the other, but not both" (XOR). The fix is to connect many neurons in layers, where each layer's outputs are the next layer's inputs.

Inputs flow through hidden layers of connected neurons to an output.
Inputs flow through hidden layers of connected neurons to an output.

Every connection has its own weight. A small network has thousands of weights; GPT-3 had 175 billion. Many layers is what "deep" means in deep learning.

AI neuron words in one table Watch

WordWhat it meansExample
NeuronOne small calculation: numbers in, one number outthe umbrella neuron
WeightHow much one input matters, learned in training3 for the rain forecast
BiasSets how easily the neuron fires-2.5 for the umbrella
ActivationTurns the sum into the outputsigmoid, ReLU
LayerA group of neurons working side by sideabout 49,000 in each GPT-3 layer
ParametersAll the weights and biases of a model together175 billion in GPT-3

Try it yourself Watch

Here is the umbrella neuron in Python. Run it free in Google Colab (colab.research.google.com) or on your own computer:

import math

def neuron(inputs, weights, bias):
    total = sum(x * w for x, w in zip(inputs, weights)) + bias
    return 1 / (1 + math.exp(-total))   # sigmoid activation

weights, bias = [2, 3, -1.5], -2.5
print('Cloudy day:', round(neuron([1, 0.7, 0], weights, bias), 2))
print('Sunny day: ', round(neuron([0, 0.1, 1], weights, bias), 2))

# Output:
# Cloudy day: 0.83
# Sunny day:  0.02

Lesson learned Watch

An AI neuron takes numbers in, multiplies each by a weight, adds a bias, and an activation decides the output. It learns by nudging its weights after every mistake, and millions of them in layers make a neural network.

Frequently asked questions

What is a neuron in AI?

An artificial neuron is a small maths function: it multiplies its inputs by weights, adds them with a bias, and passes the total through an activation function to give an output.

What are weights and bias?

Weights say how much each input matters; the bias sets how easily the neuron fires. Both are numbers the AI learns during training.

Is an AI neuron like a brain neuron?

Only in its name and the basic idea of many inputs and one output. An AI neuron is a simple maths function that works only with numbers; it does not think or feel.

How does a neuron learn?

It compares its answer with the right answer and changes each weight a little to reduce the error, over many examples. In big networks this is done with backpropagation.

How many neurons does ChatGPT have?

OpenAI has not published the size of its newest models. The older GPT-3 has 96 layers with about 49,000 neurons each in their feed-forward part, about 4.7 million in all, and 175 billion parameters.