1 / 51

Understanding Probability Notation in Applied Natural Language Processing

This lecture focuses on probability notation, manipulation, and estimation in the context of language processing. It covers probability models, assessing model quality, and the three types of statistics. Various examples and formulas are discussed.

jeske
Download Presentation

Understanding Probability Notation in Applied Natural Language Processing

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. Probability CSCI 544: Applied Natural Language Processing Nanyun (Violet) Peng based on slides of Jason Eisner

  2. Goals of this lecture • Probability notation like p(Y | X): • What does this expression mean? • How can I manipulate it? • How can I estimate its value in practice? • Probability models: • What is one? • Can we build one for language ID? • How do I know if my model is any good?

  3. this course – why? 3 Kinds of Statistics • descriptive:mean, variance, median • confirmatory:statistically significant? • predictive: wanna bet?

  4. Fugue for Tinhorns • Opening number from Guys and Dolls • 1950 Broadway musical about gamblers • Words & music by Frank Loesser • Video: https://www.youtube.com/results?search_query=fugue+for+tinhorns • Lyrics: http://www.lyricsmania.com/fugue_for_tinhorns_lyrics_guys_and_dolls.html I got the horse right here The name is Paul Revere And here's a guy that says that the weather's clear Can do, can do, this guy says the horse can do If he says the horse can do, can do, can do. I'm pickin' Valentine, 'cause on the morning line A guy has got him figured at five to nine Has chance, has chance, this guy says the horse has chance if he says the horse has chance, has chance, has chance  But look at Epitaph. he wins it by a half According to this here in the Telegraph "Big Threat" - "Big Threat" This guy calls the horse "Big Threat" If he calls the horse "Big Threat", Big Threat, Big Threat. 

  5. probability model Notation for Greenhorns 0.9 “Paul Revere” p(Paul Revere wins | weather’s clear) = 0.9

  6. What does that really mean? p(Paul Revere wins | weather’s clear) = 0.9 • Past performance? • Revere’s won 90% of races with clear weather • Hypothetical performance? • If he ran the race in many parallel universes … • Subjective strength of belief? • Would pay up to 90 cents for chance to win $1 • Output of some computable formula? • Ok, but then which formulas should we trust? p(Y | X) versus q(Y | X)

  7. p is a function on sets of “outcomes” p(win | clear)  p(win, clear) / p(clear) weather’s clear Paul Revere wins All Outcomes (races)

  8. Required Properties of p (axioms) • p() = 0 p(all outcomes) = 1 • p(X)  p(Y) for any X  Y • p(X) + p(Y) = p(X  Y) provided X  Y= e.g., p(win & clear)+p(win & clear)= p(win) p measures total probability of a set of outcomes(an “event”). weather’s clear Paul Revere wins All Outcomes (races)

  9. Definitions • Experiment: Some action that takes place in the world • Outcomes = Sample Space = Ω = the universe; every basic outcome that could happen • Event = A ⊆Ω = something that happened (could be more than one basic outcome) • Probability Distribution: 𝓕: Ω→[0,1], ∑x ∈Ω𝓕(x)=1 i.e. the values sum to 1 and no value is negative 9

  10. Independence • Events A and B are independent if P(A) = P(A|B)

  11. Bayes' Rule • P(A|B) = P(A, B)/P(B); P(A, B) = P(A|B)P(B) • P(B|A) = P(A, B)/P(A); P(A, B) = P(B|A)P(A) • P(A|B)P(B) = P(B|A)P(A) • P(A|B) = P(B|A)P(A)/P(B)

  12. Law of Total Probability • Let there be events E1...En that partition an outcome space (Ω) • ∑i=1n P(Ei) = 1 • 0≤P(Ei)≤1 • For any B ⊆Ω • P(B) = ∑i=1n P(B, Ei)

  13. Using Bayes' Rule and Law of Total Probability • Some people can read minds! • Not very many of them; • P(MR) = 1/100,000 • I have invented a mind reader detector test! • If you're a mind reader I can detect this with 95% accuracy : P(T|MR) = 0.95 • If you're not, I can detect this with 99.5% accuracy: P(¬T|¬MR) = 0.995 • Jill takes the test. The test says "T" (true). How likely is it that Jill is a mind reader?

  14. Jill Passed the Test. Is She a Mind Reader? • P(MR|T) = ? • P(MR|T) = P(MR, T)/P(T) • = P(T|MR)P(MR)/P(T) • How do we use P(T|MR) and law of totalprobability to get P(T)? • P(T) = P(T,MR)+P(T,¬MR) • P(T,MR) = P(T|MR)P(MR) = .95*.00001=.0000095 • P(T,¬MR)=P(T|¬MR)P(¬MR) = .005*.99999 = .00499995 • P(T) = .00500945 • P(MR|T) = .95*.00001/.00500945 ≈ 0.002

  15. Back to the horse race example

  16. Commas denote conjunction p(Paul Revere wins, Valentine places, Epitaph shows | weather’s clear) what happens as we add conjuncts to left of bar ? • probability can only decrease • numerator of historical estimate likely to go to zero: # times Revere wins AND Val places… AND weather’s clear # times weather’s clear

  17. Commas denote conjunction p(Paul Revere wins, Valentine places, Epitaph shows | weather’s clear) p(Paul Revere wins | weather’s clear, ground is dry, jockey getting over sprain, Epitaph also in race, Epitaph was recently bought by Gonzalez, race is on May 17, … ) what happens as we add conjuncts to right of bar ? • probability could increase or decrease • probability gets more relevant to our case (less bias) • probability estimate gets less reliable (more variance) # times Revere wins AND weather clear AND … it’s May 17 # times weather clear AND … it’s May 17

  18. Simplifying Right Side: Backing Off p(Paul Revere wins | weather’s clear, ground is dry, jockey getting over sprain, Epitaph also in race, Epitaph was recently bought by Gonzalez, race is on May 17, … ) not exactly what we want but at least we can get a reasonable estimate of it! (i.e., more bias but less variance) try to keep the conditions that we suspect will have the most influence on whether Paul Revere wins

  19. Simplifying Left Side: Backing Off p(Paul Revere wins, Valentine places, Epitaph shows | weather’s clear) NOT ALLOWED! but we can do something similar to help …

  20. Revere? Valentine? no 2/3 Revere? no 4/5 Revere? yes 1/3 no 3/4 yes 1/5 yes 1/4 Factoring Left Side: The Chain Rule RVEW/W = RVEW/VEW * VEW/EW * EW/W p(Revere, Valentine, Epitaph | weather’s clear) = p(Revere | Valentine, Epitaph, weather’s clear) * p(Valentine | Epitaph, weather’s clear) * p(Epitaph | weather’s clear) True because numerators cancel against denominators Makes perfect sense when read from bottom to top Epitaph? Valentine? Revere? Epitaph, Valentine, Revere? 1/3 * 1/5 * 1/4

  21. If this prob is unchanged by backoff, we say Revere was CONDITIONALLY INDEPENDENT of Valentine and Epitaph (conditioned on the weather’s being clear). Often we just ASSUME conditional independence to get the nice product above. Factoring Left Side: The Chain Rule RVEW/W = RVEW/VEW * VEW/EW * EW/W p(Revere, Valentine, Epitaph | weather’s clear) = p(Revere | Valentine, Epitaph, weather’s clear) * p(Valentine | Epitaph, weather’s clear) * p(Epitaph | weather’s clear) True because numerators cancel against denominators Makes perfect sense when read from bottom to top Moves material to right of bar so it can be ignored

  22. conditional independence lets us use backed-off data from all four of these cases to estimate their shared probabilities no 3/4 no 3/4 no Revere? yes 1/4 yes 1/4 Valentine? no 3/4 no yes 1/4 Revere? yes Epitaph? no 3/4 no yes 1/4 Revere? yes yes Valentine? clear? yes irrelevant Revere? Factoring Left Side: The Chain Rule p(Revere | Valentine, Epitaph, weather’s clear) If this prob is unchanged by backoff, we say Revere was CONDITIONALLY INDEPENDENT of Valentine and Epitaph (conditioned on the weather’s being clear).

  23. Estimating Probabilities • How do we get these basic outcome probabilities? • Do experiments! • Find some data (a sample) • Count stuff in the sample • e.g. "how often do sentences start with the word 'So'? • Experiment: Observe sentences that occur in the world • Basic outcomes: {every possible sentence that could occur} • Event A: {sentences that start with 'So'} • P(A) = count of sentences starting with 'So' in the sample/sentences in the sample • P(A|B) = count(A, B)/count(B)

  24. Data and Model • Suppose we have a biased 12-sided die and we throw it repeatedly: • It's easy to estimate the 11 free parameters (why 11?) • Total rolls = 324; P(1) = 0/324 = 0; P(5) = 119/324 = .367 • P(12) = 1-(P(1)+P(2)+...+P(11))

  25. Data and Model ? • What if you only saw the results and weren't told how they were generated? • Another theory: sum of two 6-sided die rolls • What about sum of three 4-sided dice? • In the 2d6 case, P(8) = P(3)P(5) + P(4)P(4) + P(5)P(3) • Now only 5 free parameters ?

  26. Data and Model • Maybe it's not dice at all • Could be number of minutes of phone calls • Historical data shows this follows a gamma curve • Shape is fixed but two numbers control center and 'flatness'

  27. Data and Model • General theory of how data got generated, together with a set of parameter estimates is called a probabilistic model • Questions: • Given a theory T, how do we know if one set of parameter estimates is better than another? • Which is better: theory T with parameters t or theory S with parameters s? • i.e. is one theory in general better than another? • can we automatically identify the best model (best theory+param combination)? ? BIG MACHINE LEARNING QUESTIONS!

  28. Data and Model • Ask the data! • For data D and models m in M, find argmaxm P(m|D) • By Bayes' rule this is equal toargmaxm P(m) P(D|m) • If we don't have any prior preferences, i.e. distribution over M is uniform, then it's just argmaxm P(D|m) does this model look generally good? given the model, does the data look reasonable?

  29. Determining P(D|m) • Quantitative! • Get some D (a sample) • apply each m • P(D|m) = ∏d∈DP(d|m) • m1: ½ * ½ * ½ * ½ = .0625 • m2: ¾ * ¾ * ¼ * ¾ = .105 • m3: 9/10 * 9/10 * 1/10 * 9/10 = .073 • argmaxmP(D|m) = m2 • This is the maximum likelihood estimation (MLE) SAMPLE m2!

  30. What if we have an opinion about M? • e.g. the coin doesn't look biased We could also compare the d12 vs 2d6 theories using the same technique!

  31. Language ID • “Horses and Lukasiewicz are on the curriculum.” • Is this English or Polish or what? • We had some notion of using n-gram models … • Is it “good” (= likely) English? • Is it “good” (= likely) Polish? • Space of outcomes will be not races but character sequences (x1, x2, x3, …) where xn = EOS

  32. Language ID • Let p(X) = probability of text X in English • Let q(X) = probability of text X in Polish • Which probability is higher? • (we’d also like bias toward English since it’s more likely a priori – ignore that for now) “Horses and Lukasiewicz are on the curriculum.” p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …)

  33. Apply the Chain Rule p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …) = p(x1=h) * p(x2=o | x1=h) * p(x3=r | x1=h, x2=o) * p(x4=s | x1=h, x2=o, x3=r) * p(x5=e | x1=h, x2=o, x3=r, x4=s) * p(x6=s | x1=h, x2=o, x3=r, x4=s, x5=e) * … 4470/ 52108 395/ 4470 5/ 395 3/ 5 3/ 3 0/ 3 counts from Brown corpus = 0

  34. Back Off On Right Side p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …) = p(x1=h) * p(x2=o | x1=h) * p(x3=r | x1=h, x2=o) * p(x4=s | x2=o, x3=r) * p(x5=e | x3=r, x4=s) * p(x6=s | x4=s, x5=e) * … 4470/ 52108 395/ 4470 5/ 395 12/ 919 12/ 126 3/ 485 counts from Brown corpus

  35. Back Off On Right Side p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …) = p(x1=h) * p(x2=o | x1=h) * p(xi=r | xi-2=h, xi-1=o, i=3) * p(xi=s | xi-2=h, xi-1=o, i=4) * p(xi=e | xi-2=h, xi-1=o, i=5) * p(xi=s | xi-2=h, xi-1=o, i=6) * … = 7.3e-10 * … 4470/ 52108 395/ 4470 5/ 395 12/ 919 12/ 126 3/ 485 counts from Brown corpus

  36. Back Off On Right Side p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …) = p(x1=h) * p(x2=o | x1=h) * p(xi=r | xi-2=h, xi-1=o) * p(xi=s | xi-2=h, xi-1=o) * p(xi=e | xi-2=h, xi-1=o) * p(xi=s | xi-2=h, xi-1=o) * … = 5.4e-7 * … 4470/ 52108 395/ 4470 5/ 395 12/ 919 12/ 126 3/ 485 counts from Brown corpus

  37. Simplify the Notation p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …)  p(x1=h) * p(x2=o | x1=h) * p(r | h, o) * p(s | o, r) * p(e | r, s) * p(s | s, e) * … 4470/ 52108 395/ 4470 1417/ 14765 1573/ 26412 1610/ 12253 2044/ 21250 counts from Brown corpus

  38. the parameters of a trigram language model! Same assumptions about language. values of those parameters, as naively estimated from Brown corpus. Simplify the Notation p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …)  p(h | BOS, BOS) * p(o | BOS, h) * p(r | h, o) * p(s | o, r) * p(e | r, s) * p(s | s, e) * … 4470/ 52108 395/ 4470 1417/ 14765 1573/ 26412 1610/ 12253 2044/ 21250 counts from Brown corpus These basic probabilities are used to define p(horses)

  39. param values definition of p generate random text find event probabilities Definition: Probability Model Trigram Model (defined in terms of parameters like t h, o, r and t o, r, s )

  40. compute p(X) compute q(X) English vs. Polish Trigram Model (defined in terms of parameters like t h, o, r and t o, r, s ) English param values definition of p Polish param values definition of q compare

  41. compute p(X) compute q(X) What is “X” in p(X)? • Element (or subset) of some implicit “outcome space” • e.g., race • e.g., sentence • What if outcome is a whole text? • p(text)= p(sentence 1, sentence 2, …)= p(sentence 1) * p(sentence 2 | sentence 1)* … definition of p definition of q compare

  42. What is “X” in “p(X)”? • Element (or subset) of some implicit “outcome space” • e.g., race, sentence, text … • Suppose an outcome is a sequence of letters:p(horses) • But we rewrote p(horses) asp(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …) • p(x1=h) * p(x2=o | x1=h) * … • What does this variable=value notation mean? compare

  43. Random Variables: What is “variable” in “p(variable=value)”? Answer: variableis really a function of Outcome • p(x1=h) * p(x2=o | x1=h) * … • Outcome is a sequence of letters • x2is the second letter in the sequence • p(number of heads=2) or just p(H=2) or p(2) • Outcome is a sequence of 3 coin flips • His the number of heads • p(weather’s clear=true) or just p(weather’s clear) • Outcome is a race • weather’s clear is true or false compare

  44. Random Variables: What is “variable” in “p(variable=value)”? • p(number of heads=2) or just p(H=2) • Outcome is a sequence of 3 coin flips • His the number of heads in the outcome • So p(H=2)= p(H(Outcome)=2) picks out set of outcomes w/2 heads= p({HHT,HTH,THH})= p(HHT)+p(HTH)+p(THH) All Outcomes

  45. weather’s clear Paul Revere wins p(win | clear)  p(win, clear) / p(clear) All Outcomes (races) Random Variables: What is “variable” in “p(variable=value)”? • p(weather’s clear) • Outcome is a race • weather’s clear is true or false of the outcome • So p(weather’s clear)= p(weather’s clear(Outcome) =true) picks out the set of outcomes with clear weather

  46. Random Variables: What is “variable” in “p(variable=value)”? • p(x1=h) * p(x2=o | x1=h) * … • Outcome is a sequence of letters • x2is the second letter in the sequence • So p(x2=o) = p(x2(Outcome)=o) picks out set of outcomes with … = p(Outcome) over all outcomes whose second letter … = p(horses) + p(boffo) + p(xoyzkklp) + …

  47. the parameters of our old trigram generator! Same assumptions about language. values of those parameters, as naively estimated from Brown corpus. Back to trigram model of p(horses) p(x1=h, x2=o, x3=r, x4=s, x5=e, x6=s, …)  t BOS, BOS,h * t BOS, h,o * t h, o,r * t o, r,s * t r, s,e * t s,e,s * … 4470/ 52108 395/ 4470 1417/ 14765 1573/ 26412 1610/ 12253 2044/ 21250 counts from Brown corpus This notation emphasizes that they’re just real variables whose value must be estimated

  48. A Different Model • Exploit fact that horses is a common word p(W1 = horses) where word vector W is a function of the outcome (the sentence) just as character vector X is. = p(Wi = horses | i=1) • p(Wi = horses) = 7.2e-5 independence assumption says that sentence-initial words w1 are just like all other words wi (gives us more data to use) Much larger than previous estimate of 5.4e-7 – why? Advantages, disadvantages?

  49. Measure Performance! • Which model does better on language ID? • Administer test where you know the right answers • Seal up test data until the test happens • Simulates real-world conditions where new data comes along that you didn’t have access to when choosing or training model • In practice, split off a test set as soon as you obtain the data, and never look at it • Need enough test data to get statistical significance • Report all results on test data • For a different task (e.g., speech transcription instead of language ID), use that task to evaluate the models

  50. Cross-Entropy (“xent”) • Another common measure of model quality • Task-independent • Continuous – so slight improvements show up here even if they don’t change # of right answers on task • Just measure probability of (enough) test data • Higher prob means model better predicts the future • There’s a limit to how well you can predict random stuff • Limit depends on “how random” the dataset is (easier to predict weather than headlines, especially in Arizona)

More Related