Create Triplets API

Training-pair projection from canonical supervision pair facts.

Positive/negative combinatorics reproduce the legacy generator: a positive is a canonical, within-sector pair that is neither an exclusion nor a unary pair (Req 9: a five-digit code and its only six-digit child); a negative j for (anchor a, positive p) requires the directed rows p -> j and a -> j; cross-sector negatives are capped per (anchor, positive). A pair is cross-sector when it carries the cross_sector relation label. An explicit exclusion of the anchor, in either direction, is never a negative (Req 8). Semantics are explicit columns: structural values are never overloaded to carry exclusion meaning.

build_training_pairs(pair_facts, *, cross_sector_cap=CROSS_SECTOR_NEGATIVE_CAP, cap_seed=CROSS_SECTOR_CAP_SEED)

Build every training pair from canonical pair facts.

Parameters:

Name Type Description Default
pair_facts DataFrame

Canonical pair facts with directional exclusion provenance.

required
cross_sector_cap int

Maximum cross-sector negatives per (anchor, positive).

CROSS_SECTOR_NEGATIVE_CAP
cap_seed int

Seed for the stable ranking that chooses capped negatives.

CROSS_SECTOR_CAP_SEED

Returns:

Type Description
DataFrame

Validated training pairs sorted by (anchor, positive, negative) code IDs.

iter_training_pair_batches(pair_facts, *, cross_sector_cap=CROSS_SECTOR_NEGATIVE_CAP, cap_seed=CROSS_SECTOR_CAP_SEED, max_pairs_per_batch=MAX_PAIRS_PER_BATCH)

Yield validated training pairs in ascending-anchor batches, each sorted by (anchor, positive, negative). Batching bounds memory: every (anchor, positive) can carry thousands of cross-sector candidates before the cap applies.