Matrix algebra & R as a toy DSM laboratory
Distributional Semantic Models Stefan Evert1 & Alessandro Lenci2
1University of Osnabr¨
uck, Germany
2University of Pisa, Italy Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 1 / 71
Matrix algebra & R as a toy DSM laboratory Distributional - - PowerPoint PPT Presentation
Matrix algebra & R as a toy DSM laboratory Distributional Semantic Models Stefan Evert 1 & Alessandro Lenci 2 1 University of Osnabr uck, Germany 2 University of Pisa, Italy Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July
1University of Osnabr¨
2University of Pisa, Italy Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 1 / 71
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 2 / 71
Introduction The DSM matrix
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 3 / 71
Introduction The DSM matrix
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 4 / 71
Introduction Geometric interpretation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 5 / 71
Introduction Geometric interpretation
◮ n = 2 ➜ Euclidean plane ◮ n = 3 ➜ three-dimensional Euclidean space Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 5 / 71
Introduction Geometric interpretation
◮ n = 2 ➜ Euclidean plane ◮ n = 3 ➜ three-dimensional Euclidean space
◮ distance, length, direction, angle, dimension, . . . ◮ intuitive in R2 and R3 ◮ can be generalised to higher dimensions
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 5 / 71
Introduction Geometric interpretation
u = (4, 2)
1 2 3 4 5 1 2 3 4 5 6 6
v = (3, 5)
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 6 / 71
Introduction Geometric interpretation
u = (4, 2)
1 2 3 4 5 1 2 3 4 5 6 6
v = (3, 5) v-u = (-1, 3)
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 7 / 71
Introduction Geometric interpretation
x = (6, 3.5)
1 2 3 4 5 1 2 3 4 5 6 6
y = (4, 6.5) y-x = v-u = (-1, 3)
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 8 / 71
Introduction Geometric interpretation
1 2 3 4 5 1 2 3 4 5 6 6
u 2u
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 9 / 71
Introduction Geometric interpretation
(0,0) (4, 2)
1 2 3 4 5 1 2 3 4 5 6 6
(3, 5)
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 10 / 71
Introduction Geometric interpretation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 11 / 71
Introduction Geometric interpretation
40 60 80 100 120 20 40 60 80 100 120
Two dimensions of English V−Obj DSM
get use
cat dog knife boat
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 11 / 71
Vector spaces Formal definition
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 12 / 71
Vector spaces Formal definition
◮ vector addition: u + v := (u1 + v1, . . . , un + vn) ◮ scalar multiplication: λu := (λu1, . . . , λun) for λ ∈ R Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 12 / 71
Vector spaces Formal definition
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 13 / 71
Vector spaces Formal definition
◮ u + v ∈ V for u, v ∈ V (addition) ◮ λu ∈ V for λ ∈ R, u ∈ V (scalar multiplication)
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 14 / 71
Vector spaces Formal definition
◮ 0 · u = 0 ◮ λ0 = 0 ◮ λu = 0 ⇒ λ = 0 ∨ u = 0 ◮ (−λ)u = λ(−u) = −(λu) =: −λu Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 15 / 71
Vector spaces Formal definition
◮ 0 · u = 0 ◮ λ0 = 0 ◮ λu = 0 ⇒ λ = 0 ∨ u = 0 ◮ (−λ)u = λ(−u) = −(λu) =: −λu
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 15 / 71
Vector spaces Formal definition
◮ 0 · u = 0 ◮ λ0 = 0 ◮ λu = 0 ⇒ λ = 0 ∨ u = 0 ◮ (−λ)u = λ(−u) = −(λu) =: −λu
◮ vector addition: ∀f , g ∈ C[a, b],
◮ s-multiplication: ∀λ ∈ R and ∀f ∈ C[a, b],
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 15 / 71
Vector spaces Basis & linear subspace
◮ intuition: all vectors that can be constructed from
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 16 / 71
Vector spaces Basis & linear subspace
◮ intuition: all vectors that can be constructed from
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 16 / 71
Vector spaces Basis & linear subspace
◮ intuition: all vectors that can be constructed from
◮ equivalent: one u(i) is a linear combination of the other vectors Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 16 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 17 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 17 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 17 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 18 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 18 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 19 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 19 / 71
Vector spaces Basis & linear subspace
◮ coordinate transformations play an important role for DSMs Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 19 / 71
Vector spaces Basis & linear subspace
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 20 / 71
Vector spaces Basis & linear subspace
1 2 3 4 5 1 2 3 4 5 6 6
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 21 / 71
Vector spaces Basis & linear subspace
1 2 3 4 5 1 2 3 4 5 6 6
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 21 / 71
Vector spaces Basis & linear subspace
DSM: Matrix Algebra 28 July 2009 22 / 71
Vector spaces Basis & linear subspace
◮ a linear subspace is a subset of V that is closed under vector
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 22 / 71
Vector spaces Basis & linear subspace
◮ a linear subspace is a subset of V that is closed under vector
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 22 / 71
Vector spaces Basis & linear subspace
◮ a linear subspace is a subset of V that is closed under vector
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 22 / 71
Vector spaces Basis & linear subspace
◮ dim U = 2 (why?)
x1 x3
1 2 3 4 5 1 2 3 4 5 6 6
x2
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 23 / 71
Vector spaces Basis & linear subspace
◮ dim U = 2 (because b(2) = 3b(3) − 3
2b(1)) x1 x3
1 2 3 4 5 1 2 3 4 5 6 6
x2
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 23 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 24 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 24 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 24 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 25 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 25 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 26 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 26 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 27 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 27 / 71
Matrix algebra in a nutshell
◮ A + B is defined by element-wise addition ◮ λA is defined by element-wise s-multiplication ◮ these operations satisfy all vector space axioms Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 28 / 71
Matrix algebra in a nutshell
◮ A + B is defined by element-wise addition ◮ λA is defined by element-wise s-multiplication ◮ these operations satisfy all vector space axioms
◮ two equation systems: z = B · y and y = C · x ◮ by inserting the expressions for y into the first system,
◮ the result is a linear equation system z = A · x
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 28 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 29 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 29 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 30 / 71
Matrix algebra in a nutshell
◮ convention: vector = column matrix Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 30 / 71
Matrix algebra in a nutshell
◮ A(BC) = (AB)C =: ABC ◮ A(B + B′) = AB + AB′ ◮ (A + A′)B = AB + A′B ◮ (λA)B = A(λB) = λ(AB) =: λAB ◮ A · 0 = 0,
◮ A · I = A,
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 31 / 71
Matrix algebra in a nutshell
DSM: Matrix Algebra 28 July 2009 32 / 71
Matrix algebra in a nutshell
◮ (A + B)T = AT + BT ◮ (λA)T = λ(AT) =: λAT ◮ (A · B)T = BT · AT
◮ rank
◮ IT = I Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 32 / 71
Matrix algebra in a nutshell
◮ (A + B)T = AT + BT ◮ (λA)T = λ(AT) =: λAT ◮ (A · B)T = BT · AT
◮ rank
◮ IT = I
◮ symmetric matrices have many special properties that will
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 32 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 33 / 71
Matrix algebra in a nutshell
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 33 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 34 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 34 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 35 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 36 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 37 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 38 / 71
Matrix algebra with R
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 39 / 71
Matrix algebra and linear maps
1
2
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 40 / 71
Matrix algebra and linear maps
1
2
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 40 / 71
Matrix algebra and linear maps
1
2
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 40 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 41 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 41 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 42 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 42 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 42 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 43 / 71
Matrix algebra and linear maps
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 43 / 71
Matrix algebra and linear maps
◮ f : Rn → Rk given by a k × n matrix A ◮ g : Rk → Rm given by a m × k matrix B ◮ recall that (g ◦ f )(u) := g(f (u)) Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 43 / 71
Matrix algebra and linear maps
◮ f : Rn → Rk given by a k × n matrix A ◮ g : Rk → Rm given by a m × k matrix B ◮ recall that (g ◦ f )(u) := g(f (u))
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 43 / 71
Matrix algebra and linear maps
◮ can be represented by a square matrix A Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 44 / 71
Matrix algebra and linear maps
◮ can be represented by a square matrix A
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 44 / 71
Matrix algebra and linear maps
◮ can be represented by a square matrix A
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 44 / 71
Matrix algebra and linear maps
◮ can be represented by a square matrix A
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 44 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 45 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 46 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 46 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 46 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 46 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 47 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 47 / 71
Matrix algebra Solving equation systems
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 47 / 71
Matrix algebra Coordinate transformation
1 2 3 4 5 1 2 3 4 5 6 6
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 48 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 49 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 49 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 50 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 50 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 50 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 51 / 71
Matrix algebra Coordinate transformation
DSM: Matrix Algebra 28 July 2009 52 / 71
Matrix algebra Coordinate transformation
DSM: Matrix Algebra 28 July 2009 52 / 71
Matrix algebra Coordinate transformation
DSM: Matrix Algebra 28 July 2009 52 / 71
Matrix algebra Coordinate transformation
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 52 / 71
DSM laboratory Introduction
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 53 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 54 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 55 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 56 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 57 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 58 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 59 / 71
DSM laboratory Frequency counts
DSM: Matrix Algebra 28 July 2009 60 / 71
DSM laboratory Frequency counts
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 60 / 71
DSM laboratory Feature scaling
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 61 / 71
DSM laboratory Feature scaling
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 62 / 71
DSM laboratory Feature scaling
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 63 / 71
DSM laboratory Feature scaling
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 64 / 71
DSM laboratory Feature scaling
−2 2 4 −10 −5 5 10
get use boat cat cup dog knife pig Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 65 / 71
DSM laboratory Nearest neighbours
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 66 / 71
DSM laboratory Nearest neighbours
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 67 / 71
DSM laboratory Nearest neighbours
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 68 / 71
DSM laboratory Nearest neighbours
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 69 / 71
DSM laboratory Nearest neighbours
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 70 / 71
DSM laboratory Nearest neighbours
knife boat cup dog cat pig 0.6 0.8 1.0 1.2 1.4 1.6 1.8
Cluster Dendrogram
Euclidean distance Height
−0.5 0.0 0.5 1.0 −1.0 −0.5 0.0 0.5 1.0
Semantic map
Dim 1 Dim 2 boat cat cup dog knife pig
Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 28 July 2009 71 / 71