mixle.task.distill module¶
Distill a big teacher into a tiny local TaskModel: teacher labels data, a small student learns to match.
The vision in one function. The teacher is any callable that labels text – a frontier LM behind an endpoint,
a slow rule, a human-curated map – exercised once over an unlabeled corpus. The student is a small classifier
over dependency-free hashed n-gram features (HashedNGram), trained to reproduce the
teacher’s labels, and returned as a TaskModel you save and call locally at a fraction
of the teacher’s cost. agreement measures how faithfully the student mimics the teacher on held-out text –
the number tune_recipe() optimizes when it searches student recipes with mixle.doe.
Only the student fit needs torch; the teacher is opaque. distill is deterministic given seed.
- distill(teacher, texts, *, labels=None, n=3, dim=256, hidden=(64,), epochs=200, lr=1e-2, seed=0, task='', device='cpu')[source]
Label
textswithteacher, fit a small student to match, and return a callableTaskModel.n/dimsize the hashed n-gram featurizer;hiddenthe student MLP.labelsfixes the label set (else inferred from the teacher’s outputs). The student’s train-set agreement with the teacher is recorded inmeta.
- distill_from_labels(texts, teacher_labels, *, labels=None, n=3, dim=256, hidden=(64,), epochs=200, lr=1e-2, seed=0, task='', device='cpu')[source]
Fit a student from already-labeled
(texts, teacher_labels)– the teacher-free training core ofdistill.Active labeling (
mixle.task.active) uses this to avoid re-querying the teacher: it controls exactly which examples were paid for and passes their labels straight in.labelsfixes the label set so a student trained on a partial sample still spans every class.
- distill_records(teacher, records, *, labels=None, dim=256, hidden=(64,), epochs=200, lr=1e-2, seed=0, task='', device='cpu')[source]
Distill a teacher into a record classifier (
record -> labelover tuples/dicts of mixed fields).The structured-data sibling of
distill(): classify a transaction, route a ticket, categorize a record. Uses the hashing-trickHashedRecordfeaturizer, so it needs no fitted encoder.
- distill_records_from_labels(records, teacher_labels, *, labels=None, dim=256, hidden=(64,), epochs=200, lr=1e-2, seed=0, task='', device='cpu')[source]
Teacher-free record-classifier training core (mirrors
distill_from_labels()for structured records).
- distill_structured(teacher, records, *, labels=None, n_components=1, min_gain=0.0, n_bins=4, max_its=30, seed=0, task='')[source]
Distill a teacher into a tiny structured probabilistic classifier – a learned Bayesian network, not an MLP.
The teacher labels
records;mixle.inference.structure.learn_structure()then discovers the dependency forest over the joint(field_1, ..., field_m, label)and fits it. The student classifies by the generative ruleargmax_label P(features, label)– and becausesoftmax_label log P(features, label) = P(label | features)exactly, its confidence is a real posterior the cascade/calibration stack can trust. Unlikedistill_records()(a hashed-feature MLP), this student is interpretable (model.edges()lists the discovered dependencies), a few kilobytes on disk, and needs no torch to run.n_components > 1fits aMixtureOfDependencyTrees– a latent-cluster student whose sub-structures differ by regime. Assumes a fixed record schema (seeStructuredClassifierIO).
- distill_structured_from_labels(records, teacher_labels, *, labels=None, n_components=1, min_gain=0.0, n_bins=4, max_its=30, seed=0, task='')[source]
Teacher-free core of
distill_structured(): fit a structured classifier from labeled records.