When I started learning about AI and neural networks, I wanted to truly understand how they work β not just copy-paste code. This blog documents my learning journey through Artificial Neural Networks (ANN), Deep Neural Networks (DNN), CNNs, and beyond, with real questions I asked and answers that finally made things click.
π― What is an ANN?
An Artificial Neural Network (ANN) is inspired by how our brain works. At its core, itβs a mathematical function that learns patterns from data.
The simplest form? A single neuron that does this:
y = w Γ x + b
Where:
- x β input (e.g., hours studied)
- w β weight (importance of the input)
- b β bias (starting offset)
- y β predicted output (e.g., exam score)
The magic: The ANNβs job is to learn the best values for w and b automatically!
π₯ My First ANN Project: Predicting Exam Scores
I built my first neural network to predict exam scores based on study hours. Hereβs the data:
| Hours Studied | Score |
|---|---|
| 1 | 50 |
| 2 | 55 |
| 3 | 60 |
| 4 | 65 |
| 5 | 70 |
| 6 | 75 |
The Code (Just 15 Lines!)
import tensorflow as tf
import numpy as np
# Input data
hours = np.array([1, 2, 3, 4, 5, 6], dtype=float)
scores = np.array([50, 55, 60, 65, 70, 75], dtype=float)
# Build ANN (1 neuron)
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=[1])
])
# Compile model
model.compile(optimizer='sgd', loss='mse')
# Train
model.fit(hours, scores, epochs=500, verbose=0)
# Predict
print("Predicted score for 8 hours:", model.predict([[8.0]]))
Result: The model predicts ~80 for 8 hours of study! π
π€ Questions I Asked (And Finally Understood)
Q: What does Dense(1, input_shape=[1]) mean?
Answer: This creates ONE neuron that:
- Takes 1 input value
- Has 1 weight (
w) and 1 bias (b) β created automatically - Outputs:
output = w Γ input + b
Think of it as the simplest possible βbrain cellβ that can learn.
Q: What is an Optimizer? What does learning_rate=0.01 mean?
Answer: The optimizer decides how the model updates its weights to reduce error.
Think of walking down a foggy hill to find the lowest point:
- Position = current weight
- Height = loss (error)
- Step size = learning rate
optimizer = tf.keras.optimizers.SGD(learning_rate=0.01)
This means: βMove 1% of the gradient distance at every update.β
| Learning Rate | Effect |
|---|---|
| Very small (0.0001) | Learns slowly, but stable π’ |
| Good (0.01) | Balanced, fast convergence β |
| Too large (1.0) | Jumps over minimum, unstable β |
Q: What does the model actually learn?
After training, I inspected the learned values:
w, b = model.layers[0].get_weights()
print("Weight:", w) # β 5
print("Bias:", b) # β 45
So the ANN learned: score β 5 Γ hours + 45
π₯ This is intelligence β nothing was hardcoded!
Q: Can I change the number of neurons and layers?
Yes! And this is how ANNs become more powerful:
# Single neuron (ANN)
Dense(1)
# Multiple neurons
Dense(4, activation='relu')
# Multiple layers (DNN)
model = tf.keras.Sequential([
tf.keras.layers.Dense(8, input_shape=[1], activation='relu'),
tf.keras.layers.Dense(4, activation='relu'),
tf.keras.layers.Dense(1)
])
Important: More neurons β automatically smarter. For simple linear problems, 1 neuron is perfect!
Q: What are βhierarchical featuresβ?
Answer: Deep networks learn simple things first, then combine them into complex patterns across layers.
Example β How a network recognizes a face:
- Layer 1: Edges & lines
- Layer 2: Shapes (eyes, nose, mouth)
- Layer 3: Complete face
This is why deep learning works β it builds understanding layer by layer! π§
π ANN vs DNN β Whatβs the Difference?
| Feature | ANN | DNN |
|---|---|---|
| Layers | 0β1 hidden | 2+ hidden β |
| Neurons | Few | Many β |
| Pattern learning | Simple | Complex β |
| Use case | Linear problems | Images, text, complex data |
Key insight: All DNNs are ANNs, but not all ANNs are deep!
π How Learning Actually Happens
- Initialize random weights (
w) and bias (b) - Forward pass: Predict output using current weights
- Calculate loss: How wrong was the prediction?
- Backpropagation: Compute gradients (which direction to adjust)
- Update weights: Move opposite to error direction
- Repeat for many epochs
After 500 epochs β the model finds the best w and b!
π§ͺ Experiments That Built My Intuition
Try these yourself:
| Experiment | What Happens |
|---|---|
| Reduce epochs to 10 | Bad prediction (not enough learning) |
| Increase epochs to 1000 | Better fit, but watch for overfitting |
| Change learning rate to 0.0001 | Very slow learning |
| Change learning rate to 1.0 | Loss explodes! β |
| Add noisy data | Model still learns the pattern |
π What I Learned (Key Takeaways)
β
Neurons are simple math: w Γ x + b
β
Training = finding the best weights automatically
β
Loss function measures how wrong predictions are
β
Optimizer decides how to update weights
β
Learning rate controls step size
β
Depth (more layers) enables learning complex patterns
π Try It Yourself
Iβve open-sourced this project! Check out the full code:
π GitHub: ANN Predict Exam Score
π― Whatβs Next on My AI Journey?
This was just the beginning! My learning roadmap:
- β ANN β Predict exam scores (DONE!)
- π DNN β Classify handwritten digits (MNIST)
- π CNN β Image classification (Cats vs Dogs)
- π RNN/LSTM β Text and sequence prediction
- π Transfer Learning β Using pretrained models
Each step builds on the previous one. Stay tuned for more posts documenting my AI learning journey!
Have questions about neural networks? Feel free to reach out β Iβm learning too, and explaining helps solidify understanding! π§ β¨