LLM Evaluation Metrics Explained: From Architecture to Hallucination Rate
This article explains how to interpret large language model evaluation metrics in context. It covers total versus active parameters in mixture-of-experts models, long-context cost and effective utilization, multimodal token budgets, agent-task evaluation, hallucination-rate definitions and confidence intervals, and a practical framework for building and using custom evaluation scripts.
1. Put the Numbers Back into Context
When a model is released, it is common to publish a set of benchmark scores and metrics. These numbers are useful, but they can be misleading when viewed in isolation. Readers need to answer three questions: what capability is being measured, whether the test conditions are consistent, and whether the gap exceeds the error range of the evaluation itself. This article explains the principles behind these metrics and provides a reusable evaluation approach.
2. Mixture-of-Experts Architecture: Total and Active Parameters Must Be Considered Separately
Sparse Mixture of Experts (MoE) splits the feed-forward network into multiple expert sub-networks. A router selects a small number of experts for each token to participate in computation. As a result, the model can have a large total parameter count while activating only part of it during each forward pass.
This structure leads to two conclusions:
- Compute is approximately determined by active parameters, so the compute cost of a single inference is lower than that of a dense model with the same total parameter count.
- Memory usage is still determined by all weights. Deployment must accommodate the full set of parameters, or use model parallelism and weight offloading.
Routing also has a load-balancing problem. If most tokens are concentrated on a few experts, those experts become overloaded, and both training and inference efficiency decline. Engineering practice typically uses auxiliary losses or expert capacity limits to constrain the routing distribution.
The following is an estimation example for judging whether deployment is feasible:
def estimate_weight_memory_gb(total_params_b: float, bytes_per_param: float) -> float:"""Estimate weight memory usage in GB, excluding KV cache and activations."""return total_params_b * 1e9 * bytes_per_param / (1024 ** 3)# Example: assume 100 billion total parameters, stored with 16-bit and 4-bit quantizationprint(round(estimate_weight_memory_gb(100, 2), 1)) # approx. 186.3print(round(estimate_weight_memory_gb(100, 0.5), 1)) # approx. 46.6
3. Long Context: Larger Windows Change the Cost Profile
The context window determines how much information a model can process at once. Extending the window to the million-token scale does not mean that every position can be used equally well. Evaluation needs to focus on three things.
First is the KV cache. During decoding, the key-value vectors for every generated token must be stored in memory, and usage grows linearly with context length. The cache size for a single request can be roughly estimated as: layers × 2 × key-value heads × head dimension × context length × bytes per element.
Second is attention computation. Standard attention compute scales with the square of sequence length, so engineering practice commonly uses chunked computation, sparse attention, or sliding windows to reduce overhead.
Third is effective utilization. Information in the middle of long texts is often ignored, a phenomenon commonly called “lost in the middle.” Evaluation should include information-retrieval questions covering different positions rather than looking only at the window length parameter.
4. Native Multimodality: How Images Enter the Reasoning Pipeline
When text and images are provided together, the image is generally first converted by a vision encoder into a set of visual tokens, which are then concatenated with text tokens and passed into the same Transformer. Image resolution directly determines the number of visual tokens and therefore affects memory usage and response latency.
The following practices can be considered in engineering work:
- Choose resolution based on the task. Text-recognition tasks require higher resolution, while coarse classification can use lower resolution.
- Estimate the token budget for multi-image scenarios to avoid exceeding the context limit.
- Cross-check image information against textual descriptions to reduce misjudgments caused by reliance on a single modality.
5. Evaluating Agent Tasks: Terminal Operations and Web Retrieval
In recent years, evaluation focus has shifted from question answering to action. Terminal-operation tasks require the model to execute commands, read outputs, correct errors, and eventually reach a specified state in an isolated sandbox. Web-retrieval tasks require the model to search, open pages, integrate information across pages, and provide an answer.
Such evaluations need attention to the following points:
- Success criteria should be objective, preferably based on environment state or verifiable answers rather than human impressions.
- The same task should be run multiple times, with mean and variance reported. Single-run results can be highly random.
- Training-data contamination must be checked to confirm that test questions do not appear extensively in the training corpus.
- The evaluation scaffold should be recorded, including tool definitions, prompt templates, and retry strategies. The same model can perform noticeably differently under different scaffolds.
Therefore, a gap of less than one point between two models on a leaderboard is usually insufficient to determine which model is better suited to a specific business need.
6. Hallucination Rate: Definition, Statistics, and Confidence Intervals
Hallucination rate refers to the proportion of model outputs that contain assertions inconsistent with facts or reference materials. The definition must specify three things: whether the denominator is the number of answers or the number of assertions, whether the judgment is based on a standard answer, retrieved evidence, or human annotation, and how refusals are counted.
For example, with 500 samples and a hallucination rate of 8.3%, the standard error under a binomial distribution is approximately √(0.083 × 0.917 / 500), or about 1.2 percentage points. The 95% confidence interval is approximately plus or minus 2.4 percentage points. When the sample size is small, a decrease of a few percentage points may not be stable. When comparing two versions, use the same sample set and apply a paired test or bootstrap method to estimate the interval of the difference.
Common approaches to reducing hallucination include:
- Retrieval-augmented generation, so that answers rely on citable materials.
- Requiring the model to provide evidence and perform self-checking.
- Explicitly outputting “cannot determine” when uncertain rather than fabricating an answer.
- Adding samples and reward signals related to factuality and refusal during post-training.
7. Building Your Own Evaluation Script
The following example shows how to calculate hallucination rate from annotated results and use bootstrapping to compute a confidence interval.
import randomdef hallucination_rate(labels: list[bool]) -> float:"""True in labels means the answer contains a hallucination."""return sum(labels) / len(labels)def bootstrap_ci(labels: list[bool], n_boot: int = 2000, alpha: float = 0.05):n = len(labels)rates = []for _ in range(n_boot):sample = [random.choice(labels) for _ in range(n)]rates.append(hallucination_rate(sample))rates.sort()low = rates[int(n_boot * alpha / 2)]high = rates[int(n_boot * (1 - alpha / 2))]return low, high# Example data for demonstrating the workflow onlylabels = [True] * 40 + [False] * 460rate = hallucination_rate(labels)low, high = bootstrap_ci(labels)print(f"Hallucination rate {rate:.1%}, 95% CI [{low:.1%}, {high:.1%}]")
8. A Practical Framework for Model Selection and Deployment
- Clarify the business task type, such as code generation, document question answering, visual understanding, or multi-step operations.
- Build a small evaluation set from your own data, covering the real input distribution and edge cases.
- Fix evaluation conditions, including prompt templates, sampling parameters, tool configuration, and retry counts.
- Evaluate quality, latency, unit cost, and stability together rather than relying on a single leaderboard.
- Monitor continuously after launch and feed online failure samples back into the evaluation set to form a closed loop.
9. Summary
The key to reading model metrics is to restore the numbers to specific capabilities, test conditions, and error ranges. For mixture-of-experts architectures, distinguish total parameters from active parameters. For long context, consider both cache overhead and effective utilization. For multimodality, pay attention to visual token budgets. For agent evaluation, use verifiable success criteria. For hallucination rate, always include the definition and confidence interval. With these principles, it becomes possible to make more reliable judgments across multiple evaluation reports.
