Skip to content

TorchLingo

TorchLingo Logo

A beginner-friendly PyTorch library for learning Neural Machine Translation

Python 3.10+ PyTorch License: AGPL-3.0

Getting Started View Tutorials


What is TorchLingo?

TorchLingo is a compact, educational library designed to teach you the fundamentals of Neural Machine Translation (NMT) using PyTorch. Whether you've never touched PyTorch before or you're looking to understand how Google Translate works under the hood, TorchLingo has you covered.

Perfect for Students

TorchLingo was built for university coursework. The code is intentionally simple, readable, and well-documentedβ€”no magic, no hidden complexity.

Run in Google Colab

The easiest way to get started is with Google Colabβ€”no installation required on your machine!

%pip install torchlingo

Colab provides free GPU access which speeds up training significantly. Just go to Runtime β†’ Change runtime type β†’ GPU.

✨ Features

  • Easy to Start


    Get your first translation model running in under 5 minutes with our quickstart guide.

    Quick Start

  • Learn by Doing


    Interactive Jupyter notebooks walk you through every concept step-by-step.

    Tutorials

  • Readable Code


    Every function is documented. Every tensor shape is explained. No black boxes.

    API Reference

  • Two Architectures


    Learn both classic LSTM and modern Transformer models side by side.

    Model Concepts

πŸš€ Quick Example

Here's a taste of what working with TorchLingo looks like:

from torchlingo.config import Config
from torchlingo.data_processing import NMTDataset, create_dataloaders
from torchlingo.models import SimpleTransformer

# 1. Create a configuration
config = Config(
    batch_size=32,
    learning_rate=1e-4,
    d_model=256,
)

# 2. Load your data
train_dataset = NMTDataset("data/train.tsv", config=config)

# 3. Create your model
model = SimpleTransformer(
    src_vocab_size=len(train_dataset.src_vocab),
    tgt_vocab_size=len(train_dataset.tgt_vocab),
    config=config,
)

# 4. Train and translate!
# (See our tutorials for the complete training loop)

πŸ—ΊοΈ Where to Go Next

If you want to... Go here
Install TorchLingo Installation Guide
Build your first model in 5 minutes Quick Start
Understand the theory behind NMT What is NMT?
Follow step-by-step notebooks Tutorials
Look up a specific function API Reference

πŸ“š Philosophy

TorchLingo follows a few key principles:

  1. Explicit is better than implicit β€” You can trace every tensor operation
  2. Notebooks are first-class β€” Every concept is executable
  3. Start simple, add complexity later β€” Basic tokenization β†’ SentencePiece β†’ Multilingual
  4. Docs that teach β€” Every docstring explains why, not just what

Read more about our design philosophy.


πŸ™ Acknowledgements

This project was initially developed by Josh Christensen as part of his undergraduate work at BYU.

"I hope that TorchLingo will be a valuable resource for students learning about neural machine translation, and that they will consider improving this project and the entire world with the knowledge they gain."
β€” Josh Christensen


Ready to translate?

Get Started