Enriching embeddings
पहले, जब आपने प्रोडक्ट जानकारी को embed किया था, तो आप केवल प्रोडक्ट की 'short_description' तक सीमित थे. इससे कुछ प्रासंगिक जानकारी तो मिली, लेकिन सारी नहीं. इस अभ्यास में, आप और अधिक जानकारी कैप्चर करने के लिए 'title', 'short_description', 'category', और 'features' को embed करेंगे.
यहाँ products नाम की dictionaries की list की याद दिलाई गई है:
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"
]
},
...
]
जब features को एक single string में मिलाएँ, तो उसका स्ट्रक्चर इस प्रकार होना चाहिए:
Title: <product title>
Description: <product description>
Category: <product category>
Features: <feature 1>; <feature 2>; <feature 3>; ...
यह अभ्यास पाठ्यक्रम का हिस्सा है
OpenAI API के साथ Embeddings परिचय
अभ्यास निर्देश
create_product_text()नाम का एक फंक्शन परिभाषित करें, जोtitle,short_description,category, औरfeaturesडेटा को वांछित स्ट्रक्चर में एक single string में जोड़ दे.create_product_text()का उपयोग करकेproductsमें हर प्रोडक्ट के features को मिलाएँ और परिणामों को एक list में स्टोर करें.product_textsमें मौजूद टेक्स्ट को embed करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# 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 = ____