Deep Neural Networks (DNN)

(डीप न्यूरल नेटवर्क्स)


🔶 1. What is a Deep Neural Network?

📌 परिभाषा:

Deep Neural Network (DNN) एक ऐसा artificial neural network होता है जिसमें एक से ज़्यादा hidden layers होते हैं।

👉 यह shallow network (जैसे simple MLP जिसमें 1 hidden layer हो) से अलग होता है क्योंकि इसमें “depth” होती है — यानी कई layers जो input से output तक data को progressively abstract करती हैं।


🧠 Structure of a DNN:

Input Layer → Hidden Layer 1 → Hidden Layer 2 → ... → Hidden Layer N → Output Layer
  • हर layer neurons का group होता है
  • Each neuron applies:

z=w⋅x+b, a=f(z)

जहाँ f कोई activation function होता है


📊 Example:

मान लीजिए एक DNN जिसमें:

  • Input Layer: 784 nodes (28×28 image pixels)
  • Hidden Layer 1: 512 neurons
  • Hidden Layer 2: 256 neurons
  • Output Layer: 10 neurons (digits 0–9 classification)

🔷 2. Why Use Deep Networks?

❓ क्यों shallow networks काफी नहीं होते?

  • Shallow networks simple problems के लिए ठीक हैं
  • लेकिन complex tasks (जैसे image recognition, NLP, audio classification) में input-output relationship बहुत nonlinear होती है

✅ Deep networks:

  • High-level features को automatically extract कर सकते हैं
  • Abstractions को hierarchy में capture करते हैं

🧠 Hierarchical Feature Learning:

LayerLearns
Layer 1Edges, curves
Layer 2Shapes, textures
Layer 3Objects, faces

🔶 DNN की Architecture क्या होती है?

Architecture का मतलब होता है कि DNN में कितनी layers हैं, हर layer में कितने neurons हैं, activation functions क्या हैं, और input-output data का flow कैसा है।


📊 High-Level Structure:

Input Layer → Hidden Layer 1 → Hidden Layer 2 → ... → Output Layer

हर layer दो चीज़ें करती है:

  1. Linear Transformation z=W⋅x+b
  2. Activation Function a=f(z)

🔷 2. Components of a DNN Architecture

ComponentDescription
Input LayerRaw input data (e.g., image pixels, features)
Hidden LayersIntermediate processing layers (more = more depth)
Output LayerFinal predictions (e.g., class scores)
Weights & BiasesParameters learned during training
Activation FunctionsAdds non-linearity (ReLU, Sigmoid, etc.)
Loss FunctionMeasures prediction error
OptimizerUpdates weights using gradients (SGD, Adam)

🧠 Typical Architecture Example (MNIST Digits):

Layer TypeShapeNotes
Input(784,)28×28 image flattened
Dense 1(784 → 512)Hidden Layer 1 + ReLU
Dense 2(512 → 256)Hidden Layer 2 + ReLU
Output(256 → 10)Digit prediction + Softmax

🧮 3. Mathematical View


🔧 4. PyTorch Code: Custom DNN Architecture

import torch.nn as nn

class DNN(nn.Module):
def __init__(self):
super(DNN, self).__init__()
self.net = nn.Sequential(
nn.Linear(784, 512), # Input to Hidden 1
nn.ReLU(),
nn.Linear(512, 256), # Hidden 1 to Hidden 2
nn.ReLU(),
nn.Linear(256, 10) # Output Layer
)

def forward(self, x):
return self.net(x)

📈 Visualization of Architecture

[Input Layer: 784]

[Dense Layer: 512 + ReLU]

[Dense Layer: 256 + ReLU]

[Output Layer: 10 (classes)]

🔍 Key Architecture Design Questions

  1. कितनी hidden layers होनी चाहिए?
  2. हर layer में कितने neurons?
  3. कौन सा activation function चुनना है?
  4. क्या dropout, batch norm चाहिए?
  5. Loss function कौन सा है?

🎯 Summary:

ElementRole
LayersInput → Hidden(s) → Output
ActivationNon-linearity लाती है
DepthLayers की संख्या
WidthNeurons per layer
OptimizerGradient से weights update करता है

📝 Practice Questions:

  1. DNN की architecture में कौन-कौन से भाग होते हैं?
  2. Hidden layers कितनी होनी चाहिए — इससे क्या फर्क पड़ता है?
  3. Activation function का क्या महत्व है architecture में?
  4. DNN architecture में overfitting कैसे रोका जाता है?
  5. Architecture tuning कैसे किया जाता है?

🔶 Training a DNN

💡 Standard Process:

  1. Forward Pass: Prediction generate करना
  2. Loss Calculation: Prediction vs ground truth
  3. Backward Pass: Gradient computation
  4. Optimizer Step: Weights update

🚧 Challenges in Training Deep Networks:

ChallengeSolution
Vanishing GradientsReLU, BatchNorm, Residual connections
OverfittingDropout, Data Augmentation
Computational CostGPU acceleration, Mini-batch training

🔧 4. PyTorch Code: Simple DNN for Classification

import torch.nn as nn

class SimpleDNN(nn.Module):
def __init__(self):
super(SimpleDNN, self).__init__()
self.model = nn.Sequential(
nn.Linear(784, 512),
nn.ReLU(),
nn.Linear(512, 256),
nn.ReLU(),
nn.Linear(256, 10)
)

def forward(self, x):
return self.model(x)

🔬 5. Applications of DNNs

DomainUse Case
Computer VisionImage classification, Object detection
NLPText classification, Sentiment analysis
HealthcareDisease prediction from X-rays
FinanceCredit scoring, Fraud detection
RoboticsSensor fusion, control systems

📈 Summary:

TermMeaning
DNNNeural network with 2+ hidden layers
DepthRefers to number of layers
PowerLearns complex mappings from data
ChallengesVanishing gradients, Overfitting, Compute cost

📝 Practice Questions:

  1. DNN और shallow network में क्या फर्क है?
  2. DNN के training में कौन-कौन सी steps होती हैं?
  3. Vanishing gradient क्या होता है और इसे कैसे solve किया जाता है?
  4. PyTorch में DNN implement करने का तरीका बताइए।
  5. DNN किन-किन क्षेत्रों में प्रयोग किया जाता है?