Challenge: Creating a Perceptron
Since our goal is to implement a multilayer perceptron, creating a Perceptron class will simplify model initialization. Its only attribute, layers is essentially a list of the Layer objects that define the structure of the network:
class Perceptron:
def __init__(self, layers):
self.layers = layers
The variables used to initialize the layers are the following:
input_size: the number of input features;hidden_size: the number of neurons in each hidden layer (both hidden layers will have the same number of neurons in this case);output_size: the number of neurons in the output layer.
The structure of the resulting perceptron should be as follows:
Swipe to start coding
Your goal is to set up the basic structure of the perceptron by implementing its layers:
-
Complete the layer initialization (
__init__()method):- Initialize the weights matrix (the shape is
(n_neurons, n_neurons)); - Initialize the biases vector (the shape is
(n_neurons, 1)).
Fill them with random values from a uniform distribution in range [β1,1). Use the
np.random.uniform()function to do this. - Initialize the weights matrix (the shape is
-
Complete the layer's forward propagation (
forward()method):- Compute the raw output values of the neurons. Use the
np.dot()function for dot product; - Apply the activation function to the raw outputs and return the result.
- Compute the raw output values of the neurons. Use the
-
Define three layers:
- Two hidden layers: each layer should have
hidden_sizeneurons and use thereluactivation function; - One output layer: it should use the
sigmoidactivation function.
- Two hidden layers: each layer should have
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain how to define the Layer class?
How do I initialize the Perceptron with specific layer sizes?
What is the purpose of having multiple hidden layers in this structure?
Awesome!
Completion rate improved to 4
Challenge: Creating a Perceptron
Swipe to show menu
Since our goal is to implement a multilayer perceptron, creating a Perceptron class will simplify model initialization. Its only attribute, layers is essentially a list of the Layer objects that define the structure of the network:
class Perceptron:
def __init__(self, layers):
self.layers = layers
The variables used to initialize the layers are the following:
input_size: the number of input features;hidden_size: the number of neurons in each hidden layer (both hidden layers will have the same number of neurons in this case);output_size: the number of neurons in the output layer.
The structure of the resulting perceptron should be as follows:
Swipe to start coding
Your goal is to set up the basic structure of the perceptron by implementing its layers:
-
Complete the layer initialization (
__init__()method):- Initialize the weights matrix (the shape is
(n_neurons, n_neurons)); - Initialize the biases vector (the shape is
(n_neurons, 1)).
Fill them with random values from a uniform distribution in range [β1,1). Use the
np.random.uniform()function to do this. - Initialize the weights matrix (the shape is
-
Complete the layer's forward propagation (
forward()method):- Compute the raw output values of the neurons. Use the
np.dot()function for dot product; - Apply the activation function to the raw outputs and return the result.
- Compute the raw output values of the neurons. Use the
-
Define three layers:
- Two hidden layers: each layer should have
hidden_sizeneurons and use thereluactivation function; - One output layer: it should use the
sigmoidactivation function.
- Two hidden layers: each layer should have
Solution
Thanks for your feedback!
single