Tensor what? An introduction to AI on mobile Luke Sleeman - - - PowerPoint PPT Presentation

tensor what
SMART_READER_LITE
LIVE PREVIEW

Tensor what? An introduction to AI on mobile Luke Sleeman - - - PowerPoint PPT Presentation

Tensor what? An introduction to AI on mobile Luke Sleeman - Freelance Android developer http://lukesleeman.com luke.sleeman@gmail.com @LukeSleeman Agenda Intro - History of AI, Recent breakthroughs, why AI on mobile is important Part 1


slide-1
SLIDE 1

Tensor what?

An introduction to AI on mobile Luke Sleeman - Freelance Android developer

http://lukesleeman.com luke.sleeman@gmail.com @LukeSleeman

slide-2
SLIDE 2

Agenda

  • Intro - History of AI, Recent breakthroughs, why AI on mobile is important
  • Part 1 - Key AI tech - Neural networks, image recognition, voice

recognition, and Siri work

  • Part 2 - TensorFlow - What TensorFlow does, Server side use, embedding

TensorFlow in a mobile app, models built with TensorFlow

  • Part 3 - Demo - We recognise a banana with my phone!
  • Closing thoughts - Strong AI, Why all this is important.
  • Questions
slide-3
SLIDE 3

Intro - A bit of history

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

Hal 9000 is a great example of “Strong AI”. Hal can:

  • Reason (use strategy, solve puzzles, and make

judgments under uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

slide-7
SLIDE 7

10 Print “Good morning Dave, I am HAL 9000”

slide-8
SLIDE 8

10 Print “Good morning Dave, I am HAL 9000” 20 Input “What can I do for you?”, R$

slide-9
SLIDE 9

10 Print “Good morning Dave, I am HAL 9000” 20 Input “What can I do for you?”, R$ ???

slide-10
SLIDE 10

10 Print “Good morning Dave, I am HAL 9000” 20 Input “What can I do for you?”, R$ 30 Print “I'm sorry, Dave. I'm afraid I can't do that.”

slide-11
SLIDE 11

10 Print “Good morning Dave, I am HAL 9000” 20 Input “What can I do for you?”, R$ 30 Print “I'm sorry, Dave. I'm afraid I can't do that.” 40 Goto 20

slide-12
SLIDE 12

The First AI Winter

"within ten years a digital computer will be the world's chess champion" and "within ten years a digital computer will discover and prove an important new mathematical theorem.” - 1958, H. A. Simon and Allen Newell "Within a generation ... the problem of creating 'artificial intelligence' will substantially be solved.” - 1967, Marvin Minsky

slide-13
SLIDE 13

Present Day

  • IBM’s Deep blue beats Kasparov - 1997
  • DARPA self driving car challenge - 2005, 2007
  • IBM’s Watson wins jeopardy - 2011
  • Googles AlphaGo beats GO champion - 2015
slide-14
SLIDE 14

AI + Mobile = A great combo

slide-15
SLIDE 15

Why AI on mobile is important

Constrained input + limited interaction means intelligence is important

slide-16
SLIDE 16

Part 1 - Key AI Tech

slide-17
SLIDE 17

Key AI Tech - Neural Networks

slide-18
SLIDE 18

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if(x1 + x2 > 0){ … we are in! } else { … we are out! }

slide-19
SLIDE 19

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if(x1 + x2 > 0){ … we are in! } else { … we are out! }

slide-20
SLIDE 20

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if(x1 + x2 > 0){ … we are in! } else { … we are out! }

slide-21
SLIDE 21

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if(x1 + x2 > b){ … we are in! } else { … we are out! }

slide-22
SLIDE 22

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if((w1 * x1) + (w2 * x2) > b){ … we are in! } else { … we are out! }

slide-23
SLIDE 23

Neural Networks - Classification problem

  • 2 dimensions to our data - x1, x2
  • Can draw it helpfully on a graph!

if((w1 *x1) + (w2 * x2) > b){ return 1.0; } else { return 0.0; }

slide-24
SLIDE 24

Neural Networks - Classification problem

slide-25
SLIDE 25

Neural Networks - Classification problem

Lets do a demo!

slide-26
SLIDE 26

Neural networks - Summary

  • They learn to recognise patterns from training data!
  • Work for complex patterns
  • Can take a long time to train
  • You have to choose the right hyper-parameters (number of nodes,

how they are laid out, activation function, input transformation, etc)

slide-27
SLIDE 27

Key AI Tech - Image search and Deep belief networks

slide-28
SLIDE 28

Image search

slide-29
SLIDE 29

Deep belief networks

  • Stack a number of layers together to make a

DBN

  • Early layers learn to recognise simple features
  • Later use features to recognise larger objects
  • A type of ‘auto-encoder’ - learns from input
  • Early unsupervised training to recognise

features

  • Later supervised training to learn what they

‘mean’

slide-30
SLIDE 30

Deep belief network layers

Unsupervised Learning of Hierarchical Representations with Convolutional Deep Belief Networks Honglak Lee, Roger Grosse, Rajesh Ranganath, and Andrew Y. Ng

slide-31
SLIDE 31

Deep belief networks

  • Stack a number of layers together to make a

DBN

  • Early layers learn to recognise simple features
  • Later use features to recognise larger objects
  • A type of ‘auto-encoder’ - learns from input
  • Early unsupervised training to recognise

features

  • Later supervised training to learn what they

‘mean’

slide-32
SLIDE 32

Key AI Tech - Speech recognition and Recurrent Neural Networks

slide-33
SLIDE 33

Speech Recognition

slide-34
SLIDE 34

Speech recognition and Recurrent Neural Networks (RNNs)

  • Everything up to now is a feed

forward network

  • In RNN’s output is fed back in as

input

  • Feedback serves as a type of short

term memory!

  • Takes a sequence of inputs
  • Supplies results over time
slide-35
SLIDE 35

Key AI Tech - Ok Google, Siri and Recursive Neural Tensor Networks

slide-36
SLIDE 36

Ok Google, Hey Siri

slide-37
SLIDE 37

Sentence parsing

slide-38
SLIDE 38

Alice drove down the street in her car

slide-39
SLIDE 39

Recursive Neural Tensor Networks (RNTN’s)

  • Good for recognising hierarchal

structures

  • Tree like structure - root node + left and

right

  • Just like RNN’s, the complexity is in how

they are invoked

Root Leaf Leaf

slide-40
SLIDE 40

Recursive Neural Tensor Networks

The car is fast

slide-41
SLIDE 41

Recursive Neural Tensor Networks

The car

slide-42
SLIDE 42

Recursive Neural Tensor Networks

The car Class, Score

slide-43
SLIDE 43

Recursive Neural Tensor Networks

The car is

slide-44
SLIDE 44

Recursive Neural Tensor Networks

The car is fast

slide-45
SLIDE 45

Recursive Neural Tensor Networks

The car is fast

slide-46
SLIDE 46

Part 2 - TensorFlow

slide-47
SLIDE 47

Tensor What?

slide-48
SLIDE 48

TensorFlow - some code

$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>

slide-49
SLIDE 49

TensorFlow - some code

$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>

slide-50
SLIDE 50

TensorFlow - some code

$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>

slide-51
SLIDE 51

TensorFlow - some code

$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>

slide-52
SLIDE 52

TensorFlow - some code

$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>

slide-53
SLIDE 53

TensorFlow - some code

dnnc = tf.contrib.learn.DNNClassifier( feature_columns=feature_columns, hidden_units=[20, 20, 20, 20], n_classes=2) dnnc.fit(x=latlng_train, y=is_mt_train, steps=200) accuracy = dnnc.evaluate(x=latlng_test, y=is_mt_test)["accuracy"] print('Accuracy: {:.2%}'.format(accuracy))

slide-54
SLIDE 54

TensorFlow - some code

dnnc = tf.contrib.learn.DNNClassifier( feature_columns=feature_columns, hidden_units=[20, 20, 20, 20], n_classes=2) dnnc.fit(x=latlng_train, y=is_mt_train, steps=200) accuracy = dnnc.evaluate(x=latlng_test, y=is_mt_test)["accuracy"] print('Accuracy: {:.2%}'.format(accuracy))

slide-55
SLIDE 55

TensorFlow - some code

dnnc = tf.contrib.learn.DNNClassifier( feature_columns=feature_columns, hidden_units=[20, 20, 20, 20], n_classes=2) dnnc.fit(x=latlng_train, y=is_mt_train, steps=200) accuracy = dnnc.evaluate(x=latlng_test, y=is_mt_test)["accuracy"] print('Accuracy: {:.2%}'.format(accuracy))

slide-56
SLIDE 56

TensorFlow - some code

dnnc = tf.contrib.learn.DNNClassifier( feature_columns=feature_columns, hidden_units=[20, 20, 20, 20], n_classes=2) dnnc.fit(x=latlng_train, y=is_mt_train, steps=200) accuracy = dnnc.evaluate(x=latlng_test, y=is_mt_test)["accuracy"] print('Accuracy: {:.2%}'.format(accuracy))

slide-57
SLIDE 57

Building an app with TensorFlow

slide-58
SLIDE 58

TensorNo

slide-59
SLIDE 59

TensorNo - Use existing APIs

  • Cloud Vision - https://cloud.google.com/vision/
  • Cloud Natural language - https://cloud.google.com/natural-language/
  • Cloud speech - https://cloud.google.com/speech/
  • Cloud Machine Learning Engine - https://cloud.google.com/ml-engine/
  • Amazon Machine Learning - https://aws.amazon.com/machine-

learning/

  • Algorithmia - algorithm marketplace - https://algorithmia.com/algorithms
slide-60
SLIDE 60

TensorFlow on the Server side - DIY

echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh Input: Bob brought the pizza to Alice . Parse: brought VBD ROOT +-- Bob NNP nsubj +-- pizza NN dobj | +-- the DT det +-- to IN prep | +-- Alice NNP pobj +-- . . punct

slide-61
SLIDE 61

TensorFlow on the Server side - gRPC

slide-62
SLIDE 62

Roll your own - Client side

  • Use the tensor flow C++ library with Android NDK or for iOS in

Xcode

  • Load up a prebuilt model, and feed data into it
  • Need to use the Bazel build system for Android!
  • Nasty mix of C, C++, Python, Java, SWIG, etc, various build

systems, etc

  • Google is working on making it nicer
slide-63
SLIDE 63

But what about the model?

  • Build your own? You need:
  • A LARGE data set - MINST has 50k images. ImageNet has 500gb
  • f thumbnails
  • A HUGE computer - 8 Tesla K40 GPU’s ($4216 each), 40GB

memory, etc

  • A lot of time - Weeks! Months!
  • Some PHD’s to run it all for you.
slide-64
SLIDE 64

But what about the model?

  • Use an existing one!
  • SyntaxNet and Parsey McParseface - Parse text, Parse english

text to extract structure

  • TextSum - Text Summarisation
  • Show and Tell - Image caption generator
  • Inception - Image recognition
slide-65
SLIDE 65

Part 3 - Demo

Recognising a banana!

slide-66
SLIDE 66

TensorFlow example app

slide-67
SLIDE 67

The DEMO

slide-68
SLIDE 68

Closing thoughts

slide-69
SLIDE 69
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-70
SLIDE 70
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-71
SLIDE 71
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-72
SLIDE 72
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-73
SLIDE 73
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-74
SLIDE 74
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-75
SLIDE 75
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-76
SLIDE 76
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-77
SLIDE 77
  • Reason (use strategy, solve puzzles, and make judgments under

uncertainty)

  • Represent knowledge, including commonsense

knowledge

  • Plan
  • Learn
  • Communicate in natural language
  • Integrate all these skills towards common goals
  • Kill All Humans

https://en.wikipedia.org/wiki/Artificial_general_intelligence

Are we any closer to strong AI?

slide-78
SLIDE 78

AI needs to be for everyone!

slide-79
SLIDE 79

… especially for mobile!

slide-80
SLIDE 80

Questions