From the course: OpenAI API: Embeddings

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Leverage cosine similarity

Leverage cosine similarity - OpenAI API Tutorial

From the course: OpenAI API: Embeddings

Leverage cosine similarity

- [Instructor] Machines use numbers to measure the similarity between words. Yes, there is a mathematical formula involved. So buckle up. We talked about how an embedding is a vector of floating point numbers representing a text string, and you know that the distance between two vectors measures their relatedness. There are several ways to measure the distance between two vectors, like using cosine similarity as the distance function. As the name states, cosine similarity is when you measure the similarity between two non-zero vectors, or in mathematical terms, the cosine distance of the angle between two vectors. Mathematically, cosine similarity is calculated as the dot product of the two vectors divided by the product of their lengths. The formula is where A and B are the word vectors, A dot B is the dot product of the vectors, and the norm of A and the norm of B of the vectors. Cosine similarity ranges from -1 to…

Contents