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:
objectA 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) –
Trueif the response exemplifies reward-hacking behavior,Falseotherwise.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:
- rhscope.training.data.load_hack_examples(path)[source]¶
Load a JSONL file of
HackExamplerecords.- Parameters:
path (str | Path) – File to read. One JSON object per line, UTF-8 encoded.
- Returns:
List of parsed examples in file order.
- Raises:
FileNotFoundError – If the path does not exist.
ValueError – If any line is not valid JSON or is missing required fields.
- Return type:
- rhscope.training.data.save_hack_examples(path, examples)[source]¶
Write examples to a JSONL file. Overwrites any existing content.
- Parameters:
examples (list[HackExample])
- Return type:
- rhscope.training.data.split_hack_clean(examples)[source]¶
Partition examples by
is_hacking.- Returns:
(hack_examples, clean_examples).- Parameters:
examples (list[HackExample])
- Return type:
- 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:
- 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: