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

नया टेक्स्ट ट्रांसफॉर्म करना

इस अभ्यास में, आप पहले बनाए गए dictionaries का उपयोग करके नए टेक्स्ट को संख्यात्मक इंडेक्स की sequences में ट्रांसफॉर्म करेंगे.

यह तब उपयोगी होता है जब आपके पास पहले से प्रशिक्षित मॉडल हो और आप उसे किसी नए डेटासेट पर लागू करना चाहें. प्रशिक्षण डेटा पर किए गए preprocessing स्टेप्स नए टेक्स्ट पर भी लागू होने चाहिए, ताकि मॉडल सही तरीके से prediction/classification कर सके.

यहाँ, आप एक विशेष टोकन '<UKN/>' भी उपयोग करेंगे जो उन शब्दों का प्रतिनिधित्व करेगा जो vocabulary में नहीं हैं. आम तौर पर ऐसे special tokens dictionaries के शुरुआती इंडेक्स होते हैं, यानी position 0.

वैरिएबल word_to_index, index_to_word और vocabulary पहले से environment में लोड हैं. साथ ही, नए टेक्स्ट वाला वैरिएबल new_text के रूप में लोड है. नए टेक्स्ट को आपके लिए देखने हेतु प्रिंट किया गया है.

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

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

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

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

  • वाक्यों वाली list new_text पर लूप चलाइए.
  • यदि शब्द dictionary में न मिले, तो उसका इंडेक्स 0 सेट कीजिए.
  • इंडेक्स वाले वाक्य को वैरिएबल new_text_split में append कीजिए.
  • dictionary index_to_word का उपयोग करके इंडेक्स को वापस टेक्स्ट में बदलिए.

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

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

# Loop through the sentences and get indexes
new_text_split = []
for sentence in ____:
    sent_split = []
    for wd in sentence.split(' '):
        index = word_to_index.get(wd, ____)
        sent_split.append(index)
    new_text_split.append(____)

# Print the first sentence's indexes
print(new_text_split[0])

# Print the sentence converted using the dictionary
print(' '.join([index_to_word[____] for index in new_text_split[0]]))
कोड संपादित करें और चलाएँ