N-Grams Chapter 4 Part 1.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

1
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Detection of Hydrological Changes – Nonparametric Approaches
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Programming Language Concepts
Chapter 7 Sampling and Sampling Distributions
5.1 Probability of Simple Events
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Biostatistics Unit 5 Samples Needs to be completed. 12/24/13.
Discrete Math Recurrence Relations 1.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
The Frequency Table or Frequency Distribution Table
An Application of Linear Programming Lesson 12 The Transportation Model.
MAT 205 F08 Chapter 12 Complex Numbers.
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
Green Eggs and Ham.
How to convert a left linear grammar to a right linear grammar
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Jim Haywood (Product Manager for Statutory Returns) Adopted from Care - Spring Release 2014.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
1 CS 388: Natural Language Processing: N-Gram Language Models Raymond J. Mooney University of Texas at Austin.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Note to the teacher: Was 28. A. to B. you C. said D. on Note to the teacher: Make this slide correct answer be C and sound to be “said”. to said you on.
Formal Language, chapter 10, slide 1Copyright © 2007 by Adam Webber Chapter Ten: Grammars.
Analyzing Genes and Genomes
. Lecture #8: - Parameter Estimation for HMM with Hidden States: the Baum Welch Training - Viterbi Training - Extensions of HMM Background Readings: Chapters.
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Chapter 8 Estimation Understandable Statistics Ninth Edition
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
9. Two Functions of Two Random Variables
Tips for Taking the FSA ELA Reading and Mathematics Assessments
Profile. 1.Open an Internet web browser and type into the web browser address bar. 2.You will see a web page similar to the one on.
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
Basics of Statistical Estimation
Commonly Used Distributions
SI485i : NLP Set 3 Language Models Fall 2012 : Chambers.
Natural Language Processing Lecture 6—9/17/2013 Jim Martin.
Speech and Language Processing
Session 12 N-grams and Corpora Introduction to Speech and Natural Language Processing (KOM422 ) Credits: 3(3-0)
1 LIN6932 Spring 2007 LIN6932: Topics in Computational Linguistics Hana Filip Lecture 5: N-grams.
6. N-GRAMs 부산대학교 인공지능연구실 최성자. 2 Word prediction “I’d like to make a collect …” Call, telephone, or person-to-person -Spelling error detection -Augmentative.
Estimating N-gram Probabilities Language Modeling.
Speech and Language Processing Lecture 4 Chapter 4 of SLP.
N-Grams Chapter 4 Part 2.
CSC 594 Topics in AI – Natural Language Processing
CSCI 5832 Natural Language Processing
CSCI 5832 Natural Language Processing
Speech and Language Processing
Presentation transcript:

N-Grams Chapter 4 Part 1

Today Word prediction task Language modeling (N-grams) N-gram intro The chain rule Model evaluation Smoothing (covered in Part 2 slides) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Word Prediction Guess the next word... ... I notice three guys standing on the ??? There are many sources of knowledge that could be helpful, including world knowledge. But we can do pretty well by simply looking at the preceding words and keeping track of simple counts. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Word Prediction Formalize this task using N-gram models. N-grams are token sequences of length N. Given N-grams counts, we can guess likely next words in a sequence. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

N-Gram Models More formally, we will assess the conditional probability of candidate words. Also, we will assess the probability of an entire sequence of words. Pretty much the same thing as we’ll see... 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Applications Being able to predict the next word (or any linguistic unit) in a sequence is very It lies at the core of the following applications Automatic speech recognition Handwriting and character recognition Spelling correction Machine translation Augmentative communication Word similarity, generation, POS tagging, etc. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Counting He stepped out into the hall, was delighted to encounter a water brother. 13 tokens, 15 if we include “,” and “.” as separate tokens. Assuming we include the comma and period, how many bigrams are there? 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Counting Not always that simple I do uh main- mainly business data processing Spoken language poses various challenges. Should we count “uh” and other fillers as tokens? What about the repetition of “mainly”? Should such do-overs count twice or just once? The answers depend on the application. If we’re focusing on something like ASR to support indexing for search, then “uh” isn’t helpful (it’s not likely to occur as a query). But filled pauses are very useful in dialog management, so we might want them there. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Counting: Types and Tokens They picnicked by the pool, then lay back on the grass and looked at the stars. 18 tokens (again counting punctuation) only 16 types In going forward, we’ll sometimes count types and sometimes tokens 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Counting: Wordforms Should “cats” and “cat” count as the same? How about “geese” and “goose”? Lemma: cats & cat and geese & goose have the same lemmas Wordform: fully inflected surface form Again, we’ll have occasion to count both lemmas and wordforms 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Counting: Corpora Corpus: body of text Google Crawl of 1,024,908,267,229 English tokens 13,588,391 wordform types That seems like a lot of types... Even large dictionaries of English have only around 500k types. Why so many here? Numbers Misspellings Names Acronyms etc 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Language Modeling Back to word prediction Assess the conditional probability of a word given the previous words in the sequence P(wn|w1,w2…wn-1) We’ll call a statistical model that can assess this a Language Model 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Language Modeling One way to calculate them is to use the definition of conditional probabilities, and get the counts from a large corpus Counts are used to estimate the probabilities 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Language Modeling Unfortunately, for most sequences and for most text collections we won’t get good estimates from this method. We’ll use the chain rule of probability And an independence assumption. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

The Chain Rule P(its water was so transparent)= P(its)* P(water|its)* P(was|its water)* P(so|its water was)* P(transparent|its water was so) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

So, that’s the chain rule We still have the problem of estimating probabilities of word sequences from counts; we’ll never have enough data The other thing we mentioned (two slides back) is an independence assumption What type of assumption would make sense? 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Independence Assumption Make the simplifying assumption P(lizard|the,other,day,I,was,walking,along,and,saw,a) = P(lizard|a) Or maybe P(lizard|the,other,day,I,was,walking,along,and,saw,a) = P(lizard|saw,a) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Independence Assumption This kind of independence assumption is called a Markov assumption after the Russian mathematician Andrei Markov. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Markov Assumption For each component in the product replace with the approximation (assuming a prefix of N) Bigram version 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Estimating Bigram Probabilities The Maximum Likelihood Estimate (MLE) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

An Example <s> I am Sam </s> <s> Sam I am </s> <s> I do not like green eggs and ham </s> 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Maximum Likelihood Estimates The maximum likelihood estimate of some parameter of a model M from a training set T Is the estimate that maximizes the likelihood of the training set T given the model M Suppose the word Chinese occurs 400 times in a corpus of a million words (Brown corpus) What is the probability that a random word from some other text from the same distribution will be “Chinese” MLE estimate is 400/1000000 = .004 This may be a bad estimate for some other corpus (We’ll return to MLEs later – we’ll do smoothing to get estimates for low-frequency or 0 counts. Even with our independence assumptions, we still have this problem.) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Berkeley Restaurant Project Sentences can you tell me about any good cantonese restaurants close by mid priced thai food is what i’m looking for tell me about chez panisse can you give me a listing of the kinds of food that are available i’m looking for a good place to eat breakfast when is caffe venezia open during the day 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Bigram Counts Out of 9222 sentences Eg. “I want” occurred 827 times 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Bigram Probabilities Divide bigram counts by prefix unigram counts to get probabilities. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Bigram Estimates of Sentence Probabilities P(<s> I want english food </s>) = P(i|<s>)* P(want|I)* P(english|want)* P(food|english)* P(</s>|food)* =.000031 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Kinds of Knowledge As crude as they are, N-gram probabilities capture a range of interesting facts about language. P(english|want) = .0011 P(chinese|want) = .0065 P(to|want) = .66 P(eat | to) = .28 P(food | to) = 0 P(want | spend) = 0 P (i | <s>) = .25 World knowledge Syntax Discourse 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Shannon’s Method Let’s turn the model around and use it to generate random sentences that are like the sentences from which the model was derived. Illustrates: Dependence of N-gram models on the specific training corpus Greater N  better model Generally attributed to Claude Shannon. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Shannon’s Method Sample a random bigram (<s>, w) according to its probability Now sample a random bigram (w, x) according to its probability And so on until we randomly choose a (y, </s>) Then string the words together <s> I I want want to to eat eat Chinese Chinese food food </s> 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Shakespeare 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Shakespeare as a Corpus N=884,647 tokens, V=29,066 Shakespeare produced 300,000 bigram types out of V2= 844 million possible bigrams... So, 99.96% of the possible bigrams were never seen (have zero entries in the table) This is the biggest problem in language modeling; we’ll come back to it. Quadrigrams are worse: What's coming out looks like Shakespeare because it is Shakespeare 4/10/2017 Speech and Language Processing - Jurafsky and Martin

The Wall Street Journal is Not Shakespeare 4/10/2017 Speech and Language Processing - Jurafsky and Martin

A bad language model (thanks to Joshua Goodman)

A bad language model

A bad language model

A bad language model

Evaluation How do we know if one model is better than another? Shannon’s game gives us an intuition. The generated texts from the higher order models sound more like the text the model was obtained from. 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Evaluation Standard method Train parameters of our model on a training set. Look at the model’s performance on some new data: a test set. A dataset which is different than our training set, but is drawn from the same source Then we need an evaluation metric to tell us how well our model is doing on the test set. One such metric is perplexity (to be introduced below) 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Perplexity Minimizing perplexity is the same as maximizing probability Perplexity is the probability of the test set (assigned by the language model), normalized by the number of words: Chain rule: For bigrams: Minimizing perplexity is the same as maximizing probability The best language model is one that best predicts an unseen test set You do not need to memorize this formula 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Lower perplexity means a better model Training 38 million words, test 1.5 million words, WSJ 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Evaluating N-Gram Models Best evaluation for a language model Put model A into an application For example, a speech recognizer Evaluate the performance of the application with model A Put model B into the application and evaluate Compare performance of the application with the two models Extrinsic evaluation 4/10/2017 Speech and Language Processing - Jurafsky and Martin

Difficulty of extrinsic (in-vivo) evaluation of N-gram models Extrinsic evaluation This is really time-consuming Can take days to run an experiment So As a temporary solution, in order to run experiments To evaluate N-grams we often use an intrinsic evaluation, an approximation called perplexity But perplexity is a poor approximation unless the test data looks just like the training data So is generally only useful in pilot experiments (generally is not sufficient to publish) But is helpful to think about. 4/10/2017 Speech and Language Processing - Jurafsky and Martin