IniziaInizia gratis

Training the model

Did you know that in 2017, Google translate served more than 500 million users daily?

Here, you will train your first Teacher Forced model. Teacher Forcing is commonly used in sequence to sequence models like your neural machine translator to achieve better performance.

You will be provided with the sents2seqs() function, English sentences en_text and French sentences fr_text.

Questo esercizio fa parte del corso

Machine Translation with Keras

Visualizza il corso

Istruzioni dell'esercizio

  • Get the decoder input which contains the onehot encoded sequences of French words (except for the last word in every sequence).
  • Get the decoder output which contains the onehot encoded sequences of French words (except for the first word in every sequence).
  • Train the model on a single batch of data.
  • Obtain the evaluation metrics (loss and accuracy) for training data en_x, de_x and de_y.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

n_epochs, bsize = 3, 250

for ei in range(n_epochs):
  for i in range(0,data_size,bsize):
    en_x = sents2seqs('source', en_text[i:i+bsize], onehot=True, reverse=True)
    de_xy = sents2seqs('target', fr_text[i:i+bsize], onehot=True)
    # Separate the decoder inputs from de_xy
    de_x = ____[:,____,:]
    # Separate the decoder outputs from de_xy
    de_y = ____[____]
    # Train the model on a single batch of data    
    nmt_tf.____([____,____], ____)    
    # Obtain the eval metrics for the training data
    res = _____.evaluate([____,____], ____, batch_size=bsize, verbose=0)
    print("{} => Train Loss:{}, Train Acc: {}".format(ei+1,res[0], res[1]*100.0))  
Modifica ed esegui il codice