Natural Language Processing · TEE · mocks
Q5B · Sentence-window vectors and cosine
Timed practice · Solved re-exam · February 2026
TEE · actual previous paper · 100 marks · 180 minutes
Target words: farmer, soil, sun, plant.
Context words: plant, water, grow, harvest.
i. Construct a co-occurrence matrix for the target and context words. Take the window size as one whole sentence.
ii. Evaluate the similarity between the vectors of the target words “farmer-soil”, “farmer-sun”, and “farmer-plant” using the cosine similarity.
iii. Plot the target word vectors by considering only two dimensions: “planted” and “harvested”. [10 marks]
Answer
Given
Five sentence windows. For alignment with the supplied matrix, target plant means the noun plants, occurring in sentences 3 and 4. Context plant covers planted and plants; watered → water; harvested → harvest. Count a target–context pair once per sentence in which both are present, including the plant–plant sentence-presence diagonal.
To find
The target–context matrix, three cosine similarities and a two-coordinate plot.
Formula: which one and why
M_{ij}=\sum_s\mathbf1[\text{target}_i\text{ and context}_j\text{ present in }s]\cos(\mathbf a,\mathbf b)=\frac{\sum_j a_jb_j}{\sqrt{\sum_j a_j^2}\sqrt{\sum_j b_j^2}}This is a sentence-presence matrix, not a position-based sliding window that excludes a token from its own context. Stating the convention is necessary because those alternatives give a different diagonal.
Solution
Step 1. Normalize and identify each sentence’s contribution
| Sentence | Targets present | Context lemmas present |
|---|---|---|
| 1 | farmer, soil | plant |
| 2 | soil | water |
| 3 | sun, plant | plant, grow |
| 4 | farmer, plant | plant, harvest |
| 5 | soil | none |
Step 2. Fill all matrix rows
| Target | plant | water | grow | harvest |
|---|---|---|---|---|
| farmer | 2 | 0 | 0 | 1 |
| soil | 1 | 1 | 0 | 0 |
| sun | 1 | 0 | 1 | 0 |
| plant | 2 | 0 | 1 | 1 |
Farmer meets context plant in sentences 1 and 4. Soil meets plant in sentence 1 and water in sentence 2. Sun meets plant and grow in sentence 3. The noun plant occurs in sentences 3 and 4, producing its last row.
Step 3. Compute farmer–soil
\mathbf f\cdot\mathbf s=(2)(1)+(0)(1)+(0)(0)+(1)(0)=2\|\mathbf f\|=\sqrt{2^2+0^2+0^2+1^2}=\sqrt5,\quad\|\mathbf s\|=\sqrt2\cos(\mathbf f,\mathbf s)=\frac2{\sqrt{10}}\approx0.632456Step 4. Compute farmer–sun
\mathbf f\cdot\mathbf u=(2)(1)+(0)(0)+(0)(1)+(1)(0)=2\|\mathbf u\|=\sqrt2,\quad\cos(\mathbf f,\mathbf u)=\frac2{\sqrt{10}}\approx0.632456Step 5. Compute farmer–plant
\mathbf f\cdot\mathbf p=(2)(2)+(0)(0)+(0)(1)+(1)(1)=5\|\mathbf p\|=\sqrt{2^2+0^2+1^2+1^2}=\sqrt6\cos(\mathbf f,\mathbf p)=\frac5{\sqrt{30}}\approx0.912871Step 6. Plot the requested two coordinates
Interpret the axis names planted and harvested as their normalized context features plant and harvest. Farmer=(2,1), soil=(1,0), sun=(1,0), plant=(2,1). Farmer and plant overlap; soil and sun overlap.
Final answer
Using the stated noun-target convention: farmer–soil = 0.632456, farmer–sun = 0.632456, farmer–plant = 0.912871.
Yaad rakho: Plant noun aur plant verb ko same maana ya separate? Pehle convention likho, phir count karo.
Two details that prevent an incorrect answer
Arithmetic: 5/√30 = 0.912871; the source key’s printed approximation 0.9444 does not equal its own fraction. Keep the exact fraction until the last step.
Normalization: If the question instead requires all noun and verb forms of plant to be merged as targets, sentence 1 also contains the plant target. Its row becomes [3,0,1,1], and farmer–plant becomes 7/√55 ≈ 0.943880. The paper leaves this choice unstated; the main worked solution explicitly uses the noun-target interpretation that reproduces its supplied matrix.