The TensorFlow dance craze
-
Upload
gabriel-hamilton -
Category
Software
-
view
25 -
download
1
Transcript of The TensorFlow dance craze
![Page 1: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/1.jpg)
The TensorFlow dancecraze
Gabe Hamilton
![Page 2: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/2.jpg)
TensorFlow is a Machine Learning library
![Page 3: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/3.jpg)
What is Machine Learning?
usually: Statistical Pattern Matching
Using past measurements to predict something about a new piece of information
![Page 4: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/4.jpg)
Does this picture contain a cat? Classification
How much is this home worth? Regression
Regression Talk https://docs.google.com/presentation/d/17FoojZ17DKDZqoByhB16PmtAXtnJtXSy1-feK9-A_fg/edit#slide=id.p10
![Page 5: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/5.jpg)
There are lots of other ML libraries
![Page 6: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/6.jpg)
Is it right for you?
Maybe Not, use Prediction APIhttp://www.slideshare.net/gabehamilton/intro-to-google-prediction-api-15167420
Or equivalent Amazon or Microsoft APIs
if you have a CSV of observed data.
![Page 7: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/7.jpg)
But I’d like to get into the details or I am working on
a complex problem...
![Page 8: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/8.jpg)
You do still have some choices.Some people prefer Keras on top of TensorFlow https://keras.io/ or tf-slim or pretty-tensor
![Page 9: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/9.jpg)
So why use TensorFlow?
It’s not much different than the “easier” libraries.
You’ll want to understand more and more details anyway.
Because you like
It has the hottest dance moves!
![Page 10: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/10.jpg)
Look out a Tensor!
![Page 11: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/11.jpg)
Some Math and a Multi-Dimensional Array had a baby
![Page 12: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/12.jpg)
For our purposesIt’s a multi-dimensional array.
Just remember that you are putting a mathematical construct in that array.
A tensor is a multi-dimensional array with certain transformation properties
![Page 13: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/13.jpg)
You have some dataEven though it’s in a 2D spreadsheet it can describe a multidimensional space.
House Price Data 1 mile to park 2 bedrooms 1800 sq ft
So our Tensor is [1, 2, 1800]Square footage
Distance to park
# of bathrooms
![Page 14: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/14.jpg)
Let’s build a Tensor Machine
= a Tensor
![Page 15: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/15.jpg)
Comparing outputis our Output
But we are expecting
- = Loss
![Page 16: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/16.jpg)
Iterate until we have a good model
![Page 17: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/17.jpg)
DemoSimple Regression
https://github.com/gabehamilton/code-from-talks/tree/master/tensorflow_intro
![Page 18: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/18.jpg)
Demo (run in Datalab)
![Page 19: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/19.jpg)
Demo code: fitting a line to pointsDemo is of Datalab notebook# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
tf.reset_default_graph()
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x_measured = np.random.rand(100).astype(np.float32)
y_measured = x_measured * (0.1 + (0.05 *np.random.rand(100))) + 0.3
plt.scatter(x_measured, y_measured)
plt.xlabel('<- Bluer : Uniform Color : Redder ->')
plt.ylabel('Deaths per mission')
plt.title('Star Trek Uniform Color Mortality Incidence')
# plt.plot([0, 1], [0, 0.5], color='purple', lw=2)
# plt.plot([0, 1], [0.25, 0.5], color='purple', lw=2)
Measured Data
![Page 20: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/20.jpg)
Demo code continuedimport tensorflow as tf
# Try to find values for slope and offset that match
# y_measured = slope * x_measured + offset
slope = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
offset = tf.Variable(tf.zeros([1]))
y_predicted = slope * x_measured + offset
loss = tf.reduce_mean(tf.square(y_predicted - y_measured))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
A test value for slope
![Page 21: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/21.jpg)
Demo code continued# Launch the graph.
sess = tf.Session()
sess.run(tf.initialize_all_variables()) # and initialize variables
# Fit the line.
print 'step #\t', 'slope\t\t', 'offset'
for step in range(201):
sess.run(train)
if step % 20 == 0:
print step,'\t', sess.run(slope)[0], '\t', sess.run(offset)[0]
A test value for slope and offset
![Page 22: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/22.jpg)
Q & APlus more slides for longer talks or
answering questions
![Page 23: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/23.jpg)
Why TensorFlow is useful
Build your graph in a high level language, execute in fast implementations.
Distribute graph operations across processors.
Whole graph can be optimized.
![Page 24: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/24.jpg)
4+ D Spaces
A given measurement all fits into a simple Tensor: [4, 4, 4, 3]
![Page 25: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/25.jpg)
Some Tensors
Scalar 0.2Vector [1, 2, 1800]Matrix [2, 1, 1], [1, 2, 0], [0, 1, 0]
n-Tensors
![Page 26: The TensorFlow dance craze](https://reader034.fdocuments.in/reader034/viewer/2022042619/5877d9c01a28abaa6c8b5ecd/html5/thumbnails/26.jpg)
Rank 2 Tensor
When a bunch of vectors hang out they make a Matrix
[2, 1, 1],[1, 2, 0],[0, 1, 0]