Model Pipeline - Cosine similarity
This pipeline calculates how similar two text pieces are by measuring the angle between their vector forms. It helps find how close their meanings are without caring about their length.
Jump into concepts and practice - no test required
This pipeline calculates how similar two text pieces are by measuring the angle between their vector forms. It helps find how close their meanings are without caring about their length.
No training loss to show for cosine similarity calculation.
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | N/A | N/A | Cosine similarity is a calculation, no training involved. |
A and B?A = [1, 2, 3] and B = [4, 5, 6], what is the cosine similarity (rounded to 2 decimals)?import numpy as np
def cosine_sim(a, b):
return np.dot(a, b) / np.linalg.norm(a + b)
A = np.array([1, 0])
B = np.array([0, 1])
print(cosine_sim(A, B))doc1 = [0, 1, 2, 0] and doc2 = [1, 0, 1, 1]. Which step is best to improve cosine similarity comparison for very sparse vectors?