CoolFace
Modelpublic

njand/wav2vec2-xls-r-latin

sourceHugging Facemitupdated 2mo agoView on Hugging Face
0likes66downloads
Model Card

Wav2Vec2 XLS-R 300M - Latin ASR (Restored Classical Pronunciation)

Fine-tuned version of `facebook/wav2vec2-xls-r-300m` for Latin Automatic Speech Recognition (ASR), trained on reading passages from njand/llpsi-speech-dataset.


🛠️ Model Variants & Optimization

To facilitate production deployment on CPU-based infrastructure, this repository provides the model in three formats:

FormatPrecisionFile SizeRecommended Use Case
PyTorchFP321.26 GBTraining, fine-tuning, and research
ONNXFP321.26 GBCross-platform inference
ONNX QuantizedINT8355 MBProduction, Edge, & CPU Inference
Why Quantized? The INT8 version offers ~3x faster inference speed on standard CPUs compared to the original FP32 PyTorch weights while retaining near-identical transcription accuracy.

🚀 Quickstart

Option 1: Standard Inference (PyTorch)

python
from transformers import pipeline

transcriber = pipeline("automatic-speech-recognition", model="njand/wav2vec2-xls-r-latin")
result = transcriber("sample.wav")
print(result["text"])

Option 2: Optimized Inference (Optimum ONNX Runtime)

For CPU inference, I recommend using the INT8 quantized model. Install dependencies: pip install "optimum[onnxruntime]"

python
from optimum.onnxruntime import ORTModelForCTC
from transformers import AutoProcessor

# Load the quantized model
model = ORTModelForCTC.from_pretrained(
    "njand/wav2vec2-xls-r-latin", 
    file_name="model_quantized.onnx"
)
processor = AutoProcessor.from_pretrained("njand/wav2vec2-xls-r-latin")

# Inference pipeline
inputs = processor("sample.wav", return_tensors="pt")
outputs = model(**inputs)
# ... decode outputs

🔤 Orthography & Text Normalization

This model transcribes audio using the following orthographic conventions:

  • —Vowel Quantity: Macronizes long vowels (ā, ē, ī, ō, ū, ȳ).
  • —Consonantal vs. Vocalic Glides: Distinguishes consonantal j and v from vocalic i and u (e.g., ējiciō rather than eicio, vīvus rather than uiuus).
  • —Casing & Punctuation: Transcribes lowercase text with no punctuation.

📊 Cross-Validation Performance

Evaluated across 5-fold cross-validation on njand/llpsi-speech-dataset:

FoldStrict WERStrict CERNorm WERNorm CER
Fold 013.37%2.73%11.71%2.26%
Fold 113.10%2.77%11.40%2.28%
Fold 212.44%2.58%10.75%2.10%
Fold 313.06%2.74%11.43%2.27%
Fold 414.04%2.91%12.44%2.41%
Average (CV)13.20%2.74%11.54%2.27%
Note: Normalized WER/CER measure core word recognition (macrons stripped, j/v → i/u), while Strict WER/CER enforce exact macron placement and j/v orthography.

🧠 Language Model Decoding (KenLM + pyctcdecode)

To improve generalization beyond the limited training audio, I integrated a unigram language model (KenLM) using `pyctcdecode`. This decoder is not provided in this Hub, but you can view it in action at the Live Gradio Demo.

Lexicon & Model Construction

  • —Lexicon Source: Derived from the comprehensive, fully inflected, macronized wordlist in the Alatius Latin Macronizer.
  • —Enclitic Expansion: Every entry was programmatically augmented with common Latin enclitics (-que, -ve, -ne).
  • —Generalization: Latin's rich inflectional system means a limited audio training set struggles with unseen word forms. The unigram LM supplies a morphological prior, enabling the decoder to correctly recognize and macronize valid inflected forms and enclitic combinations even if they never appeared in the training audio.

Decoder hyperparameters were tuned per fold using Optuna.

Constrained Decoding CV Performance

Impact: Drops mean WER from 13.20% → 8.70% (a 34.12% relative error reduction across all 5 folds).
FoldBaseline WERLM Decoded WERRelative Improvement
Fold 013.37%8.54%-36.12%
Fold 113.10%8.87%-32.27%
Fold 212.44%8.14%-34.57%
Fold 313.06%9.06%-30.63%
Fold 414.04%8.88%-36.77%
Mean13.20%8.70%-34.12%

Note: Character Error Rate (CER) saw a parallel improvement from 2.75% → 2.08% (-24.30% relative reduction).

Recommended Hyperparameters

Global Optuna optimization across the full dataset yielded the following optimal decoding parameters:

json
{
  "alpha": 0.20108,
  "beta": -0.89233,
  "unk_score_offset": -93.31052,
  "beam_prune_logp": -104.90582,
  "beam_width": 64
}

⚡ Environmental Impact & Compute

  • —Hardware: NVIDIA L4 GPU (24GB VRAM) via Modal
  • —Total Training Time: 10.47 hours
  • —Estimated Carbon Emissions: 0.2872 kg CO2eq

⚠️ Limitations & Out-of-Scope Use

  • —Pronunciation Variances: Performance will drop on audio using Ecclesiastical / Italianate pronunciation (e.g., pronouncing c before e/i as /tʃ/ rather than /k/).
  • —Audio Conditions: Optimized for clear, single-speaker reading. Background noise or overlapping speakers will reduce accuracy significantly.