ZaandaTeika/FactHiddenCheck-Llama2-7B-PsiloQA
023
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
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/}
}