def add_loss_op(self, result):
logits = result.rnn_output
with tf.control_dependencies([tf.assert_positive(tf.shape(logits)[1], data=[tf.shape(logits)])]):
length_diff = tf.reshape(self.config.max_length - tf.shape(logits)[1], shape=(1,))
padding = tf.reshape(tf.concat([[0, 0, 0], length_diff, [0, 0]], axis=0), shape=(3, 2))
preds = tf.pad(logits, padding, mode='constant')
# add epsilon to avoid division by 0
preds = preds + 1e-5
mask = tf.sequence_mask(self.output_length_placeholder, self.config.max_length, dtype=tf.float32)
loss = tf.contrib.seq2seq.sequence_loss(preds, self.output_placeholder, mask)
with tf.control_dependencies([tf.assert_non_negative(loss, data=[preds, mask], summarize=256*60*300)]):
return tf.identity(loss)
seq2seq_aligner.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录