===================
- Tensorflow Machine Learning Cookbook
- Ch 1: Getting Started with Tensorflow
- Ch 2: The Tensorflow Way
- Ch 3: Linear Regression
- Ch 4: Support Vector Machines
- Ch 5: Nearest Neighbor Methods
- Ch 6: Neural Networks
- Ch 7: Natural Language Processing
- Ch 8: Convolutional Neural Networks
- Ch 9: Recurrent Neural Networks
- Ch 10: Taking Tensorflow to Production
- Ch 11: More with Tensorflow
This chapter intends to introduce the main objects and concepts in Tensorflow. We also introduce how to access the data for the rest of the book and provide additional resources for learning about Tensorflow.
- Here we introduce Tensorflow and the general outline of how most Tensorflow algorithms work.
- How to create and initialize tensors in Tensorflow. We also depict how these operations appear in Tensorboard.
- How to create and use variables and placeholders in Tensorflow. We also depict how these operations appear in Tensorboard.
- Understanding how Tensorflow can work with matrices is crucial to understanding how the algorithms work.
- How to use various mathematical operations in Tensorflow.
- Activation functions are unique functions that Tensorflow has built in for your use in algorithms.
- Here we show how to access all the various required data sources in the book. There are also links describing the data sources and where they come from.
- Mostly official resources and papers. The papers are Tensorflow papers or Deep Learning resources.
After we have established the basic objects and methods in Tensorflow, we now want to establish the components that make up Tensorflow algorithms. We start by introducing computational graphs, and then move to loss functions and back propagation. We end with creating a simple classifier and then show an example of evaluating regression and classification algorithms.
- We show how to create an operation on a computational graph and how to visualize it using Tensorboard.
- We show how to create multiple operations on a computational graph and how to visualize them using Tensorboard.
- Here we extend the usage of the computational graph to create multiple layers and show how they appear in Tensorboard.
- In order to train a model, we must be able to evaluate how well it is doing. This is given by loss functions. We plot various loss functions and talk about the benefits and limitations of some.
- Here we show how to use loss functions to iterate through data and back propagate errors for regression and classification.
- Tensorflow makes it easy to use both batch and stochastic training. We show how to implement both and talk about the benefits and limitations of each.
- We now combine everything together that we have learned and create a simple classifier.
- Any model is only as good as it's evaluation. Here we show two examples of (1) evaluating a regression algorithm and (2) a classification algorithm.
Here we show how to implement various linear regression techniques in Tensorflow. The first two sections show how to do standard matrix linear regression solving in Tensorflow. The remaining six sections depict how to implement various types of regression using computational graphs in Tensorflow.
- How to solve a 2D regression with a matrix inverse in Tensorflow.
- Solving a 2D linear regression with Cholesky decomposition.
- Linear regression iterating through a computational graph with L2 Loss.
- L2 vs L1 loss in linear regression. We talk about the benefits and limitations of both.
- Deming (total) regression implmented in Tensorflow by changing the loss function.
- Lasso and Ridge regression are ways of regularizing the coefficients. We implement both of these in Tensorflow via changing the loss functions.
- Elastic net is a regularization technique that combines the L2 and L1 loss for coefficients. We show how to implement this in Tensorflow.
- We implment logistic regression by the use of an activation function in our computational graph.
This chapter shows how to implement various SVM methods with Tensorflow. We first create a linear SVM and also show how it can be used for regression. We then introduce kernels (RBF Gaussian kernel) and show how to use it to split up non-linear data. We finish with a multi-dimensional implementation of non-linear SVMs to work with multiple classes.
- We introduce the concept of SVMs and how we will go about implementing them in the Tensorflow framework.
- We create a linear SVM to separate I. setosa based on sepal length and pedal width in the Iris data set.
- The heart of SVMs is separating classes with a line. We change tweek the algorithm slightly to perform SVM regression.
- In order to extend SVMs into non-linear data, we explain and show how to implement different kernels in Tensorflow.
- We use the Gaussian kernel (RBF) to separate non-linear classes.
- SVMs are inherently binary predictors. We show how to extend them in a one-vs-all strategy in Tensorflow.
Nearest Neighbor methods are a very popular ML algorithm. We show how to implement k-Nearest Neighbors, weighted k-Nearest Neighbors, and k-Nearest Neighbors with mixed distance functions. In this chapter we also show how to use the Levenshtein distance (edit distance) in Tensorflow, and use it to calculate the distance between strings. We end this chapter with showing how to use k-Nearest Neighbors for categorical prediction with the MNIST handwritten digit recognition.
- We introduce the concepts and methods needed for performing k-Nearest Neighbors in Tensorflow.
- We create a nearest neighbor algorithm that tries to predict housing worth (regression).
- In order to use a distance function on text, we show how to use edit distances in Tensorflow.
- Here we implement scaling of the distance function by the standard deviation of the input feature for k-Nearest Neighbors.
- We use a mixed distance function to match addresses. We use numerical distance for zip codes, and string edit distance for street names. The street names are allowed to have typos.
- The MNIST digit image collection is a great data set for illustration of how to perform k-Nearest Neighbors for an image classification task.
Neural Networks are very important in machine learning and growing in popularity due to the major breakthroughs in prior unsolved problems. We must start with introducing 'shallow' neural networks, which are very powerful and can help us improve our prior ML algorithm results. We start by introducing the very basic NN unit, the operational gate. We gradually add more and more to the neural network and end with training a model to play tic-tac-toe.
- We introduce the concept of neural networks and how Tensorflow is built to easily handle these algorithms.
- We implement an operational gate with one operation. Then we show how to extend this to multiple nested operations.
- Now we have to introduce activation functions on the gates. We show how different activation functions operate.
- We have all the pieces to start implementing our first neural network. We do so here with regression on the Iris data set.
- This section introduces the convolution layer and the max-pool layer. We show how to chain these together in a 1D and 2D example with fully connected layers as well.
- Here we show how to functionalize different layers and variables for a cleaner multi-layer neural network.
- We show how we can improve the convergence of our prior logistic regression with a set of hidden layers.
- Given a set of tic-tac-toe boards and corresponding optimal moves, we train a neural network classification model to play. At the end of the script, you can attempt to play against the trained model.
Natural Language Processing (NLP) is a way of processing textual information into numerical summaries, features, or models. In this chapter we will motivate and explain how to best deal with text in Tensorflow. We show how to implement the classic 'Bag-of-Words' and show that there may be better ways to embed text based on the problem at hand. There are neural network embeddings called Word2Vec (CBOW and Skip-Gram) and Doc2Vec. We show how to implement all of these in Tensorflow.
- We introduce methods for turning text into numerical vectors. We introduce the Tensorflow 'embedding' feature as well.
- Here we use Tensorflow to do a one-hot-encoding of words called bag-of-words. We use this method and logistic regression to predict if a text message is spam or ham.
- We implement Text Frequency - Inverse Document Frequency (TFIDF) with a combination of Sci-kit Learn and Tensorflow. We perform logistic regression on TFIDF vectors to improve on our spam/ham text-message predictions.
- Our first implementation of Word2Vec called, "skip-gram" on a movie review database.
- Next, we implement a form of Word2Vec called, "CBOW" (Continuous Bag of Words) on a movie review database. We also introduce method to saving and loading word embeddings.
- In this example, we use the prior saved CBOW word embeddings to improve on our TF-IDF logistic regression of movie review sentiment.
- Here, we introduce a Doc2Vec method (concatenation of doc and word emebeddings) to improve out logistic model of movie review sentiment.
Convolutional Neural Networks (CNNs) are ways of getting neural networks to deal with image data. CNN derive their name from the use of a convolutional layer that applies a fixed size filter across a larger image, recognizing a pattern in any part of the image. There are many other tools that they use (max-pooling, dropout, etc...) that we show how to implement with Tensorflow. We also show how to retrain an existing architecture and take CNNs further with Stylenet and Deep Dream.
- We introduce convolutional neural networks (CNN), and how we can use them in Tensorflow.
- Here, we show how to create a CNN architecture that performs well on the MNIST digit recognition task.
- In this example, we show how to replicate an architecture for the CIFAR-10 image recognition task.
- We show how to download and setup the CIFAR-10 data for the Tensorflow retraining/fine-tuning tutorial.
- In this recipe, we show a basic implementation of using Stylenet or Neuralstyle.
- This script shows a line-by-line explanation of Tensorflow's deepdream tutorial. Taken from Deepdream on Tensorflow. Note that the code here is converted to Python 3.
Recurrent Neural Networks (RNNs) are very similar to regular neural networks except that they allow 'recurrent' connections, or loops that depend on the prior states of the network. This allows RNNs to efficiently deal with sequential data, whereas other types of networks cannot. We then motivate the usage of LSTM (Long Short Term Memory) networks as a way of addressing regular RNN problems. Then we show how easy it is to implement these RNN types in Tensorflow.
- We introduce Recurrent Neural Networks and how they are able to feed in a sequence and predict either a fixed target (categorical/numerical) or another sequence (sequence to sequence).
- We create an RNN model to improve on our spam/ham SMS text predictions.
- We show how to implement a LSTM (Long Short Term Memory) RNN for Shakespeare language generation. (Word level vocabulary)
- We stack multiple LSTM layers to improve on our Shakespeare language generation. (Character level vocabulary)
- We show how to use Tensorflow's sequence-to-sequence models to train an English-German translation model.
-
Implementing Unit Tests
-
Using Multiple Executors (Devices)
-
Parallelizing Tensorflow
-
Tips for Tensorflow in Production
-
An Example of Productionalizing Tensorflow
-
Visualizing Computational Graphs (with Tensorboard)
-
Clustering Using K-means
-
Working with a Genetic Algorithm
-
Solving a System of ODEs