Machine Learning for natural language processing

Similar documents
Lecture 3: ASR: HMMs, Forward, Viterbi

CS 136a Lecture 7 Speech Recognition Architecture: Training models with the Forward backward algorithm

Sequence labeling. Taking collective a set of interrelated instances x 1,, x T and jointly labeling them

Hidden Markov Models The three basic HMM problems (note: change in notation) Mitch Marcus CSE 391

Machine Learning for natural language processing

Hidden Markov Model. Ying Wu. Electrical Engineering and Computer Science Northwestern University Evanston, IL 60208

Lecture 11: Hidden Markov Models

CMSC 723: Computational Linguistics I Session #5 Hidden Markov Models. The ischool University of Maryland. Wednesday, September 30, 2009

Part of Speech Tagging: Viterbi, Forward, Backward, Forward- Backward, Baum-Welch. COMP-599 Oct 1, 2015

Multiscale Systems Engineering Research Group

CISC 889 Bioinformatics (Spring 2004) Hidden Markov Models (II)

Data-Intensive Computing with MapReduce

Basic math for biology

Statistical Methods for NLP

Recap: HMM. ANLP Lecture 9: Algorithms for HMMs. More general notation. Recap: HMM. Elements of HMM: Sharon Goldwater 4 Oct 2018.

Sequence Labeling: HMMs & Structured Perceptron

Dept. of Linguistics, Indiana University Fall 2009

Dynamic Programming: Hidden Markov Models

STA 414/2104: Machine Learning

Hidden Markov Models and Gaussian Mixture Models

Hidden Markov Models

Lecture 12: Algorithms for HMMs

HMM: Parameter Estimation

Lecture 12: Algorithms for HMMs

We Live in Exciting Times. CSCI-567: Machine Learning (Spring 2019) Outline. Outline. ACM (an international computing research society) has named

Hidden Markov Modelling

Hidden Markov Models

ACS Introduction to NLP Lecture 2: Part of Speech (POS) Tagging

Machine Learning for natural language processing

8: Hidden Markov Models

order is number of previous outputs

Lab 3: Practical Hidden Markov Models (HMM)

Statistical NLP: Hidden Markov Models. Updated 12/15

Hidden Markov Models. Aarti Singh Slides courtesy: Eric Xing. Machine Learning / Nov 8, 2010

CS838-1 Advanced NLP: Hidden Markov Models

More on HMMs and other sequence models. Intro to NLP - ETHZ - 18/03/2013

Automatic Speech Recognition (CS753)

STA 4273H: Statistical Machine Learning

Hidden Markov Models. By Parisa Abedi. Slides courtesy: Eric Xing

Introduction to Machine Learning CMU-10701

Machine Learning for natural language processing

CHAPTER. Speech and Language Processing. Daniel Jurafsky & James H. Martin. Copyright c All rights reserved. Draft of August 7, 2017.

Statistical Processing of Natural Language

Hidden Markov Models and Gaussian Mixture Models

Data Mining in Bioinformatics HMM

Empirical Methods in Natural Language Processing Lecture 11 Part-of-speech tagging and HMMs

Statistical Methods for NLP

Hidden Markov Models

Basic Text Analysis. Hidden Markov Models. Joakim Nivre. Uppsala University Department of Linguistics and Philology

Machine Learning for natural language processing

Hidden Markov Models

Lecture 9: Hidden Markov Model

Hidden Markov Models Part 2: Algorithms

Machine Learning & Data Mining Caltech CS/CNS/EE 155 Hidden Markov Models Last Updated: Feb 7th, 2017

Parametric Models Part III: Hidden Markov Models

1. Markov models. 1.1 Markov-chain

Sequence Modelling with Features: Linear-Chain Conditional Random Fields. COMP-599 Oct 6, 2015

Statistical Machine Learning from Data

8: Hidden Markov Models

O 3 O 4 O 5. q 3. q 4. Transition

Hidden Markov Model and Speech Recognition

A Higher-Order Interactive Hidden Markov Model and Its Applications Wai-Ki Ching Department of Mathematics The University of Hong Kong

CSC401/2511 Spring CSC401/2511 Natural Language Computing Spring 2019 Lecture 5 Frank Rudzicz and Chloé Pou-Prom University of Toronto

10. Hidden Markov Models (HMM) for Speech Processing. (some slides taken from Glass and Zue course)

Log-Linear Models, MEMMs, and CRFs

Automatic Speech Recognition (CS753)

Computational Genomics and Molecular Biology, Fall

Natural Language Processing Prof. Pushpak Bhattacharyya Department of Computer Science & Engineering, Indian Institute of Technology, Bombay

Hidden Markov Models NIKOLAY YAKOVETS

Statistical NLP for the Web Log Linear Models, MEMM, Conditional Random Fields

Advanced Data Science

Hidden Markov Models

Hidden Markov Models (I)

Supervised Learning Hidden Markov Models. Some of these slides were inspired by the tutorials of Andrew Moore

Lecture 13: Structured Prediction

COMP90051 Statistical Machine Learning

A gentle introduction to Hidden Markov Models

Fun with weighted FSTs

An Introduction to Bioinformatics Algorithms Hidden Markov Models

Hidden Markov Models in Language Processing

VL Algorithmen und Datenstrukturen für Bioinformatik ( ) WS15/2016 Woche 16

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Hidden Markov Models

CS1820 Notes. hgupta1, kjline, smechery. April 3-April 5. output: plausible Ancestral Recombination Graph (ARG)

Hidden Markov Models. Three classic HMM problems

Hidden Markov Models

Statistical methods in NLP, lecture 7 Tagging and parsing

Expectation Maximization (EM)

Hidden Markov Models

Text Mining. March 3, March 3, / 49

Learning from Sequential and Time-Series Data

Conditional Random Field

An Introduction to Bioinformatics Algorithms Hidden Markov Models

Lecture 4: Hidden Markov Models: An Introduction to Dynamic Decision Making. November 11, 2010

Hidden Markov Models: Maxing and Summing

Directed Probabilistic Graphical Models CMSC 678 UMBC

Automatic Speech Recognition (CS753)

Lecture 11: Viterbi and Forward Algorithms

Hidden Markov Models. x 1 x 2 x 3 x N

Hidden Markov Models Hamid R. Rabiee

Lecture 12: EM Algorithm

Transcription:

Machine Learning for natural language processing Hidden Markov Models Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2016 1 / 33

Introduction So far, we have classified texts/observations independent from the class of the previous text/observation Today: sequence classifier, assigning a sequence of classes to a sequence of observations Jurafsky & Martin (2015), chapter 8 2 / 33

Table of contents 1 Motivation 2 Hidden Markov Models 3 Likelihood computation 4 Decoding 5 Training 3 / 33

Motivation Hidden Markov Models (HMMs) are weighted finite state automata with states emitting outputs. Transitions and emissions are weighted. 4 / 33

Motivation HMM start 0.1 0.9 q a 0.1 q b 0.9 0.1 0.9 end in q a, a is emitted with probability 0.9; in q a, b is emitted with probability 0.1; in q b, b is emitted with probability 0.9; in q b, a is emitted with probability 0.1; Given a sequence bb, what is the most probable path traversed by the automaton, resulting in this output? The states in the automaton correspond to classes, i.e., the search for the most probable path amounts to the search for the most probable class sequence. Example POS Tagging: the classes are POS tags, the emissions are words 5 / 33

Hidden Markov Models A Markov chain is a weighted automaton in which weights are probabilities, i.e., all weights are between 0 and 1 and the sum of the weights of all outgoing edges of a state is 1, and the input sequence uniquely determines the states the automaton goes through. A Markov chain is actually a bigram language model. Markov Chain for LM example slide 9 start 1 3 2 3 1 2 Sam 1 2 1 2 2 3 am end I... 1 3 6 / 33

Hidden Markov Models Markov chains are useful when we want to compute the probability for a sequence of events that we can observe. Hidden Markov Models compute probabilities for a sequence of hidden events, given a sequence of observed events. Example from Jurafsky & Martin (2015), after Eisner (2002) HMM for inferring weather (hot = H, cold = C) from numbers of ice creams eaten by Jason. start 0.2 0.1 0.6 0.5 0.3 end 0.8 H 0.4 C 0.1 P(1 H) = 0.2 P(2 H) = 0.4 P(3 H) = 0.4 P(1 C) = 0.5 P(2 C) = 0.4 P(3 C) = 0.1 7 / 33

Hidden Markov Models HMM A HMM is a tuple Q, A, O, B, q 0, q F, with Q = {q 1,..., q N } a finite set of states; A a Q Q matrix, the transition probability matrix, with 0 a ij 1 for all 1 i Q, 1 j Q. O a finite set of observations; a sequence B of Q functions b i O R, the emission probabilities with o O b i (o) = 1 for all 1 i Q q 0, q F Q are special start and end states, associated with transition probabilities a 0i and a if (0 a 0i, a if 1) for all 1 i Q. For all i, 0 i Q, it holds that Q j=1 a ij + a if = 1. 8 / 33

Hidden Markov Models First order HMMs make the following simplifying assumptions: 1 Markov assumption: In a sequence of states q i1... q in, we assume P(q in q i1... q in 1 ) = P(q in q in 1 )(= a in 1in ) 2 Output independence: In a sequence of states q i1... q in with the associated output sequence o i1... o in, we assume P(o ij q i1... q ij... q in 1, o i1... o ij... o in 1 ) = P(o ij q ij )(= b ij(o ij ) 9 / 33

Hidden Markov Models The following three fundamental problems have to be solved: 1 Likelihood: Given an HMM and an observation sequence, determine the likelihood of the observation sequence. 2 Decoding: Given an HMM and an observation sequence, discover the best hidden state sequence leading to these observations. 3 Learning: Given the set of states of an HMM and an observation sequence, learn the HMM parameters A and B. 10 / 33

Likelihood computation Given an HMM and an observation o = o 1... o n, determine the likelihood of the observation sequence o. For a specific state sequence q = q 1... q n Q n, we have P(o, q) = P(o q)p(q) and with our independence assumptions P(o, q) = n i=1 P(o i q i ) n i=1 P(q i q i 1 ) For the probability of o, we have to sum over all possible state sequences: P(o) = n q Q n i=1 P(o i q i ) n i=1 P(q i q i 1 )P(q F q n ) 11 / 33

Likelihood computation Computing each element of the sum independently from the others would lead to an exponential time complexity. Instead, we adopt the forward algorithm that implements some dynamic programming. Idea: We fill a n Q matrix α such that α ij = P(o 1... o i, q i = q j ) Forward algorithm 1 α 1j = a 0j b j (o 1 ) for 1 j Q 2 α ij = Q k=1 α i 1ka kj b j (o i ) for 1 i n and 1 j Q 3 P(o) = Q k=1 α nka kf 12 / 33

Likelihood computation Ice cream weather example continued P(1 H) = 0.2 P(2 H) = 0.4 P(3 H) = 0.4 P(313): start 0.8 0.2 0.1 0.6 0.5 0.3 H H 0.32 3.92 10 2 1.79 10 2 C 2 10 2 5.3 10 2 3.81 10 3 3 1 3 P(313) =2.17 10 3 0.4 C 0.1 end P(1 C) = 0.5 P(2 C) = 0.4 P(3 C) = 0.1 α 1j = a 0j b j (o 1 ) α ij = Q k=1 α i 1ka kj b j (o i ) P(o) = Q k=1 α nka kf 13 / 33

Likelihood computation Alternatively, we can also compute the backward probability β. For a given observation o i in our observation sequence, the forward probability considers the part from o 1 to o i while the backward probability considers the part from o i+1 to o n. Idea: We fill a n Q matrix β such that β ij = P(o i+1... o n, q i = q j ) Backward algorithm 1 β nj = a jf for 1 j Q 2 β ij = Q k=1 β i+1ka jk b k (o i+1 ) for 1 i < n and 1 j Q 3 P(o) = Q k=1 a 0kb k (o 1 )β 1k 14 / 33

Likelihood computation Ice cream weather example continued start 0.8 0.2 0.1 0.6 0.5 0.3 0.1 end P(1 H) = 0.2 P(2 H) = 0.4 P(3 H) = 0.4 H 0.4 C P(1 C) = 0.5 P(2 C) = 0.4 P(3 C) = 0.1 observed sequence 313: H 6.38 10 3 2.7 10 2 0.1 C 7.4 10 3 2.1 10 2 0.1 3 1 3 β nj = a jf β ij = Q k=1 β i+1ka jk b k (o i+1 ) P(o) = Q k=1 a 0kb k (o 1 )β 1k P(313) = 2.17 10 3 15 / 33

Decoding Given an HMM and an observation o = o 1... o n, determine the most probable state sequence q = q 1... q n Q n for o. arg max q Q n P(o, q) = arg max q Q n and with our independence assumptions arg max q Q n P(o, q) = arg max q Q n n i=1 P(o q)p(q) P(o i q i ) n i=1 P(q i q i 1 ) 16 / 33

Decoding For the computation, we use the viterbi algorithm, which is very similar to the forward algorithm except that, instead of computing sums, we compute maxs. We fill a n Q matrix v such that v ij = max q Q i 1 P(o 1... o i, q 1... q i 1, q i = q j ) Viterbi algorithm 1 v 1j = a 0j b j (o 1 ) for 1 j Q 2 v ij = max 1 k Q v i 1k a kj b j (o i ) for 1 i n and 1 j Q 3 max q Q n P(o, q) = max 1 k Q v nk a kf In addition, in order to retreive the best state sequence, each entry v ij is equipped with a backpointer to the state that has lead to the maximum. 17 / 33

Decoding Ice cream weather example continued P(1 H) = 0.2 P(2 H) = 0.4 P(3 H) = 0.4 start 0.8 output sequence 313: 0.2 0.1 0.6 0.5 0.3 H 0.4 C 0.1 end P(1 C) = 0.5 P(2 C) = 0.4 P(3 C) = 0.1 H 32 10 2, start 384 10 4, H 9216 10 6, H C 2 10 2, start 480 10 4, H 24 10 4, C 3 1 3 v 1j = a 0j b j (o 1 ) for 1 j Q v ij = max 1 k Q v i 1k a kj b j (o i ) for 1 i n and 1 j Q max q Q n P(o, q) = max 1 k Q v nk a kf most probable weather sequence is HHH with probability 9216 10 7 18 / 33

Training Supervised HMM Training: Given a sequence of observations o and a corresponding sequence of states q, learn the parameters A and B of an HMM. MLE via the counts of q i q j sequences and of pairs q i, o j of states and observations in our training data, eventually with some smoothing. More challenging: Unsupervised HMM Training: Given an observation sequence o and a state set Q, estimate A and B. Example ice cream weather case: we have a sequence of observations o {1, 2, 3} n and we know that the possible states are Q = {H, C}. POS tagging: we have a sequence of words o {w 1, w 2,..., w V } n and we know that the possible POS tags (= states) are Q = {NN, NNS, VBD, IN,... }. Task: estimate A and B of the corresponding HMMs. 19 / 33

Training We use the forward-backward or Baum-Welch algorithm (Baum, 1972), a special case of the EM algorithm (Dempster et al., 1977). Underlying ideas: We estimate parameters iteratively: we start with some parameters and use the estimated probabilities to derive better and better parameters. We get our estimates by computing forward probabilities and then dividing the probability mass among all the different state sequences that have contributed to a forward probability. Put differently, in each iteration loop, we count all possible state sequences for the given observation sequence. But, instead of counting each of them once, we use their probabilities according to the most recent parameters as counts. We perform some kind of frequency-based MLE with these weighted or fractional counts. 20 / 33

Training We start with some initial A and B. In each iteration, new parameter â ij and ˆb i (o) are computed. Intuition: and â ij = expected number of transitions from state i to state j expected number of transitions from state i ˆbi (o) = expected number of times in i observing symbol o expected number of times in state i 21 / 33

Training More precisely, instead of the expected numbers, we use the probabilities according to the last parameters A and B and according to the counts we retreive from the observation sequence o: and â ij = probability of transitions from i to j, given o probability of transitions from state i, given o ˆbi (o) = probability of emitting o in i, given o probability of passing through state i, given o 22 / 33

Training For â ij, we first calculate the probability of being in state i at time t (observation o t ) and in state j at time t + 1, with the observation sequence given. This is a product of the probability of being in i at step t after having emitted o 1... o t, which is the forward probability α ti ; the probability of the transition from i to j, which is a ij ; the probability of emitting o t+1 in j, which is b j (o t+1 ); and the probability of moving from j to q F while emitting o t+2... o n, which is given by the backward probability β t+1,j divided by the probability of the observation since this is taken as given, i.e., divided by P(o). 23 / 33

Training We define ξ t (i, j) as this probability, i.e., the probability of being in i at time t, i.e., at observation o t and in j when emitting o t+1, given the observation sequence o: ξ t (i, j) = P(q t = q i, q t+1 = q j o) According to the previous slide, this can be computed as Transition E-step ξ t (i, j) = α tia ij b j (o t+1 )β t+1,j P(o) for i, j {1,..., Q } This is the E (expectation) step for the transition probabilities. 24 / 33

Training From these ξ t (i, j) values, we can estimate new transition probabilities towards maximizing the observed data: Remember that we want to have â ij = probability of transitions from i to j, given o probability of transitions from state i, given o With the previously defined ξ t (i, j), we obtain Transition M-step â ij = n 1 t=1 ξt(i,j) n 1 t=1 Q k=1 ξt(i,k)+ α n,i a if P(o) for i, j {1,..., Q }. â 0i = a 0ib i(o 1)β 1,i Q k=1 a 0kb k (o 1)β 1,k and â if = α n,i a if P(o) n 1 t=1 Q k=1 ξt(i,k)+ α n,i a if P(o) for 1 i Q This is the M (maximization) step for the transition probabilities. 25 / 33

Training For ˆb i (o), we calculate the probability of being in state i at time t given the observation sequence o, which we call γ t (i). Emission E-step γ t (i) = P(q t = q i o) = α tiβ ti P(o) This is the E (expectation) step for the emission probabilities. 26 / 33

Training From these γ t (i) values, we can estimate new emission probabilities towards maximizing the observed data: Remember that we want to have ˆbi (o) = probability of emitting o in i, given o probability of passing through state i, given o Emission M-step ˆbi (o) = 1 t n,o t=o γ t (i) n t=1 γ t (i) for 1 i Q This is the M (maximization) step for the emission probabilities. 27 / 33

Training Forward-backward algorithm (input observations o O n, state set Q): initialize A and B iterate until convergence: E-step γ t (i) = αtiβti P(o) for all 1 t n, 1 i Q ξ t (i, j) = αtiaijbj(ot+1)βt+1,j P(o) for all 1 t n 1, 1 i, j Q M-step â ij = â 0i = n 1 t=1 ξt(i,j) n 1 t=1 Q k=1 ξt(i,k)+ α n,i a if P(o) a 0ib i(o 1)β 1,i Q k=1 a 0kb k (o 1)β 1,k and â if = ˆbi (o) = 1 t n,ot =o γ t(i) n t=1 γt(i) return A, B for all 1 i, j Q α n,i a if P(o) n 1 t=1 Q k=1 ξt(i,k)+ α n,i a if P(o) for 1 i Q 28 / 33

Training (Simplified) ice cream weather example Initialized HMM: P(1 H) = 0.2 P(3 H) = 0.8 start 0.5 0.5 0.2 0.4 0.4 0.4 H observed sequence 31: α: H 0.4 4 10 2 C 1 10 1 0.16 t 1 2 E-step: γ: M-step: P(1 H) = 0.2 P(3 H) = 0.8 0.4 t H C 1 0.8 0.2 2 0.2 0.8 start C β: ξ 1 : 0.2 0.2 0.2 end 0.16 0.16 0.8 0.64 0.8 H C 3.97 10 2 end P(1 C) = 0.8 P(3 C) = 0.2 H 8 10 2 0.2 C 8 10 2 0.2 t 1 2 j =H j =C i =H 0.16 0.64 i =C 3.97 10 2 0.16 P(1 C) = 0.8 P(3 C) = 0.2 P(31) = 0.27 P(31) = 4 10 2 29 / 33

Training (Simplified) ice cream weather example Second step: P(1 H) = 0.2 P(3 H) = 0.8 0.2 0.2 end 0.16 0.16 0.8 0.64 0.8 H C 3.97 10 2 start P(1 C) = 0.8 P(3 C) = 0.2 α H 0.64 2.08 10 2 C 4 10 2 0.33 t 1 2 β H 0.42 0.2 C 0.1 0.8 t 1 2 E-step: γ: M-step: P(1 H) = 1.53 10 2 P(3 H) = 0.98 t H C 1 0.98 1.53 10 2 2 1.53 10 2 0.98 1.53 10 2 1.53 10 2 end 1.51 10 2 1.51 10 2 0.98 0.97 0.98 H C 1.7 10 4 start ξ j =H j =C i =H 1.51 10 2 0.97 i =C 1.7 10 4 1.51 10 2 P(1 C) = 0.98 P(3 C) = 1.52 10 2 P(31) = 0.91 30 / 33

Training (Simplified) ice cream weather example Third step: P(1 H) = 1.53 10 2 P(3 H) = 0.98 1.53 10 2 1.53 10 2 end 1.51 10 2 1.51 10 2 0.98 0.97 0.98 H C 1.7 10 4 start P(1 C) = 0.98 P(3 C) = 1.52 10 2 α H 0.97 2.1 10 4 C 2.3 10 4 0.93 t 1 2 β H 0.94 1.53 10 2 C 1.46 10 2 0.98 t 1 2 E-step: γ: t H C 1 1 0 2 0 1 ξ j =H j =C i =H 0 1 i =C 0 0 M-step: P(1 H) = 6 10 5 P(3 H) = 1 start 1 0 0 0 0 1 H 0 C end 1 P(1 C) = 1 P(3 C) = 0 P(31) = 1 31 / 33

Training Note that we can also leave out the factor initialize A and B iterate until convergence: 1 P(o), the result is the same: E-step φ t (i) = α ti β ti for all 1 t n, 1 i Q ψ t (i, j) = α ti a ij b j (o t+1 )β t+1,j for all 1 t n 1, 1 i, j Q M-step â ij = â 0i = n 1 t=1 ξt(i,j) n 1 t=1 Q k=1 ψt(i,k)+αn,ia if a 0ib i(o 1)β 1,i Q k=1 a 0kb k (o 1)β 1,k and â if = ˆbi (o) = 1 t n,ot =o φ t(i) n t=1 φt(i) return A, B for all 1 i, j Q α n,ia if n 1 t=1 Q k=1 ξt(i,k)+αn,ia if for 1 i Q 32 / 33

References Baum, L. E. 1972. An inequality and ssociated maximization technique in statistical estimation for jprobabilistic functions of markov processes. In O. Shisha (ed.), Inequalities iii: Proceedigns of the 3rd symposiom on inequalities, 1 8. University of California, Los Angeles: Academic Press. Dempster, A. P., N. M. Laird & D. B. Rubin. 1977. Maximum likelihood from incomplete data via the EM algorithm. Journal of the Royal Statistical Society 39(1). 1 21. Eisner, Jason. 2002. An interactive spreadsheet for teaching the forward-backward algorithm. In Proceedings of the acl workshop on effective tools and methodologies for teaching nlp and cl, 10 18. Jurafsky, Daniel & James H. Martin. 2015. Speech and language processing. an introduction to natural language processing, computational linguistics, and speech recognition. Draft of the 3rd edition. 33 / 33