Numerical stability, exp/log tricks
Easy FundamentalsImplement the Softmax function from scratch.
• Do NOT use torch.softmax, F.softmax, or torch.nn.Softmax
• Must be numerically stable (hint: subtract max before exp)
Implement the function below. Use only basic PyTorch operations.
Use this code to debug before submitting.
Try solving it yourself first! Click below to reveal the solution.
For interactive practice with auto-grading, run TorchCode locally:pip install torch-judge then use check("softmax")
Numerical stability, exp/log tricks