Upload
etsuji-nakai
View
1.651
Download
0
Embed Size (px)
Citation preview
Google confidential | Do not distribute
Machine Learning Basics
for Web Application Developers
Etsuji NakaiCloud Solutions Architect at Google2016/08/19 ver1.2
$ who am i
▪Etsuji NakaiCloud Solutions Architect at Google
Twitter @enakai00
Machine Learning Basics
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
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
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.
Graphical Understanding of Linear Classifier
▪ Drawing 3-dimensional graph of ,you can see that the “tilted flat plane”divides the plane into two classes.
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.
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.
Image Classificationwith Neural Network
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.
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.
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.
Let’s try with TensorFlow
http://goo.gl/UHsVmIhttp://goo.gl/VE2ISf
▪ You can see the code and its result (99.2% accuracy).
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 ;)
Client Applications using ML models
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.
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
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
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.
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
Thank you!