final report -12
final report -12
Bachelor of Technology
in
Computer Science and Engineering
(Artificial Intelligence and Machine Learning)
by
K. KRISHNA CHAITANYA - 21N31A6685
L. MEGHANA - 21N31A6696
N. SRIYAMSHA - 21N31A66D1
It is further declared that the project report or any part thereof has not been
previously submitted to any University or Institute for the award of degree or
diploma.
This is to certify that this is the bonafide record of the project titled “Neural
Machine Translator” submitted by K. Krishna Chaitanya (21N31A6685), L.
Meghana (21N31A6696), N. Sriyamsha (21N31A66D1) of B.Tech in the partial
fulfillment of the requirements for the degree of Bachelor of Technology in
Computer Science and Engineering- Artificial Intelligence and Machine
Learning, Dept. of CSE(AI&ML) during the year 2024-2025. The results
embodied in this project report have not been submitted to any other university
or institute for the award of any degree or diploma.
EXTERNAL EXAMINER
We are indebted to our Principal Dr. S. Srinivasa Rao for providing us with
facilities to do our project and his constant encouragement and moral support
which motivated us to move forward with the project.
Dr. D. Sujatha, Professor and Dean (CSE&ET) for encouraging us in every aspect
of our system development and helping us realize our full potential.
We would like to express our sincere gratitude and indebtedness to our project
supervisor Mr. S. Venkateswara raju, Assistant Professor for her valuable
suggestions and interest throughout the course of this project.
We would like to thank our parents and friends who have helped us with their
valuable suggestions and support has been very helpful in various phases of the
completion of the Major Project.
K. Krishna Chaitanya(21N31A6685)
L. Meghana(21N31A6696)
N. Sriyamsha(21N31A66D1)
iii
ABSTRACT
This project is about the application of Neural Machine Translation (NMT) for
translating French sentences into English. NMT, an advanced deep learning
methodology, has significantly transformed machine translation by enhancing accuracy
and fluency compared to traditional approaches. By leveraging NMT, this project aims
to bridge linguistic gaps, enabling seamless communication across languages.
The core components of this project involve data preprocessing, model building,
and model evaluation. A carefully curated dataset, consisting of parallel text in both
source (French) and target (English) languages, is used for training and validation.
Several architectures are explored to determine the most efficient approach, including
Recurrent Neural Networks (RNNs), Bidirectional RNNs, and Encoder-Decoder models.
These architectures are assessed based on their effectiveness in capturing linguistic
nuances and generating coherent translations.
By harnessing the power of NMT, this project demonstrates how deep learning
techniques can enhance the quality and efficiency of language translation systems,
paving the way for continued improvements in multilingual communication
technologies.
1
This project explores the application of Neural Machine Translation (NMT) for
translating French sentences as a source into the English language as the target. NMT, a
powerful deep learning technique, has revolutionized machine translation by achieving
high accuracy and fluency.
This project aims to leverage NMT's capabilities to translate texts from source language
to target language. The project will involve Preprocessing of data, model building and
testing of the model.
We will utilize separate texts for both source and target languages for training and
evaluation. This project has the potential to accurately translate sentences or text from
a source language to target language. By harnessing the power of NMT, we can
contribute to a more connected and well communicable environment.
By harnessing deep learning techniques, this model sets a foundation for further
advancements in automatic translation systems, improving fluency, accuracy, and
inclusivity in global interactions.
2
TABLE OF CONTENTS
CHAPTER 4 IMPLEMENTATION 32
4.1 Code 32-38
4.2 Output Screens 39-40
4.3 Testing 41-45
3
LIST OF FIGURES
Fig. No Figure Title Page no.
LIST OF ABBREVIATIONS
S. No ABBREVIATIONS
1. RNN - Recurrent Neural Network
2. ML – Machine Learning
3. DL – Deep Learning
4. NMT – Neural Machine Translator
5. API - Application Programming Interface
6.
8.
9.
10.
4
CHAPTER 1
INTRODUCTION
1.1 Purpose:
Limited – rule-based systems struggle with idioms, slang, and nuanced contexts.
5
3. Real-World Applications
The project explores how NMT can be deployed in areas such as:
4. Educational Purpose
In addition to its technical goal, the project also serves as a learning platform for the
team to:
6. Limitations Acknowledged
The purpose is also to highlight and understand the limitations of current NMT
systems, such as:
6
In essence, the purpose of this project is to explore how deep learning-based
translation systems can contribute to breaking language barriers, improving global
collaboration, and automating multilingual communication in a scalable, accurate,
and cost-effective way.
The successful implementation of the NMT system proved the effectiveness of deep
learning techniques in the domain of machine translation. Traditional translation
methods—such as rule-based or statistical models—are limited in their ability to
capture the context, grammar, and nuances of a sentence. In contrast, NMT uses a
sequence-to-sequence architecture with neural networks that can learn from data
patterns, understand sentence structures, and generate fluent translations. By
comparing various architectures like basic RNNs, bidirectional LSTMs, and an
encoder-decoder model, the project demonstrated that modern NMT models not
only produce more accurate translations but also improve efficiency and
adaptability.
Another major objective of the project was educational. The development process
offered the team valuable hands-on experience in natural language processing, deep
learning, and model optimization. It required a deep understanding of tokenization,
preprocessing, training models with TensorFlow/Keras, and evaluating performance
metrics. These experiences helped the team bridge the gap between theoretical
concepts and practical implementation, making the project both a technical success
and a learning milestone.
The project achieved its core purpose of showcasing how neural machine translation
can be used to overcome language barriers in a scalable, cost-effective, and efficient
way. It highlights the potential of AI to facilitate global communication, automate
translation tasks, and empower individuals and organizations to operate beyond
linguistic boundaries. This work lays a strong foundation for future enhancements,
such as integrating attention mechanisms or transformer-based models, and moving
closer to real-time, multilingual translation systems.
7
1.2 Background of project:
The background of this project is rooted in the broader field of Natural Language
Processing (NLP), a subdomain of artificial intelligence that focuses on enabling
machines to understand, interpret, and generate human language. One of the most
practical and impactful applications of NLP is machine translation, which refers to the
automatic translation of text or speech from one language to another. With
globalization and the internet bringing people from diverse linguistic backgrounds
closer than ever, machine translation has become essential in fields like education,
international business, customer service, and online communication.
The limitations of RBMT and SMT led to the evolution of Neural Machine
Translation (NMT). NMT systems use deep learning, specifically neural networks, to
learn translation patterns directly from data. Unlike SMT, which translates word-by-
word or phrase-by-phrase, NMT translates entire sentences at once using sequence-to-
sequence (Seq2Seq) models. These models consist of two main components: an
encoder, which processes the input sentence and converts it into a numerical context
vector, and a decoder, which generates the translated output. This architecture allows
the model to better understand the semantics and context of a sentence, resulting in
more fluent and human-like translations.
The motivation for this project emerged from the need to apply these modern NMT
techniques in a resource-constrained academic setting. The goal was to build a
simplified yet effective NMT model to translate French sentences into English, using
accessible tools like Google Colaboratory, Python, and deep learning libraries such as
TensorFlow and Keras. The choice of French-English translation was influenced by
the availability of clean bilingual datasets and the importance of this language pair in
NLP research and real-world applications.
8
The project also recognized the practical importance of machine translation in daily
life. Whether it’s translating user-generated content on social media, processing
customer service requests, or making technical manuals accessible in multiple
languages, translation systems are increasingly becoming critical tools in both
personal and professional settings. As a result, this project not only serves as an
academic exercise but also as a step toward solving real-world problems using
intelligent systems.
Example: A rule-based translation system might have a rule stating that the
word "dog" in English should be translated to "perro" in Spanish.
Example: SBMT learns the syntactic structure of a sentence and ensures that
the subject and verb agreement is maintained in the translation for a more
grammatically accurate output.
9
Hybrid machine translation (HMT): Hybrid machine translation may
incorporate rule-based, statistical and neural components to enhance
translation quality. For example, a hybrid system might use rule-based
methods for handling specific linguistic phenomena, statistical models for
general translation patterns, and neural models for generating fluent and
contextually aware translations.
Example: If the sentence, "The cat is playing," has been previously translated
as "El gato está jugando," EBMT can retrieve that translation as a reference to
translate a new sentence, "The cat is eating.
Machine Translation is the automatic process of translating text or speech from one
language to another using computer algorithms. Traditional approaches relied heavily
on rules or statistical methods. Neural Machine Translation is the latest and most
effective method, leveraging deep learning and neural networks.
10
1.3 Scope of project:
The scope of this project defines the boundaries within which the Neural Machine
Translation system operates, along with its potential applications and limitations.
This project specifically focuses on building an NMT model to translate one
language to another using deep learning techniques in a controlled and resource-
efficient environment.
While some content types are best left in the hands of human translators, such as
creative advertising copy designed for maximum impact, neural machine translation
excels at other types of scenarios, including:
1. Translation of large amounts of content in extremely short time frames When
NMT ingests large amounts of high-quality training data to improve its neural
networks, it can rapidly produce astoundingly precise translations without any
human intervention in record time.
2. Translation of highly repetitive content NMT is especially effective at translations
that require high neural network accuracy but are also very repetitive, such as
manuals, user guides, or other types of reference materials.
3. Translation of user-generated content (UGC) for social sentiment analysis Neural
machine translation can process hundreds of thousands of user-generated comments
overnight and deliver accurate, actionable results in record time.
4. Online customer service Neural machine translation can be very useful for
helpdesk or customer service operations, where staff members need to quickly and
accurately translate requests from customers around the world.
1. Language Pair
The project is limited to translation from source language to target language.
2. Input and Output Format
The model works with text-to-text translation.
Inputs and outputs are plain text files, without voice or image support.
3. Model Architecture
Multiple deep learning architectures were explored:
11
o Simple RNN with embedding
o Bidirectional LSTM
o Encoder-Decoder (Seq2Seq) model
The final model chosen is the Encoder-Decoder architecture, which provided the
highest translation accuracy.
4. Dataset Constraints
The dataset includes approximately 100,000 bilingual sentence pairs.
Vocabulary size:
o French: 340 unique words
o English: 199 unique words
The model can only translate sentences that fall within the vocabulary range of
the dataset.
5. Computational Resources
Implementation was done on Google Colaboratory, using:
o 12.7 GB RAM
o 30 GB disk space
o T4 GPU with 15 GB memory
Scope is limited to what can be processed within these resource limits.
6. User Scenarios
The project is well-suited for use cases where:
High volumes of repetitive content need translation (e.g., user manuals, FAQs).
Fast turnaround time is essential, and human translation would be too slow or
costly.
User-generated content (UGC) like social media comments are being processed
for tasks like sentiment analysis.
Customer service queries from various languages need quick translation to
provide real-time support.
The scope of this project is focused but impactful: it builds a working prototype of a
Neural Machine Translation model for French-to-English text translation using deep
learning. While it's limited in vocabulary and language support, the project lays the
foundation for future enhancements and demonstrates the real-world potential of
NMT systems in domains where speed, accuracy, and automation are critical.
12
Real-time speech or video translation
Multi-language support (beyond French–English)
General-purpose translation for all kinds of vocabulary or sentence structures
Extremely large-scale deployment beyond Google Colab limitations
The project includes demonstrating how neural machine translation systems can be
trained and evaluated using open-source tools and freely available resources, making
advanced AI technologies more accessible to students, researchers, and developers
with limited infrastructure.
13
1.4 Project Features:
The project on Neural Machine Translation (NMT) several designed features that
enhance its functionality, usability, and educational value. These features reflect the
integration of deep learning principles with practical translation needs, offering a
solid foundation for real-world applications and further development.
14
The system is trained on a bilingual dataset with 100,000 parallel French-English
sentence pairs. Key dataset features include:
5. Performance Evaluation
Each model is evaluated on:
Training and validation accuracy
Loss over epochs
Comparison with real-world translators (e.g., Google Translate)
6. Vocabulary-Constrained Translation
Due to hardware limitations, the project introduces a feature that only allows input
sentences within the training vocabulary range. While this limits flexibility, it
ensures high translation accuracy and efficiency under constrained resources.
15
8. Real-Time Sentence Prediction
The final model supports custom sentence input and returns translations in real-time.
During testing, user-entered sentences in French were translated into accurate
English phrases, verified against Google Translate outputs.
Reproducible Training
All model hyperparameters (e.g., epochs, loss function, optimizer type, embedding
size) are explicitly defined in the code, allowing other users or researchers to:
Reproduce the results
Experiment with variations
Extend or fine-tune the models for other language pairs or larger vocabularies
With these additional features, the project goes beyond a simple translation tool and
becomes a scalable, educational, and production-ready prototype of a neural
machine translation system. It not only serves current needs but also lays the
groundwork for more sophisticated language models in future development efforts.
17
CHAPTER 2
SYSTEM REQUIREMENTS
The software utilized in order to build a machine translation model are as follows:
The model we built had the below mentioned requirements in order to function
properly:
● Source and target language support: The aim of this project is to translate the
French text provided into English.
● Text input methods: There are text files for both source and target target
languages which were uploaded into the working environment for easy access.
● Translation modes: The translation mode is “Text-to-Text” translation, that is,
both the input and output are in text format
18
2.3 Existing System:
19
2. Statistical Machine Translation (SMT)
Overview:
Emerged in the early 1990s, dominated until the mid-2010s.
Based on probabilistic models derived from bilingual corpora.
Became the core of early versions of Google Translate and other tools.
How It Works:
SMT translates by:
Learning from large corpora of aligned sentence pairs (parallel texts).
Using language models to estimate the probability of a sequence of words.
Applying alignment models to match source and target phrases.
Performing decoding to select the best combination of translated segments.
Types of SMT:
Word-Based Models (e.g., IBM Models 1–5)
Phrase-Based Models (most widely used form)
Hierarchical Phrase-Based Models
Syntax-Based SMT (uses syntactic parsing trees)
Strengths:
Better fluency than RBMT.
Automatic training from data—no manual rules required.
Adaptable to different domains by retraining on relevant corpora.
Examples:
Google Translate (pre-2016): Based on phrase-based SMT.
Moses: Popular open-source SMT toolkit used in academia.
Joshua: Research-focused SMT toolkit supporting syntax-based approaches.
Phrasal: Developed by Stanford for phrase-based MT research.
20
Free and Easy Access:
Google Translate is a free service accessible via web browser or mobile app, making
translation readily available.
There are some drawbacks in the existing systems of Online Translators. Those issues
lead to the errors in the translated languages, miscommunication, lack of accuracy and
many more. These old-fashioned methods of translation that are based on human-
made rules and dictionaries. They are like a rigid language teacher who sticks to a
textbook—fine for simple sentences but not exactly brilliant with slang and
obscure phrases.
some of the problems of existing system are:
Accuracy Limitations:
While improving, Google Translate can still make errors, especially with complex
sentences, technical terms, or nuanced language.
Contextual Misinterpretation:
It may struggle to understand the context of a sentence, leading to inaccurate or
misleading translations.
21
Difficulty with Idioms and Slang:
Colloquialisms and cultural references are often not translated accurately, resulting in
awkward or nonsensical outputs.
RBMT systems struggle to adapt to evolving languages and new terminology, as they
require manual updates to rules and dictionaries.
Complexity:
Managing numerous rules and their interactions can lead to a very complex system
that is difficult to scale and adapt quickly.
The traditional machine translation systems, had several significant limitations that
ultimately led to the development of Neural Machine Translation (NMT).
linguistically rigorous, relied heavily on manually crafted grammar rules and
bilingual dictionaries, making it time-consuming, labor-intensive, and difficult to
scale across different languages and domains. It often produced rigid and unnatural
translations, especially in cases involving idioms, complex sentence structures, or
informal language.
Some systems are emerged as a more data-driven approach, scalability issues but
introduced new problems. While they could learn translation patterns from large
parallel corpora, it was limited to translating phrases rather than entire sentences,
resulting in fragmented and sometimes grammatically incorrect outputs.
Additionally, they lacked the ability to capture long-range dependencies and
contextual meaning across sentences, leading to inconsistent or awkward translations.
They struggled with handling rare words, managing syntactic variations, and
adapting to domains with limited training data. These shortcomings highlighted the
need for a more unified, context-aware, and fluent translation approach, paving the
way for the emergence of NMT.
22
2.4 Proposed System:
The proposed system is a Neural Machine Translation (NMT) model designed to
efficiently translate using deep learning techniques. The system operates using a
sequence-to-sequence (Seq2Seq) architecture, which consists of an encoder and a
decoder—both implemented using recurrent neural networks (RNNs) and their
variations to enhance translation quality. Below is a breakdown of the architecture,
components, functionality, advantages, and limitations of the proposed system.
23
The model outputs tokenized word IDs, which are converted back into readable
English text using a dictionary mapping.
24
Instead of literal translations, the system learns linguistic nuances from training
data.
5. Future Improvements
The proposed system provides a strong foundation, but future upgrades could
enhance its capabilities:
25
Incorporating Transformer Models
Using self-attention mechanisms (like those in Google Translate) could further
improve long-range dependencies.
Domain-Specific Fine-Tuning
Training with specialized datasets (e.g., medical or legal texts) could improve
accuracy for technical translations.
Expanding Vocabulary Coverage
Using dynamic vocabulary updating would ensure the system can handle new
words and phrases efficiently.
The proposed system presents an efficient, scalable, and highly accurate approach to
French-to-English machine translation, leveraging deep learning principles. With its
Encoder-Decoder architecture, Bidirectional LSTM layers, and optimized training
methodology, it surpasses traditional approaches in fluency, contextual awareness,
and sentence coherence. While challenges remain, the system lays the groundwork for
future advancements in NMT, with promising applications across business, education,
research, and accessibility.
It can be improved by using attention mechanisms, which help the model focus on the
most important words in a sentence while translating. Instead of treating every word
equally, attention lets the model prioritize key parts of the sentence, making the
translations more natural and accurate. This would be especially useful for longer
sentences or phrases with multiple meanings. In the future, adding Transformer-based
models, like the ones used in advanced translation tools, could make the system even
faster and more reliable for real-world use.
26
CHAPTER 3
SYSTEM DESIGN
27
3.2 UML Diagrams
Use Case during requirement elicitation and analysis to represent the functionality of the
system. Use case describes a function by the system that yields a visible result for an actor.
The identification of actors and use cases result in the definitions of the boundary of the
system i.e., differentiating the tasks accomplished by the system and the tasks accomplished
by its environment.
28
3.2.2 Class Diagram
Class diagrams model class structure and contents using design elements such as classes,
packages and objects. Class diagram describe the different perspective when designing a
system-conceptual, specification and implementation. Classes are composed of three things:
name, attributes, and operations. Class diagram also display relationships such as
containment, inheritance, association etc. The association relationship is most common
relationship in a class diagram. The association shows the relationship between instances of
classes.
29
3.2.3 Sequence Diagram
Sequence diagram displays the time sequence of the objects participating in the interaction.
This consists of the vertical dimension (time) and horizontal dimension (different objects).
Objects: An object can be thought of as an entity that exists at a specified time and has a
definite value, as well as a holder of identity. A sequence diagram depicts item interactions
in chronological order. It illustrates the scenario's objects and classes, as well as the
sequence of messages sent between them in order to carry out the scenario's functionality.
In the Logical View of the system under development, sequence diagrams are often related
with use case realizations. Event diagrams and event scenarios are other names for
sequence diagrams. A sequence diagram depicts multiple processes or things that exist
simultaneously as parallel vertical lines (lifelines), and the messages passed between them
as horizontal arrows, in the order in which they occur. This enables for the graphical
specification of simple runtime scenarios.
30
Fig 3.4 Sequence Diagram of Neural Machine Translator
The process flows in the system are captured in the activity diagram. Similar to a state
diagram, an activity diagram also consists of activities, actions, transitions, initial and final
states, and guard conditions
31
Fig 3.5 Activity Diagram of Neural Machine Translator
CHAPTER 4
IMPLEMENTATION
4.1 Code
32
Importing necessary libraries
import os
import tensorflow as tf
import numpy
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.layers import Dense, LSTM, Input, TimeDistributed, Embedding,
GRU, Bidirectional, Dropout, RepeatVector
from tensorflow.keras.losses import sparse_categorical_crossentropy
from tensorflow.keras.optimizers import Adam
english_file_path = os.path.join('/content/small_vocab_en.txt')
french_file_path = os.path.join('/content/small_vocab_fr.txt')
Preprocessing pipeline
class Preprocessing():
def lowercasing(self, text):
for i in range(len(text)):
text[i] = text[i].lower()
return text
33
#English Text
preprocessing = Preprocessing()
english_lowercase = preprocessing.lowercasing(english_sentences)
english_tokenized_text, english_tokenizer = preprocessing.tokenization(english_lowercase)
english_padded_text = preprocessing.padding(english_tokenized_text)
print(english_padded_text[0:5])
print(french_padded_text[0:5])
max_english_sequence_length = english_padded_text.shape[1]
max_french_sequence_length = french_padded_text.shape[1]
english_vocab_size = len(english_tokenizer.word_index)
french_vocab_size = len(french_tokenizer.word_index)
print('Data Preprocessed')
print("Max English sentence length:", max_english_sequence_length)
print("Max French sentence length:", max_french_sequence_length)
print("English vocabulary size:", english_vocab_size)
print("French vocabulary size:", french_vocab_size)
english_padded_text = pad_sequences(english_padded_text[:french_padded_text.shape[0]],
max_french_sequence_length)
padded_fre = pad_sequences(french_padded_text[:french_padded_text.shape[0]],
max_french_sequence_length)
tmp_x = padded_fre.reshape((-1, french_padded_text.shape[-2],
max_french_sequence_length)) #Reshaping into (Batch size, timesteps, sequence length)
english_padded_text.shape
padded_fre.shape
tmp_x.shape
french_padded_text.shape
rnn_embed_model = Sequential()
rnn_embed_model.add(Input(shape=(max_french_sequence_length,), name='Input Layer'))
rnn_embed_model.add(Embedding(input_dim=french_vocab_size+1, output_dim=512,
input_length=max_french_sequence_length))
rnn_embed_model.add(GRU(units=64, return_sequences=True))
rnn_embed_model.add(GRU(units=32, return_sequences=True))
34
rnn_embed_model.add(GRU(units=32, return_sequences=True))
rnn_embed_model.add(TimeDistributed(Dense(units=english_vocab_size+1,
activation='softmax')))
rnn_embed_model.summary()
rnn_embed_model.compile(optimizer='Adam', loss='sparse_categorical_crossentropy',
metrics=['Accuracy'])
def initialize_hidden_state(self):
return tf.zeros((self.batch_sz, self.enc_units))
class Decoder(tf.keras.Model):
def __init__(self, vocab_size, embedding_dim, dec_units, batch_sz):
super(Decoder, self).__init__()
self.batch_sz = batch_sz
self.dec_units = dec_units
self.embedding = tf.keras.layers.Embedding(vocab_size, embedding_dim)
self.gru = tf.keras.layers.GRU(units, return_sequences=True, return_state=True,
recurrent_activation='sigmoid', recurrent_initializer='glorot_uniform')
self.fc = tf.keras.layers.Dense(vocab_size)
hidden_with_time_axis = tf.expand_dims(hidden, 1)
35
attention_weights = tf.nn.softmax(score, axis=1)
x = self.embedding(x)
x = self.fc(output)
def initialize_hidden_state(self):
return tf.zeros((self.batch_sz, self.dec_units))
tf.keras.backend.clear_session()
In [20]:
optimizer = tf.keras.optimizers.Adam()
loss_object = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True,
reduction='none')
return tf.reduce_mean(loss_)
In [21]:
checkpoint_dir = './training_checkpoints'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
checkpoint = tf.train.Checkpoint(optimizer=optimizer,
encoder=encoder,
decoder=decoder)
36
Bidirectional LSTM model implementation
bi_rnn_model = Sequential()
bi_rnn_model.add(Input(shape=(tmp_x.shape[0],), name='Input Layer'))
bi_rnn_model.add(Embedding(input_dim=french_vocab_size+1, output_dim=128,
input_length=max_french_sequence_length))
bi_rnn_model.add(Bidirectional(layer=LSTM(32, return_sequences=True)))
bi_rnn_model.add(TimeDistributed(Dense(units=english_vocab_size+1,
activation='softmax')))
bi_rnn_model.summary()
bi_rnn_model.compile(optimizer='Adam', loss='sparse_categorical_crossentropy',
metrics=['Accuracy'])
model = Sequential()
#Encoder
model.add(Input(shape=(tmp_x.shape[0],), name='Input Layer'))
model.add(Embedding(input_dim=french_vocab_size+1, output_dim=512,
input_length=max_french_sequence_length))
model.add(LSTM(units=256, return_sequences=True))
model.add(Bidirectional(layer=LSTM(128, return_sequences=False)))
#context vector
model.add(RepeatVector(n=max_french_sequence_length))
#Decoder
model.add(LSTM(units=256, return_sequences=True))
model.add(LSTM(units=128, return_sequences=True))
#model.add(LSTM(units=16, return_sequences=True))
model.add(TimeDistributed(Dense(units=english_vocab_size+1, activation='softmax')))
37
model.summary()
model.compile(optimizer='Adam', loss='sparse_categorical_crossentropy',
metrics=['Accuracy'])
@tf.function
def train_step(inp, targ, enc_hidden):
loss = 0
optimizer.apply_gradients(zip(gradients, variables))
return batch_loss
Prediction of sentence
def final_predictions():
sentence = "californie est humide au mois d' août , et il est parfois le gel en hiver"
# Removing punctuation and splitting the sentence
# Convert the sentence to lowercase for consistency with the tokenizer
sentence = sentence.lower().replace(',', '').split()
# Use get method to handle OOV words, defaulting to 0 (padding or unknown token)
sentence = [french_tokenizer.word_index.get(word, 0) for word in sentence]
sentence = pad_sequences([sentence], maxlen=max_french_sequence_length,
padding='post')
#print(french_tokenized_text[0])
38
sentences = numpy.array([sentence[0], french_padded_text[0]])
predictions = model.predict(sentences, len(sentences))
#print(predictions)
eng_id_to_word = {value: key for key, value in english_tokenizer.word_index.items()}
eng_id_to_word[0] = " "
print(" ".join([eng_id_to_word[numpy.argmax(value)] for value in predictions[0]]))
#print(eng_id_to_word)
final_predictions()
39
40
4.3: Testing
41
Introduction to Testing:
The testing phase of this NMT project plays a critical role in evaluating the model's
performance and ensuring that it meets the functional requirements laid out during
the design and implementation stages. According to the project report, the testing
focuses on validating the accuracy and fluency of translations generated by the
trained model.
Testing can be stated as the process of verifying and validating whether a software
or application meets the technical requirements as guided by its design and
development, and meets the user requirements effectively and efficiently by
handling all the exceptional and boundary cases.
The process of software testing aims not only at finding faults in the existing
software but also at finding measures to improve the software in terms of efficiency,
accuracy, and usability.
Test cases:
The test cases in this project is to provide a sentence in the Source language
(French) and to verify the output in the Target language (English). We should be
ensuring that the sentence or text provided as input should have vocabulary that the
model is trained on during the training phase rather than any other vocabulary.
The second sentence we provided was ‘elle aime les poires , les oranges et les
raisins’, which was translated into ‘she likes pears , oranges , and grapes’ which was
also accurately translated by the model when compared with the translation given by
Google translate.
Purpose of Testing
The primary goal of testing in this project is to verify whether the model can
accurately translate input sentences from the source language (French) to the target
language (English). It also aims to ensure that the model handles only the
vocabulary it was trained on, which is a limitation due to the size of the dataset and
computational resources.
Testing Approach
1. Input Validation
Sentences are fed to the model in French (source language).
Inputs must fall within the vocabulary learned during training.
Out-of-vocabulary words are not supported, which could impact translation
quality.
42
2. Output Comparison
The model's English output is compared with well-established translation tools
like Google Translate to assess accuracy and fluency.
Test Case 2:
Input Sentence:
"elle aime les poires , les oranges et les raisins"
Model Output:
"she likes pears , oranges , and grapes"
Expected Result:
Same translation as Google Translate.
✅ Result: Accurate
Accuracy: Ensuring that the translation correctly reflects the source text's
meaning.
Robustness: Testing how the model handles edge cases, such as rare words or
long sentences.
Integration Testing
System Testing
Evaluates the entire translation system end-to-end using sample inputs and
analyzing outputs.
Functional Testing
Verifies that the model performs the intended function: translating from French
to English.
Includes tests based on sentences with known outputs.
Performance Testing
4. Testing Data
Testing is done using a held-out test set, separate from training and validation sets.
This dataset includes source sentences (French) and their ground-truth translations
(English).
The model’s predictions are compared against these references.
Several automatic evaluation metrics are commonly used in the NMT literature:
Measures n-gram overlap between the model output and reference translation.
Score between 0 and 1 (higher is better).
Criticized for not capturing semantic adequacy.
b. METEOR
44
Calculates the number of edits (insertions, deletions, substitutions) needed to match
the reference.
Lower TER indicates better quality.
e. COMET / BERTScore
Domain mismatch: Training on legal texts but testing on casual conversation can
lead to errors.
45
using unseen data. The aim is to assess how well the model generalizes beyond the
training data and to measure the linguistic accuracy, fluency, and semantic
consistency of the translations.
Testing also ensures that the model meets predefined objectives such as correctness,
robustness, and efficiency.
CHAPTER 5
46
CONCLUSION & FUTURE SCOPE
5.1 Conclusion
The project focused on translating sentences from French to English using various
deep learning models, including a basic RNN with embedding, a Bidirectional RNN
with LSTM, and a more complex Encoder-Decoder (Seq2Seq) model. Through
extensive experimentation and comparison, the Encoder-Decoder model
demonstrated superior performance in terms of both training and validation
accuracy. This model's ability to handle sequential dependencies and contextual
nuances resulted in highly fluent and accurate translations.
The training process involved using a curated dataset with clearly defined
vocabulary limits, preprocessing through tokenization and padding, and model
training with modern optimization techniques like the Adam optimizer and
categorical crossentropy loss function. Despite computational limitations (restricted
GPU memory and dataset size), the models achieved accuracy scores exceeding
98%, validating the effectiveness of the architecture choices and training
methodology.
The testing phase further confirmed the model's quality, with translations aligning
closely with those produced by commercial systems such as Google Translate. This
outcome demonstrated the practicality and reliability of the proposed system for
real-world translation tasks within the scope of the trained vocabulary.
From a theoretical standpoint, this project allowed us to grasp the core concepts of
sequence modeling, embedding layers, recurrent and bidirectional layers, and
attention to detail in both preprocessing and evaluation. It also provided a strong
foundation in Python-based deep learning frameworks like TensorFlow and Keras,
and introduced us to working within cloud-based environments like Google Colab.
The development process, from data preprocessing to model training and evaluation,
highlights the strengths of NMT in processing language contextually and efficiently.
47
By utilizing the Google Colaboratory environment, the team achieved a balance
between computational resource constraints and model performance, enabling the
system to generate accurate results even with limited vocabulary and data.
This project not only strengthens the understanding of NMT architectures but also
opens the door to practical applications across various industries, such as customer
service, education, and multilingual content generation.
While the current system has some limitations, such as a fixed vocabulary range and
challenges with long sentences, it sets a strong foundation for future advancements.
By incorporating attention mechanisms and transformer-based models, the project
can evolve to handle broader language pairs and enhance translation quality further.
Technical Contributions
The project makes significant advancements in the field of Natural Language
Processing (NLP) by systematically exploring and implementing state-of-the-art
NMT architectures. The choice of models like RNN with embeddings, Bidirectional
RNN, and Encoder-Decoder networks demonstrates a progression in understanding
and optimizing neural translation systems. Specifically, the finalized Encoder-
Decoder model showcases the following strengths:
The use of Google Colaboratory with GPU acceleration plays a critical role in
overcoming computational constraints, ensuring efficient training and testing. The
integration of tools like TensorFlow and Keras highlights the accessibility and
modularity of the deep learning framework utilized in the project.
Practical Applications
48
o Facilitates multilingual communication for companies operating in
international markets.
o Enables the translation of contracts, marketing materials, and reports to
cater to diverse audiences.
Research Insights
Societal Impact
49
Ultimately, this project exemplifies how Neural Machine Translation can
revolutionize language translation technologies, bridging gaps in communication,
accessibility, and collaboration across global platforms. While the current
implementation demonstrates impressive results, its limitations point toward
exciting opportunities for future growth. The project’s success serves as a stepping
stone for both academic exploration and real-world applications, showcasing the
power of AI in fostering an interconnected and inclusive world.
Let me know if you'd like further elaboration on any specific section!
50
The success of this Neural Machine Translation (NMT) project lays a robust foundation for
further advancements and real-world applications. The potential for growth and
development in this domain is vast, and here are some key aspects where the project can
evolve in the future:
2. Multilingual Translation
Currently, the project focuses on French to English translation, but the architecture can be
extended to support multiple language pairs. Implementing multilingual models like
mBERT or XLM-R could enable simultaneous translations across a wide range of
languages, making the system highly versatile and applicable globally.
The translation model can be optimized for real-time translation tools, such as chat
applications, virtual assistants, and live transcription services. By reducing latency and
increasing computational efficiency, the system can cater to use cases like:
Multilingual customer support.
Live event translations.
Real-time subtitles for videos or conferences.
4.Domain-Specific Fine-Tuning
5. Zero-Shot Translation
51
Future iterations could explore zero-shot translation, enabling the model to translate
between language pairs that it hasn’t been explicitly trained on. This approach, powered by
advanced transformer architectures, would make the system truly scalable and flexible.
Developing methods to handle cultural nuances and idiomatic expressions would improve
the translation system’s fluency and relevance. This involves refining datasets to include
context-rich and regionally specific content, helping the system cater to diverse global
audiences.
The project could evolve into a full-fledged speech translation system by integrating
automatic speech recognition (ASR) and text-to-speech (TTS) capabilities. This would
make the system suitable for applications like:
Multilingual video conferencing.
Language learning tools.
Accessibility services for visually or hearing-impaired individuals.
Integrating sentiment analysis with NMT could allow the system to preserve not just the
text’s literal meaning but also its emotional tone, ensuring more effective communication.
This would be particularly useful for social media monitoring and customer feedback
analysis.
9. Resource Optimization
The project can explore methods to reduce the reliance on high-end hardware. Efficient
model architectures like DistilBERT or TinyBERT could be adapted to create lightweight
models that perform well even on low-resource devices, expanding the system’s
accessibility.
Many languages, especially those spoken by smaller populations, lack sufficient training
data. Incorporating techniques like unsupervised learning or transfer learning could extend
the system to low-resource languages, contributing to linguistic inclusivity.
52
Future developments can focus on creating a collaborative ecosystem where users can
provide feedback on translations. By incorporating human-in-the-loop learning, the model
can continuously improve its accuracy and adapt to emerging linguistic trends.
Beyond direct translation, the system could be expanded to extract semantic insights across
languages. For instance, it can analyze customer sentiment in user-generated content,
making it valuable for businesses seeking multilingual market insights.
The future of this NMT project is rich with possibilities. By embracing innovations like
attention mechanisms, multilingual capabilities, real-time applications, and domain-specific
adaptations, the system has the potential to revolutionize language translation technology.
With growing integration into industries, education, and accessibility services, this project
will continue to contribute to an increasingly interconnected and inclusive world.
CHAPTER 6
53
BIBLIOGRAPHY
[1] Karunesh Kumar Arora, Shyam S. Agrawal, “Pre-Processing of English-
Hindi Corpus for Statistical Machine
Translation,” Computación y Sistemas, pp. 725-737, 2017, doi: 10.13053/CyS-
21-4-2697.
[4] Mussyazwann Azizi Mustafa Azizi, Mohammad Nazrin Mohd Noh, Idnin
Pasya, Ahmad Ihsan Mohd Yassin, Megat Syahirul Amin Megat Ali, “Pedestrian
detection using Doppler radar and LSTM neural network,” IAES International
Journal of Artificial Intelligence (IJ-AI), Vol. 9, No. 3, pp. 394-401, 2020, doi:
http://doi.org/10.11591/ijai.v9.i3.pp394-401
[6] Thang Luong, Ilya Sutskever, Quoc Le, Oriol Vinyals, and Wojciech
Zaremba,“Addressing the Rare Word Problem in Neural Machine
Translation,”In Proceedings of the 53rd Annual Meeting of the Association for
Computational Linguistics and the 7th International Joint Conference on
Natural Language Processing, Beijing, China. Association for Computational
Linguistics Vol. 1, pp. 11–19, 2015, doi: 10.3115/v1/P15-1002.
[7] Ahmed Y. Tawfik, Mahitab Emam, Khaled Essam, Robert Nabil and Hany
Hassan, “Morphology-Aware Word Segmentation in Dialectal Arabic Adaptation
of Neural Machine Translation”, In Proceedings of the Fourth Arabic
Natural Language Processing Workshop, pp. 11-17, 2019, doi:
10.18653/v1/W19-4602
[8] Pan, Yirong & Li, Xiao & Yang, Yating & Dong, Rui, “Morphological Word
Segmentation on Agglutinative Languages for Neural Machine Translation,”
ArXiv.org, 2020, Web Link: https://arxiv.org/abs/2001.01589.
54
models with multiple subword candidates,” Proceedings of the 56th Annual
Meeting of the Association for Computational Linguistics, pp. 66–75
Vol. 1, 2018, doi: 10.18653/v1/P18-1007
[11] Thang Luong, Richard Socher, and Christopher D. Manning, “Better Word
Representations with Recursive Neural Networks for Morphology,”In
Proceedings of the Seventeenth Conference on Computational Natural Language
Learning, CoNLL2013, Sofia, Bulgaria, August 8-9, pp. 104-113, 2013, Web
Link: https://www.aclweb.org/anthology/W13-3512.
[12] Rico Sennrich, Barry Haddow and Alexandra Birch, “Neural Machine
Translation of Rare Words with Subword Units,”In Proceedings of the 54th
Annual Meeting of the Association for Computational Linguistics, August 7-12,
pp. 1715-1725, 2016, doi: 10.18653/v1/P16-1162
[13] Mai Oudah, Amjad Almahairi and Nizar Habash, “The Impact of
Preprocessing on Arabic-English Statistical and
Neural Machine Translation,”ArXiv.org, Aug. 19-23, pp. 214-221, 2019, Web
Link: https://www.aclweb.org/anthology/W19-6621.
[14] Piotr Bojanowski, Edouard Grave, Armand Joulin and Tomas Mikolov,
“Enriching Word Vectors with Subword Information”, Transactions of the
Association for Computational Linguistics, vol. 5, pp. 135-146, 2017, doi:
10.1162/tacl_a_00051.
[16] Noe Casas, José A. R. Fonollosa, Carlos Escolano, Christine Basta, and
Marta R. Costa-jussà, The TALP-UPC Machine Translation Systems for
WMT19 News Translation Task: Pivoting Techniques for Low Resource MT, In
Proceedings of the Fourth Conference on Machine Translation, Vol. 2, pp. 155–
162, 2019, doi: 10.18653/v1/W19- 5311.
55
Computing Conference, pp. 174-177, 2016, doi: 10.1109/IACC.2016.41.
[20] Kyunghyun Cho, B. V. M., Dzmitry Bahdanau, Yoshua Bengio, “On the
Properties of Neural Machine Translation: Encoder–Decoder Approaches,
”Proceedings of SSST-8, Eighth Workshop on Syntax, Semantics and Structure in
Statistical Translation, pp. 103-111, 2014, doi: 10.3115/v1/W14-4012.
[21] Philip Gage, “A New Algorithm for Data Compression,”CUsers J., pp. 23-
38, February, 1994, Web Link: https://dl.acm.org/doi/10.5555/177910.177914.
56