<jupyter_start><jupyter_text>Task 2<jupyter_code>import tensorflow as tf
import matplotlib.pyplot as plt
# tensorflow version being used
print(tf.__version__) 
# is tf executing eagerly? 
print(tf.executing_eagerly())
# load mnist training and test data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# data shape and cardinality
print('Train data shape', x_train.shape)
print('Test data shape', x_test.shape)
print('Number of training samples', x_train.shape[0])
print('Number of testing samples', x_test.shape[0])
# plotting some numbers!
for i in range(25):
    plt.subplot(5,5,i+1) # add a subplot as 5 x 5
    plt.xticks([]) # get rid of labels
    plt.yticks([]) # get rid of labels
    plt.imshow(x_test[i], cmap="gray")
plt.show()
# reshape the input to have a list of 784 (28*28) and normalize it (/255)
x_train = x_train.reshape(x_train.shape[0], x_train.shape[1]*x_train.shape[2]) 
x_train = x_train.astype('float32')/255
x_test = x_test.reshape(x_test.shape[0], x_test.shape[1]*x_test.shape[2]) 
x_test = x_test.astype('float32')/255
# building a three-layer sequential model
model = tf.keras.Sequential([ 
    tf.keras.layers.Dense(64, activation='relu'), 
    tf.keras.layers.Dense(10, activation='relu'), 
    tf.keras.layers.Dense(10, activation='softmax')
])
# compiling the model
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# training it
model.fit(x_train, y_train)
# evaluating it
_, test_acc = model.evaluate(x_test, y_test)
print('\nTest accuracy:', test_acc)
# finally, generating predictions (the output of the last layer)
print('\nGenerating predictions for the first fifteen samples...') 
predictions = model.predict(x_test[:15])
print('Predictions shape:', predictions.shape)
for i, prediction in enumerate(predictions):
    # tf.argmax returns the INDEX with the largest value across axes of a tensor
    predicted_value = tf.argmax(prediction)
    label = y_test[i]
    print('Predicted a %d. Real value is %d.' %(predicted_value, label))<jupyter_output>Generating predictions for the first fifteen samples...
Predictions shape: (15, 10)
Predicted a 7. Real value is 7.
Predicted a 2. Real value is 2.
Predicted a 1. Real value is 1.
Predicted a 0. Real value is 0.
Predicted a 4. Real value is 4.
Predicted a 1. Real value is 1.
Predicted a 4. Real value is 4.
Predicted a 9. Real value is 9.
Predicted a 4. Real value is 5.
Predicted a 9. Real value is 9.
Predicted a 0. Real value is 0.
Predicted a 6. Real value is 6.
Predicted a 9. Real value is 9.
Predicted a 0. Real value is 0.
Predicted a 1. Real value is 1.
{'fraction_non_alphanumeric': 0.11932901258101411, 'fraction_numerical': 0.029736942432329393, 'mean_word_length': 4.594882729211087, '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': '168528', 'license': 'MIT', 'n_tokens_mistral': 968, 'n_tokens_neox': 898, 'n_words': 302, 'path': 'Classes/Class 2/task2.ipynb', 'repo_name': 'Gonkalos/CSC', 'size': '2623'}