1 / 51

Sequence Models

Sequence Models. With slides by me, Joshua Goodman, Fei Xia. Outline. Language Modeling Ngram Models Hidden Markov Models Supervised Parameter Estimation Probability of a sequence Viterbi (or decoding) Baum-Welch. A bad language model. A bad language model. A bad language model.

sarila
Download Presentation

Sequence Models

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sequence Models With slides by me, Joshua Goodman, Fei Xia

  2. Outline • Language Modeling • Ngram Models • Hidden Markov Models • Supervised Parameter Estimation • Probability of a sequence • Viterbi (or decoding) • Baum-Welch

  3. A bad language model

  4. A bad language model

  5. A bad language model

  6. A bad language model

  7. What is a language model? Language Model: A distribution that assigns a probability to language utterances. e.g., PLM(“zxcv ./,mweaafsido”) is zero; PLM(“mat cat on the sat”) is tiny; PLM(“Colorless green ideas sleeps furiously”) is bigger; PLM(“A cat sat on the mat.”) is bigger still.

  8. What’s a language model for? • Information Retrieval • Handwriting recognition • Speech Recognition • Spelling correction • Optical character recognition • Machine translation • …

  9. Example Language Model Application Speech Recognition: convert an acoustic signal (sound wave recorded by a microphone) to a sequence of words (text file). Straightforward model: But this can be hard to train effectively (although see CRFs later).

  10. Example Language Model Application Speech Recognition: convert an acoustic signal (sound wave recorded by a microphone) to a sequence of words (text file). Traditional solution: Bayes’ Rule Acoustic Model (easier to train) Language Model Ignore: doesn’t matter for picking a good text

  11. Importance of Sequence So far, we’ve been making the exchangeability, or bag-of-words, assumption: The order of words is not important. It turns out, that’s actually not true (duh!). “cat mat on the sat” ≠ “the cat sat on the mat” “Mary loves John” ≠ “John loves Mary”

  12. Language Models with Sequence Information Problem: How can we define a model that • assigns probability to sequences of words (a language model) • the probability depends on the order of the words • the model can be trained and computed tractably?

  13. Outline • Language Modeling • Ngram Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence (decoding) • Viterbi (Best hidden layer sequence) • Baum-Welch • Conditional Random Fields

  14. Smoothing: Kneser-Ney P(Francisco | eggplant) vs P(stew | eggplant) • “Francisco” is common, so backoff, interpolated methods say it is likely • But it only occurs in context of “San” • “Stew” is common, and in many contexts • Weight backoff by number of contexts word occurs in

  15. Kneser-Ney smoothing (cont) Backoff: Interpolation:

  16. Outline • Language Modeling • Ngram Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence (decoding) • Viterbi (Best hidden layer sequence) • Baum-Welch • Conditional Random Fields

  17. The Hidden Markov Model A dynamicBayes Net (dynamic because the size can change). The Oi nodes are called observed nodes. The Si nodes are called hidden nodes. S1 S2 … Sn O1 O2 … On NLP

  18. HMMs and Language Processing • HMMs have been used in a variety of applications, but especially: • Speech recognition (hidden nodes are text words, observations are spoken words) • Part of Speech Tagging (hidden nodes are parts of speech, observations are words) S1 S2 … Sn O1 O2 … On NLP

  19. HMM Independence Assumptions HMMs assume that: • Si is independent of S1 through Si-2, given Si-1 (Markov assump.) • Oi is independent of all other nodes, given Si • P(Si | Si-1) and P(Oi | Si) do not depend on i Not very realistic assumptions about language – but HMMs are often good enough, and very convenient. S1 S2 … Sn O1 O2 … On NLP

  20. HMM Formula An HMM predicts that the probability of observing a sequence o = <o1, o2, …, oT> with a particular set of hidden states s = <s1, … sT> is: To calculate, we need: - Prior: P(s1) for all values of s1 - Observation: P(oi|si) for all values of oi and si - Transition: P(si|si-1) for all values of si and si-1

  21. HMM: Pieces • A set of hidden states H = {h1, …, hN} that are the values which hidden nodes may take. • A vocabulary, or set of states V = {v1, …, vM} that are the values which an observed node may take. • Initial probabilities P(s1=hi) for all i - Written as a vector of N initial probabilities, called π • Transition probabilities P(st=hi | st-1=hj) for all i, j • Written as an NxN ‘transition matrix’ A • Observation probabilities P(ot=vj|st=hi) for all j, i - written as an MxN ‘observation matrix’ B

  22. HMM for POS Tagging • S = {DT, NN, VB, IN, …}, the set of all POS tags. • V = the set of all words in English. • Initial probabilities πi are the probability that POS tag can start a sentence. • Transition probabilities Aij represent the probability that one tag can follow another • Observation probabilities Bij represent the probability that a tag will generate a particular.

  23. Outline • Graphical Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence • Viterbi: what’s the best hidden state sequence? • Baum-Welch: unsupervised parameter estimation • Conditional Random Fields

  24. o1 ot-1 ot ot+1 oT Supervised Parameter Estimation A A A A x1 xt-1 xt xt+1 xT B B B B B • Given an observation sequence and states, find the HMM model (π, A, and B) that is most likely to produce the sequence. • For example, POS-tagged data from the Penn Treebank

  25. o1 ot-1 ot ot+1 oT Bayesian Parameter Estimation A A A A x1 xt-1 xt xt+1 xT B B B B B

  26. Outline • Graphical Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence • Viterbi • Baum-Welch • Conditional Random Fields

  27. What’s the probability of a sentence? Suppose I asked you, ‘What’s the probability of seeing a sentence w1, …, wT on the web?’ If we have an HMM model of English, we can use it to estimate the probability. (In other words, HMMs can be used as language models.)

  28. Conditional Probability of a Sentence • If we knew the hidden states that generated each word in the sentence, it would be easy:

  29. Probability of a Sentence Via marginalization, we have: Unfortunately, if there are N values for each ai (s1 through sN), Then there are NT values for a1,…,aT. Brute-force computation of this sum is intractable.

  30. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure • Special structure gives us an efficient solution using dynamic programming. • Intuition: Probability of the first t observations is the same for all possible t+1 length state sequences. • Define:

  31. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  32. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  33. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  34. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  35. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  36. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  37. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  38. x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure

  39. Backward Procedure x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Probability of the rest of the states given the first state

  40. Decoding Solution x1 xt-1 xt xt+1 xT o1 ot-1 ot ot+1 oT Forward Procedure Backward Procedure Combination

  41. Outline • Graphical Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence • Viterbi: what’s the best hidden state sequence? • Baum-Welch • Conditional Random Fields

  42. Find the hidden state sequence that best explains the observations Viterbi algorithm o1 ot-1 ot ot+1 oT Best State Sequence

  43. Viterbi Algorithm x1 xt-1 j o1 ot-1 ot ot+1 oT The state sequence which maximizes the probability of seeing the observations to time t-1, landing in state j, and seeing the observation at time t

  44. o1 ot-1 ot ot+1 oT Viterbi Algorithm x1 xt-1 xt xt+1 Recursive Computation

  45. o1 ot-1 ot ot+1 oT Viterbi Algorithm x1 xt-1 xt xt+1 xT Compute the most likely state sequence by working backwards

  46. Outline • Graphical Models • Hidden Markov Models • Supervised parameter estimation • Probability of a sequence • Viterbi • Baum-Welch: Unsupervised parameter estimation • Conditional Random Fields

  47. o1 ot-1 ot ot+1 oT Unsupervised Parameter Estimation A A A A B B B B B • Given an observation sequence, find the model that is most likely to produce that sequence. • No analytic method • Given a model and observation sequence, update the model parameters to better fit the observations.

  48. o1 ot-1 ot ot+1 oT Parameter Estimation A A A A B B B B B Probability of traversing an arc Probability of being in state i

  49. o1 ot-1 ot ot+1 oT Parameter Estimation A A A A B B B B B Now we can compute the new estimates of the model parameters.

  50. o1 ot-1 ot ot+1 oT Parameter Estimation A A A A B B B B B • Guarantee: P(o1:T|A,B,π) <= P(o1:T|Â,B̂,π̂) • In other words, by repeating this procedure, we can gradually improve how well the HMM fits the unlabeled data. • There is no guarantee that this will converge to the best possible HMM, however (only guaranteed to find a local maximum).

More Related