Machine Learning with JavaScript

5d247ff63b1861db5e6a56d4990e5a4f?s=47 yujiosaka
November 05, 2019

Machine Learning with JavaScript

5d247ff63b1861db5e6a56d4990e5a4f?s=128

yujiosaka

November 05, 2019
Tweet

Transcript

  1. Machine Learning with JavaScript

  2. @yujiosaka First member / Engineer manager of Author of https://github.com/yujiosaka/headless-chrome-crawler

    ≒ JavaScript developer (70% JavaScript)
  3. ‣ What machine learning is from the beginning ‣ How

    to use machine learning libraries I will not talk about
  4. ‣ 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
  5. ‣ 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
  6. Can you seriously do machine learning with JavaScript?

  7. 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

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

  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. If it’s for data science you should use Python

  16. But if it’s just for machine learning
 JavaScript is also

    a good option
  17. 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
  18. 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
  19. 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
  20. 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]])))
  21. 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
  22. Roadmap to TensorFlow.js 2.0 TensorFlow 2.0 Beta is available! www.tensorflow.org/community/roadmap

  23. ‣ 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
  24. 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
  25. 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
  26. TensorFlow.js is used for Google’s April Fool 2018 landing.google.co.jp/tegaki/

  27. 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.
  28. 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.
  29. 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
  30. 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
  31. ‣ 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
  32. 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
  33. 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
  34. Demo https://github.com/yujiosaka/brain-js-live-demo

  35. Machine Learning with JavaScript Enjoy