BasicRecurrentLayer

BasicRecurrentLayer[n]

represents a trainable recurrent layer that takes a sequence of vectors and produces a sequence of vectors each of size n.

BasicRecurrentLayer[n,opts]

includes options for initial weights and other parameters.

Details and Options

  • BasicRecurrentLayer[n] represents a net that takes a sequence of vectors and outputs a sequence of the same length.
  • Each element of the input sequence is a vector of size k, and each element of the output sequence is a vector of size n.
  • The size k of the input vectors is usually inferred automatically within a NetGraph, NetChain, etc.
  • The input and output ports of the net represented by BasicRecurrentLayer[n] are:
  • "Input"a sequence of vectors of size k
    "Output"a sequence of vectors of size n
  • Given an input sequence {x1,x2,,xT}, a BasicRecurrentLayer outputs a sequence of states {s1,s2,,sT}, where st=Tanh[wi.xt+ws.st-1+b].
  • BasicRecurrentLayer[n] has a single state port, "State", which is a vector of size n.
  • Within a NetGraph, a connection of the form src->NetPort[layer,"State"] can be used to provide the initial value of the state for a BasicRecurrentLayer, corresponding to s0 in the recurrence relation. The default initial value is a zero vector.
  • Within a NetGraph, a connection of the form NetPort[layer,"State"]->dst can be used to obtain the final value of the state for a BasicRecurrentLayer, corresponding to sT in the recurrence relation.
  • An initialized BasicRecurrentLayer[] that operates on vectors of size k contains the following trainable arrays:
  • "InputWeights"Wxmatrix of size n×k
    "StateWeights"Wsmatrix of size n×n
    "Biases"bvector of size n
  • In BasicRecurrentLayer[n,opts], initial values can be given to the trainable arrays using a rule of the form "array"->value.
  • BasicRecurrentLayer[n,"Dropout"->spec] indicates that dropout regularization should be applied during training, in which units are probabilistically set to zero.
  • Specifying "Dropout"->None disables dropout during training.
  • Specifying "Dropout"->p uses an automatically chosen dropout method having dropout probability p.
  • Specifying "Dropout"->{"method1"->p1,"method2"->p2,} can be used to combine specific methods of dropout with the corresponding dropout probabilities. Possible methods include:
  • "VariationalInput"dropout applied to the gate contributions from the input, using the same pattern of units at each sequence step
    "VariationalState"dropout applied to the gate contributions from the previous state, using the same pattern of units at each sequence step
  • The dropout methods "VariationalInput" and "VariationalState" correspond to Gal et al. 2016.
  • BasicRecurrentLayer[n,"Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:
  • NetEncoder[]encoder producing a sequence of vectors
    {len,k}sequence of len length-k vectors
    {len,Automatic}sequence of len vectors whose length is inferred
    {"Varying",k}varying number of vectors each of length k
    {"Varying",Automatic}varying number of vectors each of inferred length

Examples

open allclose all

Basic Examples  (2)

Create a BasicRecurrentLayer that produces a sequence of length-3 vectors:

In[1]:=
Click for copyable input
Out[1]=

Create a randomly initialized BasicRecurrentLayer that takes a sequence of length-2 vectors and produces a sequence of length-3 vectors:

In[1]:=
Click for copyable input
Out[1]=

Apply the layer to an input sequence:

In[2]:=
Click for copyable input
Out[2]//MatrixForm=

Scope  (4)

Options  (2)

Applications  (2)

See Also

GatedRecurrentLayer  LongShortTermMemoryLayer  NetMapOperator  SequenceLastLayer  LinearLayer  NetChain  NetGraph  NetExtract

Introduced in 2017
(11.1)