tensorflow white paperを読む
TRANSCRIPT
TensorFlow White Paperを読む v1.1
1
今日の内容• 自己紹介
• 神経回路網と実装
• TensorFlow White Paerの概説
2
自己紹介
3
自己紹介• バクフー株式会社 代表取締役 柏野 雄太 (かしの ゆうた)
• 大規模リアルタイムデータのデータプラットフォーム
• PPPP preprocess /process /persistence /providing
4
http://socio.bakfoo.com/[email protected]
Closed Beta
自己紹介• 大規模リアルタイムのデータプラットフォーム
リアルタイムデータ 前処理 処理 ストア 提供
tweets 整形 自然言語処理・分類 API, 検索, 可視化
気象データ 変換 分類・異常値検知 API, 検索,ストリーミング
位置データ 変換 分類 API, 検索, ストリーミング
経済データ 整形・変換 異常値検知 API, 検索, 可視化6
自己紹介• Zope3の開発
• Python • いくつかの本
• PyCon JP 2015でのトーク
• バックグラウンドは宇宙物理学
• 大規模データ統計解析,科学計算
• 深層学習ウオッチャー: 2012年Hinton講義
https://goo.gl/GG4Bo8
https://www.coursera.org/course/neuralnets7
神経回路網と実装
8
神経回路の数理表現
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
マルチレイヤー神経回路• 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
機械学習と損失関数• パラメータ・トレーニングセット
• 目的関数最小化
• 損失関数・正則関数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
勾配降下と確率的勾配降下• 目的関数Lを最小化:勾配の方向にθを動かす
• 確率的勾配降下:ミニバッチ t だけをみて勾配計算
� = �r✓l(f(x(t);✓), y(t))
✓ ✓ + ↵�
Lの等高線
α: 学習率
12
勾配の計算:誤差逆伝搬• 目的関数を最小にするには勾配の計算が必要
• 勾配の計算=誤差逆伝搬 � = �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
勾配の計算:誤差逆伝搬• 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
勾配の計算:誤差逆伝搬• 主要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
ライブラリ利用で必要なのは• データを入れる場所:テンソル • レイヤーの表現 • 活性化関数・出力関数 • 損失関数 • 最適化法 • 勾配計算(誤差伝搬)
• 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
TensorFlow
17
TensorFlowキャッチ
• 分散計算Theano
• 最もマーケティングに成功しつつある深層学習ライブラリ
• 最初のリリースについて機能的にガッカリ…
TensorFlow Demo• チュートリアルにあるMNIST
インストール
• 最初のリリースは動作環境も生焼け…
• Python2.7でないと動かない
• GPU: CUDA7.0 (7.5は動作しない)
• ProtocolBuffのバージョンでCaffeと衝突することがある
TensorFlow White Paperhttp://download.tensorflow.org/paper/whitepaper2015.pdf
ご注意
• White Paperに関して一つ一つのパラグラフを追いません
• 1stリリースのTensorFlowはWhite Paperにある実装の半分以上が実装されていません
コンセプトとモデリング• 有向非巡回グラフ(DAG)で計算を表現:
• Theano, Chainerと同じ
• nodeはoperationと呼ばれin/outを持つ
• operationはtensorを取ってtensorを返す
• opを実行する物理的実体がkernel
op
op
op
op op
op
コンセプトとモデリング
• 最初にoperationのグラフを定義
• グラフの計算はsession内のrunで実行される
• Chainer的には“define and run”
• sessionはdevice非依存:マルチデバイス,分散実行
コンセプトとモデリング
x1 x2
+
y
コンセプトとモデリング
• opのタイプ
• valiables: パーシステントなtensorを生成するoperation
計算:シングル・マルチ・分散
• サブグラフを実デバイス,マシンに分散させる
計算:デバイス間通信
• send/reciveノードを計算グラフに挟む
微分計算 (bprop)
• [db, dW, dx] = tf.gdadients( C, [b, W, x] )
部分計算:サブグラフの計算
• サブグラフを切断: feed/fetchノードを追加
計算グラフのフロー制御
• 低レベルのオペレータはある
• opの実行制御: Switch, Merge
• イテレーション:Enter, Leave,
NextIteration
入力ノード,キュー,コンテナ
• 入力制御:ノードとしてテンソルをファイル・データシステムから食わせることもできる
• キュー:enqurue/dequeueで非同期実行.FIFO+シャッフルキュー
• コンテナ:Variableで定義
実装の最適化
• 計算グラフの繰り返しや無駄を最適化
• GPUへのデータ転送,デバイス間の通信などたくさん最適化している(詳細不明)
• queueを使ったカーネルの非同期処理
• テンソル計算にはEigen libを使っている
• デバイス間のデータ転送には桁落ちしない圧縮
SGDを速く:データ並行• ミニバッチごとに複数デバイスにグラフをレプリ
SGDを速く: モデル並行• LSTMをつかうRNNなどはdeviceごとにopを割り振る
SGDを速く: 少数ステップ• 複数デバイスに分散するより,シングルデバイスで少ないステップをパイプライン化したほうが良い場合もある
ビジュアライゼーション• TensorBoard
python tensorboard.py --logdir=log-directory
localhost:6006
ビジュアライゼーション
今回の割愛
• 6 Status and Experience
• 9.2 Performance Tracing
• 10 Future Work
• 11 Related Work
Performance
• 単一マシンの速度はあまり速くない…
• ただ,Gの力を結集して最適化真っ最中
https://github.com/soumith/convnet-benchmarks/issues/66
Multiple Devices?
• シングルマシンのマルチGPUなら対応済みhttp://www.tensorflow.org/tutorials/deep_cnn/index.html
python cifar10_multi_gpu_train.py --num_gpus=2
Multiple Computers?http://www.tensorflow.org/resources/faq.html#running_a_tensorflow_computation
https://github.com/tensorflow/tensorflow/issues/23#issuecomment-155608002
kerasがTFに対応宣言
https://twitter.com/fchollet/status/663735623119949824
BlackBoxMLの動きも: skflow
• Simplified interface for TensorFlow (mimicking Scikit Learn)
https://github.com/google/skflow
DL学習リソース
46
動画講義 (全力でオススメ)
• 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
書籍• 古典: 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