Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevFest - Machine Learning on the Web

Galuh Sahid
November 30, 2019

DevFest - Machine Learning on the Web

Galuh Sahid

November 30, 2019
Tweet

More Decks by Galuh Sahid

Other Decks in Technology

Transcript

  1. Machine learning gives computers the ability to learn without being

    explicitly programmed. - Arthur Samuel (1959)
  2. Mathematical representation of a real life process. Model 2000*number of

    floors + … + 5000*number of rooms = house price
  3. 2000*number of floors + … + 5000*number of rooms =

    house price Model error = $5400 3000*number of floors + … + 5000*number of rooms = house price error = $4000
  4. 2000*number of floors + … + 5000*number of rooms =

    house price Model error = $5400 3000*number of floors + … + 5000*number of rooms = house price error = $4000 3000*number of floors + … + 2000*number of rooms = house price error = $2500
  5. Why TensorFlow.js? Browser: !Without installation !Interactive !Data stays in the

    client Server: !Nicely integrates with existing node.js stack
  6. Why TensorFlow.js? Browser: !Without installation !Interactive !Data stays in the

    client Server: !Nicely integrates with existing node.js stack
  7. Machine learning on the web? A machine learning library for

    JavaScript built on top of TensorFlow.js
  8. Machine learning on the web? A machine learning library for

    JavaScript built on top of TensorFlow.js
  9. index.html … <script> async function learnLinear(){ const model = tf.sequential();

    model.add(tf.layers.dense({units: 1, inputShape: [1]})); } learnLinear(); </script> Credit: Laurence Moroney
  10. index.html … <script> async function learnLinear(){ const model = tf.sequential();

    model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); } learnLinear(); </script> Credit: Laurence Moroney
  11. index.html … <script> async function learnLinear(){ const model = tf.sequential();

    model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]); } learnLinear(); </script> Credit: Laurence Moroney
  12. index.html … <script> async function learnLinear(){ const model = tf.sequential();

    model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]); } learnLinear(); </script> Credit: Laurence Moroney y=2x-1
  13. index.html … <script> async function learnLinear(){ const model = tf.sequential();

    model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]); await model.fit(xs, ys, { epochs: 500 }); } learnLinear(); Credit: Laurence Moroney
  14. index.html … model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); const xs

    = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]); const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]); document.getElementById("output_field").innerText = model.predict( tf.tensor2d([10], [1, 1]) ); } learnLinear(); </script> </html> Credit: Laurence Moroney y=2x-1 2(10)-1 = 19
  15. What’s next? ! A Beginner’s Guide to Machine Learning in

    JavaScript by Daniel Shiffman ! Magenta.js - music & art with machine learning ! Coursera: Machine Learning by Andrew Ng ! Machine learning + hardware ! ml5.js source code ! Bias in machine learning - book reference: Weapons of Math Destruction oleh Cathy O’Neil