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

Machine Learning for Gophers

Machine Learning for Gophers

My dotGo 2017 talk

Francesc Campoy Flores

November 06, 2017
Tweet

More Decks by Francesc Campoy Flores

Other Decks in Programming

Transcript

  1. Machine Learning for
    Gophers
    @francesc

    View Slide

  2. 1996 - Exciting times

    View Slide

  3. 1996 - Exciting times (at least for computers)

    View Slide

  4. 2016 - Very exciting times

    View Slide

  5. 2016 - Very exciting times

    View Slide

  6. name elo rating matches
    Fan Hui 3,144 5:0 against Fan Hui
    Lee Sedol 3,739 4:1 against Lee Sedol
    Master 4,858 60:0 against professional players
    Zero 5,185 100:0 against AlphaGo Lee
    89:11 against AlphaGo Master
    training
    hardware
    176 GPU
    48 TPU
    4 TPU
    4 TPU
    2017 - E_TOO_EXCITE

    View Slide

  7. deepmind.com/blog/alphago-zero-learning-scratch

    View Slide

  8. What is Machine Learning?
    “A computer program is said to learn from experience E, with respect to
    some task T, and some performance measure P, if its performance on T as
    measured by P improves with experience E”
    - Tom Mitchell

    View Slide

  9. What is Machine Learning?
    “A computer program is said to learn from experience E, with respect to
    some task T, and some performance measure P, if its performance on T as
    measured by P improves with experience E”
    - Tom Mitchell

    View Slide

  10. What is Machine Learning?
    “A computer program is said to learn from experience E, with respect to
    some task T, and some performance measure P, if its performance on T as
    measured by P improves with experience E”
    - Tom Mitchell

    View Slide

  11. What is Machine Learning?

    View Slide

  12. What is Machine Learning?
    ● task: recognizing handwritten digits
    ● performance measure: percentage of digits labeled correctly
    ● experience: try to predict, fail, improve it, repeat

    View Slide

  13. Input
    0 0 0 0 0 0 0 0
    0 0 255 0 0 255 0 0
    0 0 255 0 0 255 0 0
    0 0 255 255 255 255 0 0
    0 0 0 0 0 255 0 0
    0 0 0 0 0 255 0 0
    0 0 0 0 0 255 0 0
    0 0 0 0 0 0 0 0
    28 x 28
    , 4

    View Slide

  14. ● Very simple technique
    y = X * W + b
    Logistic regression
    input biases
    weights
    prediction

    View Slide

  15. ● Average of how “off” predictions were
    J = -1/m * sum(dist(pred, label))
    Cost function

    View Slide

  16. ● Finding the W and b that minimize J
    ● We know what direction to go by deriving J vs W and b
    not gonna show that
    Optimizing

    View Slide

  17. mnist tutorial?

    View Slide

  18. Can we do this in Go?

    View Slide

  19. ● Reading images
    ● Multiplying matrices
    ● Visualization of datasets
    ● Making it fast
    What do we need?

    View Slide

  20. ● matrices and linear algebra
    ● statistics
    ● probability distributions
    ● differentiation, integration, and optimization
    ● plotting
    ● and much more!
    gonum

    View Slide

  21. 1
    2m
    (X * theta - y)2
    Σ

    View Slide

  22. gonum
    func ComputeCost(X, y, theta *mat.Dense) float64 {
    m, _ := X.Dims()
    h := new(mat.Dense)
    h.Mul(X, theta)
    h.Sub(h, y)
    h.MulElem(h, h)
    return mat.Sum(h) / float64(2*m)
    }

    View Slide

  23. View Slide

  24. Let’s reinvent the wheel!
    github.com/campoy/mat
    ● focus on API over performance
    ● immutable matrices
    ● only float64 matrices

    View Slide

  25. ComputeCost with github.com/campoy/mat
    func ComputeCost(X, y, theta mat.Matrix) float64 {
    h := mat.Minus(mat.Product(X, theta), y)
    return mat.Product(h, h).Sum() / float64(2 * X.Rows())
    }

    View Slide

  26. demo time! *
    * not guaranteed to work

    View Slide

  27. References
    github.com/campoy/mat
    github.com/campoy/goml
    github.com/campoy/justforfunc
    github.com/campoy/tools/imgcat

    View Slide

  28. Merci!
    @francesc
    VP of Developer Relations at source{d}
    sourced.tech

    View Slide