Find a course

Module 1: The Artificial NeuronLesson 2 of 1114 min

Weights, Bias and the Neuron

Compute what a single artificial neuron outputs, see what weights and bias mean, and build logic gates from one neuron with the right numbers.

Step 1 of 11Learn

A neuron that decides about the beach

Let's build one neuron by hand. It decides whether you should go to the beach, using three inputs that are either 1 (yes) or 0 (no):

  • x1: is it sunny?
  • x2: is a friend coming?
  • x3: is the beach far away?

Each input gets a weight saying how much it matters: w1 = 4 (sun matters a lot), w2 = 2 (company is nice), w3 = −3 (distance counts against). The neuron also has a bias b = −3, a baseline reluctance.

The neuron computes a weighted sum, usually called z:

z = w1·x1 + w2·x2 + w3·x3 + b

Then it applies an activation function. The oldest choice is a step: output 1 if z > 0, else 0.

Sunny, friend coming, beach close: z = 4 + 2 + 0 − 3 = 3, so the output is 1, go. Not sunny, friend coming, beach close: z = 0 + 2 + 0 − 3 = −1, so stay home. Notice that the friend alone isn't enough, but sun alone is (4 − 3 = 1). The weights encode those preferences, and in a real network training discovers them from data.

An artificial neuron: inputs x1, x2, x3 are multiplied by weights, summed with a bias into z, and passed through an activation function to give the outputx1x2x3w1w2w3Σ + bzf(z)a

Step 2 of 11Practice · Work it out

Using the beach neuron (w1 = 4, w2 = 2, w3 = −3, b = −3), what is z on a sunny day when no friend is coming and the beach is far away (x1 = 1, x2 = 0, x3 = 1)?

Step 3 of 11Learn

What weights and bias really do

A weight has a sign and a size. A positive weight means "this input pushes toward firing," a negative weight means "this input pushes against it," and a weight near zero means "ignore this input." A large weight makes the neuron very sensitive to that input.

The bias shifts the threshold. Without it, z = w·x, and an all-zero input always gives z = 0, no matter what the weights are. With a bias of −3, the inputs must contribute more than 3 before the neuron fires; with a bias of +1, it fires even when every input is zero. You can think of the bias as the weight on an extra input that is always 1.

In vector notation the weighted sum is a dot product: z = w · x + b, where w = (w1, w2, w3) and x = (x1, x2, x3). This compact form matters in practice. Computers, and especially GPUs, can compute millions of dot products in parallel, and a whole layer of neurons becomes a single matrix multiplication.

With two inputs, the points where z = 0 form a straight line: w1·x1 + w2·x2 + b = 0. A step neuron fires on one side of the line and not the other. Changing the weights rotates the line; changing the bias slides it.

Step 4 of 11Practice · Diagram

What one neuron computes

If every input is 0, which stage alone still decides whether the neuron fires?

Tap the shape that answers the question, then press Check.

What one neuron computesProcess diagram: Inputs x1, x2, x3 → Multiply by weights → Add them up → Add the bias → Activation → Output.Inputs x1, x2, x3Multiply by weightsAdd them upAdd the biasActivationOutput
Inputs x1, x2, x3

Numbers coming in: pixels, features, or outputs of other neurons.

Multiply by weights

Each input is scaled by its own weight: sign = direction, size = importance.

Add them up

w1·x1 + w2·x2 + w3·x3

Add the bias

z = weighted sum + b. The bias shifts how easily the neuron fires, independent of the inputs.

Activation

A step (or smooth) function turns z into the output.

Output

Step 5 of 11Try the calculator

Single neuron calculator

Change the inputs, weights and bias. The step output is 1 when z is above 0; the sigmoid output is a smooth version you will meet in the next lesson.

Weighted sum z
0.3
Step output (1 if z > 0)
1
Sigmoid output
0.574

Step 6 of 11Learn

One neuron, three logic gates

Computer chips are built from logic gates, and a single step neuron can act as several of them. Take two inputs that are 0 or 1 and set both weights to 1. Now only the bias decides the gate:

Gatew1w2bFires when
AND11−1.5both inputs are 1 (1 + 1 − 1.5 = 0.5 > 0)
OR11−0.5at least one input is 1
NAND−1−11.5not both inputs are 1

Check AND with inputs (1, 0): z = 1 + 0 − 1.5 = −0.5, so it outputs 0, as AND should.

This is exactly what the 1958 perceptron could learn: given examples of inputs and desired outputs, it adjusted weights and bias until the line separated the 1s from the 0s. But there is a catch. XOR (exclusive or: fire when exactly one input is 1) cannot be drawn with a single straight line, so no single neuron can compute it. You'll fix that in the next lesson by adding a hidden layer.

Step 7 of 11Practice · Choose one

A step neuron has two binary inputs and weights w1 = w2 = 1. Which bias makes it behave as an OR gate?

Step 8 of 11Practice · Code challenge · Python

Write weighted_sum(inputs, weights, bias) that returns the dot product of inputs and weights plus bias, and fires(inputs, weights, bias) that returns 1 if that sum is greater than 0 and 0 otherwise.

Real Python, running in a sandbox in your browser.
  • weighted_sum([1, 0, 1], [4, 2, -3], -3)
  • weighted_sum([1, 1, 0], [4, 2, -3], -3)
  • weighted_sum([], [], 0.5)
  • fires([1, 1], [1, 1], -1.5)
  • fires([1, 0], [1, 1], -1.5)
  • fires([0, 0], [1, 1], 0)

Step 9 of 11Note

Step 10 of 11Practice · True or false

Doubling every weight and the bias of a step neuron changes which inputs make it fire.

Step 11 of 11Practice · What would you do?

What would you do?

A neuron that flags suspicious logins has inputs "new device" (x1), "unusual country" (x2) and "correct password on first try" (x3), all 0 or 1. After training, its weights are w1 = 1.2, w2 = 2.5, w3 = −1.8 and b = −1. What do the numbers tell you?