55
Inspection of Cloud Machine Leaning Hyper Parameter Tuning nagachika GCPUG Fukuoka

Inspection of CloudML Hyper Parameter Tuning

Embed Size (px)

Citation preview

Page 1: Inspection of CloudML Hyper Parameter Tuning

Inspection of

Cloud Machine Leaning Hyper Parameter Tuning

nagachika GCPUG Fukuoka

Page 2: Inspection of CloudML Hyper Parameter Tuning

Agenda

• Hyper Parameter Tuning とは?

• Hyper Parameter Tuning の性能を実験

• Hyper Parameter Tuning の探索⽅法を推測

Page 3: Inspection of CloudML Hyper Parameter Tuning

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

Pull Requests to TensorFlow

Page 5: Inspection of CloudML Hyper Parameter Tuning

Cloud Machine Learning

Page 6: Inspection of CloudML Hyper Parameter Tuning

Cloud Machine Leaning• Training

• TensorFlow が(分散環境、GPU環境含め) ⽤意されている実⾏環境のホスティングサービス

• TensorFlow 専⽤のPaaS(Heroku)

• Prediction

• TensorFlow Serving のホスティングサービス

• API で Training したモデルを利⽤できる

Page 7: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning

Page 8: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning

• Hyper Parameter とは?

• モデル(SVM, Random Forest, MLP, CNN 等々なんであれ)の学習に先⽴って決定しないといけないパラメータ

• モデルの精度に影響する

• より良い Hyper Parameter の探索が望ましい

Page 9: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning• Machine Learning Model

Input Output

Page 10: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning• Machine Learning Model

Dog or Cat

Page 11: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning• Machine Learning Model

Input Output

トレーニング可能なパラメータ

トレーニング不可なパラメータ

期待する Output が得られるようにトレーニング可能なパラメータを

変更するのが(教師あり)機械学習における

「学習」

Page 12: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning• Machine Learning Model

Input Output

トレーニング可能なパラメータ

トレーニング不可なパラメータ

Expectation

Error

期待(Expectation)と実際の Outputの差を定量化したもの

(Error)を最⼩にする。勾配を⽤いた⼿法が主流

Page 13: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning• Machine Learning Model

Input Output

トレーニング可能なパラメータ

トレーニング不可なパラメータ

Expectation

Error

Page 14: Inspection of CloudML Hyper Parameter Tuning

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

Hyper Parameter Tuning• Machine Learning Model

Input (Hyper Parameter)

Output (Error)

ただし、⼀般的に

• 勾配はわからない(そもそもInputが距離の概念がある空間と限らない)

• F(x) の評価には時間がかかる

Page 16: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning

• Derivative-free optimization (勾配によらない最適化⼿法)

• Simulated Annealing(焼きなまし法)

• Genetic Algorithm(遺伝的アルゴリズム)

→ ⼤量の試⾏が必要で実⾏コストが⼤きい

Page 17: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning

• Scikit learn

• Grid Search(グリッドサーチ)

• パラメータ毎に有限の候補の組み合わせ試⾏

• Random Search(ランダム探索)

→ シンプルだけどいまいち賢くない

Page 18: Inspection of CloudML Hyper Parameter Tuning

Hyper Parameter Tuning

Cloud Machine Learning の Hyper Parameter Tuning は

どんな⽅法で探索をしているのだろうか?

Page 19: Inspection of CloudML Hyper Parameter Tuning

Motivation

Page 20: Inspection of CloudML Hyper Parameter Tuning

Motivation• 多層ニューラルネットワーク

• 層の数

• (各層の)ユニット(ニューロン)の数

• etc…

Layer-1 Layer-2

Page 21: Inspection of CloudML Hyper Parameter Tuning

Motivation

• 層の数

• (各層の)ユニット(ニューロン)の数

➡ 1つのパラメータで表現したいな

➡ 極度に多峰的な関数になりそう…

Page 22: Inspection of CloudML Hyper Parameter Tuning

Motivation

• 多峰性関数→最適化が困難な性質

➡ Cloud Machine Learning はこんな関数に対してどのくらい賢く最適化してくれるんだろう?

単峰性関数 多峰性関数

Page 23: Inspection of CloudML Hyper Parameter Tuning

実験1

Page 24: Inspection of CloudML Hyper Parameter Tuning

実験1

• Cloud Machine Learning に Hyper Parameter Tuning で 既知の関数の最適化をさせる

• F(x) を明⽰的に式として与える

• Hyper Parameter を受け取って F(x) を計算して報告するだけの Python モジュールを作成

Page 25: Inspection of CloudML Hyper Parameter Tuning

実験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

実験1

N=10

Page 27: Inspection of CloudML Hyper Parameter Tuning

実験1

N=10

Page 28: Inspection of CloudML Hyper Parameter Tuning

実験1

N=10

Page 29: Inspection of CloudML Hyper Parameter Tuning

実験1

N=15

Page 30: Inspection of CloudML Hyper Parameter Tuning

実験1

N=15

Page 31: Inspection of CloudML Hyper Parameter Tuning

実験1

Page 32: Inspection of CloudML Hyper Parameter Tuning

実験1

N=30

Page 33: Inspection of CloudML Hyper Parameter Tuning

実験1

Ackley 関数

Page 34: Inspection of CloudML Hyper Parameter Tuning

実験1

Ackley 関数 N=30

Page 35: Inspection of CloudML Hyper Parameter Tuning

実験1

• あきらかに Grid Search ではない

• 低次元の多項式(?)くらいだとかなり賢い(少ない試⾏回数で最適値の近くを当てる)

• 難しい形状の関数もそれなりに(⼤域探索している? 局所解に落ちたりはなさそう)

➡ どうやってるんだろう???

Page 36: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization ベイズ最適化

Page 37: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization

http://mathetake.hatenablog.com/entry/2016/12/19/145311

Page 38: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization

https://www.youtube.com/watch?v=pQHWew4YYao

ベイズ的最適化の⼊⾨と応⽤ 機械学習による機械学習の実験計画

Page 39: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization

おおざっぱな理解では

• 既に得た⼊⼒の結果を元に推測しつつ

• まだ調べてないあたりも調べるようにしつつ

いい感じに探索するために、最適化したい関数の形状を(各⼊⼒に対する) 確率分布として捉える。

Page 40: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization• 関数を確率分布として捉える?

Page 41: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization• 関数を確率分布として捉える?

• x をある値に固定した時にF(x)が取る値を確率分布

• 既知の⼊⼒ x = x1, x2, … を元に計算する

Page 42: Inspection of CloudML Hyper Parameter Tuning

Bayesian Optimization

• Acquisition function

• 次にテストすべき点を決めるための「重要度」みたいなのを決める関数

• GP-UCB

平均 分散

= 活⽤ = 探索

Page 43: Inspection of CloudML Hyper Parameter Tuning

実験2

Page 44: Inspection of CloudML Hyper Parameter Tuning

実験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

実験2

N=10

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 46: Inspection of CloudML Hyper Parameter Tuning

実験2

N=10

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 47: Inspection of CloudML Hyper Parameter Tuning

実験2

N=10

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 48: Inspection of CloudML Hyper Parameter Tuning

実験2

N=15

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 49: Inspection of CloudML Hyper Parameter Tuning

実験2

N=15

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 50: Inspection of CloudML Hyper Parameter Tuning

実験2

Page 51: Inspection of CloudML Hyper Parameter Tuning

実験2N=30

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 52: Inspection of CloudML Hyper Parameter Tuning

実験2

Ackley 関数

Page 53: Inspection of CloudML Hyper Parameter Tuning

実験2N=30

Cloud Machine Learning Hyper Parameter Tuning

BayesianOptimization

Page 54: Inspection of CloudML Hyper Parameter Tuning

実験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

Summary• Cloud Machine Learning のHyper Parameter

Tuning はかしこくて便利

• Hyper Parameter に対して複雑な関数になる時は多めに試⾏回数を取ろう

• Hyper Parameter Tuning の裏側は Bayesian Optimization?

• オレオレ Cloud Machine Learning の構築も夢ではない!?