tensorflow white paperを読む

49
TensorFlow White Paperを読む v1.1 1

Upload: yuta-kashino

Post on 16-Apr-2017

71.070 views

Category:

Software


0 download

TRANSCRIPT

Page 1: TensorFlow White Paperを読む

TensorFlow White Paperを読む v1.1

1

Page 2: TensorFlow White Paperを読む

今日の内容• 自己紹介

• 神経回路網と実装

• TensorFlow White Paerの概説

2

Page 3: TensorFlow White Paperを読む

自己紹介

3

Page 4: TensorFlow White Paperを読む

自己紹介• バクフー株式会社 代表取締役 柏野 雄太 (かしの ゆうた)

• 大規模リアルタイムデータのデータプラットフォーム

• PPPP preprocess /process /persistence /providing

4

Page 5: TensorFlow White Paperを読む

http://socio.bakfoo.com/[email protected]

Closed Beta

Page 6: TensorFlow White Paperを読む

自己紹介• 大規模リアルタイムのデータプラットフォーム

リアルタイムデータ 前処理 処理 ストア 提供

tweets 整形 自然言語処理・分類 API, 検索, 可視化

気象データ 変換 分類・異常値検知 API, 検索,ストリーミング

位置データ 変換 分類 API, 検索, ストリーミング

経済データ 整形・変換 異常値検知 API, 検索, 可視化6

Page 8: TensorFlow White Paperを読む

神経回路網と実装

8

Page 9: TensorFlow White Paperを読む

神経回路の数理表現

9

h

(k)(x) = g(a(k)(x))

a

(k)(x) = b

(k) +W

(k)h

(k�1)(x)

…1

1

1b(3)

b(2)

b(1)W (1)

W (2)

W (3)

x1 x2 xd

a

(3)(x) = b

(3) +W

(3)h

(2)(x)

= b

(3) +W

(3)g(b(2) +W

(2)h

(1)(x))

= b

(3) +W

(3)g(b(2) +W

(2)g(b(1) +W

(1)x))

h

(0)(x) = x

h

(1)(x) = g(a(1)(x))

h

(2)(x) = g(a(2)(x))

a

(1)(x) = b

(1) +W

(1)h

(0)(x)

a

(2)(x) = b

(2) +W

(2)h

(1)(x)

a

(3)(x) = b

(3) +W

(3)h

(2)(x)

h

(3)(x) = o(a(3)(x))

= f(x)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

Page 10: TensorFlow White Paperを読む

マルチレイヤー神経回路• L個の隠れ層の神経回路

• プレ活性

• 隠れ層活性

• 出力層活性

• レイヤーは関数適用に他ならない

10

h

(k)(x) = g(a(k)(x))

a

(k)(x) = b

(k) +W

(k)h

(k�1)(x)

h

(L+1)(x) = o(a(L+1)(x))

= f(x)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

Page 11: TensorFlow White Paperを読む

機械学習と損失関数• パラメータ・トレーニングセット

• 目的関数最小化

• 損失関数・正則関数a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

l(f(x), y)

✓ = {W (1), b(1), ...,W (L+1), b(L+1)}

(x(t), y(t))

⌦(✓)

l(f(x(t);✓), y(t)) = �logf(x(t)

)y

L(✓) =1

T

X

t

l(f(x(t);✓), y(t)) + �⌦(✓)

argmin✓L(✓)

11

Page 12: TensorFlow White Paperを読む

勾配降下と確率的勾配降下• 目的関数Lを最小化:勾配の方向にθを動かす

• 確率的勾配降下:ミニバッチ t だけをみて勾配計算

� = �r✓l(f(x(t);✓), y(t))

✓ ✓ + ↵�

Lの等高線

α: 学習率

12

Page 13: TensorFlow White Paperを読む

勾配の計算:誤差逆伝搬• 目的関数を最小にするには勾配の計算が必要

• 勾配の計算=誤差逆伝搬 � = �r✓l(f(x(t);✓), y(t))

✓ ✓ + ↵�

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

13

Page 14: TensorFlow White Paperを読む

勾配の計算:誤差逆伝搬• Hugo Larochelleの講義にGo https://goo.gl/UWtRWT

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

14

Page 15: TensorFlow White Paperを読む

勾配の計算:誤差逆伝搬• 主要DLライブラリは勾配を自動に計算 • 実はあまり気にしないでいい

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

15

Page 16: TensorFlow White Paperを読む

ライブラリ利用で必要なのは• データを入れる場所:テンソル • レイヤーの表現 • 活性化関数・出力関数 • 損失関数 • 最適化法 • 勾配計算(誤差伝搬)

• GPUへの対応

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

l(f(x), y)

16

Page 17: TensorFlow White Paperを読む

TensorFlow

17

Page 18: TensorFlow White Paperを読む

TensorFlowキャッチ

• 分散計算Theano

• 最もマーケティングに成功しつつある深層学習ライブラリ

• 最初のリリースについて機能的にガッカリ…

Page 19: TensorFlow White Paperを読む

TensorFlow Demo• チュートリアルにあるMNIST

Page 20: TensorFlow White Paperを読む

インストール

• 最初のリリースは動作環境も生焼け…

• Python2.7でないと動かない

• GPU: CUDA7.0 (7.5は動作しない)

• ProtocolBuffのバージョンでCaffeと衝突することがある

Page 21: TensorFlow White Paperを読む

TensorFlow White Paperhttp://download.tensorflow.org/paper/whitepaper2015.pdf

Page 22: TensorFlow White Paperを読む

ご注意

• White Paperに関して一つ一つのパラグラフを追いません

• 1stリリースのTensorFlowはWhite Paperにある実装の半分以上が実装されていません

Page 23: TensorFlow White Paperを読む

コンセプトとモデリング• 有向非巡回グラフ(DAG)で計算を表現:

• Theano, Chainerと同じ

• nodeはoperationと呼ばれin/outを持つ

• operationはtensorを取ってtensorを返す

• opを実行する物理的実体がkernel

op

op

op

op op

op

Page 24: TensorFlow White Paperを読む

コンセプトとモデリング

• 最初にoperationのグラフを定義

• グラフの計算はsession内のrunで実行される

• Chainer的には“define and run”

• sessionはdevice非依存:マルチデバイス,分散実行

Page 25: TensorFlow White Paperを読む

コンセプトとモデリング

x1 x2

+

y

Page 26: TensorFlow White Paperを読む
Page 27: TensorFlow White Paperを読む

コンセプトとモデリング

• opのタイプ

• valiables: パーシステントなtensorを生成するoperation

Page 28: TensorFlow White Paperを読む

計算:シングル・マルチ・分散

• サブグラフを実デバイス,マシンに分散させる

Page 29: TensorFlow White Paperを読む

計算:デバイス間通信

• send/reciveノードを計算グラフに挟む

Page 30: TensorFlow White Paperを読む

微分計算 (bprop)

• [db, dW, dx] = tf.gdadients( C, [b, W, x] )

Page 31: TensorFlow White Paperを読む

部分計算:サブグラフの計算

• サブグラフを切断: feed/fetchノードを追加

Page 32: TensorFlow White Paperを読む

計算グラフのフロー制御

• 低レベルのオペレータはある

• opの実行制御: Switch, Merge

• イテレーション:Enter, Leave,

NextIteration

Page 33: TensorFlow White Paperを読む

入力ノード,キュー,コンテナ

• 入力制御:ノードとしてテンソルをファイル・データシステムから食わせることもできる

• キュー:enqurue/dequeueで非同期実行.FIFO+シャッフルキュー

• コンテナ:Variableで定義

Page 34: TensorFlow White Paperを読む

実装の最適化

• 計算グラフの繰り返しや無駄を最適化

• GPUへのデータ転送,デバイス間の通信などたくさん最適化している(詳細不明)

• queueを使ったカーネルの非同期処理

• テンソル計算にはEigen libを使っている

• デバイス間のデータ転送には桁落ちしない圧縮

Page 35: TensorFlow White Paperを読む

SGDを速く:データ並行• ミニバッチごとに複数デバイスにグラフをレプリ

Page 36: TensorFlow White Paperを読む

SGDを速く: モデル並行• LSTMをつかうRNNなどはdeviceごとにopを割り振る

Page 37: TensorFlow White Paperを読む

SGDを速く: 少数ステップ• 複数デバイスに分散するより,シングルデバイスで少ないステップをパイプライン化したほうが良い場合もある

Page 38: TensorFlow White Paperを読む

ビジュアライゼーション• TensorBoard

python tensorboard.py --logdir=log-directory

localhost:6006

Page 39: TensorFlow White Paperを読む

ビジュアライゼーション

Page 40: TensorFlow White Paperを読む

今回の割愛

• 6 Status and Experience

• 9.2 Performance Tracing

• 10 Future Work

• 11 Related Work

Page 41: TensorFlow White Paperを読む

Performance

• 単一マシンの速度はあまり速くない…

• ただ,Gの力を結集して最適化真っ最中

https://github.com/soumith/convnet-benchmarks/issues/66

Page 42: TensorFlow White Paperを読む

Multiple Devices?

• シングルマシンのマルチGPUなら対応済みhttp://www.tensorflow.org/tutorials/deep_cnn/index.html

python cifar10_multi_gpu_train.py --num_gpus=2

Page 43: TensorFlow White Paperを読む

Multiple Computers?http://www.tensorflow.org/resources/faq.html#running_a_tensorflow_computation

https://github.com/tensorflow/tensorflow/issues/23#issuecomment-155608002

Page 44: TensorFlow White Paperを読む

kerasがTFに対応宣言

https://twitter.com/fchollet/status/663735623119949824

Page 45: TensorFlow White Paperを読む

BlackBoxMLの動きも: skflow

• Simplified interface for TensorFlow (mimicking Scikit Learn)

https://github.com/google/skflow

Page 46: TensorFlow White Paperを読む

DL学習リソース

46

Page 47: TensorFlow White Paperを読む

動画講義 (全力でオススメ)

• Deep Learning Summer School 2015

• Hugo Larochelle (Twitter/U of Sherbrooke)

• Nando de Freitas (Oxford)

• CS231n: CNN for Visual Recognition

• CS224d: DL for Natural Language Processing

http://videolectures.net/deeplearning2015_montreal/

http://cs231n.stanford.edu/

http://cs224d.stanford.edu/index.html

https://www.cs.ox.ac.uk/people/nando.defreitas/machinelearning/

https://goo.gl/UWtRWT

47

Page 48: TensorFlow White Paperを読む

書籍• 古典: Bengio et.al. 2015 DLBook

• Theano Tutorial

• Neural Networks and Deep Learning

• 岡谷貴之著 深層学習 (機械学習プロ)

• 神嶌敏弘編 深層学習: Deep Learning

http://www.iro.umontreal.ca/~bengioy/dlbook/

http://neuralnetworksanddeeplearning.com/

http://deeplearning.net/tutorial/deeplearning.pdf

48

Page 49: TensorFlow White Paperを読む

ご質問・ご意見

[email protected]

49

@yutakashino