Statistical and Adaptive Natural Language Processing T-61.5020 (5 cr) L, Spring 2007 Sixth lecture Contextual Information and Compositionality Lecturer: Mathias Creutz Slides: Krista Lagus, Mathias Creutz, Timo Honkela
6. Contextual Information and Compositionality....................... 3 6.1 Word Context: Meaning Is Use.......... 4 6.2 Expressions with Limited Compositionality: Collocations..................... 7 6.3 Hypothesis Testing (for the Discovery of Collocations)........................ 15 6.4 Compositionality Within Words........... 29 2
6. Contextual Information and Compositionality The importance of context in the interpretation of language: for instance ambiguous word meanings: Aloitin alusta. Alusta kovalevy! Näin monta alusta. Compositionality of meaning and form (within and beyond words): I saw you yesterday. (= i + see + you + yesterday) openmindedness (= open + mind + -ed + -ness) What is chewing gum made of? The New Scientist reports that people who chewed gum during the memory tests scored higher than those who did not. How do you do. 3
6.1 Word Context: Meaning Is Use What is meaning? What is meaning in language? cognitive linguistics (1970 ) vs. structuralists (18xx 1970) Words are not labels for real things in the world. They refer to ideas that we have of the world. (Saussure) To understand a particular word, one has to know in which possible combinations with other words it occurs. Consider less obvious cases such as time, consider, the, of. (Harris) You shall know a word by the company it keeps. (Firth) Meaning is use. (Wittgenstein) Computational approach: The typical context in which a word occurs can be used to characterize the word in relation to other words. 4
Types of Contexts n-grams, dynamical context I don t like... fixed window, word-document matrix I don t like icecream, but I do like cookies. Represent words as vectors bag of words vs. position sensitivity Are different positions in the word context mapped onto different subvectors? distant dependencies and phrasal structure: 5
Example: Phrasal Structure Using Functional Dependency Grammar (FDG) President Bush gave the Idol finalists a tour of the White House. 6
6.2 Expressions with Limited Compositionality: Collocations Kollokaatio on kahdesta tai useammasta sanasta koostuva konventionaalistunut ilmaus Esimerkkejä: weapons of mass destruction, disk drive, part of speech (suomessa yhdyssanoina joukkotuhoaseet, levyasema, sanaluokkatieto ) bacon and eggs verbin valinta: make a decision ei take a decision. adjektiivin valinta: strong tea mutta ei powerful tea ; vahvaa teetä, harvemmin voimakasta teetä (valinnat voivat heijastaa kulttuurin asenteita: strong tea, coffee, cigarettes powerful drugs, antidote) 7
kick the bucket, heittää veivinsä (kiertoilmaus, sanonta, idiomi) Olentoja, yhteisöjä, paikkoja tai tapahtumia yksilöivät nimet: White House Valkoinen talo, Tarja Halonen Kollokaation kanssa osittain päällekkäisiä käsitteitä: termi, tekninen termi, terminologinen fraasi. Huom: tiedonhaussa sanalla termi laajempi merkitys: sana tai kollokaatio. 8
Sanan frekvenssi ja sanaluokkasuodatus Pelkän frekvenssin käyttö: Esimerkki: Onko luontevampaa sanoa strong tea vai powerful tea? Ratkaisu: Etsitään Googlella: strong tea 9270, powerful tea 201 Joihinkin täsmällisiin kysymyksiin riittävä tapa. Kuitenkin järjestettäess bigrammeja frekvenssin mukaan, parhaita ovat of the, in the, to the,... Frekvenssi + sanaluokka: Jos tunnetaan kunkin sanan sanaluokka, sekä osataan kuvailla kollokaatioiden sallitut sanaluokkahahmot: Järjestetään sanaparit tai -kolmikot yleisyyden (lukumäärä) mukaan Hyväksytään vain tietyt sanaluokkahahmot: AN, NN, AAN, ANN, NAN, NNN, NPN (Justeson & Katz s POS filter) 9
10
Sanojen etäisyyden keskiarvo ja varianssi Entä joustavammat kollokaatiot, joiden keskellä on kollokaatioon kuulumattomia sanoja? Lasketaan etäisyyden keskiarvo ja varianssi. Jos keskiarvo nollasta poikkeava ja varianssi pieni, potentiaalinen kollokaatio (Huom: oletetaan siis etäisyyden jakautuvan gaussisesti). Esim. knock... door (ei hit, beat, tai rap ): a) She knocked on his door b) They knocked at the door c) 100 women knocked on Donaldson s door d) a man knocked on the metal front door 11
Algoritmi Liu uta kiinteän kokoista ikkunaa tekstin yli (leveys esim. 9) ja kerää kaikki sanaparin esiintymät koko tekstissä Laske sanojen etäisyyksien keskiarvo: d = 1/n n i=1 d i = 1/4(3 + 3 + 5 + 5) = 4.0 (jos heittomerkki ja s lasketaan sanoiksi) Estimoi varianssi s 2 (pienillä näytemäärillä): s 2 P n i=1 = (d i d) 2 = 1/3((3 4.0) 2 +(3 4.0) 2 +(5 4.0) 2 +(5 4.0) 2 ) n 1 s = 1.15 12
13
Pohdittavaksi: 1. Mitä tapahtuu jos sanoilla on kaksi tai useampia tyypillisiä positioita suhteessa toisiinsa? 2. Mikä merkitys on ikkunan leveydellä? 14
6.3 Hypothesis Testing (for the Discovery of Collocations) Onko suuri osumamäärä yhteensattumaa (esim. johtuen siitä että jommankumman perusfrekvenssi on suuri)? Osuvatko kaksi sanaa yhteen useammin kuin sattuma antaisi olettaa? 1. Formuloi nollahypoteesi H 0 : assosiaatio on sattumaa 2. Laske tn p että sanat esiintyvät yhdessä jos H 0 on tosi 3. Hylkää H 0 jos p liian alhainen, alle merkitsevyystason, esim p < 0.05 tai p < 0.01. Nollahypoteesia varten sovelletaan riippumattomuuden määritelmää. Oletetaan että sanaparin todennäköisyys, jos H 0 sanan oman todennäköisyyden tulo: P (w 1 w 2 ) = P (w 1 )P (w 2 ) on tosi, on kummankin 15
The t Test Tilastollinen testi sille eroaako havaintojoukon odotusarvo oletetun, datan generoineen jakauman odotusarvosta. Olettaa, että todennäköisyydet ovat suunnilleen normaalijakautuneita. t = x µ, jossa (1) s 2 N x, s 2 : näytejoukon keskiarvo ja varianssi, N = näytteiden lukumäärä, ja µ = jakauman keskiarvo. Valitaan haluttu p-taso (0.05 tai pienempi). Luetaan tätä vastaava t:n yläraja taulukosta. Jos t suurempi, H 0 hylätään. 16
Discovery of Collocations Using the t Test Nollahypoteesina että sanojen yhteisosumat ovat satunnaisia: Esimerkki: H 0 : P (new companies) = P (new)p (companies) µ = P (new)p (companies) c(new companies) x = = ˆp c(, ) s 2 = p(1 p) = ˆp(1 ˆp) ˆp (pätee Bernoulli-jakaumalle) N = c(, ) Bernoulli: special case of binomial distribution: b(r; n, p) = ( n r) p r (1 p) n r, such that n = 1 and r {0, 1}. Järjestetään sanat paremmuusjärjestykseen mitan mielessä TAI Hypoteesin testaus: valitaan merkittävyystaso (p=0.05 tai p=0.01) ja katsotaan t-testin taulukosta arvo, jonka ylittäminen tarkoittaa nollahypoteesin hylkäystä. 17
Pearson s Chi-Square Test χ 2 χ 2 -testi mittaa muuttujien välistä riippuvuutta perustuen riippumattomuuden määritelmään: jos muuttujat ovat riippumattomia, yhteisjakauman arvo tietyssä jakauman pisteessä on marginaalijakaumien (reunajakaumien) tulo. Kahden muuttujan jakauma voidaan kuvata 2-ulotteisena kontingenssitaulukkona (r c). Lasketaan kussakin taulukon pisteessä (i, j) erotus havaitun jakauman O (tod. yhteisjakauma) ja odotetun jakauman E (marginaalijakaumien tulo) välillä, ja summataan skaalattuna jakauman odotusarvolla: χ 2 = i,j jossa siis E ( i, j) = O(i, ) O(, j). (O i,j E i,j ) 2 E i,j (2) χ 2 on asymptoottisesti χ 2 -jakautunut. Ongelma kuitenkin: herkkä harvalle datalle. 18
19 Nyrkkisääntö: älä käytä testiä jos N < 20 tai jos 20 N 40 ja jokin E i,j 5
Discovery of Collocations Using the χ 2 Test Formuloidaan ongelma siten että kumpaakin sanaa vastaa yksi satunnaismuuttuja joka voi saada kaksi arvoa (sana joko esiintyy tai ei esiinny yksittäisessä sanaparissa). Sanojen yhteistnjakauma voidaan tällöin esittää 2 2 taulukkoina. Esim. w 1 = new w 1 new w 2 = companies 8 4667 w 2 companies 15280 14287173 2 2-taulukon tapauksessa kaava 2 voidaan johtaa muotoon: χ 2 = N(O 11 O 22 O 12 O 21 ) 2 (O 11 + O 12 )(O 11 + O 21 )(O 12 + O 22 )(O 21 + O 22 ) Järjestetään sanat paremmuusjärjestykseen mitan mielessä TAI Hypoteesin testaus: valitaan merkittävyystaso (p=0.05 tai p=0.01) ja katsotaan χ 2 -taulukosta arvo jonka ylittäminen tarkoittaa nollahypo- 20
teesin hylkäystä. Ongelmallisuus kollokaatioiden tunnistamisen kannalta Tässä soveltamistavassa ei erotella negatiivista ja positiivista riippuvuutta. Ts. jos sanat vierastavat toisiaan, testi antaa myös suuren arvon, koska tällöin sanojen esiintymisten välillä todellakin on riippuvuus. Kollokaatioita etsittäessä ollaan kuitenkin kiinnostuttu vain positiivisista riippuvuuksista. Muita sovelluksia χ 2 -testille: Konekäännös: Kohdistettujen korpusten sana-käännösparien tunnistaminen (cow, vache yhteensattumat johtuvat riippuvuudesta) Metriikka kahden korpuksen väliselle samankaltaisuudelle: n 2- taulukko jossa kullekin tutkittavalle sanalle w i, i (1... n) kerrotaan ko. sanan lukumäärä korpuksessa j 21
Likelihood Ratios Kuinka paljon uskottavampi H 2 on kuin H 1? Lasketaan hypoteesien uskottavuuksien suhde λ: log λ = log L(H 1) L(H 2 ) Esimerkki: H 1 : w 1 ja w 2 riippumattomia: P (w 2 w 1 ) = p = P (w 2 w 1 ) H 2 : w 1 ja w 2 eivät riippumattomia: P (w 2 w 1 ) = p1 p2 = P (w 2 w 1 ) Oletetaan selvä positiivinen riippuvuus, eli p 1 p 2. Käytetään ML-estimaatteja (keskiarvoja) laskettaessa p, p 1 ja p 2 : p = c 2 N, p 1 = c 12 c 1, p 2 = c 2 c 12 N c 1 Oletetaan binomijakaumat. Esim. p(w 2 w 1 ) = b(c 12 ; c 1, p). Ilmaistaan kunkin mallin yhtäaikaa voimassa olevat rajoitteet tulona. Lopputulos: kirjan kaava 5.10. log λ on asymptoottisesti χ 2 -jakautunut. On lisäksi osoitettu että harval- 22
la datalla uskottavuuksien suhteella saadaan parempi approksimaatio χ 2 - jakaumalle kuin χ 2 -testillä. 23
Pointwise Mutual Information Muistellaan entropian H(x) ja yhteisinformaation I(x; y) kaavoja: H(x) = E(log p(x)) I(X; Y ) = H(Y ) H(Y X) = (H(X) + H(Y )) H(X, Y ) = E X,Y (log p(x,y ) p(x)p(y ) ) joka kuvastaa keskimääräistä informaatiota jonka sekä x että y sisältävät. Määritellään pisteittäinen yhteisinformaatio joidenkin tiettyjen tapahtumien x ja y välillä (Fano, 1961): I(x, y) = log p(x,y) p(x)p(y) Voidaanko käyttää kollokaatioiden valintaan? Motivaationa intuitio: jos sanojen välillä on suuri yhteisinformaatio (ts. niiden kummankin kommunikoiman informaation yhteinen osuus on suuri), voisi olettaa että kyse on kollokaatiosta. 24
Taulukosta 5.16 huomataan että jos jompikumpi sanoista on harvinainen, saadaan korkeita lukuja. 25
Täydellisen riippuville sanoille yhteisinformaatio: I(x, y) = log p(x, y) p(x)p(y) = log p(x) p(x)p(y) = log 1 P (y) kasvaa kun sanat muuttuvat harvinaisemmiksi. Ääritilanne: kaksi sanaa esiintyy kumpikin vain kerran, ja tällöin yhdessä. Kuitenkin tällöin evidenssiä kollokaationa toimimisesta on vähän, mikä jää huomiotta. Johtopäätös: Ei kovin hyvä mitta tähän tarkoitukseen, harhaanjohtava etenkin pienille todennäköisyyksille. Seurauksena kärsii datan harvuudesta erityisen paljon. 26
27
Summary: Hypothesis Testing My guess is that you will not use hypothesis testing in order to discover collocations (except in the exercise session and possibly in the exam of this course). However, you will need hypothesis testing if you do research and compare the performance of your system to some other system. You will need to prove that your system performs better than your competitor in a statistically significant way. T-test (assumes Gaussian distribution) Pearson s chi-square test (small sample sizes are not sufficient) Also take a look at (not taught in this course): Sign test Wilcoxon signed-rank test 28
6.4 Compositionality Within Words Just as it may be important to recognize that the vocabulary of a language partly consists of multi-word expressions (collocations), it is important to recognize that words have inner structure and are related to one another. Linguistic morphology studies how words are formed from morphemes, which are the minimal meaningful form-units. Morphemes are portions of utterances that recur in other utterances with approximately the same meaning. For instance, the Finnish morpheme talo (house): aave+talo+i+sta, aika+kaus+lehti+talo+j+en, aika+talo+a, aikuis+koulu+t+us+talo+n, aikuis+talo+uks+i+en, aito+talo+ude+n, akatemia+talo, akatemia+talo+n, akatemia+talo+ssa, akvaario+talo+us, alas+talo, alas+talo+n, alas+talo+on, ala+talo, ala+talo+a, ala+talo+kin, ala+talo+lla, ala+talo+n, ala+talo+on, ala+talo+sta,... 29
Zellig Harris Heuristic Morpheme Segmentation Method (1955) Morpheme boundaries are proposed at intra-word locations with a peak in successor and predecessor variety. Let us take a look at some examples of successor variety: How many different letters can continue an English word starting with d? (day, debt, dig, dog, drill,...) How many different letters can continue a word starting with drea? (dream, dreadful,...) How many different letters can continue a word starting with dream? (dreams, dreamy, dreamily, dreamboat,...) Predecessor variety works in the same way, but the words are read backwards: How many different letters can precede ily at the end of an English word? (dreamily, happily, funnily,...) 30
Example of Harris Method Note that there are more refined versions, e.g., Hafer and Weiss (1974). 31
Statistical Approaches (1995 ) Think of it as a compression problem. If we observe a corpus of natural language containing lots of different word forms, what kind of model could explain the kind of data we observe in an elegant manner? From what kind of lexicon could words such as apple, orange, lemon, juice, applejuice, orangejuice, appletree, lemontree emerge? Suppose that lexicon candidates are created using a statistical generative process: characters are drawn from an alphabet including a morph break character: Lexicon 1 a c e g i j l m n o p r t u P (Lexicon 1) = ( 1 27 )29 Lexicon 2 apple juice lemon orange tree P (Lexicon 2) = ( 1 27 )31 (14 morphs), (5 morphs), Lexicon 3 apple applejuice appletree juice lemon lemontree orange orangejuice (8 morphs), P (Lexicon 3) = ( 1 27 )69 32
Statistical Approaches: Continued Rewrite the words in the corpus (data) as morphs and compute probability (# is a word boundary morph): Data Lexicon 1 a p p l e # o r a n g e # l e m o n # j u i c e # a p p l e j u i c e # o r a n g e j u i c e # a p p l e t r e e # l e m o n t r e e # # The sequence consists of 69 morphs and its probability conditioned on Lexicon 1 is: P (Data Lexicon 1) = ( 1 14+1 )69 7.1 10 82. Data Lexicon 2 apple # orange # lemon # juice # apple juice # orange juice # apple tree # lemon tree # #. The sequence consist of 21 morphs, and P (Data Lexicon 2) = ( 1 5+1 )21 4.6 10 17. Data Lexicon 3 apple # orange # lemon # juice # applejuice # orangejuice # appletree # lemontree # #. The sequence consists of 17 morphs, and P (Data Lexicon 3) = ( 1 8+1 )17 6.0 10 17. 33
Statistical Approaches: Maximum A Posteriori (MAP) Optimization The model selection procedure is based on maximizing the posterior probability of the model P (Lexicon X Data). The posterior can be rewritten using Bayes rule: P (Lexicon X Data) = P (Lexicon X) P (Data Lexicon X) P (Data) P (Lexicon X) P (Data Lexicon X). P (Lexicon 2) P (Data Lexicon 2) 1.9 10 61 > P (Lexicon 3) P (Data Lexicon 3) 1.0 10 115 > P (Lexicon 1) P (Data Lexicon 1) 2.2 10 123. In this comparison the complexity of the model has been balanced against the fit of the training data, which favors a good compromise, that is, a model that does not overlearn and that adequately generalizes to unseen data. 34
Statistical Approaches: Demo Variations of the approach sketched out above have been used for both word segmentation (Asian languages, where words are written without explicit boundaries) and morphology modeling, e.g., Carl de Marcken (1995) Michael R. Brent (1999) John Goldsmith (2001) (Linguistica) Mathias Creutz and Krista Lagus (2002 ) (Morfessor) Sharon Goldwater, Thomas L. Griffiths, and Mark Johnson (2006) Morfessor demo: http://www.cis.hut.fi/projects/morpho/ 35