Inspection of CloudML Hyper Parameter Tuning
-
Upload
nagachika-t -
Category
Technology
-
view
1.479 -
download
0
Transcript of Inspection of CloudML Hyper Parameter Tuning
![Page 1: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/1.jpg)
Inspection of
Cloud Machine Leaning Hyper Parameter Tuning
nagachika GCPUG Fukuoka
![Page 2: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/2.jpg)
Agenda
• Hyper Parameter Tuning とは?
• Hyper Parameter Tuning の性能を実験
• Hyper Parameter Tuning の探索⽅法を推測
![Page 3: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/3.jpg)
About me• nagachika
• Ruby committer, Stable branch maintainer
• Fukuoka.rb organizer
• GCPUG
• TFUG (TensorFlow User Group)
• TensorFlow contributor ← NEW
![Page 4: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/4.jpg)
Pull Requests to TensorFlow
![Page 5: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/5.jpg)
Cloud Machine Learning
![Page 6: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/6.jpg)
Cloud Machine Leaning• Training
• TensorFlow が(分散環境、GPU環境含め) ⽤意されている実⾏環境のホスティングサービス
• TensorFlow 専⽤のPaaS(Heroku)
• Prediction
• TensorFlow Serving のホスティングサービス
• API で Training したモデルを利⽤できる
![Page 7: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/7.jpg)
Hyper Parameter Tuning
![Page 8: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/8.jpg)
Hyper Parameter Tuning
• Hyper Parameter とは?
• モデル(SVM, Random Forest, MLP, CNN 等々なんであれ)の学習に先⽴って決定しないといけないパラメータ
• モデルの精度に影響する
• より良い Hyper Parameter の探索が望ましい
![Page 9: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/9.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input Output
![Page 10: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/10.jpg)
Hyper Parameter Tuning• Machine Learning Model
Dog or Cat
![Page 11: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/11.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input Output
トレーニング可能なパラメータ
トレーニング不可なパラメータ
期待する Output が得られるようにトレーニング可能なパラメータを
変更するのが(教師あり)機械学習における
「学習」
![Page 12: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/12.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input Output
トレーニング可能なパラメータ
トレーニング不可なパラメータ
Expectation
Error
期待(Expectation)と実際の Outputの差を定量化したもの
(Error)を最⼩にする。勾配を⽤いた⼿法が主流
![Page 13: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/13.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input Output
トレーニング可能なパラメータ
トレーニング不可なパラメータ
Expectation
Error
![Page 14: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/14.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input (Hyper Parameter)
Output (Error)
Hyper Parameter を⼊⼒として誤差(Error)を出⼒とする関数とみなすこともできる
↓ Output(Error)を最⼩にする Input(Hyper Parameter)を
探索する最適化問題
![Page 15: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/15.jpg)
Hyper Parameter Tuning• Machine Learning Model
Input (Hyper Parameter)
Output (Error)
ただし、⼀般的に
• 勾配はわからない(そもそもInputが距離の概念がある空間と限らない)
• F(x) の評価には時間がかかる
![Page 16: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/16.jpg)
Hyper Parameter Tuning
• Derivative-free optimization (勾配によらない最適化⼿法)
• Simulated Annealing(焼きなまし法)
• Genetic Algorithm(遺伝的アルゴリズム)
→ ⼤量の試⾏が必要で実⾏コストが⼤きい
![Page 17: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/17.jpg)
Hyper Parameter Tuning
• Scikit learn
• Grid Search(グリッドサーチ)
• パラメータ毎に有限の候補の組み合わせ試⾏
• Random Search(ランダム探索)
→ シンプルだけどいまいち賢くない
![Page 18: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/18.jpg)
Hyper Parameter Tuning
Cloud Machine Learning の Hyper Parameter Tuning は
どんな⽅法で探索をしているのだろうか?
![Page 19: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/19.jpg)
Motivation
![Page 20: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/20.jpg)
Motivation• 多層ニューラルネットワーク
• 層の数
• (各層の)ユニット(ニューロン)の数
• etc…
Layer-1 Layer-2
![Page 21: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/21.jpg)
Motivation
• 層の数
• (各層の)ユニット(ニューロン)の数
➡ 1つのパラメータで表現したいな
➡ 極度に多峰的な関数になりそう…
![Page 22: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/22.jpg)
Motivation
• 多峰性関数→最適化が困難な性質
➡ Cloud Machine Learning はこんな関数に対してどのくらい賢く最適化してくれるんだろう?
単峰性関数 多峰性関数
![Page 23: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/23.jpg)
実験1
![Page 24: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/24.jpg)
実験1
• Cloud Machine Learning に Hyper Parameter Tuning で 既知の関数の最適化をさせる
• F(x) を明⽰的に式として与える
• Hyper Parameter を受け取って F(x) を計算して報告するだけの Python モジュールを作成
![Page 25: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/25.jpg)
実験1• Hyper Parameter
• 1変数(x), 2変数(x, y)
• 範囲は全て [-1, 1]
• 最⼩値を求める
• 探索回数(N)は
• 1変数 → N=10 or 15
• 2変数 → N=30
![Page 26: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/26.jpg)
実験1
N=10
![Page 27: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/27.jpg)
実験1
N=10
![Page 28: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/28.jpg)
実験1
N=10
![Page 29: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/29.jpg)
実験1
N=15
![Page 30: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/30.jpg)
実験1
N=15
![Page 31: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/31.jpg)
実験1
![Page 32: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/32.jpg)
実験1
N=30
![Page 33: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/33.jpg)
実験1
Ackley 関数
![Page 34: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/34.jpg)
実験1
Ackley 関数 N=30
![Page 35: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/35.jpg)
実験1
• あきらかに Grid Search ではない
• 低次元の多項式(?)くらいだとかなり賢い(少ない試⾏回数で最適値の近くを当てる)
• 難しい形状の関数もそれなりに(⼤域探索している? 局所解に落ちたりはなさそう)
➡ どうやってるんだろう???
![Page 36: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/36.jpg)
Bayesian Optimization ベイズ最適化
![Page 37: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/37.jpg)
Bayesian Optimization
http://mathetake.hatenablog.com/entry/2016/12/19/145311
![Page 38: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/38.jpg)
Bayesian Optimization
https://www.youtube.com/watch?v=pQHWew4YYao
ベイズ的最適化の⼊⾨と応⽤ 機械学習による機械学習の実験計画
![Page 39: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/39.jpg)
Bayesian Optimization
おおざっぱな理解では
• 既に得た⼊⼒の結果を元に推測しつつ
• まだ調べてないあたりも調べるようにしつつ
いい感じに探索するために、最適化したい関数の形状を(各⼊⼒に対する) 確率分布として捉える。
![Page 40: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/40.jpg)
Bayesian Optimization• 関数を確率分布として捉える?
![Page 41: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/41.jpg)
Bayesian Optimization• 関数を確率分布として捉える?
• x をある値に固定した時にF(x)が取る値を確率分布
• 既知の⼊⼒ x = x1, x2, … を元に計算する
![Page 42: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/42.jpg)
Bayesian Optimization
• Acquisition function
• 次にテストすべき点を決めるための「重要度」みたいなのを決める関数
• GP-UCB
平均 分散
= 活⽤ = 探索
![Page 43: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/43.jpg)
実験2
![Page 44: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/44.jpg)
実験2
• 実験1と同じF(x)に対して Bayesian Optimization
• 最初の3点は実験1の(Cloud MLの)結果を流⽤(Bayesian Optimization は初期何点かはランダム探索)
• PythonのBayesianOptimizationパッケージを利⽤[https://github.com/fmfn/BayesianOptimization]
• Acquisition function には GP-UCB, kappa=0.5 を選択
![Page 45: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/45.jpg)
実験2
N=10
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 46: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/46.jpg)
実験2
N=10
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 47: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/47.jpg)
実験2
N=10
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 48: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/48.jpg)
実験2
N=15
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 49: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/49.jpg)
実験2
N=15
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 50: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/50.jpg)
実験2
![Page 51: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/51.jpg)
実験2N=30
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 52: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/52.jpg)
実験2
Ackley 関数
![Page 53: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/53.jpg)
実験2N=30
Cloud Machine Learning Hyper Parameter Tuning
BayesianOptimization
![Page 54: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/54.jpg)
実験2
• Bayesian Optimization > Grid Search
• Cloud Machine Learning の Hyper Parameter Tuning と似ているといえなくもない?
• Bayesian Optimization⾃体にもHyper Parameterがある(acquisition function の選択, そのパラメータ etc..)
![Page 55: Inspection of CloudML Hyper Parameter Tuning](https://reader034.fdocument.pub/reader034/viewer/2022052117/5899858b1a28abb97c8b65cb/html5/thumbnails/55.jpg)
Summary• Cloud Machine Learning のHyper Parameter
Tuning はかしこくて便利
• Hyper Parameter に対して複雑な関数になる時は多めに試⾏回数を取ろう
• Hyper Parameter Tuning の裏側は Bayesian Optimization?
• オレオレ Cloud Machine Learning の構築も夢ではない!?