Class LSTM
Represents an LSTM
recurrent layer. This generates an output tensor by computing a one-layer LSTM (long short-term memory) on an input tensor.
Inherited Members
Namespace: Unity.Sentis.Layers
Syntax
[Serializable]
public class LSTM : Layer
Constructors
LSTM(String, String[], String[], Int32, RnnDirection, RnnActivation[], Single[], Single[], Single, Boolean, RnnLayout)
Initializes and returns an instance of a Long Short-Term Memory Network (LSTM
) recurrent layer.
Declaration
public LSTM(string name, string[] inputs, string[] outputs, int hiddenSize, RnnDirection direction, RnnActivation[] activations = null, float[] activationAlpha = null, float[] activationBeta = null, float clip = 3.40282347E+38F, bool inputForget = false, RnnLayout layout = RnnLayout.SequenceFirst)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name to use for the first output tensor of the layer. |
String[] | inputs | The names to use for the input tensors of the layer [X, W, R, (B, sequenceLens, initialH, initialC, P)]. X is the name of the input sequences tensor. W is the name of the weights tensor for the gates of the LSTM. R is the name of the recurrent weights tensor for the gates of the LSTM. B is the name of the optional bias tensor for the input gate of the LSTM. sequenceLens is the name of the optional 1D tensor specifying the lengths of the sequences in a batch. initialH is the name of the optional initial values tensor of the hidden neurons of the LSTM. If this is initialC is the name of the optional initial values tensor of the cells of the LSTM. If this is P is the name of the optional weight tensor for the peepholes of the LSTM. If this is |
String[] | outputs | The names for the output tensors of the layer [Y, Y_h, Y_c]. Y is the name of the concatenated intermediate output values tensor of the hidden neurons. Y_h is the name of the last output values tensor of the hidden neurons. Y_c is the name of the last output values tensor of the cells. |
Int32 | hiddenSize | The number of neurons in the hidden layer of the LSTM. |
RnnDirection | direction | The direction of the LSTM as an |
RnnActivation[] | activations | The activation functions of the LSTM as an array of |
Single[] | activationAlpha | The alpha values of the activation functions of the LSTM. If this is |
Single[] | activationBeta | The beta values of the activation functions of the LSTM. If this is |
Single | clip | The cell clip threshold of the LSTM. The default value is |
Boolean | inputForget | Whether to forget the input values in the LSTM. If this is |
RnnLayout | layout | The layout of the tensors as an |
Fields
activationAlpha
The alpha values of the activation functions of the LSTM.
Declaration
public float[] activationAlpha
Field Value
Type | Description |
---|---|
Single[] |
activationBeta
The beta values of the activation functions of the LSTM.
Declaration
public float[] activationBeta
Field Value
Type | Description |
---|---|
Single[] |
activations
The activation functions of the LSTM as an array of RnnActivation
.
Declaration
public RnnActivation[] activations
Field Value
Type | Description |
---|---|
RnnActivation[] |
clip
The cell clip threshold of the LSTM.
Declaration
public float clip
Field Value
Type | Description |
---|---|
Single |
direction
The direction of the LSTM as an RnnDirection
.
Declaration
public RnnDirection direction
Field Value
Type | Description |
---|---|
RnnDirection |
hiddenSize
The number of neurons in the hidden layer of the LSTM.
Declaration
public int hiddenSize
Field Value
Type | Description |
---|---|
Int32 |
inputForget
Whether to forget the input values in the LSTM. If this is false
the input and forget gates are coupled.
Declaration
public bool inputForget
Field Value
Type | Description |
---|---|
Boolean |
layout
The layout of the tensors as an RnnLayout
.
Declaration
public RnnLayout layout
Field Value
Type | Description |
---|---|
RnnLayout |
Properties
NumDirections
The number of directions of the LSTM inferred from the direction
.
Declaration
public int NumDirections { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Execute(Tensor[], ExecutionContext)
Executes the layer using the operations and variables from the ExecutionContext
and returns the output tensor.
If the layer has more than one output, output tensors are saved to variables.
Declaration
public override Tensor Execute(Tensor[] inputTensors, ExecutionContext ctx)
Parameters
Type | Name | Description |
---|---|---|
Tensor[] | inputTensors | |
ExecutionContext | ctx |
Returns
Type | Description |
---|---|
Tensor |
Overrides
ToString()
Returns a string that represents the Layer
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |