32
ANLP Lecture 21 Distributional Semantics Shay Cohen (Based on slides by Henry Thompson and Sharon Goldwater) 1 November 2019

ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

ANLP Lecture 21Distributional Semantics

Shay Cohen(Based on slides by Henry Thompson and Sharon Goldwater)

1 November 2019

Page 2: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Example Question (5)

I Question

What is a good way to remove wine stains?

I Text available to the machineSalt is a great way to eliminate wine stains

I What is hard?I words may be related in other ways, including similarity and

gradationI how to know if words have similar meanings?

Page 3: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Can we just use a thesaurus?I A thesaurus is a synonym (and sometimes antonym)

dictionaryI Organised by a hierarchy of meaning classesI First, famous, one for English by Roget published in 1852

First edition entry for Existence: Ens, entity, being, existence,essence...

I WordNet is a super-thesaurus in digital formI The next slide shows paired entries

I One from the original English versionI One from a Chinese version

Page 4: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

07200527-n (12) answer 回答

the speech act of replying to a question

06746005-n (56) answer, reply, response 答复, 回答

a statement (either spoken or written) that is made to reply to a question or request or criticism or accusation

00636279-v (7) V2

answer 解决, 回答

give the correct answer or solution to

00815686-v (123) V1, V2

answer, reply, respond 答应, 答复, 回, 答覆

, 响应, 回答

react verbally

Extract from Open Multilingual Wordnet 1.2 from results of searching for answer in English and Chinese (simplified).

Page 5: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Problems with thesauri/Wordnet

Not every language has a thesaurusEven for the ones that we do have, many words and phrases will bemissingSo, let’s try to compute similarity automatically

I Context is the key

Page 6: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Meaning from context(s)

I Consider the example from J&M (quoted from earlier sources):

a bottle of tezguino is on the tableeverybody likes tezguinotezguino makes you drunkwe make tezguino out of corn

Page 7: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Distributional hypothesis

I Perhaps we can infer meaning just by looking at the contextsa word occurs in

I Perhaps meaning IS the contexts a word occurs in (!)I Either way, similar contexts imply similar meanings:

I This idea is known as the distributional hypothesis

Page 8: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

“Distribution”: a polysemous word

I Probability distribution: a function from outcomes to realnumbers

I Linguistic distribution: the set of contexts that a particularitem (here, word) occurs inI Sometimes displayed in Keyword In Context (KWIC) format:

category error was partly the answer to the uncouth question, sinceLeg was governor, and the answer was ”one Leg”, and the

But Greg knew he would answer his questions about anyone localTrent didn’t bother to answer.not provide the sort of answer we want, we can always

we dismiss (5) with the answer ”Yes we do”! RegardingThe answer is simple – speed up your

and so he’d always answer back and say I wantdoing anything else is one answer often suggested.

Taken at random from the British National Corpus

Page 9: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Distributional semantics: basic idea

I Represent each word wi as a vector of its contextsI distributional semantic models also called vector-space

models

I Ex: each dimension is a context word; = 1 if it co-occurs withwi , otherwise 0.

pet bone fur run brown screen mouse fetch

w1 = 1 1 1 1 1 0 0 1w2 = 1 0 1 0 1 0 1 0w3 = 0 0 0 1 0 1 1 0

I Note: real vectors would be far more sparse

Page 10: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Questions to consider

I What defines “context”? (What are the dimensions, whatcounts as co-occurrence?)

I How to weight the context words (Boolean? counts? other?)

I How to measure similarity between vectors?

Page 11: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Defining the context

I Usually ignore stopwords (function words and other veryfrequent/uninformative words)

I Usually use a large window around the target word (e.g., 100words, maybe even whole document)

I Can use just cooccurrence within window, or may requiremore (e.g., dependency relation from parser)

I Note: all of these for semantic similarityI For syntactic similarity, use a small window (1-3 words) and

track only frequent words

Page 12: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

How to weight the context words

I Binary indicators not very informative

I Presumably more frequent co-occurrences matter moreI But, is frequency good enough?

I Frequent words are expected to have high counts in thecontext vector

I Regardless of whether they occur more often with this wordthan with others

Page 13: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Collocations

I We want to know which words occur unusually often in thecontext of w : more than we’d expect by chance?

I Put another way, what collocations include w?

Page 14: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Mutual information

I One way: use pointwise mutual information (PMI):

PMI(x , y) = log2P(x , y)

P(x)P(y)

Observed probability of seeing words⇐ x and y together⇐ Predicted probability of same,

if x and y are independent

I PMI tells us how much more/less likely the cooccurrence isthan if the words were independent

= 0 independent as predicted> 0 friends occur together more than predicted< 0 enemies occur together less than predicted

Page 15: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

A problem with PMI

I In practice, PMI is computed with counts (using MLE)

I Result: it is over-sensitive to the chance co-occurrence ofinfrequent words

I See next slide: ex. PMIs from bigrams with 1 count in 1st1000 documents of NY Times corpusI About 633, 000 words, compared to 14, 310, 000 in the whole

corpus

Page 16: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Example PMIs (Manning & Schutze, 1999, p181)

These values are are 2–4 binary orders of magnitude higher thanthe corresponding estimates based on the whole corpus

Page 17: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Alternatives to PMI for finding collocations

I There are a lot, all ways of measuring statistical(in)dependenceI Student t-testI Pearson’s χ2 statisticI Dice coefficientI likelihood ratio test (Dunning, 1993)I Lin association measure (Lin, 1998)I and many more...

I Of those listed here, the Dunning LR test is probably the mostreliable for low counts

I However, which works best may depend on particularapplication/evaluation

Page 18: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Improving PMI

Rather than using a different method, PMI itself can be modifiedto better handle low frequenciesI Use positive PMI (PPMI): change all negative PMI values to

0I Because for infrequent words, not enough data to accurately

determine negative PMI values

I Introduce smoothing in PMI computationI See J&M (3rd ed.) Ch 6.7 for a particularly effective method

discussed by Levy, Goldberg and Dagan 2015

Page 19: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

How to measure similarity

I So, let’s assume we have context vectors for two words ~v and~w

I Each contains PMI (or PPMI) values for all context wordsI One way to think of these vectors: as points in

high-dimensional spaceI That is, we embed words in this spaceI So the vectors are also called word embeddings

Page 20: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Vector space representation

I Example, in 2-dimensional space: cat = (v1, v2), computer= (w1,w2)

Page 21: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Euclidean distance

I We could measure (dis)similarity using Euclidean distance:(∑i (vi − wi )

2)1/2

I But doesn’t work well if even one dimension has an extremevalue

Page 22: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Dot product

I Another possibility: take the dot product of ~v and ~w :

simDP(~v , ~w) = ~v · ~w=

∑i

viwi

I Gives a large value if there are many cases where vi and wi areboth large: vectors have similar counts for context words

Page 23: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Normalized dot product

I Some vectors are longer than others (have higher values):

[5, 2.3, 0, 0.2, 2.1] vs. [0.1, 0.3, 1, 0.4, 0.1]

I If vector is context word counts, these will be frequent wordsI If vector is PMI values, these are likely to be infrequent words

I Dot product is generally larger for longer vectors, regardless ofsimilarity

Page 24: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Normalized dot product

I Some vectors are longer than others (have higher values):[5, 2.3, 0, 0.2, 2.1] vs. [0.1, 0.3, 1, 0.4, 0.1]

I If vector is context word counts, these will be frequent wordsI If vector is PMI values, these are likely to be infrequent words

I Dot product is generally larger for longer vectors, regardless ofsimilarity

I To correct for this, we normalize: divide by the length of

each vector:

simNDP(~v , ~w) = (~v · ~w)/(|~v ||~w |)

Page 25: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Normalized dot product = cosine

I The normalized dot product is just the cosine of the anglebetween vectors

I Ranges from -1 (vectors pointing opposite directions) to 1(same direction)

Page 26: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Other similarity measures

I Again, many alternativesI Jaccard measureI Dice measureI Jenson-Shannon divergenceI etc.

I Again, may depend on particular application/evaluation

Page 27: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Evaluation

I Extrinsic may involve IR, QA, automatic essay marking, ...I Intrinsic is often a comparison to psycholinguistic data

I Relatedness judgmentsI Word association

Page 28: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Relatedness judgments

I Participants are asked, e.g.: on a scale of 1-10, how relatedare the following concepts?

LEMON FLOWERI Usually given some examples initially to set the scale , e.g.

I LEMON-TRUTH = 1I LEMON-ORANGE = 10

I But still a funny task, and answers depend a lot on how thequestion is asked (‘related’ vs. ‘similar’ vs. other terms)

Page 29: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Word association

I Participants see/hear a word, say the first word that comes tomind

I Data collected from lots of people provides probabilities ofeach answer:

ORANGE 0.16SOUR 0.11TREE 0.09

LEMON ⇒ YELLOW 0.08TEA 0.07JUICE 0.05PEEL 0.04BITTER 0.03...

Example data from the Edinburgh Associative Thesaurus:

http://www.eat.rl.ac.uk/

Page 30: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Comparing to human data

I Human judgments provide a ranked list of relatedwords/associations for each word w

I Computer system provides a ranked list of most similar wordsto w

I Compute the Spearman rank correlation between the lists(how well do the rankings match?)

I Often report on several data sets, as their details differ

Page 31: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Learning a more compact space

I So far, our vectors have length V , the size of the vocabulary

I Do we really need this many dimensions?

I Can we represent words in a smaller dimensional space thatpreserves the similarity relationships of the larger space?

Page 32: ANLP Lecture 21 Distributional SemanticsExample Question (5) I Question What is a good way to remove wine stains? I Text available to the machine Salt is a great way to eliminate wine

Learning a more compact space

I So far, our vectors have length V , the size of the vocabulary

I Do we really need this many dimensions?

I Can we represent words in a smaller dimensional space thatpreserves the similarity relationships of the larger space?

We’ll talk about these ideas next week