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

मॉडल इनपुट के लिए टेक्स्ट डेटा तैयार करना

पिछले भाग में, आपने शब्दों के लिए index-to-word और word-to-index डिक्शनरी बनाना सीखा था. इस अभ्यास में, आप टेक्स्ट को characters के आधार पर विभाजित करेंगे और supervised learning के लिए डेटा तैयार करना जारी रखेंगे.

टेक्स्ट को characters में बाँटना पहले अटपटा लग सकता है, लेकिन text generation में यह अक्सर किया जाता है. साथ ही, डेटा तैयार करने की प्रक्रिया वही रहती है, फर्क सिर्फ इतना है कि टेक्स्ट को कैसे विभाजित किया जाता है.

आप training data बनाएँगे जिसमें निश्चित-लंबाई वाले टेक्स्ट की एक list और उनके labels होंगे, जहाँ label संबंधित अगला character होगा.

आप Sheldon (The Big Bang Theory) के quotes वाले dataset का उपयोग जारी रखेंगे, जो sheldon_quotes वैरिएबल में उपलब्ध है.

print_examples() फंक्शन इन जोड़ों को प्रिंट करता है ताकि आप देख सकें कि डेटा कैसे बदला. विवरण के लिए help() का उपयोग करें.

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

Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)

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

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

  • step को 2 और chars_window को 10 पर परिभाषित करें.
  • अगला sentence वैरिएबल sentences में append करें.
  • टेक्स्ट sheldon में सही position को वैरिएबल next_chars में append करें.
  • print_examples() फंक्शन का उपयोग करके 10 sentences और उनके next characters प्रिंट करें.

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

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

# Create lists to keep the sentences and the next character
sentences = []   # ~ Training data
next_chars = []  # ~ Training labels

# Define hyperparameters
step = ____          # ~ Step to take when reading the texts in characters
chars_window = ____ # ~ Number of characters to use to predict the next one  

# Loop over the text: length `chars_window` per time with step equal to `step`
for i in range(0, len(sheldon_quotes) - chars_window, step):
    sentences.____(sheldon_quotes[i:i + chars_window])
    next_chars.append(sheldon_quotes[____])

# Print 10 pairs
print_examples(____, ____, 10)
कोड संपादित करें और चलाएँ