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

Everything a Swift Dev Ever Wanted to Know Abou...

Everything a Swift Dev Ever Wanted to Know About Machine Learning But Was Too Afraid to Ask

Presented as the opening session at try! Swift, on March 2nd, 2017, in Tokyo.

Alexis Gallagher

March 02, 2017
Tweet

More Decks by Alexis Gallagher

Other Decks in Technology

Transcript

  1. Everything a Swift Dev Ever Wanted to Know about Machine

    Learning But Was Too Afraid To Ask @alexisgallagher TopologyEyewear
  2. 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 } }
  3. 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 + … }
  4. 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.
  5. Deep Learning • Lower layers identify more basic features2 •

    Network discovers intrinsic hierarchy • Deeply cool! 2 Goodfellow, 2016. Deep Learning. Figure 1.2, p 43.
  6. Networks getting bigger, faster, more accurate4 4 Canziani 2017, An

    Analysis of Deep Neural Network Models for Practical Applications.
  7. 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.
  8. Q: Could I build an ML model? (even if I'm

    not a mathematician?) Yes
  9. 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
  10. 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
  11. 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
  12. 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
  13. Curiously similar to UI design • Cannot prove anything will

    work • Starts with hunches and intuitions • Refined through experiment • 98% correct is major victory!
  14. ML

  15. 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.
  16. 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
  17. 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.