SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2303.08896 · EMNLP · 2023

SELFCHECKGPT: Zero-Resource Black-Box Hallucination Detection for Generative Large Language Models

Mark Gales, Adian Liusie, Potsawee Manakul

arXiv · PDF · Open in the Atlas

Code that ran

6 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 3 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 5 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2303.08896.json · badge: /api/ran/2303.08896.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
potsawee/selfcheckgpt marked official in Papers with Code
Papers with Code archive
6 ran · 5 no recorded run
FunctionStatusWhere it lives
method_bayes_with_alpha Ran
ran; our contract draft was wrong, not the code
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("48303d9614eef740")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Analyze the function to understand what arguments are needed:
# - prob: used with np.argmax() -> numpy array
# - u_score: appears to be set but not used in the function body
# - prob_s: list/array of prob-like objects, indexed by s in range(num_samples)
# - u_score_s: list/array of scores, indexed by s, used in arithmetic
# - num_samples: integer, used in range()
# - beta1: float, used in arithmetic
# - beta2: float, used in arithmetic

# Create small valid arguments
np.random.seed(0)

# prob: a probability array (e.g., 4 classes)
prob = np.array([0.1, 0.5, 0.3, 0.1])

# u_score: a score value (not actually used in function, but required parameter)
u_score = 0.8

# num_samples: number of samples to iterate over
num_samples = 3

# prob_s: list of probability arrays for each sample
prob_s = [
    np.array([0.2, 0.3, 0.4, 0.1]),  # sample 0
    np.array([0.5, 0.2, 0.2, 0.1]),  # sample 1
    np.array([0.1, 0.6, 0.2, 0.1]),  # sample 2
]

# u_score_s: list of answerability scores for each sample
u_score_s = [0.9, 0.7, 0.85]

# beta1, beta2: parameters for the Bayesian calculation
beta1 = 0.3
beta2 = 0.7

ARGS = {
    "prob": prob,
    "u_score": u_score,
    "prob_s": prob_s,
    "u_score_s": u_score_s,
    "num_samples": num_samples,
    "beta1": beta1,
    "beta2": beta2,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
method_simple_counting Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("a327c65c24bd1adc")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Construct arguments for method_simple_counting
# The function expects:
# - prob: array of probabilities (used with np.argmax)
# - u_score: uncertainty score (compared with AT threshold)
# - prob_s: array of probability arrays for samples (used with np.argmax)
# - u_score_s: array of uncertainty scores for samples (compared with AT threshold)
# - num_samples: number of samples
# - AT: acceptance threshold

# Create small probability distributions (4 classes)
prob = np.array([0.1, 0.6, 0.2, 0.1])

# Create uncertainty score above threshold
u_score = 0.8

# Create sample probabilities (3 samples, 4 classes each)
prob_s = np.array([
    [0.2, 0.5, 0.2, 0.1],
    [0.1, 0.2, 0.6, 0.1],
    [0.3, 0.3, 0.2, 0.2]
])

# Create uncertainty scores for samples
u_score_s = np.array([0.9, 0.7, 0.6])

# Number of samples
num_samples = 3

# Acceptance threshold
AT = 0.5

ARGS = {
    "prob": prob,
    "u_score": u_score,
    "prob_s": prob_s,
    "u_score_s": u_score_s,
    "num_samples": num_samples,
    "AT": AT
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
method_vanilla_bayes Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("fd8b74b87c682b53")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create small probability distributions (num_classes=3)
prob = np.array([0.1, 0.6, 0.3])  # argmax will be 1

# Create a small u_score above threshold
u_score = 0.8

# Create small probability distributions for samples (num_samples=2, num_classes=3)
prob_s = np.array([
    [0.2, 0.5, 0.3],  # argmax will be 1
    [0.4, 0.3, 0.3]   # argmax will be 0
])

# Create u_score_s for samples (some above, some below threshold)
u_score_s = np.array([0.9, 0.7])

num_samples = 2

# Beta parameters for the Bayesian calculation
beta1 = 0.3
beta2 = 0.6

# Acceptance threshold
AT = 0.5

ARGS = {
    "prob": prob,
    "u_score": u_score,
    "prob_s": prob_s,
    "u_score_s": u_score_s,
    "num_samples": num_samples,
    "beta1": beta1,
    "beta2": beta2,
    "AT": AT
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prepare_distractor_input Ran
ran, honoured the contract we drafted
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("91aa51bfaaa9af1c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family int, shape (1, 5) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from transformers import T5Tokenizer

torch.manual_seed(0)

# Create a minimal stand-in tokenizer that has the __call__ method
class MinimalT5Tokenizer:
    def __call__(self, texts, return_tensors=None):
        # Simulate tokenizer output with input_ids tensor
        # Return a namespace-like object with input_ids attribute
        class TokenizerOutput:
            def __init__(self):
                self.input_ids = torch.tensor([[101, 2054, 2003, 102, 0]], dtype=torch.long)
        
        return TokenizerOutput()

t5_tokenizer = MinimalT5Tokenizer()
context = "The capital of France is Paris."
question = "What is the capital of France?"
answer = "Paris"
device = torch.device('cpu')
separator = '<sep>'

ARGS = {
    't5_tokenizer': t5_tokenizer,
    'context': context,
    'question': question,
    'answer': answer,
    'device': device,
    'separator': separator
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family int, shape (1, 5) — shape (1, 5) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prepare_qa_input Ran
ran, honoured the contract we drafted
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("0f6a58be9f56b183")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family int, shape (1, 10) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockT5Tokenizer:
    def __call__(self, texts, return_tensors=None):
        # Simulate tokenizer output
        batch_size = len(texts) if isinstance(texts, list) else 1
        seq_length = 10
        
        class EncodingOutput:
            def __init__(self, input_ids):
                self.input_ids = input_ids
        
        input_ids = torch.randint(0, 32128, (batch_size, seq_length))
        return EncodingOutput(input_ids=input_ids)

t5_tokenizer = MockT5Tokenizer()
context = "What is the capital of France? Paris"
device = torch.device("cpu")

ARGS = {
    "t5_tokenizer": t5_tokenizer,
    "context": context,
    "device": device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family int, shape (1, 10) — shape (1, 10) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
question_generation_sentence_level Ran
ran, honoured the contract we drafted
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("8d22955c5597692a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.pad_token = '<pad>'
        self.eos_token = '</s>'
        self.sep_token = '<sep>'
    
    def __call__(self, texts, return_tensors=None):
        # Simple mock: return a batch of input_ids
        if return_tensors == 'pt':
            # Return a simple encoding object
            class Encoding:
                def __init__(self):
                    self.input_ids = torch.tensor([[101, 2054, 2003, 102], [101, 2054, 2003, 102]], dtype=torch.long)
            return Encoding()
        return None
    
    def decode(self, token_ids, skip_special_tokens=False):
        # Mock decode: return a string with question and answer separated
        return "What is this? <sep> answer <sep>"

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def generate(self, input_ids, max_new_tokens=None, do_sample=None):
        # Mock generate: return token ids
        # Return a tensor that when decoded gives question <sep> answer <sep> distractor1 <sep> distractor2 <sep> distractor3
        return torch.tensor([[101, 2054, 2003, 102]], dtype=torch.long)

ARGS = {
    'g1_model': MockModel(),
    'g1_tokenizer': MockTokenizer(),
    'g2_model': MockModel(),
    'g2_tokenizer': MockTokenizer(),
    'sentence': "This is a test sentence about machine learning.",
    'passage': "This is a longer passage that contains information about machine learning and artificial intelligence.",
    'num_questions_per_sent': 2,
    'device': 'cpu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MQAGConfig Not yet run
unverified (harvested, no recorded run)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("6f5cf383ae436397")
How it ran

no invocation recorded.

SelfCheckMQAG Not yet run
unverified (harvested, no recorded run)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("e976fc7d0ba93b93")
How it ran

no invocation recorded.

answerability_scoring Not yet run
unverified (harvested, no recorded run)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("1cd98422f1661366")
How it ran

no invocation recorded.

answering Not yet run
unverified (harvested, no recorded run)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("2374d4bcf09066d3")
How it ran

no invocation recorded.

prepare_answering_input Not yet run
unverified (harvested, no recorded run)
potsawee/selfcheckgpt/selfcheckgpt/modeling_selfcheck.py
code served (permissive licence) · get_code("b38e4eaa9c590ae7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 10 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
question_generation_sentence_level
brick of this paper's assembly: helper
1 other paper
1 later
2305.15852 (2023-05)
Self-contradictory Hallucinations of Large Language Models: Evaluation, Detection and Mitigation

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Generative Large Language Models (LLMs) such as GPT-3 are capable of generating highly fluent responses to a wide variety of user prompts. However, LLMs are known to hallucinate facts and make non-factual statements which can undermine trust in their output. Existing fact-checking approaches either require access to the output probability distribution (which may not be available for systems such as ChatGPT) or external databases that are interfaced via separate, often complex, modules. In this work, we propose "SelfCheckGPT", a simple sampling-based approach that can be used to fact-check the responses of black-box models in a zero-resource fashion, i.e. without an external database. SelfCheckGPT leverages the simple idea that if an LLM has knowledge of a given concept, sampled responses are likely to be similar and contain consistent facts. However, for hallucinated facts, stochastically sampled responses are likely to diverge and contradict one another. We investigate this approach by using GPT-3 to generate passages about individuals from the WikiBio dataset, and manually annotate the factuality of the generated passages. We demonstrate that SelfCheck-GPT can: i) detect non-factual and factual sentences; and ii) rank passages in terms of factuality. We compare our approach to several baselines and show that our approach has considerably higher AUC-PR scores in sentence-level hallucination detection and higher correlation scores in passage-level factuality assessment compared to grey-box methods. 1

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2303.08896")
get_code_for_paper("2303.08896")
have("2303.08896")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2303.08896.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2303.08896.svg)](https://syntology.ai/paper/2303.08896)

Connect an agent — have() is free.