Abbreviations for loss functions to be passed to model.compile()?



Here describes different loss functions, but it is possible to use abbreviations instead of importing and passing the actual loss object (see an examples here)

MeanSquaredError can be passed as the string mse, MeanAbsoluteError as mae. Some are obvious like that, but what about other losses like CategoricalCrossentropy, CosineSimilarity, or Hinge?


Here are some loss functions and their string aliases (All of them can be imported from tf.keras.losses):

Class Name String Alias(es)
MeanSquaredError() mean_squared_error, mse, MSE
MeanAbsoluteError() mean_absolute_error, mae, MAE
MeanAbsolutePercentageError() mean_absolute_percentage_error, mape, MAPE
MeanSquaredLogarithmicError() mean_squared_logarithmic_error, msle, MSLE
KLDivergence() kl_divergence, kullback_leibler_divergence, kld, KLD
Hinge() hinge
CosineSimilarity() cosine_similarity
LogCosh() log_cosh, logcosh
CategoricalCrossentropy() categorical_crossentropy
SparseCategoricalCrossentropy() sparse_categorical_crossentropy
BinaryCrossentropy() binary_crossentropy

As you can see, some of them have more than one string alias, whereas mostly have one alias.

Reference: Source code of keras.losses

Answered By – Kaveh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More