Update README.md
Browse files
README.md
CHANGED
@@ -29,7 +29,7 @@ language:
|
|
29 |
- da
|
30 |
- hu
|
31 |
- ta
|
32 |
-
-
|
33 |
- th
|
34 |
- ur
|
35 |
- hr
|
@@ -110,65 +110,64 @@ pipeline_tag: automatic-speech-recognition
|
|
110 |
|
111 |
# Den4ikAI/whisper-large-v2-no-digits-norm-punct
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
##
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
|
122 |
-
|
|
123 |
-
| `openai/whisper-large-v2` (
|
124 |
-
| `Den4ikAI/whisper-large-v2-no-digits-norm-punct` (
|
125 |
|
126 |
-
|
127 |
|
128 |
-
##
|
129 |
|
130 |
-
|
131 |
|
132 |
```python
|
133 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
134 |
import torchaudio
|
135 |
import torch
|
136 |
|
137 |
-
#
|
138 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
139 |
|
140 |
-
|
141 |
wav, sr = torchaudio.load("numbers5.mp3")
|
142 |
-
#
|
143 |
if wav.shape[0] > 1:
|
144 |
wav = torch.mean(wav, dim=0, keepdim=True)
|
145 |
resampler = torchaudio.transforms.Resample(sr, 16000)
|
146 |
wav = resampler(wav)
|
147 |
audio_input = wav.squeeze(0)
|
148 |
|
149 |
-
#
|
150 |
model_id = "Den4ikAI/whisper-large-v2-no-digits-norm-punct"
|
151 |
processor = WhisperProcessor.from_pretrained(model_id)
|
152 |
model = WhisperForConditionalGeneration.from_pretrained(model_id).to(device)
|
153 |
|
154 |
-
#
|
155 |
input_features = processor(
|
156 |
-
audio_input,
|
157 |
-
sampling_rate=16000,
|
158 |
return_tensors="pt"
|
159 |
).input_features.to(device)
|
160 |
|
161 |
-
#
|
162 |
-
# Для русского языка указываем language="russian"
|
163 |
predicted_ids = model.generate(input_features, language="russian", task="transcribe")
|
164 |
|
165 |
-
#
|
166 |
transcription = processor.batch_decode(
|
167 |
-
predicted_ids,
|
168 |
-
skip_special_tokens=False
|
169 |
)
|
170 |
|
171 |
print(transcription)
|
172 |
|
173 |
-
#
|
174 |
# ['<|startoftranscript|><|ru|><|transcribe|><|notimestamps|> Билет стоил двадцать тысяч рублей.<|endoftext|>']
|
|
|
29 |
- da
|
30 |
- hu
|
31 |
- ta
|
32 |
+
- no
|
33 |
- th
|
34 |
- ur
|
35 |
- hr
|
|
|
110 |
|
111 |
# Den4ikAI/whisper-large-v2-no-digits-norm-punct
|
112 |
|
113 |
+
This is a special version of the `openai/whisper-large-v2` model whose vocabulary has had all tokens corresponding to digits removed, as well as tokens with extraneous punctuation.
|
114 |
|
115 |
+
The primary goal of this modification is to **force the model to generate numbers as words rather than digits**. This is extremely useful for text normalization tasks, for example when preparing data for text-to-speech (TTS) systems, where numbers need to be fully spelled out.
|
116 |
|
117 |
+
## Comparison with the Original Model
|
118 |
|
119 |
+
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”).
|
120 |
|
121 |
+
| Model | Transcription Output |
|
122 |
+
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
123 |
+
| `openai/whisper-large-v2` (Original) | `<\|startoftranscript\|><\|ru\|><\|transcribe\|><\|notimestamps\|> Билет стоил **20000** рублей.<\|endoftext\|>` |
|
124 |
+
| `Den4ikAI/whisper-large-v2-no-digits-norm-punct` (This model) | `<\|startoftranscript\|><\|ru\|><\|transcribe\|><\|notimestamps\|> Билет стоил **двадцать тысяч** рублей.<\|endoftext\|>` |
|
125 |
|
126 |
+
As you can see, this modified model correctly normalized the number into words, whereas the original version left it as digits.
|
127 |
|
128 |
+
## How to Use
|
129 |
|
130 |
+
You can use this model just like any other Whisper model in the `transformers` library.
|
131 |
|
132 |
```python
|
133 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
134 |
import torchaudio
|
135 |
import torch
|
136 |
|
137 |
+
# Specify the device (GPU if available)
|
138 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
139 |
|
140 |
+
# Load the audio file
|
141 |
wav, sr = torchaudio.load("numbers5.mp3")
|
142 |
+
# Convert to mono and resample to 16 kHz
|
143 |
if wav.shape[0] > 1:
|
144 |
wav = torch.mean(wav, dim=0, keepdim=True)
|
145 |
resampler = torchaudio.transforms.Resample(sr, 16000)
|
146 |
wav = resampler(wav)
|
147 |
audio_input = wav.squeeze(0)
|
148 |
|
149 |
+
# Load the processor and model
|
150 |
model_id = "Den4ikAI/whisper-large-v2-no-digits-norm-punct"
|
151 |
processor = WhisperProcessor.from_pretrained(model_id)
|
152 |
model = WhisperForConditionalGeneration.from_pretrained(model_id).to(device)
|
153 |
|
154 |
+
# Prepare inputs and extract features
|
155 |
input_features = processor(
|
156 |
+
audio_input,
|
157 |
+
sampling_rate=16000,
|
158 |
return_tensors="pt"
|
159 |
).input_features.to(device)
|
160 |
|
161 |
+
# Generate token IDs (for Russian specify language="russian")
|
|
|
162 |
predicted_ids = model.generate(input_features, language="russian", task="transcribe")
|
163 |
|
164 |
+
# Decode tokens back to text
|
165 |
transcription = processor.batch_decode(
|
166 |
+
predicted_ids,
|
167 |
+
skip_special_tokens=False
|
168 |
)
|
169 |
|
170 |
print(transcription)
|
171 |
|
172 |
+
# Example output for an audio clip with numbers:
|
173 |
# ['<|startoftranscript|><|ru|><|transcribe|><|notimestamps|> Билет стоил двадцать тысяч рублей.<|endoftext|>']
|