भाग 1: to_categorical() फंक्शन को समझना
क्या आप जानते हैं कि वास्तविक-world समस्याओं में vocabulary का आकार बहुत बड़ा हो सकता है (जैसे 100,000 से भी अधिक)?
यह अभ्यास दो भागों में बँटा है और आप to_categorical() फंक्शन के num_classes आर्ग्युमेंट को सेट करने के महत्व के बारे में सीखेंगे. भाग 1 में, आप compute_onehot_length() फंक्शन इम्प्लीमेंट करेंगे जो दिए गए शब्दों की सूची के लिए one-hot वेक्टर जनरेट करता है और उन वेक्टरों की लंबाई निकालता है.
to_categorical() फंक्शन पहले से इम्पोर्ट किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Keras के साथ Machine Translation
अभ्यास निर्देश
compute_onehot_length()मेंwordsऔरword2indexका उपयोग करके word IDs बनाएँ.- word IDs का उपयोग करके
to_categorical()फंक्शन से onehot वेक्टर बनाएँ. <array>.shapeसिंटैक्स का उपयोग करके एक single onehot वेक्टर की लंबाई रिटर्न करें.He,drank,milkशब्दों की सूची के लिएcompute_onehot_length()का उपयोग करके onehot वेक्टरों की लंबाई compute करें और प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
def compute_onehot_length(words, word2index):
# Create word IDs for words
word_ids = [____[w] for w in ____]
# Convert word IDs to onehot vectors
onehot = ____(____)
# Return the length of a single one-hot vector
return onehot.____[1]
word2index = {"He":0, "drank": 1, "milk": 2}
# Compute and print onehot length of a list of words
print(____([____,____,____], ____))