| ggml_layer_sequence_pooling | R Documentation |
Collapses the sequence axis, turning c(seq_len, d_model) into
d_model: the step that lets a classification or regression head sit
on top of an encoder. ggml_layer_flatten() also produces a flat
vector, but keeps every position separately (seq_len * d_model
features), so its width – and the head above it – depends on the sequence
length. Pooling does not.
ggml_layer_sequence_pooling(model, mode = c("mean", "first"), name = NULL)
model |
A |
mode |
|
name |
Optional character name for the layer. |
mode = "mean" averages over the positions; every position
contributes equally, which is the usual choice for an encoder without a
dedicated summary token. mode = "first" takes position 1 and ignores
the rest – the CLS-token convention, where attention is expected to have
gathered what matters into that position.
The model with the layer appended, or a new ggml_tensor_node
of shape d_model.
ggml_layer_flatten, ggml_layer_attention
# An encoder with a regression head: the head's width is d_model, whatever
# the sequence length turns out to be.
x <- ggml_input(shape = c(10L, 32L))
h <- x |> ggml_layer_attention(d_model = 32L, n_heads = 4L)
h <- h |> ggml_layer_sequence_pooling()
y <- h |> ggml_layer_dense(1L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.