Neural Machine Translation (NMT) using Keras

Muhammad Abu Talha
2 min readAug 17, 2022

--

A step by step implementation of neural machine translation using sequence to sequence algorithm in keras. Urdu as the target language and English as the source language.

This article provides a step-by-step breakdown of how to create a neural machine translator that uses Urdu as the target language and English as the source language. In keras, we’ll be utilizing Long Short Term Memory (LSTM) units.

Prerequisites:

A step by step implementation of a neural machine translation(NMT) using Teacher forcing without Attention mechanism. Implementation is using keras library with LSTM as the basic block

High-level steps for implementation of NMT involves

  • Reading the data from the file containing the source and target sentences
  • Cleaning the data by converting to lowercase, removing spaces, special characters, digits, and quotes
  • Tag the start and end of the target sentence using START_ and _END respectively for training and inference
  • Create the dictionary of unique source and target words to vector and vice-versa
  • Shuffle the data for better generalization
  • Split the dataset into train and test data
  • Create the data; we will be using fit() to fit the data to the model
  • Build the encoder using Embedding and LSTM layers
  • Build the decoder using Embedding and LSTM layers and takes input from the embedding layer and the encoder states.
  • Compile the model and train the model
  • Make predictions from the model

Implementation

All code implemented in Google Colab Notebook which is appended below as well as code and dataset also available on GitHub repository .

Some predictions were good, some reasonable and some not right.

Code and dataset available on GitHub repository .

Reference:

Additional Information:

If you want to implement sequence to sequence with attention in PyTorch below blog will help you.

--

--