22
Google confidential | Do not distribute Machine Learning Basics for Web Application Developers Etsuji Nakai Cloud Solutions Architect at Google 2016/08/19 ver1.2

Machine Learning Basics for Web Application Developers

Embed Size (px)

Citation preview

Page 1: Machine Learning Basics for Web Application Developers

Google confidential | Do not distribute

Machine Learning Basics

for Web Application Developers

Etsuji NakaiCloud Solutions Architect at Google2016/08/19 ver1.2

Page 2: Machine Learning Basics for Web Application Developers

$ who am i

▪Etsuji NakaiCloud Solutions Architect at Google

Twitter @enakai00

Page 3: Machine Learning Basics for Web Application Developers

Machine Learning Basics

Page 4: Machine Learning Basics for Web Application Developers

Linear Binary Classifier

▪ Build a model to classify two types ofdata with a straight line.● The model will predict the probability of

being in the positive class for new data.● It’s like predicting if the patient is

infected with a specific virus based on thepreliminary check result.

▪ Observe how the model is trained on“Neural Network Playground”

● http://goo.gl/A2G4Hv

x : Positiveo : Negative

Page 5: Machine Learning Basics for Web Application Developers

Logistic Regression

▪ The straight line can be representedas below, which can be translated to aprobability through the logisticfunction σ.

▪ “To train the model” is to adjust theparameters so that themodel fits in the training dataset.

Logistic function σ

Probability ofbeing positive

The value of f increasesin this direction

Page 6: Machine Learning Basics for Web Application Developers

How to measure “fitness” of the model▪ You define the “loss function” which indicates the non-fitness of the model. Then

ML algorithms adjust parameters to minimize the loss function.● In logistic regression, you adjust the parameters to maximize the probability of giving a

perfect prediction for the training dataset.● For example, suppose that n-th data is given as and its correct label is

(1=x, 0=o). Then the probability that the model gives the correct prediction for thisdata is:

● Hence the probability of giving correct predictions for all data is:

● By defining the loss function E as below, you cal tell ML algorithms to minimize it.

Page 7: Machine Learning Basics for Web Application Developers

Graphical Understanding of Linear Classifier

▪ Drawing 3-dimensional graph of ,you can see that the “tilted flat plane”divides the plane into two classes.

Page 8: Machine Learning Basics for Web Application Developers

Linear Multiclass Classifier (Hardmax)

▪ How can you divide the plane intothree classes (instead of two)?

▪ You can define three liner functions andclassify the point based on “which of themhas the maximum value at that point.”

● It is equivalent to dividing with the threetilted flat planes.

Page 9: Machine Learning Basics for Web Application Developers

Linear Multiclass Classifier (Softmax)

▪ You can define the probability thatbelongs to the i-th class as below:

▪ This translates the magnitude ofinto the probability satisfying the followingconditions.

One dimensional example ofthe softmax translation.

Page 10: Machine Learning Basics for Web Application Developers

Image Classificationwith Neural Network

Page 11: Machine Learning Basics for Web Application Developers

Classifying Images with Softmax function

▪ For example, a gray scale image with 28x28pixels can be represented as a 784 dimensionalvector. (i.e a collection of 784 float numbers.)● In other word, it corresponds to a single point in a

784 dimensional space!

▪ When you spread a bunch of images into this 784dimensional space, similar images may cometogether to form clusters of images.● If this is a correct assumption, you can classify the

images by dividing the 784 dimensional space withthe softmax function.

Page 12: Machine Learning Basics for Web Application Developers

Let’s try with TensorFlow Correct Incorrect

http://goo.gl/rGqjYh

▪ You can see the code and its result (92% accuracy).

* Comments are in Japanese.

Page 13: Machine Learning Basics for Web Application Developers

Improving Accuracy using CNN

RawImage

Softmax Function

PoolingLayer

ConvolutionFilter

・・・

ConvolutionFilter

・・・ ・・・

Dropout Layer

Fully-connected Layer

PoolingLayer

ConvolutionFilter

・・・

ConvolutionFilter

PoolingLayer

・・・

PoolingLayer

▪ Instead of providing the raw image data into the softmaxfunction, you can extract “features” of images throughconvolutional filters and pooling layers.

Page 14: Machine Learning Basics for Web Application Developers

Let’s try with TensorFlow

http://goo.gl/UHsVmIhttp://goo.gl/VE2ISf

▪ You can see the code and its result (99.2% accuracy).

Page 15: Machine Learning Basics for Web Application Developers

A new Book for TensorFlow and CNN!

https://www.amazon.co.jp/dp/4839960887/

* This is available only in Japanese now. Please ask publishers in your region to make a translation ;)

Page 16: Machine Learning Basics for Web Application Developers

Client Applications using ML models

Page 17: Machine Learning Basics for Web Application Developers

API services for pre-trained models

http://goo.gl/dh6cwB

▪ See an example.

Send Image

Client

Cloud Service

Reply the location of facesand their emotions.

Page 18: Machine Learning Basics for Web Application Developers

Smile Detection from Webcam Images▪ The browser code sends webcam images to Google Vision API

and notify when you’re smiling ;)

http://goo.gl/9EM8tr

Page 19: Machine Learning Basics for Web Application Developers

Cucumber Classification with TensorFlow▪ A cucumber farmer built an original “Cucumber

sorter” using TensorFlow.

▪ Client application running on RasPi works withthe Aruduino Micro to control the belt conveyorand the sorting devices.

https://cloud.google.com/blog/big-data/2016/08/how-a-japanese-cucumber-farmer-is-using-deep-learning-and-tensorflow

Page 20: Machine Learning Basics for Web Application Developers

Other Possible Architectures

▪ Providing additional data to a pre-trained model to fine-tune it for yourspecific purpose. ● Technically referred as “Transfer Learning.”

▪ Running trained model on the client.● You need a lot of computing resource to train the model. But you can use the

trained model directly on the client.

▪ Realtime model training on the client?● Considering the increasing computing resource available on the client, you may be

able to train the model dynamically on the client using realtime data (such aswebcam images) available on the client.

Page 21: Machine Learning Basics for Web Application Developers

Similarity between model training and application development

Revised Model

AdditionalData

Revised Model

Final Model

Applications

APIaccess

Training

Production environment

Test

Test

Upgrade models

Training

Fix and retry

success

failExistingModels

Version controlof models

Model tunings

Preprocess and feed

Deploy newmodels

▪ This resembles the software development model (CI/CD).▪ There will be some de-fact tools to build this framework

in near future (maybe.)

ExistingModels

ExistingModels

Page 22: Machine Learning Basics for Web Application Developers

Thank you!