Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Squashing any number into a probability
The sigmoid takes any number, however large or small, and squashes it smoothly into the range from 0 to 1: very negative inputs give nearly 0, very positive ones nearly 1, and 0 gives exactly ½. That makes it the natural way to turn a score into a probability (“how likely is this a fault?”), and a soft switch for gates inside networks.
Every binary classifier, from an anomaly detector to a landing go/no-go model, ends in a sigmoid or its relative, softmax. LSTM gates, attention gates and SiLU all build on it. Implemented naively, it overflows or produces log(0) exactly when a model is confidently wrong, which is when the training signal matters most.
- 1. σ(0) =
- 2. The sigmoid's outputs lie in…
- 3. Today the sigmoid is mainly used…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Properties by hand
- Definition: σ(z) = 1/(1 + e^(−z)).
- Symmetry: σ(−z) = 1 − σ(z).
- Derivative: σ′(z) = σ(z)(1 − σ(z)). It needs only the stored output, and it is largest at z = 0, where it equals 1/4. At outputs 0.9 and 0.99 the slope has fallen to 0.09 and 0.0099: the unit saturates.
- Inverse: the logit, z = log(p/(1 − p)). logit(0.75) = ln 3, odds of 3 to 1.
- Relation to tanh: tanh(z) = 2σ(2z) − 1, the same S-shape stretched to (−1, 1), with slope 1 at 0.
Stable computation.
- 1/(1 + e^(−z)) overflows for z = −800, because e⁸⁰⁰ is infinite. Use e^(−|z|) and branch on the sign.
- log σ(z) = min(z, 0) − log(1 + e^(−|z|)).
- Binary cross-entropy from a logit z and label y: max(z, 0) − zy + log(1 + e^(−|z|)). A confident wrong logit of −1000 for y = 1 then costs exactly 1000, not NaN.
- 1. σ′(z) can be written as…
- 2. σ(−2) equals…
- 3. Why compute BCE from logits?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Where the naive formulas break
Exercise 1. The stable implementation returned finite values everywhere: σ(−800) = 0 and log σ(−800) = −800 exactly. The naive log(1/(1 + e⁸⁰⁰)) gave −∞, the infinite loss (and NaN gradient) a confidently wrong prediction would produce in training. The identities σ(−z) = 1 − σ(z), max σ′ = 1/4 and σ(logit(p)) = p were verified numerically.
Where the sigmoid is still the right choice.
- Binary or multi-label outputs: one sigmoid per label, trained with binary cross-entropy. Each label is an independent yes/no.
- Gates: LSTM and GRU gates, squeeze-and-excitation (E7-10) and gated attention use σ to make a soft 0–1 switch.
- Smooth building block: SiLU is z·σ(z) (E1-9).
Why it lost the hidden layers.
- Its maximum slope is 1/4, so gradients shrink at every layer (E0-6).
- It saturates: for |z| ≳ 5 the slope is below 0.007.
- Its outputs are all positive, so the gradients of each unit’s incoming weights all share one sign (LeCun et al., 1998).
torch.sigmoid(z); torch.nn.functional.logsigmoid(z)
torch.nn.BCEWithLogitsLoss()(logits, targets) # never sigmoid + BCELoss on raw probabilities- 1. For multi-label classification you use…
- 2. For |z| ≈ 5 the sigmoid's slope is about…
- 3. In PyTorch, binary classification losses should use…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Probabilistic origin.
- For two classes with Gaussian class-conditionals and a shared covariance, the posterior P(y = 1 | x) = σ(wᵀx + b) exactly. This is the link between LDA and logistic regression.
- More generally, σ of the log-odds is the posterior.
- The sigmoid is also the canonical link of the Bernoulli distribution in generalised linear models.
Learning dynamics. For a unit h = σ(wᵀx), the weight gradient is δ·σ′·x.
- Since every h in the previous layer is positive, each unit’s incoming weight gradients share δ’s sign. Updates are therefore confined to two orthants, which causes zig-zagging (LeCun et al., 1998).
- The small, saturating slope shrinks δ by at least 4 per layer.
- Exercise 2 separates these two effects.
Saturation and initialisation. If pre-activations are large, units saturate and stop learning. Glorot and Bengio (2010) observed that sigmoid networks push top-layer units into saturation early in training.
Interview questions.
- Why is tanh usually preferred to sigmoid in hidden layers? It is zero-centred with slope 1 at 0, four times the sigmoid’s, so gradients propagate better.
- Why combine sigmoid and BCE into one function? The combined gradient is simply σ(z) − y, and it can be computed stably from the logit.
- 1. With Gaussian classes sharing a covariance, the posterior is…
- 2. The gradient of BCE with respect to the logit is…
- 3. The sigmoid is the canonical link of the…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Is it the mean or the slope?
History.
- P.-F. Verhulst (1838) introduced the logistic curve for population growth.
- D. Cox (1958) introduced logistic regression.
- D. Rumelhart, G. Hinton and R. Williams (1986) used sigmoid units for backpropagation.
- Y. LeCun et al. (1998) recommended zero-centred, steeper activations (“Efficient BackProp”).
- X. Glorot and Y. Bengio (2010) studied sigmoid saturation.
Exercise 2. A two-hidden-layer network (width 24) on spirals (300 points) with full-batch gradient descent for 400 steps; mean final training loss over 2 seeds. Four hidden activations separate the two suspected causes: a non-zero mean and a small slope.
| hidden activation | output mean at 0 | slope at 0 | final loss, lr 0.3 | final loss, lr 3.0 |
|---|---|---|---|---|
| sigmoid | 0.5 | 1/4 | 0.654 | 0.044 |
| sigmoid − 0.5 | 0 | 1/4 | 0.662 | 0.025 |
| 2·sigmoid − 1 (= tanh(z/2)) | 0 | 1/2 | 0.387 | 0.005 |
| tanh | 0 | 1 | 0.020 | 0.001 |
- At learning rate 0.3, centring the sigmoid changed almost nothing (0.654 against 0.662). Doubling its slope helped a lot (0.387), and tanh, with four times the slope, trained easily (0.020). In this test the small slope was the main problem, not the non-zero mean.
- With a 10× larger learning rate, the plain sigmoid trained well (0.044). A larger step partly compensates for the small slope. Here centring did help somewhat (0.025), so the mean matters as a second-order effect.
- Lesson: “use tanh, not sigmoid” is mostly about gradient scale, which interacts with the learning rate. Compare activations at a tuned learning rate before drawing conclusions.
The sigmoid in AI, robotics and aerospace
- Probabilistic outputs: fault-or-nominal classifiers and detection confidence scores. Calibrate them before use in decision logic (d0 calibration).
- Gated recurrent models: LSTM and GRU gates in telemetry forecasting and trajectory prediction.
- Soft constraints: sigmoids map unconstrained network outputs to bounded physical quantities, such as valve openings or throttle settings between 0 and 1.
References
- D. R. Cox (1958). “The regression analysis of binary sequences.” JRSS B 20(2).
- Y. LeCun, L. Bottou, G. Orr, K.-R. Müller (1998). “Efficient BackProp.” In Neural Networks: Tricks of the Trade.
- X. Glorot, Y. Bengio (2010). “Understanding the difficulty of training deep feedforward neural networks.” Proc. AISTATS.
- C. M. Bishop (2006). Pattern Recognition and Machine Learning, sections 4.2–4.3. Springer.