1. Learn
  2. /
  3. 课程
  4. /
  5. 使用 OpenAI API 的 Embeddings 入门

Connected

道练习

可视化嵌入后的商品描述

既然您已经从商品描述生成了嵌入向量 (embedding — 向量表示),现在就来探索它们吧!您将使用 t-SNE 将嵌入数据的维度从 1,536 降到 2,这样更便于可视化。

您将从上一个练习中处理过的 products 字典列表开始,其中包含商品信息,以及您从 'short_description' 生成的嵌入向量。下面是 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 和 numpy 分别已按 plt 与 np 导入。

说明 1 / 共 3 个

undefined XP
    1
    2
    3
  • 使用列表推导从 products 中提取信息生成两个列表:categories,包含每个商品的 'category';以及 embeddings,包含嵌入后的简短描述。