Visualizing the embedded descriptions
Now that you've created embeddings from the product descriptions, it's time to explore them! You'll use t-SNE to reduce the number of dimensions in the embeddings data from 1,536 to two, which will make the data much easier to visualize.
You'll start with the products
list of dictionaries you worked with in the last exercise, containing product information and the embeddings you created from the 'short_description'
. As a reminder, here's a preview of products
:
products = [
{
"title": "Smartphone X1",
"short_description": "The latest flagship smartphone with AI-powered features and 5G connectivity.",
"price": 799.99,
"category": "Electronics",
"features": [
"6.5-inch AMOLED display",
"Quad-camera system with 48MP main sensor",
"Face recognition and fingerprint sensor",
"Fast wireless charging"
],
"embedding": [-0.014650369994342327, ..., 0.008677126839756966]
},
...
]
matplotlib.pyplot
and numpy
have been imported as plt
and np
, respectively.
This exercise is part of the course
Introduction to Embeddings with the OpenAI API
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create categories and embeddings lists using list comprehensions
categories = [product[____] for product in products]
embeddings = [product[____] for product in products]