<jupyter_start><jupyter_text><jupyter_code>import tensorflow as tf

class CustomCallbacks(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs={}):
      if(logs.get('acc')>0.99):
        print("\n 99% acc reached")
        self.model.stop_training = True


mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()

x_train = x_train / 255
x_test = x_test / 255

model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28,28)),
    tf.keras.layers.Dense(units=256, activation=tf.nn.relu),
    tf.keras.layers.Dense(units=128, activation=tf.nn.relu),
    tf.keras.layers.Dense(units=10, activation=tf.nn.softmax)
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(
    x_train,
    y_train,
    epochs=10,
    #callbacks=[CustomCallbacks()]
)
import tensorflow as tf

class CustomCallbacks(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs={}):
      if(logs.get('acc')>0.998):
        print("\n 99% acc reached")
        self.model.stop_training = True


def preprocess_images(image_set):
  image_set = image_set.reshape(-1, 28, 28, 1)
  image_set = image_set / 255.0
  return image_set


mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

training_images = preprocess_images(training_images)
test_images = preprocess_images(test_images)
#keras.layers.Conv2D(filters, kernel_size, strides=(1, 1),
  #padding='valid', data_format=None, dilation_rate=(1, 1),
  #activation=None, use_bias=True, kernel_initializer='glorot_uniform',
  #bias_initializer='zeros', kernel_regularizer=None,
  #bias_regularizer=None, activity_regularizer=None,
  #kernel_constraint=None, bias_constraint=None)

model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(64, (3, 3), activation='relu', input_shape=(28,28,1)),
    tf.keras.layers.MaxPooling2D(2, 2),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

model.fit(
    training_images,
    training_labels,
    batch_size=64,
    epochs=20,
    #callbacks=[CustomCallbacks()]
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14743326488706365, 'fraction_numerical': 0.028747433264887063, 'mean_word_length': 4.665116279069768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '327318', 'license': 'Apache-2.0', 'n_tokens_mistral': 947, 'n_tokens_neox': 900, 'n_words': 130, 'path': 'MNSIT_MLP_CNN.ipynb', 'repo_name': 'ahmedhisham73/Arabcbt', 'size': '2435'}