The world of Machine Learning and Computer Intelligence is coming and is a fast-moving train. Faithful to the Atwood's Law, ML also comes to JavaScript. But there is no such thing as a ‘best language for ML’ and it all depends on what you want to build, what is your background and most important - why you get involved in machine learning. This session is about demystifying and bringing machine learning into the browser.
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Machine Learning with JavaScript
1. Nov 18, 2017
Sofia
var title = “Machine Learning with JS”;
var info = {
name: “Ivelin Andreev”,
otherOptional: “Demistifying ML and
Bringing it to the Browser”
};
2. Nov 18, 2017
agenda();
• Why ML with JavaScript?
• JavaScript on the ML Map?
• Introduction to Machine Learning
• Introduction to Neural Networks
• Computer Vision with DNN
• JavaScript ML libraries
• Demo (DeepLearn.js)
3. Nov 18, 2017
Software Architect @
15 years professional experience
.NET Web Development MCPD
External Expert Horizon 2020
External Expert Eurostars-Eureka & IFD
Business Interests
Web Development, SOA, Integration
Security & Performance Optimization
IoT, Computer Intelligence
Contact
ivelin.andreev@icb.bg
www.linkedin.com/in/ivelin
www.slideshare.net/ivoandreev
Who is in front of you?
4. Nov 18, 2017
ML could be used for …
• Predictive maintenance
• Is it likely that the machine will break?
• Based on sensor readings
• Forest fire prediction
• Is it likely that a fire will start
• Based on environment parameters
• Automated teller machine replenishment
• How to optimize ATM replenishment
• Based on historical data for transactions?
• Spear phishing identification
• Is a web site likely to be phishing
• Based on URL and HTTP response
5. Nov 18, 2017
Why ML in the Browser?
• It is possible
• You feel comfortable with JS
• You want to operate offline
• You want to avoid installing on customer computer
• Customers are paranoiac about sending data to a cloud
The Downside…
• JS is a dependency mess
o left-pad in 2016
o OWASP recommend inspection of
dependencies
6. Nov 18, 2017
Main ML Market Players
Azure ML BigML Amazon ML Google
Prediction
IBM Watson ML
Flexibility High High Low Low Low
Usability High Med High Low High
Training time Low Low High Med High
Accuracy (AUC) High High High Med High
Cloud/
On-premises
+/- +/+ +/- +/- +/-
Algorithms Classification
Regression
Clustering
Anomaly detect
Recommendations
Classification
Regression
Clustering
Anomaly
Recommend
Classification
Regression
Classification
Regression
Semantic mining
Hypothesis rank
Regression
Customizations Model parameters
R-script
Evaluation support
Own models
C#, R, Node.js
Few parameters
7. Nov 18, 2017
Pricing?
Azure ML BigML Amazon ML Google
Prediction
IBM Watson
ML
Model Building $1.00 / h
$10.00 / user / month
$30 - $10’000
/ month
$0.42 / h $0.002 / MB $0.45 / h
$10.00 / service
Retraining
(per 1000)
$0.50 - N/A $0.05 -
Prediction
(per 1000)
$0.50 - $0.10 $0.50 $0.50
Compute
(per hour)
$2.00 - $0.42 - -
Free Usage 1’000 / month
2h compute
Dataset Size
Max 16MB
N/A 10’000/month 5’000 / month
5h compute
Notes Private
deployment
$55’000 / year
Shutdown
April 30, 2018
Cloud ML Engine
(TensorFlow)
9. Nov 18, 2017
Do you need Math to work with ML?
• Answer: It is not required, but would definitely help
• Data Science is what is really necessary
Processes and methods for extracting relations and knowledge from data
• Working around Math
• Select the right algorithm
• Use cheat-sheets instead
• Choose parameter settings
• Experiment
• Use parameter-sweep
• Identify underfitting and overfitting
• Compare training and validation scores
10. Nov 18, 2017
I selected an appropriate
ML algorithm but…
why my ML model fails?
11. Nov 18, 2017
ML Decision Tree
Is it an ML task?
No, use another
solution
Is it correctML
scenario?
No, try another
scenario
Is suitable model
identified?
Do you have
enough data?
Is the model overly
complicated?
Correctfeatures
used?
Performed feature
engineering?
Proper evaluation
metrics?
Good evaluation
set?
12. Nov 18, 2017
Neural Networks &
Deep Learning
• Neural-Networks are
considereduniversal
function approximators
• They can compute and
learn any function
13. Nov 18, 2017
• Human vision
o Start percepting light
o Light transferred to electro-chem signals
o Brain neural networks are activated (thinking, memories, feelings)
o Low level patterns recognized (nose, eyes, ears)
o Combined in higher order patterns (animal, fish, male/female)
o Classification - labeling the subject in words (dog, cat, trout)
• Computer Vision
o How do you do that for a computer?
o What are ears and how to describe them?
o How they look from different angles?
• DNN key use is as Classifiers
• Feature extraction - pattern recognition
How Computer Vision Works
14. Nov 18, 2017
Neural Network Architecture
• Nodes, organized in layers, with weighted connections
o Acyclic directed graph
• Layers
o Input (1), Output (1)
o Shallow - 1 hidden layer
o Deep – multiple hidden layers
• Artificial Neuron Model
15. Nov 18, 2017
DNN Training
• 5-stage Process of Supervised Training
o Create a training dataset (X)
o Feed data X to DNN model
o Determine loss (difference between target and predictions)
o Optimize and calculate loss gradient (how fast we are moving towards target)
o Adjust weights of DNN
16. Nov 18, 2017
Artificial Neuron Activation
• Calculates weighted sum of inputs
• Adds bias (function shift)
• Decides whether it shall be
activated
Natural Questions
• Why do we have so many?
• Why some work better than other?
• Which one to use ?
17. Nov 18, 2017
Activation Functions
• Goal
• Convert input -> output signal
• Output signal is input to next layer
• Approximate target function faster
• Samples
• ReLu, PReLu – good to start with
• TanH and Sigmoid – outdated
• Softmax – output layer, classification
• Linear func – output layer,
regression
18. Nov 18, 2017
How does a CNN work?
• Convolution
• Non-Linearity (i.e. PReLU)
• Pooling (Downsample)
• Fully connected (Classify)
• Dropout (Overfitting prevention)
Convolution PoolingEdge detect
filter
19. Nov 18, 2017
Оne stands out …
• DeepLearn.js
JavaScript Libraries for ML
Discontinued
• ConvNet.js
• Machine_Learning
Actively Maintained
• Synaptic.js
• ml.js
• Neataptic.js
• Tensor Fire
20. Nov 18, 2017
Deeplearn.js
• Announced August 11th, 2017 by
• WebGL optimized JS library for ML running in browser
• Open source library in TypeScript
• Can train models and run pre-trained model
• API mimics
• Runs only on Google Chrome
• Future improvements
o Import trained models from Tensorflow
o Add support from other browsers
21. Nov 18, 2017
Tensors
• Math object from Linear Algebra
• Universal standard of modern ML
o General format that could be used for any data
• Examples
o A single image is 3D tensor
o An array of images 4D tensor (samples, width, heights, rgb)
• What is the size as a tensor for 1 min FHD video?
o 60sec*25FPS*1920W*1280H*3RGB = 10.5 GB
o 1000 videos require data reduction
22. Nov 18, 2017
DeepLearn.js Terms
• Tensor Type (int, float)
o float32 only supported
• Tensor Shape
o Size of dimension
• Tensor Rank
o Number of dimensions
• Graph – represents the target calculations
• Session – contains training runtime state
• Tensor data types
o Tensor – reference to Graph object with the properties above
o NDArray – internal implementation that supports GPU via textures
o number[] – JavaScript array to input to DeepLearn.js (interoperability)
Tensor Type Shape Rank
Scalar: 3.0 float [] 0
Vector: (1, 5, -2) int [3] 1
2x2 Matrix int [2, 2] 2
23. Nov 18, 2017
Avoiding Performance Issues
• Blocking UI Thread
WebGLRenderingContext.readPixels()
o WebGL downloads NDArrays from texture to the CPU
o UI thread is blocked while waiting GPU to finish execution
NDArray.data() returns promise<Float32Array>
o Calls readPixels() when the GPU process has completed
• Memory Leaks
o When WebGL textures go out of scope, they don’t get cleaned up
o NDArray must be manually disposed later
o Texture memory leaks cause serious performance issues
const math = new NDArrayMathGPU();
math.scope((keep, track) => { //Function closure declaration
const b = Scalar.new(3); //Texture leak. Math does not know about “b”
const a = track(Scalar.new(3)); //CORRECT
});
25. Nov 18, 2017
The Datasets
MNIST
• A series of handwritten numbers
• 60’000 labeled images
• 28px*28px*1color (grey scale)
• Standard training DS
• >99% accuracy could be achieved
Fashion MNIST
CIFAR-10
26. Nov 18, 2017
Optimization Functions
• Determine how fast algorithm converges to goal while
learning properly.
• Minimize the loss function
• 1st order functions
o SGD, Momentum
o Adagrad, Adadelta, Adam
• 2nd order functions
o More sensitive
o Slower to compute
o Rarely used in practice
A good optimization algorithm makes the difference
between good results in minutes, hours, and days.
27. Nov 18, 2017
Takeaways
• Machine Learning
o Evaluating model performance
o ML algorithms by use case
• Artificial Neural Networks
o Intuitive Explanation of Convolutional Neural Networks
o Stanford Lectures on Convolutional Neural Networks
o Biginners guide to Convolutional Neural Networks
o Understanding activation functions
o Activation functions, which is better
• Deeplearn.js
o API Reference
28. Nov 18, 2017
Thanks to our Sponsors:
General Sponsor:
Gold Sponsors:
Technological Partner:
Hosting Partner:
In-Kind Partner:
Silver Sponsors: