Conditional Random Fields:
Probabilistic Models
Pusan National University
AILAB.
Kim, Minho
Labeling Sequence Data Problem
•
•
•
•
X is a random variable over data sequences
Y is a random variable over label sequences
Yi is assumed to range over a finite label alphabet A
The problem:
– Learn how to give labels from a closed set Y to a data sequence
X
x3
x1
x2
X:
Birds
like
flowers
Y:
noun
verb
noun
y1
y2
y3
Generative Probabilistic Models
• Learning problem:
Choose Θ to maximize joint likelihood:
L(Θ)= Σ log pΘ (yi,xi)
• The goal: maximization of the joint
likelihood of training examples
y = argmax p*(y|x) = argmax p*(y,x)/p(x)
• Needs to enumerate all possible
observation sequences
Hidden Markov Model
• In a Hidden Markov Model (HMM) we do not observe the
sequence that the model passed through (X) but only
some probabilistic function of it (Y). Thus, it is a Markov
model with the addition of emission probabilities:
Bik = P(Yt = k|Xt = i)
POS Tagging in HMM
• Optimal sequence
P ' arg max Pr(P |W )
Pr(P ) Pr(W | P )
arg max
Pr(W )
arg max Pr(P ) Pr(W | P )
• Contextual probability
Pr(P )
Pr(P i | P i
i
1
Pr(P )
Pr(P i | P i
i
2 i1
• Lexical probability
)
P )
Pr(W | P ) (W i | P i )
i
POS Tagging in HMM
• Learning(Maximum Likelihood Estimation)
freq(P i1P i )
Pr(P i | P i1)
freq(P i1)
freq(P i2P i1P i )
Pr(P i | P i2P i1)
freq(P i2P i1)
freq(W i,P i )
Pr(W i | P i )
freq(P i )
HMM – why not?
• Advantages:
– Estimation very easy.
– Closed form solution
– The parameters can be estimated with
relatively high confidence from small samples
• But:
– The model represents all possible (x,y)
sequences and defines joint probability over
all possible observation and label sequences
needless effort
Discriminative Probabilistic Models
Generative
Discriminative
“Solve the problem you need to solve”:
The traditional approach inappropriately uses a
generative joint model in order to solve a conditional
problem in which the observations are given.
To classify we need p(y|x) – there’s no need to implicitly
approximate p(x).
Discriminative Models - Estimation
• Choose Θy to maximize conditional
likelihood:
L(Θy)= Σ log pΘy(yi|xi)
• Estimation usually doesn’t have closed
form
• Example – MinMI discriminative approach
(2nd week lecture)
Maximum Entropy Markov Model
• MEMM:
– a conditional model that represents the
probability of reaching a state given an
observation and the previous state
– These conditional probabilities are specified
by exponential models based on arbitrary
observation features
POS Tagging in MEMM
• Optimal sequence
P ' arg max
H
i
{W
i1
,W
Pr(p | h )
Pr(P i | H i )
i
W
i,
i1
,P i1 ,P i1}
Pr(h ,p )
p 'P Pr(h ,p ')
• Joint probability
k
Pr(h ,p ) jj
f (h ,p )
j1
fi(H i,P i ) {0,1}
MEMM: the Label bias problem
The Label Bias Problem: Solutions
• Determinization of the Finite State
Machine
Not always possible
May lead to combinatorial explosion
• Start with a fully connected model and let
the training procedure to find a good
structure
Prior structural knowledge has proven to be
valuable in information extraction tasks
Random Field Model: Definition
• Let G = (V, E) be a finite graph, and let A be a
finite alphabet.
• The configuration space Ω is the set of all
labelings of the vertices in V by letters in A. If
C is a part of V and ω is an element of Ω is a
configuration, the ωc denotes the configuration
restricted to C.
• A random field on G is a probability distribution
on Ω.
Random Field Model: The Problem
• Assume that a finite number of features can
define a class
• The features fi(w) are given and fixed.
• The goal: estimating λ to maximize likelihood for
training examples
Conditional Random Field:
Definition
• X – random variable over data sequences
• Y - random variable over label sequences
• Yi is assumed to range over a finite label
alphabet A
• Discriminative approach: we construct a
conditional model p(y|x) and do not
explicitly model marginal p(x)
CRF - Definition
• Let G = (V, E) be a finite graph, and let A be a
finite alphabet
• Y is indexed by the vertices of G
• Then (X,Y) is a conditional random field if the
random variables Yv, conditioned on X, obey the
Markov property with respect to the graph:
p(Y|X,Yw,w≠v) = p(Yv|X,Yw,w~v),
where w~v means that w and v are neighbors in
G
CRF on Simple Chain Graph
• We will handle the case when G is a simple
chain: G = (V = {1,…,m}, E={ (I,i+1) })
HMM (Generative)
MEMM (Discriminative)
CRF
Fundamental Theorem of Random
Fields (Hammersley & Clifford)
• Assumption:
– G structure is a tree, of which simple chain is
a private case
CRF – the Learning Problem
• Assumption: the features fk and gk are
given and fixed.
– For example, a boolean feature gk is TRUE if
the word Xi is upper case and the label Yi is a
“noun”.
• The learning problem
– We need to determine the parameters
Θ = (λ1, λ2, . . . ; µ1, µ2, . . .) from training data
D = {(x(i), y(i))} with empirical distribution
p~(x, y).
최대 엔트로피 모델
• 우리가 알아낸 제약 조건을 다 만족하는
확률 분포들 중에서 엔트로피가 최대가
되는 확률 분포를 취함
• 알고 있는 정보는 반영하되, 확실하지 않은
경우에 대해서는 불확실성 정도를 최대로
두어 균일한 확률 분포를 구성
제약조건
p(dans) p(en) p(a) p(aucoursde) p( pendant ) 1
엔트로피를 최대로 하는 확률 분포
p(dans) 1/ 5, p(en) 1/ 5, p(a) 1/ 5, p(aucoursde) 1/ 5, p( pendant ) 1/215
최대 엔트로피 원리
• 제약조건을 만족하는 확률 분포들 중
엔트로피가 최대가 되도록 모델을 구성
• 알려진 또는 사용하고자 하는 정보에 대해
확실히 지켜주고, 고려하지 않은 경우나
모르는 경우에 대해서는 동등하게
가중치를 줌으로써 특정 부분에 치우치지
않는 분포를 구한다
H ( p)
Ref. [1]
xX , yY
p( x, y) log p( x, y)
22
최대 엔트로피 예
• 이벤트 공간
NN
NNS
NNP
NNPS
VBZ
VBD
13
3
1
• 경험적 데이터
3
5
11
• 엔트로피를 최대로 하는 확률 분포
– 제약조건: E[NN, NNS, NNP, NNPS, VBZ,
Ref. [3] VBD]=1
23
최대 엔트로피 예
– N*이 V*보다 더 빈번하게 발생, 이를 자질
함수로 추가
f N {NN , NNS , NNP, NNPS}, E{ f N } 32 / 36
NN
NNS
NNP
NNPS
VBZ
VBD
8/36
8/36
8/36
8/36
2/36
2/36
f P { NNP, NNPS}, E{ f p } 24 / 36
4/36
4/36
12/36 12/36
2/36
2/36
– 고유명사가 보통명사보다 더 빈번하게 발생
24
최대 엔트로피 모델 구성 요소
• 자질 함수
– 정해놓은 조건들을 만족하는지 여부를 확인
– 일반적으로 이진 함수로 정의
• 제약조건
– 기대치를 구할 때 사용하는 정보는 학습문서로 한정
• 파라미터 추정 알고리즘
– 자질 함수의 가중치를 구하는 방법
– GIS, IIS
25
최대 엔트로피 모델에서 확률
계산 방법
• 자질 함수를 정의
• 제약조건을 정의
• 선택한 알고리즘을 이용해 자질 함수의
가중치 계산
• 가중치를 이용해 각각의 확률 계산
• 여러 확률 값 중 제일 큰 값을 최종확률로
선택
26
자질 함수
• Trigger 형태로, 정해놓은 제약조건을
만족하였는지 여부를 구분해주는 함수
• 고려되고 있는 문맥에 사용하고자 하는
정보들이 적용가능한지 결정
1 if h meets some condition
f ( h)
0 otherwise
Ref. [1]
27
제약조건
E[ f j ] E[ f j ], 1 j k ,
E[ f j ]
hH , yY
p 1
n
p (h, y ) f j (h, y ) p(hi ) p ( yi | hi ) f j (hi , yi ) , p(hi ) : 학습 문서에서 뽑아낸 값
i 1
H : 제대로 알기 어려우며, 안다고 해도 너무 커서 평균값을 바로 구하는 것이 힘들 수 있다.
학습 문서에서 발견된 경우만 고려하는 근사화 된 수식을 이용하여 계산
n
E[ f j ] p (hi , yi ) f j (hi , yi )
i 1
p(hi , yi ) : 학습 문서에서 얻어낸 것
H , Y : 각각 있을 수 있는 모든 문맥과 원하는 출력값의 집합
n: 학습 문서에서 발견된 문맥 h와 y의 곱집합으로 얻을 수 있는 총 가지수
모델에서 고려하는 경우의 수
Ref. [1]
28
파라미터 추정
• 정해진 자질 함수를 학습 문서에 적용시켜 얻어낸 확률
정보를 가장 잘 반영하는 p*를 최우추정법(Maximum
Likelihood Estimation) 사용하여 구한다
P { p | E[ f j ] E[ f j ], j {1,....., k}}
k
1 k f j ( x, y )
f j ( x, y )
Q { p | p( y | x)
,
Z
(
x
)
y
j
j
Z ( x) j 1
j 1
L( p ) p ( x, y ) log p ( y | x)
x, y
p* arg max L( q) arg max H ( p)
qQ
pP
where
p ( x, y ) : 학습 문서에서 얻어낸 확률값
k: 자질 함수의 개수
Ref. [1]
j : 자질 함수 f j 에 해당하는 가중치
29
IIS (Improved Iterative Scaling)
입력 데이터
자질 f1 , f 2 ,...., f n
출력 데이터
파라미터 i* , 확률분포 p *
알고리즘
1. i 0, i {1, 2,...., n}
2. 각 i에 대해서
a.
p( x) p( y| x) f ( x, y) exp( f
i
i
#
( x, y )) p ( f i )를 만족하는 i 를 구한다.
x, y
n
단, f ( x, y ) f i ( x, y ).
#
i 1
b. i : i i i .
3. i 가 수렴하면 끝을 내고 그렇지 않을 경우 2. 로 간다.
Ref. [1]
30
GIS (General Iterative Scaling)
K
def
C max fi ( x, y )
x, y
i 1
K
f K 1 ( x, y ) C f i ( x, y )
i 1
E p fi p ( x, y ) f i ( x, y ) : 모든가능한 x, y에 대한 이벤트 공간에서의 합
x, y
1 N
Ep fi p( x, y ) f i ( x, y ) f i ( x j , y j ) : 경험적 기대값
N j 1
x ,, y
wher e
N: 학습문서에 있는 요소들의 수
모든 가능한 x,y의 결합의 합을 구하는 것은 데이타 집합이 크거나 무한하기 때문에 어렵다.
따라서, E p fi 를 학습 문서에 나타난 x로 근사화한다.
1 N
E p fi p ( x) p ( y | x) f i ( x, y ) p ( y j | x j ) f i ( x j , y j )
N j 1 y
x, y
Ref. [2]
31
GIS (General Iterative Scaling)
1. i(1)의 초기값을 설정한다. 보통 i(1) 1, 1 j K 1
E p fi 를 계산하고, n=1로 설정
2. 주어진 { i(1) }를 가지고, 학습문서에 있는 각 요소 ( x, y) 에 대해 p( n) ( x, y)를 계산한다.
K 1
1 K 1 (1) fi ( x , y )
p ( x, y ) ( i )
where z ( i(1) ) fi ( x , y )
Z i 1
x , y i 1
( n)
3. 모든 1 i K 1 에 대하여 E p( n ) fi 를 구한다.
4. 파라미터 i 를 업데이트한다.
( n 1)
i
(n)
i
(
E p fi
E p( n ) f i
)
1
C
5. 파라미터 값이 수렴하면 멈추고, 그렇지 않으면 n을 하나 증가시키고 2. 로 간다.
Ref. [2]
32
Conclusions
• Conditional random fields offer a unique combination of
properties:
– discriminatively trained models for sequence segmentation and
labeling
– combination of arbitrary and overlapping observation features
from both the past and future
– efficient training and decoding based on dynamic programming
for a simple chain graph
– parameter estimation guaranteed to find the global optimum
• CRFs main current limitation is the slow convergence of
the training algorithm relative to MEMMs, let alone to
HMMs, for which training on fully observed data is very
efficient.
© Copyright 2026 Paperzz