You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Euclidean distance (often called L2 norm) is the most intuitive of the metrics.
However, the Euclidean distance only considers the size not orientation (direction of the vectors). To overcome this issue, we could adapt either dot product or cosine similarity.
Dot product
One drawback of Euclidean distance is the lack of orientation considered in the calculation — it is based solely on magnitude. And this is where we can use our other two metrics. The first of those is the dot product.
The dot product considers direction (orientation) and also scales with vector magnitude.
We care about orientation because similar meaning (as we will often find) can be represented by the direction of the vector — not necessarily the magnitude of it.
For example, we may find that our vector's magnitude correlates with the frequency of a word that it represents in our dataset. Now, the word hi means the same as hello, and this may not be represented if our training data contained the word hi 1000 times and hello just twice.
So, vectors' orientation is often seen as being just as important (if not more so) as distance.
The dot product is calculated using:
The dot product considers the angle between vectors, where the angle is ~0, the cosθ component of the formula equals ~1. If the angle is nearer to 180 (orthogonal/perpendicular), the cosθ component equals ~0.
Therefore, the cosθ component increases the result where there is less of an angle between the two vectors. So, a higher dot-product correlates with higher orientation.
Clearly, the dot product calculation is straightforward (the simplest of the three) — and this gives us benefits in terms of computation time.
However, there is one drawback. It is not normalized — meaning larger vectors will tend to score higher dot products, despite being less similar.
So, in reality, the dot-product is used to identify the general orientation of two vectors — because:
Two vectors that point in a similar direction return a positive dot-product.
Two perpendicular vectors return a dot-product of zero.
Vectors that point in opposing directions return a negative dot-product.
Cosine similarity
Cosine similarity considers vector orientation, independent of vector magnitude.
The first thing we should be aware of in this formula is that the numerator is, in fact, the dot product — which considers both magnitude and direction.
In the denominator, we have the strange double vertical bars — these mean ‘the length of’. So, we have the length of u multiplied by the length of v. The length, of course, considers magnitude.
When we take a function that considers both magnitude and direction and divide that by a function that considers just magnitude — those two magnitudes cancel out, leaving us with a function that considers direction independent of magnitude.
We can think of cosine similarity as a normalized dot product! And it clearly works.
The text was updated successfully, but these errors were encountered:
Euclidean distance (often called L2 norm) is the most intuitive of the metrics.
However, the Euclidean distance only considers the size not orientation (direction of the vectors). To overcome this issue, we could adapt either dot product or cosine similarity.
One drawback of Euclidean distance is the lack of orientation considered in the calculation — it is based solely on magnitude. And this is where we can use our other two metrics. The first of those is the dot product.
The dot product considers direction (orientation) and also scales with vector magnitude.
We care about orientation because similar meaning (as we will often find) can be represented by the direction of the vector — not necessarily the magnitude of it.
For example, we may find that our vector's magnitude correlates with the frequency of a word that it represents in our dataset. Now, the word hi means the same as hello, and this may not be represented if our training data contained the word hi 1000 times and hello just twice.
So, vectors' orientation is often seen as being just as important (if not more so) as distance.
The dot product is calculated using:
The dot product considers the angle between vectors, where the angle is ~0, the cosθ component of the formula equals ~1. If the angle is nearer to 180 (orthogonal/perpendicular), the cosθ component equals ~0.
Therefore, the cosθ component increases the result where there is less of an angle between the two vectors. So, a higher dot-product correlates with higher orientation.
Clearly, the dot product calculation is straightforward (the simplest of the three) — and this gives us benefits in terms of computation time.
However, there is one drawback. It is not normalized — meaning larger vectors will tend to score higher dot products, despite being less similar.
So, in reality, the dot-product is used to identify the general orientation of two vectors — because:
Two vectors that point in a similar direction return a positive dot-product.
Two perpendicular vectors return a dot-product of zero.
Vectors that point in opposing directions return a negative dot-product.
Cosine similarity considers vector orientation, independent of vector magnitude.
The first thing we should be aware of in this formula is that the numerator is, in fact, the dot product — which considers both magnitude and direction.
In the denominator, we have the strange double vertical bars — these mean ‘the length of’. So, we have the length of u multiplied by the length of v. The length, of course, considers magnitude.
When we take a function that considers both magnitude and direction and divide that by a function that considers just magnitude — those two magnitudes cancel out, leaving us with a function that considers direction independent of magnitude.
We can think of cosine similarity as a normalized dot product! And it clearly works.
The text was updated successfully, but these errors were encountered: