| ggml_layer_positional_embedding | R Documentation |
Adds a learned vector to each position of a sequence, so that attention –
which is order-blind on its own – can tell one position from another. The
table is [d_model, seq_len], one row per position, added to the input
and broadcast over the batch.
ggml_layer_positional_embedding(model, name = NULL, trainable = TRUE)
model |
A |
name |
Optional character name for the layer. |
trainable |
Logical; whether the table is updated during training. |
Unlike ggml_layer_embedding there are no indices to look up:
the position IS the place in the sequence, so this layer takes the sequence
itself and returns it with the positional term added. The shape is
unchanged.
The model with the layer appended, or a new ggml_tensor_node
of the same shape as the input.
ggml_layer_attention, ggml_layer_embedding
# Without this the encoder cannot distinguish "ab" from "ba".
x <- ggml_input(shape = c(10L, 32L))
h <- x |> ggml_layer_positional_embedding()
h <- h |> ggml_layer_attention(d_model = 32L, n_heads = 4L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.