Learn R Programming

ggmlR (version 0.6.1)

ag_embedding: 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)

Value

An ag_embedding environment

Arguments

vocab_size

Vocabulary size

dim

Embedding dimension

Details

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

Examples

Run this code
# \donttest{
emb <- ag_embedding(100L, 16L)
idx <- c(0L, 3L, 7L, 2L)
out <- emb$forward(idx)   # [16, 4]
# }

Run the code above in your browser using DataLab