

{"id":97724,"date":"2021-06-21T13:18:00","date_gmt":"2021-06-21T07:48:00","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=97724"},"modified":"2026-06-01T14:40:10","modified_gmt":"2026-06-01T09:10:10","slug":"language-translation-machine-learning","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/","title":{"rendered":"Language Translation with Machine Learning"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2645,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/17LKhnKqt7eb6LozlZKgv3Ziak3RzbHWh\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p><strong>Create a real-time machine learning language translator with TensorFlow<\/strong><\/p>\n<p>Savez-vous comment cr\u00e9er une application de traduction de langue?<\/p>\n<p>Did you understand the above sentence?<\/p>\n<p>Well after googling it, I found its meaning as:<\/p>\n<p>Do you know how to create a language translator app?<\/p>\n<p>We all know about Google Translate which allows us to convert from one language to another and it\u2019s very useful for learning and understanding new languages.<\/p>\n<h3>About Language Translator Project:<\/h3>\n<p>In this machine learning project, we will develop a Language Translator App using a many-to-many encoder-decoder sequence model. We will train our model using LSTM which will convert English to French language where English will be input text and French will be the target text. For this, we will be using English-French dataset.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>This project requires you to have a good knowledge of Python, TensorFlow, and Keras.<\/p>\n<p>Modules required for this project are tensorflow, pickle, and sklearn. You can install with the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install tensorflow , pickle , sklearn , numpy<\/pre>\n<p>The versions which are used in this project for python and its corresponding modules are as follows:<\/p>\n<ul>\n<li>python: 3.8.5<\/li>\n<li>TensorFlow: 2.3.1 (<em>Note: TensorFlow version should be 2.2 or higher in order to use keras or else install keras directly<\/em>)<\/li>\n<li>Sklearn: 0.24.2<\/li>\n<li>Pickle: 4.0<\/li>\n<li>Numpy: 1.19.5<\/li>\n<\/ul>\n<h3>Download Language Translation Machine Learning Code<\/h3>\n<p>Please download the source code of language translation machine learning: <a href=\"https:\/\/drive.google.com\/file\/d\/17LKhnKqt7eb6LozlZKgv3Ziak3RzbHWh\/view?usp=drive_link\"><strong>Language Translation Machine Learning Code<\/strong><\/a><\/p>\n<h3>Project file structure:<\/h3>\n<ul>\n<li>eng-french.txt: This is dataset for our project, contains English text and corresponding french texts.<\/li>\n<li>langTraining.py: This file is used to create and train the model.<\/li>\n<li>training_data.pkl: This file contains lists of characters, text of input, and target data in a binary format.<\/li>\n<li>s2s: This directory contains optimizer, metrics, and weights of our trained model.<\/li>\n<li>LangTransGui.py: Gui file of our project where we load the trained model and predict output for given text.<\/li>\n<\/ul>\n<h3>Steps to develop a Language Translator App:<\/h3>\n<h4>1. Import Libraries and initialize variables.<\/h4>\n<p>Firstly we will create a file called \u201clangTraining.py\u201d and import all libraries which have been shared in the prerequisites section. Also we need to initialize variables globally which can be used throughout our functions.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tensorflow.keras.models import Model\r\nfrom tensorflow.keras import models\r\nfrom tensorflow.keras.utils import plot_model\r\nfrom tensorflow.keras.layers import Input,LSTM,Dense\r\nfrom sklearn.feature_extraction.text import CountVectorizer\r\n\r\nimport numpy as np\r\nimport pickle\r\n\r\n#initialize all variables \r\ninput_texts=[]\r\ntarget_texts=[]\r\ninput_characters=set()\r\ntarget_characters=set()\r\n<\/pre>\n<h4>2. Parse the dataset file<\/h4>\n<p>We will traverse the dataset file and extract all the input and target texts. For this, we will be using the first 10,000 rows of our dataset for the training and testing part. It can be changed as per requirements. To separate input and target texts from the row we will use \u2018\\t\u2019 and to separate rows we will use \u2018\\n\u2019.<\/p>\n<p>We will also use the Teacher Forcing algorithm:<\/p>\n<p>Teacher Forcing Algorithm (TFA): The TFA network model uses ground truth input rather than output from the previous model.<\/p>\n<p>For example, we want to predict the next word from the sequence \u2018Python is a programming language\u2019. So we will put \u2018\\t\u2019 at the start and \u2018\\n\u2019 at the end of the text(sequence) to tell the model that this is the starting and ending of the text which becomes \u2018\\tPython is a programming language\\n\u2019. So we feed \u2018\\t\u2019 to the model at the first timestep and so on for every timestep.<\/p>\n<p><strong>(x)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (y^)<\/strong><\/p>\n<p>\\t,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Python<br \/>\n\\tPython,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 is<br \/>\n\\tPython is,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 a<\/p>\n<p>As you can see after feeding input(x) it is predicting the next word(y^), it will do the same till it reaches \u2018\\n\u2019 which is our end of the sentence. This can be seen in Google when we type some words, next words are automatically predicted.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#read dataset file\r\nwith open('eng-french.txt','r',encoding='utf-8') as f:\r\n    rows=f.read().split('\\n')\r\n\r\n#read first 10,000 rows from dataset     \r\nfor row in rows[:10000]:\r\n\r\n    #split input and target by '\\t'=tab\r\n    input_text,target_text = row.split('\\t')\r\n\r\n    #add '\\t' at start and '\\n' at end of text.\r\n    target_text='\\t' + target_text + '\\n'\r\n    input_texts.append(input_text.lower())\r\n    target_texts.append(target_text.lower())\r\n\r\n    #split character from text and add in respective sets\r\n    input_characters.update(list(input_text.lower()))\r\n    target_characters.update(list(target_text.lower()))\r\n<\/pre>\n<p><strong>dataset file:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97729\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file.png\" alt=\"project dataset file\" width=\"869\" height=\"535\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file.png 869w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file-768x473.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file-720x443.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file-520x320.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/project-dataset-file-320x197.png 320w\" sizes=\"auto, (max-width: 869px) 100vw, 869px\" \/><\/a><\/p>\n<p>Now, We will use the same procedure and separate the text from rows and characters. Also, get the maximum length of encoder as well as decoder sequence. Repeat the same for target text as well.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#sort input and target characters \r\ninput_characters = sorted(list(input_characters))\r\ntarget_characters = sorted(list(target_characters))\r\n\r\n#get the total length of input and target characters\r\nnum_en_chars = len(input_characters)\r\nnum_dec_chars = len(target_characters)\r\n\r\n#get the maximum length of input and target text.\r\nmax_input_length = max([len(i) for i in input_texts])\r\nmax_target_length = max([len(i) for i in target_texts])\r\n\r\nprint(\"number of encoder characters : \",num_en_chars)\r\nprint(\"number of decoder characters : \",num_dec_chars)\r\n\r\nprint(\"maximum input length : \",max_input_length)\r\nprint(\"maximum target length : \",max_target_length)\r\n<\/pre>\n<p>After the execution of above code, we will get the total number of encoder characters, the total number of decoder characters, maximum input length, and maximum target length.<\/p>\n<h4>3. One Hot Encoding (Vectorization)<\/h4>\n<p>Models cannot work directly on the categorical data. For this, we require one hot encoding process. One-hot encoding deals with the data in binary format so we encode the categorical data in binary format.<\/p>\n<p>One-hot means that we can only make an index of data 1 (true) if it is present in the vector or else 0 (false). So every data has its unique representation in vector format.<\/p>\n<p>For example, if we have an array of data like : [\u201cpython\u201d,\u201djava\u201d,\u201dc++\u201d] then the one hot encoding representation of this array will be :<\/p>\n<p>[ [ 1 , 0 , 0 ]<br \/>\n[ 0 , 1 , 0 ]<br \/>\n[ 0 , 0 , 1 ] ]<\/p>\n<p>So in our project after separating characters from input and target text we will use a one-hot encoding process. We will fit characters and transform the texts accordingly. So if the character from input text is present in the sets of characters then it will put 1 and 0 otherwise.<\/p>\n<p>Our encoder input data, decoder input data, and decoder target data will be a 3D array where encoder input data will have shape (number of pairs, max length of English text, number of English text characters), decoder input data will have shape (number of pairs, max length of french texts, number of french characters). Decoder target data will be same as decoder input data but it will be one timestep ahead as it will not include the start character i.e. \u2018\\t\u2019 of our target sentence.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def bagofcharacters(input_texts,target_texts):\r\n\r\n    #initialize encoder , decoder input and target data.\r\n    en_in_data=[] ; dec_in_data=[] ; dec_tr_data=[]\r\n\r\n    #padding variable with first character as 1 as rest all 0.\r\n    pad_en=[1]+[0]*(len(input_characters)-1)\r\n    pad_dec=[0]*(len(target_characters)) ; pad_dec[2]=1\r\n\r\n    #countvectorizer for one hot encoding as we want to tokenize character so\r\n    #analyzer is true and None the stopwords action.\r\n    cv=CountVectorizer(binary=True,tokenizer=lambda txt:\r\n    txt.split(),stop_words=None,analyzer='char')\r\n  \r\n    for i,(input_t,target_t) in enumerate(zip(input_texts,target_texts)):\r\n        #fit the input characters into the CountVectorizer function\r\n        cv_inp= cv.fit(input_characters)\r\n    \r\n        #transform the input text from the help of CountVectorizer fit.\r\n        #it character present than put 1 and 0 otherwise.\r\n        en_in_data.append(cv_inp.transform(list(input_t)).toarray().tolist())\r\n        cv_tar= cv.fit(target_characters)\t\t\r\n        dec_in_data.append(cv_tar.transform(list(target_t)).toarray().tolist())\r\n\r\n        #decoder target will be one timestep ahead because it will not consider \r\n        #the first character i.e. '\\t'.\r\n        dec_tr_data.append(cv_tar.transform(list(target_t)[1:]).toarray().tolist())\r\n<\/pre>\n<p>Also, we need the same length of input data throughout so we will be adding an extra array of 0\u2019s to make all input text the same vector length. Repeat the same procedure for target data also.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">  #add padding variable if the length of the input or target text is smaller\r\n  #than their respective maximum input or target length. \r\n  if len(input_t) &lt; max_input_length:\r\n    for _ in range(max_input_length-len(input_t)):\r\n      en_in_data[i].append(pad_en)\r\n  if len(target_t) &lt; max_target_length:\r\n    for _ in range(max_target_length-len(target_t)):\r\n      dec_in_data[i].append(pad_dec)\r\n  if (len(target_t)-1) &lt; max_target_length:\r\n    for _ in range(max_target_length-len(target_t)+1):\r\n      dec_tr_data[i].append(pad_dec)\r\n\r\n#convert list to numpy array with data type float32\r\nen_in_data=np.array(en_in_data,dtype=\"float32\")\r\ndec_in_data=np.array(dec_in_data,dtype=\"float32\")\r\ndec_tr_data=np.array(dec_tr_data,dtype=\"float32\")\r\nreturn en_in_data,dec_in_data,dec_tr_data\r\n<\/pre>\n<h4>4. Build the training model<\/h4>\n<p>In this language translation project, we will be using LSTM to train our machine learning model to translater language, so let\u2019s see what is LSTM:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-architecture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97730\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-architecture.jpg\" alt=\"lstm architecture\" width=\"614\" height=\"400\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-architecture.jpg 614w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-architecture-520x339.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-architecture-320x208.jpg 320w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/p>\n<p><strong>LSTM (Long Short Term Memory) network:<\/strong> LSTM is a type of RNN (Recurrent Neural Network) that solves scenarios where RNN is failed.<\/p>\n<p>Long-Term Dependency: In RNN, networks have the data of previous output in memory for a short period of time because of this they are unaware about the actual context of the sentence over a long period of time. This raised the issue of long-term dependency.<\/p>\n<p>Vanishing Gradient: While training our models, in order to get the best output we have to minimize the loss i.e. errors after every time step. This can be achieved by propagating backward and calculating the gradients, that is loss with respect to weights applied to every vector at different time steps. We repeat this process until we get an optimal set of weights for which the error is minimum. After reaching at some time step gradient value becomes so less that it approximates to zero or gradient vanishes. After reaching that limit, the network stops training. This leads to the problem of vanishing gradient.<\/p>\n<p>These are some issues which are resolved by the LSTM networks. Instead of a single neural network layer, LSTM has three gates along with hidden and cell states. We will use following example to understand the basic functionality of LSTM:<\/p>\n<p>\u201cJohn wants to know how <strong>Language Translators<\/strong> work so he started studying a technique known as <strong>Deep Learning<\/strong>. His friend Jim, on the other hand, is interested in <strong>Self-Driving Cars<\/strong> and is learning about a technique known as <strong>Reinforcement Learning<\/strong>.\u201d<\/p>\n<p><strong>Cell Memory state ( ct ):<\/strong> Cell state is actually what makes LSTM a unique network. Cell state holds the memory for over a long period of time. Data can be removed or added in cell state depending upon the layer requirements.<\/p>\n<p><strong>Hidden state ( ht ):<\/strong> hidden state is basically output of the previous block. We decide what to do with the memory looking at the previous hidden state output and current input. And also we don\u2019t want output after every timestep until we reach the last input of our sequence.<\/p>\n<p><strong>Forget Gate ( ft ):<\/strong> Forget Gate is used to check what data we want to neglect away from the cell state. This is done using a sigmoid layer. This Gate looks at hidden output from previous time steps and current input, after that it outputs number 0 which means neglect the data, or 1 means keep the data.<\/p>\n<p>So from our example, in the first half of the sentence, we say \u201cJohn\u201d is interested in \u201cLanguage Translator\u201d. In order to answer \u201cDeep Learning\u201d, we can frame a question like \u201cWhich technique is used to develop a Language Translator?\u201d For this, we require \u201cLanguage Translator\u201d throughout every time step. So what about \u201cJohn\u201d? In this sentence the context is about technique, so we don\u2019t require \u201cJohn\u201d therefore we will forget or remove the data of \u201cJohn\u201d using forget Gate ( ft ).<\/p>\n<p><strong>Input Gate:<\/strong> We want to check what new information we are going to store in the cell memory state ( ct ). So data will pass through the sigmoid function which decides which values to update ( it ). Next a tanh function creates a vector of new candidates ( \u010dt ) for our state.<\/p>\n<p>Now our new data is ready and we want to update cell state with our new data. In order to do that we will multiply the old value of the cell state with the forget gate which will remove the data and then add the combined value of the tanh function which contains the candidate value ( \u010dt ) and the input vector ( it ) for the new data.<\/p>\n<p>From our example we know \u201cLanguage translator\u201d is required so we will store that in the cell state which can be accessible for the layers after every time step. And likewise we also want \u201ctechnique\u201d so we will store it in cell state.<\/p>\n<p>Now our cell state contains \u201cLanguage Translator\u201d as well as \u201ctechnique\u201d.<\/p>\n<p><strong>Output Gate:<\/strong> We want to pass the output to the next layer. As the output is dependent upon the cell state, we will be using sigmoid which decides what parts of the cell state we are going to output. Then we will apply tanh and multiply them with sigmoid value of output ( ot ) so that we only output values that are required.<\/p>\n<p>So we will pass cell state and hidden state value output to another block of the LSTM layer as an input.<\/p>\n<p>For the second part of our example now his friend \u201cJim\u201d is interested in \u201cSelf-Driving Cars\u201d we can frame a question like \u201cWhich technique is used for Self-Driving Cars?\u201d.<\/p>\n<p>As you can see the context remains same i.e. \u201ctechnique\u201d but now we require a technique for \u201cSelf-Driving Car\u201d so we will forget the previous stored data i.e. \u201cLanguage Translator\u201d from cell state using the forget gate and we will add \u201cSelf-Driving Cars\u201d in the cell state.<\/p>\n<p>And this cell and hidden output are passed to the next block of LSTM layers where the same steps repeat till we reach the right prediction.<\/p>\n<p>Encoder: For the language translation machine learning model we will be creating keras Input objects whose shape will be equal to the total number of input characters. We will use RNN\u2019s LSTM model and only the return state will be True because we only want value from hidden and cell state so we will discard encoder output and only keep the states.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#create input object of total number of encoder characters\r\nen_inputs = Input(shape=(None, num_en_chars))\r\n\r\n#create LSTM with the hidden dimension of 256\r\n#return state=True as we don't want output sequence.\r\nencoder = LSTM(256, return_state=True)\r\n\r\n#discard encoder output and store hidden and cell state.\r\nen_outputs, state_h, state_c = encoder(en_inputs)\r\nen_states = [state_h, state_c]\r\n<\/pre>\n<p>Decoder: In decoder, our Input object shape will be equal to the total number of target characters. The LSTM model with the return state and return sequence will be True as we need a model to return full output sequence(text) as well as states. We will be using a softmax activation function and also a Dense layer for our output.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#create input object of total number of decoder characters\r\ndec_inputs = Input(shape=(None, num_dec_chars))\r\n\r\n#create LSTM with the hidden dimension of 256\r\n#return state and return sequences as we want output sequence.\r\ndec_lstm = LSTM(256, return_sequences=True, return_state=True)\r\n\r\n#initialize the decoder model with the states on encoder.\r\ndec_outputs, _, _ = dec_lstm(dec_inputs, initial_state=en_states)\r\n\r\n#Output layer with shape of total number of decoder characters \r\ndec_dense = Dense(num_dec_chars, activation=\"softmax\")\r\ndec_outputs = dec_dense(dec_outputs)\r\n<\/pre>\n<h4>5. Train the model<\/h4>\n<p>To train the model we will fit \u2018(encoder input and decoder input)\u2019 which will turn into (\u2018decoder target data\u2019) using \u2018Adam\u2019 optimizer with a validation split of 0.2 and provide an epoch of 200 in a batch size of 64. Also, we will store all required variables in a binary or bytes stream like object format file using the \u2018pickle\u2019 module.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#create Model and store all variables \r\nmodel = Model([en_inputs, dec_inputs], dec_outputs)\r\n\r\npickle.dump({'input_characters':input_characters,'target_characters':target_characters, 'max_input_length':max_input_length, 'max_target_length':max_target_length, 'num_en_chars':num_en_chars, 'num_dec_chars':num_dec_chars}, open(\"training_data.pkl\", \"wb\"))\r\n\r\n#load the data and train the model\r\nen_in_data,dec_in_data,dec_tr_data = bagofcharacters(input_texts,target_texts)\r\nmodel.compile(\r\n    optimizer=\"adam\", loss=\"categorical_crossentropy\", metrics=[\"accuracy\"]\r\n)\r\n\r\nmodel.fit(\r\n    [en_in_data, dec_in_data],\r\n    dec_tr_data,\r\n    batch_size=64,\r\n    epochs=200,\r\n    validation_split=0.2,\r\n)\r\n\r\n# Save model\r\nmodel.save(\"s2s\")\r\n<\/pre>\n<p>After language translation ml model gets trained we will get a directory as \u2018s2s\u2019 with \u2018saved_model.pb\u2019 which includes optimizer, losses, and metrics of our model. The weights are saved in the variables \/ directory.<\/p>\n<p>Also, we can see the summary or visualize our model. The summary contains 1) Layers that we have used for our model 2) Output Shape which shows dimensions or shapes of our layers 3) The number of parameters for every layer is the total number of output size, i.e. number of neurons associated with the total number of input weights and one weight of connection with bias so basically<\/p>\n<p>N (number of parameters) = (number of neurons) * (number of inputs + 1)<\/p>\n<p>So the number of parameters for our dense layer (output layer) will be number of decoder characters present in our dataset i.e 67 associated with the number of input weights i.e. 256 and one weight of connection with bias, therefore our N will be<\/p>\n<p>N = 67 * ( 256 + 1) = 17219<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#summary and model plot\r\nmodel.summary()\r\n\r\nplot_model(model, to_file='Model_plot.png', show_shapes=True, show_layer_names=True)<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97731\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary.png\" alt=\"lstm model summary\" width=\"925\" height=\"341\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary.png 925w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary-768x283.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary-720x265.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary-520x192.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lstm-model-summary-320x118.png 320w\" sizes=\"auto, (max-width: 925px) 100vw, 925px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97732\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot.png\" alt=\"Model plot\" width=\"989\" height=\"405\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot.png 989w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot-768x314.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot-720x295.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot-520x213.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Model-plot-320x131.png 320w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/a><\/p>\n<p>After plotting our model we can see that our first input layer has a shape of the total number of input characters (English characters) i.e 47, which we will then pass to the first LSTM layer that has the input shape same as the previous layer and the latent(hidden) dimension of 256. Model initializes the second LSTM layer with the output of the first LSTM layer along with input from the decoder layer which has a shape of total number of target characters(french characters) i.e 67. Finally we will pass the output of the second LSTM layer to the dense layer which is our final output layer that has the shape of target characters.<\/p>\n<h4>6. Create Gui for our prediction<\/h4>\n<p>Now we will create a GUI for language translation machine learning project using the \u201ctkinter\u201d module to get input and display the decoded (translated) french text on the display window.<\/p>\n<p><strong>Initialize the window and load all the modules:<\/strong><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tkinter import *\r\nimport pickle\r\nimport numpy as np\r\nfrom sklearn.feature_extraction.text import CountVectorizer\r\nfrom tensorflow.keras.models import Model\r\nfrom tensorflow.keras import models\r\nfrom tensorflow.keras.layers import Input,LSTM,Dense\r\n\r\nBG_GRAY=\"#ABB2B9\"\r\nBG_COLOR=\"#000\"\r\nTEXT_COLOR=\"#FFF\"\r\nFONT=\"Melvetica 14\"\r\nFONT_BOLD=\"Melvetica 13 bold\"\r\n\r\ncv=CountVectorizer(binary=True,tokenizer=lambda txt: txt.split(),stop_words=None,analyzer='char') \r\n\r\nclass LangTRans:\r\n    def __init__(self):\r\n        #initialize tkinter window and load the file\r\n        self.window=Tk()\r\n        self.main_window()\r\n        self.datafile()\r\n<\/pre>\n<p><strong>Load all the variables from the datafile using the pickle module:<\/strong><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def datafile(self):\r\n    #get all datas from datafile and load the model.\r\n\r\n    datafile = pickle.load(open(\"training_data.pkl\",\"rb\"))\r\n    self.input_characters = datafile['input_characters']\r\n    self.target_characters = datafile['target_characters']\r\n\r\n    self.max_input_length = datafile['max_input_length']\r\n    self.max_target_length = datafile['max_target_length']\r\n    self.num_en_chars = datafile['num_en_chars']\r\n    self.num_dec_chars = datafile['num_dec_chars']\r\n\r\n    self.loadmodel()\r\n\r\n<\/pre>\n<p><strong>Create the main window for language translation. Also create scrollbar, text widget for the GUI:<\/strong><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def main_window(self):\r\n    #add title to window and configure it\r\n    self.window.title(\"Language Translator\")\r\n    self.window.resizable(width=False,height=False)\r\n    self.window.configure(width=520,height=520,bg=BG_COLOR)\r\n\r\n    head_label=Label(self.window,bg=BG_COLOR, fg=TEXT_COLOR, text=\"Welcome to DataFlair\",font=FONT_BOLD, pady=10)\r\n    head_label.place(relwidth=1)\r\n\r\n    line = Label(self.window,width=450,bg=BG_COLOR)\r\n    line.place(relwidth=1,rely=0.07,relheight=0.012)\r\n\r\n    #create text widget where input and output will be displayed\r\n    self.text_widget=Text(self.window,width=20,height=2,bg=\"#fff\",fg=\"#000\", font=FONT,padx=5,pady=5)\r\n    self.text_widget.place(relheight=0.745,relwidth=1,rely=0.08)\r\n    self.text_widget.configure(cursor=\"arrow\",state=DISABLED)\r\n\r\n    #create scrollbar\r\n    scrollbar=Scrollbar(self.text_widget)\r\n    scrollbar.place(relheight=1,relx=0.974)\r\n    scrollbar.configure(command=self.text_widget.yview)\r\n\r\n    #create bottom label where text widget will placed\r\n    bottom_label=Label(self.window,bg=BG_GRAY,height=80)\r\n    bottom_label.place(relwidth=1,rely=0.825)\r\n\r\n    #this is for user to put english text\r\n    self.msg_entry=Entry(bottom_label,bg=\"#2C3E50\", fg=TEXT_COLOR,font=FONT)\r\n    self.msg_entry.place(relwidth=0.788,relheight=0.06,rely=0.008,relx=0.008)\r\n    self.msg_entry.focus()\r\n    self.msg_entry.bind(\"&lt;Return&gt;\",self.on_enter)\r\n\r\n    #send button which will call on_enter function to send the text\r\n    send_button=Button(bottom_label,text=\"Send\",font=FONT_BOLD, width=8,bg=\"#fff\",command=lambda: self.on_enter(None))        \r\n    send_button.place(relx=0.80,rely=0.008,relheight=0.06,relwidth=0.20)\r\n<\/pre>\n<h4>7. Inference (sampling) model and prediction<\/h4>\n<p>Load the saved model and construct encoder and decoder. We will get the inputs from the saved model and LSTM to get the hidden and cell state of the encoder which is required to create the encoder model.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def loadmodel(self):\r\n    #Inference model\r\n    #load the model\r\n    model = models.load_model(\"s2s\")\r\n\r\n    #construct encoder model from the output of second layer\r\n    #discard the encoder output and store only states.\r\n    enc_outputs, state_h_enc, state_c_enc = model.layers[2].output \r\n\r\n    #add input object and state from the layer.\r\n    self.en_model = Model(model.input[0], [state_h_enc, state_c_enc])\r\n<\/pre>\n<p>For the decoder, we will take the second input and create an input object for hidden as well for cell state of shape (256,) which is latent(hidden) dimension of layer. Also, we will run one step of the decoder with this initial state and a start of text character after that our output will be the next character of the text.<\/p>\n<p>We will use reverse lookup to get characters from the index of the \u2018input_text\u2019 variable.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#create Input object for hidden and cell state for decoder\r\n#shape of layer with hidden or latent dimension\r\ndec_state_input_h = Input(shape=(256,), name=\"input_3\")\r\ndec_state_input_c = Input(shape=(256,), name=\"input_4\")\r\ndec_states_inputs = [dec_state_input_h, dec_state_input_c]\r\n\r\n#add input from the encoder output and initialize with states.\r\ndec_lstm = model.layers[3]\r\ndec_outputs, state_h_dec, state_c_dec = dec_lstm(\r\n    model.input[1], initial_state=dec_states_inputs\r\n)\r\n\r\ndec_states = [state_h_dec, state_c_dec]\r\ndec_dense = model.layers[4]\r\ndec_outputs = dec_dense(dec_outputs)\r\n\r\n#create Model with the input of decoder state input and encoder input\r\n#and decoder output with the decoder states.\r\nself.dec_model = Model(\r\n    [model.input[1]] + dec_states_inputs, [dec_outputs] + dec_states\r\n)\r\n<\/pre>\n<p>Encode the input sequence as state vectors. Create an empty array of the target sequence of length 1 and generate the start character i.e \u2018\\t\u2019 in our case of every pair to be 1. Use this state value along with the input sequence to predict the output index. Use reverse character index to get the character from output index and append to the decoded sequence.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def decode_sequence(self,input_seq):\r\n    #create a dictionary with a key as index and value as characters.\r\n    reverse_target_char_index = dict(enumerate(self.target_characters))\r\n    #get the states from the user input sequence\r\n    states_value = self.en_model.predict(input_seq)\r\n\r\n    #fit target characters and \r\n    #initialize every first character to be 1 which is '\\t'.\r\n    #Generate empty target sequence of length 1.\r\n    co=cv.fit(self.target_characters) \r\n    target_seq=np.array([co.transform(list(\"\\t\")).toarray().tolist()],dtype=\"float32\")\r\n\r\n    #if the iteration reaches the end of text than it will be stop the it\r\n    stop_condition = False\r\n    #append every predicted character in decoded sentence\r\n    decoded_sentence = \"\"\r\n\r\n    while not stop_condition:\r\n        #get predicted output and discard hidden and cell state.\r\n        output_chars, h, c = self.dec_model.predict([target_seq] + states_value)\r\n\r\n        #get the index and from the dictionary get the character.\r\n        char_index = np.argmax(output_chars[0, -1, :])\r\n        text_char = reverse_target_char_index[char_index]\r\n        decoded_sentence += text_char\r\n<\/pre>\n<p>For every index, put 1 to that index of our target array. So for the next iteration, our target sequence will be having a vector of the previous character. Iterate until our character is equal to the last character or max length of the target text.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">    # Exit condition: either hit max length\r\n    # or find a stop character.\r\n    if text_char == \"\\n\" or len(decoded_sentence) &gt; self.max_target_length:\r\n        stop_condition = True\r\n    #update target sequence to the current character index.\r\n    target_seq = np.zeros((1, 1, self.num_dec_chars))\r\n    target_seq[0, 0, char_index] = 1.0\r\n    states_value = [h, c]\r\n#return the decoded sentence\r\nreturn decoded_sentence\r\n<\/pre>\n<p>Get the input (English) text from the user and pass it to a bag of characters for a one-hot encoding process. After that pass the encoded vector into \u2018decode_sequence()\u2019 for the decoded(french) text.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">    def bagofcharacters(self,input_t):\r\n        cv=CountVectorizer(binary=True,tokenizer=lambda txt:\r\n        txt.split(),stop_words=None,analyzer='char') \r\n        en_in_data=[] ; pad_en=[1]+[0]*(len(self.input_characters)-1)\r\n    \r\n        cv_inp= cv.fit(self.input_characters)\r\n        en_in_data.append(cv_inp.transform(list(input_t)).toarray().tolist())\r\n    \r\n        if len(input_t)&lt; self.max_input_length:\r\n          for _ in range(self.max_input_length-len(input_t)):\r\n            en_in_data[0].append(pad_en)\r\n    \r\n        return np.array(en_in_data,dtype=\"float32\")\r\n    \r\n    def decoded_output(self,msg,sender):\r\n        self.text_widget.configure(state=NORMAL)\r\n        en_in_data = self.bagofcharacters(msg.lower()+\".\")\r\n        self.text_widget.insert(END,str(sender)+\" :\r\n        \"+self.decode_sequence(en_in_data)\r\n                                +\"\\n\\n\")\r\n        self.text_widget.configure(state=DISABLED)\r\n        self.text_widget.see(END)\r\n    \r\n    def my_msg(self,msg,sender):\r\n        if not msg:\r\n            return\r\n        self.msg_entry.delete(0,END)\r\n        self.text_widget.configure(state=NORMAL)\r\n        self.text_widget.insert(END,str(sender)+\" : \"+str(msg)+\"\\n\")\r\n        self.text_widget.configure(state=DISABLED)\r\n        \r\n    #runwindow\r\n    def run(self):\r\n        self.window.mainloop()\r\n\r\n# run the file\r\nif __name__==\"__main__\":\r\n    LT = LangTRans()\r\n    LT.run()\r\n<\/pre>\n<h4>8. Run Language Translation Code File<\/h4>\n<p>In order to run the language translator app, we need these two main files langTraining.py and LangTransGui.py.<\/p>\n<p>First, we will train the model by using the following command in the terminal.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python langTraining.py<\/pre>\n<p>Your ml model is trained after the successful execution of the above command.<\/p>\n<p>Similarly to run the second file run the following command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python LangTransGui.py<\/pre>\n<p>Now, you are ready to use Language Translator machine learning app.<\/p>\n<p>The language translator machine learning model is trained for only 10,000 rows from the dataset. You can make your predictions better by training more rows from the dataset. Also, adjust the epochs and batch_size accordingly.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97733\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training.png\" alt=\"model training\" width=\"1217\" height=\"344\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training.png 1217w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training-768x217.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training-720x204.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training-520x147.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/model-training-320x90.png 320w\" sizes=\"auto, (max-width: 1217px) 100vw, 1217px\" \/><\/a><\/p>\n<h3>Language Translation Machine Learning Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-97734\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-output.png\" alt=\"machine learning language translator output\" width=\"520\" height=\"550\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-output.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-output-320x338.png 320w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Language translation is the task of changing text from one language to another using machine learning. It\u2019s a part of NLP (Natural Language Processing). Tools like Google Translate use deep learning models trained on massive datasets. In this project, you can train a smaller model to translate between two languages like English to French, or Hindi to English. It helps in understanding sequence modeling and encoder-decoder architectures.<\/p>\n<p>In this machine learning project, we have developed a language translator app. This accepts the input from the user in English language and decodes it into French language using the LSTM model and Teacher Forcing algorithm. Language Translators are used in order to understand and communicate in various languages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a real-time machine learning language translator with TensorFlow Savez-vous comment cr\u00e9er une application de traduction de langue? Did you understand the above sentence? Well after googling it, I found its meaning as: Do&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":97728,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[24654,24653,24655,24656,20697],"class_list":["post-97724","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-language-translation","tag-language-translation-machine-learning","tag-language-translator","tag-lstm-project","tag-machine-learning-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Language Translation with Machine Learning - DataFlair<\/title>\n<meta name=\"description\" content=\"Create a machine learning project for language translation. In this project we used LSTM model and Teacher Forcing algorithm.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Language Translation with Machine Learning - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Create a machine learning project for language translation. In this project we used LSTM model and Teacher Forcing algorithm.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-21T07:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T09:10:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Language Translation with Machine Learning - DataFlair","description":"Create a machine learning project for language translation. In this project we used LSTM model and Teacher Forcing algorithm.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/","og_locale":"en_US","og_type":"article","og_title":"Language Translation with Machine Learning - DataFlair","og_description":"Create a machine learning project for language translation. In this project we used LSTM model and Teacher Forcing algorithm.","og_url":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-06-21T07:48:00+00:00","article_modified_time":"2026-06-01T09:10:10+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Language Translation with Machine Learning","datePublished":"2021-06-21T07:48:00+00:00","dateModified":"2026-06-01T09:10:10+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/"},"wordCount":2806,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg","keywords":["language translation","language translation machine learning","language translator","lstm project","machine learning project"],"articleSection":["Machine Learning Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/","url":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/","name":"Language Translation with Machine Learning - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg","datePublished":"2021-06-21T07:48:00+00:00","dateModified":"2026-06-01T09:10:10+00:00","description":"Create a machine learning project for language translation. In this project we used LSTM model and Teacher Forcing algorithm.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/machine-learning-language-translator-project.jpg","width":1200,"height":628,"caption":"machine learning language translator project"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/language-translation-machine-learning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Machine Learning Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/machine-learning\/"},{"@type":"ListItem","position":3,"name":"Language Translation with Machine Learning"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/97724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=97724"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/97724\/revisions"}],"predecessor-version":[{"id":148741,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/97724\/revisions\/148741"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/97728"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=97724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=97724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=97724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}