<jupyter_start><jupyter_text>This is the official jupyter notebook for the python script for learning digit recognitionMore coming soon...<jupyter_code>import tensorflow as tf
import tensorflowjs as tfjs
import numpy as np
import matplotlib.pyplot as plt
mnist = tf.keras.datasets.mnist  # 28x28 images of handwritten digits 0-9

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=x_train.shape[1:]))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(x_train, y_train, epochs=3)

model.save('digit_model.h5')
tfjs.converters.save_keras_model(model, 'target')
predictions = model.predict([x_test])

print('Prediction:', np.argmax(predictions[0]))

plt.imshow(x_test[0], cmap=plt.get_cmap('gray_r'))
plt.show()<jupyter_output>Prediction: 7
{'fraction_non_alphanumeric': 0.14046822742474915, 'fraction_numerical': 0.01839464882943144, 'mean_word_length': 6.0828402366863905, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '249854', 'license': 'FTL', 'n_tokens_mistral': 469, 'n_tokens_neox': 452, 'n_words': 76, 'path': 'jupyter/ml_jupyter.ipynb', 'repo_name': 'FlorianWoelki/digit-me', 'size': '1196'}