Skip to content

Tutorials

Welcome to the TorchLingo tutorials! These interactive Jupyter notebooks will guide you through building a complete neural machine translation system.

The easiest way to run these tutorials is in Google Colab—no installation required!

Tutorial Description Open in Colab
1. Data and Vocabulary Load data, build vocabularies Open In Colab
2. Train a Tiny Model Build and train a Transformer Open In Colab
3. Inference and Beam Search Generate translations Open In Colab

Enable GPU in Colab

For faster training, enable GPU: Runtime → Change runtime type → GPU

Colab provides free access to NVIDIA GPUs!

Learning Path

Follow these tutorials in order for the best learning experience:

  • Data and Vocabulary


    Learn how to load parallel data, build vocabularies, and prepare your data for training.

    Start Tutorial

  • Train a Tiny Model


    Build and train your first Transformer model on a small dataset—runs in seconds!

    Start Tutorial

  • Inference and Beam Search


    Generate translations using greedy and beam search decoding strategies.

    Start Tutorial

Prerequisites

For Google Colab (Recommended):

  • A Google account
  • Basic Python knowledge

For Local Setup:

Running the Tutorials

  1. Click any "Open in Colab" badge above
  2. Go to Runtime → Change runtime type → GPU
  3. Run the first cell to install TorchLingo: %pip install torchlingo

Option 2: Run Locally

# Navigate to the tutorials directory
cd docs/tutorials

# Start Jupyter
jupyter notebook

Option 3: Read Online

You can read the tutorials directly in the documentation—the code cells and outputs are rendered for you.

Tutorial Overview

Tutorial 1: Data and Vocabulary

Time: ~15 minutes

You'll learn:

  • Loading TSV, CSV, and other data formats
  • Building source and target vocabularies
  • Encoding and decoding text
  • Creating PyTorch datasets

Key classes covered: load_data(), SimpleVocab, NMTDataset

Tutorial 2: Train a Tiny Model

Time: ~20 minutes

You'll learn:

  • Creating a Transformer model
  • Setting up the training loop
  • Teacher forcing explained
  • Monitoring training progress
  • Saving and loading checkpoints

Key classes covered: SimpleTransformer, Config, collate_fn

Time: ~15 minutes

You'll learn:

  • Greedy decoding
  • Beam search decoding
  • Comparing decoding strategies
  • Evaluating with BLEU score

Key concepts: Inference modes, decoding algorithms, evaluation metrics

Tips for Success

Run Every Cell

Execute cells in order—many depend on previous outputs.

Experiment!

Try changing hyperparameters, model sizes, and data. Breaking things is how you learn.

Check Tensor Shapes

When debugging, print tensor shapes liberally:

print(f"src shape: {src.shape}")

What's Next?

After completing the tutorials:

  • đź“– Dive deeper into Concepts
  • 🔍 Explore the API Reference
  • 🚀 Try your own dataset

Ready to begin?

Start Tutorial 1