Loading…
Fine-Tune Wav2Vec2 for English ASR in Hugging Face with 🤗 Transformers
Patrick von Platen
Summary
Wav2Vec2 is a pretrained Automatic Speech Recognition model that learns speech representations from over 50,000 hours of unlabeled audio using a contrastive objective and masked feature vectors. The model can be fine-tuned end-to-end on labeled speech datasets using Connectionist Temporal Classification without requiring an external language model. To demonstrate this process, a base-sized checkpoint is fine-tuned on the Timit dataset, which contains five hours of training data. Data preparation involves normalizing transcriptions to lowercase, removing special punctuation characters, and configuring both a specialized feature extractor and tokenizer. Evaluating the fine-tuned acoustic model without padding on the Timit test dataset yields a word error rate of 22.1%.
Context
Pretrained on more than 50,000 hours of unlabeled speech, Wav2Vec2 can achieve competitive speech recognition performance with very little labeled data. However, practitioners need a streamlined method to fine-tune pretrained checkpoints on custom English speech datasets as standalone end-to-end acoustic models.
Approach / What changed
A base-sized Wav2Vec2 checkpoint is fine-tuned on five hours of Timit speech data using Connectionist Temporal Classification (CTC) without an auxiliary language model. Transcriptions are cleaned by stripping special punctuation and converting text to lowercase to build a character vocabulary. A linear classification layer is placed on top of the transformer representations, and inference is run with a batch size of one to prevent padding artifacts from degrading the word error rate.
Takeaways
- Wav2Vec2 pretrained checkpoints can be fine-tuned directly for speech-to-text tasks via Connectionist Temporal Classification (CTC) without relying on a language model.
- Punctuation marks are removed during text preprocessing because characters like periods lack distinct acoustic signatures, which makes classification without a language model difficult.
- Evaluating test audio with a batch size of one avoids input padding, which yields a better word error rate because padded inputs alter output representations.
Related reading
huggingface.co ·
Fine-Tune XLSR-Wav2Vec2 for low-resource ASR with 🤗 Transformers
Fine-tuning the multilingual XLS-R speech model adapts pretrained cross-lingual audio representations to automatic speech recognition tasks with limited labeled data. The demonstration configures a Wav2Vec2-XLS-R-300M checkpoint using Connectionist Temporal Classification on roughly four hours of validated Turkish audio from Common Voice. Building the pipeline requires pairing a Wav2Vec2FeatureExtractor for audio signals with a custom Wav2Vec2CTCTokenizer derived from dataset transcriptions. Training with Hugging Face Trainer over 3,200 steps decreases the validation word error rate from 0.7000 down to 0.3195. While the resulting transcription demonstrates recognizable phonetic alignment, output quality can be further improved by extending training schedules, refining preprocessing, and adding language model decoding.
Patrick von Platenhuggingface.co ·
Boosting Wav2Vec2 with n-grams in 🤗 Transformers
Wav2Vec2 models fine-tuned with Connectionist Temporal Classification transcribe speech without external language models, but decoding can still suffer from spelling inaccuracies. Hugging Face Transformers addressed this by integrating Kensho Technologies' pyctcdecode library to support decoding with n-gram language models. Instead of decoding using simple argmax operations over logits, the Wav2Vec2ProcessorWithLM class feeds full probability matrices into beam search guided by KenLM n-gram probabilities. KenLM's build_binary utility compresses language model ARPA files into binary formats, reducing file size by more than half for faster loading and hub deployment. In Swedish xls-r-300m-sv benchmarks on Common Voice 7, this 5-gram boosted decoding setup achieved an 18.85% word error rate, delivering an approximate 30% relative performance gain.