SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2601.19245 · 2026

Beyond In-Domain Detection: SpikeScore for Cross-Domain Hallucination Detection

Ling Chen, Zhen Fang, Sharon Li, Yongxin Deng

arXiv · PDF · Open in the Atlas

Code that ran

9 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; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 7 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2601.19245.json · badge: /api/ran/2601.19245.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
TianYaDY/SpikeScore canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
create_prompt_builder Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/prompt_builder.py
code served (permissive licence) · get_code("0b176513ebc12daa")
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 PromptBuilder. The image it ran in was not recorded. If your copy returns the same type 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 logging
from typing import Dict, Any, Optional

logging.basicConfig(level=logging.INFO)

class MockTokenizer:
    """Mock tokenizer that supports apply_chat_template"""
    def apply_chat_template(self, messages, tokenize=False, add_generation_prompt=False):
        """Format messages as a simple string"""
        parts = []
        for msg in messages:
            parts.append(f"{msg['role'].upper()}: {msg['content']}")
        if add_generation_prompt:
            parts.append("ASSISTANT:")
        return "\n".join(parts)

tokenizer = MockTokenizer()
system_prompt = "You are a helpful assistant."

ARGS = {
    "tokenizer": tokenizer,
    "system_prompt": system_prompt,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PromptBuilder — a PromptBuilder output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a PromptBuilder output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
extract_features_labels Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/shap_score.py
code served (permissive licence) · get_code("fdd7d9778eded6d7")
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 tuple. The image it ran in was not recorded. If your copy returns the same type 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 os
import json
import tempfile
import numpy as np

# Create a temporary directory with test JSON files
test_dir = tempfile.mkdtemp()

# Create sample JSON files with the expected structure
sample_data_1 = {
    'nli_label': 0,
    'reasoning_chain': [
        {
            'metrics': {
                'reasoning_score_per_token': {
                    'last_token_embedding': 0.5,
                    'sec_last_token_embedding': 0.6,
                    'last_tok_bef_gen_embedding': 0.7
                }
            }
        },
        {
            'metrics': {
                'reasoning_score_per_token': {
                    'last_token_embedding': 0.55,
                    'sec_last_token_embedding': 0.65,
                    'last_tok_bef_gen_embedding': 0.75
                }
            }
        },
        {
            'metrics': {
                'reasoning_score_per_token': {
                    'last_token_embedding': 0.6,
                    'sec_last_token_embedding': 0.7,
                    'last_tok_bef_gen_embedding': 0.8
                }
            }
        }
    ]
}

sample_data_2 = {
    'nli_label': 1,
    'reasoning_chain': [
        {
            'metrics': {
                'reasoning_score_per_token': {
                    'last_token_embedding': 0.3,
                    'sec_last_token_embedding': 0.4,
                    'last_tok_bef_gen_embedding': 0.5
                }
            }
        },
        {
            'metrics': {
                'reasoning_score_per_token': {
                    'last_token_embedding': 0.35,
                    'sec_last_token_embedding': 0.45,
                    'last_tok_bef_gen_embedding': 0.55
                }
            }
        }
    ]
}

# Write sample JSON files
with open(os.path.join(test_dir, 'sample_1.json'), 'w', encoding='utf-8') as f:
    json.dump(sample_data_1, f)

with open(os.path.join(test_dir, 'sample_2.json'), 'w', encoding='utf-8') as f:
    json.dump(sample_data_2, f)

ARGS = {
    'data_dir': test_dir,
    'min_steps': 2
}
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 tuple — a tuple output has no array shape of its own; none is stated
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
flatten_coqa Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/dataset_processor.py
code served (permissive licence) · get_code("2351732b7439a36e")
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 hashlib

def flatten_coqa(entry):
    story = entry.get('story', '')
    base_id = entry.get('id') or hashlib.md5(story.encode()).hexdigest()[:8]
    questions = entry.get('questions', [])
    answers = entry.get('answers', [])
    answer_map = {a['turn_id']: a for a in answers if 'turn_id' in a}
    samples = []
    for q in questions:
        turn_id = q.get('turn_id')
        q_text = q.get('input_text', '')
        ans = answer_map.get(turn_id, {})
        a_text = ans.get('input_text', '')
        new_id = f'{base_id}_{turn_id}' if turn_id is not None else base_id
        samples.append({'id': str(new_id), 'question': str(q_text), 'context': str(story), 'answer': str(a_text), 'turn_id': turn_id})
    return samples


ARGS = {
    'entry': {
        'story': 'Once upon a time there was a small village.',
        'id': 'coqa_001',
        'questions': [
            {'turn_id': 0, 'input_text': 'Where was the village?'},
            {'turn_id': 1, 'input_text': 'Was it large?'},
        ],
        'answers': [
            {'turn_id': 0, 'input_text': 'The village was small.'},
            {'turn_id': 1, 'input_text': 'No, it was very small.'},
        ]
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — 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
flatten_math Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/dataset_processor.py
code served (permissive licence) · get_code("cc0ea033d30b5f34")
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 dict. The image it ran in was not recorded. If your copy returns the same type 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 hashlib

def flatten_math(entry, idx=0):
    question = str(entry.get('en', ''))
    context = str(entry.get('solution', ''))
    answer = str(entry.get('answer', ''))
    _id = entry.get('id', None)
    if not _id or str(_id).strip() == '':
        id_source = question + '|' + context + '|' + answer + '|' + str(idx)
        _id = hashlib.md5(id_source.encode('utf-8')).hexdigest()[:12]
    return {'id': str(_id), 'question': question, 'context': context, 'answer': answer, 'turn_id': None}


# Construct valid arguments
entry = {
    'en': 'What is 2 + 2?',
    'solution': 'We add the two numbers together.',
    'answer': '4',
    'id': 'test_id_001'
}

idx = 0

ARGS = {
    'entry': entry,
    'idx': idx
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
flatten_svamp Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/dataset_processor.py
code served (permissive licence) · get_code("f2663fa566f37f2a")
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 dict. The image it ran in was not recorded. If your copy returns the same type 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 hashlib

# Analyze the function:
# - entry: dict with keys 'Question', 'Body', 'Answer', 'ID'
# - idx: integer (default 0)
# The function calls .get() on entry dict and converts values to strings
# If ID is missing or empty, it generates one from hashing

ARGS = {
    'entry': {
        'Question': 'What is 2+2?',
        'Body': 'In mathematics, addition is a fundamental operation.',
        'Answer': '4',
        'ID': 'sample_id_123'
    },
    'idx': 0
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
get_unembedding_weight Ran
ran, honoured the contract we drafted
TianYaDY/SpikeScore/metrics_score.py
code served (permissive licence) · get_code("199e9463ec3c81cb")
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 float, shape (3, 4) 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)

# Create a model with lm_head attribute
class ModelWithLMHead(nn.Module):
    def __init__(self):
        super().__init__()
        self.lm_head = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.lm_head(x)

model = ModelWithLMHead()

ARGS = {
    'model': model
}
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 float, shape (3, 4) — shape (3, 4) 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
hallucination_score Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
TianYaDY/SpikeScore/eval_score.py
code served (permissive licence) · get_code("6fb5df7611bc42d7")
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 a sample scores array
# Shape: (num_steps, num_features)
# Using distinct dimensions: 4 steps, 3 score values
scores = np.array([
    [0.1, 0.2, 0.15],
    [0.3, 0.25, 0.28],
    [0.5, 0.45, 0.48],
    [0.6, 0.55, 0.58]
], dtype=np.float32)

ARGS = {
    'scores': scores,
    'mode': 'peaked'
}
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
jsd Ran
ran, violated the contract we drafted
TianYaDY/SpikeScore/metrics_score.py
code served (permissive licence) · get_code("b6e699e8f8f1fd8e")
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 float64, ndim 0, 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 numpy as np
from scipy.spatial.distance import jensenshannon

def jsd(p, q):
    return jensenshannon(p, q, base=2) ** 2

# jsd takes two probability distributions p and q
# jensenshannon expects 1D array-like inputs representing probability distributions
# Create two simple probability distributions that sum to 1

p = np.array([0.2, 0.3, 0.3, 0.2])
q = np.array([0.25, 0.25, 0.25, 0.25])

ARGS = {
    "p": p,
    "q": q
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
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
layerwise_probs Ran
ran; our contract draft was wrong, not the code
TianYaDY/SpikeScore/metrics_score.py
code served (permissive licence) · get_code("6106420483a2ca85")
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 ndarray, ndim 3, dtype family float, shape (3, 2, 3) 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)

# hidden: needs to support .float() method and indexing, should be a tensor
# Shape: (num_layers, batch_size, hidden_dim) - using distinct sizes
hidden = torch.randn(5, 2, 4)

# unembedding_weight: needs to support .T attribute for transpose
# Shape: (vocab_size, hidden_dim) - distinct sizes
unembedding_weight = torch.randn(3, 4)

# layer_range: optional tuple of (start, end) for slicing
layer_range = (1, 3)

ARGS = {
    "hidden": hidden,
    "unembedding_weight": unembedding_weight,
    "layer_range": layer_range,
}
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 ndarray, ndim 3, dtype family float, shape (3, 2, 3) — shape (3, 2, 3) 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
load_probe Not yet run
unverified (harvested, no recorded run)
TianYaDY/SpikeScore/metrics_probe.py
code served (permissive licence) · get_code("a9504d497a61ad93")
How it ran

no invocation recorded.

probe_score Not yet run
unverified (harvested, no recorded run)
TianYaDY/SpikeScore/metrics_probe.py
code served (permissive licence) · get_code("871e1beb1b399789")
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, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 11 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.

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-23.

Repositories linked to this paper

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

Abstract

Hallucination detection is critical for deploying large language models (LLMs) in real-world applications. Existing hallucination detection methods achieve strong performance when the training and test data come from the same domain, but they suffer from poor cross-domain generalization. In this paper, we study an important yet overlooked problem, termed generalizable hallucination detection (GHD), which aims to train hallucination detectors on data from a single domain while ensuring robust performance across diverse related domains. In studying GHD, we simulate multi-turn dialogues following LLMs' initial response and observe an interesting phenomenon: hallucination-initiated multi-turn dialogues universally exhibit larger uncertainty fluctuations than factual ones across different domains. Based on the phenomenon, we propose a new score SpikeScore, which quantifies abrupt fluctuations in multi-turn dialogues. Through both theoretical analysis and empirical validation, we demonstrate that SpikeScore achieves strong cross-domain separability between hallucinated and non-hallucinated responses. Experiments across multiple LLMs and benchmarks demonstrate that the SpikeScore-based detection method outperforms representative baselines in crossdomain generalization and surpasses advanced generalization-oriented methods, verifying the effectiveness of our method in cross-domain hallucination detection.

For agents

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

get_harvested_code_for_paper("2601.19245")
get_code_for_paper("2601.19245")
have("2601.19245")

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

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

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

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

Connect an agent — have() is free.