Recitation 7

Review session

Bohan Jiang

2026-10-16

Topics covered today

  1. Sets and quantifiers as vectors
  2. Relations, matrices and types
  3. From counts to PMI, PPMI and cosine
  4. Bilinear forms and metrics
  5. Outer products and rank

1. Sets and quantifiers

Sets are indicator vectors

Domain D={Tom,Ann,Joe,Sue,Sam}\mathcal{D} = \{\text{Tom}, \text{Ann}, \text{Joe}, \text{Sue}, \text{Sam}\}

A=runner=(1,1,0,1,0)A = \text{runner} = (1,1,0,1,0) B=tall=(0,1,1,1,0)B = \text{tall} = (0,1,1,1,0)

  • A={Tom,Ann,Sue}A = \{\text{Tom}, \text{Ann}, \text{Sue}\} and B={Ann,Joe,Sue}B = \{\text{Ann}, \text{Joe}, \text{Sue}\}
  • A⊙B=(0,1,0,1,0)A \odot B = (0,1,0,1,0), the set A∩B={Ann,Sue}A \cap B = \{\text{Ann}, \text{Sue}\}, so ⊙\odot is intersection
  • A⋅B=2A \cdot B = 2, so the dot product counts ∣A∩B∣|A \cap B|
  • ∣A∣=3|A| = 3

Quantifiers are tests on two counts

Here A=runner={Tom,Ann,Sue}A = \text{runner} = \{\text{Tom}, \text{Ann}, \text{Sue}\}, B=tall={Ann,Joe,Sue}B = \text{tall} = \{\text{Ann}, \text{Joe}, \text{Sue}\} and A∩B={Ann,Sue}A \cap B = \{\text{Ann}, \text{Sue}\}, so ∣A∣=3|A| = 3 and ∣A∩B∣=2|A \cap B| = 2.

Sentence Test Here
Every AA is BB ∣A∩B∣=∣A∣\lvert A \cap B \rvert = \lvert A \rvert 2≠32 \neq 3, false, Tom is the witness
Some AA is BB ∣A∩B∣>0\lvert A \cap B \rvert > 0 2>02 > 0, true
No AA is BB ∣A∩B∣=0\lvert A \cap B \rvert = 0 2≠02 \neq 0, false

Tips

Always say which test you applied. The verdict alone is not the answer.

Practice 1. Quantifiers

Domain D={Tom,Ann,Joe,Sue,Sam}\mathcal{D} = \{\text{Tom}, \text{Ann}, \text{Joe}, \text{Sue}, \text{Sam}\}

A=singer=(1,0,1,1,1),B=dancer=(0,0,1,1,1)A = \text{singer} = (1,0,1,1,1), \qquad B = \text{dancer} = (0,0,1,1,1)

(a) Compute A⊙BA \odot B and A⋅BA \cdot B. Say what each denotes.

(b) Evaluate Every singer is a dancer, Some singer is a dancer and No singer is a dancer, naming the test.

(c) Evaluate Every dancer is a singer. Compare with part (b).

(d) What single change to the model makes Every singer is a dancer true?

Practice 1. Answers

  • (a) (0,0,1,1,1)(0,0,1,1,1), the set A∩B={Joe,Sue,Sam}A \cap B = \{\text{Joe}, \text{Sue}, \text{Sam}\} of singers who are dancers, and 33, the size of that set
  • (b) ∣A∣=4|A| = 4 and ∣A∩B∣=3|A \cap B| = 3. Every needs 3=43 = 4, false, Tom is the witness. Some needs 3>03 > 0, true. No needs 3=03 = 0, false
  • (c) Now the restrictor is dancer, ∣B∣=3=∣A∩B∣|B| = 3 = |A \cap B|, so true. Swapping the arguments changes the answer, because the first noun is the restrictor
  • (d) Make Tom a dancer, so that ∣A∩B∣=∣A∣=4|A \cap B| = |A| = 4

2. Relations, matrices and types

A relation is a matrix

Domain D={Tom,Ann,Joe,Sue}\mathcal{D} = \{\text{Tom}, \text{Ann}, \text{Joe}, \text{Sue}\}. Fij=1F_{ij} = 1 when ii follows jj, rows are the follower.

Columns, rows and sentences

  • FeJoe=(1,1,0,1)F\mathbf{e}_{\text{Joe}} = (1,1,0,1), the people who follow Joe, {Tom,Ann,Sue}\{\text{Tom}, \text{Ann}, \text{Sue}\}
  • F⊤eJoe=(1,0,0,0)F^\top\mathbf{e}_{\text{Joe}} = (1,0,0,0), the people Joe follows, {Tom}\{\text{Tom}\}
  • The two indices of FF are different argument positions, so the two sets differ
  • “Ann follows Joe” is the bilinear form eAnn⊤F eJoe=F23=1\mathbf{e}_{\text{Ann}}^\top F\,\mathbf{e}_{\text{Joe}} = F_{23} = 1, true

Types and tensor orders

Object Order Type
FF 2, matrix ⟨e,⟨e,t⟩⟩\langle e,\langle e,t\rangle\rangle
FeF\mathbf{e} 1, vector ⟨e,t⟩\langle e,t\rangle
e⊤Fe\mathbf{e}^\top F\mathbf{e} 0, scalar tt

Each application to an entity contracts one index and drops one order.

FF is not symmetric. F12=1F_{12} = 1 but F21=0F_{21} = 0, since Tom follows Ann and Ann does not follow Tom.

Practice 2. Relations

Domain D={Tom,Ann,Joe,Sue}\mathcal{D} = \{\text{Tom}, \text{Ann}, \text{Joe}, \text{Sue}\}. Tij=1T_{ij} = 1 when ii teaches jj.

(a) Compute TeSueT\mathbf{e}_{\text{Sue}} and T⊤eSueT^\top\mathbf{e}_{\text{Sue}}. Name each set in English.

(b) Write “Ann teaches Tom” as a bilinear form and evaluate it.

(c) Is TT symmetric? Name a pair that settles it.

(d) Give the type of teaches, and the order and type of TeSueT\mathbf{e}_{\text{Sue}}.

Practice 2. Answers

  • (a) TeSue=(1,1,0,0)T\mathbf{e}_{\text{Sue}} = (1,1,0,0), the people who teach Sue, {Tom,Ann}\{\text{Tom}, \text{Ann}\}. T⊤eSue=(1,0,0,0)T^\top\mathbf{e}_{\text{Sue}} = (1,0,0,0), the people Sue teaches, {Tom}\{\text{Tom}\}
  • (b) eAnn⊤T eTom=T21=0\mathbf{e}_{\text{Ann}}^\top T\,\mathbf{e}_{\text{Tom}} = T_{21} = 0, false
  • (c) Not symmetric. T12=1T_{12} = 1 but T21=0T_{21} = 0. Any such pair works
  • (d) ⟨e,⟨e,t⟩⟩\langle e,\langle e,t\rangle\rangle. TeSueT\mathbf{e}_{\text{Sue}} has order 1 and type ⟨e,t⟩\langle e,t\rangle, a predicate

Bonus. What is T⊤eJoeT^\top\mathbf{e}_{\text{Joe}}, and what does it say? The zero vector, since Joe teaches nobody.

3. From counts to PMI, PPMI and cosine

The pipeline

counts→ratio→PMI=log⁡2(ratio)\text{counts} \to \text{ratio} \to \text{PMI} = \log_2(\text{ratio})

PMI→PPMI=max⁡(0,PMI)→cos⁡\text{PMI} \to \text{PPMI} = \max(0, \text{PMI}) \to \cos

  • With counts, the ratio is N⋅n(w,c)n(w) n(c)\dfrac{N \cdot n(w,c)}{n(w)\,n(c)}
  • Ratio above 11. They co-occur more than chance predicts, PMI is positive
  • Ratio 11. Independent, PMI is 00
  • Ratio below 11. They co-occur less than chance, PMI is negative

A worked table

Row totals (50,30,20)(50, 30, 20), column totals (40,40,20)(40, 40, 20).

Reading the table

  • PMI(coffee,hot)=log⁡2100⋅4050⋅40=log⁡22=1\text{PMI}(\text{coffee}, \text{hot}) = \log_2 \dfrac{100 \cdot 40}{50 \cdot 40} = \log_2 2 = 1
  • PMI(coffee,cup)=log⁡2100⋅1050⋅40=log⁡212=−1\text{PMI}(\text{coffee}, \text{cup}) = \log_2 \dfrac{100 \cdot 10}{50 \cdot 40} = \log_2 \dfrac{1}{2} = -1
  • A zero count gives ratio 00 and PMI=−∞\text{PMI} = -\infty
  • PPMI clips every negative value to 00, so −1-1 and −∞-\infty both become 00

Clipping merges “co-occurs less than chance” with “exactly at chance”. Both now read 00.

The usual reason to accept that loss. Negative PMI is unreliable when counts are small.

Cosine on PPMI rows

cos⁡(u,v)=u⋅v∥u∥ ∥v∥\cos(\mathbf{u},\mathbf{v}) = \frac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{u}\|\,\|\mathbf{v}\|}

  • Two PPMI rows are orthogonal when they share no context with a positive value
  • A word whose PPMI row is all zeros is the zero vector, with ∥0∥=0\|\mathbf{0}\| = 0
  • Then the cosine is 00\dfrac{0}{0}, which is undefined. That is a modeling problem, not a rounding one

Context smoothing

Raise context counts to a power α<1\alpha < 1 before normalizing.

pα(c)=count(c)α∑c′count(c′)αp_\alpha(c) = \frac{\text{count}(c)^\alpha}{\sum_{c'} \text{count}(c')^\alpha}

What smoothing does

  • It flattens the context distribution, so the rare context c3c_3 gains mass, from 0.0500.050 to 0.0890.089
  • The probability sits in the denominator of PMI, so a larger pα(c3)p_\alpha(c_3) pushes its PMI down
  • That corrects PMI’s bias toward rare contexts, which look strongly associated by accident

Practice 3a. A table to work through

Row totals (50,30,20)(50, 30, 20), column totals (50,30,20)(50, 30, 20). Leave answers as log⁡2\log_2 of a fraction.

(a) Compute PMI(x1,c1)\text{PMI}(x_1, c_1) and PMI(x1,c2)\text{PMI}(x_1, c_2).

(b) Compute the whole PMI row of x3x_3. What does it say about x3x_3?

(c) Write the PPMI matrix. What distinction was lost?

Practice 3a. More parts

Use the same table.

(d) Compute cos⁡(x1,x2)\cos(x_1, x_2) on the PPMI rows. Then try cos⁡(x1,x3)\cos(x_1, x_3) and say precisely what goes wrong.

(e) On the raw count rows, cos⁡(x1,x2)≈0.87\cos(x_1, x_2) \approx 0.87. Explain why this disagrees with part (d).

Practice 3a. Answers

  • (a) Ratio 100⋅3050⋅50=65\frac{100 \cdot 30}{50 \cdot 50} = \frac{6}{5}, so PMI(x1,c1)=log⁡265\text{PMI}(x_1,c_1) = \log_2\frac65. Ratio 100⋅1250⋅30=45\frac{100 \cdot 12}{50 \cdot 30} = \frac45, so PMI(x1,c2)=log⁡245\text{PMI}(x_1,c_2) = \log_2\frac45, which is negative
  • (b) Every ratio is 11, so the row is (0,0,0)(0,0,0). The distribution of x3x_3 over contexts equals the context totals, so x3x_3 is independent of every context, uninformative rather than rare
  • (c) PPMI=(log⁡265000log⁡243log⁡243000)\text{PPMI} = \begin{pmatrix} \log_2\frac65 & 0 & 0 \\ 0 & \log_2\frac43 & \log_2\frac43 \\ 0 & 0 & 0 \end{pmatrix}. Negative association and independence both became 00

Practice 3a. Answers continued

  • (d) x1x_1 has support only on c1c_1 and x2x_2 only on c2,c3c_2, c_3, so the dot product is 00 and cos⁡=0\cos = 0. For x3x_3 the PPMI row is the zero vector, so the formula gives 00\frac{0}{0}, undefined
  • (e) The raw rows (30,12,8)(30,12,8) and (10,12,8)(10,12,8) overlap on every context, mostly because both words are frequent. PPMI removes the frequency baseline, and after clipping they share no positive context

Practice 3b. Smoothing

Context counts (60,30,10)(60, 30, 10) and α=0.5\alpha = 0.5.

(a) Compute p(c)p(c) and pα(c)p_\alpha(c) for the three contexts.

(b) Which context gains probability, and which loses?

(c) What happens to the PMI of the rarest context, and why is that the point of smoothing?

Practice 3b. Answers

  • (a) p=(0.60,0.30,0.10)p = (0.60, 0.30, 0.10) and the square roots are (7.75,5.48,3.16)(7.75, 5.48, 3.16) with sum 16.3916.39, so p0.5≈(0.47,0.33,0.19)p_{0.5} \approx (0.47, 0.33, 0.19)
  • (b) The rare context c3c_3 gains, from 0.100.10 to 0.190.19. The common context c1c_1 loses
  • (c) A larger denominator lowers the PMI of c3c_3. Rare contexts were being over-rewarded, and smoothing corrects that

4. Bilinear forms and metrics

The bilinear form

u⊤G v=∑i,jui Gij vj\mathbf{u}^\top G\,\mathbf{v} = \sum_{i,j} u_i\,G_{ij}\,v_j

Take u=(2,3)\mathbf{u} = (2,3), v=(5,1)\mathbf{v} = (5,1) and G=(1203)G = \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix}.

  • With G=IG = I the form is the dot product, 2⋅5+3⋅1=132 \cdot 5 + 3 \cdot 1 = 13
  • With GG, write out all four terms

2⋅1⋅5⏟10+2⋅2⋅1⏟4+3⋅0⋅5⏟0+3⋅3⋅1⏟9=23\underbrace{2\cdot1\cdot5}_{10} + \underbrace{2\cdot2\cdot1}_{4} + \underbrace{3\cdot0\cdot5}_{0} + \underbrace{3\cdot3\cdot1}_{9} = 23

Reversing the roles gives v⊤G u=49\mathbf{v}^\top G\,\mathbf{u} = 49. Because G≠G⊤G \neq G^\top, the order of the arguments matters.

Ranking with a metric

A query q\mathbf{q} is compared with several candidates x\mathbf{x}. Each candidate gets a score, and the ranking sorts the candidates by score.

scoreG(x)=q⊤G x\text{score}_G(\mathbf{x}) = \mathbf{q}^\top G\,\mathbf{x}

  • The metric GG decides how much each coordinate counts
  • G=IG = I is the ordinary dot product, so every coordinate counts equally
  • G=diag(g1,g2)G = \text{diag}(g_1, g_2) gives g1q1x1+g2q2x2g_1 q_1 x_1 + g_2 q_2 x_2, so gig_i is the weight of coordinate ii
  • A non-diagonal GG also mixes coordinates, through the cross terms qiGijxjq_i G_{ij} x_j

The scores

Query q=(1,2)\mathbf{q} = (1,2), candidates a=(4,1)\mathbf{a} = (4,1) and b=(1,3)\mathbf{b} = (1,3), and metric G=diag(g,1)G = \text{diag}(g, 1).

  • Dot product. q⋅a=6\mathbf{q}\cdot\mathbf{a} = 6 and q⋅b=7\mathbf{q}\cdot\mathbf{b} = 7, so b\mathbf{b} is returned
  • With this GG, q⊤Ga=4g+2\mathbf{q}^\top G \mathbf{a} = 4g + 2 and q⊤Gb=g+6\mathbf{q}^\top G \mathbf{b} = g + 6
  • a\mathbf{a} wins when 4g+2>g+64g + 2 > g + 6, that is g>43g > \frac{4}{3}
  • With g=3g = 3 the scores are 1414 and 99, so the ranking is reversed

A diagonal GG reweights coordinates. A larger weight on coordinate 1 favors the candidate that is large there.

A metric can reverse a ranking

Each label gives the score of that point. Dashed lines join points with the same score. The grey arrow points toward higher scores, so the point on the higher line wins.

Practice 4. Bilinear forms and metrics

(a) Let u=(1,4)\mathbf{u} = (1,4), v=(3,2)\mathbf{v} = (3,2) and G=(2101)G = \begin{pmatrix} 2 & 1 \\ 0 & 1 \end{pmatrix}. Compute u⊤v\mathbf{u}^\top\mathbf{v} and u⊤Gv\mathbf{u}^\top G\mathbf{v}, writing out all four terms for the second.

(b) A query q=(3,1)\mathbf{q} = (3,1) is compared with a=(2,2)\mathbf{a} = (2,2) and b=(5,0)\mathbf{b} = (5,0). Which is returned under the dot product?

(c) Find a diagonal G=diag(1,g)G = \text{diag}(1,g) under which the other candidate wins. Verify by computing both scores.

Practice 4. Answers

  • (a) u⊤v=3+8=11\mathbf{u}^\top\mathbf{v} = 3 + 8 = 11. And 1⋅2⋅3+1⋅1⋅2+4⋅0⋅3+4⋅1⋅2=6+2+0+8=161\cdot2\cdot3 + 1\cdot1\cdot2 + 4\cdot0\cdot3 + 4\cdot1\cdot2 = 6 + 2 + 0 + 8 = 16
  • (b) q⋅a=8\mathbf{q}\cdot\mathbf{a} = 8 and q⋅b=15\mathbf{q}\cdot\mathbf{b} = 15, so b\mathbf{b} is returned
  • (c) q⊤Ga=6+2g\mathbf{q}^\top G\mathbf{a} = 6 + 2g and q⊤Gb=15\mathbf{q}^\top G\mathbf{b} = 15, so a\mathbf{a} wins when g>4.5g > 4.5. Take g=5g = 5, giving 1616 against 1515

5. Outer products and rank

The outer product

(uv⊤)ij=ui vj(\mathbf{u}\mathbf{v}^\top)_{ij} = u_i\,v_j

Take u=(2,1,0)\mathbf{u} = (2,1,0) and v=(1,0,3)\mathbf{v} = (1,0,3).

uv⊤=(206103000)\mathbf{u}\mathbf{v}^\top = \begin{pmatrix} 2 & 0 & 6 \\ 1 & 0 & 3 \\ 0 & 0 & 0 \end{pmatrix}

  • Every row is a multiple of v⊤\mathbf{v}^\top, by 22, 11 and 00
  • Every column is a multiple of u\mathbf{u}
  • So the rank is 11. This is forced by how an outer product is built

A relation that factors this way is “a property of the first argument” times “a property of the second”.

Practice 5. Outer products

(a) For u=(3,0,1)\mathbf{u} = (3,0,1) and v=(1,2,1)\mathbf{v} = (1,2,1) write out uv⊤\mathbf{u}\mathbf{v}^\top and state its rank.

(b) Is (1224)\begin{pmatrix} 1 & 2 \\ 2 & 4 \end{pmatrix} an outer product of two vectors? If so, which?

(c) Is the 2×22\times2 identity an outer product of two vectors? Explain using rank.

Practice 5. Answers

  • (a) (363000121)\begin{pmatrix} 3 & 6 & 3 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{pmatrix}, rank 11, since every row is a multiple of v⊤\mathbf{v}^\top
  • (b) Yes. It equals ww⊤\mathbf{w}\mathbf{w}^\top with w=(1,2)\mathbf{w} = (1,2), and its second row is twice the first
  • (c) No. The identity has rank 22, but an outer product of nonzero vectors has rank 11. The identity is a sum of two outer products, e1e1⊤+e2e2⊤\mathbf{e}_1\mathbf{e}_1^\top + \mathbf{e}_2\mathbf{e}_2^\top

Wrap up

One operation, three readings

Topic Coordinates The inner product gives
Sets and relations individuals a count, then a truth value
Distributional pipeline contexts a similarity, repaired by PPMI and smoothing
Bilinear forms any basis a score that depends on the metric GG