Skip to main content

hprobes

Docs DeepWiki

Discover and causally validate hallucination-associated FFN neurons (H-Neurons) in transformer LLMs, including dense and mixture-of-experts models.

Builds on arXiv:2512.01797.

Our paper: Hallucination Neurons and Where to Find Them: An Investigation into the existence of Hallucination Neurons, arXiv:2609.29781, AIMLAI @ ECML-PKDD 2026.

Features

  • Dense and MoE H-Neuron discovery
  • Causal validation: α-scaling, ablation, routing counterfactuals
  • Inference-time steering: neuron write-vectors, contrastive directions, ablation
  • Bootstrap stability for dense and MoE probes
  • Production hallucination-risk scoring (detect() / detect_batch())

Install

pip install hprobes
# or
uv add hprobes

Quickstart

from transformers import AutoModelForCausalLM, AutoTokenizer
from hprobes import HProbes

model = AutoModelForCausalLM.from_pretrained("google/gemma-3-4b-it", torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("google/gemma-3-4b-it")

# samples: list of dicts with question, options, answer
probe = HProbes(model, tokenizer)
probe.fit(samples, options_key="choices", answer_key="answer")

print(probe.n_neurons_, probe.layer_distribution_)

results = probe.score()
print(f"AUROC {results['auroc']:.3f}  gap {results['auroc_gap']:+.3f}")

probe.causal_validate()

CLI

# Fit and score on an MCQ dataset
hprobes run --model google/gemma-3-4b-it --data dataset.jsonl --samples 500

# Transfer: score a saved probe on a different model
hprobes transfer --probe results/probe --model google/gemma-3-4b --data dataset.jsonl

# Fit from pre-generated responses with judge labels
hprobes responses --model google/gemma-3-4b-it --data responses.jsonl

# MoE probing (routed + shared experts)
hprobes moe --model allenai/OLMoE-1B-7B-0924 --data medqa.parquet --score mean_abs --stability

# Inference-time steering
hprobes steer --model gpt2 --prompt "The capital of France is" \
  --kind neuron_write --layer 6 --neuron 123 --dose 0.5

Supported formats

Input files: .jsonl, .json, .parquet

Auto-detected dataset formats: mmlu, medqa, medmcqa. Any other format works by passing options_key and answer_key directly.

Key options

Parameter Default Description
l1_C 0.01 Inverse L1 strength — lower = fewer neurons
contrastive True 3-vs-1 labeling at the generated answer token
layer_stride 1 Sample every Nth layer (2 = faster)
validation_split 0.2 Holdout fraction for scoring
max_tokens 1024 Truncation length

Save & load

probe.save("results/gemma_medqa")          # writes .json + .pkl
probe = HProbes.load("results/gemma_medqa", model, tokenizer)
probe.score_on(new_samples, options_key="choices", answer_key="answer")

Acknowledgements

This research is conducted in collaboration with the Great Ormond Street Hospital DRIVE Unit.

Contributors

  • Huseyin Cavus — Core Contributor
  • Pavithra Rajendran, PhD — Machine Learning Lead, GOSH DRIVE
  • Sebin Sabu — Senior AI Scientist, GOSH DRIVE
  • Jaskaran Singh Kawatra — ML Engineer, GOSH DRIVE
  • Josh Spear, PhD — Postdoctoral Researcher, GOSH DRIVE

Metadata

Release files for hprobes 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hprobes 0.12.0
File Size Uploaded Provenance Actions
hprobes-0.12.0.tar.gz 316.1 kB Without provenance Details for hprobes-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hprobes 0.12.0
File Interpreter ABI Platform Actions
hprobes-0.12.0-py3-none-any.whl Python 3 none any Details for hprobes-0.12.0-py3-none-any.whl

Total release size: 404.8 kB

Release files / hprobes-0.12.0.tar.gz

Download URL hprobes-0.12.0.tar.gz
Size 316.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9fce260130a3a7e67fde358711b83e4e41f1d06e021913384e5028e10e7164e5
BLAKE2b-256 checksum
How to use checksums
3cc42ab7b6d91ca746b017f957bde68c072d93bcf52021ff6343c8a94a789e10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / hprobes-0.12.0-py3-none-any.whl

Download URL hprobes-0.12.0-py3-none-any.whl
Size 88.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f4aa9c82005cb5df99659bcc449c0e11060747ad9625b5fed24fa30c6aa8b6b
BLAKE2b-256 checksum
How to use checksums
2ad9964a6ca8bf909e28f425273c69fdad728d14d493de44a25496bd5533a51f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for hprobes 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page