Installation | Basic usage | Overview | Benchmark | Demo application | Documentation
LM-Polygraph provides a battery of state-of-the-art uncertainty estimation (UE) methods for LLMs in text generation tasks. High uncertainty can indicate the presence of hallucinations and knowing a score that estimates uncertainty can help to make applications of LLMs safer.
LM-Polygraph is also one of the most widely used benchmarks for the consistent evaluation of uncertainty estimation and hallucination detection methods. It is adopted by hundreds of researchers and technology companies.
The latest stable version is available in the main branch, it is recommended to use a virtual environment:
python -m venv env # Substitute this with your virtual environment creation command
source env/bin/activate
pip install git+https://github.com/IINemo/lm-polygraph.git
You can also use tags:
pip install git+https://github.com/IINemo/lm-polygraph.git@v0.5.0
The latest tagged version is also available via PyPI:
pip install lm-polygraph
Some features require additional packages that are not installed by default:
unbabel-comet pins numpy<2.0 which may conflict with packages like vLLM. Install via extras:
shell
pip install lm-polygraph[comet]
If you need numpy 2.x (e.g., for vLLM), install without the extra and add comet manually:
shell
pip install lm-polygraph
pip install unbabel-comet --no-depsfrom transformers import AutoModelForCausalLM, AutoTokenizer
from lm_polygraph.utils.model import WhiteboxModel
model_path = "Qwen/Qwen2.5-0.5B-Instruct"
base_model = AutoModelForCausalLM.from_pretrained(model_path, device_map="cuda:0")
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = WhiteboxModel(base_model, tokenizer, model_path=model_path)
from lm_polygraph.estimators import *
ue_method = MeanTokenEntropy()
from lm_polygraph.utils import estimate_uncertainty
input_text = "Who is George Bush?"
ue = estimate_uncertainty(model, ue_method, input_text=input_text)
print(ue)
# UncertaintyOutput(uncertainty=-6.504108926902215, input_text='Who is George Bush?', generation_text=' President of the United States', model_path='Qwen/Qwen2.5-0.5B-Instruct')
LM-Polygraph can work with any OpenAI-compatible API services:
from lm_polygraph import BlackboxModel
from lm_polygraph.estimators import Perplexity, MaximumSequenceProbability
model = BlackboxModel.from_openai(
openai_api_key='YOUR_API_KEY',
model_path='gpt-4o',
supports_logprobs=True # Enable for deployments
)
ue_method = Perplexity() # or MeanTokenEntropy(), EigValLaplacian(), etc.
estimate_uncertainty(model, ue_method, input_text='What has a head and a tail but no body?')
UE methods such as EigValLaplacian() support fully blackbox LLMs that do not provide logits.
| Uncertainty Estimation Method | Type | Category | Compute | Memory | Need Training Data? | Level |
|---|---|---|---|---|---|---|
| Maximum sequence probability | White-box | Information-based | Low | Low | No | sequence/claim |
| Perplexity (Fomicheva et al., 2020a) | White-box | Information-based | Low | Low | No | sequence/claim |
| Mean/max token entropy (Fomicheva et al., 2020a) | White-box | Information-based | Low | Low | No | sequence/claim |
| Monte Carlo sequence entropy (Kuhn et al., 2023) | White-box | Information-based | High | Low | No | sequence |
| Pointwise mutual information (PMI) (Takayama and Arase, 2019) | White-box | Information-based | Medium | Low | No | sequence/claim |
| Conditional PMI (van der Poel et al., 2022) | White-box | Information-based | Medium | Medium | No | sequence |
| Rényi divergence (Darrin et al., 2023) | White-box | Information-based | Low | Low | No | sequence |
| Fisher-Rao distance (Darrin et al., 2023) | White-box | Information-based | Low | Low | No | sequence |
| Attention Score (Sriramanan et al., 2024) | White-box | Information-based | Medium | Low | No | sequence/claim |
| Contextualized Sequence Likelihood (CSL) (Lin et al., 2024) | White-box | Information-based | Medium | Low | No | sequence |
| Recurrent Attention-based Uncertainty Quantification (RAUQ) (Vazhentsev et al., 2025) | White-box | Information-based | Low | Low | No | sequence |
| Focus (Zhang et al., 2023) | White-box | Information-based | Medium | Low | No | sequence/claim |
| BoostedProb (Dinh et al., 2025) | White-box | Information-based | Low | Low | No | sequence/claim |
| Semantic entropy (Kuhn et al., 2023) | White-box | Meaning diversity | High | Low | No | sequence |
| Claim-Conditioned Probability (Fadeeva et al., 2024) | White-box | Meaning diversity | Low | Low | No | sequence/claim |
| FrequencyScoring (Mohri et al., 2024) | White-box | Meaning diversity | High | Low | No | claim |
| TokenSAR (Duan et al., 2023) | White-box | Meaning diversity | High | Low | No | sequence/claim |
| SentenceSAR [(Duan et al., 2023)](https://arxiv.org/abs/23 |
$ claude mcp add lm-polygraph \
-- python -m otcore.mcp_server <graph>