harvardnlp/var-attn
Latent Alignment and Variational Attention
What it solves
Typical neural machine translation uses deterministic attention weights to align source and target words. This project instead treats the alignment as a hidden (latent) variable and learns an approximate posterior distribution over possible alignments. By doing so, it aims to better capture the uncertainty in how source words map to target words, which can improve translation quality and model interpretability.
How it works
The code is built on a fork of OpenNMT-py. It includes a preprocessing step that applies Byte Pair Encoding (BPE) to the raw German–English dataset. Training supports several attention variants: soft attention (the standard baseline), categorical attention with exact marginalization, and three variational approaches that approximate the posterior over alignments — exact ELBO enumeration, REINFORCE sampling, and Gumbel-Softmax. A separate Wake-Sleep algorithm is also included. After training, evaluation scripts compute the exact perplexity of the generative model and produce translations of test data, which can be scored with BLEU.
Who it’s for
This project is aimed at researchers and practitioners working on probabilistic sequence-to-sequence models, especially those interested in attention mechanisms, latent variable models, and reproducible experiments in neural machine translation.
Highlights
- Implements the NeurIPS 2018 paper "Latent Alignment and Variational Attention"
- Provides multiple training methods for categorical attention (exact enumeration, REINFORCE, Gumbel-Softmax, Wake-Sleep)
- All commands are wrapped in a single script
va.shfor easy reproduction - Includes trained model checkpoints and reports test perplexity and BLEU scores showing improvements over soft attention
Related
- Project
- Project
- Project
- Project