This repository contains a FastAPI backend that serves a custom Transformer-based German to English (de→en) translation model Repo.
The model architecture is inspired by the attention mechanism and is defined in attention_model.py.
- API built with FastAPI
- Translation from German to English
- Uses a custom Transformer model with attention
- CORS-enabled (can be publicly accessed or restricted)
- Ready for deployment (Render, Docker, etc.)
- app.py # FastAPI app with /translate endpoint
- attention_model.py # Transformer model & decode_sequence function
- transformer_de_to_en_model.keras # Trained Keras model (In Git LFS)
- source_vocab.pkl # Source (German) vocabulary
- target_vocab.pkl # Target (English) vocabulary
- requirements.txt # Python dependencies
- README.md
- The API exposes a single POST endpoint at
/translate - It receives a German sentence and returns the English translation
POST /translate
Content-Type: application/json
{
"text": "ich bin klug"
}{
"translation": "i am smart"
}git clone https://github.com/your-username/attention-api.git
cd attention-apipip install -r requirements.txtModel file is large (
.keras,.pkl), make sure to use Git LFS:
git lfs install
git lfs pulluvicorn app:app --reload --port 8000it'll run on: http://localhost:8000
By default, the app allows all origins (*).
You can restrict this in app.py for production environments.
MIT License