Skip to content
BIASED

Stable softmax

Self-study exercise. Checking on the site is not available yet. Write and download a solution to work on your computer.

Finish softmax(z). For a length-KK vector return probabilities along the last axis; for a (batch, classes) matrix, along axis=1 (each row a distribution).

Subtract the max along that axis before exp, or large logits yield inf/nan. Use NumPy.

PyTorch and automatic differentiation