Skip to content
Advertisement

What do the functions tf.squeeze and tf.nn.rnn do?

What do the functions tf.squeeze and tf.nn.rnn do?

I searched these API, but I can’t find argument, examples etc. Also, what is the shape of p_inputs formed by the following code using tf.squeeze, and what is the meaning and case of using tf.nn.rnn?

batch_num = 10
step_num = 2000
elem_num = 26

p_input = tf.placeholder(tf.float32, [batch_num, step_num, elem_num])
p_inputs = [tf.squeeze(t, [1]) for t in tf.split(1, step_num, p_input)]

Advertisement

Answer

The best source of answers to questions like these is the TensorFlow API documentation. The two functions you mentioned create operations and symbolic tensors in a dataflow graph. In particular:

  • The tf.squeeze() function returns a tensor with the same value as its first argument, but a different shape. It removes dimensions whose size is one. For example, if t is a tensor with shape [batch_num, 1, elem_num] (as in your question), tf.squeeze(t, [1]) will return a tensor with the same contents but size [batch_num, elem_num].

  • The tf.nn.rnn() function returns a pair of results, where the first element represents the outputs of a recurrent neural network for some given input, and the second element represents the final state of that network for that input. The TensorFlow website has a tutorial on recurrent neural networks with more details.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement