A layer is a matrix multiplication
Each output neuron takes a weighted sum of the inputs plus a bias. Stack those weights in rows and you have a matrix.
positive weightnegative weightThicker means larger.
W
×x
+1.00.5−1.0
b
=0.20.00.30.4
z
0.30−0.800.501.35
z₁ = (0.7)(1.0) + (−1.4)(0.5) + (−0.1)(−1.0) + 0.2 = 0.30
ShapesW is 4 × 3, x has 3, b and z have 4
Neuron 1 output z₁0.30
Challenges
0 of 3 complete
- Find inputs that make every output equal its own bias. (not yet)
- Push one neuron's output as high as the input sliders allow. (not yet)
- Make a neuron output 0.00 without setting any input to 0. (not yet)
Try this
- Select an output neuron and find its row of W. The highlighted lines and the highlighted row are the same weights.
- Set all inputs to 0: every output becomes its bias.
- Press New weights and confirm the shapes never change.
The same layer in a few lines of codePython with NumPy
import numpy as np
# The demo's starting layer: 4 neurons, each reading the same 3 inputs.
W = np.array([[ 0.7, -1.4, -0.1], # row i holds neuron i's weights
[-1.3, 0.8, -0.1],
[ 0.0, -1.0, -0.7],
[ 0.2, -0.9, -1.2]])
b = np.array([0.2, 0.0, 0.3, 0.4])
x = np.array([1.0, 0.5, -1.0])
z = W @ x + b # one dot product per row, plus that row's bias
print("shapes:", W.shape, "times", x.shape, "->", z.shape)
print("z =", z.round(2))
# Neuron 1 by hand: the first row's dot product with x.
print("z1 =", round(0.7 * 1.0 + (-1.4) * 0.5 + (-0.1) * (-1.0) + 0.2, 2))
# A batch: stack inputs as rows of X and compute X W^T + b in one go.
X = np.array([[1.0, 0.5, -1.0],
[0.0, 0.0, 0.0]]) # an all-zero input returns b
print((X @ W.T + b).round(2))
print("parameters:", W.size + b.size)shapes: (4, 3) times (3,) -> (4,)
z = [ 0.3 -0.8 0.5 1.35]
z1 = 0.3
[[ 0.3 -0.8 0.5 1.35]
[ 0.2 0. 0.3 0.4 ]]
parameters: 16