02. PyTorch Neural Network Classification - sigmoid not working for the problem? #1331
|
Using ReLU as activation function works for the problem, if I replace it with sigmoid, the model doesn't seem to be able to learn. I am using the exact same layers and number of neurons. The class is defined as the following: Sigmoid function should be sufficient to train the model, as I tested it on the tensorflow playground website. tAnyone knows why it's not working? |
Replies: 1 comment 1 reply
|
The issue you're experiencing is a classic case of the vanishing gradient problem. Why did it work on TensorFlow Playground? What you can do to make sigmoid work:
|
The issue you're experiencing is a classic case of the vanishing gradient problem.
When you use sigmoid as a hidden layer activation, it squashes all values into a narrow range (0, 1). During backpropagation, gradients are multiplied at each layer - and since sigmoid derivatives max out at 0.25, after just 2–3 layers those gradients become extremely small. The weights barely update, and the model appears stuck.
ReLU avoids this because its gradient is simply 1 for any positive input - it passes the signal through without squashing it.
Why did it work on TensorFlow Playground?
The Playground uses very clean, well-scaled 2D data and a relatively forgiving optimizer setup. It masks the vanis…