Translator
Translator
ABSTRACT
LIST OF FIGURES
LIST OF TABLES
LIST OF ABBREVATION
I INTRODUCTION
1.1 Motivation
1.3 Objectives
1.4 Scope
3.2 Implementation
3.2.2 Dataset
IV RESULT ANALYSIS
V CONCLUSION
The development of technology connects everyone from all around the worlds. The
problem is, people cannot really mingle with one another because they have communication
problems. Some of the problems are with other traveler, disabled peoples, Friends in social
media, and International business partners. This device invented to solve this entire problem
that faced by people in today’s life. This device invented to make people more
knowledgeable, reduce miscommunication among people all around the world, connects
people, get maximum profit and give job opportunity to people.
The better translation must be accepted by all people in logic and based on fact; thus,
the message which contained in the source language (SL) can satisfy the target language (TL)
reader with the information within. Translation is necessary for the spreading new
information, knowledge, and ideas across the world. It is absolutely necessary to achieve
effective communication between different cultures. In the process of spreading new
information, translation is something that can change history
ABBREVATION DESCRIPTION
SL Source Language
TL Target Language
ST Source Text
TT Target Text
MT Machine Translation
INTRODUCTION
Translation is necessary for the spreading new information, knowledge, and ideas
across the world. It is absolutely necessary to achieve effective communication between
different cultures.In the process of spreading new information, translation is something
that can change history.
1.1 MOTIVATION
The structure of sentences in English and other languages may be different. This is
considered to be one of the main structural problems in translation. Limit your Expertise:
Gain expertise only in a couple of languages that you are already well-versed with. The
translator has to know the exact structure in each language, and use the appropriate
structure.
OBJECTIVES
1.3 SCOPE
.
CHAPTER 2
REVIEW OF LITERATURE
to develop a proof
concept to provi
1. Direct Speech to Speech Sireesh Haang December 2020 evidence supporting
Translation Using Machine Limbu unique translation syste
Learning that might prove to
better and faster
PROPOSED SYSTEM
1. IMPORTMODULES:
WeimportttkmodulesfromtkinterlibraryandTranslator,LANGUAGESmodulesf
rom googletrans library, speech recoginition module, gtts module.
2. CREATEADISPLAYWINDOW:
Weusetkinterlibrarytocreateawindowwherewe’llenterthetextwhichwewantto convert
into voice.
Tk()initializedtkinterwhichmeanswindowcreated geometry() set the width and height
of the window.
resizable(0,0)setthefixedsizeofthewindowbg=‘’useto set the background color title()
used to set the title of the window.
Label()widgetusetodisplayoneormorethanonelineoftextthatusersaren’tableto modify.
root is the name which we refer to our window text
whichwedisplayonthelabelfontinwhichthetextis written pack organized widget in
block.
3. CREATEAINPUT-OUTPUTTEXTWIDGET:
Theabovecodecreatestwotextwidgetsoneforenteringtextandtheotherfordisplaying
translated text.
Text()widgetisusedformultipletextlines.
wrap=WORDwillstop thelineafterthelastwordthatwillfit.padxputsan extra bit of space
to the left and right of the widget.
Padyaddsanextrabit ofspacetothetopandbottom.
4. DEFINECOMBOBOX:
5. DEFINEFUNCTION:
The Translate function will translate the message and give the output. src gets the
languageselectedasinputtextlanguagedestgetsthelanguageselecttotranslatetext
getstheinputtextenteredbytheuser.”1.0″meansthattheinputshouldbereadfrom zero
characters to line one The END part means to read the text until the end is
reachedtranslator=
Translator()usedtocreateaTranslatorclassobjectOutput_text.delete(1.0,END) delete all
the text from line one to end.
Output_text.insert(END,translated.text)willinsertthetranslatedtextinOutput_text.
6. CREATEATRANSLATEBUTTON:
WhenweclickontheTranslatebuttonitwillcallthetranslatefunctionButton()widget used
to display button on our window command is called when we click the button
activebackground sets the background color to use when the button is active
root.mainloop().
3.1.1 ALGORITHM / FLOWCHART:
ALGORITHM:
Step1:Selectthelanguage.
Step2:Inputthetext/speechthatwanttotranslate.
Step4:Languagedetection
Step5:Translateintogivenlanguage
Step7:Outputoftranslatedlanguage
TkintermoduleasGUIinterface.
Cttypeslibrary.
PILlibrary(pythonimaginglibrary).
Tkinter.Messagebox as MessageBox.
Speechrecognitionlibrary.
pyttsx3isatext-to-speechconversionlibrary.
Threadinglibrary.
Fromdeep translator moduleimportgoogletranslibrary.
Gttsmodulefortextto audio.
PydubisaPythonlibraryworkwithaudiofiles.
CHAPTER 4
SOFTWARE SPECIFICATION
Programming Language:
Python
Frontend:
HTML, CSS/Reactjs
Backend:
Database:
Cloud Services:
METHODOLOGY
This section discusses There are three methods for learning a word embedding from
text data. However, this section discusses, about Embedding Layer and Word2Vec.
5.2.2 Word2Vec:
Word2Vec is a statistical approach for learning a solitary word embedding from a text
corpus quickly and effectively (Brownlee, 2017).
It was Introduced by Tomas Mikolov et al. at Google in 2013 as a way to improve the
efficiency of neural-network-based embedding training, and it has since become the de facto
standard for producing pre-trained word embedding (Brownlee, 2017).
The task also included analysing the learnt vectors and experimenting with vector
math on word representations. For example, taking the "man-ness" out of "King" and adding
"womenness" gives "Queen," which captures the connection "king is to queen as man is to
woman" (Brownlee, 2017)
The following are the two distinct learning models that are used as a part of word2vec
(Brownlee, 2017). CBOW Model (Continuous Bag-Of-Words) Continuous Skip-Gram Model
CBOW model is used to predict the current word based on its context. Whereas, for
Continuous Skip-Gram model is used to predict the current words based on the adjacent
words (Brownlee, 2017).
Both of these models are concerned with learning about words in the context of their
local use, which is specified by a window of nearby words. It is possible to configure this
window as a model parameter (Brownlee, 2017).
The main advantage of this approach is that high quality word embeddings can be
learnt quickly (due to time complexity and low space), this enables more dimensions to be
learned from considerably larger corpora of text (Brownlee, 2017).
5.3 Long Short-term Memory (LSTM):
LSTM came into the picture because of the drawbacks of simple RNN’s i.e..,
Vanishing Gradient problem, which was discussed in the previous chapter. To resolve this
issue, LSTM will use Gated mechanism, which can control the memorizing process (Singhal,
2020b). The
Gates that open and close will allow the information to be saved, written or read in
LSTM’s. Sigmoid ranges with values between 0 and 1 implement element-wise
multiplication using these gates. This Analog is appropriate for the back propagation, as it is
differentiable in nature (Singhal, 2020b).
Tanh is an activation function that is not linear. Tanh function controls the values that
flow through the network, ranging the values between -1 and 1. There is a need for a function
that can retain its second derivative for a longer period of time in order to prevent information
fading (Singhal, 2020b). Values might become enormous in some cases, further resulting in
insignificance among them. In the below illustration, the number 5 stays inside the bounds
because of this tanh activation function (Singhal, 2020b).
Sigmoid activation function is also non-linear function. The gate contains the sigmoid
activation function. The values of the sigmoid function ranges between 0 and 1 (Singhal,
2020b). This will assist the network by updating the information or by forgetting the
information. If the value is 1, then the information stays, similarly, If their product is 0, then
the information is forgotten. This aids the network, that which information is important to
keep and which to forget (Singhal, 2020b).
To summarise the concept of LSTM, it contains three gates (forget gate, input gate
and an output gate). In order to determine whether prior information is relevant, the forget
gate must be used. Adding relevant information from the current step is controlled by the
input gate, and finalizing it is controlled by the output gate.
5.4 Language Translation using Transformers :
5.4.1 Transformers :
self-attention mechanism is shown in the above figure. In addition to looking at "I", "kicked",
and "ball" in the input sequence, the model can also answer three questions - "Who", "Did
what", and "To Whom" - to get a better understanding of the specific word "kicked"(Nguyen,
2019). As explained by (Vaswani et al., 2017), the mechanism used for attention is dot-
product attention, which can be described as follows:
Attention Formula
A matrix Q consists of a row and column matrix containing the set of queries packed
together and a K and a V matrix containing the required keys and values. Encoder-decoders
are typically hidden in both their query and key states. Keys and values are inputs. Based on
how much attention a corresponding key receives, the value represents a normalized weight
(Nguyen, 2019).
The encoder side of self-attention layer provides better representation for the input xt,
where t is the time step, that is generated by self-attention using all other inputs
x1,x2,x3,x4…….xn. where n is the length of the sequence (Nguyen, 2019).
The Transformer is more suitable for parallelization than RNNs because this work can
be done simultaneously for all input steps.
As another advantage, a self-attention layer connects all positions utilizing only O(1)
number of sequential operations, which is cheaper than using RNNs with a dimension of O(n)
(Nguyen, 2019).
xt is the input at time step t, that is being used as a query at the decoder. The keys and
values of the self-attention layer are obtained by combining all of the past queries x1,
x2,...,xt-1 (Nguyen, 2019).
5.6 Self-Attention Layer predicts at time step
Each head transforms the input representation into a unique query, key and value.
MultiHeaded attention is calculated by calculating the scaled dot attention h times in parallel.
Afterward, the outputs are concatenated (Nguyen, 2019).
After that, one single linear transformation is applied to the input, as shown in Figure,
and it is then concatenated.
EXPERIMENTATION
Dataset
For a language translation model, finding proper datasets is really important. After
thorough research there is a parallel corpus for both the languages (scionoftech, 2019).This
corpus contains approximately 300,000 sentences of the Tamil Language and the English
language. Once the corpus is downloaded, it is assigned to a variable. Apart from this, we are
taking the non-breaking prefixes (moses-smt, 2019). In both the languages are also imported
as mentioned below
Data Cleaning
Cleaning the data is the primary step in data pre-processing. Now, convert the non-
breaking prefixes from both the languages into lists. Whenever these non-breaking prefixes
appear in a sentence, they do not mark the end of the sentence. It would be better to have the
lists of non-breaking prefixes prepared as a list with a period at the end so it is easier to use. It
is shown below.
Procedure to remove Consecutive spaces from the corpus:
To determine if there are any non-breaking prefixes in the corpus, iterate over the
lists.
Append “$$$” at the end of each prefix.
Once after finding all the occurrences of periods, then there will be an immediate
appending of this alpha numeric “$$$” between the period and the character.
By removing all the occurrences of “.$$$”. Then there won’t be any non-braking
periods.
Now, these consecutives spaces will be replaced with single space.
Final step is splitting the corpus into a list.
6.2 Text Tokenization :
For a neural network to process the information, the data should have to be in a
numerical form. So, one of the ways to convert a string into a text is by using tokenizer. Here,
in this project SubWordEncoder is used to create a tokenizer for the data. This Encoder
encodes the text into a number, which can be used for calculation. The vocabulary size of a
tokenizer is of 213 i.e., approximately 8,192 tokens.
6.3 Building the model :
Basic components required to build our model are
Positional Encodings
Self-Attention Layers
Point- Wise Feed forward Network Layers
By using these components Multi layered Encoders and decoders are created.
The below image illustrates the transformer architecture. Here are the parts. There is a
multilayer encoder. It transmits its output to the decoder. From the decoder, the model output
is generated. The encoder and decoder inputs are preceded by embedded and positional
encoding. Technically, these steps are not part of the model, but they are necessary.
Additionally, a linear transformation and SoftMax functions are applied to the decoder
outputs.
Multi-Headed attention are multiple scaled dot-product attention layers stacked upon
each other and concatenated, then passed through a dense layer. Multi-Headed attention
allows the transformer model to jointly deal with multiple subspace representations from
different positioned tokens.
6.5 Decoder :
The Decoder takes in the target value and applies token and positional encoding to it
aswell. The decoder also contains a Multi-Head Attention layer, however the scaled dot-
production attention layer in the Multi-Head Attention masks out all values that the softmax
activation deems unnecessary or illegal, hence the name Masked Multi-Head Attention
Layer. The output of the MMHAL is the query for the next regular Multi-Headed Attention
while the key and value are the outputs from the encoder (encoded inputs). The decoder then
passes the result through a Feed Forward Layer and then a classification Dense network for
final predictions
train.py
--data_directory data
followed by a space to seperate each hyperparameter entered. Please refer to the file to see
specific hyperparamters. NOTE: In order to train yourself, either download the proper
tgz files in the datasets section below and correct the script parameters or use your own
dataset and modify the train.py file to work with your dataset.
translate.py
This command will translate the text "What is your name?" to French.
To use tranlate.py correctly, the model weights and dictionary files must follow the
following organization. In the saved_models directory, create a directory signifying the
translation model (eg. english2french) and save the models that translate from english to
french in said directory. Also save the dictionary files using pixel. If your cloning this repo
and don't want to train, then there is no need to do any of the steps above as all files are
in place.
models.py
Contains the component classes to build a Transformer model and includes the
Transformer Class. Also includes Feed-Forward Layer, Multi-Head Attention, Encoder
Layers, Encoder, Decoder Layers, and Decoder.
dictionary.py
creates a Dictionary class which keeps track of all words seen from the dataset in
each language and assigns a unique token to every new word.
utilities.py
contains utility functions to help with preprocessing and post processing data.
6.7 PURELY TESTING :
If you want to test the software without training or any other steps described above,
then follow the following steps:
Step 1:
Step 2:
Ensure you have all the requirements necessary in the requirements.txt file. Main ones
are Pytorch and other math libraries such as Numpy.
Step 3:
For example,
For this project, the European Parliament Proceedings Parallel Corpus 1996-2011 is
used. Note, the downloaded files are tgz files. In order to use them, please extract them and
name them according to the format you see in this repo, including appropriately expanding
names for convenient access. Link to dataset: https://www.statmt.org/europarl/
SAMPLES :
Since I do not know many of the langauges I have trained on the Transformer
model, I will be using more robust translators as comparison such as Google Translate.
INPUT: "this debate and the amendment of the directive currently in force allow us to
incorporate differentiating elements which demonstrate the diversity of this Europe of ours."
PREDICTION: "ce debat et l amendement de la directive nous permet d integrer les
elements qui demontrent la diversite de notre europe ."
LI TRANSLATE:: " ce débat et l'amendement de la directive actuellement en vigueur nous
permettent d'intégrer des éléments de différenciation qui démontrent la diversité de cette
Europe qui est la nôtre."
As you can see with the example above, the prediction may not be word to word with
Google Translate results, but the prediction still maintains the semantic information and
context that was in the input.
INPUT: "você deve dormir uma boa quantidade de sono todos os dias."
PREDICTION: "sleep a good amount of sleep every day ."
LI TRANSLATE: "you should get a good amount of sleep every day."
CHAPTER 7
APPENDIX
Source code
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Translator App</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
.bubble {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
color: rgba(255,255,255,0.7);
font-family: sans-serif;
@keyframes float {
/* Liquid blobs */
.liquid-translation-container {
perspective: 1000px;
transform-style: preserve-3d;
position: relative;
.liquid-blob {
position: absolute;
border-radius: 50%;
filter: blur(1px);
mix-blend-mode: screen;
opacity: 0.5;
.blob1 {
width: 60px;
height: 60px;
top: 10px;
left: 10px;
animation-delay: 0s;
.blob2 {
width: 70px;
height: 70px;
top: 20px;
right: 5px;
animation-delay: -2s;
.blob3 {
width: 55px;
height: 55px;
bottom: 15px;
left: 30px;
animation-delay: -4s;
@keyframes morph {
0%, 100% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
25% { border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%; }
50% { border-radius: 50% 60% 50% 40% / 40% 30% 60% 50%; }
75% { border-radius: 40% 60% 70% 30% / 60% 40% 30% 70%; }
/* Text particles */
.text-particle-container {
position: absolute;
inset: 0;
transform-style: preserve-3d;
}
.text-particle {
position: absolute;
font-weight: bold;
color: white;
opacity: 0.8;
@keyframes pulse {
@keyframes rotate3d {
/* Connection lines */
.connection-line {
stroke-dasharray: 5;
@keyframes dash {
to { stroke-dashoffset: 100; }
/* Progress bar */
.translation-progress-bar {
@keyframes progress {
0% { width: 15%; }
@keyframes shimmer {
0% { background-position: -200% 0; }
About us.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #fffd7f;
.container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
.header {
text-align: center;
padding: 2rem 0;
background-color: #ff51e8;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
.content {
background-color: #a5f79d;
padding: 2rem;
margin: 2rem 0;
border-radius: 8px;
.features {
display: grid;
gap: 2rem;
margin-top: 2rem;
.feature-card {
background-color: #ff92c5;
padding: 1.5rem;
border-radius: 6px;
text-align: center;
h1 {
color: #333;
margin-bottom: 1rem;
h2 {
color: #444;
margin-bottom: 1rem;
</style>
</head>
<body>
<div class="header">
</div>
<div class="container">
<div class="content">
<p>We are dedicated to breaking down language barriers and facilitating global
communication through our advanced translation service. Our platform leverages state-of-
the-art machine translation technology to provide accurate and reliable translations across
multiple languages.</p>
<h2>Our Mission</h2>
<ul>
<li>English to Hindi</li>
<li>English to French</li>
<li>English to Arabic</li>
</ul>
<div class="features">
<div class="feature-card">
<h3>Fast Translation</h3>
</div>
<div class="feature-card">
<h3>Accurate Results</h3>
</div>
<div class="feature-card">
<h3>Free to Use</h3>
</div>
</div>
<h2>Technology</h2>
<p>Our translation service is powered by the OPUS-MT (Open Parallel Universal
Speech) machine translation models, which are specifically trained for high-quality
translations between various language pairs.</p>
<h2>Contact Us</h2>
<p>Have questions or feedback? We'd love to hear from you! Please reach out to us
through our contact form or email.</p>
</div>
</div>
</body>
</html>
Contact us
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
</button>
</a>
</a>
</div>
</div>
<div class="space-y-6">
<div class="space-y-4">
</div>
<div>
<p class="text-gray-600">support@translator.com</p>
</div>
</div>
</div>
<div>
</div>
</div>
</div>
<div>
</div>
</div>
</div>
<div class="pt-6">
</a>
<a href="#" class="w-10 h-10 bg-blue-100 rounded-full flex items-center
justify-center hover:bg-blue-200 transition-all duration-300">
</a>
</a>
</div>
</div>
</div>
App.py
translation_service = TranslationService()
translation_service.initialize()
@app.route('/api/detect', methods=['POST'])
def detect_language():
data = request.json
result = translation_service.detect_language(data['text'])
return jsonify(result)
@app.route('/api/translate', methods=['POST'])
def translate_text():
data = request.json
source_lang = data.get('source_lang')
result = translation_service.translate_text(
text=data['text'],
source_lang=source_lang,
target_lang=target_lang
return jsonify(result)
@app.route('/api/sentiment', methods=['POST'])
def analyze_sentiment():
data = request.json
original_lang = data.get('lang')
result = translation_service.analyze_sentiment(
text=data['text'],
original_lang=original_lang
return jsonify(result)
@app.route('/api/identify', methods=['POST'])
def identify_text():
data = request.json
categories = data.get('categories')
original_lang = data.get('lang')
result = translation_service.identify_text(
text=data['text'],
categories=categories,
original_lang=original_lang
return jsonify(result)
@app.route('/api/languages', methods=['GET'])
def get_languages():
languages = translation_service.get_supported_languages()
@app.route('/api/pairs', methods=['GET'])
def get_pairs():
pairs = translation_service.get_supported_pairs()
@app.route('/api/health', methods=['GET'])
def health_check():
return jsonify({
"status": "ok",
"languages_supported": len(translation_service.get_supported_languages()),
"pairs_supported": len(translation_service.get_supported_pairs())
})
def main():
args = parser.parse_args()
translation_service.initialize()
if _name_ == "_main_":
main()
OUTPUT
Logo
CHAPTER 7
RESULT ANALYSIS
We develop this application for desktop application. Here we are integrating the
speech to speech, text to text, speech to text and language translator in one system so user
doesn’t have to download for the different application. You can also give voice input to
translate language.
TECHNOLOGY:
⚫ Python frontend
⚫ API calls
7.1 MODULES:
USER MODULE
CONCLUSION
In this proposed system, we implemented the system for user who phasing
problems of language barrier and also it user interface is also user friendly so that user
can easily interact with this system . so it automatically reduce the user task for
understanding the languages for communication. Translation is not merely at changing
words, but also transferring of cultural equivalence with the culture of the original
language and the recipient of that language as well as possible.
The better translation must be accepted by all people in logic and based on
fact; thus, the message which contained in the source language (SL) can satisfy the
target language (TL) reader with the information within. When you understand the
importance of translation for everyone, you will be able to see it as a necessary and
worthy investment.
The primary objective of this study was to build a language translation model
that uses machine learning to translate from Tamil to English. As many studies have
focused on the English language and other European languages in the past, However,
there aren't any existing studies done on the Tamil language.
So, the Tamil language has been chosen for this research. The neural network
architecture used for this research, that made this project success, is by using
Transformers for language translation. It translates own sentences of the Tamil
language into the English. Moreover, in this research the language translation using
Transformer model is providing a bit better result when compared to Google
Translator from (Tamil to English).
The training time, the model took to train the dataset is almost 12.5 hours. And
the accuracy of the translation is quite good. However, there are few drawbacks in the
translation, this can be eradicated by researching further.
CHAPTER 9
FUTURE SCOPE
However to make this system more precise and useful for a wide range of target
audience, it demands some further improvements Further we are aiming at following
improvements: To take input text from an image of printed English text by implementing
character recognition. Presently we are only able to take manual input through virtual
keyboard. The system can be further extended to include more languages and possibly
dialects.
Languages such as Tamil need more research, since they are different from English
and other languages. Due to the lack of parallel datasets, they are unable to develop several
natural language processing tasks, particularly translation. The building of datasets will
therefore support and help researchers develop new and reliable models. Further research
might need to build Tamil datasets since there are not sufficient datasets for these languages.
This would encourage a great deal of research in this area since datasets are always a barrier
when it comes to NLP tasks. However, when we use google translate, we would get a good
result out of existing language i.e., If we ask the google translator to translate from the
English to Tamil, we will get a good translation which is quite good. If any foreigners visit
India, they would know what to talk, what to say. However, there are several immigrants who
want to have a better life and want to understand how to speak in English, they will use these
translations really well. When we try to translate other way around i.e., from Tamil to
English, the translation is not as good as the translation from English to Tamil. Moreover,
further research and experimentation on the Tamil translation would be very useful. In this 69
Bournemouth University, Department of Computing and Informatics, Final Year Project
regard, I would encourage others to improve our existing models.
REFERENCES