This document discusses and compares several different probabilistic models for sequence labeling tasks, including Hidden Markov Models (HMMs), Maximum Entropy Markov Models (MEMMs), and Conditional Random Fields (CRFs).
It provides mathematical formulations of HMMs, describing how to calculate the most likely label sequence using the Viterbi algorithm. It then introduces MEMMs, which address some limitations of HMMs by incorporating arbitrary, overlapping features. CRFs are presented as an improvement over MEMMs that models the conditional probability of labels given observations, avoiding the label bias problem of MEMMs. The document concludes by describing how to train CRF models using generalized iterative scaling.
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationHidekazu Oiwa
?
Large-Scale Learning with Less RAM via Randomization proposes algorithms that reduce memory usage for machine learning models during training and prediction while maintaining prediction accuracy. It introduces a method called randomized rounding that represents model weights with fewer bits by randomly rounding values to the nearest representation. An algorithm is proposed that uses randomized rounding and adaptive learning rates on a per-coordinate basis, providing theoretical guarantees on regret bounds. Memory usage is reduced by 50% during training and 95% during prediction compared to standard floating point representation.
The document discusses the EM algorithm and K-means clustering. It begins by introducing mixture models and the EM algorithm for parameter estimation. It then describes the K-means clustering algorithm and how it can be viewed as a special case of EM. The document concludes by explaining how EM can be applied to Gaussian mixture models, deriving the E and M steps, and introducing the responsibilities that indicate cluster assignments.
6. 5.1 系列ラベリング概論
? チャンキング(chunking) [5.5章]
? 言語表現の意味的あるいは文法的にまとまった部分を発見する研究
? 名詞句の抽出や人名抽出などが挙げられる
“After stubbing out the cigarette, Lunvalet talked to me.”
人名
“Lunvalet”という人名が存在することを知らなくても、文脈から推測する
ことが出来る
? 複数語からなる表現が人を指していることもある
“Suddenly, the tall German guy talked to me.”
O B I I I O O O
人
B(人名開始単語),I(人名部),O(その他)のようにタグ付けがしたい
11. 5.2.1 HMMの導入
xとyの同時確率は、以下の式で導出できる
P (x, y ) = P ( xk , yk | xk ?1 , yk ?1 ) P( xk ?1 , yk ?1 | xk ? 2 , yk ? 2 )...P ( x1 , y1 | x0 , y0 )
= ∏ P ( xi , yi | xi ?1 , yi ?1 )
i
= ∏ P( xi | yi ) P( yi | yi ?1 )
i
簡単のため、ダミー要素(x0,y0)を用意し、以下の式を用いた
P( x1 , y1 ) = P( x1 , y1 | x0 , y0 )
P( y1 ) = P( y1 | y0 )
12. 5.2.2 パラメータ推定
訓練データ: D = {( x (1) , y (1) ),..., (x , y
(D) (D)
)} の最尤推定解を求めることで、パラ
メータP( x | y ), P( y | y ' ) を推定する
まず、対数尤度 log P( D) を下式のように表す
log P ( D ) = ∑ log P(x (i )
, y (i ) )
( x ( i ) , y ( i ) )∈D
? ?
= ∑ ? ∑ log P ( x j | y j ) + ∑ log P ( y j | y j ?1 ) ?
?
(i ) (i ) (i ) (i )
?
( x ( i ) , y ( i ) )∈D ? j j ?
= ∑ n(( x, y ), D) log P( x | y ) + ∑ n(( y ' , y ), D) log P( y | y ' )
x, y y, y'
= ∑ [データDで、xにラベルyが付与された回数] log p x| y
x, y
+ ∑ [データDで、ラベルy'の次にラベルyが出現した回数] log q y '| y
y ', y
13. 5.2.2 パラメータ推定
制約条件を考慮すると、最尤推定解は以下の問題を解くことで導出できる
max ∑ n(( x, y ), D) log p x| y + ∑ n(( y ' , y ), D) log q y| y '
x, y y, y'
s.t. ∑p
x
x| y =1 ∑p
y
y| y ' =1
ラグランジュ法を用いて、最大化するパラメータを求めると、以下の式になる
(演習問題1)
n(( x, y ), D)
p x| y =
∑ n(( x, y), D)
x
n(( y ' , y ), D)
q y| y ' =
∑ n(( y' , y), D)
x
要素とラベル、ラベルとラベルの組み合わせの出現頻度を
パラメータとしているだけなので、当たり前の結果
14. 5.2.3 HMMの推論
ある系列xが与えられたときの最適なラベル列yを求めたい
?この最適化問題を解きたい: y max = arg max P(x, y )
y
しかし、冒頭に述べたように、ラベル列の組み合わせ数が膨大なので、全て
列挙することは不可能
? Viterbi algorithm(ヴィタビアルゴリズム)
? 上の最適化問題を効率的に解くアルゴリズム
? 一種の動的計画法
? 先頭の要素から順番にラベルを付与していく
15. Viterbi algorithm Pseudocode(前半)
入力:系列x
for j=2 to |x|
for all yj
t ( j , y j ) = max[log P( x j , y j | x j ?1 , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
s ( j , y j ) = arg max[log P( x j , y j | x j ?1 , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
end for
全ての要素に対応する全てのラベルについて、どのラベル
end for から遷移する確率が高いかを比較する
t(j,yj):要素jに対応するラベルがyjをとる条件のもと、確率が最大となるラ
ベル列をとる確率。
s(j,yj):確率が最大となるラベルをとった場合のyj-1を保存。アルゴリズムの
後半で使用。
16. Viterbi algorithm Pseudocode(後半)
前半部のイメージ
最適なラベル列を探す
後半部
入力:t(|x|,y),s
y|max = arg max t (| x |, y )
x|
y
for j=|x|-1 to 1
y max = s ( j + 1, y max )
j j +1
end for 最適なラベル列を後ろ側の要素から順に、逆向きに取り出している
20. 5.4 条件付確率場(CRF)
? 条件付確率場(Conditional Random Field)
? CRFと呼ばれることが多い
? 様々な素性を用いることが出来、またラベル系列全体の確からしさにも
焦点を当てた学習を行えるモデル
? 4.5節の対数線形モデルを系列ラベリング問題へ適用したもの
訓練データ: D = {( x (1) , y (1) ),..., (x
(D) (D)
,y )} が与えられたとする
この時、ラベル列の系列に対する条件付き確率を以下のようにおく
1
P ( y | x) = exp(w ? Φ(x, y))
Z x,w
w : 素性に対する重みベクトル
? ?
Z x,w : 正規化係数? Z x, w =
? ∑ exp(w ? Φ(x, y)) ?
?
? y ?
21. 5.4.1 条件付確率場(CRF)の導入
最適なラベル列を求めたい。よって、以下の最大化問題を解く
1
y ? = arg max exp(w ? Φ(x, y))
y Z x,w
= arg max w ? Φ(x, y)
y
ただし、この最大化問題を解くのは非常に時間がかかるため、yは隣り合う
ラベルyt,yt-1にのみに依存するという条件をおく
φk (x, y ) = ∑ φk (x, yt , yt ?1 )
t
w ? Φ(x, y) = w ? ∑ φk (x, yt , yt ?1 )
t
= ∑ w ? φk (x, yt , yt ?1 )
t
y ? = arg max ∑ w ? φk (x, yt , yt ?1 )
y t
22. 5.4.1 条件付確率場(CRF)の導入
y ? = arg max ∑ w ? φk (x, yt , yt ?1 )
y t
上式ならば、wが分かっていればViterbi Algorithmで高速に解くことがで
きる
t ( j , y j ) = max[log P( x j , y j | x j ?1 , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
s ( j , y j ) = arg max[log P( x j , y j | x j ?1 , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
t ( j , y j ) = max[w ? Φ(x, y j , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
s ( j , y j ) = arg max[w ? Φ(x, y j , y j ?1 ) + t ( j ? 1, y j ?1 )]
y j ?1
モデルの拡張も容易に可能
φk (x, y ) = ∑ φk (x, yt , yt ?1 , yt ? 2 )
t
23. 5.4.2 条件付確率場(CRF)の学習
Wの学習方法
以下の目的関数を最大化する
L(w ) = ∑ log P(y | x) = ∑ w ? Φ(x, y) ? log Z
D D
x,w
実際は、正則化項を加えた目的
関数を最適化する場合が多い
L(w ) ? C | w | 2
しかし、上式は解析的に解くことが不可能
最急勾配法(1.2.2節)を用いる(準ニュートン法や確率的勾配法が用いられやすい)
w new = w old + ε? w L(w old )
? ?
? w L(w old
)= ∑ ? Φ ( x (i ) , y (i ) ) ?
? ∑ P ( y | x )Φ ( x , y ) ?
(i ) (i )
?
D ? y ?
系列ラベリングではyの組み合わせが膨大で、
P(y|x)が計算不可能
24. 5.4.2 条件付確率場(CRF)の学習
∑ P ( y | x )Φ ( x , y ) = ∑ P ( y | x )∑ Φ ( x , y , y )
y
(i ) (i )
y
(i )
t
(i )
t t ?1
= ∑ ∑ P( y , y
t yt , yt ?1
t t ?1 | x (i ) )Φ (x (i ) , yt , yt ?1 )
と変形することで、P( yt , yt ?1 | x (i ) ) が計算できればよい形となる
? t ( yt , yt ?1 ) = exp( w ? Φ (x, yt , yt ?1 ))とおけば、
? t ( yt , yt ?1 )
P ( y | x) = ∏ t
Z x,w
と書けるので、
P( yt , yt ?1 | x) = ∑ ∑ P ( y | x)
y 0:t ?2 y t +1:T +1
∑ ∑ ∏? ( y , y
1
= t' t' t '?1 )
Z x, w y 0:t ?2 y t +1:T +1 t'
? t ( yt , yt ?1 )
=
Z x, w ∑ ∑ ∏? ( y , y
y 0:t ?2 y t +1:T +1 t '≠ t
t' t' t '?1 )
25. 5.4.2 条件付確率場(CRF)の学習
∑ ∑ ∏? ( y , y )
y 0:t ?2 y t +1:T +1 t '≠ t
t' t' t '?1
? t ?1 ?? T +1 ? ? t ?
= ?
? ∑∏ ? t ' ( yt ' , yt '?1 ) ??
?? ∑∏ ? t ' ( yt ' , yt '?1 ) ?
?
α ( yt , t ) = ?
? ∑∏ ? t ' ( yt ' , yt '?1 ) ?
?
? y 0:t ?2 t '=1 ?? y t +1:T +1 t '=t +1 ? ? y 0:t ?2 t '=1 ?
= α ( yt ?1 , t ? 1) β ( yt , t ) ? T +1 ?
1
β ( yt , t ) = ?
? ∑∏ ? t ' ( yt ' , yt '?1 ) ?
?
P( yt , yt ?1 | x) = ? t ( yt , yt ?1 )α ( yt ?1 , t ? 1) β ( yt , t ) ? y t +1:T +1 t '=t +1 ?
Z x,w
上式が高速に計算できればよい
α ( yt , t ) = ∑? ( y , y t t t ?1 )α ( yt ?1 , t ? 1)
α β
yt ?1
β ( yt , t ) = ∑?
yt +1
t +1 ( yt +1 , yt ) β ( yt +1 , t + 1)
Z x,w = ∑α ( y
yT
T ,T ) を利用すれば、DPを用いて高速に計算可能になる
26. 5.4.2 条件付確率場(CRF)の学習
α ( yt , t ), β ( yt , t ) を利用したこのような算法は、前向き?後ろ向きアルゴリズム
(forward-backward algorithm)の一種
一般のCRFは、系列上のノードだけでなく、グラフ上のノードのラベリング問
題に適用可能(Ex.係り受け解析)