Lingoflop is a machine translation model based on the original Transformer (Encoder-Decoder), implemented with PyTorch.
For more details, see the paper Attention Is All You Need.
- A machine translation model based on the original Transformer (Encoder-Decoder), implemented with PyTorch.
- A standard Encoder-Decoder Transformer built from scratch.
- A WordLevel tokenizer trained with the
tokenizerslibrary. - The
opus_booksdataset loaded through Hugging Facedatasets. - Support for training, validation, model checkpoint saving, and resuming training.
- TensorBoard logging for monitoring the training process.
Python 3.10 or later is recommended.
Set up the environment:
conda create -n lingoflop python=3.10
conda activate lingoflop
pip install -r requirements.txtStart training from the project directory:
python train.pyThe model can be trained on a single NVIDIA RTX 4090 with 24 GB of VRAM. The default training settings are:
batch_size = 8num_epochs = 20lr = 1e-4seq_len = 350d_model = 512lang_src = "en"lang_tgt = "fr"
To resume training from a checkpoint, update config.py:
preload = None: train from scratch.preload = "xx": loadweights/tmodel_xx.ptand continue training.
Model weights are saved in the weights/ directory. TensorBoard logs are saved in runs/tmodel.
If TensorBoard is not installed, run:
pip install tensorboardLaunch TensorBoard with:
tensorboard --logdir=runsThen open the following address in your browser:
http://localhost:6006
The current implementation includes:
- Encoder self-attention
- Decoder masked self-attention
- Cross-attention
- Feed-forward layers with residual connections and layer normalization
The validation stage uses greedy decoding to generate example translations.
The project uses English-to-French translation as the default example. The opus_books dataset supports additional language pairs; to use a different target language, update lang_tgt in config.py.
PS: To be honest, maintaining a codebase written entirely by hand is not a light task in today's agentic era.