Tokenizer के साथ vocabulary नियंत्रित करना
आइए Tokenizer के कामकाज को थोड़ा और गहराई से समझें. इस अभ्यास में आप सीखेंगे कि किसी भी वाक्य को trained Tokenizer की मदद से sequence में कैसे बदला जाए. इसके अलावा, आप यह भी सीखेंगे कि Tokenizer की vocabulary का आकार कैसे नियंत्रित करें. आप यह भी जाँचेंगे कि जब आप किसी Tokenizer की vocabulary का आकार सीमित करते हैं, तो out-of-vocabulary (OOV) शब्दों के साथ क्या होता है.
इस अभ्यास के लिए, आपको पहले से लागू किया हुआ en_tok Tokenizer दिया गया है. आपके लिए यह Tokenizer import कर लिया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Keras के साथ Machine Translation
अभ्यास निर्देश
- पिछले
en_tokTokenizer का उपयोग करके नीचे दिए गए वाक्य को sequence में बदलें:she likes grapefruit , peaches , and lemons . - एक नया
Tokenizerबनाएँ,en_tok_new, जिसकी vocabulary size 50 हो और out-of-vocabulary शब्दUNKहो. - नए tokenizer को
en_textडेटा पर fit करें. en_tok_newके साथ वाक्यshe likes grapefruit , peaches , and lemons .को sequence में बदलें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Convert the sentence to a word ID sequence
seq = ____.____(['she likes grapefruit , peaches , and lemons .'])
print('Word ID sequence: ', seq)
# Define a tokenizer with vocabulary size 50 and oov_token 'UNK'
en_tok_new = ____(num_words=____, ____=____)
# Fit the tokenizer on en_text
en_tok_new.____(____)
# Convert the sentence to a word ID sequence
seq_new = en_tok_new.____(['she likes grapefruit , peaches , and lemons .'])
print('Word ID sequence (with UNK): ', seq_new)
print('The ID 1 represents the word: ', en_tok_new.index_word[1])