RNNCell¶
- class paddle.fluid.layers. RNNCell [source]
-
- api_attr
-
Static Graph
RNNCell is the base class for abstraction representing the calculations mapping the input and state to the output and new state. It is suitable to and mostly used in RNN.
-
call
(
inputs,
states,
**kwargs
)
call¶
-
Every cell must implement this method to do the calculations mapping the inputs and states to the output and new states.
To be more flexible, both inputs and states can be a tensor variable or a nested structure (list|tuple|namedtuple|dict) of tensor variable, that is, a (possibly nested structure of) tensor variable[s].
- Parameters
-
inputs – A (possibly nested structure of) tensor variable[s].
states – A (possibly nested structure of) tensor variable[s].
**kwargs – Additional keyword arguments, provided by the caller.
- Returns
-
- outputs and new_states pair. outputs and new_states both
-
can be nested structure of tensor variables. new_states must have the same structure with states.
- Return type
-
tuple
-
get_initial_states
(
batch_ref,
shape=None,
dtype='float32',
init_value=0,
batch_dim_idx=0
)
get_initial_states¶
-
Generate initialized states according to provided shape, data type and value.
- Parameters
-
batch_ref – A (possibly nested structure of) tensor variable[s]. The first dimension of the tensor will be used as batch size to initialize states.
shape – A (possibly nested structure of) shape[s], where a shape is represented as a list/tuple of integer). -1(for batch size) will beautomatically inserted if shape is not started with it. If None, property state_shape will be used. The default value is None.
dtype – A (possibly nested structure of) data type[s]. The structure must be same as that of shape, except when all tensors’ in states has the same data type, a single data type can be used. If property cell.state_shape is not available, float32 will be used as the data type. The default value is float32.
init_value – A float value used to initialize states.
batch_dim_idx – An integer indicating which dimension of the tensor in inputs represents batch size. The default value is 0.
- Returns
-
- tensor variable[s] packed in the same structure provided
-
by shape, representing the initialized states.
- Return type
-
Variable
- property state_shape
-
Abstract method (property). Used to initialize states. A (possibly nested structure of) shape[s], where a shape is represented as a list/tuple of integers (-1 for batch size would be automatically inserted into a shape if shape is not started with it). Not necessary to be implemented if states are not initialized by get_initial_states or the shape argument is provided when using get_initial_states.
- property state_dtype
-
Abstract method (property). Used to initialize states. A (possibly nested structure of) data types[s]. The structure must be same as that of shape, except when all tensors’ in states has the same data type, a single data type can be used. Not necessary to be implemented if states are not initialized by get_initial_states or the dtype argument is provided when using get_initial_states.