考虑以下代码:

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之间是什么关系?

最佳答案

对于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

08-24 21:27