RNNLayerConfig is identical to BaseRNNLayerConfig, except it makes the cell property required. This interface is to be used with constructors of concrete RNN layer subtypes.

interface RNNLayerArgs {
    batchInputShape?: Shape;
    batchSize?: number;
    dtype?: keyof DataTypeMap;
    goBackwards?: boolean;
    inputDType?: keyof DataTypeMap;
    inputDim?: number;
    inputLength?: number;
    inputShape?: Shape;
    name?: string;
    returnSequences?: boolean;
    returnState?: boolean;
    stateful?: boolean;
    trainable?: boolean;
    unroll?: boolean;
    weights?: Tensor<Rank>[];
}

Hierarchy

  • BaseRNNLayerArgs
    • RNNLayerArgs

Properties

batchInputShape?: Shape

If defined, will be used to create an input layer to insert before this layer. If both inputShape and batchInputShape are defined, batchInputShape will be used. This argument is only applicable to input layers (the first layer of a model).

batchSize?: number

If inputShape is specified and batchInputShape is not specified, batchSize is used to construct the batchInputShape: [batchSize, ...inputShape]

dtype?: keyof DataTypeMap

The data-type for this layer. Defaults to 'float32'. This argument is only applicable to input layers (the first layer of a model).

goBackwards?: boolean

If true, process the input sequence backwards and return the reversed sequence (default: false).

inputDType?: keyof DataTypeMap

Legacy support. Do not use for new code.

inputDim?: number

Dimensionality of the input (integer). This option (or alternatively, the option inputShape) is required when this layer is used as the first layer in a model.

inputLength?: number

Length of the input sequences, to be specified when it is constant. This argument is required if you are going to connect Flatten then Dense layers upstream (without it, the shape of the dense outputs cannot be computed). Note that if the recurrent layer is not the first layer in your model, you would need to specify the input length at the level of the first layer (e.g., via the inputShape option).

inputShape?: Shape

If defined, will be used to create an input layer to insert before this layer. If both inputShape and batchInputShape are defined, batchInputShape will be used. This argument is only applicable to input layers (the first layer of a model).

name?: string

Name for this layer.

returnSequences?: boolean

Whether to return the last output in the output sequence, or the full sequence.

returnState?: boolean

Whether to return the last state in addition to the output.

stateful?: boolean

If true, the last state for each sample at index i in a batch will be used as initial state of the sample of index i in the following batch (default: false).

You can set RNN layers to be "stateful", which means that the states computed for the samples in one batch will be reused as initial states for the samples in the next batch. This assumes a one-to-one mapping between samples in different successive batches.

To enable "statefulness":

  • specify stateful: true in the layer constructor.
  • specify a fixed batch size for your model, by passing
    • if sequential model: batchInputShape: [...] to the first layer in your model.
    • else for functional model with 1 or more Input layers: batchShape: [...] to all the first layers in your model. This is the expected shape of your inputs including the batch size. It should be a tuple of integers, e.g., [32, 10, 100].
  • specify shuffle: false when calling LayersModel.fit().

To reset the state of your model, call resetStates() on either the specific layer or on the entire model.

trainable?: boolean

Whether the weights of this layer are updatable by fit. Defaults to true.

unroll?: boolean

If true, the network will be unrolled, else a symbolic loop will be used. Unrolling can speed up a RNN, although it tends to be more memory-intensive. Unrolling is only suitable for short sequences (default: false). Porting Note: tfjs-layers has an imperative backend. RNNs are executed with normal TypeScript control flow. Hence this property is inapplicable and ignored in tfjs-layers.

weights?: Tensor<Rank>[]

Initial weight values of the layer.

Generated using TypeDoc