Here’s a clear example demonstrating the difference in behavior between the models when transcribing the same audio clip containing the phrase “Билет стоил двадцать тысяч рублей” (“The ticket cost twenty thousand rubles”).
As you can see, this modified model correctly normalized the number into words, whereas the original version left it as digits.
1from transformers import WhisperProcessor, WhisperForConditionalGeneration
2import torchaudio
3import torch
4
5# Specify the device (GPU if available)
6device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
8# Load the audio file
9wav, sr = torchaudio.load("numbers5.mp3")
10# Convert to mono and resample to 16 kHz
11if wav.shape[0] > 1:
12 wav = torch.mean(wav, dim=0, keepdim=True)
13resampler = torchaudio.transforms.Resample(sr, 16000)
14wav = resampler(wav)
15audio_input = wav.squeeze(0)
16
17# Load the processor and model
18model_id = "Den4ikAI/whisper-large-v2-no-digits-norm-punct"
19processor = WhisperProcessor.from_pretrained(model_id)
20model = WhisperForConditionalGeneration.from_pretrained(model_id).to(device)
21
22# Prepare inputs and extract features
23input_features = processor(
24 audio_input,
25 sampling_rate=16000,
26 return_tensors="pt"
27).input_features.to(device)
28
29# Generate token IDs (for Russian specify language="russian")
30predicted_ids = model.generate(input_features, language="russian", task="transcribe")
31
32# Decode tokens back to text
33transcription = processor.batch_decode(
34 predicted_ids,
35 skip_special_tokens=False
36)
37
38print(transcription)
39
40# Example output for an audio clip with numbers:
41# ['<|startoftranscript|><|ru|><|transcribe|><|notimestamps|> Билет стоил двадцать тысяч рублей.<|endoftext|>']