![]() ![]() It surely looked at the last sentence and noticed that it is completely different from the others. (I added the sentence about the song “Happy” to show that.) But still, it’s pretty decent. And it’s low when the sentence is different. Sentence: Pharrell Williams wrote the song 'Happy' in 2014Īs you can see the “similarity” number is high when the sentence is like the original sentence. If you run the above script, you will get a response like: Input Sentence: That is a happy person. In the above script, we are using the model named: all-MiniLM-L6-v2 Similarity_tensor = util.pytorch_cos_sim(input_embedding, sentence_embedding) Sentence_embedding = model.encode(sentence) # and print the similarity between the input sentence and # Next we loop over all the sentences we want to compare Print("Input Sentence:", input_sentence, "\n") Input_embedding = model.encode(input_sentence) Model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') "Pharrell Williams wrote the song 'Happy' in 2014", Input_sentence = "That is a happy person." So, in order to install the library you have to do something like: > pip install -U sentence-transformersĪnd then you can use the library in a script like: from sentence_transformers import SentenceTransformer, util In order to do that, we are going to use the sentence-transformers library from Hugging Face. Okay, so, now that we know what vector embeddings are, the next question is, how to convert our quotes into vector embeddings. Converting The Knowledge Base Into Vectors So, let me summarize with a quote from this article: Meet AI’s multitool: Vector embeddings from the Google Cloud Blog.Įmbeddings are a way of representing data–almost any kind of data, like text, images, videos, users, music, whatever–as points in space where the locations of those points in space are semantically meaningful. But, don’t worry, they will all make sense very soon. You might find that there are a lot of new concepts and ideas introduced above. We ask it to summarize all the “wisdom” from the quotes that we got back. We take all the quotes that are similar to the user’s question and create a “prompt” for ChatGPT.We are doing this, because can ask the vector DB to bring back similar quotes to the question. Next, we take the user’s question and turn that also into a vector.(It has a free plan that allows you to play with all of this) Here we are going to use a cloud-hosted vector DB called Pinecone. ![]() Vector databases help us do all this effortlessly. We are doing this because later in the process we need to find all the similar quotes to the user’s query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |