1️⃣ What Is Deep Learning?
Deep learning is a subset of machine learning that uses neural networks inspired by the human brain.
A neural network:
2️⃣ Basic Components of a Neural Network
🔹 1. Input Layer
This is where data enters the model.
Example:
🔹 2. Hidden Layers
These layers process the data.
Each layer:
The more hidden layers → the “deeper” the network.
🔹 3. Output Layer
Produces the final result.
Examples:
3️⃣ The Mathematics (Simple Version)
Each neuron does:
output = activation( (inputs × weights) + bias )
Or mathematically:
y = f(Wx + b)
Where:
4️⃣ Activation Functions
They introduce non-linearity (so the model can learn complex patterns).
Here are common ones:
ReLU(x) = max(0, x) Sigmoid(x) = 1 / (1 + e^-x) Tanh(x) = (e^x - e^-x) / (e^x + e^-x)
5️⃣ Types of Deep Learning Architectures
Below is a beginner-friendly overview.
| Architecture | Used For | Key Idea | |-------------|----------|----------| | Feedforward Neural Network (FNN) | Basic classification & regression | Data moves forward only | | Convolutional Neural Network (CNN) | Image processing | Uses convolution filters | | Recurrent Neural Network (RNN) | Sequence data | Has memory of previous inputs | | LSTM | Long sequences | Solves vanishing gradient problem | | GRU | Sequence modeling | Simpler version of LSTM | | Transformer | NLP, LLMs | Uses self-attention mechanism | | Autoencoder | Dimensionality reduction | Learns compressed representation | | GAN | Image generation | Two networks compete |
6️⃣ Feedforward Neural Network (FNN)
Simplest architecture.
Structure:
Input → Hidden Layer(s) → Output
No loops.
Data flows one direction only.
7️⃣ Convolutional Neural Networks (CNN)
Used in:
Famous Example:
Key idea:
Layers in CNN:
8️⃣ Recurrent Neural Networks (RNN)
Used for:
They have loops:
Output(t) depends on Input(t) AND Hidden(t-1)
Problem:
Solution:
9️⃣ Transformer Architecture
Revolutionized NLP.
Used in:
Core concept:
Paper:
🔟 Example: Simple Neural Network in Python
Using PyTorch:
import torch
import torch.nn as nn
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(4, 8) # input layer
self.relu = nn.ReLU()
self.fc2 = nn.Linear(8, 3) # output layer
def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
return x
model = SimpleNN()
print(model)
What this means:
1️⃣1️⃣ Example: CNN in PyTorch
import torch
import torch.nn as nn
class SimpleCNN(nn.Module):
def __init__(self):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(1, 16, 3)
self.relu = nn.ReLU()
self.pool = nn.MaxPool2d(2)
self.fc1 = nn.Linear(16 * 13 * 13, 10)
def forward(self, x):
x = self.pool(self.relu(self.conv1(x)))
x = x.view(x.size(0), -1)
x = self.fc1(x)
return x
model = SimpleCNN()
print(model)
1️⃣2️⃣ How Architecture Affects Performance
Architecture determines:
Too small → underfitting
Too large → overfitting
Compilation of All Code Blocks (Combined)
import torch
import torch.nn as nn
# --------------------------
# Simple Feedforward Network
# --------------------------
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(4, 8)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(8, 3)
def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
return x
model_fnn = SimpleNN()
print("Feedforward Network:")
print(model_fnn)
# --------------------------
# Simple CNN
# --------------------------
class SimpleCNN(nn.Module):
def __init__(self):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(1, 16, 3)
self.relu = nn.ReLU()
self.pool = nn.MaxPool2d(2)
self.fc1 = nn.Linear(16 * 13 * 13, 10)
def forward(self, x):
x = self.pool(self.relu(self.conv1(x)))
x = x.view(x.size(0), -1)
x = self.fc1(x)
return x
model_cnn = SimpleCNN()
print("\nCNN Network:")
print(model_cnn)