Log-softmax, logsumexp trick
Easy FundamentalsImplement cross-entropy loss from scratch.
• Do NOT use F.cross_entropy or nn.CrossEntropyLoss
• Must be numerically stable (use logsumexp trick)
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("cross_entropy")
Log-softmax, logsumexp trick