Presentazione di Pierpaolo Basile, durante il suo talk dal titolo "Geometria e Semantica del Linguaggio.
L'incontro si è tenuto il giorno 17 Dicembre 2014 all'interno del progetto SSC (Scientific Storming Café).
L'abstract del talk è "Rappresentare concetti in uno spazio geometrico è una tecnica ampiamente utilizzata nell'informatica per modellare la semantica del linguaggio naturale. Ad esempio i motori di ricerca che interroghiamo ogni giorno utilizzano la geometria per rappresentare parole e documenti. Obiettivo del talk è introdurre i concetti di base dei modelli di semantica distribuzionale e presentare alcuni operatori geometrici per la composizione dei termini per rappresentare concetti più complessi come frasi o interi documenti"
2. Il significato nel mondo reale
Rappresentazione estensionale del significato!
automobile
3. Il significato nel mondo reale
Rappresentazione intensionale del significato!
automòbile agg. e s. f. [dal fr. automobile ‹otomobìl›, comp. di auto-1 e dell’agg. lat.
mobĭlis «che si muove»]. – 1. agg. Che si muove da sé, soprattutto con riferimento a
veicoli che si muovono sul terreno (o anche nell’acqua, come per es. i mezzi
autopropulsi, quali i siluri e i missili) per mezzo di un motore proprio. 2. s. f.
Autoveicolo a quattro ruote con motore generalmente a scoppio, adibito al trasporto di
un numero limitato di persone su strade ordinarie (detto, nelle... Leggi
AUTOMOBILE
automobile
4. Il significato nella nostra mente
La rappresentazione del concetto
AUTOMOBILE nella nostra mente
Connessionisti
(reti neurali)
Simbolici
(formalismo logico)
5. Il significato nel testo
Semantica distribuzionale: cosa è un’automobile?
AUTOMOBILE è l’insieme dei contesti
linguistici in cui la parola automobile
occorre
6. A bottle of Tezguno is on the table.
Everyone likes Tezguno.
Tezguno makes you drunk.
We make Tezguno out of corn.
What’s Tezguno?
8. Modelli distribuzionali semantici
• Modelli computazionali che costruiscono
rappresentazioni semantiche delle parole
analizzando dei corpora
– Le parole sono rappresentate tramite vettori
– I vettori sono costruiti analizzando statisticamente
i contesti linguistici in cui le parole occorrono
9. Vettore distribuzionale
1. contare quante volte una parola occorre in
un determinato contesto
2. costruire un vettore in funzione delle
occorrenze calcolate al punto 1
PAROLE SIMILI AVRANNO VETTORI SEMILI
12. Matrice = Spazio geometrico
C3
C5
pasta
topo
cane
gatto
Similarità->vicinanza in uno spazio
multi-dimensionale
(similarità del coseno)
13. Generalizzazione
• Un modello distribuzionale può essere
definito da <T, C, R, W, M, d, S>
– T: target elements -> le parole (generalmente)
– C: i contesti
– R: la relazione che lega T a C
– W: schema di pesatura
– M: spazio geometrico TxC
– d: funzione di riduzione dello spazio M -> M’
– S: funzione di similarità in M’
14. Costruire uno spazio semantico
1. Pre-processing del corpus
2. Individuare parole e contesti
3. Contare le co-occorrenze parole/contesti
4. Pesatura (opzionale, ma consigliata)
5. Costruzione della matrice TxC
6. Riduzione della matrice (opzionale)
7. Calcolare la similarità tra vettori
15. I parametri
• La definizione di contesto
– Una finestra di dimensione n, frase, paragrafo,
documento, un particolare contesto sintattico
• Schema di pesatura
• Funzione di similarità
16. Un esempio
• Matrice Termini-Termini
– T: parole
– C: parole
– R: T occorre «vicino» a C
– W: numero di volte che T e C co-occorrono
– M: matrice termini/termini
– d: nessuna o ad esempio SVD (Latent Semantic
Analysis)
– S: similarità del coseno
17. 1. pre-processing
• Tokenizzazione necessaria!
– PoS-tag
– Lemmatizazzione
– Parsing
• Un’analisi troppo profonda
– Introduce errori
– Richiede altri parametri
– Dipende dalla lingua
• Pre-processing influisce sulla scelta delle parole e
dei contesti
18. 2. Definizione del contesto
• Il documento
– l’intero documento
– paragrafo, frase, porzione di testo (passage)
• Le altre parole
– In genere si scelgono le n più frequenti
– Dove?
• ad un distanza fissata a priori (finestra)
• dipendenza sintattica
• pattern
19. 3. Pesatura
• Frequenza o log(frequenza) per mitigare i
contesti che occorrono tante volte
• Idea: se l’occorrenza è più bassa significa che
la relazione è più forte
– Mutual Information, Log-Likelihood Ratio
• Information Retrieval: tf-idf, word-entropy, …
21. 5. Riduzione della matrice
• M (TxC) è una matrice altamente
dimensionale può essere utile ridurla:
1. Individuare le dimensioni latenti: LSI, PCA
2. Ridurre lo spazio: approssimazioni di M ad
esempio Random Indexing
23. Il metodo
• Assegnare un “vettore random” ad ogni
contesto: random/context vector
• Il vettore semantico associato ad ogni target
(e.s. parole) è la somma di tutti i vettori
contesto in cui il target (parola) occorre
24. Vettore contesto
• sparso
• altamente dimensionale
• ternario, valori in {-1, 0, +1}
• un piccolo numero di elementi non nulli
distribuiti casualmente
0 0 0 0 0 0 0 -1 0 0 0 0 1 0 0 -1 0 1 0 0 0 0 1 0 0 0 0 -1
24
27. Random Indexing
• Vantaggi
– Semplice e veloce
– Scalabile e parallelizzabile
– Incrementale
• Svantaggi
– Richiede molta memoria
28. Permutazioni
• Utilizzare diverse permutazioni degli elementi
del vettore random per codificare diversi
contesti
– l’ordine delle parole
– dipendenza (sintattica/relazionale) tra termini
• Il vettore random prima di essere sommato
viene permutato in base al contesto che si sta
codificando
30. Permutazioni (query)
• In fase di query applicare la permutazione
inversa in base al contesto
• Word order: <t> ? (i termini più simili che si
trovano a destra di <t>)
– Permutare -1 il vettore random di t R-1t
• t deve comparire a sinistra
– Calcolare la similarità di R-1t con tutti i vettori
presenti nel term space
32. Simple DSMs…
Term-term co-occurrence matrix (TTM): each
cell contains the co-occurrences between two
terms within a prefixed distance
dog cat computer animal mouse
dog 0 4 0 2 1
cat 4 0 0 3 5
computer 0 0 0 0 3
animal 2 3 0 0 2
mouse 1 5 3 2 0
33. …Simple DSMs
Latent Semantic Analysis (LSA): relies on the
Singular Value Decomposition (SVD) of the co-
occurrence matrix
Random Indexing (RI): based on the Random
Projection
Latent Semantic Analysis over Random Indexing
(RILSA)
34. Latent Semantic Analysis over Random
Indexing
1. Reduce the dimension of the co-occurrences
matrix using RI
2. Perform LSA over RI (LSARI)
– reduction of LSA computation time: RI matrix
contains less dimensions than co-occurrences
matrix
35. Simple operators…
Addition (+): pointwise sum of components
Multiplication (∘): pointwise multiplication of
components
Addition and multiplication are commutative
– do not take into account word order
Complex structures represented summing or
multiplying words which compose them
36. …Simple operators
Given two word vectors u and v
– composition by sum p = u + v
– composition by multiplication p = u ∘ v
Can be applied to any sequence of words
40. Representing dependences
Use filler/role binding approach to represent a
dependency dep(u, v)
rd⊚u + rh⊚v
rd and rh are vectors which represent
respectively the role of dependent and head
⊚ is a placeholder for a composition operator
42. Structured DSMs
1. Vector permutation in RI (PERM) to encode
dependencies
2. Circular convolution (CONV) as filler/binding
operator to represent syntactic dependencies
in DSMs
3. LSA over PERM and CONV carries out two
spaces: PERMLSA and CONVLSA
43. Vector permutation in RI (PERM)
Using permutation of elements in context
vectors to encode dependencies
– right rotation of n elements to encode
dependents (permutation)
– left rotation of n elements to encode heads
(inverse permutation)
43
44. PERM (method)
Create and assign a context vector to each term
Assign a rotation function Π+1 to the dependent and
Π-1 to the head
Each term is represented by a vector which is
– the sum of the permuted vectors of all the dependent
terms
– the sum of the inverse permuted vectors of all the
head terms
– the sum of the no-permuted vectors of both
dependent and head words
44
45. PERM (example…)
John eats a red apple
John -> (0, 0, 0, 0, 0, 0, 1, 0, -1, 0)
eat -> (1, 0, 0, 0, -1, 0, 0 ,0 ,0 ,0)
red -> (0, 0, 0, 1, 0, 0, 0, -1, 0, 0)
apple -> (1, 0, 0, 0, 0, 0, 0, -1, 0, 0)
TVapple = Π+1(CVred) + Π-1(CVeat) + CVred + CVeat
45
apple
red
eats
47. Convolution (CONV)
Create and assign a context vector to each term
Create two context vectors for head and dependent
roles
Each term is represented by a vector which is
– the sum of the convolution between dependent terms
and the dependent role vector
– the sum of the convolution between head terms and
the head role vector
– the sum of the vectors of both dependent and head
words
49. Circular convolution by FFTs
Circular convolution is computed in O(n2)
– using FFTs is computed in O(nlogn)
Given f the discrete FFTs and f -1 its inverse
– u ⊛v = f -1( f(u) ∘ f (v) )
50. CONV (example)
John eats a red apple
John -> (0, 0, 0, 0, 0, 0, 1, 0, -1, 0)
eat -> (1, 0, 0, 0, -1, 0, 0 ,0 ,0 ,0)
red-> (0, 0, 0, 1, 0, 0, 0, -1, 0, 0)
apple -> (1, 0, 0, 0, 0, 0, 0, -1, 0, 0)
rd -> (0, 0, 1, 0, -1, 0, 0, 0, 0, 0)
rh -> (0, -1, 1, 0, 0, 0, 0, 0, 0, 0)
apple = eat +red + (rd⊛ red) + (rh ⊛ eat)
50
Context vector for dependent role
Context vector for head role
51. Complex operators
Based on filler/role binding taking into account
syntactic role: rd ⊚ u + rh ⊚ v
– u and v could be recursive structures
Two vector operators to bind the role:
– convolution (⊛)
– tensor (⊗)
– convolution (⊛+): exploits also the sum of term
vectors
rd ⊛ u + rh ⊛ v + v + u
52. Complex operators (remarks)
Existing operators
– t1 ⊚ t2 ⊚ … ⊚ tn: does not take into account
syntactic role
– t1 ⊛ t2 is commutative
– t1⊗t2 ⊗ … ⊗tn: tensor order depends on the
phrase length
• two phrases with different length are not comparable
– t1 ⊗ r1 ⊗t2 ⊗r2 ⊗ … ⊗ tn ⊗rn : also depends on
the sentence length
53. System setup
• Corpus
– WaCkypedia EN based on a 2009 dump of Wikipedia
– about 800 million tokens
– dependency parse by MaltParser
• DSMs
– 500 vector dimension (LSA/RI/RILSA)
– 1,000 vector dimension (PERM/CONV/PERMLSA/CONVLSA)
– 50,000 most frequent words
– co-occurrence distance: 4
53
54. Evaluation
• GEMS 2011 Shared Task for compositional
semantics
– list of two pairs of words combination
(support offer) (help provide) 7
(old person) (right hand) 1
• rated by humans
• 5,833 rates
• 3 types involved: noun-noun (NN), adjective-noun (AN),
verb-object (VO)
– GOAL: compare the system performance against
humans scores
• Spearman correlation
54
57. Final remarks
• Best results are obtained when complex
operators/spaces (or both) are involved
• No best combination of operator/space exists
– depend on the type of relation (NN, AN, VO)
• Tensor product and convolution provide good results in
spite of previous results
– filler/role binding is effective
• Future work
– generate several rd and rh vectors for each kind of
dependency
– apply this approach to other direct graph-based
representations
58. Thank you for your attention!
Questions?
<pierpaolo.basile@uniba.it>