🧠 Neural Networks Basics (Perceptron, MLP)
Neural Networks आधुनिक Deep Learning का आधार हैं। यह इंसानी दिमाग के neuron system से inspired हैं। इस blog में हम step-by-step देखेंगे कि Perceptron और Multi-Layer Perceptron (MLP) कैसे काम करते हैं, उनकी आवश्यकता क्यों है और practical examples में कैसे use किया जाता है।
📌 Neural Network क्या है?
Neural Network एक computational मॉडल है जिसमें कई artificial neurons होते हैं। हर neuron input लेता है, उस पर weights और bias apply करता है, फिर एक activation function के जरिए output देता है। कई neurons मिलकर एक layer बनाते हैं और कई layers मिलकर एक deep neural network बनाते हैं।
🔑 Perceptron
Perceptron Neural Network का सबसे basic unit है जिसे Frank Rosenblatt ने 1958 में introduce किया था। इसका काम है: input values लेना → उन्हें weight और bias के साथ process करना → फिर activation function लगाकर decision देना। इसे आप simple binary classifier की तरह समझ सकते हैं।
y = f( Σ(wi * xi) + b )
- xi: input features
- wi: weights
- b: bias
- f: activation function (step, sigmoid, relu)
💡 Example: AND Gate using Perceptron
import numpy as np
def AND_gate(x1, x2):
weights = np.array([0.5, 0.5])
bias = -0.7
x = np.array([x1, x2])
linear_output = np.dot(weights, x) + bias
return 1 if linear_output > 0 else 0
print(AND_gate(0,0))
print(AND_gate(0,1))
print(AND_gate(1,0))
print(AND_gate(1,1))
🧮 Multi-Layer Perceptron (MLP)
जब perceptron को multiple hidden layers में arrange किया जाता है, तो उसे Multi-Layer Perceptron कहते हैं। MLP complex non-linear problems को solve कर सकता है, जैसे image recognition, NLP, speech processing आदि।
- Input Layer: features को input करता है
- Hidden Layers: complex feature transformations
- Output Layer: prediction देता है
📐 Mathematical Intuition
हर layer का काम है inputs का linear combination बनाना और फिर non-linear activation function apply करना। Backpropagation algorithm के जरिए network अपने weights को optimize करता है।
a = f(Wx + b)
🖥️ Python Example (MLPClassifier)
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
digits = load_digits()
X_train, X_test, y_train, y_test = train_test_split(
digits.data, digits.target, test_size=0.3, random_state=42
)
mlp = MLPClassifier(hidden_layer_sizes=(64, 32), max_iter=500)
mlp.fit(X_train, y_train)
y_pred = mlp.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
🌍 Applications of Perceptron & MLP
- 🖼️ Image Classification (MNIST, CIFAR)
- 📜 Natural Language Processing
- 🎙️ Speech Recognition
- 📊 Stock Price Prediction
- 🤖 Robotics Control
✅ Pros & ❌ Cons
Advantages:
- Simple and intuitive
- Foundation of deep learning
- Capable of learning non-linear problems (MLP)
Limitations:
- Perceptron cannot solve XOR problem alone
- Training requires high computation
- Overfitting possible on small data
🏆 निष्कर्ष
Perceptron और MLP Deep Learning की foundation हैं। Perceptron basic decision making unit है जबकि MLP complex patterns को identify कर सकता है। आगे आने वाले blogs में हम Activation Functions और Backpropagation सीखेंगे, जो Neural Networks को और powerful बनाते हैं। Neural Networks की समझ हर Data Scientist और AI Engineer के लिए अनिवार्य है।