Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow: Replacement for tf.nn.rnn_cell._linear(input, size, 0, scope)

I am trying to get the SequenceGAN (https://github.com/LantaoYu/SeqGAN) from https://arxiv.org/pdf/1609.05473.pdf to run.
After fixing the obvious errors, like replacing pack with stack, it still doesn't run, since the highway-network part requires the tf.nn.rnn_cell._linear function:

# 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

the tf.nn.rnn_cell._linear function doesn't appear to be there anymore in Tensorflow 1.0 or 0.12, and I have no clue what to replace it with. I can't find any new implementations of this, or any information on tensorflow's github or (unfortunately very sparse) documentation.

Does anybody know the new pendant of the function? Thanks a lot in advance!

like image 355
Chris Stenkamp Avatar asked Feb 24 '17 11:02

Chris Stenkamp


1 Answers

I met this error while using SkFlow's TensorFlowDNNRegressor. The first time I saw the answer of ruoho ruots, I am a bit confused. But the next day I realized what he meant.

Here is what I do:

from tensorflow.python.ops import rnn_cell_impl

replace tf.nn.rnn_cell._linear with rnn_cell_impl._linear

like image 144
qw_eee Avatar answered Sep 18 '22 23:09

qw_eee