Slide 1

Slide 1 text

Machine Learning with JavaScript

Slide 2

Slide 2 text

@yujiosaka First member / Engineer manager of Author of https://github.com/yujiosaka/headless-chrome-crawler ≒ JavaScript developer (70% JavaScript)

Slide 3

Slide 3 text

‣ What machine learning is from the beginning ‣ How to use machine learning libraries I will not talk about

Slide 4

Slide 4 text

‣ How much we can do for
 machine learning with JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda

Slide 5

Slide 5 text

‣ How much we can do for
 machine learning with JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda

Slide 6

Slide 6 text

Can you seriously do machine learning with JavaScript?

Slide 7

Slide 7 text

Deep learning with Javascript in 2016 https://speakerdeck.com/yujiosaka/enjoy-deep-learning-by-javascript https://github.com/yujiosaka/js-mind https://www.reddit.com/r/node/comments/4dg157

Slide 8

Slide 8 text

Conclusion in 2016 was very sad https://speakerdeck.com/yujiosaka/enjoy-deep-learning-by-javascript?slide=61

Slide 9

Slide 9 text

Q. Why do data scientists choose Python? A. Because the more people use it, the faster it improves https://trends.google.co.jp/trends/explore?date=today%205-y&geo=JP&q=JavaScript,Python,AI

Slide 10

Slide 10 text

Python libraries that boost data science ‣ Numpy / Pandas ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU

Slide 11

Slide 11 text

Python libraries that boost data science ‣ Numpy / Pandas ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU

Slide 12

Slide 12 text

Numpy powered by C, SIMD and math Python + Numpy > import time > import numpy as np > a = np.random.random((1000, 1000)) > b = np.random.random((1000, 1000)) > t = time.time() > np.dot(a, b) > > print(time.time() - t) 0.08162903785705566 JavaScript + math.js > const math = require(‘mathjs’); > > const a = math.random([1000, 1000]); > const b = math.random([1000, 1000]); > const t = Date.now(); > math.multiply(a, b); > > console.log((Date.now() - t) / 1000); 44.166

Slide 13

Slide 13 text

Python libraries that boost data science ‣ Numpy / Pandas ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU

Slide 14

Slide 14 text

Consistant interface (fit, transform, predict) of scikit-learn The LightGBM support in AiDeal was completed by adding several lines of code github.com/Microsoft/LightGBM

Slide 15

Slide 15 text

If it’s for data science you should use Python

Slide 16

Slide 16 text

But if it’s just for machine learning
 JavaScript is also a good option

Slide 17

Slide 17 text

Data science vs. Machine learning Data science requires substantive expertise as well as math and statistics knowledge and hacking skills drewconway.com/zia/2013/3/26/the-data-science-venn-diagram

Slide 18

Slide 18 text

Data science vs. Machine learning But even if you don’t have substantive expertise, you can do machine learning with math and statistics knowledge and hacking skills drewconway.com/zia/2013/3/26/the-data-science-venn-diagram

Slide 19

Slide 19 text

Python libraries that boost data science ‣ Numpy / Pandas ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU

Slide 20

Slide 20 text

Sample code for TensorFlow (Keras) from tensorflow.contrib.keras.python import keras import numpy as np model = keras.Sequential() model.add(keras.layers.Dense(units=1, input_shape=[1])) model.compile(optimizer=‘sgd’, loss=‘mean_squared_error’) xs = np.array([[1], [2], [3], [4]]) ys = np.array([[1], [3], [5], [7]]) model.fit(xs, ys, epochs=1000) print(model.predict(np.array([[5]])))

Slide 21

Slide 21 text

Sample code for TensorFlow.js import * as tf from ‘@tensorlowjs/tfjs’; const model = tf.sequential(); model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({optimizer: ‘sgd’, loss: ‘meanSquaredError’}); const xs = tf.tensor2d([[1], [2], [3], [4]], [4, 1]); const ys = tf.tensor2d([[1], [3], [5], [7]], [4, 1]); await model.fit(xs, ys, {epochs: 1000}); model.predict(tf.tensor2d([[5]], [1, 1])).print(); Utilize GPU with WebGL ≒ Super fast

Slide 22

Slide 22 text

Roadmap to TensorFlow.js 2.0 TensorFlow 2.0 Beta is available! www.tensorflow.org/community/roadmap

Slide 23

Slide 23 text

‣ How much we can do for
 machine learning with JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda

Slide 24

Slide 24 text

Advantages of using JavaScript (especially on browser) ‣ You can share the same code both in frontend and backend (Isomorphic JavaScript) ‣ You can use TypeScript ‣ You can provide interactive UI ‣ You don’t need to install runtime ‣ You can utilize the client side resources

Slide 25

Slide 25 text

Advantages of using JavaScript (especially on browser) ‣ You can share the same code both in frontend and backend (Isomorphic JavaScript) ‣ You can use TypeScript ‣ You can provide interactive UI ‣ You don’t need to install runtime ‣ You can utilize the client side resources - You can save money

Slide 26

Slide 26 text

TensorFlow.js is used for Google’s April Fool 2018 landing.google.co.jp/tegaki/

Slide 27

Slide 27 text

Disadvantages of using JavaScript ‣ It’s vulnerable to reverse engineering ‣ You don’t find enough information on the web ‣ Latest algorithms and classifiers are sometimes not available ‣ There are not sufficient libraries for evaluation metrics, data splitting and etc.

Slide 28

Slide 28 text

Disadvantages of using JavaScript ‣ It’s vulnerable to reverse engineering ‣ You don’t find enough information on the web ‣ Latest algorithms and classifiers are sometimes not available ‣ There are not sufficient libraries for evaluation metrics, data splitting and etc.

Slide 29

Slide 29 text

Typical code you write very often you are using scikit-learn from sklearn.cross_validation import train_test_split from sklearn.grid_search import GridSearchCV from sklearn.metrics import classification_report ... X_train, X_test, y_train, y_test = train_test_split(X, y) ... clf = GridSearchCV(...) … report = classification_report(y_test, y_pred) … Although each function is just a few lines of code, you miss it when you lose it

Slide 30

Slide 30 text

Python vs. JavaScript ‣ Use Python if it’s for data science ‣ Use Python if you are developing a machine learning app from scratch ‣ If you are familiar with JavaScript, you don’t necessarily have to switch to Python ‣ If you want to utilize client side resources, use JavaScript ‣ If you are using TensorFlow, you can train model in Python and predict in JavaScript

Slide 31

Slide 31 text

‣ How much we can do for
 machine learning with JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda

Slide 32

Slide 32 text

JavaScript libraries for machine learning ‣ TensorFlow.js ‣ brain.js ‣ Natural ‣ ml.js ‣ math.js - Keras / TensorFlow compatible library with GPU acceleration - Simple and easy neural networks library with GPU acceleration - General natural language facilities with tokenizing and etc - Compilation of machine learning and numerical analysis libraries - Extensive math library for statistics and matrix operations

Slide 33

Slide 33 text

JavaScript libraries for machine learning ‣ TensorFlow.js ‣ brain.js ‣ Natural ‣ ml.js ‣ math.js - Keras / TensorFlow compatible library with GPU acceleration - Simple and easy neural networks library with GPU acceleration - General natural language facilities with tokenizing and etc - Compilation of machine learning and numerical analysis libraries - Extensive math library for statistics and matrix operations

Slide 34

Slide 34 text

Demo https://github.com/yujiosaka/brain-js-live-demo

Slide 35

Slide 35 text

Machine Learning with JavaScript Enjoy