rhscope.training.data

Data types and loaders for probe training.

Training data is a flat JSONL file where each line is a HackExample:

{“prompt”: “…”, “response”: “…”, “is_hacking”: true, “category”: “…”}

Only prompt, response, and is_hacking are required. category is optional and respected when the probe is category-specific; source and extra allow tracking data provenance without changing the schema.

class rhscope.training.data.HackExample(prompt, response, is_hacking, category=None, source=None, extra=<factory>)[source]

Bases: object

A single labeled example for probe training.

Variables:
  • prompt (str) – User-facing prompt (as seen by the model).

  • response (str) – Model continuation to be scored.

  • is_hacking (bool) – True if the response exemplifies reward-hacking behavior, False otherwise.

  • category (str | None) – Optional RH-Detect category (e.g. "code_shortcut").

  • source (str | None) – Optional provenance tag (dataset name, filename, …).

  • extra (dict[str, Any]) – Arbitrary extra fields preserved across load/save.

Parameters:
prompt: str
response: str
is_hacking: bool
category: str | None = None
source: str | None = None
extra: dict[str, Any]
to_dict()[source]

Return a JSON-serializable dict representation.

Return type:

dict[str, Any]

classmethod from_dict(data)[source]

Parse a dict (e.g. from a JSONL line) into a HackExample.

Unknown keys land in extra so forward-compatible fields survive round trips through older code.

Parameters:

data (dict[str, Any])

Return type:

HackExample

rhscope.training.data.load_hack_examples(path)[source]

Load a JSONL file of HackExample records.

Parameters:

path (str | Path) – File to read. One JSON object per line, UTF-8 encoded.

Returns:

List of parsed examples in file order.

Raises:
Return type:

list[HackExample]

rhscope.training.data.save_hack_examples(path, examples)[source]

Write examples to a JSONL file. Overwrites any existing content.

Parameters:
Return type:

Path

rhscope.training.data.split_hack_clean(examples)[source]

Partition examples by is_hacking.

Returns:

(hack_examples, clean_examples).

Parameters:

examples (list[HackExample])

Return type:

tuple[list[HackExample], list[HackExample]]

rhscope.training.data.train_val_split(examples, val_fraction, *, seed=0, stratify=True)[source]

Deterministic train/val split, optionally stratified by label.

Parameters:
  • examples (list[HackExample]) – Examples to split.

  • val_fraction (float) – Fraction allocated to the validation set, in (0, 1).

  • seed (int) – RNG seed for the shuffle.

  • stratify (bool) – Preserve the hack/clean ratio in both halves. Default True.

Returns:

(train, val).

Return type:

tuple[list[HackExample], list[HackExample]]

rhscope.training.data.hash_examples(examples)[source]

Return a stable SHA-256 hex digest over the examples’ canonical content.

Used for training-data provenance metadata so saved probes can be traced back to a specific dataset.

Parameters:

examples (list[HackExample])

Return type:

str