Skip to content

Commit 2ad5ab2

Browse files
Implement Vector-Derived Transformation Binding (#149)
* WIP implementing VTB model * [github-action] formatting fixes * Implement efficient binding method and add tests * [github-action] formatting fixes * Update documentation --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a346f40 commit 2ad5ab2

15 files changed

+685
-163
lines changed

docs/torchhd.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ VSA Models
8585
MAPTensor
8686
HRRTensor
8787
FHRRTensor
88+
VTBTensor
8889

8990

9091
Utilities

torchhd/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from torchhd.tensors.map import MAPTensor
3535
from torchhd.tensors.hrr import HRRTensor
3636
from torchhd.tensors.fhrr import FHRRTensor
37+
from torchhd.tensors.vtb import VTBTensor
3738

3839
from torchhd.functional import (
3940
ensure_vsa_tensor,
@@ -84,6 +85,7 @@
8485
"MAPTensor",
8586
"HRRTensor",
8687
"FHRRTensor",
88+
"VTBTensor",
8789
"functional",
8890
"embeddings",
8991
"structures",

torchhd/embeddings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,9 @@ def __init__(
806806
self.out_features = out_features
807807
self.vsa = vsa
808808

809-
if vsa not in {"MAP", "HRR"}:
809+
if vsa not in {"MAP", "HRR", "VTB"}:
810810
raise ValueError(
811-
f"Projection embedding only supports MAP and HRR but provided: {vsa}"
811+
f"Projection embedding supports MAP, HRR, VTB but provided: {vsa}"
812812
)
813813

814814
self.weight = nn.parameter.Parameter(
@@ -877,9 +877,9 @@ def __init__(
877877
self.out_features = out_features
878878
self.vsa = vsa
879879

880-
if vsa not in {"MAP", "HRR"}:
880+
if vsa not in {"MAP", "HRR", "VTB"}:
881881
raise ValueError(
882-
f"Sinusoid embedding only supports MAP and HRR but provided: {vsa}"
882+
f"Sinusoid embedding supports MAP, HRR, VTB but provided: {vsa}"
883883
)
884884

885885
self.weight = nn.parameter.Parameter(

torchhd/functional.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from torchhd.tensors.map import MAPTensor
3333
from torchhd.tensors.hrr import HRRTensor
3434
from torchhd.tensors.fhrr import FHRRTensor
35+
from torchhd.tensors.vtb import VTBTensor
3536
from torchhd.types import VSAOptions
3637

3738

@@ -82,6 +83,8 @@ def get_vsa_tensor_class(vsa: VSAOptions) -> Type[VSATensor]:
8283
return HRRTensor
8384
elif vsa == "FHRR":
8485
return FHRRTensor
86+
elif vsa == "VTB":
87+
return VTBTensor
8588

8689
raise ValueError(f"Provided VSA model is not supported, specified: {vsa}")
8790

@@ -540,9 +543,9 @@ def circular(
540543
"""
541544
vsa_tensor = get_vsa_tensor_class(vsa)
542545

543-
if vsa_tensor == HRRTensor:
546+
if vsa == "HRR" or vsa == "VTB":
544547
raise ValueError(
545-
"The circular hypervectors don't currently work with the HRR model. We are not sure why, if you have any insight that could help please share it at: https://github.com/hyperdimensional-computing/torchhd/issues/108."
548+
"The circular hypervectors do currently not work with the HRR and VTB models. We are not sure why, if you have any insight that could help please share it at: https://github.com/hyperdimensional-computing/torchhd/issues/108."
546549
)
547550

548551
# convert from normalized "randomness" variable r to

0 commit comments

Comments
 (0)