tf.keras.layers.SimpleRNNCell
Stay organized with collections
Save and categorize content based on your preferences.
Cell class for SimpleRNN.
Inherits From: Layer
tf.keras.layers.SimpleRNNCell(
units, activation='tanh', use_bias=True, kernel_initializer='glorot_uniform',
recurrent_initializer='orthogonal', bias_initializer='zeros',
kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None,
kernel_constraint=None, recurrent_constraint=None, bias_constraint=None,
dropout=0.0, recurrent_dropout=0.0, **kwargs
)
Arguments |
units
|
Positive integer, dimensionality of the output space.
|
activation
|
Activation function to use.
Default: hyperbolic tangent (tanh ).
If you pass None , no activation is applied
(ie. "linear" activation: a(x) = x ).
|
use_bias
|
Boolean, whether the layer uses a bias vector.
|
kernel_initializer
|
Initializer for the kernel weights matrix,
used for the linear transformation of the inputs.
|
recurrent_initializer
|
Initializer for the recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state.
|
bias_initializer
|
Initializer for the bias vector.
|
kernel_regularizer
|
Regularizer function applied to
the kernel weights matrix.
|
recurrent_regularizer
|
Regularizer function applied to
the recurrent_kernel weights matrix.
|
bias_regularizer
|
Regularizer function applied to the bias vector.
|
kernel_constraint
|
Constraint function applied to
the kernel weights matrix.
|
recurrent_constraint
|
Constraint function applied to
the recurrent_kernel weights matrix.
|
bias_constraint
|
Constraint function applied to the bias vector.
|
dropout
|
Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.
|
recurrent_dropout
|
Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.
|
Call arguments:
inputs
: A 2D tensor.
states
: List of state tensors corresponding to the previous timestep.
training
: Python boolean indicating whether the layer should behave in
training mode or in inference mode. Only relevant when dropout
or
recurrent_dropout
is used.
Methods
get_dropout_mask_for_cell
View source
get_dropout_mask_for_cell(
inputs, training, count=1
)
Get the dropout mask for RNN cell's input.
It will create mask based on context if there isn't any existing cached
mask. If a new mask is generated, it will update the cache in the cell.
Args |
inputs
|
the input tensor whose shape will be used to generate dropout
mask.
|
training
|
boolean tensor, whether its in training mode, dropout will be
ignored in non-training mode.
|
count
|
int, how many dropout mask will be generated. It is useful for cell
that has internal weights fused together.
|
Returns |
List of mask tensor, generated or cached mask based on context.
|
get_initial_state
View source
get_initial_state(
inputs=None, batch_size=None, dtype=None
)
get_recurrent_dropout_mask_for_cell
View source
get_recurrent_dropout_mask_for_cell(
inputs, training, count=1
)
Get the recurrent dropout mask for RNN cell.
It will create mask based on context if there isn't any existing cached
mask. If a new mask is generated, it will update the cache in the cell.
Args |
inputs
|
the input tensor whose shape will be used to generate dropout
mask.
|
training
|
boolean tensor, whether its in training mode, dropout will be
ignored in non-training mode.
|
count
|
int, how many dropout mask will be generated. It is useful for cell
that has internal weights fused together.
|
Returns |
List of mask tensor, generated or cached mask based on context.
|
reset_dropout_mask
View source
reset_dropout_mask()
Reset the cached dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so
that the cached mask is cleared before calling the cell.call(). The mask
should be cached across the timestep within the same batch, but shouldn't
be cached between batches. Otherwise it will introduce unreasonable bias
against certain index of data within the batch.
reset_recurrent_dropout_mask
View source
reset_recurrent_dropout_mask()
Reset the cached recurrent dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so
that the cached mask is cleared before calling the cell.call(). The mask
should be cached across the timestep within the same batch, but shouldn't
be cached between batches. Otherwise it will introduce unreasonable bias
against certain index of data within the batch.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.layers.SimpleRNNCell\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/layers/SimpleRNNCell) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1109-L1268) |\n\nCell class for SimpleRNN.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.layers.SimpleRNNCell`](/api_docs/python/tf/keras/layers/SimpleRNNCell)\n\n\u003cbr /\u003e\n\n tf.keras.layers.SimpleRNNCell(\n units, activation='tanh', use_bias=True, kernel_initializer='glorot_uniform',\n recurrent_initializer='orthogonal', bias_initializer='zeros',\n kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None,\n kernel_constraint=None, recurrent_constraint=None, bias_constraint=None,\n dropout=0.0, recurrent_dropout=0.0, **kwargs\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `units` | Positive integer, dimensionality of the output space. |\n| `activation` | Activation function to use. Default: hyperbolic tangent (`tanh`). If you pass `None`, no activation is applied (ie. \"linear\" activation: `a(x) = x`). |\n| `use_bias` | Boolean, whether the layer uses a bias vector. |\n| `kernel_initializer` | Initializer for the `kernel` weights matrix, used for the linear transformation of the inputs. |\n| `recurrent_initializer` | Initializer for the `recurrent_kernel` weights matrix, used for the linear transformation of the recurrent state. |\n| `bias_initializer` | Initializer for the bias vector. |\n| `kernel_regularizer` | Regularizer function applied to the `kernel` weights matrix. |\n| `recurrent_regularizer` | Regularizer function applied to the `recurrent_kernel` weights matrix. |\n| `bias_regularizer` | Regularizer function applied to the bias vector. |\n| `kernel_constraint` | Constraint function applied to the `kernel` weights matrix. |\n| `recurrent_constraint` | Constraint function applied to the `recurrent_kernel` weights matrix. |\n| `bias_constraint` | Constraint function applied to the bias vector. |\n| `dropout` | Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. |\n| `recurrent_dropout` | Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state. |\n\n\u003cbr /\u003e\n\n#### Call arguments:\n\n- **`inputs`**: A 2D tensor.\n- **`states`**: List of state tensors corresponding to the previous timestep.\n- **`training`** : Python boolean indicating whether the layer should behave in training mode or in inference mode. Only relevant when `dropout` or `recurrent_dropout` is used.\n\nMethods\n-------\n\n### `get_dropout_mask_for_cell`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1033-L1067) \n\n get_dropout_mask_for_cell(\n inputs, training, count=1\n )\n\nGet the dropout mask for RNN cell's input.\n\nIt will create mask based on context if there isn't any existing cached\nmask. If a new mask is generated, it will update the cache in the cell.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|---------------------------------------------------------------------------------------------------------------|\n| `inputs` | the input tensor whose shape will be used to generate dropout mask. |\n| `training` | boolean tensor, whether its in training mode, dropout will be ignored in non-training mode. |\n| `count` | int, how many dropout mask will be generated. It is useful for cell that has internal weights fused together. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| List of mask tensor, generated or cached mask based on context. ||\n\n\u003cbr /\u003e\n\n### `get_initial_state`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1233-L1234) \n\n get_initial_state(\n inputs=None, batch_size=None, dtype=None\n )\n\n### `get_recurrent_dropout_mask_for_cell`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1069-L1105) \n\n get_recurrent_dropout_mask_for_cell(\n inputs, training, count=1\n )\n\nGet the recurrent dropout mask for RNN cell.\n\nIt will create mask based on context if there isn't any existing cached\nmask. If a new mask is generated, it will update the cache in the cell.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|---------------------------------------------------------------------------------------------------------------|\n| `inputs` | the input tensor whose shape will be used to generate dropout mask. |\n| `training` | boolean tensor, whether its in training mode, dropout will be ignored in non-training mode. |\n| `count` | int, how many dropout mask will be generated. It is useful for cell that has internal weights fused together. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| List of mask tensor, generated or cached mask based on context. ||\n\n\u003cbr /\u003e\n\n### `reset_dropout_mask`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1009-L1019) \n\n reset_dropout_mask()\n\nReset the cached dropout masks if any.\n\nThis is important for the RNN layer to invoke this in it call() method so\nthat the cached mask is cleared before calling the cell.call(). The mask\nshould be cached across the timestep within the same batch, but shouldn't\nbe cached between batches. Otherwise it will introduce unreasonable bias\nagainst certain index of data within the batch.\n\n### `reset_recurrent_dropout_mask`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/layers/recurrent.py#L1021-L1031) \n\n reset_recurrent_dropout_mask()\n\nReset the cached recurrent dropout masks if any.\n\nThis is important for the RNN layer to invoke this in it call() method so\nthat the cached mask is cleared before calling the cell.call(). The mask\nshould be cached across the timestep within the same batch, but shouldn't\nbe cached between batches. Otherwise it will introduce unreasonable bias\nagainst certain index of data within the batch."]]