पैरामीटर्स की संख्या की तुलना
आपने देखा कि one-hot representation शब्दों के लिए अच्छा प्रतिनिधित्व नहीं है क्योंकि यह बहुत sparse होता है. Embedding लेयर का उपयोग करने से वेक्टर्स का dense representation बनता है, लेकिन साथ ही सीखने के लिए बहुत सारे पैरामीटर्स भी चाहिए होते हैं.
इस अभ्यास में आप embeddings और one-hot एनकोडिंग वाले दो मॉडलों के पैरामीटर्स की संख्या की तुलना करेंगे ताकि अंतर समझ सकें.
मॉडल model_onehot पहले से एनवायरनमेंट में लोड है, और keras से Sequential, Dense और GRU भी. अंत में, पैरामीटर्स vocabulary_size=80000 और sentence_len=200 भी लोड हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Keras के साथ भाषा मॉडलिंग के लिए Recurrent Neural Networks (RNNs)
अभ्यास निर्देश
keras.layersसेEmbeddingलेयर इम्पोर्ट करें.- Embedding लेयर पर, input dimension के रूप में vocabulary size में एक जोड़ें, और input length के रूप में sentence size दें.
- मॉडल को compile करें.
- Embedding वाले मॉडल का summary प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the embedding layer
from tensorflow.keras.layers import ____
# Create a model with embeddings
model = Sequential(name="emb_model")
model.add(Embedding(input_dim=____, output_dim=wordvec_dim, input_length=____, trainable=True))
model.add(GRU(128))
model.add(Dense(1))
model.____(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Print the summaries of the one-hot model
model_onehot.summary()
# Print the summaries of the model with embeddings
model.____