January 2019
Intermediate to advanced
342 pages
9h 17m
English
The loss optimized is the categorical cross entropy loss with respect to predicting the correct word out of the whole corpus of caption words at each time step of the LSTM 2 . The same is accumulated in each step of the Decoding phase for all the data points in the batch. The code associated with the loss accumulation during the decoding phase is as follows:
labels = tf.expand_dims(caption[:, i+1], 1) indices = tf.expand_dims(tf.range(0, self.batch_size, 1), 1) concated = tf.concat([indices, labels],1) onehot_labels = tf.sparse_to_dense(concated, tf.stack ([self.batch_size,self.n_words]), 1.0, 0.0) logit_words = tf.nn.xw_plus_b(output2, self.word_emb_W, self.word_emb_b) # Computing the loss cross_entropy ...
Read now
Unlock full access