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
() -> inputorrng -> 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:
objectA verified synthetic dataset: inputs, optional labels, and the verifier that vouched for them.
inputsandlabelsstay 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.
- exception IncompleteSynthesisError(message, dataset)[source]
Bases:
RuntimeErrorSynthesis exhausted its attempt budget before producing the requested number of verified rows.
datasetholds 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
naccepted rows from a generativesource(see module docstring).sourceis 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) acceptsverify(x)orverify(x, label)and gates each row – rejected rows are resampled up tomax_triestotal draws. The verifier is attached to the returnedDatasetso consumers canrecheck()independently.nmust be an exact non-negative integer (boolis not an integer here). A returned dataset always holds exactlynverified rows; if the attempt budget, an impossible verifier, a short sampler, or real-input deduplication leaves it short,IncompleteSynthesisErroris raised with the partial dataset attached rather than a shortfall being returned as an ordinary result.