1. Learn
  2. /
  3. कोर्स
  4. /
  5. OpenAI API के साथ Embeddings परिचय

Connected

अभ्यास

कलेक्शन में डेटा जोड़ना

अब अपनी कलेक्शन में Netflix की फ़िल्में और टीवी शोज़ जोड़ने का समय है! आपको डॉक्यूमेंट IDs और टेक्स्ट्स की एक सूची दी गई है, जो क्रमशः ids और documents में स्टोर हैं. इन्हें netflix_titles.csv से नीचे दिए गए कोड द्वारा निकाला गया है:

ids = []
documents = []

with open('netflix_titles.csv') as csvfile:
  reader = csv.DictReader(csvfile)
  for i, row in enumerate(reader):
    ids.append(row['show_id'])
    text = f"Title: {row['title']} ({row['type']})\nDescription: {row['description']}\nCategories: {row['listed_in']}"
    documents.append(text)

एंबेड होने वाली जानकारी का एक उदाहरण देने के लिए, documents का पहला डॉक्यूमेंट यहाँ है:

Title: Dick Johnson Is Dead (Movie)
Description: As her father nears the end of his life, filmmaker Kirsten Johnson stages his death in inventive and comical ways to help them both face the inevitable.
Categories: Documentaries

सारी ज़रूरी functions और packages इम्पोर्ट कर दिए गए हैं, और एक persistent client बना कर client को असाइन कर दिया गया है.

निर्देश

100 XP
  • अपनी netflix_titles कलेक्शन को दोबारा बनाएँ.
  • डॉक्यूमेंट्स और उनके IDs कलेक्शन में जोड़ें.
  • collection में डॉक्यूमेंट्स की संख्या और पहली दस आइटम्स प्रिंट करें.