如何在BasicRNNCell中确定单元状态大小和单元输出大小?

时间:2017-06-09 17:54:55

标签: python tensorflow recurrent-neural-network

请考虑以下代码:

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_size中确定cell.output_sizeBasicRNNCell? BasicRNNCell的启动器中的num_units = rnn_size与其state_sizeoutput_size之间的关系是什么?

1 个答案:

答案 0 :(得分:3)

如果是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