tensorflow学习之GRUCell详解

版权声明:微信公众号:数据挖掘与机器学习进阶之路。本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013230189/article/details/82822668

 

tf.contrib.rnn.GRUCell

Aliases:

  • Class tf.contrib.rnn.GRUCell
  • Class tf.nn.rnn_cell.GRUCell

门控循环单元cell

__init__(

    num_units,

    activation=None,

    reuse=None,

    kernel_initializer=None,

    bias_initializer=None,

    name=None,

    dtype=None

)

参数说明:

num_unit:GRU cell中神经元数量。即隐藏的神经元数量。

activation:使用的激活函数

resue:布尔型,表示是否在现有的scope中重复使用变量。如果不为True,并且现有的scope中已经存在给定的变量,则会产生错误。

Kernel_initializer:可选参数,权重和投影矩阵使用的初始化器。

Bias_initializer:可选参数,偏置使用的初始化器。

name:该层的名称。拥有同样名称的层共享权重,但为了避免错误,一般会使用reuse=True

dtype:该层默认的数据类型。

 

代码示例:

import tensorflow as tf

batch_size=10

depth=128

output_dim=100

inputs=tf.Variable(tf.random_normal([batch_size,depth]))

previous_state=tf.Variable(tf.random_normal([batch_size,output_dim])) #前一个状态的输出

gruCell=tf.nn.rnn_cell.GRUCell(output_dim)

output,state=gruCell(inputs,previous_state)

print(output)

print(state)

输出:

Tensor("gru_cell/add:0", shape=(10, 100), dtype=float32)

Tensor("gru_cell/add:0", shape=(10, 100), dtype=float32)

 

猜你喜欢

转载自blog.csdn.net/u013230189/article/details/82822668
今日推荐