SlideShare a Scribd company logo
hermanwu@mcrosoft.com
在Apache Spark 架構上使用機器學習的挑戰
•使用者需要寫大量程式碼來準備機器學習演算法所
需要的資料欄位
• Learning 所需要的資料類型和資料結構
• 使用不同Learners 所需要的Conventions
•缺少常見應用場景通用的Library: 例如電腦視覺,文
字分析
•模型評估與管理功能有限
Microsoft Machine Learning Library (MML Spark) 介紹
•針對需處理大量資料的機器學習場景設計
•提供Library來簡化在Apache Spark 上創建機器學習應用的難
度.
•協助資料科學家在Apache Spark 環境上專注處理機器學習問
題, 而不是軟體工程問題
•在Apache Spark上可以更易使用深度學習(Deep Learning)相
關演算法, 特別針對電腦視覺, 文字等的應用
•通過在Github 上開源, 通過社區協助可以快速演進
GitHub, MIT License
https://github.com/Azure/mmlspark
https://github.com/Azure/mmlspark
https://github.com/Azure/mmlspark
MMLSpark Requirements
執行環境: Scala 2.11, Spark 2.1+, and
either Python 2.7 or Python 3.5+
環境安裝:
Docker
Spark Cluster
Databricks Cloud
STB
HDInsight (Azure)
運用MMLSpark 來加速Spark 上機器學習專案
MMLSpark 安裝 - Docker
docker run -it -p 8888:8888 -e ACCEPT_EULA=yes
microsoft/mmlspark
打開 htpp://localhost:8888/notebooks/ 查看Jupyter
Notebook
MMLSpark 安裝 – Spark Cluster
spark-shell --packages Azure:mmlspark:0.8
pyspark --packages Azure:mmlspark:0.8
spark-submit Azure:mmlspark:0.8 MyApp.jar
MMLSpark 安裝 – Databricks cloud
Create a new library from Maven coordinates in your workspace
For the coordinates use: com.microsoft.ml.spark:mmlspark:0.8
under Advanced Options, use https://mmlspark.azureedge.net/maven
for the repository
Ensure this library is attached to all clusters you create.
Finally, ensure that your Spark cluster has at least Spark 2.1 and
Scala 2.11.
You can use MMLSpark in both your Scala and PySpark notebooks.
MMLSpark 安裝 – STB Build Tool (Scala)
build.sbt:
```scala
resolvers += "MMLSpark Repo" at
"https://mmlspark.azureedge.net/maven"
libraryDependencies += "com.microsoft.ml.spark" %%
"mmlspark" % "0.8“
```
MMLSpark 安裝 – HDInsight
Go to Script actions → Submit new in the Overview section of your cluster
blade.
In the Bash script URI field, input the script action URL
https://mmlspark.azureedge.net/buildartifacts/0.8/install-mmlspark.sh
Microsoft Machine Learning Library (MML Spark) 設計原則
• 可執行在任何Apache Spark 支援的平臺跟語言
• 相容於 SparkML pipeline 模型. MML-Spark 由Spark 評估器
(Estimators) 及轉換器 (Transformer) 所組成, 可以將既有 SparkML
組件整合到pipelines中.
• 使用 SparkML DataFrames. 可以使用已有Spark 功能來讀取資料
到機器學習模型中.
• 針對不同演算法的不同的資料類型(text, categorical, image)有一
致的處理機制 . 不需要做底層的資料處理 (type coercion,
encoding or vector assembly.)
DEMO
MML Spark 安装
MML Spark 與 PySpark 程式碼比較
預測Amazon 上書籍 Review的內容是正面還是負面
dataFile = "BookReviewsFromAmazon10K.tsv"
預測Amazon 上書籍 Review的內容是正面還是負面
PySpark MMLSpark
預測Amazon 上書籍 Review的內容是正面還是負面
PySpark
MMLSpark
預測Amazon 上書籍 Review的內容是正面還是負面
PySpark
MMLSpark
預測Amazon 上書籍 Review的內容是正面還是負面
PySpark
MMLSpark
預測Amazon 上書籍 Review的內容是正面還是負面
PySpark MMLSpark
運用MMLSpark 來加速Spark 上機器學習專案
Text Analytics
• 目標: 提供One-Step文本featurization能力,讓使用者可以把自由格式
的文本記錄轉換成ML演算法需要的特徵向量:
• Tokenization, stop-word removal, case normalization
• N-Gram creation, feature hashing, IDF weighing.
• 未來: 多語言支援, 更多高級的文本處理和DNN特徵化能力.
運用MMLSpark 來加速Spark 上機器學習專案
Deep Neural Net Featurization
• 基本概念:預訓練好的DNN模型的隱層有關於特徵的高階資訊
• 使用“headless”預訓練DNN模型能夠抽取圖像的精准特徵,從而訓練
更傳統的模型,比如random forests, SVM, logistic regression等等.
• 預訓練DNN模型通常是ImageNet, MSCoco或者CIFAR資料集上的模型,比如
Resnet (Microsoft), GoogLeNet (Google), Inception (Google), VGG, 等等.
• 轉移學習(Transfer learning) 能夠針對資料不足、計算能力不足、或者
缺少專業知識的場景訓練有效的模型
• 性能隨著executor擴展而變好
High-order features
Predictions
Image Processing Transforms
DNNs 通常對於輸入資料格式和正則化有嚴格要求。
我們提供與OpenCV影像處理操作相關的綁定, 暴露為
SparkML PipelineStages:
tr = ImageTransform().setOutputCol("transformed")
.resize(height = 200, width = 200)
.crop(0, 0, height = 180, width = 180)
smallImages =
tr.transform(images).select("transformed")
DEMO
MML Spark 展示 – Image DNN Featurization & Processing
Transforms
Virtual network
結合GPU 與 Spark 進行深度學習訓練
• GPUs 適合用來進行深度學習訓練, 但是整個Spark Cluster 都採用GPU 機器不僅昂
貴而且沒有必要
• 透過CPU Spark cluster載入大量資料並進行預處理, 然後將處理完資料透過GPU
Node 來訓練. 最後訓練完的模型可以發布到CPU Node 來做Evaluation.
Raw
data
Processed data
as DataFrame
Trained DNN as
PipelineStage
GPU VMSpark Cluster
learner = CNTKLearner(brainScript=brainscriptText, dataTransfer='hdfs-mount', =‘my-
gpu-gpuMachinesvm’, workingDir=‘file:/tmp/’).fit(trainData)
predictions = learner.setOutputNode(‘z’).transform(testData)
Eg. Azure Environment GPU Setup: http://azuremlbuild.blob.core.windows.net/pysparkapi/azure-setup.html
DNN Featurization using MML-Spark
cntkModel = CNTKModel().setInputCol("images").
setOutputCol("features").setModelLocation(resnetModel).
setOutputNode("z.x")
featurizedImages = cntkModel.transform(imagesWithLabels).
select(['labels','features'])
model = TrainClassifier(model=LogisticRegression(),labelCol="labels").
fit(featurizedImages)
DNN featurization和SparkML pipeline stage協作。 評估直接在Scala的JVM上進行,
不需要Python UDF!
CNTK Model Gallery
https://www.microsoft.com/en-us/cognitive-toolkit/features/model-gallery/
運用MMLSpark 來加速Spark 上機器學習專案
MML for Spark應用場景
•Image Ingestion, processing and featurization
從HDFS中獲取圖片資料到Spark DataFrame
使用OpenCV的transforms預處理圖片
在使用預訓練的CNTK-DNN上特徵化圖片
•Text Analytics
在SparkML上通過單個transformer便捷地featurize free-form text data
• GPU and CPU environment configuration
使用Azure上的N-Series GPU VMs 訓練基於DNN的圖像分類模型
•Training and evaluation simplification
簡便地訓練分類和回歸模型
計算豐富的評估指標,甚至是per-instance metrics
Docs
http://azuremlbuild.blob.core.windows.net/pysparkapi/intro.html
MMLSpark PySpark Library
• http://mmlspark.azureedge.net/docs/pyspark/
MMLSpark Scala Library
• http://mmlspark.azureedge.net/docs/scala
CNTK Pre-trained Image Models
• AlexNet
• AlexNet for ImageNet 1K
• GoogLeNet
• InceptionV3 for ImageNet 1K
• BN-Inception for ImageNet 1K
• VGG
• VGG16 for ImageNet 1K
• VGG19 for ImageNet 1K
https://github.com/Microsoft/CNTK/blob/master/PretrainedModels/Image.md
• ResNet
• ResNet18 for ImageNet 1K
• ResNet34 for ImageNet 1K
• ResNet50 for ImageNet 1K
• ResNet20 for CIFAR-10
• ResNet110 for CIFAR-10
• ResNet101 for ImageNet 1K
• ResNet152 for ImageNet 1K
運用MMLSpark 來加速Spark 上機器學習專案

More Related Content

PDF
Azure Data Lake 簡介
PDF
How to plan a hadoop cluster for testing and production environment
PDF
Data Engineering in Taiwan: PAST, NOW and FUTURE
PPT
Hadoop 與 SQL 的甜蜜連結
PDF
2016-07-12 Introduction to Big Data Platform Security
PDF
Azure HDInsight 介紹
PDF
選擇正確的Solution 來建置現代化的雲端資料倉儲
PDF
Spark tutorial
Azure Data Lake 簡介
How to plan a hadoop cluster for testing and production environment
Data Engineering in Taiwan: PAST, NOW and FUTURE
Hadoop 與 SQL 的甜蜜連結
2016-07-12 Introduction to Big Data Platform Security
Azure HDInsight 介紹
選擇正確的Solution 來建置現代化的雲端資料倉儲
Spark tutorial

What's hot (20)

PPTX
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
PPTX
給初學者的Spark教學
PDF
大資料趨勢介紹與相關使用技術
PDF
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
PPT
Hadoop Map Reduce 程式設計
PPTX
Hadoop hive
PDF
Apache hadoop and cdh(cloudera distribution) introduction 基本介紹
PDF
Hadoop ecosystem - hadoop 生態系
PDF
Delta Lake Architecture: Delta Lake + Apache Spark Structured Streaming
PPTX
Hadoop的典型应用与企业化之路 for HBTC 2012
PPTX
淘宝Hadoop数据分析实践
PDF
基于Spring batch的大数据量并行处理
PDF
Big Data Taiwan 2014 Track1-3: Big Data, Big Challenge — Splunk 幫你解決 Big Data...
PDF
Introduction of Spark by Wang Haihua
PPTX
From Java Stream to Java DataFrame
PDF
Distributed Data Analytics at Taobao
PDF
SMACK Dev Experience
PPTX
Elasticsearch search engine_development_tips
PDF
Hadoop 0.20 程式設計
PPTX
Elastic stack day-1
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
給初學者的Spark教學
大資料趨勢介紹與相關使用技術
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
Hadoop Map Reduce 程式設計
Hadoop hive
Apache hadoop and cdh(cloudera distribution) introduction 基本介紹
Hadoop ecosystem - hadoop 生態系
Delta Lake Architecture: Delta Lake + Apache Spark Structured Streaming
Hadoop的典型应用与企业化之路 for HBTC 2012
淘宝Hadoop数据分析实践
基于Spring batch的大数据量并行处理
Big Data Taiwan 2014 Track1-3: Big Data, Big Challenge — Splunk 幫你解決 Big Data...
Introduction of Spark by Wang Haihua
From Java Stream to Java DataFrame
Distributed Data Analytics at Taobao
SMACK Dev Experience
Elasticsearch search engine_development_tips
Hadoop 0.20 程式設計
Elastic stack day-1
Ad

Viewers also liked (14)

PDF
運用CNTK 實作深度學習物件辨識 Deep Learning based Object Detection with Microsoft Cogniti...
PDF
Bot Framework & Azure cognitive service簡介
PDF
物聯網應用全貌以及微軟全球案例
PDF
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
PPTX
Microsoft blockchain vision - enterprise smart contracts, coco framework and...
PDF
Game Analytics & Machine Learning
PPTX
Recency/Frequency and Predictive Analytics in the gaming industry
PDF
Realtime analytics with Flink and Druid
PDF
運用對話機器人提供線上客服服務
PDF
Azure Machine Learning using R
PDF
Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習
PPTX
Windows phone發展概況 2013Q3
PDF
好的Windows Phone App 主要特色 (注意事項)
PDF
數據營運與指標設計 web analytics 101 slideshare
運用CNTK 實作深度學習物件辨識 Deep Learning based Object Detection with Microsoft Cogniti...
Bot Framework & Azure cognitive service簡介
物聯網應用全貌以及微軟全球案例
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
Microsoft blockchain vision - enterprise smart contracts, coco framework and...
Game Analytics & Machine Learning
Recency/Frequency and Predictive Analytics in the gaming industry
Realtime analytics with Flink and Druid
運用對話機器人提供線上客服服務
Azure Machine Learning using R
Azure 機器學習 - 使用Python, R, Spark, CNTK 深度學習
Windows phone發展概況 2013Q3
好的Windows Phone App 主要特色 (注意事項)
數據營運與指標設計 web analytics 101 slideshare
Ad

Similar to 運用MMLSpark 來加速Spark 上 機器學習專案 (7)

PDF
Report 106553012 - copy
PDF
2020 MLaaS 產業介紹.pdf
PDF
20150206 aic machine learning
PDF
Azurebootcamp 2018
PDF
Introduction to MLOps in Azure Machine Learning with Live Demo
PDF
Week4 neural network
PDF
從大數據走向人工智慧
Report 106553012 - copy
2020 MLaaS 產業介紹.pdf
20150206 aic machine learning
Azurebootcamp 2018
Introduction to MLOps in Azure Machine Learning with Live Demo
Week4 neural network
從大數據走向人工智慧

運用MMLSpark 來加速Spark 上 機器學習專案

  • 2. 在Apache Spark 架構上使用機器學習的挑戰 •使用者需要寫大量程式碼來準備機器學習演算法所 需要的資料欄位 • Learning 所需要的資料類型和資料結構 • 使用不同Learners 所需要的Conventions •缺少常見應用場景通用的Library: 例如電腦視覺,文 字分析 •模型評估與管理功能有限
  • 3. Microsoft Machine Learning Library (MML Spark) 介紹 •針對需處理大量資料的機器學習場景設計 •提供Library來簡化在Apache Spark 上創建機器學習應用的難 度. •協助資料科學家在Apache Spark 環境上專注處理機器學習問 題, 而不是軟體工程問題 •在Apache Spark上可以更易使用深度學習(Deep Learning)相 關演算法, 特別針對電腦視覺, 文字等的應用 •通過在Github 上開源, 通過社區協助可以快速演進
  • 7. MMLSpark Requirements 執行環境: Scala 2.11, Spark 2.1+, and either Python 2.7 or Python 3.5+ 環境安裝: Docker Spark Cluster Databricks Cloud STB HDInsight (Azure)
  • 9. MMLSpark 安裝 - Docker docker run -it -p 8888:8888 -e ACCEPT_EULA=yes microsoft/mmlspark 打開 htpp://localhost:8888/notebooks/ 查看Jupyter Notebook
  • 10. MMLSpark 安裝 – Spark Cluster spark-shell --packages Azure:mmlspark:0.8 pyspark --packages Azure:mmlspark:0.8 spark-submit Azure:mmlspark:0.8 MyApp.jar
  • 11. MMLSpark 安裝 – Databricks cloud Create a new library from Maven coordinates in your workspace For the coordinates use: com.microsoft.ml.spark:mmlspark:0.8 under Advanced Options, use https://mmlspark.azureedge.net/maven for the repository Ensure this library is attached to all clusters you create. Finally, ensure that your Spark cluster has at least Spark 2.1 and Scala 2.11. You can use MMLSpark in both your Scala and PySpark notebooks.
  • 12. MMLSpark 安裝 – STB Build Tool (Scala) build.sbt: ```scala resolvers += "MMLSpark Repo" at "https://mmlspark.azureedge.net/maven" libraryDependencies += "com.microsoft.ml.spark" %% "mmlspark" % "0.8“ ```
  • 13. MMLSpark 安裝 – HDInsight Go to Script actions → Submit new in the Overview section of your cluster blade. In the Bash script URI field, input the script action URL https://mmlspark.azureedge.net/buildartifacts/0.8/install-mmlspark.sh
  • 14. Microsoft Machine Learning Library (MML Spark) 設計原則 • 可執行在任何Apache Spark 支援的平臺跟語言 • 相容於 SparkML pipeline 模型. MML-Spark 由Spark 評估器 (Estimators) 及轉換器 (Transformer) 所組成, 可以將既有 SparkML 組件整合到pipelines中. • 使用 SparkML DataFrames. 可以使用已有Spark 功能來讀取資料 到機器學習模型中. • 針對不同演算法的不同的資料類型(text, categorical, image)有一 致的處理機制 . 不需要做底層的資料處理 (type coercion, encoding or vector assembly.)
  • 16. MML Spark 與 PySpark 程式碼比較
  • 24. Text Analytics • 目標: 提供One-Step文本featurization能力,讓使用者可以把自由格式 的文本記錄轉換成ML演算法需要的特徵向量: • Tokenization, stop-word removal, case normalization • N-Gram creation, feature hashing, IDF weighing. • 未來: 多語言支援, 更多高級的文本處理和DNN特徵化能力.
  • 26. Deep Neural Net Featurization • 基本概念:預訓練好的DNN模型的隱層有關於特徵的高階資訊 • 使用“headless”預訓練DNN模型能夠抽取圖像的精准特徵,從而訓練 更傳統的模型,比如random forests, SVM, logistic regression等等. • 預訓練DNN模型通常是ImageNet, MSCoco或者CIFAR資料集上的模型,比如 Resnet (Microsoft), GoogLeNet (Google), Inception (Google), VGG, 等等. • 轉移學習(Transfer learning) 能夠針對資料不足、計算能力不足、或者 缺少專業知識的場景訓練有效的模型 • 性能隨著executor擴展而變好 High-order features Predictions
  • 27. Image Processing Transforms DNNs 通常對於輸入資料格式和正則化有嚴格要求。 我們提供與OpenCV影像處理操作相關的綁定, 暴露為 SparkML PipelineStages: tr = ImageTransform().setOutputCol("transformed") .resize(height = 200, width = 200) .crop(0, 0, height = 180, width = 180) smallImages = tr.transform(images).select("transformed")
  • 28. DEMO MML Spark 展示 – Image DNN Featurization & Processing Transforms
  • 29. Virtual network 結合GPU 與 Spark 進行深度學習訓練 • GPUs 適合用來進行深度學習訓練, 但是整個Spark Cluster 都採用GPU 機器不僅昂 貴而且沒有必要 • 透過CPU Spark cluster載入大量資料並進行預處理, 然後將處理完資料透過GPU Node 來訓練. 最後訓練完的模型可以發布到CPU Node 來做Evaluation. Raw data Processed data as DataFrame Trained DNN as PipelineStage GPU VMSpark Cluster learner = CNTKLearner(brainScript=brainscriptText, dataTransfer='hdfs-mount', =‘my- gpu-gpuMachinesvm’, workingDir=‘file:/tmp/’).fit(trainData) predictions = learner.setOutputNode(‘z’).transform(testData) Eg. Azure Environment GPU Setup: http://azuremlbuild.blob.core.windows.net/pysparkapi/azure-setup.html
  • 30. DNN Featurization using MML-Spark cntkModel = CNTKModel().setInputCol("images"). setOutputCol("features").setModelLocation(resnetModel). setOutputNode("z.x") featurizedImages = cntkModel.transform(imagesWithLabels). select(['labels','features']) model = TrainClassifier(model=LogisticRegression(),labelCol="labels"). fit(featurizedImages) DNN featurization和SparkML pipeline stage協作。 評估直接在Scala的JVM上進行, 不需要Python UDF!
  • 33. MML for Spark應用場景 •Image Ingestion, processing and featurization 從HDFS中獲取圖片資料到Spark DataFrame 使用OpenCV的transforms預處理圖片 在使用預訓練的CNTK-DNN上特徵化圖片 •Text Analytics 在SparkML上通過單個transformer便捷地featurize free-form text data • GPU and CPU environment configuration 使用Azure上的N-Series GPU VMs 訓練基於DNN的圖像分類模型 •Training and evaluation simplification 簡便地訓練分類和回歸模型 計算豐富的評估指標,甚至是per-instance metrics
  • 35. MMLSpark PySpark Library • http://mmlspark.azureedge.net/docs/pyspark/
  • 36. MMLSpark Scala Library • http://mmlspark.azureedge.net/docs/scala
  • 37. CNTK Pre-trained Image Models • AlexNet • AlexNet for ImageNet 1K • GoogLeNet • InceptionV3 for ImageNet 1K • BN-Inception for ImageNet 1K • VGG • VGG16 for ImageNet 1K • VGG19 for ImageNet 1K https://github.com/Microsoft/CNTK/blob/master/PretrainedModels/Image.md • ResNet • ResNet18 for ImageNet 1K • ResNet34 for ImageNet 1K • ResNet50 for ImageNet 1K • ResNet20 for CIFAR-10 • ResNet110 for CIFAR-10 • ResNet101 for ImageNet 1K • ResNet152 for ImageNet 1K