facebook/wav2vec2-base-960h with a CTC head on 50k subsample of Common Voice 17.0 (English) and provides scripts to train, evaluate, export to ONNX, and deploy on AWS SageMaker. It also includes a robust audio loading stack (FFmpeg preferred, with fallbacks) and utilities for text normalization and evaluation (WER/CER).@amirhossein-yousefi)en)facebook/wav2vec2-base-960hThe training/evaluation pipeline uses Hugging Facetransformers,datasets, andjiwerand includes scripts for inference and SageMaker deployment.
1import torch, torchaudio
2from transformers import AutoModelForCTC, AutoProcessor
3
4model_dir = "./outputs/asr" # or a Hugging Face hub id
5device = "cuda" if torch.cuda.is_available() else "cpu"
6
7processor = AutoProcessor.from_pretrained(model_dir)
8model = AutoModelForCTC.from_pretrained(model_dir).to(device).eval()
9
10wav, sr = torchaudio.load("path/to/file.wav")
11target_sr = processor.feature_extractor.sampling_rate
12if sr != target_sr:
13 wav = torchaudio.functional.resample(wav, sr, target_sr)
14
15inputs = processor(wav.squeeze(0).numpy(), sampling_rate=target_sr, return_tensors="pt", padding=True)
16with torch.no_grad():
17 logits = model(**{k: v.to(device) for k, v in inputs.items()}).logits
18pred_ids = torch.argmax(logits, dim=-1)
19print(processor.batch_decode(pred_ids.cpu().numpy())[0])python src/infer.py --model_dir ./outputs/asr --audio path/to/file.wavsentencetorchaudio/soundfile/librosa), resampling to 16 kHz as required by Wav2Vec2.adamw_torch_fusedsrc/output/logs (or similar path as configured)jiwer utilities.assets/ directory for plots.ml.g4dn.xlarge).transformers, datasets, torch, torchaudio, soundfile, librosa, jiwer, onnxruntime (for ONNX testing), and boto3/sagemaker for deployment.1@article{baevski2020wav2vec,
2 title={wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations},
3 author={Baevski, Alexei and Zhou, Henry and Mohamed, Abdelrahman and Auli, Michael},
4 journal={arXiv preprint arXiv:2006.11477},
5 year={2020}
6}src/export_onnx.pysagemaker/ for training, deployment, and autoscaling.assets/ (e.g., train_loss.svg, eval_wer.svg, eval_cer.svg).