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

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

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

More Decks by Alexis Gallagher

Other Decks in Technology


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

    Learning But Was Too Afraid To Ask @alexisgallagher TopologyEyewear
  2. None
  3. None
  4. None
  5. None
  6. 1. What is MACHINE LEARNING really?

  7. func foo() { /* … */ }

  8. func foo() { /* … */ }

  9. let heights = [160,162.2,183,...] ꔅ let expectedHeight = average(heights) ꔅ

    func height() -> Float { return expectedHeight }
  10. 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 } }
  11. 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 + … }
  12. Francis Galton (1822-1911)

  13. 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.
  14. 2. So why all the EXCITEMENT right now ?

  15. Neural networks, circa 1958

  16. Neural networks, circa 2016

  17. None
  18. Deep Learning • Lower layers identify more basic features2 •

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

    Analysis of Deep Neural Network Models for Practical Applications.
  20. Object recognition 2014: funny punchline5 2016: WWDC sample code 5

    xkcd, https://xkcd.com/1425/
  21. 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.
  22. 3. As a SWIFT DEVELOPER you might ask …

  23. Q: Does this affect me? Yes

  24. ML will creep into everything

  25. Q: Could I build an ML model? (even if I'm

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

    not a mathematician?) Yes
  27. 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
  28. Q: Can I build it in Swift? A: Sort of.

  29. 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
  30. 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
  31. Q: What's it like?

  32. 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
  33. Curiously similar to UI design • Cannot prove anything will

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

  35. Q: Where do I start?

  36. 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.
  37. 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
  38. end curious? say hi! (we're hiring) twitter: @alexisgallagher alexis@topologyeyewear.com

  39. 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.
  40. the real end curious? say hi! (we're hiring) twitter: @alexisgallagher