Top Banner
Google confidential | Do not distribute Your first TensorFlow programming with Jupyter Etsuji Nakai Cloud Solutions Architect at Google 2016/08/29 ver1.1
13

Your first TensorFlow programming with Jupyter

Jan 10, 2017

Download

Technology

Etsuji Nakai
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Your first TensorFlow programming with Jupyter

Google confidential | Do not distribute

Your first TensorFlow programming with Jupyter

Etsuji NakaiCloud Solutions Architect at Google2016/08/29 ver1.1

Page 2: Your first TensorFlow programming with Jupyter

Etsuji Nakai

Cloud Solutions Architect at Google

The author of “Introduction to Machine Learning

Theory” (Japanese Book)

New book “ML programming with TensorFlow”

will be published soon!

$ who am i

Page 3: Your first TensorFlow programming with Jupyter

Google's open source library for

machine intelligence

tensorflow.org launched in Nov 2015

Used by many production ML projects

What is TensorFlow?

Page 4: Your first TensorFlow programming with Jupyter

Web based interactive data analysis

platform.

Can be used as a TensorFlow

runtime environment.

What is Jupyter?

How to use Jupyter on GCP? (Japanese Blog)http://enakai00.hatenablog.com/entry/2016/07/03/201117

Page 5: Your first TensorFlow programming with Jupyter

● All calculations are done in a “Session”

● The session contains:○ Placeholders : where you put actual data

○ Variables : to be optimized by the algorithm

○ Functions : consisting of placeholders and variables

○ Training algorithm : to optimize the variables

Programming Paradigm of TensorFlow

Page 6: Your first TensorFlow programming with Jupyter

Programming Paradigm of TensorFlow

● Three steps to write a program with TnesorFlow○ Define a model with placeholders, variables, functions.

○ Define a loss function and a training algorithm.

○ Run session to optimize the variables minimizing the loss

function.

Page 7: Your first TensorFlow programming with Jupyter

Example: Least Squares Method

● Figure out a smooth curve which predicts

next year’s temperature.

● In matrix representation:Monthly average temperature in Tokyo.

VariablePlaceholder

Function

Page 8: Your first TensorFlow programming with Jupyter

● Define a loss function

● In matrix representation:

Example: Least Squares Method

Placeholder

Function

Observed temperature

Prediction vs Observed Values

Page 9: Your first TensorFlow programming with Jupyter

● The matrix representations can be directly

translated into TensorFlow codes.

Example: Least Squares Method

x = tf.placeholder(tf.float32, [None, 5])w = tf.Variable(tf.zeros([5, 1]))y = tf.matmul(x, w)t = tf.placeholder(tf.float32, [None, 1])loss = tf.reduce_sum(tf.square(y-t))

Page 10: Your first TensorFlow programming with Jupyter

● Specify an optimization algorithm.

● Finally, prepare a session and run the optimization loop.

Example: Least Squares Method

sess = tf.Session()sess.run(tf.initialize_all_variables())i = 0for _ in range(100000): i += 1 sess.run(train_step, feed_dict={x:train_x, t:train_t}) if i % 10000 == 0: loss_val = sess.run(loss, feed_dict={x:train_x, t:train_t}) print ('Step: %d, Loss: %f' % (i, loss_val))

train_step = tf.train.AdamOptimizer().minimize(loss)

Putting actual data values in placeholders

Page 11: Your first TensorFlow programming with Jupyter

● You can see the actual result at:○ http://goo.gl/Dojgp4

Example: Least Squares Method

Page 12: Your first TensorFlow programming with Jupyter

Demo: More Interesting Examples!

Page 13: Your first TensorFlow programming with Jupyter

Thank you!