Back to Blog

Understanding Artificial Neural Networks: My Learning Journey from Zero

December 15, 2025 β€’ By Sangeeth Kariyapperuma
AI Machine Learning Neural Networks TensorFlow Deep Learning Tutorial

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!

ANN with Single Layer

πŸ”₯ 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 StudiedScore
150
255
360
465
570
675

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 RateEffect
Very small (0.0001)Learns slowly, but stable 🐒
Good (0.01)Balanced, fast convergence βœ…
Too large (1.0)Jumps over minimum, unstable ❌
Learning Rate with Step Sizes

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:

  1. Layer 1: Edges & lines
  2. Layer 2: Shapes (eyes, nose, mouth)
  3. Layer 3: Complete face

This is why deep learning works β€” it builds understanding layer by layer! 🧠


πŸ“Š ANN vs DNN β€” What’s the Difference?

FeatureANNDNN
Layers0–1 hidden2+ hidden βœ…
NeuronsFewMany βœ…
Pattern learningSimpleComplex βœ…
Use caseLinear problemsImages, text, complex data

Key insight: All DNNs are ANNs, but not all ANNs are deep!


πŸ”„ How Learning Actually Happens

  1. Initialize random weights (w) and bias (b)
  2. Forward pass: Predict output using current weights
  3. Calculate loss: How wrong was the prediction?
  4. Backpropagation: Compute gradients (which direction to adjust)
  5. Update weights: Move opposite to error direction
  6. Repeat for many epochs

After 500 epochs β†’ the model finds the best w and b!


πŸ§ͺ Experiments That Built My Intuition

Try these yourself:

ExperimentWhat Happens
Reduce epochs to 10Bad prediction (not enough learning)
Increase epochs to 1000Better fit, but watch for overfitting
Change learning rate to 0.0001Very slow learning
Change learning rate to 1.0Loss explodes! ❌
Add noisy dataModel 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:

  1. βœ… ANN β€” Predict exam scores (DONE!)
  2. πŸ”„ DNN β€” Classify handwritten digits (MNIST)
  3. πŸ”„ CNN β€” Image classification (Cats vs Dogs)
  4. πŸ”„ RNN/LSTM β€” Text and sequence prediction
  5. πŸ”„ 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! 🧠✨

"Exploring technology through creative projects"

β€” K.M.N.Sangeeth Kariyapperuma

Navigation
HomeProjectsBlog
Connect

Β© 2026 NipunSGeeTH. All rights reserved.

Crafted with Love ❀️