Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- openslr/librispeech_asr
|
| 4 |
+
- ghananlpcommunity/twi-speech-text-multispeaker-16k
|
| 5 |
+
- ghananlpcommunity/twi-english-paragraph-dataset_news
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# MMT-JEPA
|
| 9 |
+
|
| 10 |
+
A multimodal machine translation model for English ↔ Twi using a JEPA (Joint Embedding Predictive Architecture) objective.
|
| 11 |
+
|
| 12 |
+
## What it does
|
| 13 |
+
|
| 14 |
+
Learns a shared latent space across text and audio in both languages by training a predictor to anticipate target representations from context — no reconstruction loss, no cascaded pipeline.
|
| 15 |
+
|
| 16 |
+
Three training objectives:
|
| 17 |
+
- **A** — Audio → Text (both languages)
|
| 18 |
+
- **B** — Text → Text (translation)
|
| 19 |
+
- **C** — Text → Audio (both languages)
|
| 20 |
+
|
| 21 |
+
## Files
|
| 22 |
+
|
| 23 |
+
| File | Purpose |
|
| 24 |
+
|---|---|
|
| 25 |
+
| `model.py` | `MMT_JEPA` model + EMA target encoder |
|
| 26 |
+
| `dataset.py` | `ObjA`, `ObjB`, `ObjC` dataset classes |
|
| 27 |
+
| `tokenizer.py` | Trains a joint BPE tokenizer on all text data |
|
| 28 |
+
| `train.py` | Training loop (all objectives) |
|
| 29 |
+
| `train_b.py` | Training loop (Objective B only) |
|
| 30 |
+
|
| 31 |
+
## Setup
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
pip install torch librosa soundfile sentencepiece datasets
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
**1. Train the tokenizer**
|
| 40 |
+
```bash
|
| 41 |
+
python tokenizer.py
|
| 42 |
+
# outputs: tokenizer.model, tokenizer.vocab
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
**2. Train the model**
|
| 46 |
+
```bash
|
| 47 |
+
python train.py
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
Checkpoints saved to `checkpoints/epoch{N}.pt` after each epoch.
|
| 51 |
+
|
| 52 |
+
## Data
|
| 53 |
+
|
| 54 |
+
| Objective | Dataset |
|
| 55 |
+
|---|---|
|
| 56 |
+
| A + C (English audio) | [LibriSpeech train-clean-100](https://huggingface.co/datasets/openslr/librispeech_asr) |
|
| 57 |
+
| A + C (Twi audio) | [twi-speech-text-multispeaker-16k](https://huggingface.co/datasets/ghananlpcommunity/twi-speech-text-multispeaker-16k) |
|
| 58 |
+
| B (translation) | [twi-english-paragraph-dataset_news](https://huggingface.co/datasets/ghananlpcommunity/twi-english-paragraph-dataset_news) · [english-twi-sentences-non-nouns](https://huggingface.co/datasets/ghananlpcommunity/english-twi-sentences-non-nouns) · [english-twi-nouns-v2](https://huggingface.co/datasets/ghananlpcommunity/english-twi-nouns-v2) |
|
| 59 |
+
|
| 60 |
+
All datasets load automatically via HuggingFace on first run.
|
| 61 |
+
|
| 62 |
+
## Model config
|
| 63 |
+
|
| 64 |
+
Edit `ModelConfig` in `model.py` to change capacity:
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
d_model = 512 # embedding dimension
|
| 68 |
+
trunk_layers = 6 # shared transformer depth
|
| 69 |
+
vocab_size = 16_000
|
| 70 |
+
n_mels = 80
|
| 71 |
+
sample_rate = 16_000
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## Training notes
|
| 75 |
+
|
| 76 |
+
- First 5 epochs run text-only (ObjB) to warm up representations before audio is introduced
|
| 77 |
+
- L2 normalization applied to both sides before MSE loss to keep scale stable across modalities
|
| 78 |
+
- EMA target encoder uses cosine-annealed decay (0.990 → 0.996)
|
| 79 |
+
- Collapse logged as `COLLAPSE` when `std < 0.01` or `cos_sim > 0.99`
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Get code on github [MMT-JEPA](https://github.com/etornam45/mmt-jepa)
|