Learn R Programming

ggmlR (version 0.6.1)

ggml_layer_gru: Add a GRU Layer

Description

Gated Recurrent Unit recurrent layer. Implemented as an unrolled computation graph (BPTT).

Usage

ggml_layer_gru(
  model,
  units,
  return_sequences = FALSE,
  activation = "tanh",
  recurrent_activation = "sigmoid",
  input_shape = NULL,
  name = NULL,
  trainable = TRUE
)

Value

Updated model or a new ggml_tensor_node.

Arguments

model

A ggml_sequential_model or ggml_tensor_node.

units

Integer, number of hidden units.

return_sequences

Logical; return all hidden states or only the last.

activation

Activation for the candidate hidden state ("tanh").

recurrent_activation

Activation for z/r gates ("sigmoid").

input_shape

Input shape c(seq_len, input_size) -- required for the first layer only.

name

Optional layer name.

trainable

Logical.

Weight layout

  • W_zh [input_size, 2*units] — input kernel for z and r gates.

  • U_zh [units, 2*units] — recurrent kernel for z and r.

  • b_zh [2*units] — bias for z and r.

  • W_n [input_size, units] — input kernel for candidate.

  • U_n [units, units] — recurrent kernel for candidate.

  • b_n [units] — bias for candidate.

Examples

Run this code
# \donttest{
model <- ggml_model_sequential() |>
  ggml_layer_gru(64L, input_shape = c(10L, 32L)) |>
  ggml_layer_dense(10L, activation = "softmax")
# }

Run the code above in your browser using DataLab