Set
North Market can have several merchant tags, such as grocery and essential. Set represents their membership without giving the tag order meaning. These descriptors enrich the payment alongside its amount and merchant identity. Use Category for one label and Branch when each item has its own fields or position.
import relflow as rf
model = rf.Model.xs(
amount=rf.Number,
merchant=rf.Category,
merchant_tags=rf.Set,
disputed=rf.Boolean(mask=True),
)One labeled payment:
amount: 84.50
merchant: North Market
merchant_tags:
- grocery
- essential
disputed: falseInput and options
An Arrow list holds the labels; a scalar label is treated as a one-member set. Labels may be Boolean, integer, floating-point, string, or binary, with one compatible Arrow type family per field. Duplicate members collapse, and null members are ignored, as are NaN members of floating-point sets. An empty list is valued; a null list has state null.
| Option | Default | Meaning |
|---|---|---|
p_unavailable |
0.01 |
Training probability of hiding each known positive input member. Reconstruction answers remain intact. |
threshold |
None |
Prediction filter in [0, 1]; retain labels whose probability meets it. None returns every populated label. |
strip |
False |
Trim surrounding whitespace from string labels before vocabulary lookup. |
cased |
True |
False lowercases string labels before lookup. Vocabulary snapshots and written labels hold the folded form; other label types are unaffected. |
See shared leaf options for target and embedding configuration.
Vocabulary and learning
Vocabulary storage grows automatically, with no size option to configure. The shared Online vocabulary contract covers admission order, growth and state preservation, supported training strategies, and checkpoint reuse.
The training process binds batch-local member dictionaries before forward, growing embedding rows, membership width, counters, and decoder rows as needed. Validation, test, and prediction reuse the frozen mapping. For an application-supplied trained model:
labels = rf.Set.vocabulary(model, rf.Address("merchant_tags"))This tuple snapshot lists populated labels in index order. It also accepts a preprocessor’s encoding_context; consult established vocabularies for inference preprocessing, not to decide which training labels may be learned.
Content lists each set’s distinct known member identities as compact indices, padded to the widest set in the batch, plus a count of distinct unavailable members; dense membership over the allocation forms only where the reconstruction loss needs it. Unknown identities take no index; duplicates and member order do not affect either representation, and storage grows with observed members rather than with the vocabulary. The encoder averages known member embeddings and adds a learned contribution when any member is unavailable, plus the value-state embedding. That contribution starts at zero; real or simulated OOV training teaches it. It distinguishes unavailable membership from genuinely empty input without inventing unknown identities.
Reconstruction combines unweighted state classification with binary cross entropy over populated labels in valued target sets. Unallocated slots are not negative examples of future labels. Complete set annotations are assumed: known positives and known negatives remain supervised even in a partial-OOV or all-OOV set. Unknown members cannot supply identity-specific positives. An empty set supplies known negatives; null is a separate state.
Metrics use a fixed 0.5 cutoff. Training scores describe the latest batch; validation and test use summed counts across batches and DDP ranks:
| Metric | Meaning |
|---|---|
targets.known, targets.unavailable |
Counts of distinct positive memberships per selected valued set, summed across observations. |
coverage.content |
Known positive memberships / all positive memberships. |
sets.valued, sets.complete, coverage.set |
Selected valued sets, sets with no unknown members, and their complete fraction. Empty sets are complete. |
loss.content, accuracy.content |
BCE and bit accuracy over populated membership slots only. |
accuracy.set |
Exact-set accuracy; any unknown target member makes the complete answer unrecoverable. |
precision.content, recall.content, f1.content |
Micro membership scores on known labels. |
recall.all, f1.all |
Micro scores also counting unknown target members as missed positives. |
An empty denominator yields NaN, not perfect reconstruction. Bit accuracy alone can still be misleading for sparse sets; examine F1, exact-set accuracy, and coverage together. Output threshold does not change these metrics.
P063 tests probability preservation and coverage; P064 tests learning the empty/unknown distinction.
Prediction
content is a list of value / probability structs, with string labels and independent membership probabilities. Only populated vocabulary entries appear. The configured threshold filters this list; it changes neither training metrics nor the decoder computation over the current allocation.
See the prediction envelope for shared state probabilities, inferred, and repeated shapes.