Language Modeling: Ngrams

Slides:



Advertisements
Similar presentations
School of something FACULTY OF OTHER School of Computing FACULTY OF ENGINEERING Word-counts, visualizations and N-grams Eric Atwell, Language Research.
Advertisements

Chapter 6: Statistical Inference: n-gram Models over Sparse Data
1 CS 388: Natural Language Processing: N-Gram Language Models Raymond J. Mooney University of Texas at Austin.
Language Modeling.
Language Models Naama Kraus (Modified by Amit Gross) Slides are based on Introduction to Information Retrieval Book by Manning, Raghavan and Schütze.
N-Grams and Corpus Linguistics 6 July Linguistics vs. Engineering “But it must be recognized that the notion of “probability of a sentence” is an.
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 N-gram Language Models Shallow Processing Techniques for NLP Ling570 October 24, 2011.
CS 4705 N-Grams and Corpus Linguistics Julia Hirschberg CS 4705.
CSC 9010: Special Topics, Natural Language Processing. Spring, Matuszek & Papalaskari 1 N-Grams CSC 9010: Special Topics. Natural Language Processing.
N-Grams and Corpus Linguistics.  Regular expressions for asking questions about the stock market from stock reports  Due midnight, Sept. 29 th  Use.
1 I256: Applied Natural Language Processing Marti Hearst Sept 13, 2006.
Morphology & FSTs Shallow Processing Techniques for NLP Ling570 October 17, 2011.
N-Grams and Corpus Linguistics
N-Gram Language Models CMSC 723: Computational Linguistics I ― Session #9 Jimmy Lin The iSchool University of Maryland Wednesday, October 28, 2009.
CS 4705 Lecture 6 N-Grams and Corpus Linguistics.
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.
Part 5 Language Model CSE717, SPRING 2008 CUBS, Univ at Buffalo.
CS 4705 Lecture 15 Corpus Linguistics III. Training and Testing Probabilities come from a training corpus, which is used to design the model. –overly.
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.
Introduction to Language Models Evaluation in information retrieval Lecture 4.
CS 4705 N-Grams and Corpus Linguistics. Homework Use Perl or Java reg-ex package HW focus is on writing the “grammar” or FSA for dates and times The date.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 18: 10/26.
Language Modeling Julia Hirschberg CS Approaches to Language Modeling Context-Free Grammars –Use in HTK Ngram Models.
CS 4705 N-Grams and Corpus Linguistics. Spelling Correction, revisited M$ suggests: –ngram: NorAm –unigrams: anagrams, enigmas –bigrams: begrimes –trigrams:
CS 4705 Lecture 14 Corpus Linguistics II. Relating Conditionals and Priors P(A | B) = P(A ^ B) / P(B) –Or, P(A ^ B) = P(A | B) P(B) Bayes Theorem lets.
SI485i : NLP Set 3 Language Models Fall 2012 : Chambers.
1 Advanced Smoothing, Evaluation of Language Models.
Introduction to Automatic Speech Recognition
Multi-Style Language Model for Web Scale Information Retrieval Kuansan Wang, Xiaolong Li and Jianfeng Gao SIGIR 2010 Min-Hsuan Lai Department of Computer.
Lanugage Modeling Lecture 12 Spoken Language Processing Prof. Andrew Rosenberg.
Lecture 1, 7/21/2005Natural Language Processing1 CS60057 Speech &Natural Language Processing Autumn 2007 Lecture 7 8 August 2007.
Heshaam Faili University of Tehran
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.
Combining Statistical Language Models via the Latent Maximum Entropy Principle Shaojum Wang, Dale Schuurmans, Fuchum Peng, Yunxin Zhao.
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.
Lecture 4 Ngrams Smoothing
Language modelling María Fernández Pajares Verarbeitung gesprochener Sprache.
N-gram Models CMSC Artificial Intelligence February 24, 2005.
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.
Estimating N-gram Probabilities Language Modeling.
Natural Language Processing Statistical Inference: n-grams
A Maximum Entropy Language Model Integrating N-grams and Topic Dependencies for Conversational Speech Recognition Sanjeev Khudanpur and Jun Wu Johns Hopkins.
Maximum Entropy techniques for exploiting syntactic, semantic and collocational dependencies in Language Modeling Sanjeev Khudanpur, Jun Wu Center for.
N-Gram Model Formulas Word sequences Chain rule of probability Bigram approximation N-gram approximation.
Speech and Language Processing Lecture 4 Chapter 4 of SLP.
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.
CSCI 5832 Natural Language Processing
N-Grams and Corpus Linguistics
N-Grams and Corpus Linguistics
N-Gram Model Formulas Word sequences Chain rule of probability
CS4705 Natural Language Processing
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
INF 141: Information Retrieval
Presentation transcript:

Language Modeling: Ngrams Julia Hirschberg CS 4706

Approaches to Language Modeling Context-Free Grammars Use in Pocket Sphinx Ngram Models Use for large vocabulary tasks like recognizing Broadcast News or telephone conversations

Problems for Larger Vocabulary Applications CFGs complicated to build and hard to modify to accommodate new data: Add capability to make a reservation Add capability to ask for help Add ability to understand greetings … Parsing input with large CFGs is slow for real-time applications So…for large applications we use ngram models

Next Word Prediction The air traffic control supervisor who admitted falling asleep while on duty at Reagan National Airport has been suspended, and the head of the Federal Aviation Administration on Friday ordered new rules to ensure a similar incident doesn't take place. FAA chief Randy Babbitt said he has directed controllers at regional radar facilities to contact the towers of airports where there is only one controller on duty at night before sending planes on for landings. Babbitt also said regional controllers have been told that if no controller can be raised at the airport, they must offer pilots the option of diverting to another airport. Two commercial jets were unable to contact the control tower early Wednesday and had to land without gaining clearance.

Word Prediction How do we know which words occur together? Domain knowledge Syntactic knowledge Lexical knowledge Can we model this knowledge computationally? Simple statistical techniques do a good job when trained appropriately Most common way of constraining ASR predictions to conform to probabilities of word sequences in the language – Language Modeling via N-grams

N-Gram Models of Language Use the previous N-1 words in a sequence to predict the next word Language Model (LM) unigrams, bigrams, trigrams,… How do we train these models to discover co-occurrence probabilities?

Finding Corpora Corpora are online collections of text and speech Brown Corpus Wall Street Journal, AP newswire, web DARPA/NIST text/speech corpora (Call Home, Call Friend, ATIS, Switchboard, Broadcast News, TDT, Communicator) Internet anywhere

Tokenization: Counting Words in Corpora What is a word? e.g., are cat and cats the same word? Cat and cat? September and Sept? zero and oh? Is _ a word? * ? ‘(‘ ? Uh ? Should we count parts of self-repairs? (go to fr- france) How many words are there in don’t? Gonna? Any token separated by white space from another? In Japanese, Thai, Chinese text -- how do we identify a word?

Terminology Sentence: unit of written language (SLU) Utterance: unit of spoken language (prosodic phrase) Wordform: inflected form as it actually appears in the corpus Lemma: an abstract form, shared by word forms having the same stem, part of speech, and word sense – stands for the class of words with stem X Types: number of distinct words in a corpus (vocabulary size) Tokens: total number of words Stopped here

Simple Word Probability Assume a language has T word types and N tokens, how likely is word y to follow word x? Simplest model: 1/T But is every word equally likely? Alternative 1: estimate likelihood of y occurring in new text based on its general frequency of occurrence estimated from a corpus (unigram probability) ct(y)/N But is every word equally likely in every context? Alternative 2: condition the likelihood of y occurring on the context of previous words ct(x,y)/ct(x)

Computing Word Sequence (Sentence) Probabilities Compute probability of a word given a preceding sequence P(the mythical unicorn…) = P(the|<start>) P(mythical|<start> the) * P(unicorn|<start> the mythical)… Joint probability: P(wn-1,wn) = P(wn | wn-1) P(wn-1) Chain Rule: Decompose joint probability, e.g. P(w1,w2,w3) as P(w1,w2, ...,wn) = P(w1) P(w2|w1) P(w3|w2,w1) … P(wn|w1 to n-1) But…the longer the sequence, the less likely we are to find it in a training corpus P(<start>Most biologists and folklore specialists believe that in fact the mythical unicorn horns derived from the narwhal<end>)

Bigram Model Markov assumption: the probability of a word depends only on the probability of a limited history Approximate by P(unicorn|the mythical) by P(unicorn|mythical) Generalization: the probability of a word depends only on the probability of the n previous words trigrams, 4-grams, 5-grams… the higher n is, the more training data needed

From P(<start>the mythical unicorn…) = P(the|<start>) P(mythical|<start> the) P(unicorn|<start> the mythical)… To P(<start>the,mythical,unicorn…) = P(the|<start>) P(mythical|the) P(unicorn|mythical)…

What do we need: Bigram Counts eats honey mythical cat unicorn the a <end> 5 10 2 80 90 3 1 8 4 7 15 12 999 n-1

Determining Bigram Probabilities Normalization: divide each row's counts by appropriate unigram counts for wn-1 Computing the bigram probability of mythical mythical C(m,m)/C(all m-initial bigrams) p (m|m) = 2 / 35 = .05714 Maximum Likelihood Estimation (MLE): relative frequency of e.g. <start> a mythical cat eats honey <end> 1000 200 35 60 25 50

A Simple Example P(a mythical cat…) = P(a | <start>) P(mythical | a) P(cat | mythical) … P(<end>|…) = 90/1000 * 5/200 * 8/35 … Needed: Bigram counts for each of these word pairs (x,y) Counts for each unigram (x) to normalize P(y|x) = ct(x,y)/ct(x) Why do we usually represent bigram probabilities as log probabilities? What do these bigrams intuitively capture?

Training and Testing N-Gram probabilities come from a training corpus overly narrow corpus: probabilities don't generalize overly general corpus: probabilities don't reflect task or domain A separate test corpus is used to evaluate the model, typically using standard metrics held out test set; development (dev) test set cross validation results tested for statistical significance – how do they differ from a baseline? Other results?

Evaluating Ngram Models: Perplexity Information theoretic, intrinsic metric that usually correlates with extrinsic measures (e.g. ASR performance) At each choice point in a grammar or LM Weighted average branching factor: Average number of choices y following x, weighted by their probabilities of occurrence Or, if LM(1) assigns more probability to test set sentences than LM(2), we say its perplexity is lower it models the test set better

Ngram Properties As we increase the value of N, the accuracy of an ngram model increases – why? Ngrams are quite sensitive to the corpus they are trained on A few events (words) occur with high frequency, e.g.? Easy to collect statistics on these A very large number occur with low frequency, e.g.? You may wait an arbitrarily long time to get valid statistics on these Some of the zeros in a table are really zeros Others are just low frequency events you haven't seen yet How to allow for these events in unseen data?

Ngram Smoothing Every n-gram training matrix is sparse, even for very large corpora Zipf’s law: a word’s frequency is approximately inversely proportional to its rank in the word distribution list Solution: Estimate the likelihood of unseen n-grams Problem: how do to adjust the rest of the corpus to accommodate these ‘phantom’ n-grams? Many techniques described in J&M: LaPlace or add-one Most frequent word will occur ~twice as often as the second most frequent, three times as often as the, etc. in Brown Corpus"the" is the most frequently occurring word, and accounts for ~7% of all word occurrences (69,971 out of slightly over 1 million). second-place word "of" accounts for slightly over 3.5% of words (36,411 occurrences) followed by "and" (28,852). Only 135 vocabulary account for half the Brown Corpus.

Good-Turing Discounting: use counts of ngrams you’ve seen to estimate those you haven’t

Backoff and Interpolation For e.g. a trigram model Backoff (e.g. Katz ‘87) Compute unigram, bigram and trigram probabilities In use: Where trigram unavailable back off to bigram if available, o.w. unigram probability E.g An omnivorous unicorn Interpolation Compute trigram by linearly interpolating trigram, bigram, and unigram models, weighted appropriately

LM toolkits The CMU-Cambridge LM toolkit (CMULM) The SRILM toolkit http://www.speech.cs.cmu.edu/SLM/toolkit.html The SRILM toolkit http://www.speech.sri.com/projects/srilm/

Next Pronunciation and Acoustic Models