Build, Scale, and Deploy
Deep Learning Pipelines
Using Apache Spark
Bay Area Spark Meetup
Nov8, 2017
Sue Ann Hong, Databricks
This talk
• Deep Learning at scale: current state
• Deep Learning Pipelines: the philosophy
• End-to-end workflow with DL Pipelines
• Future
Deep Learning at Scale
: current state
3put	your	#assignedhashtag	here	by	setting	the
What is Deep Learning?
• A set of machine learning techniques that use layers that
transform numerical inputs
• Classification
• Regression
• Arbitrary mapping
• Popular in the 80’s as Neural Networks
• Recently came back thanks to advances in data collection,
computation techniques, and hardware.
Success of Deep Learning
Tremendous success for applications with complex data
• AlphaGo
• Image interpretation
• Automatictranslation
• Speech recognition
Deep Learning is often challenging
Labeled
Data
Compute Resources
& Time
Engineer hours
• Tedious or difficult to distribute computations
• No exact science around deep learning à lots of tweaking
• Low level APIs with steep learning curve
• Complex models à need a lot of data
Deep Learning in industry
• Currently limited adoption
• Huge potential beyond the industrial giants
• How do we accelerate the road to massive availability?
Deep Learning Pipelines
8put	your	#assignedhashtag	here	by	setting	the
Deep Learning Pipelines:
Deep Learning with Simplicity
• Open-source Databricks library
• Focuses on easeof useand integration
• without sacrificing performance
Deep Learning is often challenging
Compute Resources
& Time
Engineer hours Labeled
Data
• Tedious or difficult to distribute computations
• No exact science around deep learning à lots of tweaking
• Low level APIs with steep learning curve
• Complex models à need a lot of data
Deep Learning is often challenging
• Tedious or difficult to distribute computations
• No exact science around deep learning à lots of tweaking
• Low level APIs with steep learning curve
• Complex models à need a lot of data
• Tedious or difficult to distribute computations
• No exact science around deep learning à lots of tweaking
• Low level APIs with steep learning curve
• Complex models à need a lot of data
Instead
• Be easy to scale
• Require little tweaking
• Be easy to write
• Require little or no data
Common	workflows	should
How
• Be easy to scale
• Require little tweaking
• Be easy to write
• Require little or no data
Common	workflows	should
• Use Apache Spark for scaling out common tasks
• Leverage well-knownmodel architectures
• Integrate with MLlib Pipelines API to capture ML workflowconcisely
• Leverage pre-trained models for common tasks
Apache Spark for scaling out
MLlib Pipelines API
pre-trained models
Demo: Build a visual recommendation AI
10minutes
7lines of code
Elastic Scale-out
using Apache Spark
MLlib Pipelines API Leverage
pre-trained models
0labels
To the notebook!
End-to-EndWorkflow
with Deep Learning Pipelines
18put	your	#assignedhashtag	here	by	setting	the
A typical Deep Learning workflow
• Load data (images, text, time series, …)
• Interactive work
• Train
• Select an architecture for a neural network
• Optimize the weights of the NN
• Evaluateresults, potentially re-train
• Apply:
• Pass the data through the NN to produce new features or output
Load data
Interactive work
Train
Evaluate
Apply
A typical Deep Learning workflow
Load data
Interactive work
Train
Evaluate
Apply
• Image	loading	in	Spark
• Distributed	batch	prediction
• Deploying	models	in	SQL
• Transfer	learning
• Distributed	tuning
• Pre-trained	models
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Adds support for images in Spark
• ImageSchema, reader, conversion functions to/from numpy arrays
• Most of the tools we’ll describe work on ImageSchema columns
from sparkdl import readImages
image_df = readImages(sample_img_dir)
Upcoming: built-in support in Spark
• Spark-21866
• Contributing image format & reading to Spark
• Targeted for Spark 2.3
• Joint work with Microsoft
23put	your	#assignedhashtag	here	by	setting	the
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Applying popular models
• Popular pre-trained models accessible through MLlib
Transformers
predictor = DeepImagePredictor(inputCol="image",
outputCol="predicted_labels",
modelName="InceptionV3")
predictions_df = predictor.transform(image_df)
Applying popular models
predictor = DeepImagePredictor(inputCol="image",
outputCol="predicted_labels",
modelName="InceptionV3")
predictions_df = predictor.transform(image_df)
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Hyperparameter tuning
Transfer	learning
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Hyperparameter tuning
Transfer	learning
Transfer learning
• Pre-trained models may not be directly applicable
• New domain, e.g. shoes
• Training from scratch requires
• Enormous amounts of data
• A lot of compute resources & time
• Idea: intermediate representations learned for one task may be useful
for other related tasks
Transfer Learning
SoftMax
GIANT PANDA 0.9
RACCOON 0.05
RED PANDA 0.01
…
Transfer Learning
Transfer Learning
Classifier
Transfer Learning
Classifier
Rose: 0.7
Daisy: 0.3
Transfer Learning as a Pipeline
DeepImageFeaturizer
Image
Loading Preprocessing
Logistic
Regression
MLlib Pipeline
Transfer Learning as a Pipeline
35put	your	#assignedhashtag	here	by	setting	the	
featurizer = DeepImageFeaturizer(inputCol="image",
outputCol="features",
modelName="InceptionV3")
lr = LogisticRegression(labelCol="label")
p = Pipeline(stages=[featurizer, lr])
p_model = p.fit(train_df)
Transfer Learning
• Usually for classification tasks
• Similar task, new domain
• But other forms of learning leveraging learned representations
can be loosely considered transfer learning
Featurization for similarity-based ML
DeepImageFeaturizer
Image
Loading Preprocessing
Logistic
Regression
Featurization for similarity-based ML
DeepImageFeaturizer
Image
Loading Preprocessing
Clustering
KMeans
GaussianMixture
Nearest Neighbor
KNN LSH
Distance
computation
Featurization for similarity-based ML
DeepImageFeaturizer
Image
Loading Preprocessing
Clustering
KMeans
GaussianMixture
Nearest Neighbor
KNN LSH
Distance
computation
Duplicate
Detection
Recommendation
Anomaly
Detection
Search result
diversification
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Hyperparameter tuning
Transfer	learning
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Spark	SQL
Batch	prediction
s
Deep Learning Pipelines
• Load data
• Interactive work
• Train
• Evaluate model
• Apply
Spark	SQL
Batch	prediction
Batch prediction as an MLlib Transformer
• A model is a Transformer in MLlib
• DataFrame goes in, DataFrame comes out with output columns
predictor = XXTransformer(inputCol="image",
outputCol="prediction",
modelSpecification={…})
predictions = predictor.transform(test_df)
Hierarchy of DL transformers for images
46
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizerDeepImagePredictor
NamedImageTransformer(model_name)
(keras.Model)
(tf.Graph)
Input	
(Image)
Output	
(vector)
model_namemodel_name
Keras.Model
tf.Graph
Hierarchy of DL transformers for images
47
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizerDeepImagePredictor
NamedImageTransformer(model_name)
(keras.Model)
(tf.Graph)
Input	
(Image)
Output	
(vector)
model_namemodel_name
Keras.Model
tf.Graph
Hierarchy of DL transformers
48
TFImageTransformer
KerasImageTransformer
DeepImageF
eaturizer
DeepImageP
redictor
NamedImageTransformer
)
Input	
(Image
)
Output	
(vector
)
model_namemodel_name
Keras.Model
tf.Graph
TFTextTransformer
KerasTextTransformer
DeepTextFeat
urizer
DeepTextPre
dictor
NamedTextTransformerInput	
(Text)
Output	
(vector)
model_namemodel_name
Keras.Model
tf.Graph
TFTransformer
Hierarchy of DL transformers
49
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizerDeepImagePredictor
NamedImageTransformer
TFTextTransformer
KerasTextTransformer
DeepTextFeaturizerDeepTextPredictor
NamedTextTransformer
TFTransformer
Hierarchy of DL transformers
50
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizerDeepImagePredictor
NamedImageTransformer
TFTextTransformer
KerasTextTransformer
DeepTextFeaturizerDeepTextPredictor
NamedTextTransformer
TFTransformer
CommonTasks Easy
Advanced Ones Possible
51
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizerDeepImagePredictor
NamedImageTransformer
TFTextTransformer
KerasTextTransformer
DeepTextFeaturizerDeepTextPredictor
NamedTextTransformer
TFTransformer
CommonTasks Easy
Advanced Ones Possible
52
TFImageTransformer
KerasImageTransformer
DeepImageFeaturizer
DeepImagePredictor
NamedImageTransformer
TFTextTransformer
KerasTextTransformer
DeepTextFeaturizer
DeepTextPredictor
NamedTextTransformer
TFTransformer
Pre-built Solutions
80%-built Solutions
Self-built Solutions
Deep Learning Pipelines : Future
In progress
• Text featurization (embeddings)
• TFTransformer for arbitrary vectors
Future directions
• Non-image data domains: video, text, speech, …
• Distributed training
• Support for more backends, e.g. MXNet, PyTorch, BigDL
Questions?
Thank you!
54put	your	#assignedhashtag	here	by	setting	the
Resources
DL Pipelines GitHub Repo, Spark Summit Europe 2017 Deep Dive
Blog posts & webinars (http://databricks.com/blog)
• Deep Learning Pipelines
• GPU acceleration in Databricks
• BigDL on Databricks
• Deep Learning and Apache Spark
Docs for Deep Learningon Databricks (http://docs.databricks.com)
• Getting started
• Deep Learning Pipelines Example
• Spark integration

Build, Scale, and Deploy Deep Learning Pipelines Using Apache Spark

  • 1.
    Build, Scale, andDeploy Deep Learning Pipelines Using Apache Spark Bay Area Spark Meetup Nov8, 2017 Sue Ann Hong, Databricks
  • 2.
    This talk • DeepLearning at scale: current state • Deep Learning Pipelines: the philosophy • End-to-end workflow with DL Pipelines • Future
  • 3.
    Deep Learning atScale : current state 3put your #assignedhashtag here by setting the
  • 4.
    What is DeepLearning? • A set of machine learning techniques that use layers that transform numerical inputs • Classification • Regression • Arbitrary mapping • Popular in the 80’s as Neural Networks • Recently came back thanks to advances in data collection, computation techniques, and hardware.
  • 5.
    Success of DeepLearning Tremendous success for applications with complex data • AlphaGo • Image interpretation • Automatictranslation • Speech recognition
  • 6.
    Deep Learning isoften challenging Labeled Data Compute Resources & Time Engineer hours • Tedious or difficult to distribute computations • No exact science around deep learning à lots of tweaking • Low level APIs with steep learning curve • Complex models à need a lot of data
  • 7.
    Deep Learning inindustry • Currently limited adoption • Huge potential beyond the industrial giants • How do we accelerate the road to massive availability?
  • 8.
  • 9.
    Deep Learning Pipelines: DeepLearning with Simplicity • Open-source Databricks library • Focuses on easeof useand integration • without sacrificing performance
  • 10.
    Deep Learning isoften challenging Compute Resources & Time Engineer hours Labeled Data • Tedious or difficult to distribute computations • No exact science around deep learning à lots of tweaking • Low level APIs with steep learning curve • Complex models à need a lot of data
  • 11.
    Deep Learning isoften challenging • Tedious or difficult to distribute computations • No exact science around deep learning à lots of tweaking • Low level APIs with steep learning curve • Complex models à need a lot of data
  • 12.
    • Tedious ordifficult to distribute computations • No exact science around deep learning à lots of tweaking • Low level APIs with steep learning curve • Complex models à need a lot of data Instead • Be easy to scale • Require little tweaking • Be easy to write • Require little or no data Common workflows should
  • 13.
    How • Be easyto scale • Require little tweaking • Be easy to write • Require little or no data Common workflows should • Use Apache Spark for scaling out common tasks • Leverage well-knownmodel architectures • Integrate with MLlib Pipelines API to capture ML workflowconcisely • Leverage pre-trained models for common tasks Apache Spark for scaling out MLlib Pipelines API pre-trained models
  • 14.
    Demo: Build avisual recommendation AI 10minutes 7lines of code Elastic Scale-out using Apache Spark MLlib Pipelines API Leverage pre-trained models 0labels
  • 16.
  • 18.
    End-to-EndWorkflow with Deep LearningPipelines 18put your #assignedhashtag here by setting the
  • 19.
    A typical DeepLearning workflow • Load data (images, text, time series, …) • Interactive work • Train • Select an architecture for a neural network • Optimize the weights of the NN • Evaluateresults, potentially re-train • Apply: • Pass the data through the NN to produce new features or output Load data Interactive work Train Evaluate Apply
  • 20.
    A typical DeepLearning workflow Load data Interactive work Train Evaluate Apply • Image loading in Spark • Distributed batch prediction • Deploying models in SQL • Transfer learning • Distributed tuning • Pre-trained models
  • 21.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply
  • 22.
    Adds support forimages in Spark • ImageSchema, reader, conversion functions to/from numpy arrays • Most of the tools we’ll describe work on ImageSchema columns from sparkdl import readImages image_df = readImages(sample_img_dir)
  • 23.
    Upcoming: built-in supportin Spark • Spark-21866 • Contributing image format & reading to Spark • Targeted for Spark 2.3 • Joint work with Microsoft 23put your #assignedhashtag here by setting the
  • 24.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply
  • 25.
    Applying popular models •Popular pre-trained models accessible through MLlib Transformers predictor = DeepImagePredictor(inputCol="image", outputCol="predicted_labels", modelName="InceptionV3") predictions_df = predictor.transform(image_df)
  • 26.
    Applying popular models predictor= DeepImagePredictor(inputCol="image", outputCol="predicted_labels", modelName="InceptionV3") predictions_df = predictor.transform(image_df)
  • 27.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply Hyperparameter tuning Transfer learning
  • 28.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply Hyperparameter tuning Transfer learning
  • 29.
    Transfer learning • Pre-trainedmodels may not be directly applicable • New domain, e.g. shoes • Training from scratch requires • Enormous amounts of data • A lot of compute resources & time • Idea: intermediate representations learned for one task may be useful for other related tasks
  • 30.
    Transfer Learning SoftMax GIANT PANDA0.9 RACCOON 0.05 RED PANDA 0.01 …
  • 31.
  • 32.
  • 33.
  • 34.
    Transfer Learning asa Pipeline DeepImageFeaturizer Image Loading Preprocessing Logistic Regression MLlib Pipeline
  • 35.
    Transfer Learning asa Pipeline 35put your #assignedhashtag here by setting the featurizer = DeepImageFeaturizer(inputCol="image", outputCol="features", modelName="InceptionV3") lr = LogisticRegression(labelCol="label") p = Pipeline(stages=[featurizer, lr]) p_model = p.fit(train_df)
  • 36.
    Transfer Learning • Usuallyfor classification tasks • Similar task, new domain • But other forms of learning leveraging learned representations can be loosely considered transfer learning
  • 38.
    Featurization for similarity-basedML DeepImageFeaturizer Image Loading Preprocessing Logistic Regression
  • 39.
    Featurization for similarity-basedML DeepImageFeaturizer Image Loading Preprocessing Clustering KMeans GaussianMixture Nearest Neighbor KNN LSH Distance computation
  • 40.
    Featurization for similarity-basedML DeepImageFeaturizer Image Loading Preprocessing Clustering KMeans GaussianMixture Nearest Neighbor KNN LSH Distance computation Duplicate Detection Recommendation Anomaly Detection Search result diversification
  • 41.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply Hyperparameter tuning Transfer learning
  • 42.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply
  • 43.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply Spark SQL Batch prediction s
  • 44.
    Deep Learning Pipelines •Load data • Interactive work • Train • Evaluate model • Apply Spark SQL Batch prediction
  • 45.
    Batch prediction asan MLlib Transformer • A model is a Transformer in MLlib • DataFrame goes in, DataFrame comes out with output columns predictor = XXTransformer(inputCol="image", outputCol="prediction", modelSpecification={…}) predictions = predictor.transform(test_df)
  • 46.
    Hierarchy of DLtransformers for images 46 TFImageTransformer KerasImageTransformer DeepImageFeaturizerDeepImagePredictor NamedImageTransformer(model_name) (keras.Model) (tf.Graph) Input (Image) Output (vector) model_namemodel_name Keras.Model tf.Graph
  • 47.
    Hierarchy of DLtransformers for images 47 TFImageTransformer KerasImageTransformer DeepImageFeaturizerDeepImagePredictor NamedImageTransformer(model_name) (keras.Model) (tf.Graph) Input (Image) Output (vector) model_namemodel_name Keras.Model tf.Graph
  • 48.
    Hierarchy of DLtransformers 48 TFImageTransformer KerasImageTransformer DeepImageF eaturizer DeepImageP redictor NamedImageTransformer ) Input (Image ) Output (vector ) model_namemodel_name Keras.Model tf.Graph TFTextTransformer KerasTextTransformer DeepTextFeat urizer DeepTextPre dictor NamedTextTransformerInput (Text) Output (vector) model_namemodel_name Keras.Model tf.Graph TFTransformer
  • 49.
    Hierarchy of DLtransformers 49 TFImageTransformer KerasImageTransformer DeepImageFeaturizerDeepImagePredictor NamedImageTransformer TFTextTransformer KerasTextTransformer DeepTextFeaturizerDeepTextPredictor NamedTextTransformer TFTransformer
  • 50.
    Hierarchy of DLtransformers 50 TFImageTransformer KerasImageTransformer DeepImageFeaturizerDeepImagePredictor NamedImageTransformer TFTextTransformer KerasTextTransformer DeepTextFeaturizerDeepTextPredictor NamedTextTransformer TFTransformer
  • 51.
    CommonTasks Easy Advanced OnesPossible 51 TFImageTransformer KerasImageTransformer DeepImageFeaturizerDeepImagePredictor NamedImageTransformer TFTextTransformer KerasTextTransformer DeepTextFeaturizerDeepTextPredictor NamedTextTransformer TFTransformer
  • 52.
    CommonTasks Easy Advanced OnesPossible 52 TFImageTransformer KerasImageTransformer DeepImageFeaturizer DeepImagePredictor NamedImageTransformer TFTextTransformer KerasTextTransformer DeepTextFeaturizer DeepTextPredictor NamedTextTransformer TFTransformer Pre-built Solutions 80%-built Solutions Self-built Solutions
  • 53.
    Deep Learning Pipelines: Future In progress • Text featurization (embeddings) • TFTransformer for arbitrary vectors Future directions • Non-image data domains: video, text, speech, … • Distributed training • Support for more backends, e.g. MXNet, PyTorch, BigDL
  • 54.
  • 55.
    Resources DL Pipelines GitHubRepo, Spark Summit Europe 2017 Deep Dive Blog posts & webinars (http://databricks.com/blog) • Deep Learning Pipelines • GPU acceleration in Databricks • BigDL on Databricks • Deep Learning and Apache Spark Docs for Deep Learningon Databricks (http://docs.databricks.com) • Getting started • Deep Learning Pipelines Example • Spark integration