<jupyter_start><jupyter_text>MNIST  Keras MLP example<jupyter_code>import warnings  
with warnings.catch_warnings():  
    warnings.filterwarnings("ignore",category=FutureWarning)
    from tensorflow import keras
    from tensorflow.keras.datasets import mnist
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Dense, Dropout
    from tensorflow.keras.optimizers import RMSprop<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>batch_size = 128
num_classes = 10
epochs = 20<jupyter_output><empty_output><jupyter_text>Data<jupyter_code>(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(60000, 784)
x_test = x_test.reshape(10000, 784)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255
x_train.shape
x_test.shape
# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)<jupyter_output><empty_output><jupyter_text>Building the Arquitecture<jupyter_code>model = Sequential()
model.add(Dense(512, activation='relu', input_shape=(784,)))
model.add(Dropout(0.2))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(num_classes, activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy',
              optimizer=RMSprop(),
              metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs)<jupyter_output>Epoch 1/20
60000/60000 [==============================] - 9s 149us/sample - loss: 0.2458 - acc: 0.9232
Epoch 2/20
60000/60000 [==============================] - 9s 146us/sample - loss: 0.1039 - acc: 0.9685
Epoch 3/20
60000/60000 [==============================] - 8s 140us/sample - loss: 0.0757 - acc: 0.9771
Epoch 4/20
60000/60000 [==============================] - 8s 135us/sample - loss: 0.0596 - acc: 0.9814
Epoch 5/20
60000/60000 [==============================] - 8s 135us/sample - loss: 0.0516 - acc: 0.9844
Epoch 6/20
60000/60000 [==============================] - 8s 136us/sample - loss: 0.0450 - acc: 0.9866
Epoch 7/20
60000/60000 [==============================] - 9s 147us/sample - loss: 0.0375 - acc: 0.9886
Epoch 8/20
60000/60000 [==============================] - 9s 142us/sample - loss: 0.0352 - acc: 0.9895
Epoch 9/20
60000/60000 [==============================] - 8s 139us/sample - loss: 0.0316 - acc: 0.9903
Epoch 10/20
60000/60000 [==============================] - 9s 146us/sampl[...]<jupyter_text>Test & evaluation<jupyter_code>model.evaluate(x_test, y_test, verbose=0)[1]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22944199706314244, 'fraction_numerical': 0.11343612334801761, 'mean_word_length': 5.8639798488664985, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '317890', 'license': 'MIT', 'n_tokens_mistral': 1216, 'n_tokens_neox': 982, 'n_words': 174, 'path': 'codes/keras-mlp.ipynb', 'repo_name': 'gebakx/ml-games', 'size': '2724'}