Inizia subitoInizia gratis

Controllare il vocabolario con il Tokenizer

Approfondiamo un po' il funzionamento del Tokenizer. In questo esercizio imparerai a convertire una frase qualsiasi in una sequenza usando un Tokenizer già addestrato. Inoltre, imparerai a controllare la dimensione del vocabolario del Tokenizer. Esaminerai anche cosa succede alle parole fuori vocabolario (OOV) quando limiti la dimensione del vocabolario di un Tokenizer.

Per questo esercizio, ti è stato fornito il Tokenizer en_tok che hai implementato in precedenza. Il Tokenizer è già stato importato per te.

Questo esercizio fa parte del corso

Traduzione automatica con Keras

Visualizza corso

Istruzioni dell'esercizio

  • Converte la seguente frase in una sequenza usando il Tokenizer en_tok: she likes grapefruit , peaches , and lemons .
  • Crea un nuovo Tokenizer, en_tok_new, con un vocabolario di dimensione 50 e parola fuori vocabolario UNK.
  • Esegui il fit del nuovo tokenizer sui dati en_text.
  • Converte la frase she likes grapefruit , peaches , and lemons . in una sequenza con en_tok_new.

esercizio interattivo pratico

Prova questo esercizio completando questo codice di esempio.

# 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])
Modifica ed esegui il codice