🤖

Building Neural Networks from Scratch

Mar 15, 2025

Lecture on Building a Neural Network from Scratch

Overview

  • Presenter: Samson
  • Objective: Build a neural network from scratch using numpy and linear algebra, not utilizing TensorFlow or Keras.
  • Application: Digit classification using the MNIST dataset.

Introduction to Neural Networks

  • Neural networks consist of multiple layers and nodes.
  • Often complex and used for predictions in AI/ML.
  • Learning through implementation from scratch provides a deeper understanding.

Dataset: MNIST

  • Consists of thousands of 28x28 grayscale images of handwritten digits.
  • Each image has 784 pixels.

Neural Network Architecture

  • Input Layer: 784 nodes corresponding to each pixel.
  • Hidden Layer: 10 units.
  • Output Layer: 10 units, each representing a digit from 0 to 9.
  • Terminology: Input Layer, First Hidden Layer, Second Layer (Output Layer).

Steps in Building the Neural Network

1. Forward Propagation

  • Input Layer (a0): Initial input, equal to X.
  • First Layer (z1): Apply weights and biases using matrix operations.
  • Activation Function: Uses ReLU (Rectified Linear Unit).
    • ReLU(x) = max(0, x).
  • Second Layer (z2): Similar operations with different weights and biases.
  • Softmax Activation: Applied to output layer for probabilities.

2. Backward Propagation

  • Calculate prediction error.
  • Adjust weights and biases based on contribution to error.
  • Gradients: Compute derivatives to adjust parameters.

3. Updating Parameters

  • Update weights and biases using gradient information and learning rate (alpha).
  • Learning Rate (alpha) is a hyperparameter.

Implementation

  • Code written in Python using numpy and pandas.
  • Utilize functions for parameter initialization, forward and backward propagation, and parameter updates.
  • Train using gradient descent; observe improvement through iterations.

Performance

  • Initial accuracy reached around 84% on training data.
  • Cross-validation (dev set) accuracy around 85.5%.
  • Future improvements possible with more layers or units.

Conclusion

  • Building a neural network from scratch enhances understanding.
  • Emphasis on exploring variations like regularization and alternative optimization methods.
  • Satisfaction in seeing accurate predictions from a self-built model.

Resources

  • Follow-up materials and links to code and notes provided in the lecture.
  • Encouragement to explore further into the mathematics and implementation of neural networks.

This lecture provides a comprehensive guide to understanding and implementing neural networks, emphasizing the value of hands-on learning.