ExamplesΒΆ

Short, self-contained scripts that demonstrate the library. Every page here is a literalinclude of a runnable .py file from the examples/ directory of the repository - the code you see is the code that runs.

Example

What it shows

Runs on

Train your first probe

Train a DoM probe on a small HF model and use it as a monitor.

CPU or GPU, downloads SmolLM-135M

Benchmark baseline detectors

Score RandomDetector and TokenCountDetector on a toy labelled set.

CPU, no model

Compose multiple detectors

Fuse detectors with max / mean / weighted_mean reducers.

CPU, no model

Filter DPO preference data

Flag preference pairs where the chosen completion is more hack-like than the rejected.

CPU, no model

Plug a monitor into TRL

Build a TRL-compatible reward function from a HackMonitor.

CPU, no model

Only the first example needs a real model (SmolLM-135M, ~270 MB). The rest use a CallableDetector stand-in so they run instantly without model weights. In production you swap the stand-in for HackMonitor.from_pretrained("your/probe") or HackMonitor.from_probe(probe, model=..., tokenizer=...).