mixle.inference.synthesize module

Verified synthetic dataset creation.

synthesize draws inputs from a generative source, optionally labels them with a teacher callable, and optionally filters them through a verifier. The result is a Dataset that carries its verifier so consumers can recheck rows independently.

Supported sources include:

  • a fitted model with a sampler;

  • a list of real inputs, from which a generator is inferred and sampled;

  • a callable () -> input or rng -> input.

Without label the result is unlabeled. Without verify every draw is accepted. max_tries bounds rejection sampling so an impossible verifier raises IncompleteSynthesisError instead of looping indefinitely – a returned Dataset therefore always holds exactly the requested number of verified rows. The partially built dataset travels on the exception’s dataset attribute for callers that want to inspect what did pass.

class Dataset(inputs, labels=None, verify=None, acceptance_rate=1.0, n_rejected=0, provenance=<factory>)[source]

Bases: object

A verified synthetic dataset: inputs, optional labels, and the verifier that vouched for them.

inputs and labels stay ordinary mutable lists, but a labeled dataset must always hold exactly one label per input. That alignment is checked at construction and again before every operation that walks the rows, so a post-construction edit that leaves the two out of step is reported instead of silently truncating the rows that get iterated, paired, or rechecked.

Parameters:
require_aligned()[source]

Raise unless every input carries exactly one label (vacuous for an unlabeled dataset).

Return type:

None

pairs()[source]

(input, label) pairs – raises if the dataset is unlabeled or misaligned.

Return type:

list[tuple[Any, Any]]

recheck()[source]

Re-run the attached verifier over every row.

Returns True when every row still passes, or when no verifier is attached. Raises if the dataset is misaligned – a partial recheck that skipped unlabeled inputs would report a pass it never made.

Return type:

bool

exception IncompleteSynthesisError(message, dataset)[source]

Bases: RuntimeError

Synthesis exhausted its attempt budget before producing the requested number of verified rows.

dataset holds the rows that did pass, so a caller that genuinely wants a short dataset can take it deliberately rather than receiving one that looks like the full request.

Parameters:
  • message (str)

  • dataset (Dataset)

Return type:

None

synthesize(source, *, label=None, verify=None, n=100, max_tries=None, seed=0)[source]

Build a verified dataset of n accepted rows from a generative source (see module docstring).

source is a fitted model (sampled), a list of real inputs (a generator is inferred over them), or a callable draw function. label (optional) is the teacher applied to each input. verify (optional) accepts verify(x) or verify(x, label) and gates each row – rejected rows are resampled up to max_tries total draws. The verifier is attached to the returned Dataset so consumers can recheck() independently.

n must be an exact non-negative integer (bool is not an integer here). A returned dataset always holds exactly n verified rows; if the attempt budget, an impossible verifier, a short sampler, or real-input deduplication leaves it short, IncompleteSynthesisError is raised with the partial dataset attached rather than a shortfall being returned as an ordinary result.

Parameters:
Return type:

Dataset