Chr*_*amp 6 python neural-network tensorflow
我正在尝试从https://arxiv.org/pdf/1609.05473.pdf运行SequenceGAN ( https://github.com/LantaoYu/SeqGAN ) 。
在修复了明显的错误后,比如替换为,它仍然没有运行,因为公路网络部分需要这个功能:packstacktf.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
Run Code Online (Sandbox Code Playgroud)
这 tf.nn.rnn_cell._linear函数在 Tensorflow 1.0 或 0.12 中似乎不再存在,我不知道用什么来替换它。我找不到任何新的实现,也找不到关于 tensorflow 的 github 或(不幸的是非常稀疏的)文档的任何信息。
有人知道这个功能的新挂件吗?非常感谢!
在 1.0 版本中,一切都发生了变化。我也有过类似的狩猎tf.nn.rnn_cell.LSTMCell更新tf.contrib.rnn.BasicLSTMCell。
对于您的情况,tf.nn.rnn_cell._linear现在存在于tf.contrib.rnn.python.ops.core_rnn_cell_impl以及 的定义中BasicRNNCell。检查BasicRNNCell文档和源代码,我们在L113-L118处看到_线性的使用。
def __call__(self, inputs, state, scope=None):
"""Most basic RNN: output = new_state = act(W * input + U * state + B)."""
with _checked_scope(self, scope or "basic_rnn_cell", reuse=self._reuse):
output = self._activation(
_linear([inputs, state], self._num_units, True))
return output, output
Run Code Online (Sandbox Code Playgroud)
_线性方法在第 854 行定义为:
Linear map: sum_i(args[i] * W[i]), where W[i] is a variable.
祝你好运!