Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Attention-API: German to English Transformer Translation

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.


Features

  • 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.)

Project Structure

- 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

How It Works

  • The API exposes a single POST endpoint at /translate
  • It receives a German sentence and returns the English translation

Example Request

POST /translate
Content-Type: application/json

{
  "text": "ich bin klug"
}

Example Response

{
  "translation": "i am smart"
}

Setup

1. Clone the repo

git clone https://github.com/your-username/attention-api.git
cd attention-api

2. Install dependencies

pip install -r requirements.txt

Model file is large (.keras, .pkl), make sure to use Git LFS:

git lfs install
git lfs pull

3. Run the FastAPI server

uvicorn app:app --reload --port 8000

it'll run on: http://localhost:8000


CORS Policy

By default, the app allows all origins (*).
You can restrict this in app.py for production environments.


License

MIT License

About

backend for the attention model using FastAPI

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages