【问题标题】:How the cell state size and cell output size is determined in BasicRNNCell?BasicRNNCell 中如何确定单元状态大小和单元输出大小?
【发布时间】:2017-06-09 17:54:54
【问题描述】:

考虑以下代码:

import tensorflow as tf
cell=tf.contrib.rnn.BasicRNNCell(num_units = rnn_size)
output, state = tf.nn.dynamic_rnn(cell, input, dtype=tf.float32) 

根据documentation of dynamic_rnnoutputstate 的形状分别为[batch_size, max_time, cell.output_size][batch_size, cell.state_size]

问题:cell.state_sizecell.output_size 是如何在BasicRNNCell 中确定的? BasicRNNCell的initilizer中的num_units = rnn_size和它的state_sizeoutput_size是什么关系?

【问题讨论】:

    标签: python tensorflow recurrent-neural-network


    【解决方案1】:

    BasicRNNCell的情况下,你提到的所有数量都是一样的(参考code):

     class BasicRNNCell(RNNCell):
         """The most basic RNN cell.
    
         Args:
          num_units: int, The number of units in the LSTM cell.
          activation: Nonlinearity to use.  Default: `tanh`.
          reuse: (optional) Python boolean describing whether to reuse variables
    
           in an existing scope.  If not `True`, and the existing scope already has
           the given variables, an error is raised.
         """
    
      def __init__(self, num_units, activation=None, reuse=None):
        super(BasicRNNCell, self).__init__(_reuse=reuse)
        self._num_units = num_units
        self._activation = activation or math_ops.tanh
    
      @property
      def state_size(self):
        return self._num_units
    
      @property
      def output_size(self):
        return self._num_units
    

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 2016-06-13
      • 2021-12-13
      • 2021-09-13
      • 2014-07-08
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 2015-03-20
      相关资源
      最近更新 更多