July 2018
Beginner to intermediate
312 pages
8h 31m
English
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 ...
Read now
Unlock full access