Learner and Escalator¶
Noncommercial licence
These classes are in vegaml-learn, which is free for noncommercial use only (PolyForm Noncommercial 1.0.0). A company needs a commercial licence: embedding.in/licence. See Licensing.
Guide: continuous learning.
Learner ¶
Learner(
questions=None,
examples=None,
*,
bundle=None,
model=None,
device=None,
workdir=None,
every=50,
auto=True,
max_drop=0.2,
phase_out=True,
max_rows=5000,
keep=3,
cache=4096,
follow=0,
reader=None,
on_event=None,
modality="text",
context="full",
budget=DEFAULT_BUDGET,
frames=4,
asr=None,
language=None,
)
questions: vegaml questions, {id: {"type": "choice" | "boolean" | "score", "instructions",
"criteria"}}.
examples: an optional starting set, [(text, {question id: answer})]. A question with enough examples
starts
with a head fitted on them; one with none starts with vega's own answers and learns from yours.
bundle: instead of questions and examples, a learner bundle (a .zip or folder with vega/learn.json and
vega/start.npz, as save_bundle() writes it) to start from.
model / device: the vega checkpoint and device (default: vegaml's default model, cuda when present).
workdir: where learned state is saved and resumed from (None: nothing is saved).
every: learn after this many confirmed answers. auto: learn in a background thread.
max_drop: a batch the current heads agree with this much less than they agree with your answers so
far is
held for review (a broken feed, or a real change of policy that someone should confirm).
follow: seconds between reloads of the newest state in workdir, for a read-only copy (0: off).
A follower never learns; one writer learns and saves, any number of followers answer.
modality: what this learner reads. "text" takes text, conversations, audio (its transcript) and
clips with speech; "image" takes pictures (with any words beside them) and silent clips (their
frames). The two are read through different paths, so they are separate learners. A record is
a string, or a dict as vegaml_learn.as_record describes (text / image / images / audio / video,
or turns of them).
context / budget: what is read of a long conversation ("full", "recent" or "last") within budget
characters, keeping the newest turns. frames / asr / language: how clips are sampled and
recordings transcribed.
save_bundle ¶
The learned state as a bundle (.zip) another Learner can start from, on another machine.
record ¶
A record ready for this learner: a string, a vegaml_learn.Record, or a dict of text / image / images / audio / video or turns of them (transcribed and sampled here, once).
decide ¶
Answer every installed question (or the ids in questions) about one record: a message, or
what record() takes (a picture, a recording, a clip, a conversation).
feedback ¶
One decision whose right answer is now known. answers: {question id: answer}, written as decide()
returns it in "answer" (an option name, true/false, or a level). Returns at once; learning happens
every every answers in the background.
correction: a person is fixing an answer they know was wrong (vega's, or one given earlier). It replaces the earlier answer for the same record and is always learned: the guard that holds a batch disagreeing with what was learned (a broken feed) does not count it, since a correction is meant to disagree.
calibrate ¶
Fit each head's temperature on labelled examples it was not fitted on ([(record, {question id:
answer})]), so its confidence means what it says, and record the start line: the lowest calibrated
confidence above which it was right trust of the time. Attached to this learner at once, applied
by decide(), saved with its state and carried by save_bundle(). Returns per question: temperature,
start line and the calibration error before and after. Calibrate again after much learning.
step ¶
Learn now from what is buffered (at least min_rows, default every). For use without the
thread.
held ¶
Batches that would have made a question worse, kept out until you decide: {question: why, rows, at}.
refresh ¶
Load the newest saved state if it is newer than this one (what a follower does on its timer).
close ¶
Stop the background thread. Answers buffered but not learned yet are dropped; call flush() first to keep them.
Escalator ¶
Escalator(
learner,
teacher,
*,
line=None,
engine_line=None,
audit=0.05,
trust=0.95,
window=300,
min_checked=30,
max_line=0.995,
on_engine=("abstain", "unbound"),
accept_held=True,
seed=0,
)
learner: a vegaml_learn.Learner. teacher: function(text, {question id: question}) returning
{question id: answer}, each answer written as you would write feedback (an option name, true/false,
a level); a question it cannot answer may be left out, and returning None or raising means no
answer at all (vega's answer is served and nothing is learned).
line: the confidence a head answer needs to skip the teacher, to start with; it then follows the
measurements, per question. "calibrated": each question starts at the start line its calibration
measured (Learner.calibrate, or a calibrated bundle), so a calibrated starting set saves from the
first request; audits and the customer's own checks still move it. None (the default): trust is
earned, so a head answers alone only once min_checked of its answers have been checked against
the teacher and agreed often enough; until then every head answer is checked. A number trusts
heads above it from the start.
engine_line: the same for vega's own answers (before a head takes a question over): None earns it
the same way, since an untaught engine can be confident and wrong on a new kind of record (a
bare name, a one-word reply); 0 trusts every engine answer that carries no abstain or unbound
flag (the behaviour before vegaml 0.19).
audit: the share of answers vega was sure of that still go to the teacher, to keep measuring.
trust: how often vega's answers above the line must agree with the teacher's: one number for every
question, or {question id: number} to hold each to its own bar (a low-stakes label can be
trusted sooner than a safety flag); questions left out get 0.95. set_trust() changes it later.
window: how many teacher-checked head answers per question the measurement keeps.
min_checked: the fewest checked answers above a line before that line can be chosen.
max_line: the line when no confidence has earned trust yet (only audits skip the teacher above it,
so the measuring never stops).
on_engine: the engine flags that send an answer to the teacher.
accept_held: the learner holds a batch that sharply disagrees with what it learned (a broken feed,
or a real change of policy) for someone to decide. With a teacher, the teacher is that someone,
so held batches are learned (and counted in the report); False leaves them for a person.
decide ¶
Answer one record. Every answer says who gave it ("source": "vega" or "teacher") and, when the teacher was asked, why ("escalated": "abstain", "unbound", "below line" or "audit").
shadow: ask the teacher about every question and serve its answers, while vega still answers, learns and is measured. An answer vega would have kept is marked "escalated": "shadow", and its agreement with the teacher is counted like an audit's, so the report shows how often vega would have been right before anyone lets it answer alone.
set_trust ¶
Change the bar for some questions ({question id: number}); each line is recomputed at once from the checks already measured, so a lower bar takes effect on the next record.
state ¶
What the Escalator has measured (lines, checks, audits, counts), as JSON-ready data, so a restarted service picks up where it was instead of sending everything to the teacher again.
load_state ¶
Restore what state() returned. Questions this Escalator does not have are ignored.
report ¶
How much the teacher is still needed: overall, over the last 100 records, and per question the line and the agreement measured by audits.
vllm_teacher ¶
vllm_teacher(
base_url="http://localhost:8000/v1",
model=None,
*,
system=SYSTEM,
api_key=None,
thinking=False,
max_tokens=None,
timeout=120.0,
extra_body=None,
usage=None,
)
A teacher backed by a model you serve yourself: vLLM by default, or any OpenAI-compatible server (SGLang, llama.cpp server, Ollama, LM Studio). Nothing leaves the machines you run it on, and there is no cost per call. Start one with, for example:
vllm serve Qwen/Qwen3.8-27B --served-model-name teacher --max-model-len 8192
model: the served model name (None asks the server for its first model).
thinking: let a thinking model reason before answering (slower; off by default). The answer is
constrained by a JSON schema that only admits the questions' own options either way.
extra_body: extra request fields for your server; the default sends vLLM's
chat_template_kwargs to switch thinking off or on, which other servers ignore or reject, so
pass extra_body={} for them.
usage: an optional dict that collects prompt and completion tokens and the number of calls.
Pick a teacher clearly better than vega on your question: the learner learns up to its teacher, not past it, and audits measure agreement with the teacher, so they cannot catch a teacher that is wrong.
claude_teacher ¶
claude_teacher(
model="claude-opus-5",
*,
system=SYSTEM,
effort="low",
client=None,
fallbacks=True,
max_tokens=4096,
usage=None,
)
A teacher backed by Claude (needs pip install "vegaml-learn[claude]" and ANTHROPIC_API_KEY, or pass a
client). The record and the escalated questions go to Anthropic's API; nothing else does. A refused
record returns no answer, so vega's own answer is served and nothing is learned from it.
usage: an optional dict that collects input and output tokens and the number of calls.