SetEncoder¶
Encoder for unordered sets using bundling.
vsax.encoders.SetEncoder
¶
Bases: AbstractEncoder
Encoder for unordered sets using bundling.
Encodes sets by simply bundling all element hypervectors together. Since bundling is commutative, the result is order-invariant.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The VSAModel instance defining the VSA algebra. |
|
memory |
The VSAMemory instance for accessing basis hypervectors. |
Example
from vsax import create_fhrr_model, VSAMemory from vsax.encoders import SetEncoder model = create_fhrr_model(dim=512) memory = VSAMemory(model) memory.add_many(["dog", "cat", "bird"]) encoder = SetEncoder(model, memory) animals_set_hv = encoder.encode({"dog", "cat", "bird"})
Source code in vsax/encoders/set.py
Functions¶
encode(elements)
¶
Encode an unordered set of symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
Union[set[str], list[str]]
|
A set or list of symbol names in memory. |
required |
Returns:
| Type | Description |
|---|---|
AbstractHypervector
|
The encoded hypervector representing the set. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If any symbol in the set is not in memory. |
ValueError
|
If the set is empty. |
Example
encoder = SetEncoder(model, memory) set_hv = encoder.encode({"dog", "cat", "bird"})