docs/cpp/source/api/nn/embedding.md
Embedding layers map discrete tokens (words, categories, IDs) to dense vector representations. They are the foundation of NLP models and recommendation systems.
Key parameters:
num_embeddings: Size of the vocabulary (number of unique tokens)embedding_dim: Dimension of each embedding vectorpadding_idx: Index that outputs zeros (useful for padding tokens):members:
:undoc-members:
:members:
:undoc-members:
Example:
auto embedding = torch::nn::Embedding(
torch::nn::EmbeddingOptions(10000, 256) // num_embeddings, embedding_dim
.padding_idx(0));
auto indices = torch::tensor({1, 2, 3, 4});
auto embedded = embedding->forward(indices); // [4, 256]
:members:
:undoc-members:
:members:
:undoc-members: