Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure of your implementation but the <a href="http://en.wikipedia.org/wiki/Dot_product" rel="nofollow noreferrer">cosine distance</a> of two vectors is equal to the normalized dot product of those vectors.</p> <p>The dot product of two matrix can be expressed as a . b = a<sup>T</sup>b. As a result if the matrix have different length you can't take the dot product to identify the cosine.</p> <p>Now in a standard TF*IDF approach the terms in your matrix should be indexed by <code>term, document</code> as a result any terms not appearing in a document should appear as zeroes in your matrix. </p> <p>Now the way you have it set up seems to suggest there are two different matrices for your two documents. I'm not sure if this is your intent, but it seems incorrect.</p> <p>On the other hand if one of your matrices is supposed to be your query, then it should be a vector and not a matrix, so that the transpose produces the correct result.</p> <p>A full explanation of TF*IDF follows:</p> <p>Ok, in a classic TF*IDF you construct a term-document matrix <code>a</code>. Each value in matrix <code>a</code> is characterized as a<sub>i,j</sub> where <code>i</code> is the term and <code>j</code> is the document. This value is a combination of local, global and normalized weights (although if you normalize your documents, the normalized weight should be 1). Thus a<sub>i,j</sub> = f<sub>i,j</sub>*D/d<sub>i</sub>, where f<sub>i,j</sub> is the frequency of word <code>i</code> in doc <code>j</code>, <code>D</code> is the document size, and d<sub>i</sub> is the number of documents with term <code>i</code> in them.</p> <p>Your query is a vector of terms designated as <code>b</code>. For each term b<sub>i,q</sub> in your query refers to term <code>i</code> for query <code>q</code>. b<sub>i,q</sub> = f<sub>i,q</sub> where f<sub>i,q</sub> is the frequency of term <code>i</code> in query <code>q</code>. In this case each query is a vector, and multiple queries form a matrix.</p> <p>We can then calculate the unit vectors of each so that when we take the dot product it will produce the correct cosine. To achieve the unit vector we divide both the matrix <code>a</code> and the query <code>b</code> by their <a href="http://mathworld.wolfram.com/FrobeniusNorm.html" rel="nofollow noreferrer">Frobenius norm</a>.</p> <p>Finally we can perform the cosine distance by taking the transpose of the vector <code>b</code> for a given query. Thus one query (or vector) per calculation. This is denoted as b<sup>T</sup>a. The final result is a vector with the scoring for each term where a higher score denotes higher document rank.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload