<jupyter_start><jupyter_text>Import Libraries<jupyter_code>%matplotlib inline

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Download Data<jupyter_code>(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 0s 0us/step<jupyter_text>Plot Examples<jupyter_code>plt.figure(figsize=(10, 10))

for i in range(16):
    plt.subplot(4, 4, i + 1)
    plt.imshow(x_train[i], cmap='binary')
    plt.xlabel(str(y_train[i]))
    plt.xticks([])
    plt.yticks([])
plt.show()<jupyter_output><empty_output><jupyter_text>Normalize Data<jupyter_code>x_train = np.reshape(x_train, (60000, 784))
x_train = x_train / 255.

x_test = np.reshape(x_test, (10000, 784))
x_test = x_test / 255.<jupyter_output><empty_output><jupyter_text>Create a Neural Network Model<jupyter_code>model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(32, activation='sigmoid', input_shape=(784,)),
    tf.keras.layers.Dense(64, activation='sigmoid'),
    tf.keras.layers.Dense(32, activation='sigmoid'),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Train the Model<jupyter_code>_ = model.fit(
    x_train, y_train,
    validation_data=(x_test, y_test),
    epochs=50, batch_size=1024,
    verbose=2
)<jupyter_output>Epoch 1/20
59/59 - 1s - loss: 2.1740 - accuracy: 0.3771 - val_loss: 1.9758 - val_accuracy: 0.5691
Epoch 2/20
59/59 - 0s - loss: 1.7945 - accuracy: 0.6146 - val_loss: 1.5901 - val_accuracy: 0.6796
Epoch 3/20
59/59 - 0s - loss: 1.4178 - accuracy: 0.7317 - val_loss: 1.2316 - val_accuracy: 0.7926
Epoch 4/20
59/59 - 0s - loss: 1.0922 - accuracy: 0.8144 - val_loss: 0.9433 - val_accuracy: 0.8434
Epoch 5/20
59/59 - 0s - loss: 0.8458 - accuracy: 0.8533 - val_loss: 0.7391 - val_accuracy: 0.8720
Epoch 6/20
59/59 - 0s - loss: 0.6751 - accuracy: 0.8736 - val_loss: 0.6011 - val_accuracy: 0.8850
Epoch 7/20
59/59 - 0s - loss: 0.5595 - accuracy: 0.8858 - val_loss: 0.5079 - val_accuracy: 0.8931
Epoch 8/20
59/59 - 0s - loss: 0.4809 - accuracy: 0.8944 - val_loss: 0.4439 - val_accuracy: 0.9012
Epoch 9/20
59/59 - 0s - loss: 0.4257 - accuracy: 0.9017 - val_loss: 0.3987 - val_accuracy: 0.9065
Epoch 10/20
59/59 - 0s - loss: 0.3849 - accuracy: 0.9075 - val_loss: 0.3642 - val_accuracy: 0.9119
Epoch 11/20
59/59 -[...]<jupyter_text>Save the Model<jupyter_code>model.save('model.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16082089552238807, 'fraction_numerical': 0.1332089552238806, 'mean_word_length': 4.4271255060728745, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '292099', 'license': 'MIT', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1134, 'n_words': 209, 'path': 'Streamlit Web Apps/NN-Visualizer-Web-App/Train.ipynb', 'repo_name': 'Storiesbyharshit/Data-Science-Portfolio', 'size': '2680'}