LLM Language Quality Metrics: Perplexity, BLEU, ROUGE & BERTScore Deep Dive
Automated measurement of fluency, n-gram precision, recall in summarization, and neural semantic similarity without human raters.
⚡ Executive Summary
How do we automatically measure LLM response quality? Explore probability perplexity, exact string overlap (BLEU/ROUGE), and BERTScore semantic alignment.
Key Takeaways
- ✓Perplexity — covered in depth with practical examples, formulas, and code.
- ✓BLEU (Bilingual Evaluation Understudy) — covered in depth with practical examples, formulas, and code.
- ✓ROUGE (Recall-Oriented Understudy for Gisting Evaluation) — covered in depth with practical examples, formulas, and code.
LLM Evaluation Metrics — Language Quality
LLM Language Quality
├── Perplexity → Next-token probability surprise
├── BLEU → N-gram precision & Brevity penalty
├── ROUGE → N-gram recall & Longest Common Subsequence
└── BERTScore → Contextual embedding cosine similarity#1. Perplexity
Definition: How "surprised" a language model is by a sequence of text.
import torch
import torch.nn.functional as F
def perplexity(logits, target_ids):
log_probs = F.log_softmax(logits, dim=-1)
token_log_probs = log_probs.gather(1, target_ids.unsqueeze(1)).squeeze(1)
return torch.exp(-token_log_probs.mean())#2. BLEU (Bilingual Evaluation Understudy)
Measures n-gram precision with brevity penalty:
Precision-oriented, penalizes extra words. Weak for open-ended chat where paraphrasing is common.
#3. ROUGE (Recall-Oriented Understudy for Gisting Evaluation)
Counterpart to BLEU, recall-oriented for summarization:
#4. BERTScore
Embeds candidate and reference using pretrained models (e.g. BERT/DeBERTa) and calculates semantic similarity via cosine distance.
Surya N
Full Stack Developer
Surya N is part of the Junglans Solutions engineering team, specializing in llm evaluation & benchmarking. Junglans builds a 20-product ecosystem of local-first enterprise software — AI developer tools, encrypted communication, and data infrastructure with zero cloud telemetry.
Meet the full Junglans engineering team ↗This article is part of the Junglans Research knowledge base, produced alongside the engineering teams that build our production AI tools. Explore related product documentation and research:
- Junglans ML Visualizer ↗
Interactive 22-algorithm machine learning sandbox — see the concepts in action.
- JunglasNCode ↗
Line-by-line code execution and call stack visualizer for algorithm practice.
- All Junglans Research Articles ↗
More engineering and AI deep-dives from the Junglans team.
Related Research & Articles
Modern LLM Reasoning Evaluation: LLM-as-a-Judge, G-Eval, Correctness & Hallucinations
Discover how top AI labs replace human raters with LLM-as-a-Judge frameworks like G-Eval, evaluating correctness, relevance, and hallucination rates.
RAG Evaluation Frameworks & LLM Serving Metrics: TTFT, Throughput, Latency & VRAM Sizing
A practical operational guide covering RAG metrics (Context Precision, Recall, Groundedness) and physical serving metrics (TTFT, VRAM sizing, Throughput).
LLM Inference Hyperparameters: Temperature, Top-P Nucleus, Top-K, Repetition Penalty & Context Windows
Master decoding parameters: Temperature logits scaling, Top-P nucleus sampling, Top-K truncation, Repetition Penalties, and system prompt engineering.