LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

37
LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO

Transcript of LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

Page 1: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

LINGUISTICA GENERALE E COMPUTAZIONALE

DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO

Page 2: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

2

POS tagging: the problem

• People/NNS continue/VBP to/TO inquire/VB the/DT reason/NN for/IN the/DT race/NN for/IN outer/JJ space/NN

• Problem: assign a tag to race• Requires: tagged corpus

Page 3: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

3

Ambiguity in POS tagging

The ATman NN VBstill NN VB RBsaw NN VBDher PPO PP$

Page 4: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

4

How hard is POS tagging?

Number of tags 1 2 3 4 5 6 7

Number of words types

35340 3760 264 61 12 2 1

In the Brown corpus,- 11.5% of word types ambiguous- 40% of word TOKENS

Page 5: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

5

Frequency + Context

• Both the Brill tagger and HMM-based taggers achieve good results by combining– FREQUENCY

• I poured FLOUR/NN into the bowl.• Peter should FLOUR/VB the baking tray

– Information about CONTEXT • I saw the new/JJ PLAY/NN in the theater.• The boy will/MD PLAY/VBP in the garden.

Page 6: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

6

The importance of context

• Secretariat/NNP is/VBZ expected/VBN to/TO race/VB tomorrow/NN

• People/NNS continue/VBP to/TO inquire/VB the/DT reason/NN for/IN the/DT race/NN for/IN outer/JJ space/NN

Page 7: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

TAGGED CORPORA

Page 8: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

8

Choosing a tagset

• The choice of tagset greatly affects the difficulty of the problem

• Need to strike a balance between– Getting better information about context (best:

introduce more distinctions)– Make it possible for classifiers to do their job

(need to minimize distinctions)

Page 9: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

9

Some of the best-known Tagsets

• Brown corpus: 87 tags• Penn Treebank: 45 tags• Lancaster UCREL C5 (used to tag the BNC): 61

tags• Lancaster C7: 145 tags

Page 10: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

10

Important Penn Treebank tags

Page 11: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

11

Verb inflection tags

Page 12: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

12

The entire Penn Treebank tagset

Page 13: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

13

UCREL C5

Page 14: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

14

Tagsets per l’italiano

Si-TAL (Pisa, Venezia, IRST, ....)

PAROLE

TEXTPRO (dopo)

Page 15: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

15

Il tagset di SI-TAL

Page 16: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

16

POS tags in the Brown corpus

Television/NN has/HVZ yet/RB to/TO work/VB out/RP a/AT living/RBG arrangement/NN with/IN jazz/NN ,/, which/VDT comes/VBZ to/IN the/AT medium/NN more/QL as/CS an/AT uneasy/JJ guest/NN than/CS as/CS a/AT relaxed/VBN member/NN of/IN the/AT family/NN ./.

Page 17: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

17

SGML-based POS in the BNC

<div1 complete=y org=seq> <head> <s n=00040> <w NN2>TROUSERS <w VVB>SUIT </head> <caption> <s n=00041> <w EX0>There <w VBZ>is <w PNI>nothing <w AJ0>masculine <w PRP>about <w DT0>these <w AJ0>new <w NN1>trouser <w NN2-VVZ>suits <w PRP>in <w NN1>summer<w POS>'s <w AJ0>soft <w NN2>pastels<c PUN>. <s n=00042> <w NP0>Smart <w CJC>and <w AJ0>acceptable <w PRP>for <w NN1>city <w NN1-VVB>wear <w CJC>but <w AJ0>soft <w AV0>enough <w PRP>for <w AJ0>relaxed <w NN2>days </caption>

Page 18: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

18

Quick test

DoCoMo and Sony are to develop a chip that would let people pay for goods through their mobiles.

Page 19: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

POS TAGGED CORPORA IN NLTK

>>> tagged_token = nltk.tag.str2tuple('fly/NN') >>> tagged_token('fly', 'NN') >>> tagged_token[0] 'fly' >>> tagged_token[1] 'NN'

>>> nltk.corpus.brown.tagged_words() [('The', 'AT'), ('Fulton', 'NP-TL'), ('County', 'NN-TL'), ...]

Page 20: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

Exploring tagged corpora

• Ch.5, p. 184-189

Page 21: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

OTHER POS-TAGGED CORPORA

• NLTK:• WAC Corpora:

– English: UKWAC– Italian: ITWAC

Page 22: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

POS TAGGING

Page 23: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

23

Markov Model POS tagging

• Again, the problem is to find an `explanation’ with the highest probability:

• As in the lecture on text classification, this can be ‘turned around’ using Bayes’ Rule:

)..|..(argmax 11Tt

nn wwttPi

)..(

)..()..|..(argmax

1

111

n

nnn

wwP

ttPttwwP

Page 24: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

24

Combining frequency and contextual information

• As in the case of spelling, this equation can be simplified:

• As we will see, once further simplifications are applied, this equation will encode both FREQUENCY and CONTEXT INFORMATION

prior

1

likelihood

11 )..()..|..(argmax nnn ttPttwwP

Page 25: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

25

Three further assumptions

• MARKOV assumption: a tag only depends on a FIXED NUMBER of previous tags (here, assume bigrams)– Simplify second factor

• INDEPENDENCE assumption: words are independent from each other.

• A word’s identity only depends on its own tag– Simplify first factor

Page 26: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

26

The final equations

FREQUENCYCONTEXT

Page 27: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

27

Estimating the probabilities

Can be done using Maximum Likelihood Estimation as usual, for BOTH probabilities:

Page 28: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

28

An example of tagging with Markov Models :

• Secretariat/NNP is/VBZ expected/VBN to/TO race/VB tomorrow/NN

• People/NNS continue/VBP to/TO inquire/VB the/DT reason/NN for/IN the/DT race/NN for/IN outer/JJ space/NN

• Problem: assign a tag to race given the subsequences– to/TO race/???– the/DT race/???

• Solution: we choose the tag that has the greater of these probabilities:– P(VB|TO) P(race|VB)– P(NN|TO)P(race|NN)

Page 29: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

29

Tagging with MMs (2)• Actual estimates from the Switchboard corpus:• LEXICAL FREQUENCIES:

– P(race|NN) = .00041– P(race|VB) = .00003

• CONTEXT:– P(NN|TO) = .021– P(VB|TO) = .34

• The probabilities:– P(VB|TO) P(race|VB) = .00001– P(NN|TO)P(race|NN) = .000007

Page 30: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

30

A graphical interpretation of the POS tagging equations

Page 31: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

31

Hidden Markov Models

Page 32: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

32

An example

Page 33: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

33

Computing the most likely sequence of tags

• In general, the problem of computing the most likely sequence t1 .. tn could have exponential complexity

• It can however be solved in polynomial time using an example of DYNAMIC PROGRAMMING: the VITERBI ALGORITHM (Viterbi, 1967)

• (Also called TRELLIS ALGORITHMs)

Page 34: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

POS TAGGING IN NLTK

DEFAULT POS TAGGER: nltk.pos_tag

>>> text = nltk.word_tokenize("And now for something completely different")>>> nltk.pos_tag(text) [('And', 'CC'), ('now', 'RB'), ('for', 'IN'), ('something', 'NN'), ('completely', 'RB'), ('different', 'JJ')]

Page 35: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

TEXTPRO

• The most widely used NLP tool for Italian• http://textpro.fbk.eu/• Demo

Page 36: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

THE TEXTPRO TAGSET

Page 37: LINGUISTICA GENERALE E COMPUTAZIONALE DISAMBIGUAZIONE DELLE PARTI DEL DISCORSO.

READINGS

• Bird et al, chapter 5, chapter 6.1