Biological Neuron vs Artificial Neuron

(जैविक न्यूरॉन बनाम कृत्रिम न्यूरॉन)


🔹 1. Biological Neuron (जैविक न्यूरॉन) क्या होता है?

यह मानव मस्तिष्क की मूल इकाई है जो संकेतों (signals) को लेती है, प्रक्रिया करती है और अन्य न्यूरॉनों को भेजती है।

🔬 संरचना (Structure):

भागकार्य
DendritesInput signal लेते हैं
Cell Body (Soma)Input को process करता है
AxonOutput signal को भेजता है
Synapseदो neurons के बीच signal पास करता है

🧠 कार्यप्रणाली:

  • जब कुल Input signal एक Threshold से ऊपर जाता है, तब neuron “Fire” करता है (Signal भेजता है)।

🔹 2. Artificial Neuron (कृत्रिम न्यूरॉन)

Deep Learning में Artificial Neuron का उपयोग किया जाता है, जो Biological neuron से प्रेरित है लेकिन गणितीय होता है।

🔢 कार्यप्रणाली:

  • xi​: Inputs
  • wi: Weights
  • b: Bias
  • f: Activation function
  • y: Output

🔁 तुलनात्मक तालिका (Comparison Table)

विशेषताजैविक न्यूरॉनकृत्रिम न्यूरॉन
संरचनाDendrites, Axon, SynapseInputs, Weights, Activation
संकेत (Signal)ElectrochemicalNumerical (वास्तविक संख्या)
प्रसंस्करणThreshold based firingWeighted sum + Activation
सीखनाSynapse के बदलाव सेWeights update (Gradient Descent)
नेटवर्कBiological Neural NetworkArtificial Neural Network (ANN)

🧠 विज़ुअल तुलना (Diagram)

Biological Neuron:                        Artificial Neuron:

Input (Dendrites) x1, x2, x3 →
↓ ↓
Cell Body (Summation) w1x1 + w2x2 + w3x3 + b
↓ ↓
Axon → Output Activation Function → Output

🔍 निष्कर्ष (Conclusion):

  • Artificial Neurons inspired हैं Biological Neurons से, परंतु वे सरल गणितीय मॉडल हैं।
  • एक Artificial Neuron सिर्फ एक छोटा सा भाग है Deep Learning नेटवर्क का, लेकिन उसका inspiration मानव मस्तिष्क से आया है।
  • जैसा मानव मस्तिष्क सिखता है अनुभव से, वैसे ही ANN सिखता है डेटा से।

🎯 उद्देश्य (Objective Summary)

  • जैविक न्यूरॉन की संरचना और कार्यप्रणाली समझना
  • कृत्रिम न्यूरॉन का गणितीय स्वरूप जानना
  • दोनों के बीच की समानता और भिन्नता पहचानना
  • Deep Learning में इस संबंध का महत्व समझना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Dendrites और Axon का कार्य क्या होता है?
  2. Artificial Neuron किस प्रकार का Input लेता है?
  3. दोनों प्रकार के न्यूरॉन में signal कैसा होता है?
  4. एक Artificial Neuron का गणितीय formula लिखिए।
  5. कृत्रिम न्यूरॉन जैविक न्यूरॉन से कैसे प्रेरित है?

Neural Networks Fundamentals

(न्यूरल नेटवर्क की मूल बातें)


🔷 1. परिचय (Introduction)

Neural Network एक ऐसा गणितीय मॉडल है जो इंसानी मस्तिष्क की तरह सीखने का प्रयास करता है। यह इनपुट को लेता है, layers के ज़रिए प्रोसेस करता है और फिर आउटपुट देता है।

Deep Learning = कई layers वाले Neural Network


🧱 2. Basic Structure of a Neural Network

एक Neural Network में मुख्यतः तीन प्रकार की layers होती हैं:

Layer Nameकार्य
Input Layerबाहरी डेटा को लेती है
Hidden Layersडेटा को प्रोसेस करती हैं
Output Layerअंतिम निर्णय या अनुमान देती है

🔁 Working Flow:

Input → Weights × Input + Bias → Activation → Output

🧠 3. Perceptron – सबसे सरल Neural Unit

➤ परिभाषा:

Perceptron एक single-layer neural network है, जो binary classification कर सकता है।

Perceptron Formula:

जहाँ:

  • xi​: Input
  • wi: Weights
  • b: Bias
  • f: Activation Function (जैसे: Step Function)

💡 4. Activation Functions

Activation function यह तय करता है कि कोई neuron activate होगा या नहीं। यह non-linearity introduce करता है।


🔂 5. Forward Pass & Backpropagation

🔄 Forward Pass:

Input → Output तक की गणना
(Weights, Biases, Activation के साथ)

🔁 Backpropagation:

Loss को Output से Input की तरफ propagate करना
→ Gradient निकालना (Chain Rule)
→ Weights update करना (Gradient Descent)


💻 आवश्यक कोड: एक सिंपल Neural Network (PyTorch)

import torch
import torch.nn as nn

# Simple feedforward network
class SimpleNN(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(2, 4) # Input layer to hidden
self.relu = nn.ReLU()
self.fc2 = nn.Linear(4, 1) # Hidden to output

def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
return self.fc2(x)

model = SimpleNN()
print(model)

📌 Visualization: Neural Network Structure

Input Layer: x1, x2

Hidden Layer (Neurons)

Activation (ReLU)

Output Layer: ŷ

🎯 Chapter Objectives (लक्ष्य)

  • Neural Network की मूल संरचना को समझना
  • Perceptron की कार्यप्रणाली को जानना
  • Activation Functions का महत्व जानना
  • Forward और Backpropagation के बीच का संबंध समझना
  • PyTorch में एक सरल मॉडल बनाना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Neural Network में तीन मुख्य layers कौन-सी होती हैं?
  2. Perceptron का गणितीय फ़ॉर्मूला लिखिए और समझाइए।
  3. ReLU और Sigmoid में क्या अंतर है?
  4. Forward Pass और Backpropagation क्या होते हैं?
  5. नीचे दिए गए कोड में कितने neurons hidden layer में हैं?

self.fc1 = nn.Linear(3, 5)


Chain Rule and Partial Derivatives

(चेन रूल और आंशिक अवकलज – मल्टीलेयर नेटवर्क में Gradient की कुंजी)

🔷 1. परिचय (Introduction)

Deep Learning में हर layer interconnected होती है, और output पर effect डालती है।Gradient को backward propagate करने के लिए हम दो concepts पर निर्भर करते हैं:

  • Partial Derivatives (∂)
  • Chain Rule

यह अध्याय Neural Networks की training को समझने में केंद्रीय भूमिका निभाता है

🔹 2. Partial Derivatives (आंशिक अवकलज)

➤ परिभाषा:

जब किसी फंक्शन में एक से अधिक variable हों (multivariable function), तब किसी एक variable के respect में निकाले गए derivative को Partial Derivative कहते हैं।

📌 Deep Learning में उपयोग:

  • Loss Function कई weights पर निर्भर करता है
  • हर weight का gradient आंशिक अवकलज से निकाला जाता है
  • Vector form में ये gradients बनाते हैं: Gradient Vector

🔹 3. Chain Rule (श्रृंखलित नियम)

➤ परिभाषा:

जब एक function दूसरे function के अंदर होता है (nested function), तब derivative निकालने के लिए हम Chain Rule का उपयोग करते हैं।

➤ Deep Learning Analogy:

मान लीजिए:

👉 यही Backpropagation में होता है — gradients हर layer से पीछे propagate होते हैं।

📉 4. Multivariable Chain Rule Example

मान लीजिए:

💡 Visualization Idea:

Loss L

Activation a = f(w·x + b)

Weight w

We want:

PyTorch में Automatic Chain Rule

import torch

x = torch.tensor(2.0, requires_grad=True)
y = x**2 + 3 * x + 1

y.backward()
print("dy/dx:", x.grad) # Output: dy/dx = 2x + 3 = 7

🎯 Chapter Objectives (लक्ष्य)

  • Partial Derivative की परिभाषा और गणना समझना
  • Chain Rule के पीछे का सिद्धांत जानना
  • Deep Learning में gradient propagation कैसे होता है, इसे समझना
  • Real model में gradients कैसे जुड़ते हैं, यह देखना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Partial Derivative किसे कहते हैं? उदाहरण सहित समझाइए।
  2. Chain Rule का उपयोग कहाँ किया जाता है?
  3. Deep Learning में Chain Rule का वास्तविक उपयोग किस चरण में होता है?
  4. नीचे दिए गए कोड का आउटपुट क्या होगा?
x = torch.tensor(3.0, requires_grad=True)
y = (2*x + 1)**2
y.backward()
print(x.grad)

Deep learning :Probability and Statistics

(प्रायिकता और सांख्यिकी – Deep Learning की गणितीय नींव)


🔷 1. परिचय (Introduction)

Probability और Statistics, Deep Learning की अनिश्चितताओं से निपटने की क्षमता का आधार हैं।
Neural Networks noisy data, uncertain predictions, और stochastic optimization पर आधारित होते हैं, इसलिए इन दोनों शाखाओं की समझ अत्यंत आवश्यक है।


🔢 2. Probability (प्रायिकता)

➤ परिभाषा:

Probability किसी घटना के घटने की संभावना को मापती है।

उदाहरण:

उदाहरण: सिक्का उछालने पर Head आने की प्रायिकता: P(Head)=1/2


📌 Deep Learning में उपयोग:

उपयोग क्षेत्रभूमिका
DropoutRandomly neurons को हटाना (probability आधारित)
Bayesian Neural NetsUncertainty modeling
ClassificationProbabilities में output (Softmax)
SamplingRandom initialization, augmentation

📊 3. Statistics (सांख्यिकी)

➤ परिभाषा:

Statistics का कार्य है डेटा को संगठित करना, विश्लेषण करना और सारांश निकालना


📌 मुख्य सांख्यिकीय माप:

मापसूत्र/उदाहरण
Mean (औसत)xˉ=1/n ∑xi
Median (मध्य)मध्य मान (sorted list में बीच का मान)
Mode (मोड)सबसे अधिक बार आने वाला मान
Variance (σ2)1/ n ∑(xi−xˉ)2
Standard Deviation (σ)sqrt Variance

📌 Deep Learning में Statistics के उपयोग:

क्षेत्रउपयोग
Data NormalizationMean & Std से scaling
BatchNorm LayersRunning Mean और Variance
EvaluationAccuracy, Confusion Matrix
Loss AnalysisDistribution plotting (e.g., Histogram)

🧠 4. Random Variables & Distributions

➤ Random Variable:

ऐसा variable जो किसी प्रयोग के परिणाम पर निर्भर करता है।

➤ Common Distributions:

नामउपयोग
BernoulliBinary classification (0 या 1)
BinomialRepeated binary trials
Normal (Gaussian)Image, speech data – most natural data
UniformRandom weight initialization
PoissonRare event modeling

📉 Normal Distribution Formula:


(Statistics & Probability in PyTorch)

import torch

# Random Normal Distribution Tensor
data = torch.randn(1000)

mean = torch.mean(data)
std = torch.std(data)

print("Mean:", mean.item())
print("Standard Deviation:", std.item())

🎯 Chapter Objectives (लक्ष्य)

  • Probability की मूल अवधारणा समझना
  • Statistics के माप और उनका प्रयोग जानना
  • Deep Learning में distributions का महत्व समझना
  • Variance, Std Deviation, Mean आदि का उपयोग करना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Probability का Deep Learning में क्या उपयोग होता है?
  2. Mean और Median में क्या अंतर है?
  3. Variance और Standard Deviation क्यों आवश्यक हैं?
  4. Gaussian Distribution का एक उदाहरण दीजिए।
  5. निम्नलिखित कोड से क्या परिणाम मिलेगा? pythonCopyEditdata = torch.tensor([2.0, 4.0, 6.0]) print(torch.mean(data))

Deep Learning : Calculus Basics – Derivatives & Gradients

🔹 1. परिचय (Introduction)

Calculus, विशेष रूप से Differential Calculus, Deep Learning में उस प्रक्रिया को दर्शाता है जिससे हम यह समझते हैं कि एक फ़ंक्शन का आउटपुट, उसके इनपुट में हुए छोटे बदलाव से कैसे प्रभावित होता है।

Deep Learning में “Gradient Descent” और “Backpropagation” इन्हीं सिद्धांतों पर आधारित हैं।


🔹 2. Derivative क्या होता है?

➤ परिभाषा:

किसी फ़ंक्शन f(x) का Derivative यह बताता है कि x में एक छोटी-सी वृद्धि करने पर f(x) में कितना बदलाव आता है।

उदाहरण:


🔧 Deep Learning में उपयोग:

  • Derivative बताता है कि Loss Function कितनी तेज़ी से बदल रहा है।
  • इससे हम जान पाते हैं कि weights को बढ़ाना चाहिए या घटाना, ताकि Loss कम हो।

🔹 3. Chain Rule

जब एक फ़ंक्शन दूसरे फ़ंक्शन के अंदर छुपा हो (nested function), तब Derivative निकालने के लिए Chain Rule का उपयोग होता है।

उदाहरण:


🔁 Backpropagation इसी principle पर आधारित है – यह हर layer के output का derivative पिछले layers तक propagate करता है।


🔹 4. Gradient क्या है?

➤ परिभाषा:

Gradient, एक multi-variable function का vector derivative होता है। यह उस दिशा को दिखाता है जिसमें function सबसे तेजी से बढ़ता या घटता है।


➤ Deep Learning में Gradient का उपयोग:

  • Model के weights और biases को अपडेट करने के लिए
  • Gradient Descent के माध्यम से Loss को minimize करने के लिए

💻 आवश्यक कोड (PyTorch में Gradient निकालना)

import torch

# Variable with gradient tracking enabled
x = torch.tensor(2.0, requires_grad=True)

# Function: f(x) = x^2
y = x**2

# Compute gradient
y.backward()

print("dy/dx at x=2:", x.grad) # Output: 4.0 (because dy/dx = 2x)

📌 वास्तविक उपयोग (Real Use in Deep Learning)

ConceptCalculus उपयोग
Loss FunctionDerivative से gradient निकालना
OptimizersGradient Descent step में
BackpropagationChain Rule से gradient को पीछे propagate करना
RegularizationCost Function में derivative से नियंत्रण

🎯 Chapter Objectives (लक्ष्य)

  • Derivatives की बुनियादी समझ प्राप्त करना
  • Chain Rule की अवधारणा को जानना
  • Gradient के महत्व को समझना
  • Gradient Descent और Backpropagation में Calculus की भूमिका जानना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Derivative का Deep Learning में क्या कार्य है?
  2. Chain Rule किसलिए उपयोग होता है?
  3. Gradient क्या दर्शाता है और इसे क्यों निकाला जाता है?
  4. यदि f(x)=x3 तो f′(x) क्या होगा?
  5. नीचे दिए गए PyTorch कोड का आउटपुट बताइए:

6. नीचे दिए गए PyTorch कोड का आउटपुट बताइए:

x = torch.tensor(3.0, requires_grad=True)
y = x**3
y.backward()
print(x.grad)

🔹Deep Learning मॉडल का उद्देश्य होता है कि वह सही prediction करे। इसके लिए हमें Loss Function को न्यूनतम (minimize) करना होता है।
यह कार्य Gradient Descent नाम की optimization तकनीक से होता है।


🔹 5. Gradient Descent क्या है?

➤ परिभाषा:

Gradient Descent एक iterative optimization algorithm है जिसका उपयोग Loss Function को कम करने के लिए किया जाता है।
यह हमेसा gradient की उल्टी दिशा में चलता है – जहाँ loss कम होता है।

🔁 “उतरती पहाड़ी पर सही रास्ते से नीचे जाना।”


🔹 6. Gradient Descent का सूत्र

मान लीजिए हमारा वेट w है, और हमने उसका gradient निकाला है ∂L/∂w तो नया वेट होगा:

जहाँ:

  • η = Learning rate (0.001, 0.01 etc.)
  • ∂L/∂w = Gradient of Loss function

🔹 7. Learning Rate का महत्व

Learning Rateप्रभाव
बहुत छोटा (η≪1)Training धीमी होगी
बहुत बड़ा (η≫1)Model सही direction में नहीं सीख पाएगा
संतुलित (η ठीक)Loss धीरे-धीरे कम होगा और model सटीक होगा

🔹 8. Gradient Descent के प्रकार

प्रकारविवरण
Batch Gradient Descentसभी डेटा से gradient निकालता है – धीमा पर सटीक
Stochastic GD (SGD)एक उदाहरण से gradient – तेज़ पर अशांत
Mini-batch GDकुछ उदाहरणों से gradient – तेजी और स्थिरता का संतुलन

🔹 9. Optimization Techniques (GD का उन्नत रूप)

📌 1. SGD (Stochastic Gradient Descent)

हर सैंपल पर वेट अपडेट – noisy पर तेज़

📌 2. Momentum

Gradient की दिशा में “गति” जोड़ता है – तेज़ और smooth convergence

📌 3. RMSProp

हर वेट के लिए learning rate adapt करता है – बेहतर stability

📌 4. Adam (Most Popular)

Momentum + RMSProp का मेल – कम समय में बेहतर परिणाम


💻 आवश्यक कोड (PyTorch में Optimizer का प्रयोग)

import torch
import torch.nn as nn
import torch.optim as optim

model = nn.Linear(1, 1) # एक सिंपल मॉडल
criterion = nn.MSELoss() # Loss function
optimizer = optim.SGD(model.parameters(), lr=0.01) # Optimizer

# Forward + Backward + Optimize
for epoch in range(10):
inputs = torch.tensor([[1.0]])
targets = torch.tensor([[2.0]])

outputs = model(inputs)
loss = criterion(outputs, targets)

optimizer.zero_grad()
loss.backward()
optimizer.step()

print(f"Epoch {epoch+1}, Loss: {loss.item():.4f}")

📌 Optimization Diagram (सैद्धांतिक)

Loss

│ ● ← Loss अधिक है
│ /
│ ●
│ /
│ ● ← Gradient Descent Steps
│/
●──────────── Weights

🎯 Chapter Objectives (लक्ष्य)

  • Gradient Descent का मूल सिद्धांत समझना
  • Loss को कम करने की प्रक्रिया जानना
  • विभिन्न Optimization Techniques को पहचानना
  • Learning Rate के प्रभाव को समझना

📝 अभ्यास प्रश्न (Practice Questions)

  1. Gradient Descent क्या है और Deep Learning में क्यों आवश्यक है?
  2. Learning Rate बहुत अधिक हो तो क्या दिक्कत हो सकती है?
  3. Momentum Optimizer किस concept पर आधारित है?
  4. Mini-batch Gradient Descent के क्या लाभ हैं?
  5. नीचे दिए गए कोड का उद्देश्य बताइए:

optimizer.zero_grad() loss.backward() optimizer.step()