mixle.task.design module¶
LLM-designed models: let an LLM propose the mixle structure from data – and make mixle validate it.
The hardcoded auto-estimator (mixle.task.recommend.recommend_model()) is a fine fallback, but the
differentiator is flexibility: an LLM can read a data profile and propose a structure no fixed heuristic encodes
– a mixture here, a heavy-tailed leaf there, a composite of mixed families. The risk with “LLM picks the model”
is hallucination; the answer is grounding. The LLM emits a small, allowlisted JSON spec (no code, no eval);
spec_to_estimator() builds a real mixle estimator from it; and design_model() fits it before
trusting it, falling back to the heuristic when the LLM is unavailable or its spec fails to build or fit.
So the LLM proposes and mixle disposes: you get flexible, data-aware model design with a hard correctness gate
(it must parse, build, and fit), not a plausible-looking guess. design_model(data, llm) returns the chosen
estimator, the spec, and whether it came from the LLM or the fallback.
- spec_to_estimator(spec)[source]
Build a mixle estimator from an allowlisted spec dict (recursively); raise on anything off the allowlist.
- Specs:
{"family": "<name>"}– a scalar leaf (seeALLOWED_FAMILIES);{"type": "composite", "fields": [spec, ...]}– a tuple record of sub-models;{"type": "mixture", "k": K, "component": spec}– a K-component mixture of the component model.
- data_profile(data, *, max_rows=500)[source]
A compact, family-agnostic description of
datafor the LLM: per-field kind and a few sample values.
- class DesignedModel(estimator, spec, source, note='')[source]
Bases:
objectThe model an LLM (or the fallback) designed: the estimator, the spec it built from, and the source.
- estimator: Any
- source: str
- note: str = ''
- design_model(data, llm, *, fallback=True, validate_rows=200)[source]
Ask
llmto design a model fordata; build, fit-validate, and fall back to the heuristic on failure.The LLM sees a compact
data_profile()and returns a JSON spec; the spec is built into a real estimator and fit on a sample to prove it works. Any failure (no LLM, bad JSON, off-allowlist family, fit error) yields the heuristicmixle.task.recommend.recommend_model()estimator whenfallbackis set.