GRUCell

class paddle.fluid.layers. GRUCell ( hidden_size, param_attr=None, bias_attr=None, gate_activation=None, activation=None, dtype=’float32’, name=’GRUCell’ ) [源代码]

门控循环单元(Gated Recurrent Unit)。通过对 fluid.contrib.layers.rnn_impl.BasicGRUUnit 包装,来让它可以应用于RNNCell。

公式如下:

GRUCell - 图1

更多细节可以参考 Learning Phrase Representations using RNN Encoder Decoder for Statistical Machine Translation

参数:

  • hidden_size (int) - GRUCell中的隐藏层大小。

  • param_attr (ParamAttr,可选) - 指定权重参数属性的对象。默认值为None,表示使用默认的权重参数属性。具体用法请参见 ParamAttr

  • bias_attr (ParamAttr,可选) - 指定偏置参数属性的对象。默认值为None,表示使用默认的偏置参数属性。具体用法请参见 ParamAttr

  • gate_activation (function,可选) -

    GRUCell - 图2

    的激活函数。 默认值为 fluid.layers.sigmoid

  • activation (function,可选) -

    GRUCell - 图3

    的激活函数。 默认值为 fluid.layers.tanh

  • dtype (string,可选) - 此cell中使用的数据类型。 默认为”float32”。

  • name (string,可选) - 用于标识参数和偏差的名称域。

返回:GRUCell类的实例对象。

示例代码

  1. import paddle.fluid.layers as layers
  2. cell = layers.GRUCell(hidden_size=256)

call ( inputs, states )

执行GRU的计算。

参数:

  • input (Variable) - 输入,形状为

    GRUCell - 图4

    的tensor,对应于公式中的

    GRUCell - 图5

    。数据类型应为float32。

  • states (Variable) - 状态,形状为

    GRUCell - 图6

    的tensor。 对应于公式中的 ht−1ht−1 。数据类型应为float32。

返回:一个元组 (outputs, new_states) ,其中 outputsnew_states 是同一个tensor,其形状为 [batch_size,hidden_size][batch_size,hidden_size],数据类型和 state 的数据类型相同,对应于公式中的 htht。

返回类型:tuple

state_shape ( )

GRUCell的 state_shape 是形状 [hidden_size][hidden_size] (batch大小为-1,自动插入到形状中),对应于 ht−1ht−1 的形状。

参数:无。

返回:GRUCell的 state_shape

返回类型:Variable