Today, while experimenting with open-source models for Telugu language processing as part of my voice agent work, I ended up training a simple MLP.
Initially, I had just one hidden layer and an output layer, without any activation function in between.
I was using a relatively high learning rate and started observing exploding gradients.
I decided to introduce tanh in the hidden layer. Interestingly, the training ran without the gradient explosion I had observed earlier.
But that wasn't the end of it. I wanted to understand WHY.
A little digging into the mathematics revealed something interesting.
The derivative of tanh is:
1 - tanh(x)^2
As the activation approaches -1 or 1, its derivative approaches zero.
This means that when neurons saturate, gradients flowing through them become extremely small, resulting in very small weight updates.
So, while tanh bounded my hidden-layer activations and reduced gradient magnitudes in this experiment, it also introduced the possibility of vanishing gradients.
An unexpected trade-off!
One thing I initially thought would simply fix my training problem ended up teaching me something more interesting about activation functions and gradient propagation.
Sometimes, the best learning happens when you stop after hitting Run and start asking WHY.
Try looking at the notebook, it will be fun: https://t.co/FRj4gOYbVI
#MachineLearning #DeepLearning #NeuralNetworks #MLP
Built a Transformer from scratch in PyTorch! ๐
Implemented:
Multi-head attention
Positional encoding
Encoder-decoder architecture
Masking & cross-attention
Training loop and greedy decoding
Then trained it for English โ Italian translation.
The best way to understand an architecture is to build it.
๐ https://t.co/VQO2T0wm7s
#DeepLearning #PyTorch
We played with you @nAts__ss, bro, for 3 years, we went through ups and downs together, unfortunately we went our separate ways, but you will always be my brother๐
It's Friday and these people arranged meeting for half an hour and continuing it for 2 more hours and it will take atleast one more hour to complete the tasks . God please me out of here ๐ซ