A Practical Guide to Consistency Evaluation for LLM Text Analysis
This guide explains why output consistency is a prerequisite for trustworthy LLM analysis in high-risk settings, and how to measure it with independent multi-model runs, Cohen’s kappa, and semantic similarity. It covers experimental design, complementary metrics, engineering practices, and human-in-the-loop review.
1. Background: why consistency is a prerequisite for trustworthy AI
In high-risk settings such as psychotherapy, clinical intake, and content moderation, teams increasingly rely on large language models to structure interviews and conversational transcripts. A single run is often noisy: the same model on the same material may produce different wording or even conflicting conclusions. Without evidence that results are stable, automated findings are hard for practitioners and business stakeholders to accept.
The core evaluation question is therefore not whether one model “got it right,” but whether multiple models and independent analyses agree enough. High consistency indicates robust, reproducible conclusions; low consistency signals the need for human review or better prompts and workflows. This article uses repeated multi-model analysis of a psychotherapy interview as a thread, and abstracts a general reliability-evaluation method.
2. Experiment design: turn the process into measurable steps
A rigorous consistency experiment can be split into three parts.
Step 1: Parallel independent analysis. Choose several LLMs of comparable capability. Each analyzes the same interview record in isolation so they cannot influence one another.
Step 2: Repeated sampling. Run each model independently on the same material multiple times (for example, six). The goal is to observe the model’s own variance. This matters because LLM output is stochastic; one sample does not represent its typical behavior.
Step 3: Two-dimensional checks. Use two independent “rulers”: one for whether models agree on labels, and another for whether meaning stays close even when wording differs. Together they cover both label agreement and semantic agreement.
Skeleton for repeated sampling and collection:
models = ["model_a", "model_b", "model_c"]records = ["interview_01"] # same interview recordruns = 6results = {m: [] for m in models}for m in models:for _ in range(runs):label = analyze(m, records[0]) # structured label, e.g. anxiety / depression / normalresults[m].append(label)
3. Metric 1: Cohen’s kappa
Cohen’s kappa is a classic statistic for agreement between two raters on categorical labels. Its value is that it subtracts agreement expected by chance. If two models both prefer a frequent label, raw agreement can look high even without real consensus; kappa corrects that inflation.
Computation in brief: (observed agreement − expected agreement) / (1 − expected agreement). Values typically range from −1 to 1: near 1 means strong agreement after chance correction; near 0 is chance-level; negative values indicate systematic disagreement.
In practice, compute pairwise kappa to form an agreement matrix and locate the largest disagreements. Example:
from sklearn.metrics import cohen_kappa_score# label agreement between two models across repeated runskappa = cohen_kappa_score(results["model_a"], results["model_b"])print(f"Cohen's Kappa = {kappa:.3f}")
Kappa is for discrete labels (classification). For continuous scores or ordinal ratings, use weighted kappa or intra-class correlation instead.
4. Metric 2: semantic similarity
Category labels discard a lot of information. When models produce free-text conclusions, two answers may use different words but mean nearly the same thing. Semantic similarity maps each conclusion to a high-dimensional vector, then uses cosine similarity for a continuous score between 0 and 1.
The strength is robustness to wording; the limitation is that it does not subtract a chance baseline the way kappa does. The two metrics are complementary: kappa for stability of discrete judgments, semantic similarity for alignment of free-form meaning.
import numpy as npdef cosine_similarity(a, b):a, b = np.array(a), np.array(b)return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b)))# vec is the text embeddingsim = cosine_similarity(vec_a, vec_b)
5. Engineering recommendations
- Control sources of randomness: Where allowed, lower sampling temperature and fix random seeds so evaluation focuses on real disagreement, not extra jitter.
- Prefer structure: Have models emit enumerated labels rather than long prose so kappa can be applied strictly, with semantic similarity as a complement.
- Set agreement thresholds: Define a minimum acceptable consistency for the business risk; below it, trigger human review.
- Productize the pipeline: Automate repeated sampling, dual metrics, and visualization. Object storage can keep raw records; a message queue can decouple sampling jobs; logging and alerting can track consistency drift.
- Human fallback: In high-risk domains, model output should assist rather than decide; consistency data supports when people should step in.
6. Summary
Evaluating LLM text analysis is less about whether a single output “looks right” and more about whether multi-model, multi-run independent analyses stay consistent. Collect data with parallel independent sampling, measure discrete robustness with Cohen’s kappa, and measure free-text meaning with semantic similarity. Together they form a reproducible, quantitative reliability stack. With general engineering capabilities on platforms such as Baidu AI Cloud, the method can be automated and scaled to support trustworthy AI in high-risk scenarios.
