Click to play: Building Your First NN
8:32 / 24:10
3.3 Building Your First Neural Network
Lesson Overview
In this lesson, we'll dive into implementing a feedforward neural network from scratch using Python and NumPy. You'll understand how data flows through layers, how weights are updated, and how to evaluate your model's performance.
By the end of this session, you'll be able to build, train, and debug a basic neural network without relying on high-level frameworks like PyTorch or TensorFlow.
Key Takeaways
- Implement forward propagation with matrix operations
- Apply loss functions and backpropagation logic
- Use gradient descent to minimize error
- Evaluate accuracy on test datasets
Starter Code
import numpy as np
class NeuralNetwork:
def __init__(self, layers):
self.layers = layers
self.weights = [np.random.randn(layers[i], layers[i+1]) for i in range(len(layers)-1)]
self.biases = [np.zeros((1, layers[i+1])) for i in range(len(layers)-1)]
def sigmoid(self, x):
return 1 / (1 + np.exp(-x))
# Forward pass implementation...
def forward(self, X):
self.activations = [X]
for w, b in zip(self.weights, self.biases):
z = np.dot(self.activations[-1], w) + b
a = self.sigmoid(z)
self.activations.append(a)
return a
Module 3 Curriculum
Backpropagation Basics
12:30
Activation Functions
18:45
Building Your First NN
24:10
Optimization Techniques
21:00
MK
Can someone clarify why we initialize weights randomly instead of zeros? The video mentioned vanishing gradients but I'm still fuzzy on the math behind it.
DR
I added a ReLU activation for the hidden layers and saw a 15% improvement in accuracy. Highly recommended!
Personal Notes
Auto-saved • Markdown supported