Code lab 8.1 – Semantic distance metrics
The file you need to access from the GitHub repository is titled CHAPTER8-1_DISTANCEMETRICS.ipynb
.
Our first code lab in this chapter will focus on the different ways you can calculate the distance between vectors, giving you a hands-on view of the difference between each of these approaches. We will use a brand new notebook called CHAPTER8-1_DISTANCEMETRICS.ipynb
that has separate code from what we have used up to this point. We will install and import the packages we need, create the embeddings for the sentences we discussed, and then we will step through three types of distance metric formulas that are very common in NLP, generative AI, and RAG systems.
We first install the open source sentence_transformers
library that will set up our embedding algorithm:
%pip install sentence_transformers -q --user
The sentence_transformers
package provides an easy way to compute dense vector representations for sentences and paragraphs...