Visualize Embeddings in 2D
OpenAI Cookbook notebook that reduces 1536-dim embeddings to 2D with t-SNE and plots them colored by star rating.
Why it matters
Reduce high-dimensional embedding data to 2D for easier visualization and analysis. Understand data separation and patterns through interactive plotting.
Outcomes
What it gets done
Reduce embedding dimensionality using t-SNE.
Plot embeddings in a 2D scatter plot.
Color plot points by star rating for visual analysis.
Observe data separation in the reduced dimensions.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/oai-visualizingembeddingsin2d | bash Steps
Steps in the chain
Overview
Visualizing Embeddings In 2D
Reduces 1536-dimension embeddings to 2D via t-SNE and plots them as a scatter plot colored by star rating. Use as a quick visual check that embeddings separate meaningfully by label before further analysis.
What it does
This notebook takes embeddings (produced in the companion Get_embeddings_from_dataset notebook) and reduces their dimensionality from 1536 down to 2 using t-SNE decomposition. It then plots the reduced embeddings as a 2D scatter plot, coloring each point by its review's star rating on a red-to-green scale, so the resulting chart shows how well embeddings of differently-rated reviews separate visually even after being compressed to just two dimensions.
When to use - and when NOT to
Use this when you want a quick, visual sanity check that your embeddings actually capture meaningful structure - for example, whether reviews with different star ratings form distinguishable clusters. This is a visualization/diagnostic step, not a retrieval or classification pipeline on its own; it depends on embeddings and a labeled dataset (here, star ratings) already existing.
Inputs and outputs
Input: high-dimensional (1536-dim) text embeddings plus their star-rating labels, sourced from the Get_embeddings_from_dataset notebook. Output: a 2D scatter plot of the t-SNE-reduced embeddings, colored by star rating, showing the degree of separation between rating groups.
Who it's for
Developers and analysts who want a fast visual check on whether their embeddings encode meaningful distinctions in their data before building downstream classification or retrieval on top of them.
Source README
Visualizing the embeddings in 2D
We will use t-SNE to reduce the dimensionality of the embeddings from 1536 to 2. Once the embeddings are reduced to two dimensions, we can plot them in a 2D scatter plot. The dataset is created in the Get_embeddings_from_dataset Notebook.
1. Reduce dimensionality
We reduce the dimensionality to 2 dimensions using t-SNE decomposition.
2. Plotting the embeddings
We colour each review by its star rating, ranging from red to green.
We can observe a decent data separation even in the reduced 2 dimensions.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.