#Embedding to 2D
1 messages · Page 1 of 1 (latest)
Hi @odd oyster. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can use a dimensionality reduction technique like t-SNE (t-Distributed Stochastic Neighbor Embedding) to reduce the dimensionality of your embeddings to 2D. Here's an example of how you can do this using Python and the sklearn library:
import pandas as pd
from sklearn.manifold import TSNE
import numpy as np
from ast import literal_eval
# Load the embeddings
datafile_path = "data/fine_food_reviews_with_embeddings_1k.csv"
df = pd.read_csv(datafile_path)
# Convert to a list of lists of floats
matrix = np.array(df.embedding.apply(literal_eval).to_list())
# Create a t-SNE model and transform the data
tsne = TSNE(n_components=2, perplexity=15, random_state=42, init='random', learning_rate=200)
vis_dims = tsne.fit_transform(matrix)
vis_dims.shape
In this example, the embeddings are loaded from a CSV file, converted to a list of lists of floats, and then transformed using t-SNE. The result is a 2D array of coordinates, which can be plotted on a 2D scatter plot.
Please note that t-SNE is a stochastic algorithm, meaning it can produce different results when run multiple times. You can control this by setting the random_state parameter.
This information was extracted from the OpenAI Cookbook (https://cookbook.openai.com/examples/visualizing_embeddings_in_2d).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@neon vector Use typscript instead
Let me check the knowledge base for you. One moment! :books: