Stochastic introspective mini-batch ascent.
Each of max_steps steps:
- takes the next training minibatch of
bszrows from a seeded shuffle; - runs
num_candidatestrajectories per row, each with a program sampled from the pool by a softmax over mean minibatch scores (temperature); - ranks rows by the gap between their best and worst trajectory scores, then by lowest best score, so variable and then weak behavior is targeted first;
- for the top
num_candidatesrows, builds a new candidate from a sampled pool program with one strategy, chosen at random:append_a_demoadds the best trajectory's final call per predictor as a demonstration (keeping at mostmax_demos),append_a_ruleasks the proposal role to contrast the best and worst trajectory and appends the advice to one predictor's instruction; the positive trajectory is the row's own best when it succeeded and beat its worst; for a weak row with no gap, it is the best successful trajectory of another minibatch row that scored higher. A row with no such positive is skipped, so failures never become demonstrations;
- scores new candidates on the same minibatch and adds them to the pool.
Finally the baseline and the num_final best pool programs by mean
minibatch score are evaluated on the full validation set; only a complete,
eligible validation result is returned.
Options: :bsz (default 4), :num_candidates (default 4), :max_steps
(default 4), :max_demos (default 4), :temperature (default 0.2),
:num_final (default 3).
Differences from DSPy: trajectory variation comes from sampling pool programs, not from changing the model temperature; final selection uses the explicit validation set.