Skip to contents

Combines one-hot encoding and linear projection in a single efficient operation to convert categorical indices to embeddings.

Usage

one_hot_and_linear(num_classes, embed_dim)

Arguments

num_classes

Integer. Number of distinct categories for one-hot encoding.

embed_dim

Integer. Output embedding dimension.

Value

A nn_module that transforms integer indices to dense embeddings.

Examples

if (FALSE) { # \dontrun{
encoder <- one_hot_and_linear(num_classes = 10L, embed_dim = 32L)
indices <- torch_randint(1L, 11L, c(2L, 20L))  # [batch, seq_len]
embeddings <- encoder(indices)  # [batch, seq_len, embed_dim]
} # }