Artefactual#
Artefactual assigns a language model’s answer a probability of being a hallucination. It reads the answer that has already been generated, together with the token probabilities returned alongside it, and needs nothing else from the model.
pip install artefactual
from artefactual import WEPR, LogProbParser
K = 15 # the k the published detectors were trained with
# response: the result of an OpenAI-compatible call made with logprobs=True and top_logprobs
logprobs = LogProbParser(k=K).transform(response)
detector = WEPR.from_pretrained("artefactory/wepr-ministral")
detector.predict_proba(logprobs)[:, 1] # P(hallucination) per sequence
Two answers from the same model, scored by the same detector:
The model was asked |
It answered |
P(hallucination) |
|---|---|---|
What is the capital city of France? |
Paris. |
0.08 |
Who is Charles Moslonka? Where was he born? |
Charles Moslonka is a French singer born in Lyon in 1985. |
0.99 |
Neither answer was checked against anything. The second scores high because the model was uncertain while generating it. Both numbers are the ones Score responses with WEPR prints, and it also marks which tokens drove them.
A response here is the result of a call to an OpenAI-compatible API (chat completions,
Responses API or batch output) made with logprobs and top_logprobs.
The project README covers the requirements and the published results. This site covers installing and using a detector in depth.
Installation — installing from PyPI or from source
Using a detector — choosing a detector, thresholds, batches, Langfuse traces
Training a detector — fitting one for a model with no published weights, in three notebooks
How it works — the three pipeline stages and the two entropy poolings
Reference — candidates and ranks, weight-file layout, accepted inputs
scikit-learn compatibility — scikit-learn compatibility, model selection, feature names, persistence
Examples — runnable notebooks: EPR and WEPR scoring, and Langfuse traces
API reference — generated signatures
Changelog — what changed in each release