Random
- class torchhd.embeddings.Random(num_embeddings: int, embedding_dim: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', requires_grad: bool = False, padding_idx: int | None = None, max_norm: float | None = None, norm_type: float = 2.0, scale_grad_by_freq: bool = False, sparse: bool = False, device=None, dtype=None, **kwargs)[source]
Embedding wrapper around
random().Class inherits from Embedding and supports the same keyword arguments.
- Parameters:
num_embeddings (int) – the number of hypervectors to generate.
embedding_dim (int) – the dimensionality of the hypervectors.
vsa – (
VSAOptions, optional): specifies the hypervector type to be instantiated. Default:"MAP".dtype (
torch.dtype, optional) – the desired data type of returned tensor. Default: ifNoneuses default ofVSATensor.device (
torch.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (see torch.set_default_tensor_type()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.
Examples:
>>> emb = embeddings.Random(4, 6) >>> idx = torch.LongTensor([0, 1, 3]) >>> emb(idx) MAPTensor([[-1., 1., -1., 1., -1., -1.], [ 1., -1., -1., -1., 1., -1.], [ 1., -1., 1., 1., 1., 1.]]) >>> emb = embeddings.Random(4, 6, "BSC") >>> idx = torch.LongTensor([0, 1, 3]) >>> emb(idx) BSCTensor([[ True, False, False, False, False, True], [False, True, True, True, False, True], [False, False, True, False, False, False]])
- forward(input: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.