Views
No views yet
1import torch
2from transformers import AutoProcessor, AutoModelForCTC
3filename = "demo.wav" #change this line to the name of your audio file
4sample_rate = 16_000
5processor = AutoProcessor.from_pretrained('ITG/wav2vec2-large-xlsr-gl')
6model = AutoModelForSpeechSeq2Seq.from_pretrained('ITG/wav2vec2-large-xlsr-gl')
7device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
8model.to(device)
9speech_array, _ = librosa.load(filename, sr=sample_rate)
10inputs = processor(speech_array, sampling_rate=sample_rate, return_tensors="pt", padding=True).to(device)
11with torch.no_grad():
12 logits = model(inputs.input_values, attention_mask=inputs.attention_mask.to(device)).logits
13decode_output = processor.batch_decode(torch.argmax(logits, dim=-1))[0]
14print(f"ASR Galician wav2vec2-large-xlsr output: {decode_output}")| Hyper-parameter | Value |
|---|---|
| Training batch size | 16 |
| Evaluation batch size | 8 |
| Learning rate | 3e-4 |
| Gradient accumulation steps | 2 |
| Group by length | true |
| Evaluation strategy | steps |
| Max training epochs | 50 |
| Max steps | 4000 |
| Generate max length | 225 |
| FP16 | true |
| Metric for best model | wer |
| Greater is better | false |