ag_embedding: Create an Embedding layer

View source: R/ag_layers.R

ag_embeddingR Documentation

Create an Embedding layer

Description

Maps 0-based integer indices to dense vectors via table lookup. Input: integer matrix or vector of 0-based indices. Output: float tensor [dim, length(idx)].

Usage

ag_embedding(vocab_size, dim)

Arguments

vocab_size

Vocabulary size

dim

Embedding dimension

Details

Backward: scatter-add — only the looked-up rows accumulate gradient.

Value

An ag_embedding environment

Examples


emb <- ag_embedding(100L, 16L)
idx <- c(0L, 3L, 7L, 2L)
out <- emb$forward(idx)   # [16, 4]


ggmlR documentation built on July 14, 2026, 1:08 a.m.