Skip to content

feat: add LearnabilityBatchSampler — variance-weighted example selection#338

Open
LakshyAAAgrawal wants to merge 1 commit into
mainfrom
feat/learnability-batch-sampler
Open

feat: add LearnabilityBatchSampler — variance-weighted example selection#338
LakshyAAAgrawal wants to merge 1 commit into
mainfrom
feat/learnability-batch-sampler

Conversation

@LakshyAAAgrawal

Copy link
Copy Markdown
Contributor

Summary

Add a new BatchSampler that 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 minibatch
  • temperature — controls sampling concentration:
    • 0.0 — deterministic: always pick the top-K highest-variance examples
    • 1.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 to EpochShuffledBatchSampler until then)

Usage

from gepa.strategies.learnability_sampler import LearnabilityBatchSampler

result = gepa.optimize(
    ...,
    batch_sampler=LearnabilityBatchSampler(minibatch_size=5, temperature=0.5),
)

Test plan

  • 483 tests pass (7 new)
  • pyright: 0 errors
  • Tests cover: variance computation, temperature=0 deterministic mode, fallback behavior, determinism with seed, high/low temperature distribution shapes

🤖 Generated with Claude Code

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>
@semanticdiff-com

semanticdiff-com Bot commented Apr 17, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  src/gepa/strategies/learnability_sampler.py  0% smaller
  tests/test_learnability_sampler.py  0% smaller

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants