शुरू करेंमुफ़्त में शुरू करें

प्रोडक्ट रिकमेंडेशन सिस्टम

इस अभ्यास में, आप एक ऑनलाइन रिटेलर के लिए रिकमेंडेशन सिस्टम बनाएँगे जो विभिन्न प्रोडक्ट बेचता है. यह सिस्टम उन उपयोगकर्ताओं को तीन मिलते-जुलते प्रोडक्ट सुझाता है जो किसी प्रोडक्ट पेज पर जाते हैं लेकिन खरीद नहीं करते, उनके द्वारा देखे गए अंतिम प्रोडक्ट के आधार पर.

आपको साइट पर उपलब्ध प्रोडक्ट्स की डिक्शनरीज़ की एक लिस्ट दी गई है,

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

और वह डिक्शनरी भी दी गई है जो उपयोगकर्ता द्वारा देखे गए अंतिम प्रोडक्ट का विवरण रखती है, last_product में स्टोर है.

कोर्स में पहले परिभाषित निम्नलिखित कस्टम फंक्शन भी आपके उपयोग के लिए उपलब्ध हैं:

  • create_embeddings(texts)texts में प्रत्येक टेक्स्ट के लिए embeddings (एम्बेडिंग — वेक्टर रूप में निरूपण) की लिस्ट लौटाता है.
  • create_product_text(product)product की विशेषताओं (features) को मिलाकर एम्बेडिंग के लिए एक एकल स्ट्रिंग बनाता है.
  • find_n_closest(query_vector, embeddings, n=3) → cosine distances के आधार पर query_vector और embeddings के बीच n सबसे नज़दीकी दूरियाँ और उनके इंडेक्स लौटाता है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

OpenAI API के साथ Embeddings परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • create_product_text() का उपयोग करके, last_product और products में प्रत्येक product के text features को संयोजित करें.
  • create_embeddings() से last_product_text और product_texts को embed करें, और सुनिश्चित करें कि last_product_embeddings एक single list हो.
  • find_n_closest() का उपयोग करके तीन सबसे छोटी cosine distances और उनके इंडेक्स ढूँढ़ें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Combine the features for last_product and each product in products
last_product_text = ____
product_texts = ____

# Embed last_product_text and product_texts
last_product_embeddings = ____
product_embeddings = ____

# Find the three smallest cosine distances and their indexes
hits = ____(____, product_embeddings)

for hit in hits:
  product = products[hit['index']]
  print(product['title'])
कोड संपादित करें और चलाएँ