chiphuyen / stanford-tensorflow-tutorials

This repository contains code examples for the Stanford's course: TensorFlow for Deep Learning Research.
http://cs20.stanford.edu
MIT License
10.32k stars 4.32k forks source link

Calculating unpaded length in 11_char_rnn.py is wrong #118

Open lifa08 opened 6 years ago

lifa08 commented 6 years ago

length = tf.reduce_sum(tf.reduce_max(tf.sign(seq), 2), 1)

I believe this length calculation function in 11_char_rnn.py is wrong. Since the seq in the above line is the one-hot version of seq, so even for the padded 0, tf.reduce_max(tf.sign(seq), 2) will get a value of 1 instead of 0. So it will always return the num_steps. Instead, tf.reduce_sum(tf.sign(self.seq), 1) will get the right unpadded length. Note self.seq here is NOT the one-hot version of sequence.