torch.prod multiplies the per-token probabilities for a prompt into one joint sequence likelihood. Here it closes the scoring loop after softmax turns logits into next-token probabilities. section 5.4
The calculation indexes each position’s true next token, gathers its probability, then takes the product across the sequence. The result is used to compare candidate completions such as Berlin versus Bridge. section 5.4
Used to support token-level sequence scoring in this workflow:
- Aggregates those probabilities into a single sequence score. section 5.4
- Highlights why raw likelihoods can underflow on longer sequences. section 5.4
Prompt likelihood scoring
For "The capital of Germany is Berlin", the gathered next-token probabilities multiply to 5.9372e-08. For "The capital of Germany is Bridge", the product is 1.0481e-13, so the former scores higher under the model’s own distribution.
