Created
April 28, 2019 12:02
-
-
Save ChunML/34174eafb41cce35a5b7cb2fdfe3dc5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crossentropy = tf.keras.losses.SparseCategoricalCrossentropy( | |
from_logits=True) | |
def loss_func(targets, logits): | |
mask = tf.math.logical_not(tf.math.equal(targets, 0)) | |
mask = tf.cast(mask, dtype=tf.int64) | |
loss = crossentropy(targets, logits, sample_weight=mask) | |
return loss | |
optimizer = tf.keras.optimizers.Adam() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment