next up previous contents index
Next: Queries as vectors Up: The vector space model Previous: The vector space model   Contents   Index

Dot products

We denote by $\vec{V}(d)$ the vector derived from document $d$, with one component in the vector for each dictionary term. Unless otherwise specified, the reader may assume that the components are computed using the tf-idf weighting scheme, although the particular weighting scheme is immaterial to the discussion that follows. The set of documents in a collection then may be viewed as a set of vectors in a vector space, in which there is one axis for each term. This representation loses the relative ordering of the terms in each document; recall our example from Section 6.2 (page [*]), where we pointed out that the documents Mary is quicker than John and John is quicker than Mary are identical in such a bag of words representation.

How do we quantify the similarity between two documents in this vector space? A first attempt might consider the magnitude of the vector difference between two document vectors. This measure suffers from a drawback: two documents with very similar content can have a significant vector difference simply because one is much longer than the other. Thus the relative distributions of terms may be identical in the two documents, but the absolute term frequencies of one may be far larger.

% latex2html id marker 8047
...osine similarity illustrated.}{$\mbox{sim}(d_1,d_2) = \cos\theta$.}
To compensate for the effect of document length, the standard way of quantifying the similarity between two documents $d_1$ and $d_2$ is to compute the cosine similarity of their vector representations $\vec{V}(d_1)$ and $\vec{V}(d_2)$
\mbox{sim}(d_1,d_2)= \frac{\vec{V}(d_1)\cdot \vec{V}(d_2)}{\vert\vec{V}(d_1)\vert \vert\vec{V}(d_2)\vert},
\end{displaymath} (24)

where the numerator represents the dot product (also known as the inner product ) of the vectors $\vec{V}(d_1)$ and $\vec{V}(d_2)$, while the denominator is the product of their Euclidean lengths . The dot product $\vec{x} \cdot \vec{y}$ of two vectors is defined as $\sum_{i=1}^Mx_iy_i$. Let $\vec{V}(d)$ denote the document vector for $d$, with $M$ components $\vec{V}_1(d)\ldots \vec{V}_M(d)$. The Euclidean length of $d$ is defined to be $\sqrt{\sum_{i=1}^M\vec{V}_i^2(d)}$.

The effect of the denominator of Equation 24 is thus to length-normalize the vectors $\vec{V}(d_1)$ and $\vec{V}(d_2)$ to unit vectors $\vec{v}(d_1)=\vec{V}(d_1)/\vert\vec{V}(d_1)\vert$ and $\vec{v}(d_2)=\vec{V}(d_2)/\vert\vec{V}(d_2)\vert$. We can then rewrite (24) as

\mbox{sim}(d_1,d_2)= \vec{v}(d_1)\cdot \vec{v}(d_2).
\end{displaymath} (25)

Worked example. Consider the documents in Figure 6.9 . We now apply Euclidean normalization to the tf values from the table, for each of the three documents in the table. The quantity $\sqrt{\sum_{i=1}^M\vec{V}_i^2(d)}$ has the values 30.56, 46.84 and 41.30 respectively for Doc1, Doc2 and Doc3. The resulting Euclidean normalized tf values for these documents are shown in Figure 6.11 .

Figure 6.11: Euclidean normalized tf values for documents in Figure 6.9 .
\begin{figure}\begin{tabular}{\vert\vert l\vert l\vert l\vert l\vert\vert}
...0 & 0.71 & 0.70 \\
best & 0.46 & 0 & 0.41 \\
End worked example.

Thus, (25) can be viewed as the dot product of the normalized versions of the two document vectors. This measure is the cosine of the angle $\theta$ between the two vectors, shown in Figure 6.10 . What use is the similarity measure $\mbox{sim}(d_1,d_2)$? Given a document $d$ (potentially one of the $d_i$ in the collection), consider searching for the documents in the collection most similar to $d$. Such a search is useful in a system where a user may identify a document and seek others like it - a feature available in the results lists of search engines as a more like this feature. We reduce the problem of finding the document(s) most similar to $d$ to that of finding the $d_i$ with the highest dot products ($\mbox{sim}$ values) $\vec{v}(d)\cdot \vec{v}(d_i)$. We could do this by computing the dot products between $\vec{v}(d)$ and each of $\vec{v}(d_1),\ldots,\vec{v}(d_N)$, then picking off the highest resulting $\mbox{sim}$ values.

% latex2html id marker 8153
\begin{tabular}{\vert\vert l\vert r\v...
...Pride and Prejudice} and Bront\uml {e}'s \emph{Wuthering Heights.}}

Worked example. Figure 6.12 shows the number of occurrences of three terms (affection, jealous and gossip) in each of the following three novels: Jane Austen's Sense and Sensibility (SaS) and Pride and Prejudice (PaP) and Emily Brontë's Wuthering Heights (WH). Of course, there are many other terms occurring in each of these novels. In this example we represent each of these novels as a unit vector in three dimensions, corresponding to these three terms (only); we use raw term frequencies here, with no idf multiplier. The resulting weights are as shown in Figure 6.13.

% latex2html id marker 8173
\begin{tabular}{\vert\vert l\ver...
...e documents, their tf-idf weight would be 0 in most formulations.)}

Now consider the cosine similarities between pairs of the resulting three-dimensional vectors. A simple computation shows that sim($\vec{v}$(SAS), $\vec{v}$(PAP)) is 0.999, whereas sim($\vec{v}$(SAS), $\vec{v}$(WH)) is 0.888; thus, the two books authored by Austen (SaS and PaP) are considerably closer to each other than to Brontë's Wuthering Heights. In fact, the similarity between the first two is almost perfect (when restricted to the three terms we consider). Here we have considered tf weights, but we could of course use other term weight functions. End worked example.

Viewing a collection of $N$ documents as a collection of vectors leads to a natural view of a collection as a term-document matrix and jealousy would under stemming be considered as a single dimension. This matrix view will prove to be useful in Chapter 18 .

next up previous contents index
Next: Queries as vectors Up: The vector space model Previous: The vector space model   Contents   Index
© 2008 Cambridge University Press
This is an automatically generated page. In case of formatting errors you may want to look at the PDF edition of the book.