<jupyter_start><jupyter_text>A Naive Deep learning example<jupyter_code># import mnist
from tensorflow.keras.datasets import mnist
# get data
(train_images,train_labels), (test_images, test_labels) = mnist.load_data()

train_images.shape
len(train_labels)
test_images.shape
len(test_labels)<jupyter_output><empty_output><jupyter_text>The layers are connected to each other via network topolopy. The space in which the network finds the solution is the topological space of these layers and is called hypothesis space.<jupyter_code># import models, layers
from tensorflow.keras import models
from tensorflow.keras import layers

network = models.Sequential()
# Add a layer which takes array of images(28X28 units) (input tensor) as 
#inputs and gives an output(tensor) of shape 512. The rest of dimenttions
# remains the same.
network.add(layers.Dense(512, activation='relu',input_shape = (28*28,)))
network.add(layers.Dense(10, activation='softmax'))<jupyter_output><empty_output><jupyter_text>keras.layers.Dense(512, activation='relu') is similar tooutput = relu(dot(W,input) + b)relu = np.maximum(x,0.)W is weight vectorinput is the neural nodesb is a vector<jupyter_code># setup optimizer, loss function, metrics to monitor 
network.compile(optimizer='rmsprop', 
                loss='categorical_crossentropy', 
                metrics=['accuracy'])


# preparing image data
train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype('float32') / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype('float32') / 255
# preparing the labels
from tensorflow.keras.utils import to_categorical

train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
# Train the network
network.fit(train_images, train_labels, epochs=5, batch_size=128)
# Testing the accuracy and loss on test data
test_loss, test_acc = network.evaluate(test_images, test_labels)
print('test_loss:',test_loss)
print('test_acc:',test_acc)<jupyter_output>10000/10000 [==============================] - 1s 55us/step
test_loss: 0.077565630448
test_acc: 0.9771
{'fraction_non_alphanumeric': 0.11284230406043437, 'fraction_numerical': 0.03918791312559018, 'mean_word_length': 6.540925266903915, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '592086', 'license': 'Unlicense', 'n_tokens_mistral': 745, 'n_tokens_neox': 671, 'n_words': 178, 'path': 'Fundamentals of Deep Learning/Basic Neural Network.ipynb', 'repo_name': 'srivastavaprashant/Deep-Learning', 'size': '2118'}