mixle.task.generative_text module¶
A GENERATIVE text student – per-class token models, so the classifier owns a real p(x).
The moat meeting the product: instead of a discriminative hashed-feature net, the student is a set of
mixle generative models – one multinomial p(tokens | class) per label (a token Categorical fit by
the ordinary estimator machinery; a document scores as the sum of its token logs) plus class log-priors. Classification is the exact posterior
P(class | x) (softmax of the per-class log-joints), and – the part a softmax net cannot offer –
log p(x) = logsumexp_c log p(x, c) comes for free, so the same student scores how typical an input
is without a separate density gate.
Rare and unseen tokens clamp to <unk> (vocabulary = tokens seen at least min_count times), and
every class is Laplace-smoothed over the SHARED vocabulary — so a word the class never saw (or a novel
word) dims its likelihood smoothly instead of vetoing it to -inf.
Drop-in with the rest of the spine: distill_text_generative(teacher, texts) returns a
TaskModel whose adapter exposes proba_batch, so conformal calibration,
solve(student="generative"), cascades, and routers all work unchanged.
- class GenerativeTextIO(labels, vocab, log_prior)[source]
Bases:
objectAdapter over
{label: fitted p(tokens|label)}+ log-priors: exact posteriors andlog p(x).- kind = 'generative_text'
- logits_batch(model, raw_inputs)[source]
log P(tokens, label)per label – an(m, K)matrix (multinomial: sum of token logs).
- proba_batch(model, raw_inputs)[source]
The exact class posterior (softmax of log-joints; the shared evidence cancels).
- log_evidence(model, raw_inputs)[source]
Per-token
log p(x)(length-normalized) – the built-in typicality/OOD score.Raw document evidence scales with length (a short gibberish string would outrank a long in-domain one), so typicality is reported per token: mean log-probability under the full generative model.
- predict_batch(model, raw_inputs)[source]
- distill_text_generative_from_labels(texts, teacher_labels, *, labels=None, pseudo_count=1.0, min_count=2, task='')[source]
Fit the per-class token models from already-labeled texts (the teacher-free training core).
- distill_text_generative(teacher, texts, *, labels=None, pseudo_count=0.5, min_count=2, task='')[source]
Distill a teacher into the generative text student (the teacher labels; see module docstring).