torch.log_softmax converts logits into log probabilities in one optimized step. It is used where token scores need to stay comparable while avoiding the extra work of chaining softmax and log. section 5.5 section 7.3.2
It preserves ranking: larger logits still become higher probabilities and less negative log probabilities. For scoring next tokens, that makes the best candidate the least negative log-probability. section 5.5 section 7.3.2
Used here to support probability-based scoring and training diagnostics:
- computes per-token log probabilities from model logits section 5.5
- supports next-token and sequence log-probability sums section 5.5
- feeds entropy calculations over vocabulary distributions section 7.3.2
Next-token scoring
A prompt like “The capital of Germany is Berlin” is scored by taking model logits, applying torch.log_softmax, selecting the log probability for each observed next token, and summing them; an implausible token like “Bridge” produces a much lower total. section 5.5 section 7.3.2
