Upload
axel-santin
View
220
Download
0
Embed Size (px)
Citation preview
8/11/2019 iobasics
1/12
N o t e s o n t h e I n s i d e - O u t s i d e A l g o r i t h m
T o m a k e a g r a m m a r p r o b a b i l i s t i c , w e n e e d t o a s s i g n a p r o b a b i l i t y t o e a c h c o n t e x t - f r e e r e w r i t e
r u l e . B u t h o w s h o u l d t h e s e p r o b a b i l i t i e s b e c h o s e n ? I t i s n a t u r a l t o e x p e c t t h a t t h e s e p r o b a b i l i t i e s
s h o u l d d e p e n d i n s o m e w a y o n t h e d o m a i n t h a t i s b e i n g p a r s e d . J u s t a s a s i m p l e a p p r o a c h s u c h a s t h e
t r i g r a m m o d e l u s e d i n s p e e c h r e c o g n i t i o n i s \ t u n e d " t o a t r a i n i n g c o r p u s , w e w o u l d l i k e t o \ t u n e " o u r
r u l e p r o b a b i l i t i e s t o o u r d a t a . T h e s t a t i s t i c a l p r i n c i p l e o f m a x i m u m l i k e l i h o o d g u i d e s u s i n d e c i d i n g
h o w t o p r o c e e d . A c c o r d i n g t o t h i s p r i n c i p l e , w e s h o u l d c h o o s e o u r r u l e p r o b a b i l i t i e s s o a s t o m a x i m i z e
t h e l i k e l i h o o d o f o u r d a t a , w h e n e v e r t h i s i s p o s s i b l e . I n t h e s e n o t e s w e d e s c r i b e h o w t h i s p r i n c i p l e i s
r e a l i z e d i n t h e I n s i d e - O u t s i d e a l g o r i t h m f o r p a r a m e t e r e s t i m a t i o n o f c o n t e x t - f r e e g r a m m a r s .
L e t ' s b e g i n b y b e i n g c o n c r e t e , a n d c o n s i d e r i n g a n e x a m p l e o f a s i m p l e s e n t e n c e a n d s y n t a c t i c p a r s e .
anchovieswithoutpizzaeatsShe
F i g u r e 6 . 1
I m p l i c i t i n t h i s p a r s e a r e f o u r c o n t e x t - f r e e r u l e s o f t h e f o r m A ! B C . T h e s e a r e t h e r u l e s
S ! N V
V ! V N
N ! N P
P ! P P N
I n a d d i t i o n , t h e r e a r e v e \ l e x i c a l p r o d u c t i o n s " o f t h e f o r m A ! w
N ! S h e
V ! e a t s
N ! p i z z a
P P ! w i t h o u t
N ! a n c h o v i e s
1
8/11/2019 iobasics
2/12
O f c o u r s e , f r o m a p u r e l y s y n t a c t i c p o i n t - o f - v i e w , t h i s s e n t e n c e s h o u l d a l s o h a v e a v e r y d i e r e n t p a r s e .
T o s e e t h i s , j u s t c h a n g e t h e w o r d \ a n c h o v i e s " t o \ h e s i t a t i o n " :
hesitationwithoutpizzaeatsShe
F i g u r e 6 . 2
H e r e t w o n e w c o n t e x t - f r e e r u l e s h a v e b e e n u s e d :
V ! V N P
N ! h e s i t a t i o n
I n t h e a b s e n c e o f o t h e r c o n s t r a i n t s , b o t h p a r s e s a r e v a l i d f o r e a c h s e n t e n c e . T h a t i s , o n e c o u l d , a t l e a s t
s y n t a c t i c a l l y , s p e a k o f a t y p e o f \ p i z z a w i t h o u t h e s i t a t i o n , " t h o u g h t h i s w o u l d c e r t a i n l y b e s e m a n t i c
g i b b e r i s h , i f n o t c o m p l e t e l y w i t h o u t t a s t e . O n e o f t h e g o a l s o f p r o b a b i l i s t i c t r a i n i n g a n d p a r s i n g i s t o
e n a b l e t h e s t a t i s t i c s t o c o r r e c t l y d i s t i n g u i s h b e t w e e n s u c h s t r u c t u r e s f o r a g i v e n s e n t e n c e . T h i s i s i n d e e d
a f o r m i d a b l e p r o b l e m . T h r o u g h o u t t h i s c h a p t e r w e w i l l r e f e r t o t h e a b o v e s e n t e n c e s a n d g r a m m a r t o
d e m o n s t r a t e h o w t h e t r a i n i n g a l g o r i t h m i s a c t u a l l y c a r r i e d o u t . W h i l e c e r t a i n l y a \ t o y " e x a m p l e , i t
w i l l s e r v e t o i l l u s t r a t e t h e g e n e r a l a l g o r i t h m , a s w e l l a s t o d e m o n s t r a t e t h e s t r e n g t h s a n d w e a k n e s s e s o f
t h e a p p r o a c h .
L e t ' s n o w a s s u m e t h a t w e h a v e p r o b a b i l i t i e s a s s i g n e d t o e a c h o f t h e a b o v e c o n t e x t - f r e e r e w r i t e r u l e s .
T h e s e p r o b a b i l i t i e s w i l l b e w r i t t e n a s , f o r e x a m p l e ,
( S ! N V )
o r a s
( N ! p i z z a )
a n d w e c a l l t h e s e n u m b e r s t h e p a r a m e t e r s o f o u r p r o b a b i l i s t i c m o d e l . T h e o n l y r e q u i r e m e n t s o f t h e s e
n u m b e r s a r e t h a t t h e y b e n o n - n e g a t i v e , a n d t h a t f o r e a c h n o n t e r m i n a l A t h e y s u m t o o n e ; t h a t i s ,
X
( A ! ) = 1
f o r e a c h A , w h e r e t h e s u m i s o v e r a l l s t r i n g s o f w o r d s a n d n o n t e r m i n a l s t h a t t h e g r a m m a r a l l o w s t h e
s y m b o l A t o r e w r i t e a s . F o r o u r e x a m p l e g r a m m a r , t h i s r e q u i r e m e n t i s s p e l l e d o u t a s f o l l o w s :
( N ! N P ) + ( N ! p i z z a ) + ( N ! a n c h o v i e s ) +
+ ( N ! h e s i t a t i o n ) + ( N ! S h e ) = 1
( V ! V N ) + ( V ! V N P ) + ( V ! e a t s ) = 1
2
8/11/2019 iobasics
3/12
( S ! N V ) = 1
( P ! P P N ) = 1
( P P ! w i t h o u t ) = 1
S o , t h e o n l y p a r a m e t e r s t h a t a r e g o i n g t o b e t r a i n e d , a r e t h o s e a s s o c i a t e d w i t h r e w r i t i n g a n o u n N o r a
v e r b V ; a l l o t h e r s a r e c o n s t r a i n e d t o b e e q u a l t o o n e .
T h e I n s i d e - O u t s i d e a l g o r i t h m s t a r t s f r o m s o m e i n i t i a l s e t t i n g o f t h e p a r a m e t e r s , a n d i t e r a t i v e l y
a d j u s t s t h e m s o t h a t t h e l i k e l i h o o d o f t h e t r a i n i n g c o r p u s ( i n t h i s c a s e t h e t w o s e n t e n c e s \ S h e e a t s p i z z a
w i t h o u t a n c h o v i e s " a n d \ S h e e a t s p i z z a w i t h o u t h e s i t a t i o n " ) i n c r e a s e s . T o w r i t e d o w n t h e c o m p u t a t i o n
o f t h i s l i k e l i h o o d f o r o u r e x a m p l e , w e ' l l h a v e t o i n t r o d u c e a b i t o f n o t a t i o n . F i r s t , w e ' l l w r i t e
W
1
= \ S h e e a t s p i z z a w i t h o u t a n c h o v i e s "
a n d
W
2
= \ S h e e a t s p i z z a w i t h o u t h e s i t a t i o n "
A l s o , T
1
w i l l r e f e r t o t h e p a r s e i n F i g u r e 6 . 1 , a n d T
2
w i l l r e f e r t o t h e p a r s e i n F i g u r e 6 . 2 . T h e n t h e
s t a t i s t i c a l m o d e l a s s i g n s p r o b a b i l i t i e s t o t h e s e p a r s e s a s
P
( W
1
T
1
) = ( S ! N V ) ( V ! V N ) ( N ! N P )
( P ! P P N ) ( N ! S h e ) ( V ! e a t s )
( N ! p i z z a ) ( P P ! w i t h o u t ) ( N ! a n c h o v i e s )
a n d
P
( W
2
T
1
) = ( S ! N V ) ( V ! V N P ) ( P ! P P P )
( N ! S h e ) ( V ! e a t s ) ( N ! p i z z a )
( P P ! w i t h o u t ) ( N ! h e s i t a t i o n )
I n t h e a b s e n c e o f o t h e r r e s t r i c t i o n s , e a c h s e n t e n c e c a n h a v e b o t h p a r s e s . T h u s w e a l s o h a v e
P
( W
1
T
2
) = ( S ! N V ) ( V ! V N P ) ( P ! P P P )
( N ! S h e ) ( V ! e a t s ) ( N ! p i z z a )
( P P ! w i t h o u t ) ( N ! a n c h o v i e s )
a n d
P
( W
2
T
1
) = ( S ! N V ) ( V ! V N ) ( N ! N P )
( P ! P P N ) ( N ! S h e ) ( V ! e a t s )
( N ! p i z z a ) ( P P ! w i t h o u t ) ( N ! h e s i t a t i o n )
T h e l i k e l i h o o d o f o u r c o r p u s w i t h r e s p e c t t o t h e p a r a m e t e r s i s t h u s
L ( ) = ( P
( W
1
T
1
) + P
( W
1
T
2
) ) ( P
( W
2
T
1
) + P
( W
2
T
2
)
I n g e n e r a l , t h e p r o b a b i l i t y o f a s e n t e n c e W i s
P
( W ) =
X
T
P
( W T )
3
8/11/2019 iobasics
4/12
w h e r e t h e s u m i s o v e r a l l v a l i d p a r s e t r e e s t h a t t h e g r a m m a r a s s i g n s t o W , a n d i f o u r t r a i n i n g c o r p u s
c o m p r i s e s s e n t e n c e s W
1
W
2
; : : : ; W
N
, t h e n t h e l i k e l i h o o d L ( ) o f t h e c o r p u s i s g i v e n b y
L ( ) = P
( W
1
) P
( W
2
) P
( W
N
)
S t a r t i n g a t s o m e i n i t i a l p a r a m e t e r s , t h e i n s i d e - a l g o r i t h m r e e s t i m a t e s t h e p a r a m e t e r s t o o b t a i n n e w
p a r a m e t e r s f o r w h i c h L ( ) L ( ) . T h i s p r o c e s s i s r e p e a t e d u n t i l t h e l i k e l i h o o d h a s c o n v e r g e d .
S i n c e i t i s q u i t e p o s s i b l e t h a t s t a r t i n g w i t h a d i e r e n t i n i t i a l i z a t i o n o f t h e p a r a m e t e r s c o u l d l e a d t o a
s i g n i c a n t l y l a r g e r o r s m a l l e r l i k e l i h o o d i n t h e l i m i t , w e s a y t h a t t h e I n s i d e - O u t s i d e a l g o r i t h m \ l o c a l l y
m a x i m i z e s " t h e l i k e l i h o o d o f t h e t r a i n i n g d a t a .
T h e I n s i d e - O u t s i d e a l g o r i t h m i s a s p e c i a l c a s e o f t h e E M a l g o r i t h m 1 ] f o r m a x i m u m l i k e l i h o o d
e s t i m a t i o n o f \ h i d d e n " m o d e l s . H o w e v e r , i t i s b e y o n d t h e s c o p e o f t h e s e n o t e s t o d e s c r i b e i n d e t a i l h o w
t h e I n s i d e - O u t s i d e a l g o r i t h m d e r i v e s f r o m t h e E M a l g o r i t h m . I n s t e a d , w e w i l l s i m p l y p r o v i d e f o r m u l a s
f o r u p d a t i n g t h e p a r a m e t e r s , a s w e l l a s d e s c r i b e h o w t h e C Y K a l g o r i t h m i s u s e d t o a c t u a l l y c o m p u t e
t h o s e u p d a t e s . T h i s i s a l l t h a t i s n e e d e d t o i m p l e m e n t t h e t r a i n i n g a l g o r i t h m f o r y o u r f a v o r i t e g r a m m a r .
T h o s e r e a d e r s w h o a r e i n t e r e s t e d i n t h e a c t u a l m a t h e m a t i c s o f t h e I n s i d e - O u t s i d e a l g o r i t h m a r e r e f e r r e d
t o 3 ] .
0 . 1 T h e P a r a m e t e r U p d a t e s
I n t h i s s e c t i o n w e ' l l d e n e s o m e m o r e n o t a t i o n , a n d t h e n w r i t e d o w n t h e u p d a t e s f o r t h e p a r a m e t e r s .
T h i s w i l l b e r a t h e r g e n e r a l , a n d t h e f o r m u l a s m a y s e e m c o m p l e x , b u t i n t h e n e x t s e c t i o n w e w i l l g i v e a
d e t a i l e d d e s c r i p t i o n o f h o w t h e s e u p d a t e s a r e a c t u a l l y c o m p u t e d u s i n g o u r s a m p l e g r a m m a r .
T o w r i t e d o w n h o w t h e I n s i d e - O u t s i d e a l g o r i t h m u p d a t e s t h e p a r a m e t e r s , i t i s m o s t c o n v e n i e n t t o
a s s u m e t h a t t h e g r a m m a r i s i n C h o m s k y n o r m a l f o r m . I t s h o u l d b e e m p h a s i z e d , h o w e v e r , t h a t t h i s
i s o n l y a c o n v e n i e n c e . I n t h e f o l l o w i n g s e c t i o n w e w i l l w o r k t h r o u g h t h e I n s i d e - O u t s i d e a l g o r i t h m f o r
o u r t o y g r a m m a r , w h i c h i s n o t , i n f a c t , i n C h o m s k y n o r m a l f o r m . B u t w e ' l l a s s u m e h e r e t h a t w e h a v e
a g e n e r a l c o n t e x t - f r e e g r a m m a r G a l l o f w h o s e r u l e s a r e e i t h e r o f t h e f o r m A ! B C f o r n o n t e r m i n a l s
A B C , o r o f t h e f o r m ( A ! w ) f o r s o m e w o r d w .
S u p p o s e t h a t w e h a v e c h o s e n v a l u e s f o r o u r r u l e p r o b a b i l i t i e s . G i v e n t h e s e p r o b a b i l i t i e s a n d a
t r a i n i n g c o r p u s o f s e n t e n c e s W
1
W
2
; : : : ; W
N
, t h e p a r a m e t e r s a r e r e e s t i m a t e d t o o b t a i n n e w p a r a m e t e r s
a s f o l l o w s :
( A ! B C ) =
c o u n t ( A ! B C )
P
c o u n t ( A ! )
a n d
( A ! w ) =
c o u n t ( A ! w )
P
c o u n t ( A ! )
w h e r e
c o u n t ( A ! B C ) =
N
X
i = 1
c
( A ! B C W
i
)
a n d
c o u n t ( A ! w ) =
N
X
i = 1
c
( A ! w W
i
)
T h e n u m b e r c
( A ! W
i
) i s t h e e x p e c t e d n u m b e r o f t i m e s t h a t t h e r e w r i t e r u l e A ! i s u s e d
i n g e n e r a t i n g t h e s e n t e n c e W
i
w h e n t h e r u l e p r o b a b i l i t i e s a r e g i v e n b y . T o g i v e a f o r m u l a f o r t h e s e
e x p e c t e d c o u n t s , w e n e e d t w o m o r e p i e c e s o f n o t a t i o n . T h e r s t p i e c e o f n o t a t i o n i s s t a n d a r d i n t h e
4
8/11/2019 iobasics
5/12
a u t o m a t a l i t e r a t u r e ( s e e , f o r e x a m p l e , 2 ] ) . I f b e g i n n i n g w i t h a n o n t e r m i n a l A w e c a n d e r i v e a s t r i n g
o f w o r d s a n d n o n t e r m i n a l s b y a p p l y i n g a s e q u e n c e o f r e w r i t e r u l e s f r o m o u r g r a m m a r , t h e n w e w r i t e
A
)
a n d s a y t h a t A d e r i v e s . S o , i f a s e n t e n c e W = w
1
w
2
w
n
c a n b e p a r s e d b y t h e g r a m m a r w e c a n
w r i t e
S
) w
1
w
2
w
n
I n t h e n o t a t i o n u s e d a b o v e , t h e p r o b a b i l i t y o f t h e s e n t e n c e g i v e n o u r p r o b a b i l i s t i c g r a m m a r i s t h e n
P
( W ) =
X
T
P
( W T ) = P
( S
) w
1
w
2
w
n
)
T h e o t h e r p i e c e o f n o t a t i o n i s j u s t a s h o r t h a n d f o r c e r t a i n p r o b a b i l i t i e s . T h e p r o b a b i l i t y t h a t t h e
n o n t e r m i n a l A d e r i v e s t h e s t r i n g o f w o r d s w
i
w
j
i n t h e s e n t e n c e W = w
1
w
n
i s d e n o t e d b y
i j
( A )
T h a t i s ,
i j
( A ) = P
( A
) w
i
w
j
)
A l s o , w e s e t t h e p r o b a b i l i t y t h a t b e g i n n i n g w i t h t h e s t a r t s y m b o l S w e c a n d e r i v e t h e s t r i n g
w
1
w
i 1
A w
j + 1
w
n
e q u a l t o
i j
( A ) . T h a t i s ,
i j
( A ) = P
( S
) w
1
w
i 1
A w
j + 1
w
n
)
T h e a l p h a s a n d b e t a s a r e r e f e r r e d t o , r e s p e c t i v e l y , a s i n s i d e a n d o u t s i d e p r o b a b i l i t i e s .
W e a r e n a l l y r e a d y t o g i v e t h e f o r m u l a f o r c o m p u t i n g t h e e x p e c t e d c o u n t s . F o r a r u l e A ! B C , t h e
e x p e c t e d n u m b e r o f t i m e s t h a t t h e r u l e i s u s e d i n d e r i v i n g t h e s e n t e n c e W i s
c
( A ! B C W ) =
( A ! B C )
P
( W )
X
1 i j k n
i k
( A )
i j
( B )
j + 1 k
( C )
S i m i l a r l y , t h e e x p e c t e d n u m b e r o f t i m e s t h a t a l e x i c a l r u l e A ! w i s u s e d i n d e r i v i n g W i s g i v e n b y
c
( A ! w W ) =
( A ! w )
P
( W )
X
1 n
i i
( A )
T o a c t u a l l y c a r r y o u t t h e c o m p u t a t i o n , w e n e e d a n e c i e n t m e t h o d f o r c o m p u t i n g t h e ' s a n d ' s
F o r t u n a t e l y , t h e r e i s a n e c i e n t w a y o f c o m p u t i n g t h e s e , b a s e d u p o n t h e f o l l o w i n g r e c u r e n c e r e l a t i o n s .
I f w e s t i l l a s s u m e t h a t o u r g r a m m a r i s i n C h o m s k y n o r m a l f o r m , t h e n i t i s e a s y t o s e e t h a t t h e ' s m u s t
s a t i s f y
i j
( A ) =
X
B C
X
i k j
( A ! B C )
i k
( B )
k + 1 j
( C )
f o r i < j i f w e t a k e
i i
( A ) = ( A ! w
i
)
I n t u i t i v e l y , t h i s f o r m u l a s a y s t h a t t h e i n s i d e p r o b a b i l i t y
i j
( A ) i s c o m p u t e d a s a s u m o v e r a l l p o s s i b l e
w a y s o f d r a w i n g t h e f o l l o w i n g p i c t u r e :
5
8/11/2019 iobasics
6/12
i k k+1 j
F i g u r e 6 3
I n t h e s a m e w a y , i f t h e o u t s i d e p r o b a b i l i t i e s a r e i n i t i a l i z e d a s
1 n
( S ) = 1 a n d
1 n
( A ) = 0 f o r A 6= S
t h e n t h e ' s a r e g i v e n b y t h e f o l l o w i n g r e c u r s i v e e x p r e s s i o n :
i j
( A ) =
X
B C
X
1 k < i
( B ! C A )
k i 1
( C )
k j
( B ) +
+
X
B C
X
n k > j
( B ! A C )
j + 1 k
( C )
i k
( B )
A g a i n , t h e r s t p a i r o f s u m s c a n b e v i e w e d a s c o n s i d e r i n g a l l w a y s o f d r a w i n g t h e f o l l o w i n g p i c t u r e :
k i-1 i j
F i g u r e 6 4
T o g e t h e r w i t h t h e u p d a t e f o r m u l a s , t h e a b o v e r e c u r e n c e f o r m u l a s f o r m t h e c o r e o f t h e I n s i d e - O u t s i d e
a l g o r i t h m .
6
8/11/2019 iobasics
7/12
T o s u m m a r i z e , t h e I n s i d e - O u t s i d e a l g o r i t h m c o n s i s t s o f t h e f o l l o w i n g s t e p s . F i r s t , c h o s e s o m e i n i t i a l
p a r a m e t e r s a n d s e t a l l o f t h e c o u n t s c o u n t ( A ! ) t o z e r o . T h e n , f o r e a c h s e n t e n c e W
i
i n t h e t r a i n i n g
c o r p u s , c o m p u t e t h e i n s i d e p r o b a b i l i t i e s a n d t h e o u t s i d e p r o b a b i l i t i e s . T h e n c o m p u t e t h e e x p e c t e d
n u m b e r o f t i m e s t h a t e a c h r u l e A ! i s u s e d i n g e n e r a t i n g t h e s e n t e n c e W
i
. T h e s e a r e t h e n u m b e r s
c
( A ! W
i
) . F o r e a c h r u l e A ! a d d t h e n u m b e r c
( A ! W
i
) t o t h e t o t a l c o u n t c o u n t ( A ! )
a n d p r o c e e d t o t h e n e x t s e n t e n c e . A f t e r p r o c e s s i n g e a c h s e n t e n c e i n t h i s w a y , r e e s t i m a t e t h e p a r a m e t e r s
t o o b t a i n
( A ! ) =
c o u n t ( A ! )
P
c o u n t ( A ! )
T h e n , r e p e a t t h e p r o c e s s a l l o v e r a g a i n , s e t t i n g = , a n d c o m p u t i n g t h e e x p e c t e d c o u n t s w i t h r e s p e c t
t o t h e n e w p a r a m e t e r s .
H o w d o w e k n o w w h e n t o s t o p ? D u r i n g e a c h i t e r a t i o n , w e c o m p u t e t h e p r o b a b i l i t y
P
( W ) = P
( S
) w
1
w
n
) =
1 n
( S )
o f e a c h s e n t e n c e . T h i s e n a b l e s u s t o c o m p u t e t h e l i k e l i h o o d ,
L ( ) = P
( W
1
) P
( W
2
) P
( W
N
)
o r , b e t t e r y e t , t h e l o g l i k e l i h o o d
L L ( ) =
N
X
i = 1
l o g P
( W
i
)
T h e I n s i d e - O u t s i d e a l g o r i t h m i s g u a r a n t e e d n o t t o d e c r e a s e t h e l o g l i k e l i h o o d ; t h a t i s , L L ( ) ? L L ( )
0 . O n e m a y d e c i d e t o s t o p w h e n e v e r t h e c h a n g e i n l o g l i k e l i h o o d i s s u c i e n t l y s m a l l . I n o u r e x p e r i e n c e ,
t h i s i s t y p i c a l l y a f t e r o n l y a f e w i t e r a t i o n s f o r a l a r g e n a t u r a l l a n g u a g e g r a m m a r .
I n t h e n e x t s e c t i o n , w e w i l l r e t u r n t o o u r t o y e x a m p l e , a n d d e t a i l h o w t h e s e c a l c u l a t i o n s a r e a c t u a l l y
c a r r i e d o u t . W h e t h e r t h e g r a m m a r i s s m a l l o r l a r g e , f e a t u r e - b a s e d o r i n s t a n d a r d c o n t e x t - f r e e f o r m ,
t h e b a s i c c a l c u l a t i o n s a r e t h e s a m e , a n d a n u n d e r s t a n d i n g o f t h e m f o r t h e f o l l o w i n g e x a m p l e w i l l e n a b l e
y o u t o i m p l e m e n t t h e a l g o r i t h m f o r y o u r o w n g r a m m a r .
0 . 2 C a l c u l a t i o n o f t h e i n s i d e a n d o u t s i d e p r o b a b i l i t i e s
T h e a c t u a l i m p l e m e n t a t i o n o f t h e s e c o m p u t a t i o n s i s u s u a l l y c a r r i e d o u t w i t h t h e h e l p o f t h e C Y K
a l g o r i t h m 2 ] . T h i s i s a c u b i c r e c o g n i t i o n a l g o r i t h m , a n d i t p r o c e e d s a s f o l l o w s f o r o u r e x a m p l e p r o b a -
b i l i s t i c g r a m m a r . F i r s t , w e n e e d t o p u t t h e g r a m m a r i n t o C h o m s k y n o r m a l f o r m . I n f a c t , t h e r e i s o n l y
o n e a g r a n t r u l e , V ! V N P , w h i c h w e b r e a k u p i n t o t w o r u l e s N - P ! N P a n d V ! V N - P , i n t r o d u c i n g a
n e w n o n t e r m i n a l N - P . N o t i c e t h a t s i n c e t h e r e i s o n l y o n e N - P r u l e , t h e p a r a m e t e r ( N - P ! N P ) w i l l b e
c o n s t r a i n e d t o b e o n e , s o t h a t
( V ! V N - P ) ( N - P ! N P ) = ( V ! V N - P )
i s o u r e s t i m a t e f o r ( V ! V N P ) . W e n o w w a n t t o l l u p t h e C Y K c h a r t f o r o u r r s t s e n t e n c e , w h i c h i s
s h o w n b e l o w .
7
8/11/2019 iobasics
8/12
She
eats
pizza
without
anchovies
F i g u r e 6 5
T h e a l g o r i t h m p r o c e e d s b y l l i n g u p t h e b o x e s i n t h e o r d e r s h o w n i n t h e f o l l o w i n g p i c t u r e .
1 2 3 4 5
F i g u r e 6 . 6
T h e r s t s t e p i s t o l l t h e o u t e r m o s t d i a g o n a l . I n t o e a c h b o x i s e n t e r e d t h e n o n t e r m i n a l s w h i c h c a n
g e n e r a t e t h e w o r d a s s o c i a t e d w i t h t h a t b o x . T h e n t h e ' s f o r t h e n o n t e r m i n a l s w h i c h w e r e e n t e r e d a r e
i n i t i a l i z e d . T h u s , w e o b t a i n t h e c h a r t
8
8/11/2019 iobasics
9/12
She
eats
pizza
without
anchovies
F i g u r e 6 7
a n d w e w i l l h a v e c o m p u t e d t h e i n s i d e p r o b a b i l i t i e s
1 1
( N ) = ( N ! S h e )
2 2
( V ) = ( V ! e a t s )
3 3
( N ) = ( N ! p i z z a )
4 4
( P P ) = ( P P ! w i t h o u t )
5 5
( N ) = ( N ! a n c h o v i e s )
A l l o t h e r ' s a r e z e r o .
N o w i t h a p p e n e d i n t h i s c a s e t h a t e a c h b o x c o n t a i n s o n l y o n e n o n t e r m i n a l . I f , h o w e v e r , a b o x
c o n t a i n e d t w o o r m o r e n o n t e r m i n a l s , t h e n t h e f o r e a c h n o n t e r m i n a l w o u l d b e u p d a t e d . S u p p o s e , f o r
e x a m p l e , t h a t t h e w o r d \ a n c h o v i e s " w e r e r e p l a c e d b y \ m u s h r o o m s . " T h e n s i n c e \ m u s h r o o m s " c a n b e
e i t h e r a n o u n o r a v e r b , t h e b o t t o m p a r t o f t h e c h a r t w o u l d a p p e a r a s
without
mushrooms
F i g u r e 6 8
a n d w e w o u l d h a v e c o m p u t e d t h e i n s i d e p r o b a b i l i t i e s
5 5
( N ) = ( N ! m u s h r o o m s )
a n d
5 5
( V ) = ( V ! m u s h r o o m s )
I n g e n e r a l , t h e r u l e f o r l l i n g t h e b o x e s i s t h a t e a c h n o n t e r m i n a l i n b o x ( i j ) m u s t g e n e r a t e w o r d s
w
i
w
j
, w h e r e t h e b o x e s a r e i n d e x e d a s s h o w n i n t h e f o l l o w i n g p i c t u r e .
9
8/11/2019 iobasics
10/12
1 2 3 4 5
1
2
3
4
5
F i g u r e 6 9
I n t h i s g u r e , t h e s h a d e d b o x , w h i c h i s b o x ( 2 4 ) , s p a n s w o r d s w
2
w
3
w
4
T o r e t u r n n o w t o o u r e x a m p l e , w e p r o c e e d b y l l i n g t h e n e x t d i a g o n a l a n d u p d a t i n g t h e ' s , t o g e t :
She
eats
pizza
without
anchovies
F i g u r e 6 . 1 0
w i t h
1 2
( S ) = ( S ! N V )
1 1
( N )
2 2
( V )
2 3
( V ) = ( V ! V N )
2 2
( V )
3 3
( N )
4 5
( P ) = ( P ! P P N )
4 4
( P P )
5 5
( N )
W h e n w e n i s h l l i n g t h e c h a r t , w e w i l l h a v e
1 0
8/11/2019 iobasics
11/12
She
eats
pizza
without
anchovies
F i g u r e 6 . 1 1
w i t h , f o r e x a m p l e , i n s i d e p r o b a b i l i t i e s
2 5
( V ) = ( V ! V N )
2 2
( V )
3 5
( N ) +
+ ( V ! V N - P )
2 2
( V )
3 5
( N - P )
a n d
1 5
( S ) = ( S ! N V )
1 1
( N )
2 5
( V )
T h i s l a s t a l p h a i s t h e t o t a l p r o b a b i l i t y o f t h e s e n t e n c e :
1 5
( S ) = P
( S
) S h e e a t s a n c h o v i e s )
=
X
T
P
( S h e e a t s a n c h o v i e s T )
T h i s c o m p l e t e s t h e i n s i d e p a s s o f t h e I n s i d e - O u t s i d e a l g o r i t h m . N o w f o r t h e o u t s i d e p a s s . T h e
o u t s i d e p a s s p r o c e e d s i n t h e r e v e r s e o r d e r o f F i g u r e 6 . 6 .
W e i n i t i a l i z e t h e ' s b y s e t t i n g
1 5
( S ) = 1 a n d a l l o t h e r ' s e q u a l t o z e r o . T h e n
2 5
( V ) = ( S ! N V )
1 1
( N )
1 5
( S )
3 5
( N ) = ( V ! V N )
2 2
( V )
2 5
( V )
5 5
( N ) = ( P ! P P N )
4 4
( P P )
4 5
( P )
T h e ' s a r e c o m p u t e d i n a t o p - d o w n m a n n e r , r e t r a c i n g t h e s t e p s t h a t t h e i n s i d e p a s s t o o k . F o r a
g i v e n r u l e u s e d i n b u i l d i n g t h e t a b l e , t h e o u t s i d e p r o b a b i l i t y f o r e a c h c h i l d i s u p d a t e d u s i n g t h e o u t s i d e
p r o b a b i l i t y o f i t s p a r e n t , t o g e t h e r w i t h t h e i n s i d e p r o b a b i l i t y o f i t s s i b l i n g n o n t e r m i n a l .
N o w w e h a v e a l l t h e n e c e s s a r y i n g r e d i e n t s n e c e s s a r y t o c o m p u t e t h e c o u n t s . A s a n e x a m p l e o f h o w
t h e s e a r e c o m p u t e d , w e h a v e
c
( V ! V N W
1
) =
( V ! V N )
1 5
( S )
(
2 2
( V )
3 3
( N )
2 3
( V ) +
+
2 2
( V )
3 5
( N )
2 5
( V ) )
=
( V ! V N )
1 5
( S )
(
2 2
( V )
3 3
( N )
2 3
( V ) )
1 1
8/11/2019 iobasics
12/12
s i n c e
2 3
( V ) = 0 . A l s o ,
c
( V ! V N - P W
1
) =
( V ! V N - P )
1 5
( S )
(
2 2
( V )
3 5
( N - P )
2 5
( V ) )
W e n o w p r o c e e d t o t h e n e x t s e n t e n c e , \ S h e e a t s p i z z a w i t h o u t h e s i t a t i o n . " I n t h i s c a s e , t h e c o m p u -
t a t i o n p r o c e e d s e x a c t l y a s b e f o r e , e x c e p t , o f c o u r s e , t h a t a l l i n s i d e p r o b a b i l i t i e s i n v o l v i n g t h e p r o b a b i l i t y
( N ! a n c h o v i e s ) a r e r e p l a c e d b y t h e p r o b a b i l i t y ( N ! h e s i t a t i o n ) . W h e n w e a r e n i s h e d u p d a t i n g
t h e c o u n t s f o r t h i s s e n t e n c e , t h e p r o b a b i l i t i e s a r e r e c o m p u t e d a s , f o r e x a m p l e ,
( V ! V N ) =
c
( V ! V N W
1
) + c
( V ! V N W
2
)
P
i = 1 2
c
( V ! V N P W
i
) + c
( V ! e a t s W
i
) + c
( V ! V N W
i
)
( V ! e a t s ) =
c
( V ! e a t s W
1
) + c
( V ! e a t s W
2
)
P
i = 1 2
c
( V ! V N P W
i
) + c
( V ! e a t s W
i
) + c
( V ! V N W
i
)
T h o u g h w e h a v e d e s c r i b e d a n a l g o r i t h m f o r t r a i n i n g t h e g r a m m a r p r o b a b i l i t i e s , i t i s a s i m p l e m a t t e r
t o m o d i f y t h e a l g o r i t h m t o e x t r a c t t h e m o s t p r o b a b l e p a r s e f o r a g i v e n s e n t e n c e . F o r h i s t o r i c a l r e a s o n s ,
t h i s i s c a l l e d t h e V i t e r b i a l g o r i t h m , a n d t h e m o s t p r o b a b l e p a r s e i s c a l l e d t h e V i t e r b i p a r s e . B r i e y , t h e
a l g o r i t h m p r o c e e d s a s f o l l o w s . F o r e a c h n o n t e r m i n a l A a d d e d t o a b o x ( i j ) , i n t h e c h a r t , w e k e e p a
r e c o r d o f w h i c h i s t h e m o s t p r o b a b l e w a y o f r e w r i t i n g A . T h a t i s , w e d e t e r m i n e w h i c h n o n t e r m i n a l s B C
a n d i n d e x k m a x i m i z e t h e p r o b a b i l i t y
( A ! B C )
i k
( B )
k + 1 j
( C )
W h e n w e r e a c h t h e t o p m o s t n o n t e r m i n a l S , w e c a n t h e n \ t r a c e b a c k " t o c o n s t r u c t t h e V i t e r b i p a r s e .
W e s h a l l l e a v e t h e d e t a i l s o f t h i s a l g o r i t h m a s a n e x e r c i s e f o r t h e r e a d e r .
T h e c o m p u t a t i o n o u t l i n e d h e r e h a s m o s t o f t h e e s s e n t i a l f e a t u r e s o f t h e I n s i d e - O u t s i d e a l g o r i t h m
a p p l i e d t o a \ s e r i o u s " n a t u r a l l a n g u a g e g r a m m a r .
R e f e r e n c e s
1 ] A . P . D e m p s t e r , N . M . L a i r d , a n d D . B . R u b i n . M a x i m u m l i k e l i h o o d f r o m i n c o m p l e t e d a t a v i a t h e
E M a l g o r i t h m . J o u r n a l o f t h e R o y a l S t a t i s t i c a l S o c i e t y , 3 9 ( B ) : 1 { 3 8 , 1 9 7 7 .
2 ] J . E . H o p c r o f t a n d J . D . U l l m a n . I n t r o d u c t i o n t o A u t o m a t a T h e o r y , L a n g u a g e s , a n d C o m p u t a t i o n
A d d i s o n - W e s l e y , R e a d i n g , M a s s a c h u s e t t s , 1 9 7 9 .
3 ] J . D . L a e r t y . A d e r i v a t i o n o f t h e i n s i d e - o u t s i d e a l g o r i t h m f r o m t h e E M a l g o r i t h m . T e c h n i c a l r e p o r t ,
I B M R e s e a r c h , 1 9 9 2 .
1 2