AI Notes
Master artificial neural networks for AI. Learn ANN architecture, layers, activation functions, forward propagation, backpropagation algorithms. Technical interview questions 2024.
What Are Artificial Neural Networks?
Artificial Neural Networks (ANNs) are computational models inspired by biological neural systems. They consist of interconnected processing units (neurons) organized in layers, capable of learning complex patterns from data through adjustable connection weights. ANNs are the foundation of deep learning and power everything from image recognition to language translation.
Unlike traditional programming where you write explicit rules, neural networks learn rules implicitly from examples. Show a network thousands of cat and dog images with labels, and it discovers the distinguishing features automatically—edges, textures, shapes, and ultimately semantic concepts that no programmer explicitly coded.
Biological Inspiration
From Biological to Artificial Neurons
Biological Neuron
Dendrites → receive signals from other neurons
Cell body → integrates incoming signals
Axon → transmits output signal
Synapse → connection point (variable strength)
Artificial Neuron
Inputs (x₁, x₂, ...) → receive data
Weights (w₁, w₂, ...) → connection strengths (learnable)
Summation (Σwᵢxᵢ + b) → integrate inputs
Activation f(z) → produce output
Output → sends to next layer
The analogy is loose but motivating: synaptic strength ≈ weights, firing threshold ≈ bias, action potential ≈ activation function. The key insight is that adjusting connection strengths (weights) allows the system to learn.
Network Architecture
Layers
INPUT LAYER
- Receives raw data (pixels, features, tokens)
- No computation—just passes data forward
- Size equals number of input features
HIDDEN LAYERS
- Where computation and learning happen
- Each neuron: z = Σwᵢxᵢ + b, output = f(z)
- More layers = more abstract features
- "Deep" = many hidden layers (2+)
OUTPUT LAYER
- Produces final predictions
- Size depends on task:
- Binary classification: 1 neuron (sigmoid)
- Multi-class (k classes): k neurons (softmax)
- Regression: 1 neuron (linear/no activation)
Fully Connected (Dense) Architecture
| ├─ | ALL├ ├─→ALL├ ├─→ALL├ |
| ├─ | ALL├ ├─→ALL├ ├─→ALL├ |
| Total parameters | (3×3+3) + (3×3+3) + (3×3+3) = 36 |
How a Neural Network Learns
The Training Loop
| 2. Forward pass | compute predictions from input |
| 3. Compute loss | how wrong are the predictions? |
| 4. Backward pass | compute gradients via backpropagation |
| 5. Update weights | w = w - learning_rate × gradient |
Example: Training a Network to Classify Digits
| Network: 784 inputs (28×28 pixels) | 128 hidden → 10 output |
| Epoch 1 | Loss = 2.3 (random guessing among 10 classes) |
| Epoch 5 | Loss = 0.8 (learning basic patterns) |
| Epoch 20 | Loss = 0.15 (recognizing most digits) |
| Epoch 50 | Loss = 0.04 (98% accuracy on training data) |
| Neuron 1 | activates for horizontal lines |
| Neuron 2 | activates for vertical lines |
| Neuron 15 | activates for curves |
| Neuron 42 | activates for closed loops (0, 8, 9) |
Universal Approximation Theorem
A neural network with one hidden layer containing enough neurons can approximate any continuous function to arbitrary accuracy. This is a powerful theoretical result:
Caveat: The theorem guarantees existence but says nothing about learnability. Finding those weights through gradient descent is a separate challenge. In practice, deeper networks (more layers, fewer neurons each) learn more efficiently than wide shallow ones.
Network Design Choices
How Many Layers?
| 1 hidden layer | Can learn any function (theory) |
| Practice | simple patterns, tabular data |
| 2-3 hidden layers | Hierarchical features |
| Practice | most classical ML tasks |
| 5-20 layers | Complex vision/language patterns |
| Practice | CNNs for images, small transformers |
| 50-100+ layers | State-of-the-art deep learning |
| Practice | ResNets, GPT, requires skip connections |
How Many Neurons Per Layer?
| Rule of thumb | Start with layers decreasing in size |
| Example: [512, 256, 128, 64] | gradually compress representation |
| Too few neurons | Underfitting (can't capture complexity) |
| Too many neurons | Overfitting (memorizes training data) + slow |
Regularization: Preventing Overfitting
Dropout
| During training | randomly set neurons to 0 with probability p |
| Mask | [1, 0, 1, 0] (random) |
| Output | [0.5, 0.0, 0.3, 0.0] then scale by 1/(1-p) |
| Effect | Forces redundancy, prevents co-adaptation |
L2 Regularization (Weight Decay)
Early Stopping
Types of Neural Networks
| Architecture | Input | Specialty | Applications |
|---|---|---|---|
| Feedforward (MLP) | Vectors | Tabular data | Classification, regression |
| CNN | Images/grids | Spatial patterns | Vision, image recognition |
| RNN/LSTM | Sequences | Temporal patterns | Text, speech, time series |
| Transformer | Sequences | Long-range deps | NLP, vision, everything |
| GAN | Noise vector | Generation | Image synthesis |
| Autoencoder | Any | Compression | Anomaly detection, features |
Common Loss Functions
| Binary Classification | Binary Cross-Entropy |
| Multi-class Classification | Categorical Cross-Entropy |
| Regression | Mean Squared Error |
Interview Questions
Q: What is the difference between a neuron's weight and bias? A: Weights determine how much each input feature influences the neuron. Bias shifts the activation function, allowing the neuron to activate even when all inputs are zero. Together, they define the neuron's decision boundary: weights set the boundary's orientation, bias sets its position.
Q: Why do we need multiple layers? A: Each layer learns increasingly abstract features. Layer 1 might learn edges, layer 2 combines edges into shapes, layer 3 recognizes objects. A single layer would need exponentially more neurons to achieve the same representational power as a deep hierarchy.
Q: How is a neural network different from logistic regression? A: Logistic regression is a single-layer neural network (one neuron with sigmoid). Adding hidden layers allows the network to learn nonlinear decision boundaries. Logistic regression: linear boundary only. Deep network: arbitrary complex boundaries.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Artificial Neural Networks (ANN) - Complete BTech Guide.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, neural, networks, artificial neural networks (ann) - complete btech guide
Related Artificial Intelligence Topics