Cosine similarity is a metric used to measure the similarity between two vectors in an n-dimensional space by calculating the cosine of the angle between them.
It is commonly applied in NLP for comparing text documents represented as vectors.
The formula for cosine similarity is given by:
\( \text{cos}( \theta ) = \frac{A \cdot B}{\|A\| \|B\|} \),
where \( A \) and \( B \) are vectors, and \( A \cdot B \) is their dot product.
A cosine similarity value ranges from -1 to 1, with 1 indicating that the vectors are identical, 0 indicating orthogonality (no similarity), and -1 indicating opposite directions.
This metric is preferred when measuring textual similarity because it focuses on orientation rather than magnitude, making it insensitive to document length. Cosine similarity is used in tasks like information retrieval, document clustering, and recommendation systems.