Activation Functions
Activation function क्या है
Activation function neural network में neuron के output को तय करता है। यह neuron का input लेकर बदलता है, non-linearity जोड़कर ताकि network complex patterns सीख सके। आम हैं Sigmoid, Tanh, ReLU और Softmax — हर एक का अलग आकार और इस्तेमाल।
इनकी ज़रूरत क्यों
Activation function बिना, हर layer बस एक linear equation होती, और कई linear layers stack करना फिर भी एक linear result देता। वो असली, curvy patterns कभी model नहीं कर पाता। Activation functions output को मोड़ते हैं, तो कई layers साथ मिलकर rich, complex relationships सीख सकती हैं। यही deep learning को शक्तिशाली बनाता है।
Sigmoid
किसी भी input को 0 और 1 के बीच value में दबा देता है।
- Range: 0 से 1।
- किसके लिए बढ़िया: binary (हाँ/ना) समस्याओं की output layer।
- कमज़ोरी: deep networks में vanishing gradient problem कर सकता है।
Tanh
Sigmoid जैसा पर -1 और 1 के बीच output देता है।
- Range: -1 से 1 (0 पर केंद्रित)।
- किसके लिए बढ़िया: hidden layers जहाँ केंद्रित output मदद करे।
- कमज़ोरी: बहुत deep networks में अब भी vanishing gradients झेलता है।
ReLU
सबसे लोकप्रिय विकल्प — input positive हो तो उसे, वरना 0 output करता है।
def relu(x):
return max(0, x)
print(relu(5)) # 5
print(relu(-3)) # 0
0
ReLU सरल और तेज़ है, और vanishing gradient problem से काफ़ी बचता है, तो यह ज़्यादातर आधुनिक networks की hidden layers में default है।
Softmax
numbers की list को ऐसी probabilities में बदलता है जो जुड़कर 1 होती हैं।
- Output: probabilities का set (हर एक 0 से 1, जोड़ 1)।
- किसके लिए बढ़िया: multi-class समस्याओं की output layer (जैसे 10 categories में classify)।
- विचार: सबसे बड़े input को सबसे ऊँची probability मिलती है।
कौन-सा इस्तेमाल करें
| Function | Range | आम इस्तेमाल |
|---|---|---|
| ReLU | 0 से ∞ | Hidden layers (default) |
| Sigmoid | 0 से 1 | Binary output |
| Tanh | -1 से 1 | कुछ hidden layers |
| Softmax | 0 से 1 (जोड़ 1) | Multi-class output |
आम भ्रम
- हर जगह Sigmoid इस्तेमाल करना। hidden layers में ReLU बेहतर; Sigmoid मुख्यतः binary output को।
- यह भूलना कि non-linearity मायने रखती है। Activations बिना, extra layers कुछ नहीं जोड़तीं।
- Softmax बनाम Sigmoid confusion। एक हाँ/ना output को Sigmoid; कई classes में से चुनने को Softmax।
- Vanishing gradients अनदेखा करना। Deep Sigmoid/Tanh networks बहुत धीरे train हो सकते हैं — ReLU मदद करता है।
सारांश
- Activation functions non-linearity जोड़ते हैं ताकि networks complex patterns सीखें।
- ReLU hidden layers के लिए तेज़, लोकप्रिय default है।
- Sigmoid (0-1) binary output को; Tanh (-1 से 1) कुछ hidden layers को।
- Softmax multi-class output के लिए class probabilities देता है।
- Activations बिना, deep layers एक linear layer जैसा व्यवहार करती हैं।
आगे, model quality सीखिए overfitting और underfitting में, या architectures तुलना कीजिए CNN बनाम RNN में।
