Skip to content

Commit 0c10f12

Browse files
committed
add flaks ui and Peft + LoRA fine tune
1 parent ccdde2c commit 0c10f12

21 files changed

Lines changed: 7198 additions & 404 deletions

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
${{ runner.os }}-buildx-
3333
3434
- name: Build Docker image
35-
run: docker build -t bilingual-bridge .
35+
run: docker build -t translatica .
3636

3737
- name: Test the application (Run tests inside container)
38-
run: docker run --rm bilingual-bridge pytest tests/
38+
run: docker run --rm translatica pytest tests/

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ COPY . /app
1010
# Install the dependencies
1111
RUN pip install --no-cache-dir -r requirements.txt
1212

13-
# Expose Streamlit default port
14-
EXPOSE 8501
13+
# Expose the port Flask runs on
14+
EXPOSE 5000
1515

16-
# Correct command to run Streamlit app
17-
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
16+
# Command to run the Flask app
17+
CMD ["python", "app.py"]

README.md

Lines changed: 160 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Bilingual Bridge: English to Spanish Translation
2-
[![Image](https://github.com/user-attachments/assets/0cc3d6e3-fda2-4037-8fad-f08c60442448)](https://github.com/user-attachments/assets/55599f0a-0a62-4bee-9406-b79212dd3890)
1+
# Translatica: English to Spanish Translation
2+
33
## 📌 Overview
4-
Build a Machine Translation System capable of translating English text into Spanish using a fine-tuned Transformer-based model. The goal is to adapt a pre-trained multilingual model (Helsinki-NLP/opus-mt-en-es) on a domain-specific parallel corpus to improve translation. Deployed with a responsive Streamlit UI, containerized with Docker, and integrated with GitHub CI/CD for continuous delivery.
4+
Translatica is a Fine-tuned(with PEFT + LoRA) full-stack, LLM-powered translation system. This Machine Translation System capable of translating English text into Spanish using a fine-tuned Transformer-based model. Deployed with a responsive HTML, CSS & Flask, containerized with Docker, and integrated with GitHub CI/CD for continuous delivery.
5+
6+
[![Image](https://github.com/user-attachments/assets/ee8472fe-644e-48e8-adaf-63787a4abd06)](https://github.com/user-attachments/assets/ee8472fe-644e-48e8-adaf-63787a4abd06)
57

68
---
79

810
## 🚀 Live Demo
9-
1011
🎯 Try the real-time English → Spanish Translator here:
11-
👉 [**Bilingual Bridge – Click Here**](https://bilingual-bridge.onrender.com/)
12+
👉 [**Translatica– Click Here**](https://bilingual-bridge.onrender.com/)
1213

1314
---
1415

1516
## ✅ Real-World Use Case
16-
1717
In today's globalized digital ecosystem, cross-lingual communication is a key challenge. A **customized English-to-Spanish translation model** is highly valuable for:
1818

1919
* 🌐 **Global E-Commerce Platforms** where product descriptions, reviews, and customer support need real-time translation.
@@ -25,65 +25,161 @@ In today's globalized digital ecosystem, cross-lingual communication is a key ch
2525
---
2626

2727
## 📘 Technical Stack
28-
| **Category** | **Technology/Resource** |
29-
|----------------------|---------------------------------------------------------------------------------------|
30-
| **Programming Language** | Python 3.9+ |
31-
| **Core ML Framework** | HuggingFace Transformers 4.28+ |
32-
| **Model Architecture** | MarianMT (Transformer-based Seq2Seq) |
33-
| **Pretrained Model** | Helsinki-NLP/opus-mt-en-es |
34-
| **Dataset** | OPUS Books (en-es) + Custom Spanish Parallel Corpus |
35-
| **Data Processing** | HuggingFace Datasets, Pandas, NLTK (Text Preprocessing) |
36-
| **Tokenization** | SentencePiece (via HuggingFace Tokenizers) |
37-
| **CI/CD Pipeline** | GitHub Actions (Model Training/Evaluation Workflow) |
38-
| **Containerization** | Docker (with PyTorch Base Image) |
39-
| **Web UI** | Streamlit UI |
40-
| **Hosting Services** | Render |
28+
29+
| Feature | Description |
30+
| ------------------------------ | --------------------------------------------------------------------------- |
31+
| 🔁 **Translation** | Translate fluently English to Spanish |
32+
| 🧠 **Fine-Tuned LLM** | Custom model fine-tuned using **LoRA + PEFT** on bilingual datasets |
33+
| 🧰 **Techniques Used** | Peft, LoRA (Parameter Efficient Fine-Tuning), SentencePiece Tokenizer |
34+
| 🖥️ **Frontend** | Responsive UI built with **HTML + CSS + JS**, integrated via Flask |
35+
| 🧪 **Backend API** | Lightweight Flask server with endpoint for dynamic translation |
36+
| 🧠 **Tokenizer Customization** | Trained custom tokenizers with SentencePiece for improved language fidelity |
37+
| 💽 **Offline-Ready** | Entire model is local & GPU-optional — designed for CPU-based deployment |
38+
| 📦 **Modular Codebase** | Fully modular design following clean code & MLOps practices |
39+
| 📊 **Tested Dataset** | Trained and validated on Bangla-Spanish aligned translation corpus |
40+
| 📉 **Evaluation** | BLEU Score via `evaluate` |
41+
| 🔧 **CI/CD Pipeline** | GitHub Actions (Model Training/Evaluation Workflow) |
42+
| 🐳 **Containerization** | Docker |
43+
| 🚀 **Hosting Services** | Render |
44+
45+
---
46+
47+
## ⚙️ Tech Stack
48+
49+
* **Model**: [Helsinki-NLP/opus-mt-en-es](https://huggingface.co/Helsinki-NLP/opus-mt-en-es) (LoRA fine-tuned)
50+
* **Fine-Tuning**: LoRA + PEFT + Hugging Face Trainer
51+
* **Tokenizer**: SentencePiece (custom trained)
52+
* **Frontend**: HTML, CSS, JavaScript
53+
* **Backend**: Flask (Python)
54+
* **Deployment**: CPU-friendly, Flask server
55+
* **Project Structure**: Clean, modular, scalable
4156

4257
---
4358

4459
## 🧠 Model Training
45-
- **Dataset:** `opus_books` (English-Spanish parallel corpus)
46-
- **Model:** `Helsinki-NLP/opus-mt-en-es`
47-
- **Tokenizer:** SentencePiece tokenizer from pretrained model
48-
- **Fine-tuning:**
49-
- Batch size: 16
50-
- Epochs: 3
51-
- Learning rate: 2e-5
52-
- Weight decay: 0.01
53-
- Early stopping used
54-
- **Saving:** Trained model and tokenizer saved for deployment
60+
61+
* **🔡 Dataset:** [`opus_books`](https://huggingface.co/datasets/Helsinki-NLP/opus_books)
62+
63+
* English-Spanish parallel corpus
64+
* High-quality literary translation data
65+
66+
* **🏗️ Base Model:** [`Helsinki-NLP/opus-mt-en-es`](https://huggingface.co/Helsinki-NLP/opus-mt-en-es)
67+
68+
* Pretrained NMT model for English → Spanish
69+
70+
* **🧪 Tokenizer:**
71+
72+
* SentencePiece tokenizer (`AutoTokenizer`) from the base model
73+
74+
* **🧠 Fine-Tuning Strategy:**
75+
76+
* **PEFT (Parameter-Efficient Fine-Tuning)** using **LoRA (Low-Rank Adaptation)**
77+
* **Frozen base model** — only LoRA-injected layers are trainable
78+
79+
* **🧬 LoRA Configuration:**
80+
81+
* `r = 8`, `alpha = 32`, `dropout = 0.1`
82+
* Target Modules: `["q_proj", "v_proj"]` (attention heads)
83+
84+
* **⚙️ Trainer Configuration:**
85+
86+
* Epochs: `3`
87+
* Batch Size: `16`
88+
* Learning Rate: `2e-5`
89+
* Weight Decay: `0.01`
90+
* Evaluation: Per Epoch
91+
* Early Stopping: Enabled
92+
* Mixed Precision: Enabled (`fp16`)
93+
94+
* **📊 Evaluation Metric:**
95+
96+
* BLEU Score using Hugging Face `evaluate` library
97+
98+
* **📉 Training Performance:**
99+
100+
| Epoch | Training Loss | Validation Loss | BLEU Score |
101+
| ----- | ------------- | --------------- | ---------- |
102+
| 1 | 1.3853 | 1.3317 | 0.1164 |
103+
| 2 | 1.3521 | 1.2777 | 0.1136 |
104+
| 3 | 1.3885 | 1.2645 | 0.1128 |
105+
106+
* **💾 Saving Checkpoints:**
107+
108+
* Tokenizer: `tokenizer.save_pretrained("saved_tokenizer")`
109+
* LoRA Adapter: `peft_model.save_pretrained("saved_peft_model")`
110+
111+
* **📦 Trainable Parameters:**
112+
113+
* Only \~0.38% of parameters were updated
114+
* Verified using: `peft_model.print_trainable_parameters()`
55115

56116
---
57117

58-
## 🧱 Modular Codebase
118+
## 📊 Model Performance
119+
120+
| Epoch | Training Loss | Validation Loss | BLEU Score |
121+
|-------|---------------|-----------------|------------|
122+
| 1 | 1.3853 | 1.3317 | 0.1164 |
123+
| 2 | 1.3521 | 1.2777 | 0.1136 |
124+
| 3 | 1.3885 | 1.2645 | 0.1128 |
125+
126+
📌 **Observations**:
127+
- Training and validation loss gradually decreased.
128+
- BLEU score stabilized over epochs, indicating early convergence.
129+
- Indicates the model is learning but BLEU can be improved further with more epochs or tuning.
130+
131+
---
132+
133+
## 🧱 Project File Structure
59134
```
60135
Bilingual-Bridge/
61136
62-
├── .github/ # GitHub specific files
137+
├── .github/
63138
│ └── workflows/
64-
│ └── main.yml # GitHub Actions CI/CD workflow file
139+
│ └── main.yml
65140
66-
├── fine-tuned-model/
67-
│ └── fine-tuned-model/
68-
│ └── fine-tuned-tokenizer/
141+
├── fine-tuned-model/
142+
│ ├── adapter_config.json
143+
│ ├── adapter_model.safetensors
144+
│ └── README.md
69145
70-
├── tests/
71-
│ └── data.py
146+
├── fine-tuned-tokenizer/
147+
│ ├── source.spm
148+
│ ├── special_tokens_map.json
149+
│ ├── target.spm
150+
│ ├── tokenizer_config.json
151+
│ └── vocab.json
72152
73-
├── src/
74-
│ └── data.py
75-
│ └── logger.py
153+
├── logs/
154+
155+
├── notebook/
156+
│ └── Experiment.ipynb
157+
158+
├── src/
159+
│ ├── data.py
160+
│ ├── logger.py
76161
│ └── model.py
77162
78-
├── app.py
79-
├── train.py
163+
├── static/
164+
│ ├── css/
165+
│ │ └── style.css
166+
│ └── js/
167+
│ └── script.js
168+
169+
├── templates/
170+
│ └── index.html
171+
172+
├── tests/
173+
174+
├── .gitignore
175+
├── app.png
176+
├── demo.mp4
177+
├── Dockerfile
178+
├── LICENSE
179+
├── README.md
180+
├── requirements.txt
80181
├── setup.py
81-
├── logs/ # Training and app logs
82-
├── app.png # Utility functions
83-
├── LICENSE
84-
├── Dockerfile # For containerization
85-
├── requirements.txt # Dependencies
86-
└── README.md # Project summary
182+
└── train.py
87183
```
88184

89185
---
@@ -92,18 +188,18 @@ Bilingual-Bridge/
92188
```mermaid
93189
sequenceDiagram
94190
participant User
95-
participant StreamlitUI
96-
participant TranslationApp
97-
participant HuggingFace
98-
99-
User->>StreamlitUI: Enters English text
100-
StreamlitUI->>TranslationApp: translate(input_text)
101-
TranslationApp->>HuggingFace: Tokenize input
102-
HuggingFace-->>TranslationApp: Tokenized output
103-
TranslationApp->>HuggingFace: Generate Spanish tokens
104-
HuggingFace-->>TranslationApp: Translated tokens
105-
TranslationApp-->>StreamlitUI: Spanish text
106-
StreamlitUI->>User: Displays translation
191+
participant WebUI as Web UI (Flask + HTML/CSS)
192+
participant TranslationServer as Translation App (Python)
193+
participant HFModel as Hugging Face Model
194+
195+
User->>WebUI: Enter English text
196+
WebUI->>TranslationServer: translate(input_text)
197+
TranslationServer->>HFModel: Tokenize input
198+
HFModel-->>TranslationServer: Return tokenized input
199+
TranslationServer->>HFModel: Generate translation tokens
200+
HFModel-->>TranslationServer: Return translated tokens
201+
TranslationServer-->>WebUI: Return Spanish text
202+
WebUI->>User: Display translated output
107203
```
108204

109205
---
@@ -114,32 +210,13 @@ FROM python:3.10
114210
WORKDIR /app
115211
COPY . .
116212
RUN pip install -r requirements.txt
117-
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
213+
CMD ["python", "app.py"]
118214
```
119215

120216
Build & run:
121217
```bash
122-
docker build -t bilingual-bridge .
123-
docker run -p 8501:8501 bilingual-bridge
124-
```
125-
126-
---
127-
128-
## 🖥️ Web App
129-
Features:
130-
- Input box for English text
131-
- Button-triggered translation
132-
- Spanish output display
133-
- Logs activity in real-time
134-
135-
Example:
136-
```python
137-
translated_tokens = model.generate(
138-
inputs['input_ids'],
139-
max_length=256,
140-
num_beams=8,
141-
early_stopping=False
142-
)
218+
docker build -t translatica .
219+
docker run -p 8501:8501 translatica
143220
```
144221

145222
---
@@ -168,4 +245,4 @@ streamlit run app.py
168245
🔗 **LinkedIn:** [Md Emon Hasan](https://www.linkedin.com/in/md-emon-hasan-695483237/)
169246
🔗 **Facebook:** [Md Emon Hasan](https://www.facebook.com/mdemon.hasan2001/)
170247

171-
---
248+
---

app.png

262 KB
Loading

0 commit comments

Comments
 (0)