Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AISecurityLab Hackagent load calibration

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Datasets, Calibration
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for loading human-labelled calibration datasets used to measure judge panel reliability, provided by the HackAgent datasets framework.

Description

load_calibration loads a labelled calibration dataset (currently HarmBench's human-labelled classifier validation set) and draws a deterministic stratified sample. It is the data source for judge panel audits — an ordinary dataset supplies goals to attack, a calibration dataset supplies exchanges that people have already judged.

load_harmbench downloads HarmBench's validation set: model generations, each labelled by three annotators. The behaviour text lives in a second file, so the two are joined on BehaviorID. A behaviour's ContextString becomes the sample's prompt. Downloads are cached on disk; the HarmBench revision is pinned for reproducibility.

stratified_sample draws size samples deterministically, keeping both label classes (safe/unsafe) in proportion. Drawing at random would let a small sample come out all-positive, and a judge measured on it would have no recall to report.

CalibrationSpec configures which dataset, which revision, how many samples, the random seed, the cache directory, and the download timeout.

Usage

Import this module when you need labelled samples for a judge audit. It is called by aaudit_configured_panel with a CalibrationSpec from the campaign's AuditSpec. Call load_calibration directly for custom audit pipelines.

Code Reference

Source Location

Signature

def load_calibration(spec: CalibrationSpec) -> list[LabelledSample]:
    """Load spec's dataset and draw its sample."""

def load_harmbench(
    *,
    revision: str = DEFAULT_HARMBENCH_REVISION,
    cache_dir: Optional[Path] = None,
    timeout: float = 30.0,
) -> list[LabelledSample]: ...

def stratified_sample(samples: list[LabelledSample], size: Optional[int], seed: int) -> list[LabelledSample]: ...

class CalibrationSpec(BaseModel):
    dataset: Literal["harmbench"] = "harmbench"
    revision: str = DEFAULT_HARMBENCH_REVISION
    sample_size: Optional[int] = 100
    seed: int = 42
    cache_dir: Optional[str] = None
    download_timeout: float = 30.0

Import

from hackagent.datasets.calibration import (
    load_calibration, load_harmbench, stratified_sample, CalibrationSpec,
)

I/O Contract

Inputs

Name Type Required Description
spec CalibrationSpec Yes Dataset, revision, sample size, seed

Outputs

Name Type Description
return list[LabelledSample] Each has sample (goal, prompt, response), label (bool), id (BehaviorID)

Usage Examples

Load a Calibration Sample

from hackagent.datasets.calibration import load_calibration, CalibrationSpec

# Default: 100 samples from HarmBench, seed 42
spec = CalibrationSpec(sample_size=50, seed=123)
samples = load_calibration(spec)

print(f"Loaded {len(samples)} labelled samples")
for s in samples[:5]:
    print(f"  id={s.id}, label={s.label}, goal={s.sample.goal[:50]}...")

Use All Samples

from hackagent.datasets.calibration import CalibrationSpec, load_calibration

# sample_size=None uses the whole dataset
spec = CalibrationSpec(sample_size=None)
all_samples = load_calibration(spec)
print(f"Full dataset: {len(all_samples)} samples")

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment