gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:35:41 24 4
gpt4 key购买 nike

考虑以下代码:

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],分别。

问题:在BasicRNNCell中如何确定cell.state_sizecell.output_size? 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

关于python - BasicRNNCell 中如何确定单元状态大小和单元输出大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44464055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com