intro to deep learning w/ clojure

47
Intro to Deep Learning w/ Clojure It’s Difficult to Make Predictions. Especially About the Future. @JulioBarros Consultant E-String.com @JulioBarros http://E-String.com 1

Upload: juio-barros

Post on 21-Jan-2018

1.038 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Intro to Deep Learning w/ Clojure

Intro to Deep Learning w/ ClojureIt’s Difficult to Make Predictions.Especially About the Future.

@JulioBarrosConsultantE-String.com

@JulioBarros http://E-String.com 1

Page 2: Intro to Deep Learning w/ Clojure

Hypothesis

Given that Python dominates ML/DL;Is there a valid use case for Clojure?TL;DR -- It depends

@JulioBarros http://E-String.com 2

Page 3: Intro to Deep Learning w/ Clojure

I Hope So

... and I'm not the only one.

@JulioBarros http://E-String.com 3

Page 4: Intro to Deep Learning w/ Clojure

Hype or Reality?

@JulioBarros http://E-String.com 4

Page 5: Intro to Deep Learning w/ Clojure

"It is a renaissance, it is a golden age,"

"Machine learning and AI is a horizontal enabling layer. It will empower and improve every business, every government organization, every philanthropy — basically there's no institution in the world that cannot be improved with machine learning."— Bezos

@JulioBarros http://E-String.com 5

Page 6: Intro to Deep Learning w/ Clojure

Every industry can expect to be transformed by Artificial Intelligence

@JulioBarros http://E-String.com 6

Page 7: Intro to Deep Learning w/ Clojure

Image Classification

Justin Johnson, Andrej Karpathy, Li Fei-Fei - Stanford@JulioBarros http://E-String.com 7

Page 8: Intro to Deep Learning w/ Clojure

My dog Rex

@JulioBarros http://E-String.com 8

Page 9: Intro to Deep Learning w/ Clojure

Object Detection

@JulioBarros http://E-String.com 9

Page 10: Intro to Deep Learning w/ Clojure

Image Captioning

@JulioBarros http://E-String.com 10

Page 11: Intro to Deep Learning w/ Clojure

Dense Captioning

@JulioBarros http://E-String.com 11

Page 12: Intro to Deep Learning w/ Clojure

Healthcare

Near or better than human level performance.

@JulioBarros http://E-String.com 12

Page 13: Intro to Deep Learning w/ Clojure

Business

— Law & Finance— Text, audio, image, video understanding— Churn prediction, customer segmentation— Product recommendations— Manufacturing, maintenance and control— Many many more

@JulioBarros http://E-String.com 13

Page 14: Intro to Deep Learning w/ Clojure

Artificial Intelligence

Artificial Intelligence (AI) - the study of "intelligent agents". Reasoning, knowledge representation, planning, robotics, etc.

— Artificial Narrow Intelligence (ANI)— Artificial General Intelligence (AGI)— Artificial Superintelligence (ASI)

@JulioBarros http://E-String.com 14

Page 15: Intro to Deep Learning w/ Clojure

Machine Learning

Machine Learning (ML) - Programs that learn from the data and make predictions.

@JulioBarros http://E-String.com 15

Page 16: Intro to Deep Learning w/ Clojure

Types of prediction

Regression - continuous values

Classification - discreet values/labels

@JulioBarros http://E-String.com 16

Page 17: Intro to Deep Learning w/ Clojure

Types of ML Algorithms

Supervised - trained on labeled data (regression or classification).

Unsupervised - trained on unlabeled data (clustering, segmentation).

Reinforcement - learns based on outcomes/results of actions.

@JulioBarros http://E-String.com 17

Page 18: Intro to Deep Learning w/ Clojure

Deep Learning

Deep Learning (DL) - ML/AI using artificial neural networks (ANNs)

You might be thinking ...

What? Isn't that just a neural net? Didn't we show those don't work. Twice.

@JulioBarros http://E-String.com 18

Page 19: Intro to Deep Learning w/ Clojure

Third time is a charm

Capabilities of neural nets have changed dramatically due to advancements in:

— Data

— Algorithms

— Hardware

@JulioBarros http://E-String.com 19

Page 20: Intro to Deep Learning w/ Clojure

Neurons: Biologically inspired

1942 McCulloch and Pitts1957 Rosenblatt

(A (+ b (apply + (map * x w)))

@JulioBarros http://E-String.com 20

Page 21: Intro to Deep Learning w/ Clojure

Activation Function

Introduces non linearity

— Historicaly: Identity, Step, Tanh, Sigmoid

— Currently: Rectified linear Unit (relu), Softmax

@JulioBarros http://E-String.com 21

Page 22: Intro to Deep Learning w/ Clojure

Universal Approximation Theorem (1989)

... a feed-forward network with a single hidden layer containing a finite number of neurons can approximate continuous functions ...

@JulioBarros http://E-String.com 22

Page 23: Intro to Deep Learning w/ Clojure

Deep Neural Nets

A net with more than one hidden layer.

@JulioBarros http://E-String.com 23

Page 24: Intro to Deep Learning w/ Clojure

VGG16

@JulioBarros http://E-String.com 24

Page 25: Intro to Deep Learning w/ Clojure

GoogleLeNet

@JulioBarros http://E-String.com 25

Page 26: Intro to Deep Learning w/ Clojure

Training

1) Initialize weights randomly

2) Make prediction

3) Measure error (loss)

4) Adjust weights in the right direction

5) GOTO 2

Repeat over and over and over again with your training data

@JulioBarros http://E-String.com 26

Page 27: Intro to Deep Learning w/ Clojure

Backpropagation

Finding the right direction.

@JulioBarros http://E-String.com 27

Page 28: Intro to Deep Learning w/ Clojure

Backpropagation

To know the right direction calculate the gradient of the loss function with respect to each weight. Multiply by the error and a learning rate to get the delta.

Don't worry. The libraries do it for you.

@JulioBarros http://E-String.com 28

Page 29: Intro to Deep Learning w/ Clojure

Millions of Knobs Parameters

@JulioBarros http://E-String.com 29

Page 30: Intro to Deep Learning w/ Clojure

A Simple Neural Net in Cortex

(def network-architecture [(layers/input 11 1 1 :id :x)

(layers/linear 64) (layers/relu)

(layers/linear 1 :id :y)])

@JulioBarros http://E-String.com 30

Page 31: Intro to Deep Learning w/ Clojure

Wine Quality Data

11 features, 1 target column

@JulioBarros http://E-String.com 31

Page 32: Intro to Deep Learning w/ Clojure

UCI Machine Learning Repository

https://archive.ics.uci.edu/ml/datasets/Wine+Quality

Source: Paulo Cortez, University of Minho, Guimarães, Portugal, http://www3.dsi.uminho.pt/pcortez A. Cerdeira, F. Almeida, T. Matos and J. Reis, Viticulture Commission of the Vinho Verde Region(CVRVV), Porto, Portugal @2009

@JulioBarros http://E-String.com 32

Page 33: Intro to Deep Learning w/ Clojure

Normalized / Scaled data (Standardized)

@JulioBarros http://E-String.com 33

Page 34: Intro to Deep Learning w/ Clojure

Demo

https://github.com/thinktopic/cortexhttps://github.com/JulioBarros/clj-dl-demo

@JulioBarros http://E-String.com 34

Page 35: Intro to Deep Learning w/ Clojure

How Do We Work With Images

Well, images are just numbers/data.

Though numbers close to each other are more related.@JulioBarros http://E-String.com 35

Page 36: Intro to Deep Learning w/ Clojure

Convolutional Layers

Similar to correlations from signal processing or filters from photoshop.

A small NxN filter is slid over and convolved/correlated with the image. Learns to find features.

Then lower level features are combined into higher level features.

@JulioBarros http://E-String.com 36

Page 37: Intro to Deep Learning w/ Clojure

Common Types of Layers

— input / output— fully connected (dense)— activation - relu, softmax— convolutional— maxpool— flatten— drop out

@JulioBarros http://E-String.com 37

Page 38: Intro to Deep Learning w/ Clojure

Types of ANN

1. Dense Neural Net (DNN)2. Convolutional Neural Net (CNN)3. Recurrent Neural Net (RNN)4. Everything else

@JulioBarros http://E-String.com 38

Page 39: Intro to Deep Learning w/ Clojure

Programming Abstractions

Level Python CLJ/JVM

DSL/API Keras, Lasagne, TF-Slim Cortex, ???

Computation Graph, Backprop, Autograd

Tensorflow, Theano, Torch, Pytorch, Caffe, MXNet, CNTK

Cortex, dl4j, Java bindings

Matrix Math CUDA (cuDNN), Eigen3 Neandertal, core.matrix, vectorz-clj

@JulioBarros http://E-String.com 39

Page 40: Intro to Deep Learning w/ Clojure

Production Considerations

— Target hardware environment— GPU(s)— Powerful multicore server— Mobile device— Embedded

— Desired latency / scalability— Data pipeline— Software engineering practices@JulioBarros http://E-String.com 40

Page 41: Intro to Deep Learning w/ Clojure

Don't Underestimate the Last Two

We need to consider running and maintaining the models in production.

@JulioBarros http://E-String.com 41

Page 42: Intro to Deep Learning w/ Clojure

Approaches

— Python based environment— Clojure based environment— Generate C++ binaries— API calls to third party— API calls to microservices

@JulioBarros http://E-String.com 42

Page 43: Intro to Deep Learning w/ Clojure

Challenges with DL

— Needs lots of data. Labeled data is expensive.— Lacks explain-ability— Performance requirements - training and inference— Max performance unclear— Best architecture unclear

@JulioBarros http://E-String.com 43

Page 44: Intro to Deep Learning w/ Clojure

Benefits of DL

— Handles much of the feature engineering

— Handles complex (non linear) problems

— Advancements coming quickly

@JulioBarros http://E-String.com 44

Page 45: Intro to Deep Learning w/ Clojure

Recommendations

Do not be intimidated by ANNs or the math.

Start with Keras (and Tensorflow or Theano) tutorials (or maybe Pytorch).

Later choose language/framework as needs dictate.

@JulioBarros http://E-String.com 45

Page 46: Intro to Deep Learning w/ Clojure

Resources

Andrew Ng's Coursera Course and Fast.AI Mooc

Deep Learning Book - Goodfellow, Bengio and Courville

Meetups- Portland-Data-Science-Group- Portland-Machine-Learning-Meetup- Portland-Deep-Learning

@JulioBarros http://E-String.com 46

Page 47: Intro to Deep Learning w/ Clojure

Thank you! Questions?

[email protected] @JulioBarros@JulioBarros http://E-String.com 47