Part 1: Treasure hunt
आपने हाल ही में एक हरे-भरे ट्रॉपिकल द्वीप की ऑल-पेड यात्रा जीती है. वहाँ घूमते समय आपको एक प्राचीन खज़ाने का नक्शा मिला, जो किसी बड़े खज़ाने की ओर इशारा कर रहा था. उस पर 1s और 0s में लिखे कुछ गोपनीय संदेश थे. अभी-अभी यह कोर्स करने के बाद, आप तुरंत पहचान लेते हैं कि यह onehot encoded वेक्टरों का सीक्वेंस है. आपको शब्द से इंडेक्स की मैपिंग भी मिल गई है, जिससे पता चलता है कि कौन-सा शब्द किस ID से मेल खाता है.
अब आपको इस गोपनीय संदेश को डिक्रिप्ट करना है और जानना है कि नक्शा क्या कह रहा है. आपको treasure_map दिया गया है, जो एक number of sentences × number of words × onehot vector length मैट्रिक्स है. साथ ही आपको index2word Python dictionary भी दी गई है, जो किसी ID को उसके शब्द से मैप करती है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Keras के साथ Machine Translation
अभ्यास निर्देश
treasure_mapमें मौजूद onehot encoded वेक्टरों से शब्द IDs निकालें (onehot वेक्टर की dimension सबसे आखिर में है).treasure_mapसे sequence length (यानी time steps की संख्या) निकालकरseq_lenमें असाइन करें.i-thवाक्य मेंt-thपोजीशन पर शब्द ID प्राप्त करें.widके अनुरूपStringप्रकार का वास्तविक शब्द (यानी शब्द ID नहीं) सूचीwordsमें append करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Get the word IDs from the treasure map
word_ids = ____.____(____, axis=____)
# Get the sequence length from the treasure map
seq_len = treasure_map.shape[____]
for i in range(treasure_map.shape[0]):
words = []
for t in range(seq_len):
# Get the word ID for the i-th sentence and t-th position
wid = word_ids[i, ____]
if wid != 0:
# Append the word corresponding to wid
words.append(____[____])
print("Instruction ", i+1, ": ", ' '.join(words))