Building a Three-Layer Neural Network with Keras and TensorFlow
Build intelligent neural networks with TensorFlow and Keras
Three-Layer Neural Network Components
Input Layer
Flattens 28x28 pixel images into 784 values. Converts human-readable grid format into machine-readable list for optimal processing.
Hidden Layer
Dense layer with 128 neurons processing 784 inputs. Creates 100,000 weighted connections that form the mysterious black box of pattern recognition.
Output Layer
10 neurons representing digits 0-9. Uses softmax activation to produce probability percentages that sum to 100% for final classification.
Neural Network Architecture by Numbers
Building Your Keras Sequential Model
Create Sequential Model
Initialize a Keras sequential model that processes layers in order from input to output
Add Flatten Layer
Convert 28x28 image grid into single 784-value list with specified input shape
Configure Dense Layer
Add hidden layer with 128 neurons using ReLU activation for pattern recognition
Define Output Layer
Create final dense layer with 10 neurons and softmax activation for digit classification
Neural networks process images more efficiently as one-dimensional lists rather than two-dimensional grids. The computer doesn't need spatial relationships between pixels - it learns to weight each of the 784 individual values to recognize patterns.
Black box is a term for stuff's happening in there, we can't really see into it
ReLU vs Traditional Activation Functions
| Feature | ReLU | Sigmoid |
|---|---|---|
| Complexity | Simple max function | Complex smooth curve |
| Performance | Faster processing | Slower computation |
| Negative values | Returns 0 | Maps to 0-1 range |
| Current usage | Modern standard | Legacy approach |
Key Activation Functions Explained
ReLU Function
Returns maximum of input value or 0. Prevents negative confidence from decreasing other digit probabilities, ensuring only positive contributions to classification.
Softmax Function
Scales output values to 0-1 range where all probabilities sum to 100%. Converts raw neural network outputs into interpretable percentage confidence scores.
Example Output Layer Probability Distribution
Your three-layer neural network is now built with proper input flattening, hidden layer processing, and probability-based output classification. The next step is compilation and training to make it functional.
This lesson is a preview from our Data Science & AI Certificate Online (includes software) and Python Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.
Key Takeaways