Learn R Programming

ggmlR (version 0.8.4)

ggml_dense: Create a Dense Layer Object

Description

Returns a reusable layer object for use with ggml_apply(). Applying the same object to multiple tensor nodes shares weights.

Usage

ggml_dense(
  units,
  activation = NULL,
  name = NULL,
  trainable = TRUE,
  time_distributed = FALSE
)

Value

A ggml_layer object.

Arguments

units

Number of output units.

activation

Activation function name or NULL.

name

Optional character name.

trainable

Logical; whether weights are updated during training.

time_distributed

Logical; apply the kernel independently at every position of a sequence input rather than flattening it (default FALSE). A c(seq_len, features) parent then yields c(seq_len, units) instead of a flat units, which is what a transformer's position-wise feed-forward sublayer needs. See ggml_layer_dense for details.

Examples

Run this code
# \donttest{
encoder <- ggml_dense(64L, activation = "relu")
x1 <- ggml_input(shape = 32L)
x2 <- ggml_input(shape = 32L)
out1 <- x1 |> ggml_apply(encoder)
out2 <- x2 |> ggml_apply(encoder)  # shared weights
# }

Run the code above in your browser using DataLab