LSTM Projected Layer - Long short-term memory (LSTM) projected layer for recurrent neural network

  (RNN) - Simulink ([original](https://www.mathworks.com/help/deeplearning/ref/lstmprojectedlayer.html)) ([raw](?raw))

Long short-term memory (LSTM) projected layer for recurrent neural network (RNN)

Since R2024b

Libraries:
Deep Learning Toolbox / Deep Learning Layers / Sequence Layers

Description

The LSTM Projected Layer block represents a recurrent neural network (RNN) layer that learns long-term dependencies between time steps in time-series and sequence data in the CT format (two dimensions corresponding to channels and time steps, in that order) by using projected learnable weights.

To compress a deep learning network, you can use projected layers. A projected layer is a type of deep learning layer that enables compression by reducing the number of stored learnable parameters. The layer introduces learnable projector matrices_Q_, replaces multiplications of the form Wx, where W is a learnable matrix, with the multiplication WQQ⊤x, and stores Q and W′=WQ instead of storing W. Projecting x into a lower dimensional space using Q typically requires less memory to store the learnable parameters and can have similarly strong prediction accuracy.

Reducing the number of learnable parameters by projecting an LSTM layer rather than reducing the number of hidden units of the LSTM layer maintains the output size of the layer and, in turn, the sizes of the downstream layers, which can result in better prediction accuracy.

The exportNetworkToSimulink function generates this block to represent an lstmProjectedLayer object.

Limitations

Ports

Input

expand all

Input data. The data must have two dimensions corresponding to channels and time steps, in that order.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

The result of the projected LSTM operation. The output data has two dimensions corresponding to channels and time steps, in that order.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

To edit block parameters interactively, use theProperty Inspector. From the Simulink® Toolstrip, on the Simulation tab, in thePrepare gallery, select Property Inspector.

Main

Specify the name of a workspace variable that contains anlstmProjectedLayer object from a trained network. The LSTM Projected Layer block configures itself by using the properties of the object and calculates the block output by using the learnable parameters of the object.

Programmatic Use

Block Parameter: Layer
Type: workspace variable
Values: lstmProjectedLayer object
Default: 'layerObject'

Data format for the input data. The options use the same notation as the fmt argument of thedlarray object, except layer blocks do not support the Batch (B) dimension and instead assume an observation number of1.

Programmatic Use

Block Parameter: DataFormat
Type: character vector
Values: 'CT'
Default: 'CT'

Whether to use stateful prediction, specified as a boolean. Iftrue, the block maintains the cell state and hidden state between time steps. If false, the block performs stateless prediction by resetting cell states and hidden states to their initial values at the beginning of each time step. Use stateless prediction for frame-based processing where Simulink step time represents frame period and the network processes multiple samples at each time step. For more information, see Sample- and Frame-Based Concepts (DSP System Toolbox).

Programmatic Use

Block Parameter: StatefulPrediction
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Data Types

If the object that you pass as the value of the Layer parameter uses the tanh state activation function or thesigmoid gate activation function, then the block uses the approximation method that you specify to compute the layer output.

Approximation Method Data Types Supported When to Use This Method
None (default) Floating-point You are processing only floating-point data.
CORDIC Floating-point (double and single) and fixed-point with aBias value of 0 and aSlope value of a power of 2 You are processing fixed-point data and want to deploy to FPGA hardware.
Lookup Floating-point and fixed-point You are processing fixed-point data and want to generate C/C++ code.

For more information about the CORDIC approximation method, see cordictanh (Fixed-Point Designer).

Programmatic Use

Block Parameter: ApproximationMethod
Type: character vector
Values: 'None' | 'CORDIC' 'Lookup'
Default: 'None'

Lower value of the output range that the software checks.

The software uses the minimum to perform:

Tips

Output minimum does not saturate or clip the actual output signal. Use the Saturation (Simulink) block instead.

Dependencies

To enable this parameter, set Output data type to a value other than Inherit: Inherit via internal rule.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutMin
Values: '[]' (default) | scalar in quotes

Upper value of the output range that the software checks.

The software uses the maximum value to perform:

Tips

Output maximum does not saturate or clip the actual output signal. Use the Saturation (Simulink) block instead.

Dependencies

To enable this parameter, set Output data type to a value other than Inherit: Inherit via internal rule.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutMax
Values: '[]' (default) | scalar in quotes

Choose the data type for the output. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) |

Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: LockScale
Values: 'off' (default) | 'on'

Specify the rounding mode for fixed-point operations. For more information, see Rounding Modes (Fixed-Point Designer).

Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB® rounding function in the mask field.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RndMeth
Values: 'Floor' (default) | 'Ceiling' 'Convergent' 'Nearest' 'Round' 'Simplest' 'Zero'

Specify whether integer overflows saturate or wrap.

For example, the maximum value that the signed 8-bit integer int8 can represent is 127. Any block operation result greater than the maximum value causes overflow of the 8-bit integer.

Tips

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: SaturateOnIntegerOverflow
Values: 'off' (default) | 'on'

The block casts the value of the InputWeights property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the RecurrentWeights property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RecurrentWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the Bias property of the object that you specify with the Layer parameter to this data type.The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: BiasDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the InputProjector property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

For more information, see LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputProjectorWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the OutputProjector property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

For more information, see LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutputProjectorWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the CellState property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

This parameter affects only the initial cell state, _c_0. To cast later cell state values, use the Cell state parameter. For more information, see Long Short-Term Memory Layer

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: TODODataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

Choose the data type for the output of the Sum blockForIteratorSubsystem/LSTMProjectedCore/CellAdd inside theLSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Sum block computes the cell state c t as c _t_=f t_⊙_c t_-1+i t_⊙_g t, where i, f, and_g denote the input gate, forget gate, and cell candidate gate, respectively, and ⊙ denotes the Hadamard product (element-wise multiplication of vectors). For more information, see Long Short-Term Memory Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: CellStateDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Keep LSB' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input' 'Inherit: Same as accumulator'

The block casts the value of the HiddenState property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

This parameter affects only the initial hidden state, _h_0. To cast later hidden state values, use the Hidden state parameter. For more information, see Long Short-Term Memory Layer

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InitialHiddenStateDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

Choose the data type for the output of the Product blockForIteratorSubsystem/LSTMProjectedCore/HiddenStateProduct inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the hidden state h t as h _t_=o t_⊙_σ c(c t),where o denotes the output gate, σ c denotes the state activation function, and ⊙ denotes the Hadamard product (element-wise multiplication of vectors). For more information, see Long Short-Term Memory Layer and LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: HiddenStateDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Keep LSB' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input' 'Inherit: Same as accumulator'

Choose the data type for the output of the Product blockInputWeightsMatrixMultiply/W*x inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the product of the input weights (W) and the projected input at the time step (x t). For more information, see Long Short-Term Memory Layer and LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputWeightsMatrixMulitplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the output of the Product blockForIteratorSubsystem/LSTMProjectedCore/RecurrentWeightsMatrixMultiply/R*h_t-1 inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the product of the recurrent weights (R) and the projected hidden state at the previous time step (h _t_-1). For more information, see Long Short-Term Memory Layer and LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RecurrentWeightsMatrixMulitplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the output of the Product blockInputWeightsMatrixMultiply/x'*Q_in inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

The Product block computes the product of the transposed input (_x_T) and the input projector weights (_Q_in). For more information, see LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputProjectorWeightsMatrixMultiplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the output of the Product blockForIteratorSubsystem/LSTMProjectedCore/RecurrentWeightsMatrixMultiply/h_t-1'*Q_out inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the product of the transposed previous hidden state (h _t_-1T) and the output projector weights (_Q_out). For more information, see LSTM Projected Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutputProjectorWeightsMatrixMultiplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the accumulator of the Sum blockForIteratorSubsystem/LSTMProjectedCore/LinearGateAdd/Wx+Rh+b inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

The Sum block computes the sum W QinT x+R QoutT _h_t+b, where W denotes the input weights,Qin denotes the input projector matrix,x denotes the input, R denotes the recurrent weights, Qout denotes the output projector matrix, h t denotes the hidden state at time step t, and b denotes the bias. For more information, see Long Short-Term Memory Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: LinearGateAccumDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Same as first input'

Choose the data type for the output of the Sum blockForIteratorSubsystem/LSTMProjectedCore/LinearGateAdd/Wx+Rh+b inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

The Sum block computes the sum W QinT x+R QoutT _h_t+b, where W denotes the input weights,Qin denotes the input projector matrix,x denotes the input, R denotes the recurrent weights, Qout denotes the output projector matrix, h t denotes the hidden state at time step t, and b denotes the bias. For more information, see Long Short-Term Memory Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: LinearGateAddOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Keep LSB' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input' 'Inherit: Same as accumulator'

Choose the data type for the output of the gate activation function. For more information about gate activation functions, see GateActivationFunction. For more information on how an LSTM layer uses activation functions, see Long Short-Term Memory Layer.

The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: GateActivationoutDataTypeStr
Values: Inherit: Inherit via internal rule (default) | Inherit: Same as first input

Choose the data type for the output of the state activation function. For more information about state activation functions, see StateActivationFunction. For more information on how an LSTM layer uses activation functions, see Long Short-Term Memory Layer.

The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: StateActivationOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Same as first input'

Choose the data type for the output of the Product blocksForIteratorSubsystem/LSTMProjectedCore/f*c_t-1 andForIteratorSubsystem/LSTMProjectedCore/i*g inside the LSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product blocks compute the Hadamard products (element-wise multiplication of vectors, denoted as ⊙) f_t⊙_c _t_-1 and i t_⊙_g t, where f denotes the forget gate,c denotes the cell state, i denotes the input gate, and g denotes the cell candidate. For more information, seeLong Short-Term Memory Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: CellStateProductOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the accumulator of the Sum blockForIteratorSubsystem/LSTMProjectedCore/CellAdd inside theLSTM Projected Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Sum block computes the cell state c t as

,

where i, f, and g denote the input gate, forget gate, and cell candidate gate, respectively, and ⊙ denotes the Hadamard product (element-wise multiplication of vectors). For more information, seeLong Short-Term Memory Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: CellStateProductOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Same as first input'

Execution

Specify the discrete interval between sample time hits or specify another type of sample time, such as continuous (0) or inherited (-1). For more options, see Types of Sample Time (Simulink).

By default, the block inherits its sample time based on the context of the block within the model.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: SampleTime
Data Types: char
Values: '-1' (default) | scalar

Extended Capabilities

Version History

Introduced in R2024b

expand all

Starting in R2025a, the default value for the Layer parameter is 'layerObject'. In previous versions, the default value is 'layer'. If you have code that programmatically creates Simulink and relies on variables with the name 'layer', update your code so that the variable has the name 'layerObject'.

New Gate activation output and State activation output parameters control the data types of the gate and state activation outputs.

The default value of Linear gate add output is nowInherit: Same as first input.