BaşlayınÜcretsiz başlayın

Zenginleştirilmiş embeddings

Daha önce ürün bilgilerini embed ederken, yalnızca ürünün 'short_description' alanını embed edebiliyordun; bu alan bazı ilgili bilgileri yakalasa da tümünü kapsamıyordu. Bu egzersizde, çok daha fazla bilgiyi yakalamak için 'title', 'short_description', 'category' ve 'features' alanlarını embed edeceksin.

İşte products sözlük listesine bir hatırlatma:

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"
        ]
    },
    ...
]

Özellikleri tek bir metinde birleştirirken, yapı aşağıdaki gibi olmalıdır:

Title: <product title>
Description: <product description>
Category: <product category>
Features: <feature 1>; <feature 2>; <feature 3>; ...

Bu egzersiz, kursun bir parçasıdır

OpenAI API ile Embeddings’e Giriş

Kursa Göz Atın

Egzersiz talimatları

  • title, short_description, category ve features verilerini istenen yapıda tek bir metinde birleştirmek için create_product_text() adlı bir fonksiyon tanımla.
  • products içindeki her ürün için özellikleri birleştirmek üzere create_product_text() fonksiyonunu kullan ve sonuçları bir listede sakla.
  • product_texts içindeki metinleri embed et.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Define a function to combine the relevant features into a single string
def create_product_text(product):
  return f"""Title: {____}
Description: {____}
Category: {____}
Features: {____}"""

# Combine the features for each product
product_texts = [____ for product in ____]

# Create the embeddings from product_texts
product_embeddings = ____
Kodu Düzenle ve Çalıştır