Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Glossary › Cosine similarity

What is cosine similarity?

The dot product of two vectors divided by both their lengths. It measures direction only, from −1-1−1 (opposite) to 111 (the same).

Where it is taught

The dot product. One number that says how much two vectors point the same way. It is the most used calculation in all of AI.

What the lesson leaves you with

  • a⋅b\mathbf{a} \cdot \mathbf{b}a⋅b multiplies matching entries and adds them up, giving one number.
  • It is positive for similar directions, zero for perpendicular, negative for opposite.
  • Cosine similarity divides out the lengths so that only direction counts.
Open the lesson

Questions

What is cosine similarity?
The dot product of two vectors divided by both their lengths. It measures direction only, from -1 (opposite) to 1 (the same).
Where is cosine similarity used in AI?
One number that says how much two vectors point the same way. It is the most used calculation in all of AI.
What is the key idea to remember about cosine similarity?
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold">a</mi><mo>⋅</mo><mi mathvariant="bold">b</mi></mrow><annotation encoding="application/x-tex">mathbf{a} cdot mathbf{b}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.4445em;"></span><span class="mord mathbf">a</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.6944em;"></span><span class="mord mathbf">b</span></span></span></span> multiplies matching entries and adds them up, giving one number.
Where can I learn cosine similarity step by step?
In the lesson “The dot product” in Gradient’s course on the maths behind AI, with interactive diagrams and questions.

See it in 3D on the blog

  • What is cosine similarity? How alike two things are3 min

Related terms

  • Dot product
  • Embedding
  • Nearest neighbours
  • Parameter
  • Vector