Skip to contents

Backward states are re-aligned to the original time index before the concatenation, so output[t, ] mixes prefix and suffix at t.

Usage

morie_geron_bidirectional_rnn(
  X,
  Wx_f,
  Wh_f,
  Wx_b,
  Wh_b,
  b_f = NULL,
  b_b = NULL,
  h0_f = NULL,
  h0_b = NULL,
  activation = "tanh"
)

Arguments

X

Sequence (T, d).

Wx_f, Wh_f, Wx_b, Wh_b

Weight matrices.

b_f, b_b, h0_f, h0_b

Optional biases and initial states.

activation

One of "tanh", "relu", "sigmoid", "identity".

Value

List with output, h_fwd, h_bwd, final, hidden_size.

Examples

morie_geron_bidirectional_rnn(matrix(c(1, 1, 0.5), ncol = 1),
    matrix(1), matrix(0.5), matrix(1), matrix(-0.5))
#> $output
#>           [,1]      [,2]
#> [1,] 0.7615942 0.5894633
#> [2,] 0.8811296 0.6463135
#> [3,] 0.7354816 0.4621172
#> 
#> $h_fwd
#>           [,1]
#> [1,] 0.7615942
#> [2,] 0.8811296
#> [3,] 0.7354816
#> 
#> $h_bwd
#>           [,1]
#> [1,] 0.5894633
#> [2,] 0.6463135
#> [3,] 0.4621172
#> 
#> $final
#> [1] 0.7354816 0.5894633
#> 
#> $hidden_size
#> [1] 1
#> 
#> $estimate
#> [1] 0.6793499
#> 
#> $n
#> [1] 3
#> 
#> $method
#> [1] "Bidirectional RNN with concatenated forward/backward states"
#>