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

Machine Learning for Developers

Machine Learning for Developers

Voxxed Days Zurich, February 23rd, 2017

Have you always wanted to add predictive capabilities or voice recognition to your application, but haven’t been able to find the time or the right technology to get started? Everybody wants to build smart apps, but only a few are Data Scientists. This session will help you understand machine learning terminology & challenges, implement a machine learning model, add predictive capabilities to your app, and provide your customer with voice UX.

Danilo Poccia

February 23, 2017
Tweet

More Decks by Danilo Poccia

Other Decks in Programming

Transcript

  1. Machine Learning
    for Developers
    Danilo Poccia
    @danilop danilop
    AWS Technical Evangelist

    View Slide

  2. Credit: Gerry Cranham/Fox Photos/Getty Images
    http://www.telegraph.co.uk/travel/destinations/europe/united-kingdom/england/london/galleries/The-history-of-the-Tube-in-pictures-150-years-of-London-Underground/1939-ticket-examin/

    View Slide

  3. 1939 London Underground
    Credit: Gerry Cranham/Fox Photos/Getty Images
    http://www.telegraph.co.uk/travel/destinations/europe/united-kingdom/england/london/galleries/The-history-of-the-Tube-in-pictures-150-years-of-London-Underground/1939-ticket-examin/

    View Slide

  4. Batch
    Reports
    Real-Time
    Alerts
    Prediction
    Forecasts

    View Slide

  5. Predictions

    View Slide

  6. Data Predictions

    View Slide

  7. Data Model Predictions

    View Slide

  8. Model

    View Slide

  9. http://www.thehudsonvalley.com/articles/60-years-ago-today-local-technology-demonstrated-artificial-intelligence-for-the-first-time
    1959 Arthur Samuel

    View Slide

  10. Machine Learning

    View Slide

  11. Machine Learning
    Supervised
    Learning
    Inferring a model
    from labeled
    training data

    View Slide

  12. Machine Learning
    Supervised
    Learning
    Unsupervised
    Learning
    Inferring a model
    from labeled
    training data
    Inferring a model
    to describe hidden
    structure from
    unlabeled data

    View Slide

  13. Reinforcement
    Learning
    Perform a certain
    goal in a
    dynamic
    environment

    View Slide

  14. Driving a vehicle
    Playing a game
    against an opponent

    View Slide

  15. Clustering

    View Slide

  16. Clustering

    View Slide

  17. Topic Modeling
    Discovering abstract “topics”
    that occur in a collection of documents
    Try that with your own emails ;-)

    View Slide

  18. Regression “How many bikes will
    be rented tomorrow?”
    Happy, Sad, Angry,
    Confused, Disgusted,
    Surprised, Calm,
    Unknown
    Binary
    Classification
    Multi-Class
    Classification
    “Is this email spam?”
    “What is the
    sentiment of this
    tweet, or of this social
    media comment?”
    1, 0, 100K
    Yes, No
    True, False
    %

    View Slide

  19. Training the Model
    Minimizing the Error

    View Slide

  20. Validation

    View Slide

  21. Labeled Data

    View Slide

  22. Labeled Data
    70%
    30%
    Training
    Validation

    View Slide

  23. Be Careful of Overfitting

    View Slide

  24. Be Careful of Overfitting

    View Slide

  25. Be Careful of Overfitting

    View Slide

  26. Better Fitting

    View Slide

  27. Better Fitting

    View Slide

  28. Different Models ⇒ Different Predictions

    View Slide

  29. Adding a “cost” for using
larger
    parameters in the model
    L1, L2,
    Neural Network Dropouts
    Regularization

    View Slide

  30. Large numbers can have a bigger impact
    in a mathematical model
    Feature Scaling
    So they are all in the same range,
    For example between 0 and 1
    Normalization

    View Slide

  31. Model Parameters
    “Hyperparameters”

    View Slide

  32. Labeled Data
    70%
    15%
    Training
    Validation
    15% Test
    Try Different
    Hyperparameters

    View Slide

  33. Labeled Data
    Cross Validation

    View Slide

  34. Neural
    Networks

    View Slide

  35. 1943 Warren McCulloch, Walter Pitts
    Threshold
    Logic
    Units

    View Slide

  36. 1962 Frank Rosenblatt
    Perceptron

    View Slide

  37. https://github.com/cdipaolo/goml/tree/master/perceptron
    weights activation function
    input output

    View Slide

  38. https://en.wikipedia.org/wiki/Artificial_neural_network
    Multiple Layers
    Backpropagation

    View Slide

  39. Microprocessor Transistor Counts 1971-2011
    Intel E7 CPU
    4-24 cores
    NVIDIA K80 GPU
    2,496 cores
    https://en.wikipedia.org/wiki/Moore's_law

    View Slide

  40. LeCun, Gradient-Based
    Learning Applied to Document
    Recognition,1998
    Hinton, A Fast Learning
    Algorithm for Deep Belief
    Nets, 2006
    Bengio, Learning Deep
    Architectures for AI, 2009
    Advances in Research 1998-2009

    View Slide

  41. Image
    Processing

    View Slide

  42. Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg
    Convolution Matrix

    View Slide

  43. Convolution Matrix
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  44. Convolution Matrix
    0 0 0
    0 1 0
    0 0 0
    Identity
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  45. Convolution Matrix
    1 0 -1
    2 0 -2
    1 0 -1
    Left Edges
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  46. Convolution Matrix
    -1 0 1
    -2 0 2
    -1 0 1
    Right Edges
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  47. Convolution Matrix
    1 2 1
    0 0 0
    -1 -2 -1
    Top Edges
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  48. Convolution Matrix
    -1 -2 -1
    0 0 0
    1 2 1
    Bottom Edges
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  49. Convolution Matrix
    0.6 -0.6 1.2
    -1.4 1.2 -1.6
    0.8 -1.4 1.6
    Random Values
    Photo by David Iliff. License: CC-BY-SA 3.0
    https://commons.wikimedia.org/wiki/File:Colosseum_in_Rome,_Italy_-_April_2007.jpg

    View Slide

  50. Convolutional Neural Networks (CNNs)
    https://en.wikipedia.org/wiki/Convolutional_neural_network

    View Slide

  51. ImageNet Classification Error Over Time
    0
    5
    10
    15
    20
    25
    30
    2010 2011 2012 2013 2014 2015 2016
    Classification Error
    CNNs

    View Slide

  52. 2012 ImageNet Classification with Deep Convolutional Neural Networks

    View Slide

  53. SuperVision: 8 layers, 60M parameters
    0

    View Slide

  54. 2013 Visualizing and Understanding Convolutional Networks

    View Slide

  55. View Slide

  56. View Slide

  57. How Do Neural Networks Learn?
    ?
    More generic and can be reused
    as feature extractor for other visual tasks
    Specific
    to task
    Cat
    Dog
    0

    View Slide

  58. output
    input
    state
    output
    input
    state(t)
    memory
    Feedforward
    Neural Networks
    (no cycle)
    Recurrent
    Neural Networks
    (directed cycle)
    What About Memory?

    View Slide

  59. https://en.wikipedia.org/wiki/Long_short-term_memory
    Long Short-Term Memory (LSTM)
    How much
    goes into
    memory
    How much
    is used
    in computing
    the output
    How much
    remains in
    memory

    View Slide

  60. http://www.asimovinstitute.org/neural-network-zoo/
    Lots of Parameters
    Network Architectures
    defined by Hyperparameters
    Dropout Layers
    for Regularization

    View Slide

  61. Generative Adversarial Networks (GANs)
    Generator
    Neural
    Network
    Discriminator
    Neural
    Network
    Real or
    Generated?
    Real
    Picture
    Generated
    Picture

    View Slide

  62. 2014
    Generative Adversarial Networks (GANs)

    View Slide

  63. 2016
    Generative Adversarial Networks (GANs)

    View Slide

  64. How much can you improve?
    Bayes Limit Vs Human Performance
    Training better than Validation?
    Learning Bias
    Data Leakage
    Do you have all the Data?
    Building a Model

    View Slide

  65. Artificial Intelligence & Deep Learning At Amazon
    Thousands Of Employees Across The Company Focused on AI
    Discovery &
    Search
    Fulfilment &
    Logistics
    Add ML-powered
    features to existing products
    Echo &
    Alexa

    View Slide

  66. View Slide

  67. Create Great Content:
    ASK is how you connect
    to your consumer
    THE ALEXA ECOSYSTEM
    Supported by two powerful frameworks
    A L E X A
    V O I C E
    S E R V I C E
    Unparalleled Distribution:
    AVS allows your content
    to be everywhere
    Lives In The Cloud
    Automated Speech
    Recognition (ASR)
    Natural Language
    Understanding (NLU)
    Always Learning
    A L E X A
    S K I L L S
    K I T

    View Slide

  68. UNDER THE HOOD OF ASK
    A closer look at how the Alexa Skills Kit process a request and returns an appropriate
    response
    You Pass Back a Textual
    or Audio Response
    You Pass Back a Graphical Response
    Alexa Converts Text-to-Speech
    (TTS) & Renders Graphical
    Component
    Respond to Intent
    through Text & Visual
    Alexa sends Customer
    Intent to Your Service
    User Makes
    a Request
    Alexa Identifies Skill &
    Recognizes Intent Through
    ASR & NLU
    Your Service
    processes
    Request
    Audio Stream is
    sent up to Alexa

    View Slide

  69. Artificial Intelligence on AWS
    P2 Deep Learning
    AMI and template
    Investment in
    Apache MXNet

    View Slide

  70. Elastic GPUs On EC2
    P2
    M4 D2 X1 G2
    T2 R4 I3 C5
    General Purpose
    GPU
    General Purpose
    Dense storage Large memory
    Graphics
    intensive
    Memory intensive High I/O
    Compute intensive
    Burstable
    Lightsail
    Simple VPS
    F1
    FPGAs
    Instance Families

    View Slide

  71. Up to
    40 thousand parallel processing cores
    70 teraflops (single precision)
    over 23 teraflops (double precision)
    Instance Size GPUs GPU Peer
    to Peer
    vCPUs Memory
    (GiB)
    Network
    Bandwidth*
    p2.xlarge 1 - 4 61 1.25Gbps
    p2.8xlarge 8 Y 32 488 10Gbps
    p2.16xlarge 16 Y 64 732 20Gbps
    *In a placement group
    Amazon EC2 P2 Instances

    View Slide

  72. Elastic GPUs For EC2: GPU Acceleration For Graphics Workloads
    1GiB
    GPU Memory
    2 GiB
    4 GiB
    8 GiB
    Current
    Generation
    EC2
    Instance

    View Slide

  73. F1 Instances: Bringing Hardware Acceleration To All
    FPGA Images Available In AWS Marketplace
    F1 Instance
    With your custom logic
    running on an FPGA
    Develop, simulate, debug
    & compile your code
    Package as
    FPGA Images

    View Slide

  74. Apache MXNet

    View Slide

  75. Deep Learning Frameworks
    MXNet, Caffe, Tensorflow,
    Theano, Torch, CNTK and Keras
    Pre-installed components to
    speed productivity, such as
    Nvidia drivers, CUDA, cuDNN,
    Intel MKL-DNN with MXNet,
    Anaconda, Python 2 and 3
    AWS Integration
    Deep Learning AMI

    View Slide

  76. Apache Spark MLlib

    View Slide

  77. Amazon AI
    Bringing Powerful Artificial Intelligence To All Developers

    View Slide

  78. Amazon Rekognition
    Image Recognition And Analysis
    Powered By Deep Learning
    1

    View Slide

  79. Amazon Rekognition: Images In,
    Categories and Facial Analysis Out
    Amazon
    Rekognition
    Car
    Outside
    Daytime
    Driving
    Objects
    & Scenes
    Female
    Smiling
    Sunglasses
    Faces

    View Slide

  80. Ground Truth Generation
    Training

    View Slide

  81. Deep Learning Process
    Conv 1 Conv 2 Conv n


    Feature Maps
    Labrador
    Dog
    Beach
    Outdoors
    Softmax
    Probability
    Fully
    Connected
    Layer

    View Slide


  82. Amazon Rekognition

    View Slide

  83. Amazon Polly
    Text To Speech Powered By Deep Learning
    2

    View Slide

  84. Amazon Polly: Text In, Life-like Speech Out
    Amazon Polly
    “The temperature
    in WA is 75°F”
    “The temperature
    in Washington is 75 degrees
    Fahrenheit”

    View Slide

  85. TEXT
    Market grew by > 20%.
    WORDS
    PHONEMES
    {
    {
    {
    {
    {
    ˈtwɛn.ti
    pɚ.ˈsɛnt
    ˈmɑɹ.kət ˈgɹu baɪ ˈmoʊɹ
    ˈðæn
    PROSODY CONTOUR
    UNIT SELECTION AND ADAPTATION
    TEXT PROCESSING
    PROSODY MODIFICATION
    STREAMING
    Market grew by more
    than
    twenty
    percent
    Speech units
    inventory

    View Slide


  86. Amazon Polly

    View Slide

  87. Amazon ALEXA
    (It’s what’s inside Alexa)
    3
    Natural Language Understanding (NLU) &
    Automatic Speech Recognition (ASR) Powered By Deep Learning

    View Slide

  88. Amazon Lex: Speech Recognition
    & Natural Language Understanding
    Amazon Lex
    Automatic Speech Recognition
    Natural Language Understanding
    “What’s the weather
    forecast?”
    Weather
    Forecast

    View Slide

  89. Amazon Lex: Speech Recognition
    & Natural Language Understanding
    Amazon Lex
    Automatic Speech Recognition
    Natural Language Understanding
    “What’s the weather
    forecast?”
    “It will be sunny
    and 25°C”
    Weather
    Forecast

    View Slide

  90. Lex Bot Structure
    Utterances
    Spoken or typed phrases that invoke your
    intent
    BookHotel
    Intents
    An Intent performs an action in response
    to natural language user input
    Slots
    Slots are input data required to fulfill the
    intent
    Fulfillment
    Fulfillment mechanism for your intent

    View Slide

  91. Hotel Booking
    City New York City
    Check In Nov 30th
    Check Out Dec 2nd
    Hotel Booking
    City New York City
    Check In
    Check Out
    “Book a Hotel”
    Book Hotel
    NYC
    “Book a Hotel in
    NYC”
    Automatic Speech
    Recognition
    Hotel Booking
    New York City
    Natural Language
    Understanding
    Intent/Slot
    Model
    Utterances
    “Your hotel is booked
    for Nov 30th”
    Polly
    Confirmation: “Your hotel is
    booked for Nov 30th”
    a
    in
    “Can I go ahead with
    the booking?”

    View Slide

  92. View Slide


  93. Amazon Lex

    View Slide

  94. Amazon Machine Learning
    Create ML models without having to learn
    complex algorithms and technology
    4

    View Slide

  95. Train
    model
    Evaluate and
    optimize
    Retrieve
    predictions
    Building smart applications with Amazon ML
    1 2 3

    View Slide

  96. Train
    model
    Evaluate and
    optimize
    Retrieve
    predictions
    Building smart applications with Amazon ML
    Create a datasource object pointing to your data
    Explore and understand your data
    Transform data and train your model
    1 2 3

    View Slide

  97. Create a datasource object
    >>> import boto
    >>> ml = boto.connect_machinelearning()
    >>> ds = ml.create_data_source_from_s3(
    data_source_id = ’my_datasource',
    data_spec= {
    'DataLocationS3':'s3://bucket/input/',
    'DataSchemaLocationS3':'s3://bucket/input/.schema'},
    compute_statistics = True)

    View Slide

  98. Explore and understand your data

    View Slide

  99. Train your model
    >>> import boto
    >>> ml = boto.connect_machinelearning()
    >>> model = ml.create_ml_model(
    ml_model_id=’my_model',
    ml_model_type='REGRESSION',
    training_data_source_id='my_datasource')

    View Slide

  100. Train
    model
    Evaluate and
    optimize
    Retrieve
    predictions
    Building smart applications with Amazon ML
    Understand model quality
    Adjust model interpretation
    1 2 3

    View Slide

  101. Explore model quality

    View Slide

  102. Fine-tune model interpretation

    View Slide

  103. Fine-tune model interpretation

    View Slide

  104. Train
    model
    Evaluate and
    optimize
    Retrieve
    predictions
    Building smart applications with Amazon ML
    Batch predictions
    Real-time predictions
    1 2 3

    View Slide

  105. Batch predictions
    Asynchronous, large-volume prediction generation
    Request through service console or API
    Best for applications that deal with batches of data records
    >>> import boto
    >>> ml = boto.connect_machinelearning()
    >>> model = ml.create_batch_prediction(
    batch_prediction_id = 'my_batch_prediction’
    batch_prediction_data_source_id = ’my_datasource’
    ml_model_id = ’my_model',
    output_uri = 's3://examplebucket/output/’)

    View Slide

  106. Real-time predictions
    Synchronous, low-latency, high-throughput prediction generation
    Request through service API or server or mobile SDKs
    Best for interaction applications that deal with individual data
    records
    >>> import boto
    >>> ml = boto.connect_machinelearning()
    >>> ml.predict(
    ml_model_id=’my_model',
    predict_endpoint=’example_endpoint’,
    record={’key1':’value1’, ’key2':’value2’})
    {
    'Prediction': {
    'predictedValue': 13.284348,
    'details': {
    'Algorithm': 'SGD',
    'PredictiveModelType': 'REGRESSION’
    }
    }
    }

    View Slide


  107. Bike Sharing

    View Slide

  108. View Slide

  109. All Users
    Casual Users
    Registered Users

    View Slide

  110. Your Skill
    (Lambda function)
    Amazon
    Machine Learning
    get real-time predictions
    invoke
    Weather
    Forecast
    Historical Data
    get forecast
    build & train model

    View Slide

  111. View Slide

  112. Nikola Tesla, 1926
    “When wireless is perfectly
    applied, the whole earth will be
    converted into a huge brain…”

    View Slide

  113. Let’s Build Smarter Apps
    Using
    Services
    Platforms
    Engines

    View Slide

  114. Machine Learning
    for Developers
    Danilo Poccia
    @danilop danilop
    AWS Technical Evangelist

    View Slide