gpt4 book ai didi

python - 无法解释一行使用 tensorflow 创建 LSTM 单元的 python 代码

转载 作者:行者123 更新时间:2023-11-28 17:58:52 25 4
gpt4 key购买 nike

我正在尝试弄清楚功能齐全的 Python 代码是如何工作的。一个 block 使用 tensorflow 创建一个 LSTM 单元。我不知道如何解释下面由评论指定的行。

def get_lstm_weights(n_hidden, forget_bias, dim, scope="rnn_cell"):
# Create LSTM cell
cell = tf.contrib.rnn.LSTMCell(num_units = n_hidden, reuse=None, forget_bias = forget_bias)
#--------------------------------------
# I DO NOT UNDERSTAND THE NEXT LINE
cell(tf.zeros([1, dim +1]), (tf.zeros([1, n_hidden]),tf.zeros([1, n_hidden])), scope=scope)
# -------------------------------------
cell = tf.contrib.rnn.LSTMCell(num_units = n_hidden, reuse=True, forget_bias = forget_bias)

# Create output weights
weights = {
'W_1': tf.Variable(tf.truncated_normal([n_hidden, dim], stddev=0.05)),
'b_1': tf.Variable(0.1*tf.ones([dim])),
}

return cell, weights

最佳答案

请注意,tf.contrib.rnn.LSTMCellcallable class 的示例.

那是一个可以像函数一样调用的类。您正在努力解决的问题正是这样做的。它使用括号中的参数调用 cell

如果你想看看这是做什么的,你可以检查 tf.contrib.rnn.LSTMCell 的类定义中的 __call__ 方法

关于python - 无法解释一行使用 tensorflow 创建 LSTM 单元的 python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56801863/

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