Skip to content

Commit

Permalink
Update log_softmax to adapt metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
kepei1106 committed Dec 16, 2018
1 parent 8522fc8 commit f604158
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions models/seq2seq-tensorflow/utils/output_projection.py
Expand Up @@ -17,15 +17,14 @@ def sampled_sequence_loss(outputs, targets, masks):
weights = tf.transpose(tf.get_variable("kernel", [num_units, num_symbols]))
bias = tf.get_variable("bias", [num_symbols])

local_dis = tf.nn.softmax(tf.einsum('aij,kj->aik', outputs, weights) + bias)
local_dis = tf.nn.log_softmax(tf.einsum('aij,kj->aik', outputs, weights) + bias)
local_labels = tf.reshape(targets, [-1])
local_masks = tf.reshape(masks, [-1])

y_prob = tf.reshape(local_dis, [-1, num_symbols])
labels_onehot = tf.one_hot(local_labels, num_symbols)
labels_onehot = tf.clip_by_value(labels_onehot, 0.0, 1.0)
y_prob = tf.clip_by_value(y_prob, 1e-18, 1.0)
local_loss = tf.reduce_sum(-labels_onehot * tf.log(y_prob), 1) * local_masks
local_loss = tf.reduce_sum(-labels_onehot * y_prob, 1) * local_masks

loss = tf.reduce_sum(local_loss)
total_size = tf.reduce_sum(local_masks)
Expand Down

0 comments on commit f604158

Please sign in to comment.