简体   繁体   中英

Unable to interpret a line of python code that creates a LSTM cell using tensorflow

I am trying to figure out how a fully-functional python code works. One block creates a LSTM cell using tensorflow. I don't know how to interpret the line specified by the comment below.

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

Note that tf.contrib.rnn.LSTMCell is an example of a callable class .

That is a class that can be called like a function. The line you are struggling with does exactly that. It calls cell with the parameters in brackets.

If you want to see what this does you can inspect the __call__ method on the class definition for tf.contrib.rnn.LSTMCell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM