hprobes
Discover and causally validate hallucination-associated FFN neurons (H-Neurons) in transformer LLMs.
Based on arXiv:2512.01797.
Install
pip install hprobes
# or
uv add hprobes
Quickstart
from transformers import AutoModelForCausalLM, AutoTokenizer
from hprobes import HProbe
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 = HProbe(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
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 = HProbe.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.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hprobes-0.10.0.tar.gz | 255.2 kB | Without provenance | Details for hprobes-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hprobes-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for hprobes-0.10.0-py3-none-any.whl |
Total release size: 299.5 kB
Release files / hprobes-0.10.0.tar.gz
| Download URL | hprobes-0.10.0.tar.gz |
|---|---|
| Size | 255.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34ad3ace98620fd22c8942707c908742c188a7fb826847314c106c1deb01237e
|
|
BLAKE2b-256 checksum How to use checksums |
ae890a751a561104a9ac5ba2d359c28808147f5df5bbf8cb506f750523c7701c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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.10.0-py3-none-any.whl
| Download URL | hprobes-0.10.0-py3-none-any.whl |
|---|---|
| Size | 44.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02ab48fa7eef82a3e24c603025d03582d87e82713a6ec4602e87935cd2f07955
|
|
BLAKE2b-256 checksum How to use checksums |
8a117dbe858b633154d65a15855f8f6b2edc4d7a1a5fb60424fa92f63f42d3a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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.10.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.