Skip to content

fix(probe_data): support zero, fractional, and seeded weights in dataset blending - #397

Merged
msoedov merged 1 commit into
msoedov:mainfrom
brixtonpham:fix/weighted-dataset-blending
Nov 26, 2026
Merged

msoedov merged 1 commit into
msoedov:mainfrom
brixtonpham:fix/weighted-dataset-blending

Conversation

@brixtonpham

Copy link
Copy Markdown
Contributor

What this changes

Refs #76.

Fixes weighted dataset blending in UnifiedDatasetLoader._merge_weighted (agentic_security/probe_data/unified_loader.py), where repeat_count = max(1, int(weight)) previously included weight == 0.0 datasets and collapsed all fractional weights in (0.0, 2.0) to 1:

from agentic_security.probe_data.models import ProbeDataset
from agentic_security.probe_data.unified_loader import UnifiedDatasetLoader
a = ProbeDataset("a", {}, ["a1", "a2", "a3", "a4"], 40, 0.0)
b = ProbeDataset("b", {}, ["b1", "b2", "b3", "b4"], 40, 0.0)
UnifiedDatasetLoader([])._merge_weighted([(a, 0.0), (b, 1.0)]).prompts
# before: ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4']
# after:  ['b1', 'b2', 'b3', 'b4']
UnifiedDatasetLoader([])._merge_weighted([(a, 0.25), (b, 0.75)]).prompts
# before: ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4']
# after:  ['a1', 'b1', 'b2', 'b3']
  • Excludes weight == 0 sources in load_all() and _merge_weighted() (returning unified_empty when all sources are excluded or empty).
  • Rejects negative, NaN, and infinite weights in InputSourceConfig.weight (allow_inf_nan=False) and _merge_weighted().
  • Scales prompt counts proportionally via target = max(1, round(prompt_count * weight)) (full copies plus remainder sampling) and scales tokens and approx_cost proportionally, preserving existing integer-weight behavior.
  • Adds backwards-compatible optional seed: int | None = None on UnifiedDatasetLoader and _merge_weighted for deterministic fractional sampling and shuffled interleaving.

How it was tested

  • pytest tests/unit/probe_data/test_unified_loader.py -v: 21 passed (6 new tests covering zero-weight exclusion, fractional <1.0 and >1.0 blending + token scaling, seeded determinism/shuffling, and negative/NaN/inf rejection).
  • Full offline unit suite (pytest . -q with placeholder OPENAI_API_KEY): 578 passed, 4 skipped, 594 deselected.
  • Pre-commit checks matching .pre-commit-config.yaml (black --check, flake8, pyupgrade --py314-plus, pycln --check, codespell, poetry check --lock): all clean.

Checklist

  • No real API key, token or customer endpoint anywhere in the code, tests, docs or this description (CONTRIBUTING.md).
  • pytest passes and new behaviour has a test. Tests don't call paid APIs.
  • pre-commit run --all-files is clean.
  • Docs updated if behaviour changed. (Docstrings updated on UnifiedDatasetLoader.__init__ and _merge_weighted.)

@msoedov msoedov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brixtonpham thx for the patch! LGTM

@msoedov
msoedov merged commit 415759b into msoedov:main Nov 26, 2026
2 checks passed
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