1 CS 388: Natural Language Processing: N-Gram Language Models Raymond J. Mooney University of Texas at Austin.

Slides:



Advertisements
Similar presentations
Chapter 6: Statistical Inference: n-gram Models over Sparse Data
Advertisements

Language Modeling.
N-Grams Chapter 4 Part 1.
N-gram model limitations Important question was asked in class: what do we do about N-grams which were not in our training corpus? Answer given: we distribute.
Albert Gatt Corpora and Statistical Methods – Lecture 7.
SI485i : NLP Set 4 Smoothing Language Models Fall 2012 : Chambers.
Smoothing Techniques – A Primer
HMM II: Parameter Estimation. Reminder: Hidden Markov Model Markov Chain transition probabilities: p(S i+1 = t|S i = s) = a st Emission probabilities:
Smoothing N-gram Language Models Shallow Processing Techniques for NLP Ling570 October 24, 2011.
Language modelling using N-Grams Corpora and Statistical Methods Lecture 7.
Morphology & FSTs Shallow Processing Techniques for NLP Ling570 October 17, 2011.
Probabilistic Pronunciation + N-gram Models CSPP Artificial Intelligence February 25, 2004.
N-Gram Language Models CMSC 723: Computational Linguistics I ― Session #9 Jimmy Lin The iSchool University of Maryland Wednesday, October 28, 2009.
Ngram models and the Sparsity problem John Goldsmith November 2002.
N-gram model limitations Q: What do we do about N-grams which were not in our training corpus? A: We distribute some probability mass from seen N-grams.
1 Language Model (LM) LING 570 Fei Xia Week 4: 10/21/2009 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAAA A A.
1 Smoothing LING 570 Fei Xia Week 5: 10/24/07 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA A A AA A A A.
Part 5 Language Model CSE717, SPRING 2008 CUBS, Univ at Buffalo.
Language Model. Major role: Language Models help a speech recognizer figure out how likely a word sequence is, independent of the acoustics. A lot of.
I256 Applied Natural Language Processing Fall 2009 Lecture 7 Practical examples of Graphical Models Language models Sparse data & smoothing Barbara Rosario.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 18: 10/26.
Maximum Entropy Model & Generalized Iterative Scaling Arindam Bose CS 621 – Artificial Intelligence 27 th August, 2007.
SI485i : NLP Set 3 Language Models Fall 2012 : Chambers.
1 Advanced Smoothing, Evaluation of Language Models.
8/27/2015CPSC503 Winter CPSC 503 Computational Linguistics Lecture 5 Giuseppe Carenini.
Natural Language Processing Lecture 6—9/17/2013 Jim Martin.
Machine Translation Course 3 Diana Trandab ă ț Academic year:
Natural Language Processing Language Model. Language Models Formal grammars (e.g. regular, context free) give a hard “binary” model of the legal sentences.
Multi-Style Language Model for Web Scale Information Retrieval Kuansan Wang, Xiaolong Li and Jianfeng Gao SIGIR 2010 Min-Hsuan Lai Department of Computer.
Topic Models in Text Processing IR Group Meeting Presented by Qiaozhu Mei.
6. N-GRAMs 부산대학교 인공지능연구실 최성자. 2 Word prediction “I’d like to make a collect …” Call, telephone, or person-to-person -Spelling error detection -Augmentative.
NLP Language Models1 Language Models, LM Noisy Channel model Simple Markov Models Smoothing Statistical Language Models.
Chapter 6: Statistical Inference: n-gram Models over Sparse Data
Statistical NLP: Lecture 8 Statistical Inference: n-gram Models over Sparse Data (Ch 6)
Chapter 6: N-GRAMS Heshaam Faili University of Tehran.
1 CS 391L: Machine Learning: Bayesian Learning: Naïve Bayes Raymond J. Mooney University of Texas at Austin.
CSC321: 2011 Introduction to Neural Networks and Machine Learning Lecture 11: Bayesian learning continued Geoffrey Hinton.
NLP. Introduction to NLP Extrinsic –Use in an application Intrinsic –Cheaper Correlate the two for validation purposes.
Chapter6. Statistical Inference : n-gram Model over Sparse Data 이 동 훈 Foundations of Statistic Natural Language Processing.
An Overview of Nonparametric Bayesian Models and Applications to Natural Language Processing Narges Sharif-Razavian and Andreas Zollmann.
Lecture 4 Ngrams Smoothing
N-gram Models CMSC Artificial Intelligence February 24, 2005.
1 Modeling Long Distance Dependence in Language: Topic Mixtures Versus Dynamic Cache Models Rukmini.M Iyer, Mari Ostendorf.
Ngram models and the Sparcity problem. The task Find a probability distribution for the current word in a text (utterance, etc.), given what the last.
1 Introduction to Natural Language Processing ( ) Language Modeling (and the Noisy Channel) AI-lab
Introduction to N-grams Language Modeling. Dan Jurafsky Probabilistic Language Models Today’s goal: assign a probability to a sentence Machine Translation:
Estimating N-gram Probabilities Language Modeling.
Natural Language Processing Statistical Inference: n-grams
Learning, Uncertainty, and Information: Evaluating Models Big Ideas November 12, 2004.
N-Gram Model Formulas Word sequences Chain rule of probability Bigram approximation N-gram approximation.
Statistical Language Models Hongning Wang CS 6501: Text Mining1.
Discriminative n-gram language modeling Brian Roark, Murat Saraclar, Michael Collins Presented by Patty Liu.
Statistical Methods for NLP Diana Trandab ă ț
Probabilistic Pronunciation + N-gram Models CMSC Natural Language Processing April 15, 2003.
Language Modeling Part II: Smoothing Techniques Niranjan Balasubramanian Slide Credits: Chris Manning, Dan Jurafsky, Mausam.
Language Model for Machine Translation Jang, HaYoung.
Statistical Methods for NLP
N-Grams Chapter 4 Part 2.
CSC 594 Topics in AI – Natural Language Processing
CSCI 5832 Natural Language Processing
Neural Language Model CS246 Junghoo “John” Cho.
CPSC 503 Computational Linguistics
N-Gram Model Formulas Word sequences Chain rule of probability
CSCE 771 Natural Language Processing
Presented by Wen-Hung Tsai Speech Lab, CSIE, NTNU 2005/07/13
Chapter 6: Statistical Inference: n-gram Models over Sparse Data
CSCE 771 Natural Language Processing
CPSC 503 Computational Linguistics
INF 141: Information Retrieval
Presentation transcript:

1 CS 388: Natural Language Processing: N-Gram Language Models Raymond J. Mooney University of Texas at Austin

Language Models Formal grammars (e.g. regular, context free) give a hard “binary” model of the legal sentences in a language. For NLP, a probabilistic model of a language that gives a probability that a string is a member of a language is more useful. To specify a correct probability distribution, the probability of all sentences in a language must sum to 1.

Uses of Language Models Speech recognition –“I ate a cherry” is a more likely sentence than “Eye eight uh Jerry” OCR & Handwriting recognition –More probable sentences are more likely correct readings. Machine translation –More likely sentences are probably better translations. Generation –More likely sentences are probably better NL generations. Context sensitive spelling correction –“Their are problems wit this sentence.”

Completion Prediction A language model also supports predicting the completion of a sentence. –Please turn off your cell _____ –Your program does not ______ Predictive text input systems can guess what you are typing and give choices on how to complete it.

N-Gram Models Estimate probability of each word given prior context. –P(phone | Please turn off your cell) Number of parameters required grows exponentially with the number of words of prior context. An N-gram model uses only N  1 words of prior context. –Unigram: P(phone) –Bigram: P(phone | cell) –Trigram: P(phone | your cell) The Markov assumption is the presumption that the future behavior of a dynamical system only depends on its recent history. In particular, in a kth-order Markov model, the next state only depends on the k most recent states, therefore an N-gram model is a (N  1)-order Markov model.

N-Gram Model Formulas Word sequences Chain rule of probability Bigram approximation N-gram approximation

Estimating Probabilities N-gram conditional probabilities can be estimated from raw text based on the relative frequency of word sequences. To have a consistent probabilistic model, append a unique start ( ) and end ( ) symbol to every sentence and treat these as additional words. Bigram: N-gram:

Generative Model & MLE An N-gram model can be seen as a probabilistic automata for generating sentences. Relative frequency estimates can be proven to be maximum likelihood estimates (MLE) since they maximize the probability that the model M will generate the training corpus T. Initialize sentence with N  1 symbols Until is generated do: Stochastically pick the next word based on the conditional probability of each word given the previous N  1 words.

Example from Textbook P( i want english food ) = P(i | ) P(want | i) P(english | want) P(food | english) P( | food) =.25 x.33 x.0011 x.5 x.68 = P( i want chinese food ) = P(i | ) P(want | i) P(chinese | want) P(food | chinese) P( | food) =.25 x.33 x.0065 x.52 x.68 =.00019

Train and Test Corpora A language model must be trained on a large corpus of text to estimate good parameter values. Model can be evaluated based on its ability to predict a high probability for a disjoint (held-out) test corpus (testing on the training corpus would give an optimistically biased estimate). Ideally, the training (and test) corpus should be representative of the actual application data. May need to adapt a general model to a small amount of new (in-domain) data by adding highly weighted small corpus to original training data.

Unknown Words How to handle words in the test corpus that did not occur in the training data, i.e. out of vocabulary (OOV) words? Train a model that includes an explicit symbol for an unknown word ( ). –Choose a vocabulary in advance and replace other words in the training corpus with. –Replace the first occurrence of each word in the training data with.

Evaluation of Language Models Ideally, evaluate use of model in end application (extrinsic, in vivo) –Realistic –Expensive Evaluate on ability to model test corpus (intrinsic). –Less realistic –Cheaper Verify at least once that intrinsic evaluation correlates with an extrinsic one.

Perplexity Measure of how well a model “fits” the test data. Uses the probability that the model assigns to the test corpus. Normalizes for the number of words in the test corpus and takes the inverse. Measures the weighted average branching factor in predicting the next word (lower is better).

Sample Perplexity Evaluation Models trained on 38 million words from the Wall Street Journal (WSJ) using a 19,979 word vocabulary. Evaluate on a disjoint set of 1.5 million WSJ words. UnigramBigramTrigram Perplexity

Smoothing Since there are a combinatorial number of possible word sequences, many rare (but not impossible) combinations never occur in training, so MLE incorrectly assigns zero to many parameters (a.k.a. sparse data). If a new combination occurs during testing, it is given a probability of zero and the entire sequence gets a probability of zero (i.e. infinite perplexity). In practice, parameters are smoothed (a.k.a. regularized) to reassign some probability mass to unseen events. –Adding probability mass to unseen events requires removing it from seen ones (discounting) in order to maintain a joint distribution that sums to 1.

Laplace (Add-One) Smoothing “Hallucinate” additional training data in which each possible N-gram occurs exactly once and adjust estimates accordingly. where V is the total number of possible (N  1)-grams (i.e. the vocabulary size for a bigram model). Bigram: N-gram: Tends to reassign too much mass to unseen events, so can be adjusted to add 0<  <1 (normalized by  V instead of V).

Advanced Smoothing Many advanced techniques have been developed to improve smoothing for language models. –Good-Turing –Interpolation –Backoff –Kneser-Ney –Class-based (cluster) N-grams

Model Combination As N increases, the power (expressiveness) of an N-gram model increases, but the ability to estimate accurate parameters from sparse data decreases (i.e. the smoothing problem gets worse). A general approach is to combine the results of multiple N-gram models of increasing complexity (i.e. increasing N).

Interpolation Linearly combine estimates of N-gram models of increasing order. Learn proper values for i by training to (approximately) maximize the likelihood of an independent development (a.k.a. tuning) corpus. Interpolated Trigram Model: Where:

Backoff Only use lower-order model when data for higher- order model is unavailable (i.e. count is zero). Recursively back-off to weaker models until data is available. Where P* is a discounted probability estimate to reserve mass for unseen events and  ’s are back-off weights (see text for details).

A Problem for N-Grams: Long Distance Dependencies Many times local context does not provide the most useful predictive clues, which instead are provided by long-distance dependencies. –Syntactic dependencies “The man next to the large oak tree near the grocery store on the corner is tall.” “The men next to the large oak tree near the grocery store on the corner are tall.” –Semantic dependencies “The bird next to the large oak tree near the grocery store on the corner flies rapidly.” “The man next to the large oak tree near the grocery store on the corner talks rapidly.” More complex models of language are needed to handle such dependencies.

Summary Language models assign a probability that a sentence is a legal string in a language. They are useful as a component of many NLP systems, such as ASR, OCR, and MT. Simple N-gram models are easy to train on unsupervised corpora and can provide useful estimates of sentence likelihood. MLE gives inaccurate parameters for models trained on sparse data. Smoothing techniques adjust parameter estimates to account for unseen (but not impossible) events.