Set
Use Set for multi-label discrete values or targets from a bounded, learned vocabulary: tags, permissions, flags, detected concepts, applicable categories, and similar multi-label fields.
{
"tags": ["vip", "international", "vip"]
}import json2vec as jv
tags = jv.Set(
"tags",
size=2048,
p_unavailable=0.02,
threshold=0.75,
)
tagstags [set] active
pooling=query weight=1 p_mask=0 p_prune=0 n_heads=4 n_linear=1
size=2048 p_unavailable=0.02 threshold=0.75
The input to a Set and a Branch of Category values can look similar, but use Set("tags") for unordered labels. An Branch of Category expects order or item-level structure to matter.
Input Values
Set accepts common multi-label shapes:
Nonebecomes a null field state.- A string becomes a single-item set.
- An iterable becomes a multi-item set.
- A non-iterable scalar becomes a single-item set.
- An empty iterable becomes a valued field with no active labels.
Repeated labels collapse into one active vocabulary entry. The vocabulary is learned online from training data and saved with the model.
Examples
Common set fields include:
- Product tags, content topics, user interests, or applicable policies.
- Permissions, feature flags, alert codes, or rule hits.
- Detected entities or concepts from an upstream parser.
- Multi-label outcomes where more than one class can be true at once.
Use Branch(tag=Category()) instead when repeated labels need positions, attributes, or their own local context.
Configuration
| Option | Default | Notes |
|---|---|---|
size |
10000 |
Maximum number of learned labels. One extra internal bucket is reserved for unavailable labels. |
p_unavailable |
0.01 |
During training, randomly routes known labels to the unavailable bucket so the decoder learns that case. |
threshold |
None |
Optional prediction-time probability threshold. When set, prediction output only includes labels at or above the threshold. |
Target Behavior
When a Set is masked or used as a target, the decoder predicts:
state: probabilities forvalued,null,padded, andmasked.content: independent logits for each learned vocabulary item.
Content loss uses binary cross entropy because each label is independently present or absent.
Prediction Output
Without threshold, Model.predict(...) returns state probabilities and one probability array per known label:
{
"record/tags": {
"state": {"valued": ..., "null": ..., "padded": ..., "masked": ...},
"content": {
"vip": ...,
"international": ...,
},
}
}{"record/tags": {"state": {"valued": "text/plain:Ellipsis", "null": "text/plain:Ellipsis", "padded": "text/plain:Ellipsis", "masked": "text/plain:Ellipsis"}, "content": {"vip": "text/plain:Ellipsis", "international": "text/plain:Ellipsis"}}}With threshold=0.75, content is a nested JSON-like structure that only includes labels whose probabilities meet the threshold:
{
"record/tags": {
"state": {"valued": ..., "null": ..., "padded": ..., "masked": ...},
"content": {"vip": 0.91},
}
}{"record/tags": {"state": {"valued": "text/plain:Ellipsis", "null": "text/plain:Ellipsis", "padded": "text/plain:Ellipsis", "masked": "text/plain:Ellipsis"}, "content": {"vip": "text/plain+float:0.91"}}}Notes
Unknown labels at validation, test, or inference time are represented internally with the reserved unavailable bucket. Prediction output only includes labels in the learned vocabulary. Thresholding is an inference-output filter; it does not change training loss.