What is an Autoencoder?

अब हम एक और महत्वपूर्ण और रोचक deep learning तकनीक को समझेंगे —
📦 Autoencoder
जिसका उपयोग representation learning, dimensionality reduction, और unsupervised learning में होता है।


🔶 1. Definition (परिभाषा):

Autoencoder एक ऐसा neural network है जिसे input को ही output के रूप में reproduce करने के लिए train किया जाता है — लेकिन इस प्रक्रिया में यह data के compressed और meaningful features सीखता है।

🎯 “Autoencoder खुद से feature सीखता है — बिना किसी label के।”


🧠 2. Structure of Autoencoder

Autoencoder में तीन मुख्य भाग होते हैं:

  1. Encoder: Input को compress करता है (latent space में)
  2. Latent Space: Data का compressed representation
  3. Decoder: Compressed data को reconstruct करता है

Diagram:

      Input

[Encoder]

Compressed Code (Latent Vector)

[Decoder]

Reconstructed Output

🧮 3. Objective (Loss Function)

Autoencoder को train करने का उद्देश्य है:

जहाँ:

  • x: Original input
  • x^: Reconstructed output
  • L: Mean Squared Error (या कोई और loss)

🧱 4. Types of Autoencoders

TypeDescription
🔹 Vanilla AutoencoderBasic encoder-decoder structure
🔹 Sparse AutoencoderRegularization to learn sparse codes
🔹 Denoising AutoencoderNoisy input → Clean reconstruction
🔹 Variational Autoencoder (VAE)Probabilistic latent space
🔹 Convolutional AutoencoderCNN-based encoder-decoder for images

🔧 5. PyTorch Example (Basic Autoencoder)

import torch.nn as nn

class Autoencoder(nn.Module):
def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = nn.Sequential(
nn.Linear(784, 128),
nn.ReLU(),
nn.Linear(128, 32),
)
self.decoder = nn.Sequential(
nn.Linear(32, 128),
nn.ReLU(),
nn.Linear(128, 784),
nn.Sigmoid()
)

def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x

📊 6. Applications of Autoencoders

ApplicationDescription
✅ Dimensionality Reductionजैसे PCA से बेहतर
✅ Image DenoisingNoise हटाना
✅ Anomaly DetectionOutlier data पकड़ना
✅ Data CompressionLatent representation
✅ Image ColorizationBlack & white → Color
✅ Feature ExtractionFor downstream tasks

🔄 7. Difference from PCA

PCAAutoencoder
LinearNon-linear
No trainingTrained via gradient descent
Limited capacityLearn complex structure
Fixed basisFlexible learned features

📝 Practice Questions:

  1. Autoencoder क्या होता है?
  2. Autoencoder में latent space का क्या महत्व है?
  3. Vanilla और Denoising Autoencoder में क्या अंतर है?
  4. Autoencoder का loss function क्या होता है?
  5. Autoencoder का प्रयोग कहाँ किया जा सकता है?

🎯 Summary

FeatureDescription
Input = OutputLearns to reconstruct data
Unsupervisedकोई label नहीं चाहिए
Encoder + DecoderCompress और reconstruct करता है
ApplicationsCompression, denoising, anomaly detection