# The perplexity is e^(average NLL). sentence_perplexity = (probs.log() * -1.0).mean().exp().item() print(f"Sentence Perplexity: {sentence_perplexity:.2f}")