我正在尝试从 https://github.com/LantaoYu/SeqGAN 获取 SequenceGAN ( https://arxiv.org/pdf/1609.05473.pdf )运行。
在修复了明显的错误后,比如将 pack
替换为 stack
,它仍然无法运行,因为 highway-network 部分需要 tf.nn.rnn_cell。 _linear
函数:
# highway layer that borrowed from https://github.com/carpedm20/lstm-char-cnn-tensorflow
def highway(input_, size, layer_size=1, bias=-2, f=tf.nn.relu):
"""Highway Network (cf. http://arxiv.org/abs/1505.00387).
t = sigmoid(Wy + b)
z = t * g(Wy + b) + (1 - t) * y
where g is nonlinearity, t is transform gate, and (1 - t) is carry gate.
"""
output = input_
for idx in range(layer_size):
output = f(tf.nn.rnn_cell._linear(output, size, 0, scope='output_lin_%d' % idx)) #tf.contrib.layers.linear instad doesn't work either.
transform_gate = tf.sigmoid(tf.nn.rnn_cell._linear(input_, size, 0, scope='transform_lin_%d' % idx) + bias)
carry_gate = 1. - transform_gate
output = transform_gate * output + carry_gate * input_
return output
tf.nn.rnn_cell._linear
函数在 Tensorflow 1.0 或 0.12 中似乎不再存在,我不知道用什么来代替它。我找不到这方面的任何新实现,也找不到关于 tensorflow 的 github 或(不幸的是非常稀疏)文档的任何信息。
有人知道函数的新挂件吗? 非常感谢!
最佳答案
我在使用 SkFlow 的 TensorFlowDNNRegressor 时遇到了这个错误。 第一次看到ruoho ruots的回答,有点懵。 但第二天我就明白他的意思了。
这是我的做法:
from tensorflow.python.ops import rnn_cell_impl
将 tf.nn.rnn_cell._linear
替换为 rnn_cell_impl._linear
关于python - Tensorflow:替换 tf.nn.rnn_cell._linear(input, size, 0, scope),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42437115/