<jupyter_start><jupyter_text><jupyter_code># Imports 
from keras.datasets import mnist
from keras.layers import Dense, Flatten, Dropout
from keras.layers import Conv2D
from tensorflow.keras.utils import to_categorical
from keras import Sequential,Input

# the data, shuffled and split between train and test sets
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Make input daat from 0 to 1
x_train = x_train.astype("float32") / 255
x_test = x_test.astype("float32") / 255

# convert class vectors to binary class matrices
y_train = to_categorical(y_train, 10)
y_test = to_categorical(y_test, 10)


def CNN():
  model = Sequential([Input(shape = (28,28,1)),
                      Conv2D(32, kernel_size=(3, 3), activation='relu'),
                      Conv2D(64, kernel_size=(3, 3), activation='relu'),
                      Dense(128,activation='relu'),
                      Flatten(),
                      Dropout(0.2),
                      Dense(10, activation='softmax')
                      ]
                      )
  
  model.compile(loss = 'catgorical_crossentropy', optimizer= 'adadelta',metrics =['acc'])
  return model


def train(model):
  history = model.fit(x_train,x_test ,
                      batch_size = 512,
                      epochs = 10,
                      verbose = 1,
                      validation_data = (x_test,y_test))
            
  return history.history

def score(model):
  return model.evaluate(x_test,y_test,verbose=0)


model = CNN()
model.summary()
history = train(model)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10897435897435898, 'fraction_numerical': 0.029487179487179487, 'mean_word_length': 2.4383259911894273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '19031', 'license': 'MIT', 'n_tokens_mistral': 536, 'n_tokens_neox': 485, 'n_words': 113, 'path': 'lec2_CNN/lec2_cnn.ipynb', 'repo_name': 'ChihabEddine98/DL_course', 'size': '1560'}