0% found this document useful (0 votes)
17 views

MLwith JS

This document discusses using machine learning with JavaScript, including reasons for doing so, common components of ML systems, and examples of libraries for tasks like visualization, computation, and NLP. It covers libraries like TensorFlow.js, Plotly.js, and tsne.js and provides code samples and links to further resources.

Uploaded by

Cynthia Paramita
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

MLwith JS

This document discusses using machine learning with JavaScript, including reasons for doing so, common components of ML systems, and examples of libraries for tasks like visualization, computation, and NLP. It covers libraries like TensorFlow.js, Plotly.js, and tsne.js and provides code samples and links to further resources.

Uploaded by

Cynthia Paramita
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Machine Learning with

JavaScript
Resources
Why ML with JS?
• Server cost
• Lowered inference latency
• Audio, Video, Images
• Data privacy
• Instant WebGL acceleration
• Supports for GPU acceleration
• Instant access
• Zero install
• Portability
• Works on multiple platforms
• Can switch to server mode with Node.js
Components of a ML System
• Visualization
• Custom codes with d3.js
• plotly.js (similar to pyplot in Python) and others (cola.js, c3.js)
• Computation
• Custom codes for ML algorithms (See reference 1)
• TensorFlow.js (similar to keras in Python) (See reference 2)
• Some other packages (tsne.js, scagnostics.js)
Plotly.js https://plot.ly/javascript/
• Visualization library built on top of d3.js
• Pros:
• Quick to visualize data with rich features and interactions
• Cons:
• Slow in many cases
• Not flexible
Web Worker https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API
• ML is computation intensive
• Web Worker help to
• Support parallelism
• Non-blocking GUI (and interaction)
t-Distributed Stochastic Neighbor Embedding
• Why tsne?
• Linear methods for dimensional reduction vs. Non-linear methods
dimensional reduction
• Inter-cluster and Intra-cluster distances
• tsne.js
• https://github.com/karpathy/tsnejs
• Playground
• https://distill.pub/2016/misread-tsne/
t-SNE main ideas
Kullback Leiber Divergence

Dog Cat Fish Horse Mouse


High dimensional space (P) 0.5 x 0.05 0.15 0.3
Low dimensional space (Q) 0.6 x 0.06 0.14 0.2

Distances to probabilities
Scagnostics
ScagnosticsJS
• Documentation and main ideas
• https://idatavisualizationlab.github.io/Scagnostics2018
Natural Language Processing
• Natural Language Processing
• Sentiment Analysis
• Topic Modeling
• Resources
• spaCy: https://explosion.ai/demos/
• IBM: https://natural-language-understanding-demo.ng.bluemix.net/
TensorFlow.jshttps://playground.tensorflow.org
Example
Installation
• Visualization
• <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

• Calculation
• <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
Data

https://codepen.io/tfjs-book/pen/dgQVze
Visualization

https://codepen.io/tfjs-book/pen/dgQVze
Converting data into tensors
Defining a simple model
Defining the model

Compiling the model

Simple linear model in this case


Fitting the model
Results for different epochs

https://codepen.io/tfjs-book/pen/VEVMMd
References

You might also like