rhscope.bench.detectors

Detector interface and baseline implementations.

A Detector scores (prompt, response) pairs on a hacking-vs-clean axis. Baselines (random, token-count) provide floor comparisons; ProbeDetector wraps a trained Probe with the activation-extraction glue required to score free-form text.

class rhscope.bench.detectors.Detector[source]

Bases: ABC

Abstract base class for reward-hacking detectors.

Concrete detectors implement score_batch. name is used for bookkeeping in benchmark results.

name: str = 'detector'
abstractmethod score_batch(prompts, responses)[source]

Return a 1-D numpy array of scores (higher = more hack-like).

Parameters:
Return type:

ndarray

class rhscope.bench.detectors.RandomDetector(seed=0)[source]

Bases: Detector

Baseline that emits uniform random scores. AUROC should be ~0.5.

Parameters:

seed (int)

name: str = 'random'
score_batch(prompts, responses)[source]

Return i.i.d. uniform [0, 1) scores, one per example.

Parameters:
Return type:

ndarray

class rhscope.bench.detectors.TokenCountDetector[source]

Bases: Detector

Baseline that uses response length as the hacking score.

Longer responses often correlate with verbosity-type hacking; this baseline exists mostly to confirm that any serious probe clearly beats “count tokens”.

name: str = 'token_count'
score_batch(prompts, responses)[source]

Return the whitespace-token count of each response as its score.

Parameters:
Return type:

ndarray

class rhscope.bench.detectors.ProbeDetector(probe, model, tokenizer, *, batch_size=8, max_length=1024)[source]

Bases: Detector

Wrap a trained Probe with activation extraction.

Variables:
  • probe – Trained Probe whose metadata.layer and metadata.pooling drive activation extraction.

  • model – Loaded Hugging Face causal LM that the probe was trained against.

  • tokenizer – Matching tokenizer.

  • batch_size – Mini-batch size for forward passes.

  • max_length – Token truncation length.

Parameters:
  • probe (Probe)

  • model (Any)

  • tokenizer (Any)

  • batch_size (int)

  • max_length (int)

score_batch(prompts, responses)[source]

Run the wrapped probe against activations of (prompt, response).

Parameters:
Return type:

ndarray

rhscope.bench.detectors.Reducer

Supported reducers for CompositeDetector.

  • "mean": equal-weight average.

  • "max" / "min": element-wise max / min (strict aggregator / veto).

  • "sum": raw sum; useful when each sub-detector’s scale is already calibrated.

  • "weighted_mean": sum(w_i * s_i) / sum(w_i) - requires weights.

alias of Literal[‘mean’, ‘max’, ‘min’, ‘sum’, ‘weighted_mean’]

class rhscope.bench.detectors.CompositeDetector(detectors, reducer='mean', *, weights=None, name=None)[source]

Bases: Detector

Ensemble multiple Detector instances into one.

All sub-detectors are called on the same (prompts, responses) batch and their outputs are reduced element-wise into a single score vector. Common use cases:

  • Probe + LLM-judge fusion: CompositeDetector([probe_det, judge_det], "mean").

  • Veto ensemble: CompositeDetector([probe, rule], "max") - any sub-detector firing flags the response.

  • Weighted combination: pass weights=[1.0, 0.3] with reducer="weighted_mean".

The composite does not rescale its inputs. Sub-detectors with wildly different output scales should be normalized (e.g. sigmoid) before being composed - otherwise one detector dominates the reduction.

Variables:
  • detectors – Sub-detectors, scored in order.

  • reducer – Reduction strategy.

  • weights – Per-detector weights for reducer="weighted_mean"; otherwise unused.

Parameters:
property detectors: list[Detector]

Sub-detectors, in the order they are scored and reduced.

property reducer: Literal['mean', 'max', 'min', 'sum', 'weighted_mean']

Reduction strategy used across sub-detector scores.

score_batch(prompts, responses)[source]

Score (prompts, responses) with every sub-detector and reduce.

Parameters:
Return type:

ndarray

class rhscope.bench.detectors.CallableDetector(fn, *, name='callable')[source]

Bases: Detector

Adapter wrapping a plain callable as a Detector.

Useful for ad-hoc experiments or for scoring with external services during an evaluation sweep.

Parameters:
  • fn (Any)

  • name (str)

score_batch(prompts, responses)[source]

Forward to the wrapped callable and validate its output shape.

Parameters:
Return type:

ndarray