Embed Endpoint
The Embed Endpoint
In this lab, we'll learn how to analyze a text dataset using Cohere's Embed cohere endpoint. This colab accompanies the Embed endpoint lesson of LLM University.
Setting Up
The first step is to install the Cohere Python SDK. Next, create an API key, which you can generate from the Cohere dashboard.
Analyzing Text
Cohere’s Embed endpoint takes a piece of text and turns it into a vector embedding. Embeddings represent text in the form of numbers that capture its meaning and context. What it means is that it gives you the ability to turn unstructured text data into a structured form. It opens up ways to analyze and extract insights from them.
Get embeddings
Here we have a list of 50 top web search terms about Hello, World! taken from a keyword tool. Let’s look at a few examples:
We use the Embed endpoint to get the embeddings for each of these serach terms.
Semantic Search
Note: This semantic search section is not contained in the blog post, but we encourage you to still check it out if you'd like to see how the embedding is used for searching in the dataset!
We’ll look at a couple of example applications. The first example is semantic search. Given a new query, our "search engine" must return the most similar FAQs, where the FAQs are the 50 search terms we uploaded earlier.
We use cosine similarity to compare the similarity of the new query with each of the FAQs
Finally, we display the top 5 FAQs that match the new query
New query: what is the history of hello world Similar queries: Similarity: 0.86; how did hello world originate Similarity: 0.84; what is hello world Similarity: 0.83; how to do hello world Similarity: 0.81; why hello world Similarity: 0.81; where did hello world come from
Semantic Exploration
In the second example, we take the same idea as semantic search and take a broader look, which is exploring huge volumes of text and analyzing their semantic relationships.
We'll use the same 50 top web search terms about Hello, World! There are different techniques we can use to compress the embeddings down to just 2 dimensions while retaining as much information as possible. We'll use a technique called UMAP. And once we can get it down to 2 dimensions, we can plot these embeddings on a 2D chart.