Fundamentals of machine learning and neural networks: Worked Example — Core Machine Learning and AI Knowledge (NVIDIA-Certified Associate: Generative AI LLM)
Fundamentals of Machine Learning and Neural Networks: Worked Example Understanding the core concepts of machine learning (ML) and neural networks is...
Fundamentals of Machine Learning and Neural Networks: Worked Example
Understanding the core concepts of machine learning (ML) and neural networks is essential for the NVIDIA-Certified Associate: Generative AI LLM certification. This worked example demonstrates the step-by-step process of training a simple neural network to classify handwritten digits, a classic problem known as the MNIST digit classification task.
Scenario
You are tasked with building a neural network model that can accurately classify images of handwritten digits (0–9). The dataset consists of 28x28 pixel grayscale images, each labeled with the correct digit.
Step 1: Define the Problem and Dataset
- Input: 28x28 pixel images flattened into a 784-dimensional vector.
- Output: One of 10 classes representing digits 0 through 9.
- Goal: Train a model to predict the correct digit label for each input image.
Step 2: Choose the Model Architecture
We select a simple feedforward neural network with one hidden layer:
- Input layer: 784 neurons (one per pixel).
- Hidden layer: 128 neurons with ReLU activation.
- Output layer: 10 neurons with softmax activation to produce class probabilities.
Step 3: Initialize Model Parameters
Randomly initialize weights and biases for each layer. Weights connect neurons between layers, and biases allow shifting the activation function.
Step 4: Forward Propagation
For each input image:
- Calculate the weighted sum of inputs plus bias for the hidden layer.
- Apply the ReLU activation function: ReLU(x) = max(0, x).
- Calculate the weighted sum plus bias for the output layer.
- Apply the softmax function to obtain probabilities for each digit class.
Step 5: Compute Loss
Use the cross-entropy loss function to measure the difference between predicted probabilities and the true label:
Loss = -∑(y_true * log(y_pred))
where y_true is the one-hot encoded true label and y_pred is the predicted probability vector.
Step 6: Backpropagation
Calculate gradients of the loss with respect to weights and biases using the chain rule. This step propagates the error backward through the network to update parameters.
Step 7: Update Parameters
Apply an optimization algorithm such as stochastic gradient descent (SGD) to adjust weights and biases:
- weight_new = weight_old - learning_rate * gradient
- bias_new = bias_old - learning_rate * gradient
Step 8: Iterate Training
Repeat steps 4–7 over multiple epochs (full passes through the training dataset) until the loss converges or accuracy plateaus.
Worked Example Summary
Given: 28x28 pixel images, 10 output classes.
Process:
- Flatten image to 784-dimensional vector.
- Forward propagate through hidden layer with ReLU activation.
- Forward propagate through output layer with softmax activation.
- Calculate cross-entropy loss.
- Backpropagate error to compute gradients.
- Update weights and biases using SGD.
- Repeat for multiple epochs.
Outcome: The neural network learns to classify handwritten digits with increasing accuracy by iteratively adjusting parameters to minimize loss.
This example encapsulates the fundamental workflow of training a neural network, a core skill validated by the NVIDIA-Certified Associate: Generative AI LLM exam. Mastery of these steps builds a solid foundation for developing and integrating AI-driven applications using large language models and other deep learning architectures.
More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →