24
PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17 th , 2019 Heather Nolis, Machine Learning Engineer, T-Mobile – @heatherklus Jacqueline Nolis, Principal Data Scientist, Nolis LLC – @skyetetra

Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 1 | AI @ T-MOBILE

Push straight to prodAPI development with R and TensorFlow at T-Mobilerstudio::confJanuary 17th, 2019Heather Nolis, Machine Learning Engineer, T-Mobile – @heatherklusJacqueline Nolis, Principal Data Scientist, Nolis LLC – @skyetetra

Page 2: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 2 | AI @ T-MOBILE

What does it mean to put into production?

ANALYSISRunning code once to produce a result

Writing code that is continuously running

BUILD

Putting code into production is letting customers interact with it

Page 3: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 3 | AI @ T-MOBILE

Goal Use machine learning to improve the customer experience

Scope customer care messaging

The project:

Page 4: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 4 | AI @ T-MOBILE

Scenario Customer sends message:“This high bill shall not pass!”

Goal Prep customer care agent before first response: Current bill status

Method• Classify the message with machine learning: [bill breakdown]• Improve the prediction with customer data:

• Recent account activity• Signal strength• Bill status [overdue]

Page 5: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 5 | AI @ T-MOBILE

Model creation with R

Page 6: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 6 | AI @ T-MOBILE

Model building workflow

1. rmarkdown for exploratory analysis

2. Save the model to flat files (and log the build with rmarkdown)

3. Show model off with a shiny demo

Page 7: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 7 | AI @ T-MOBILE

Neural networks with R, Keras, and TensorFlow

A Convolutional Neural Network (CNN) processes initial customer message and customer data

“Unlock my phone.”

ACCOUNT UNLOCK ORDER

0.80 0.150.05

Recent order: YES

CNN

Page 8: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 8 | AI @ T-MOBILE

Page 9: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 9 | AI @ T-MOBILE

Model deployment to prod

Page 10: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 10 | AI @ T-MOBILE

Choosing the language

Option Analysis Modeling Deployment Verdict

1 ❎

2 ❎

3 ✅

“If you want machine learning in production you need Python” –literally everyone

Page 11: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 11 | AI @ T-MOBILE

Commit is

made to AI

repository

Jenkins builds the

image

Mesos replicates

and hosts the

containers

Marathon

orchestrates container

deployment

Idea! Treat R like a full programming language(because it is one)

Page 12: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 12 | AI @ T-MOBILE

Turning R into an API: plumber

#* @get /sumfunction(a, b){as.numeric(a) + as.numeric(b)

}

library(plumber)r <- plumb("rest_contoller.R")r$run(host='0.0.0.0',port=80)

rest_controller.R main.R

Create an R file for the API endpoints

Start the plumber service

Now make HTTP requests to R!

Page 13: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 13 | AI @ T-MOBILE

• Dockerfile—build instructions• Image—the result of the Dockerfile• Container—Hitting run on an image

# start from the rocker/r-ver:3.5.0 imageFROM rocker/r-ver:3.5.0

# install the linux libraries needed for plumberRUN apt-get update -qq && apt-get install -y \libssl-dev \libcurl4-gnutls-dev

# install plumberRUN R -e "install.packages('plumber')"

# copy everything from the current directory into the containerCOPY / /

# open port 80 to trafficEXPOSE 80

# when the container starts, start the main.RscriptENTRYPOINT ["Rscript", "main.R"]

Example Dockerfilae

Behold: containers!

Page 14: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 14 | AI @ T-MOBILE

R Keras requires Python• Added Python 3.6 (Anaconda) and

Python Keras installation to Dockerfile• Configured Reticulate to use correct

Python

Container Struggles: Python

Page 15: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 15 | AI @ T-MOBILE

Plumber does not support HTTPS• Added an Apache 2 server to reroute

Text needs encryption• Sodium R library

Container Struggles: Security

Docker Container

Apache 2

R(plumber)

HTTPS

HTTPS

HTTP

HTTP

Page 16: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 16 | AI @ T-MOBILE

Initial size (5+ GB)• Switched Pythons

(Anaconda →Miniconda)• Removed Rstudio

(rocker/tidyverse → rocker/r-ver:3.5.0)

• Removed unnecessary Linux, R, Python libraries

Container Struggles: Size

Page 17: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 17 | AI @ T-MOBILE

R-native API container

TensorFlow enabled

Lightweight

Secure

Status: UP

Page 18: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 18 | AI @ T-MOBILE

Lessons learned

Page 19: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 19 | AI @ T-MOBILE

R vs Python

• R & Plumber close to parity with Python & Flask• R advantageous for quick data exploration• Language was never the project failpoint

Page 20: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 20 | AI @ T-MOBILE

Product

Data Scientist

Data Scientist

ML Engineer

ML Engineer

Java Engineer

Data Scientist

Sr. Manager

Working Together is Critical

Page 21: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 21 | AI @ T-MOBILE

Where are we today

Page 22: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 22 | AI @ T-MOBILE

R in prod: Apple Business Chat

“Can I please pay my bill” Customer

Page 23: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 23 | AI @ T-MOBILE

And you can be here too!

Page 24: Push straight to prod - Nolis, LLC · PAGE 1 | AI @ T-MOBILE Push straight to prod API development with R and TensorFlow at T-Mobile rstudio::conf January 17th, 2019 Heather Nolis,

PAGE 24 | AI @ T-MOBILE

Materials: nolisllc.com/rstudio19twitter: @skyetetra @heatherklus