More Related Content Similar to Deep learning を用いた画像から説明文の自動生成に関する研究の紹介
Similar to Deep learning を用いた画像から説明文の自動生成に関する研究の紹介 (20) More from 株式会社メタップスホールディングス
More from 株式会社メタップスホールディングス (18) Deep learning を用いた画像から説明文の自動生成に関する研究の紹介2. © 2015 Metaps Inc. All Rights Reserved.
調査・資料作成
礼王 懐成
Keo Darawong
• 株式会社メタップス(研究開発部門)所属
• 東京大学大学院 工学系研究科 卒業
• 人工生命研究所(役員)、東京大学先端科学技術研究セ
ンター特任助手、独立やベンチャーを経てメタップスへ
• 大学院学生時代は大脳基底核と前頭葉ループにおける運動系列強化学習を研究。
問題解決法に興味を持ち人工知能の研究開発を行なっているベンチャー会社へ。
機械学習を用いた自然言語解析や画像認識や知識推論の研究開発(接地問題に
挑戦)。 金融工学や検索エンジン(マップ検索も含む)も経験。 画像認識機能を持つ
自然言語対話システムのための要素技術の研究開発。 トピックモデルなど自然言語
解析を用いたマーケティングの研究開発。
3. © 2015 Metaps Inc. All Rights Reserved.
画像の説明文生成システム概要
画像認識識
⾃自然⾔言語解析
画像-‐‑‒テキス
トの融合空間
説明⽂文の⽣生成
学習時のみ使用
4. © 2015 Metaps Inc. All Rights Reserved.
従来モデルとdeep learningモデルの比較
従来のモデル Deep learningモデル
画像認識識部 SIFT,HOGなどの伝統の画像認識識
Convolutional neural
network (CNN)
画像-テキスト
の融合 3項モデル
埋め込み空間 or
(埋め込み空間 + RNN)
⽂文章⽣生成
テンプレート・統合論論ベース⾔言語
モデル RNN (LSTM等)
*RNN: Recurrent Neural Networks
5. © 2015 Metaps Inc. All Rights Reserved.
画像認識のパイプラインの変化
中山英樹, 2014
生の画素値から、識別に至る階層構造を直接的に学習。
従来の特徴量に相当する構造が中間層に自然に出現 。
6. © 2015 Metaps Inc. All Rights Reserved.
Convolutional neural network
7. © 2015 Metaps Inc. All Rights Reserved.
レイヤーごとの特徴表現の可視化
Matthew D. Zeiler and Rob Fergus ,2014
8. © 2015 Metaps Inc. All Rights Reserved.
レイヤーごとの特徴表現の可視化
Matthew D. Zeiler and Rob Fergus ,2014
9. © 2015 Metaps Inc. All Rights Reserved.
画像-テキストembedding
• 画像と文章の特徴ベクトルを共通空間に写像して、それぞれの
類似度を比較できるようにする。
• 写像先の共通空間の設計が重要である。
Every Picture Tells a Story: Generating
Sentences from Images
DeViSE: Andrea Frome etc 2013
Ali Farhadi,etc 2010
10. © 2015 Metaps Inc. All Rights Reserved.
従来の手法:Template based language generation
• Image Space を Meaning Space にマップする。
• Sentence Space から Meaning Spaceにマップをする。
• Imagesに対応したSentencesをMeaning Spaceを通して検索する。
Ali Farhadi, etc 2010
Meaning Spaceは
の3項からなる。
11. © 2015 Metaps Inc. All Rights Reserved.
従来の手法:Template based language generation
Image Space を Meaning Space にマップする。
Meaning Spaceは
の3項からなる。
Ali Farhadi, etc 2010
12. © 2015 Metaps Inc. All Rights Reserved.
従来の手法:Template based language generation
Image Space を Meaning Space にマップする。
MRFを用いて の割り当てを計算する。
Ali Farhadi, etc 2010
13. © 2015 Metaps Inc. All Rights Reserved.
Sentence Space から Meaning Spaceにマップをする。
従来の手法:Template based language generation
Ali Farhadi, etc 2010
14. © 2015 Metaps Inc. All Rights Reserved.
トレーニングデータにあるセンテンスから主語、動詞、シーンを抽出する。
従来の手法:Template based language generation
Ali Farhadi, etc 2010
15. © 2015 Metaps Inc. All Rights Reserved.
従来の手法:Template based language generation
Imagesに対応したSentencesをMeaning Spaceを通して検索して、
当てはまる文を選択する。
Ali Farhadi, etc 2010
16. © 2015 Metaps Inc. All Rights Reserved.
従来の手法:Template based language generation
その2
CRFを用いて、物体、属性、関係性を学習する。
この結果をテンプレートやILPを用いて文章の生成を行う。
Girish Kulkarni, etc. 2013
17. © 2015 Metaps Inc. All Rights Reserved.
統合論的言語モデルによる文章生成
統合論的文章生成:構文構造を考慮した文章の生成を行う。
Kuznetsova, Polina, etc2014)
18. © 2015 Metaps Inc. All Rights Reserved.
Embedding Spaceの設計
• 人の手でイメージと言語をつなげるmeaning
space用のデータセットを作るのは、効率が悪い。
• どのようにして自動的に言語情報とイメージ情報
を結びつけた空間を構築するか?
• 言語情報をベクトル化を行い(word2vec) CNNなどで処
理を行った画像ベクトルの距離が最小になるように写像を
行って同じ空間に埋め込む(Embedding Space)。
19. © 2015 Metaps Inc. All Rights Reserved.
Skip-gram language model
1000次元の国や首都のSkip-gramベクトルをPCAで2次元に写像した図
国の分布と首都の分布が分かれており、国と首都との対応も確認ができる。
Tomas Mikolov,etc 2013
20. © 2015 Metaps Inc. All Rights Reserved.
DeViSE: A Deep Visual-Semantic Embedding Model
Andrea Frome,etc 2013
CNNを通して作成した画像ベクトルを、Skip-gram言語モデルで作
成ベクトルに距離を最小化する写像を行い、Multimodal 埋め込み
空間を作成。
21. © 2015 Metaps Inc. All Rights Reserved.
DeViSE: A Deep Visual-Semantic Embedding Model
Andrea Frome,etc 2013
ILSVRC 2012 1K labelのサブセットでskip-gramで埋め込み学習を行う。
類義語は似たようなコンテキストに現れる傾向があり、このシンプルな関数はそのよ
うな性質を利用して、意味的に関係する語を似たような埋め込みベクトルになるよう
に学習することができる。
22. © 2015 Metaps Inc. All Rights Reserved.
RNN(Recurrent Neural Networks)による画像からの説
明文の生成
RNNによる説明文の生成には以下のようなモデルがある。
• SimpleなRNN
– 1),Junhua Mao, etc 2014. 2) Andrej Karpathy, etc 2015
• SC-‐‑‒NLM
– Ryan Kiros, etc 2015
• LSTM
– Oriol Vinyals, etc 2015.
• Attention Model + LSTM
– Xu, etc 2015
23. © 2015 Metaps Inc. All Rights Reserved.
Deep Captioning With Multimodal
Recurrent Neural Networks (M-RNN)
Junhua Mao,etc 2015
24. © 2015 Metaps Inc. All Rights Reserved.
Deep Captioning With Multimodal Recurrent
Neural Networks (M-RNN)
Junhua Mao,etc 2015
[図]単純なRNNを用いたモデル:
縦の紫の矢印は時間経過
上式は、左図のRecurrent部(赤い四角)
に対応し、t時間による入力単語w(t)と
1ステップ前の回帰部r(t-1)をUrで変換
したものを以下の関数f_2の引数とする。
f_2はRectified Linear Unit (ReLU)
で、出力は次の回帰部 r(t)となる。
上の式は、Multimodal部(紫の四角)に相当し、 単語
w(t), Recurrent部r(t) , CNNで処理されたイメージI
から計算される。g_2は右式のように定義される。
25. © 2015 Metaps Inc. All Rights Reserved.
Deep Captioning With Multimodal Recurrent
Neural Networks (M-RNN)
は画像Iと が与えられたときのw_nの確率 上式の
と はトレーニングセットにあるそれぞれ単語の数とセンテンス数である。
θは、前述のモデルパラメータである。
このコスト関数Cを最小化するようにパラメータθを決める。
Junhua Mao,etc 2015
26. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for
Generating Image Descriptions
Andrej Karpathy, etc 2015
27. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for Generating
Image Descriptions
Infer region-word alignments (R-CNN + BRNN + MRF)
これを用いることで、画像を一対一対応でラベル付けする
ことなく、画像とテキストの対応付けすることができる。
Andrej Karpathy, etc 2015
28. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for Generating
Image Descriptions
Infer region-word alignments
(RCNN + BRNN + MRF)
Andrej Karpathy, etc 2015
処理の全体像:
RCNNで領域別画像のベクトルを
BRNNを用いて作った文章ベクトルと
の内積を計算し、写真領域と説明文
の対応が最大のものを抽出する。
29. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for Generating
Image Descriptions
2. Extract region proposals:
オブジェクトが存在している領域を四角で切り出す技術でSelective Search
などのComputer Visionの技術を用いている。
3. Convolutional neural networks: CNNを用いて計算。
4. Classify Regions: SVMを用いて物体の分類を行う。
Andrej Karpathy, etc 2015
30. © 2015 Metaps Inc. All Rights Reserved.
Bidirectional recurrent neural networks
x_tの前後だけでなく文全体のコンテキストを取り入れたモデルをs_tとして出力する。
W_wはword2vecを用いて単語のベクトル化を行う。
31. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for Generating
Image Descriptions
文章の記述の対象がRCNNで得られる方形領域a_jを複数またぐ場合、
以下のようなMRFも用いて複数領域を統合する。
v_i,s_tはそれぞれ画像ベクトルと文章ベクトルである。
Max margin を用いた構造損失関数を用いて、イメージと文章のマッチングの
ランキング付けを行う。
Andrej Karpathy, etc 2015
32. © 2015 Metaps Inc. All Rights Reserved.
Deep Visual-Semantic Alignments for
Generating Image Descriptions
*RNNを用いて文章を生成。
*画像とテキストの共通空間への
埋め込みを使わずに、コンテキスト
と前に出現した単語により次の単
語出現確率を計算する。
*画像の特徴量は、最初のコンテ
キスト情報として用いられる。
(RCNN + BRNN + MRFで得られ
た結果を教師データとして用いる。)
Andrej Karpathy, etc 2015
33. © 2015 Metaps Inc. All Rights Reserved.
Show and Tell: A Neural Image Caption
Generator
Oriol Vinyals,etc 2015
34. © 2015 Metaps Inc. All Rights Reserved.
Show and Tell: A Neural Image Caption Generator
Oriol Vinyals,etc 2015
x_tからLSTMで次の単語ベクトルS_(t+1)の出現を計
算する。
35. © 2015 Metaps Inc. All Rights Reserved.
LSTMの隠れ状態の構造
Ilya Sutskever, etc 2014
文章の処理後のLSTMの隠れ状態をPCAで2次元に写像。
bag-of-wordsモデルでは難しい語順を考慮した意味によってクラスタリング
されていることがわかる。
左右のクラスタは似たような内部構造があると確認できる。
36. © 2015 Metaps Inc. All Rights Reserved.
Show and Tell: A Neural Image Caption Generator
画像入力はCNNを通して、
LSTMの最初だけである。(式10)
その後の処理は単語ベクトルを
画像と共通のembedding空間に
埋め込みながら、LSTMで次の単
語ベクトルの出現確率を計算する。
S_tは単語から生成されたone hot vectorであり、embedding行列Weに
よってembedding空間に単語ベクトルを埋め込み、それをx_tとする。
x_tからLSTMで次の単語ベクトルS_(t+1)の出現を計算する。
図、処理の全体像
Oriol Vinyals,etc 2015
37. © 2015 Metaps Inc. All Rights Reserved.
Unifying Visual-Semantic Embeddings
with Multimodal Neural Language Models
Ryan Kiros, etc 2014
38. © 2015 Metaps Inc. All Rights Reserved.
文章は計算処理を行ったLSTMのメモリノードの状態ベクトルvをMultimodal空間
に写像する。CNNで計算した画像ベクトルqを、LSTMのメモリノードの状態ベクトル
vに近づけるようにWI行列でMultimodal空間にベクトルxとして写像する。
Multi-modal spaceに射影された画像ベクトルをSC-NLMを用いてdecodeを行い、
文章生成を行う。
処理の全体概要
Unifying Visual-Semantic Embeddings with
Multimodal Neural Language Models
Ryan Kiros, etc 2014
39. © 2015 Metaps Inc. All Rights Reserved.
Unifying Visual-Semantic Embeddings with
Multimodal Neural Language Models
Multimodal空間の性質として、言語ベクトルと画像ベクトルの加算、減算が可能であり、
それは、物体のみならず、その色などの性質も扱うことができる。
文章に含まれる単語ベクトルW_iの総和として、文章ベクトルを定義する。
v_blue + v_carはI_barの近くに射影される。つまり、青いという単語ベクトルと
車という単語ベクトルを加算すると青い画像ベクトルの近いベクトルが合成される。
また、以下のように減算も加算と同様な概念で操作が可能である。
Ryan Kiros, etc 2014
40. © 2015 Metaps Inc. All Rights Reserved.
Unifying Visual-Semantic Embeddings with
Multimodal Neural Language Models
Ryan Kiros, etc 2014
Multimodal spaceでの言語ベクトルと画像ベクトルの加算、減算が可能
41. © 2015 Metaps Inc. All Rights Reserved.
Unifying Visual-Semantic Embeddings with Multimodal
Neural Language Models
300次元の言語とイメージをPCA射影を行い
(a) 自動車と色
(b) 天気と気温
とクラスタに分かれてそれぞれ言葉とイメージが対応している。
Ryan Kiros, etc 2014
42. © 2015 Metaps Inc. All Rights Reserved.
Structure-content neural language model
(SC-NLM)による説明文の生成
図(a)のSC-NLMは、図(b)のMLBL-F のように簡素化したモデルとして見なせる。
図(b)のC1,C2..,Cm行列は、図(a)のcontext行列に対応する。
図(b)のW_fxは、図(a)のcontentの出力行列に対応しているとみなすことができる。
(a) SC-NLM decoder
(b) Factored 3-way Log-Bilinear Model
(MLBL-F)
Ryan Kiros, etc 2014
43. © 2015 Metaps Inc. All Rights Reserved.
Factored 3-way Log-Bilinear Model
f: factor 因子に対して次の
行列が定義される。
:単語から因子への写像行列
Factored 3-way Log-Bilinear Model (MLBL-F)
:因子から生成単語への写像行列
:画像から因子への写像行列
生成される単語がiである確率をMLBL-Fを用いて以下の式で計算している。
uは、画像ベクトルである。
Ryan Kiros, etc 2014
44. © 2015 Metaps Inc. All Rights Reserved.
Unifying Visual-Semantic Embeddings with
Multimodal Neural Language Models
前出のcontentである画像uに加え、文の
品詞情報を考慮した新しいu^を以下の式
のように定義する。t_iは単語iに対応した
品詞情報である。
図:SC-NLMにcontentである画像
に加え、品詞情報をstructとして導入。
Ryan Kiros, etc 2014
45. © 2015 Metaps Inc. All Rights Reserved.
Show, Attend and Tell: Neural Image Caption
Generation with Visual Attention
Kelvin Xu,etc 2015
46. © 2015 Metaps Inc. All Rights Reserved.
Show, Attend and Tell: Neural Image Caption
Generation with Visual Attention
Kelvin Xu, etc 2015
画像の一部に焦点を当てて、画像を解析するモデルは、画像全体を解析するよ
り単語対応での効率と精度が良く、また、RCNNのようにオブジェクト認識をし
ないため、動きによって形を変える物を認識するのに優れているとされている。
LSTMによって生成される系列のコンテキストと生成された言語と読み込まれ
た画像ベクトルの一部によって注意系列と単語が生成される。
47. © 2015 Metaps Inc. All Rights Reserved.
LSTM(Long Short-TermMemory)
Kelvin Xu, etc 2015
y_iは説明文の中の単語ベクトル
はそれぞれ入力、忘却、メモリー、出力、隠れ状態
a_iは画像のアノテーションベクトル
iは画像のロケーションのindexである。
48. © 2015 Metaps Inc. All Rights Reserved.
Show, Attend and Tell: Neural Image Caption
Generation with Visual Attention
e_tiは、注意モデルf_attによる
出力。時間tでCNNで抽出された
部分画像a_iベクトルとLSTMの
一つステップ前の隠れ状態h_(t-1
)によって決定される。
α_tiはe_tiをsoftmaxで正規化し
た重み。
z_tは、部分画像a_iと注意係数α_iとの組み合わせによるコンテキストベクトル。
式(7)は時系列t時におけるLSTMで計算された単語y_tの予測確率。
m:はembedding次元数 , n: LSTMの次元数、K:単語数、D:画像のベクトル次元
Kelvin Xu, etc 2015
49. © 2015 Metaps Inc. All Rights Reserved.
前で定義したsを用いた評価関数 L_sを、logp(y|a)の変分
下界として以下のように定義できる。
s_t,iは、t個目の単語がi番目の場所が選択されたときに1とする
one-hot変数である。
Stochastic “Hard” Attention model
Kelvin Xu, etc 2015
50. © 2015 Metaps Inc. All Rights Reserved.
前で定義したsを用いた評価関数 L_sを、重み行列Wで微
分して最適なWを得る。
α_iから場所s_tをサンプリングする多項サンプリングを作成
Monte Carloサンプリングを用いて、重みの学習を行う。
Stochastic “Hard” Attention model
Kelvin Xu, etc 2015
51. © 2015 Metaps Inc. All Rights Reserved.
エントロピー項を導入して式展開すると、強化学習のような式になる。
位置ベクトルs(where), 画像ベクトルa(what)に対する単語ベクト
ルyの出現確率の予測誤差を用いて、重みを学習する。
Monte Carloの推定の分散を少なくするために、ミニバッチkごと
に移動平均ベースラインの上式のように計算を行う。
Stochastic “Hard” Attention model
Kelvin Xu, etc 2015
52. © 2015 Metaps Inc. All Rights Reserved.
Deterministic “Soft” Attention
“Soft” Attentionは機械翻訳の技術を応用している。ある言語 {x_1, x_2,..,x_T}
から言語 {y_1,y_2,..,y_N} に翻訳。翻訳元の言語Xの隠れ状態を{h_1,h_2,..h_T}
として、翻訳先の隠れ状態を{s_1, s_2,..,s_D} とする。翻訳先の隠れ状態s_iに対
して、翻訳元の影響因子をコンテキストc_iとする。
c_iは、h_jとその重みα_ijの積を、jの総和により計算できる(式3)。
この式3の計算が Soft Attentionが用いている手法である。
(1)
(2)
(3)
(4)
(5)
Kelvin Xu, etc 2015
53. © 2015 Metaps Inc. All Rights Reserved.
Deterministic “Soft” Attention、Hard attention が狭い注意モデルに
対して、“Soft” Attentionはもっと広い画像の位置をカバーしている。
機械翻訳で使用の注意モデルを適用する。
LSTMの出力ベクトルn_tは、n_tkiのように、t:時間スップ,k:単語,
i:部分画像indexのような要素に分解することができる。
与えられた画像から生成される単語kのnormalized weighted geometric mean
(NWGM)は上式のように計算することができる。
Deterministic “Soft” Attention
Kelvin Xu, etc 2015
54. © 2015 Metaps Inc. All Rights Reserved.
注意可能な全てのロケーションに対する期待値は、場所変数s_tをランダムに選択し
、予測contextベクトルE[^zt]を用いて、単純なフィードフォワード伝搬によって計算さ
れる。
つまり、Deterministic “Soft” Attentionは、注意ロケーション上の周辺尤度の近似で
計算される。
上の2式からNWGMは、以下の式のように近似することができる。
Deterministic “Soft” Attention
Kelvin Xu, etc 2015
55. © 2015 Metaps Inc. All Rights Reserved.
注意遷移系列の例。最右の画像に対して、単語の生成を行いながら、遷移する注意
対象に関連する部分画像を白く塗っている。
上の列が”soft attention” 下の列が”hard attention”に対応する。
Show, Attend and Tell: Neural Image Caption Generation
with Visual Attention
Kelvin Xu, etc 2015
56. © 2015 Metaps Inc. All Rights Reserved.
まとめ
• 従来のモデルに比べ、教師データの作成コストが
下がったにもかかわらず、精度が既存の手法と
比べて高い。
• RNNを用いることで、人の手で用意していた言語
モデルより、説明文の表現力が増える。
57. © 2015 Metaps Inc. All Rights Reserved.
参考文献
• Ali Farhadi, Mohsen Hejrati, Mohammad Amin Sadeghi, Peter Young, Cyrus
Rashtchian, Julia. Hockenmaier, and David Forsyth. Every picture tells a
story: Generating sentences from images. In ECCV. 2010.
• Andrea Frome, Greg S Corrado, Jon Shlens, Samy Bengio, Jeffrey Dean,
and Tomas Mikolov MarcAurelio Ranzato. Devise: A deep visual-semantic
embedding model. NIPS, 2013.
• Andrej Karpathy, Li Fei-Fei: Deep Visual-Semantic Alignments for
Generating Image Descriptions. CVPR 2015
• Girish Kulkarni, Visruth Premraj, Sagnik Dhar, Siming Li, Yejin Choi,
Alexander C Berg,and Tamara L Berg. Baby talk: Understanding and
generating simple image descriptions. IEEE TRANSACTIONS ON PATTERN
ANALYSIS AND MACHINE INTELLIGENCE, VOL. 35, NO. 12, DECEMBER 2013
• Junhua Mao, Wei Xu, Yi Yang, JiangWang, Alan Yuille. Deep captioning
with multimodal recurrent neural networks (m-rnn). arXiv:1412.6632,
December 2014.
• Kuznetsova, Polina, Vicente Ordonez, Tamara L. Berg, U. C. Hill, and Yejin
Choi. "Treetalk: Composition and compression of trees for image
descriptions.“ TACL (2014)
58. © 2015 Metaps Inc. All Rights Reserved.
参考文献
• Ilya Sutskever,Oriol Vinyals,Quoc V. Le. Sequence to sequence learning
with neural networks. In NIPS, pp. 3104–3112, 2014.
• Oriol Vinyals, Alexander Toshev, Samy Bengio, Dumitru Erhan. Show and
tell: A neural image caption generator. Computer Vision and Pattern
Recognition (2015)
• Ryan Kiros, Ruslan Salakhutdinov, Richard Zemel. Unifying Visual-
Semantic Embeddings with Multimodal Neural Language Models. TACL,
2015.
• Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean.
Distributed Representations of Words and Phrases and their
Compositionality. In Proceedings of NIPS, 2013.
• Xu, Kelvin, Ba, Jimmy, Kiros, Ryan, Cho, Kyunghyun, Courville, Aaron,
Salakhutdinov, Ruslan, Zemel, Richard, and Bengio, Yoshua. Show, attend
and tell: Neural image caption generation with visual attention.arXiv preprint
arXiv:1207.0580, 2015.