mixle.task.extract module¶
Structured extraction: distill a teacher into a compact sequence tagger for typed text fields.
Use this module when brittle regular expressions or hand-written parsers are no longer enough for
semi-structured text such as invoices, support tickets, orders, or clinical notes. The student model learns
to extract fields such as id, amount, or date from labeled examples and can be retrained when
the source format changes. The model is token-level: tokenizer and orthographic features, then an embedding,
bidirectional GRU, per-token BIO tags, and a decoder back to {field: value}. Labels can come from an LLM
teacher, a rule-based teacher, or gold annotations.
distill_extractor(teacher, texts, fields) returns a callable TaskModel:
model(text) -> {field: value}. It saves through the same durable artifact (vocab + tag scheme in the
manifest, weights in safetensors) and loads in a fresh process. extraction_f1 scores span-level fidelity.
- tokenize(text)[source]
Split
textinto(token, start, end)triples: runs of digits, letters, or single punctuation.
- build_seq_tagger(vocab_size, n_tags, *, d_model=64, hidden=64, n_feats=_N_FEATS)[source]
A bidirectional-GRU sequence tagger:
(token_ids, features) -> per-token tag logits.
- class ExtractionIO(vocab, fields, *, max_len=128)[source]
Bases:
objecttext -> {field: value}: tokenize, tag (BIO), decode spans back to substrings of the original text.- kind = 'extraction'
- predict_batch(module, texts)[source]
- predict_with_confidence(module, texts)[source]
Extract each record and a confidence in
[0, 1]: the min per-token tag probability over tagged tokens.A low confidence or a missing field is an explicit signal that the format may be unfamiliar and should be escalated. Returns
0.0when nothing was tagged.
- distill_extractor(teacher, texts, fields, *, max_vocab=5000, d_model=64, hidden=64, epochs=60, lr=5e-3, max_len=128, seed=0, device='cpu', task='')[source]
Distill a teacher’s extractions into a tiny sequence tagger; return
model(text) -> {field: value}.