O'Reilly logo

Hands-On Natural Language Processing with Python by Rajalingappaa Shanmugamani, Rajesh Arumugam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Training

We will now train our network on the French sentence and the corresponding English translation. Before that, we will look into the function that outputs the training batches:

def get_batches(en_text, fr_text, batch_size):    for batch_idx in range(0, len(fr_text)//batch_size):        start_idx = batch_idx * batch_size        en_batch = en_text[start_idx:start_idx + batch_size]        fr_batch = fr_text[start_idx:start_idx + batch_size]        pad_en_batch = np.array(pad_sentences(en_batch, en_word2int))        pad_fr_batch = np.array(pad_sentences(fr_batch,fr_word2int))        pad_en_lens = []        for en_b in pad_en_batch:            pad_en_lens.append(len(en_b))         pad_fr_lens = []        for fr_b in pad_fr_batch:            pad_fr_lens.append(len(fr_b))  yield pad_en_batch, pad_fr_batch, pad_en_lens, pad_fr_lens ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required