📚 The CoCalc Library - books, templates and other resources
License: OTHER
Deep Learning with TensorFlow
Credits: Forked from TensorFlow by Google
Setup
Refer to the setup instructions.
Exercise 2
Previously in 1_notmnist.ipynb
, we created a pickle with formatted datasets for training, development and testing on the notMNIST dataset.
The goal of this exercise is to progressively train deeper and more accurate models using TensorFlow.
First reload the data we generated in 1_notmist.ipynb
.
Reformat into a shape that's more adapted to the models we're going to train:
data as a flat matrix,
labels as float 1-hot encodings.
We're first going to train a multinomial logistic regression using simple gradient descent.
TensorFlow works like this:
First you describe the computation that you want to see performed: what the inputs, the variables, and the operations look like. These get created as nodes over a computation graph. This description is all contained within the block below:
Then you can run the operations on this graph as many times as you want by calling
session.run()
, providing it outputs to fetch from the graph that get returned. This runtime operation is all contained in the block below:
Let's load all the data into TensorFlow and build the computation graph corresponding to our training:
Let's run this computation and iterate:
Let's now switch to stochastic gradient descent training instead, which is much faster.
The graph will be similar, except that instead of holding all the training data into a constant node, we create a Placeholder
node which will be fed actual data at every call of sesion.run()
.
Let's run it:
Problem
Turn the logistic regression example with SGD into a 1-hidden layer neural network with rectified linear units (nn.relu()) and 1024 hidden nodes. This model should improve your validation / test accuracy.