FactHiddenCheck-Llama2-7B-PsiloQA

Standard SAPLMA probe trained on PsiloQA (English), for hallucination scoring from Llama-2-7B hidden states.

This is not a generative LLM. It is a small MLP: 4096 โ†’ 256 โ†’ 128 โ†’ 64 โ†’ 1 โ†’ P(supported).

Sibling Azaria baseline: ZaandaTeika/FactHiddenCheck-Llama2-7B (SLT L16).

Model details

Field Value
Probe SAPLMA MLP (SLT baseline)
Base LM NousResearch/Llama-2-7b-hf
Layer 28 (last token / SLT)
Train data PsiloQA EN, Q+A format, human HAL spans (n_train=16115)
Seed 42
Checkpoint F_transfer/psiloqa/slt_l28_seed42.pt

Labels: 1 = supported (no HAL span), 0 = hallucinated (has HAL span).

Input format used in training:
Question: โ€ฆ\nAnswer: โ€ฆ โ€” features from answer-side / last-token HS at layer 28.

How to use

import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoTokenizer

# 1) hidden state from Llama-2-7B
base = "NousResearch/Llama-2-7b-hf"
tok = AutoTokenizer.from_pretrained(base)
llm = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.float16, device_map="auto")

text = "Question: What is the capital of France?\nAnswer: Paris."
inputs = tok(text, return_tensors="pt").to(llm.device)
with torch.no_grad():
    out = llm(**inputs, output_hidden_states=True)
hs = out.hidden_states[28][0, -1, :].float().cpu().numpy()  # layer 28, last token

# 2) probe
ckpt = torch.load(
    hf_hub_download("ZaandaTeika/FactHiddenCheck-Llama2-7B-PsiloQA", "saplma.pt"),
    map_location="cpu",
    weights_only=False,
)

class SAPLMA(nn.Module):
    def __init__(self, in_dim):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(in_dim, 256), nn.ReLU(),
            nn.Linear(256, 128), nn.ReLU(),
            nn.Linear(128, 64), nn.ReLU(),
            nn.Linear(64, 1),
        )
    def forward(self, x):
        return self.net(x).squeeze(-1)

model = SAPLMA(int(ckpt["state_dict"]["net.0.weight"].shape[1]))
model.load_state_dict(ckpt["state_dict"])
model.eval()

Xn = (hs - ckpt["mu"]) / (ckpt["std"] + 1e-6)
p_supported = torch.sigmoid(model(torch.from_numpy(Xn).float())).item()
print(p_supported)

Repo files: saplma.pt, model.safetensors, config.json.

Notes

  • Tied to Llama-2-7B activations; other LMs need their own probe.
  • Class balance on PsiloQA train is heavily skewed (~4% supported); prefer AUROC / calibrated thresholds over Acc@0.5.
  • In-domain SLT L28 AUROC โ‰ˆ 0.77 (Q+A); stronger pooling/concat variants exist but this is the standard SLT baseline.

Citation

@inproceedings{azaria-mitchell-2023-internal,
  title = {The Internal State of an {LLM} Knows When It's Lying},
  author = {Azaria, Amos and Mitchell, Tom},
  booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2023},
  year = {2023},
  url = {https://aclanthology.org/2023.findings-emnlp.68/}
}
Downloads last month
15
Safetensors
Model size
1.1M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for ZaandaTeika/FactHiddenCheck-Llama2-7B-PsiloQA

Finetuned
(52)
this model