<jupyter_start><jupyter_text>MNIST with different losses<jupyter_code>import keras
from keras.models import Sequential
from keras.layers import Flatten, Dense
from keras.losses import *
# losses source: https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/losses.py
from keras.datasets import mnist
from keras.utils import to_categorical
import keras.backend as K
%%capture
(X_train, Y_train), (X_val, Y_val) = mnist.load_data()
X_train, X_val = X_train / 255., X_val / .255
Y_train, Y_val = to_categorical(Y_train), to_categorical(Y_val)
losses = categorical_crossentropy, mae, mse, hinge, categorical_hinge, cosine

for loss in losses:
  print('loss:', loss.__name__)
  K.clear_session()
  model = Sequential([Flatten(input_shape=(28, 28)),
                      Dense(32, activation='relu'),
                      Dense(10, activation='softmax')])

  model.compile('sgd', loss, metrics=['acc'])
  history = model.fit(X_train, Y_train, validation_data=(X_val, Y_val), epochs=5, verbose=2)
  print('=========================\n')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14695009242144177, 'fraction_numerical': 0.01756007393715342, 'mean_word_length': 5.11864406779661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '179309', 'license': 'Apache-2.0', 'n_tokens_mistral': 397, 'n_tokens_neox': 375, 'n_words': 80, 'path': 'Part II - Learning in Deep Networks/MNIST_losses.ipynb', 'repo_name': 'transtrades/DL-workshop-series', 'size': '1082'}