Slide 1

Slide 1 text

Dōmo arigatō, Mr. Roboto: Machine Learning with Ruby # Eric Weinstein # RubyConf 2016 # Cincinnati, Ohio # 10 November 2016

Slide 2

Slide 2 text

for Joshua

Slide 3

Slide 3 text

Part 0: Hello!

Slide 4

Slide 4 text

About Me eric_weinstein = { employer: 'Hulu', github: 'ericqweinstein', twitter: 'ericqweinstein', website: 'ericweinste.in' } 30% off with RUBYCONF30!

Slide 5

Slide 5 text

Agenda • What is machine learning? • What is supervised learning? • What’s a neural network? • Machine learning with Ruby and the MNIST dataset

Slide 6

Slide 6 text

Part 1: Machine Learning

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

What’s machine learning?

Slide 9

Slide 9 text

In a word:

Slide 10

Slide 10 text

Generalization

Slide 11

Slide 11 text

What’s Supervised Learning? Classification or regression, generalizing from labeled data to unlabeled data

Slide 12

Slide 12 text

Features && Labels • Raw pixel features (vectors of intensities) • Digit (0..9)

Slide 13

Slide 13 text

Features && Labels • Raw pixel features (vectors of intensities) • Digit (0..9)

Slide 14

Slide 14 text

Image credit: https://www.tensorflow.org/versions/r0.9/tutorials/mnist/ beginners/index.html

Slide 15

Slide 15 text

What’s a neural network?

Slide 16

Slide 16 text

Image credit: https://github.com/cdipaolo/goml/tree/master/perceptron

Slide 17

Slide 17 text

Image credit: https://en.wikipedia.org/wiki/Artificial_neural_network

Slide 18

Slide 18 text

Part 2: The MNIST Dataset

Slide 19

Slide 19 text

Our Data • Images of handwritten digits, size-normalized and centered • Training: 60,000 examples, test: 10,000 • http://yann.lecun.com/exdb/mnist/

Slide 20

Slide 20 text

Image credit: https://www.researchgate.net/

Slide 21

Slide 21 text

How’d We Do? • Correct: 9328 / 10_000 • Incorrect: 672 / 10_000 • Overall: 93.28% accuracy

Slide 22

Slide 22 text

Developing the App

Slide 23

Slide 23 text

Front End submit() { fetch('/submit', { method: 'POST', body: this.state.canvas.toDataURL('image/png') }).then(response => { return response.json(); }).then(j => { this.setState({ prediction: j.prediction }); }); }

Slide 24

Slide 24 text

Front End render() { return(
); }

Slide 25

Slide 25 text

Back End train = RubyFann::TrainData.new(inputs: features, desired_outputs: labels) fann = RubyFann::Standard.new(num_inputs: 576, hidden_neurons: [300], num_outputs: 10) fann.train_on_data(train, 1000, 10, 0.01)

Slide 26

Slide 26 text

STOP #demotime

Slide 27

Slide 27 text

Summary • Machine learning is generalization • Supervised learning is labeled data -> unlabeled data • Neural networks are awesome • You can do all this with Ruby!

Slide 28

Slide 28 text

Takeaways (TL;DPA) • We can do machine learning with Ruby • Contribute to tools like Ruby FANN (github.com/tangledpath/ruby-fann) and sciruby (http://sciruby.com/) • Check it out: http://ruby-mnist.herokuapp.com/ • PRs welcome! github.com/ericqweinstein/ruby- mnist

Slide 29

Slide 29 text

Thank You!

Slide 30

Slide 30 text

Questions? eric_weinstein = { employer: 'Hulu', github: 'ericqweinstein', twitter: 'ericqweinstein', website: 'ericweinste.in' } 30% off with RUBYCONF30!