<jupyter_start><jupyter_text>Preprocessing Data<jupyter_code>def get_mnist_data():
    from keras.datasets import mnist
    from keras.utils import np_utils
    (X_train, y_train), (X_test, y_test) = mnist.load_data()
    X_train = X_train.reshape(X_train.shape[0], 1, X_train.shape[1], X_train.shape[2])
    y_train = y_train.reshape(y_train.shape[0], 1)
    X_test = X_test.reshape(X_test.shape[0], 1, X_test.shape[1], X_test.shape[2])
    y_test = y_test.reshape(y_test.shape[0], 1)
    
    y_train = np_utils.to_categorical(y_train)
    y_test  = np_utils.to_categorical(y_test)
    
    return X_train, y_train, X_test, y_test
X_train, y_train, X_test, y_test = get_mnist_data()
X_train.shape, y_train.shape, X_test.shape, y_test.shape
X_mean = X_train.mean().astype(np.float32)
X_std = X_train.std().astype(np.float32)
def normalizer(x):
    return (x - X_mean) / X_std<jupyter_output><empty_output><jupyter_text>Building the model<jupyter_code>from keras.layers import Convolution2D, Dense, Flatten, Lambda, Dropout
from keras.models import Sequential
from keras.optimizers import Adam<jupyter_output><empty_output><jupyter_text>Linear Model<jupyter_code>nb_epoch = 5
model = Sequential([Lambda(normalizer, input_shape=(1, 28, 28)), Flatten(), Dense(10, activation='softmax')])
model.compile(Adam(), loss='categorical_crossentropy', metrics=['accuracy'] )
model.fit(X_train, y_train,validation_data=(X_test, y_test), nb_epoch=nb_epoch)<jupyter_output>Train on 60000 samples, validate on 10000 samples
Epoch 1/10
60000/60000 [==============================] - 6s - loss: 0.3889 - acc: 0.8857 - val_loss: 0.2963 - val_acc: 0.9172
Epoch 2/10
60000/60000 [==============================] - 6s - loss: 0.2988 - acc: 0.9156 - val_loss: 0.2857 - val_acc: 0.9186
Epoch 3/10
60000/60000 [==============================] - 6s - loss: 0.2893 - acc: 0.9183 - val_loss: 0.2775 - val_acc: 0.9235
Epoch 4/10
60000/60000 [==============================] - 6s - loss: 0.2816 - acc: 0.9210 - val_loss: 0.2805 - val_acc: 0.9215
Epoch 5/10
60000/60000 [==============================] - 6s - loss: 0.2768 - acc: 0.9228 - val_loss: 0.3059 - val_acc: 0.9122
Epoch 6/10
60000/60000 [==============================] - 6s - loss: 0.2733 - acc: 0.9242 - val_loss: 0.2876 - val_acc: 0.9216
Epoch 7/10
60000/60000 [==============================] - 6s - loss: 0.2710 - acc: 0.9249 - val_loss: 0.3029 - val_acc: 0.9169
Epoch 8/10
60000/60000 [==============================] - 6s [...]<jupyter_text>Is learning rate optimal?default in Adam is 0.001<jupyter_code>model.optimizer.lr = 0.1
model.fit(X_train, y_train,validation_data=(X_test, y_test), nb_epoch=nb_epoch)
model.optimizer.lr = 0.0001
model.fit(X_train, y_train,validation_data=(X_test, y_test), nb_epoch=15)<jupyter_output>Train on 60000 samples, validate on 10000 samples
Epoch 1/15
60000/60000 [==============================] - 5s - loss: 0.2557 - acc: 0.9286 - val_loss: 0.2927 - val_acc: 0.9205
Epoch 2/15
60000/60000 [==============================] - 6s - loss: 0.2555 - acc: 0.9294 - val_loss: 0.2944 - val_acc: 0.9239
Epoch 3/15
60000/60000 [==============================] - 5s - loss: 0.2557 - acc: 0.9279 - val_loss: 0.2934 - val_acc: 0.9227
Epoch 4/15
60000/60000 [==============================] - 5s - loss: 0.2550 - acc: 0.9284 - val_loss: 0.2887 - val_acc: 0.9245
Epoch 5/15
60000/60000 [==============================] - 5s - loss: 0.2533 - acc: 0.9301 - val_loss: 0.3095 - val_acc: 0.9200
Epoch 6/15
60000/60000 [==============================] - 5s - loss: 0.2531 - acc: 0.9296 - val_loss: 0.2953 - val_acc: 0.9215
Epoch 7/15
60000/60000 [==============================] - 5s - loss: 0.2539 - acc: 0.9298 - val_loss: 0.2923 - val_acc: 0.9240
Epoch 8/15
60000/60000 [==============================] - 5s [...]
{'fraction_non_alphanumeric': 0.25743099787685775, 'fraction_numerical': 0.14915074309978768, 'mean_word_length': 4.600297176820208, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '504992', 'license': 'MIT', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1470, 'n_words': 303, 'path': 'mnist/Linear Model.ipynb', 'repo_name': 'prasannals/neural_networks', 'size': '3768'}