सबसे मिलते-जुलते प्रोडक्ट को खोजना
एम्बेडिंग्स के बीच similarity निकाल पाना, embeddings-आधारित एप्लिकेशनों का एक मुख्य चरण है। इस अभ्यास में, आप पहले इस्तेमाल की गई products list-of-dictionaries पर वापस आएँगे, जिसमें वे embedded short descriptions शामिल हैं जो आपने पहले बनाए थे.
आप किसी एक टेक्स्ट को इन embedded descriptions से तुलना करेंगे ताकि सबसे मिलती-जुलती description पहचान सकें.
numpy को np नाम से इम्पोर्ट किया गया है, और scipy.spatial से distance उपलब्ध है। आपके लिए एक create_embeddings() फंक्शन पहले से परिभाषित है, जिसे किसी एकल इनपुट से embeddings बनाने के लिए उपयोग कर सकते हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
OpenAI API के साथ Embeddings परिचय
अभ्यास निर्देश
- अपने
create_embeddings()custom फंक्शन का उपयोग करके"soap"टेक्स्ट को embed करें और embeddings की एक सिंगल list निकालें. query_embeddingऔरproductमें मौजूद embeddings के बीच cosine distance निकालें.distancesमें उपलब्ध cosine distances का उपयोग करके सर्च टेक्स्ट के सबसे मिलते-जुलते प्रोडक्ट का'short_description'ढूँढें और प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Embed the search text
search_text = "soap"
search_embedding = ____
distances = []
for product in products:
# Compute the cosine distance for each product description
dist = ____(search_embedding, ____)
distances.append(dist)
# Find and print the most similar product short_description
min_dist_ind = ____
print(____)