File size: 5,746 Bytes
02a8814 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | ---
license: cc-by-nc-4.0
language:
- cop
base_model: MahmoudAshraf/mms-300m-1130-forced-aligner
pipeline_tag: automatic-speech-recognition
tags:
- forced-alignment
- ctc
- wav2vec2
- coptic
- chant
- liturgy
---
# Coptic chant aligner (MMS-300m, fine-tuned on hand-timed hymns)
This model finds when each word of a Coptic hymn is sung. You give it a recording and the hymn's text, and it returns a start time for every word. It powers the sing-along lessons at **https://code-tomato.github.io/coptic-transcription/**, where each word lights up as it's sung. The code is at **https://github.com/Code-Tomato/coptic-transcription** (see `liturgy/`).
It's a fine-tuned copy of [MahmoudAshraf/mms-300m-1130-forced-aligner](https://huggingface.co/MahmoudAshraf/mms-300m-1130-forced-aligner), a wav2vec2 CTC model from Meta's MMS, trained on 1,130 languages. The vocabulary is unchanged: romanised letters `a`–`z` and `'`.
- **Coptic isn't one of MMS's languages.** The text goes in as English-letter transliteration in Greco-Bohairic pronunciation, the way the [tasbeha.org hymn library](https://tasbeha.org/hymn_library/) writes it (e.g. ⲧⲉⲛⲛⲁϩϯ → `tennahti`).
- **The base model struggles with long held notes.** In a 30–70 s melisma it hears a plain "aaa", so it loses track of which word is being sung. This copy was fine-tuned on hand-timed chant so it can follow words through melismas.
## Use it
**Use it mixed 50/50 with the base model**, not on its own: average the two models' frame probabilities, then run CTC forced alignment on the transliteration. On its own, the fine-tuned model is better on long held notes but worse elsewhere. The mix keeps most of the gain and loses nothing overall (see the results below).
```python
import numpy as np, torch
from transformers import Wav2Vec2ForCTC
base = Wav2Vec2ForCTC.from_pretrained("MahmoudAshraf/mms-300m-1130-forced-aligner").eval()
chant = Wav2Vec2ForCTC.from_pretrained("codetomato/coptic-chant-aligner").eval()
def log_probs(model, wav16k): # wav16k: float32 mono at 16 kHz, normalised to zero mean / unit variance
with torch.no_grad():
return model(torch.from_numpy(wav16k)[None].to(model.dtype)).logits[0].float().log_softmax(-1).numpy()
em = np.logaddexp(np.log(0.5) + log_probs(chant, wav), np.log(0.5) + log_probs(base, wav)) # (frames, 31), 20 ms/frame
# then run CTC Viterbi forced alignment of the transliterated text over `em`
```
For long recordings, run 30 s windows with 4 s of context on each side.
The repo's `liturgy/scripts/make_lesson.py` does the whole job. It downloads from YouTube, mixes the two models and aligns the text. The alignment also skips audio that isn't in the text, skips lines that aren't sung, and lets a vowel be held across pauses:
```bash
python liturgy/scripts/make_lesson.py --text 32 --audio youtube:3eFEgD7Jg-w --ft-model path/to/coptic-chant-aligner
```
## Training
- **Data:** tasbeha.org's hand-timed "lessons", split by hymn so test hymns are never heard in training.
- Train: 53 recordings, 108 minutes of timed chant.
- Validation: 6 recordings.
- Test: 16 recordings of 13 hymns. These always include the hardest drawn-out hymns: Apekran, Sotees Amen, Shere Maria, Tai Shori and Yes Pateer (Great).
- **Training segments:** runs of words cut at tasbeha's word starts, up to 25 s each. A single held word can be up to 60 s. The CTC target is the words' letters. Spans without letters, such as where a patriarch's name is sung, are left out.
- **Recipe:**
- The CNN feature encoder and the lower 12 transformer layers are frozen.
- Learning rate 3e-5 with 100 warmup steps and cosine decay, 1,500 steps.
- Batches of 120 s of audio, bf16, SpecAugment time masking at p=0.05.
- The checkpoint was chosen by validation alignment accuracy, at step 300.
- One RTX 3090, about 15 minutes.
- `train_log.json` has the full validation curve.
## Results
The test set is the 13 held-out hymns. The score is the share of words whose predicted start is within 0.5 s of tasbeha's hand-checked start. All rows use the same alignment settings: the whole text, near-free skipping of audio between lines, skipping lines that aren't sung, and held vowels.
| | All test words (428) | After a note held ≥ 8 s (63) | Apekran | Tai Shori | Shere Maria | Yes Pateer |
|---|---|---|---|---|---|---|
| base model | 77.3 | 50.8 | 58 | 81 | 78 | 78 |
| this model alone | 76.2 | 60.3 | 68 | 88 | 96 | 73 |
| **50/50 mix (recommended)** | **77.6** | **55.6** | 65 | 88 | 83 | 74 |
These test hymns are hard by design. Across all 75 timed recordings, the base model with the same settings already gets 93% of words within 0.5 s.
## Limitations
- **Small training set.** 108 minutes of chant from mostly one source of recordings, the Higher Institute of Coptic Studies lessons on tasbeha.org. The test set is small too, so differences of a few points are a few words.
- **Very long holds are still hard.** In Sotees Amen, one word is held for 74 s, and the start of Apekran is still placed about 19 s late.
- **It only matches text you give it.** It aligns the known text and doesn't recognise free Coptic speech. Audio that isn't in the text, such as a different patriarch's name or a spoken Arabic introduction, has to be skipped by the aligner.
- **Non-commercial license.** Like the base model, it is CC-BY-NC 4.0.
## Credits
- **Base model:** MMS (Pratap et al., *Scaling Speech Technology to 1,000+ Languages*, 2023), via [MahmoudAshraf/mms-300m-1130-forced-aligner](https://huggingface.co/MahmoudAshraf/mms-300m-1130-forced-aligner).
- **Training timings, recordings and transliterations:** [tasbeha.org](https://tasbeha.org/hymn_library/). The recordings themselves aren't included here.
|