Slide 1

Slide 1 text

Everything a Swift Dev Ever Wanted to Know about Machine Learning But Was Too Afraid To Ask @alexisgallagher TopologyEyewear

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

1. What is MACHINE LEARNING really?

Slide 7

Slide 7 text

func foo() { /* … */ }

Slide 8

Slide 8 text

func foo() { /* … */ }

Slide 9

Slide 9 text

let heights = [160,162.2,183,...] ꔅ let expectedHeight = average(heights) ꔅ func height() -> Float { return expectedHeight }

Slide 10

Slide 10 text

let menHeights = [160,162.2,183,...] let womenHeights = [160,150.2,170,...] ꔅ let expectedManHeight = average(menHeights) let expectedWomanHeight = average(womenHeights) ꔅ func height(sex:Sex) -> Float { switch sex { case .female: return expectedWomanHeight case .male: return expectedManHeight } }

Slide 11

Slide 11 text

let data = // data on our age, weight, shoe size, etc.. // ꔅ let (c1, c2, c3, ... ) = ... ꔅ func height(age:Float,weight:Float,shoeSize:Float,…) -> Float { return age * c1 + weight * c2 + shoeSize * c3 + … }

Slide 12

Slide 12 text

Francis Galton (1822-1911)

Slide 13

Slide 13 text

their respective means. Figure 1. Figure 1. Connecting the means of the individual columns of data provides a crude approximation of the regression line. The slope is exactly 0.50 and the correlation is approximately r = 0.51. Many, though not all, Sweetpea size heritability Galton (1894)1 1 Stanton (2001). Galton, Pearson, and the Peas. Journal of Statistics Education.

Slide 14

Slide 14 text

2. So why all the EXCITEMENT right now ?

Slide 15

Slide 15 text

Neural networks, circa 1958

Slide 16

Slide 16 text

Neural networks, circa 2016

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Deep Learning • Lower layers identify more basic features2 • Network discovers intrinsic hierarchy • Deeply cool! 2 Goodfellow, 2016. Deep Learning. Figure 1.2, p 43.

Slide 19

Slide 19 text

Networks getting bigger, faster, more accurate4 4 Canziani 2017, An Analysis of Deep Neural Network Models for Practical Applications.

Slide 20

Slide 20 text

Object recognition 2014: funny punchline5 2016: WWDC sample code 5 xkcd, https://xkcd.com/1425/

Slide 21

Slide 21 text

Human-like, or deeply weird?3 bstract s (DNNs) have recently been performance on a variety of most notably visual classification Ns are now able to classify objects an-level performance, questions differences remain between com- A recent study [30] revealed that a lion) in a way imperceptible to to label the image as something eling a lion a library). Here we easy to produce images that are e to humans, but that state-of-the- ecognizable objects with 99.99% with certainty that white noise ally, we take convolutional neu- form well on either the ImageNet en find images with evolutionary cent that DNNs label with high o each dataset class. It is possi- lly unrecognizable to human eyes ar certainty are familiar objects, ages” (more generally, fooling ex- Figure 1. Evolved images that are unrecognizable to humans, 3 Nguyen 2015. Deep Neural Networks are Easily Fooled: High Confidence Predictions for Unrecognizable Images. Computer Vision and Pattern Recognition, IEEE, 2015.

Slide 22

Slide 22 text

3. As a SWIFT DEVELOPER you might ask …

Slide 23

Slide 23 text

Q: Does this affect me? Yes

Slide 24

Slide 24 text

ML will creep into everything

Slide 25

Slide 25 text

Q: Could I build an ML model? (even if I'm not a mathematician?)

Slide 26

Slide 26 text

Q: Could I build an ML model? (even if I'm not a mathematician?) Yes

Slide 27

Slide 27 text

Google's TensorFlow • Under active development, documented • Loads of official and unofficial tutorials (Siraj Raval on You, etc) • Making ML approachable • TensorFlow version 1 is like Swift version 1

Slide 28

Slide 28 text

Q: Can I build it in Swift? A: Sort of.

Slide 29

Slide 29 text

Build models with Python • Adapt a standard model: plain old regression, existing pre-trained neural network, or one of many off-the-shelf models • Use TensorFlow, in Python (probably) • Train with your data

Slide 30

Slide 30 text

Deployment on iOS in various ways • Talk to TensorFlow server over the network • Embed TensorFlow library in the app • Port to Accelerate • Port to MetalPerformanceShaders

Slide 31

Slide 31 text

Q: What's it like?

Slide 32

Slide 32 text

Reminiscent of AVFoundation and CoreImage • Deferred execution model • Wire up a "session," inputs, outputs, filters • Framework optimizes data flow on hardware • Computation only as needed

Slide 33

Slide 33 text

Curiously similar to UI design • Cannot prove anything will work • Starts with hunches and intuitions • Refined through experiment • 98% correct is major victory!

Slide 34

Slide 34 text

ML

Slide 35

Slide 35 text

Q: Where do I start?

Slide 36

Slide 36 text

Resources • TensorFlow tutorials and summit videos (tensorflow for poets) • Introduction to Machine Learning (Stanford/ Coursera, Andrew Ng) • This Week in Machine Learning & AI podcast • Saraj Raval's YouTube videos • Deep Learning, by Goodfellow et al.

Slide 37

Slide 37 text

Conclusion • Yes, ML really is real • Likely coming soon to an API near you • Increasingly approachable, thanks to tooling and resources. (Version 1.0 all over again!) • Python on the server, Swift in the hand

Slide 38

Slide 38 text

end curious? say hi! (we're hiring) twitter: @alexisgallagher [email protected]

Slide 39

Slide 39 text

Concepts. Model definition vs training vs execution. Training vs test data. Accuracy and loss function. Overfit vs underfit. Models. Linear and logistic regression. Convolutional, recurrent, and adversarial neural networks. Support vector machines. Ensemble regression trees. Etc. Libraries. TensorFlow. Theano. Caffe. Torch. Keras. SciPy. NumPy. HelloWorlds. MNIST. ImageNet. Iris images. Networks. Inception. AlexNet. VGGNet. Resources. Intro to ML, Andrew Ng (Coursera). Siraj Ravel (Youtube). TensorFlow Summit videos. This Week in Machine Learning.

Slide 40

Slide 40 text

the real end curious? say hi! (we're hiring) twitter: @alexisgallagher [email protected]