Skip to content

Latest commit

ย 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ Machine Translation with Seq2Seq Neural Networks

A Neural Machine Translation (NMT) system that translates English to Spanish using TensorFlow, Keras, and a Seq2Seq Encoder-Decoder architecture built with LSTM neural networks.

Originally developed as part of the Codecademy Machine Translation project, this application has been extended into a complete machine learning portfolio project with:

  • Interactive command-line translator
  • Streamlit web application
  • Statistics dashboard
  • Unknown vocabulary detection
  • Custom sentence translation
  • Early stopping
  • Modern Keras model persistence (.keras)
  • Improved preprocessing and tokenization

๐Ÿš€ Features

Neural Machine Translation

Translate English sentences into Spanish using:

  • Seq2Seq architecture
  • Encoder-Decoder design
  • LSTM neural networks
  • Teacher forcing
  • TensorFlow / Keras

Example:

Input:
Who?

Output:
ยฟQuiรฉn?

Interactive Command-Line Application

Launch the translator directly from the terminal:

python src/translate.py

Features:

1 - Translate custom text
2 - Test dataset examples
3 - Show model statistics
4 - Exit

๐ŸŒ Streamlit Web Application

The project includes a web-based interface powered by Streamlit.

Run:

streamlit run streamlit_app.py

The application launches in your browser and allows users to:

  • Enter English text
  • Generate Spanish translations
  • View model statistics
  • Interact with the translator without using a terminal

๐Ÿ“ธ Application Screenshots

Home Page

Home Page


Translation Example

Translation Example


Model Statistics

Model Statistics


๐Ÿ“‚ Project Structure

machine-translation/
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ home-page.png
โ”‚   โ”œโ”€โ”€ translation-example.png
โ”‚   โ””โ”€โ”€ model-statistics.png
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ spa.txt
โ”‚
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ training_model.keras
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ preprocessing.py
โ”‚   โ”œโ”€โ”€ train.py
โ”‚   โ”œโ”€โ”€ translate.py
โ”‚   โ””โ”€โ”€ utils.py
โ”‚
โ”œโ”€โ”€ tests/
โ”‚
โ”œโ”€โ”€ streamlit_app.py
โ”‚
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ .gitignore

๐Ÿง  Model Architecture

Encoder

Input Sequence
      โ†“
LSTM (256 units)
      โ†“
Hidden State
Cell State

Decoder

Start Token
      โ†“
LSTM (256 units)
      โ†“
Dense Softmax Layer
      โ†“
Predicted Output Token

Total Parameters

9,894,582

Latent Dimension

latent_dim = 256

๐Ÿ“Š Dataset

Source:

ManyThings.org Language Dataset

Language Pair:

English โ†’ Spanish

Training Data Used:

10,000 sentence pairs

Vocabulary Learned:

Encoder Vocabulary : 2516 words
Decoder Vocabulary : 5302 words

โš™๏ธ Training Configuration

latent_dim = 256
batch_size = 50
epochs = 100

Training uses:

EarlyStopping(
    monitor="val_loss",
    patience=5,
    restore_best_weights=True
)

This automatically stops training once validation performance stops improving.


๐Ÿ“ˆ Model Statistics Dashboard

The application provides real-time model information.

Example:

Encoder vocabulary : 2516
Decoder vocabulary : 5302

Maximum input tokens : 8
Maximum output tokens : 17

Latent dimension : 256

Model size : 75.52 MB

๐Ÿ” Unknown Vocabulary Detection

Custom translation mode detects words that were not present in the training dataset.

Example:

Input:
My name is Wayne

Warning:
'Wayne' not found in training vocabulary

This helps explain translation limitations.


๐Ÿ›  Technologies Used

  • Python 3
  • TensorFlow
  • Keras
  • NumPy
  • Streamlit
  • Natural Language Processing (NLP)
  • Seq2Seq Neural Networks
  • LSTM Networks
  • Machine Learning
  • Deep Learning

๐Ÿ’ป Installation

Clone the repository:

git clone https://github.com/YOUR_USERNAME/machine-translation.git

Navigate into the project:

cd machine-translation

Create a virtual environment:

python -m venv venv

Activate:

Windows

venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

โ–ถ๏ธ Usage

Train the Model

python src/train.py

Output:

models/training_model.keras

Run CLI Translator

python src/translate.py

Run Web Application

streamlit run streamlit_app.py

๐Ÿงช Example Results

Input

Who?

Translation

ยฟQuiรฉn?

Input

Run!

Translation

ยกร“rale!

Input

How are you?

Translation

ยฟEstabas aquรญ?

๐ŸŽฏ Learning Outcomes

This project demonstrates:

  • Neural Machine Translation
  • Encoder-Decoder Architectures
  • Seq2Seq Models
  • LSTM Networks
  • Deep Learning Workflows
  • Model Persistence
  • TensorFlow / Keras Development
  • NLP Tokenization
  • Streamlit Application Development
  • Git & GitHub Project Management

๐Ÿ”ฎ Future Enhancements

Potential future improvements:

  • Word Embeddings
  • Attention Mechanisms
  • Transformer Architecture
  • Translation Confidence Scores
  • BLEU Score Evaluation
  • Larger Training Datasets
  • Multiple Language Support
  • Docker Deployment
  • Cloud Hosting

๐Ÿท Topics

Machine Learning โ€ข Deep Learning โ€ข NLP โ€ข Natural Language Processing โ€ข Machine Translation โ€ข Neural Machine Translation โ€ข Seq2Seq โ€ข Encoder Decoder โ€ข LSTM โ€ข TensorFlow โ€ข Keras โ€ข Streamlit โ€ข Python โ€ข Artificial Intelligence


๐Ÿ“„ License

This project is licensed under the MIT License.

See the LICENSE file for details.

Codecademy Machine Translation project and expanded into a standalone machine learning portfolio project featuring a Streamlit web application, custom translation interface, statistics dashboard, and modern Keras workflow.

Releases

Packages

Contributors

Languages