feat: add LearnabilityBatchSampler — variance-weighted example selection#338
Open
LakshyAAAgrawal wants to merge 1 commit into
Open
feat: add LearnabilityBatchSampler — variance-weighted example selection#338LakshyAAAgrawal wants to merge 1 commit into
LakshyAAAgrawal wants to merge 1 commit into
Conversation
Add a new BatchSampler that prioritizes training examples where
candidates disagree most. For each example, computes the variance of
scores across all evaluated candidates. Higher variance means the
example is more "learnable" — better prompts can make a bigger
difference on it.
Features:
- temperature parameter: 0.0 = deterministic top-K, 1.0 = proportional,
>1.0 = approaches uniform
- min_candidates threshold before learnability weighting kicks in
- Falls back to EpochShuffledBatchSampler when insufficient data
- Deterministic with seeded RNG
Usage:
from gepa.strategies.learnability_sampler import LearnabilityBatchSampler
result = gepa.optimize(
...,
batch_sampler=LearnabilityBatchSampler(minibatch_size=5, temperature=0.5),
)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Changed Files
|
Benzhang2004
added a commit
to Benzhang2004/gepa
that referenced
this pull request
Jul 12, 2026
…amples first (gepa-ai#34) For the combined train+val pool workflow (valset=None), bias reflection minibatches toward the examples with the lowest best-achieved score (state.pareto_front_valset): where even the best candidate scores low, there is the most headroom, so those examples are the most learnable. Score-deficit counterpart to PR gepa-ai#338's variance-weighted LearnabilityBatchSampler. temperature controls concentration (0 = deterministic worst-k with least-sampled tie-breaks, 1 = proportional to deficit, >1 flattens); uniform_mix keeps solved examples in rotation so the optimizer does not drift away from them. Ids without recorded scores are treated as worst; sampling is uniform until any scores exist. Exposed as batch_sampler="worst_first" in gepa.optimize and ReflectionConfig. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
BatchSamplerthat prioritizes training examples where candidate performance varies most — the examples most likely to benefit from prompt improvements.How it works
For each training example, compute the variance of scores across all evaluated candidates. High variance means candidates disagree on this example, so it's "learnable" — better prompts can make a bigger difference. Low variance (all candidates score similarly) means the example provides less optimization signal.
Parameters
minibatch_size— examples per minibatchtemperature— controls sampling concentration:0.0— deterministic: always pick the top-K highest-variance examples1.0(default) — sample proportional to variance> 1.0— flatten toward uniform (exploration)< 1.0— sharpen toward highest-variance (exploitation)min_candidates— minimum candidates evaluated before variance weighting activates (falls back toEpochShuffledBatchSampleruntil then)Usage
Test plan
🤖 Generated with Claude Code