Lesson 7 of 15
The Dense Layer
Vectorizing to Multiple Neurons
A single neuron maps . A dense layer (fully connected layer) stacks neurons in parallel, mapping :
- — weight matrix, row are the weights of neuron
- — bias vector
- — input vector
- — pre-activation outputs
Each output is an independent neuron computation.
DenseLayer Class
We represent a layer as an object with:
weights: list of rows, each of lengthbiases: list of scalarsforward(inputs): computes
We initialize with small Gaussian weights (standard deviation 0.1) and zero biases. Large initial weights cause saturated activations that kill gradients.
Your Task
Implement the DenseLayer class with:
__init__(self, in_features, out_features)— initialize weights withrandom.gauss(0, 0.1)(setrandom.seed(42)before the loop) and zero biasesforward(self, inputs)— compute and return the output vector
Python runtime loading...
Loading...
Click "Run" to execute your code.