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mit
3
+ language: fr
4
+ library_name: transformers
5
+ pipeline_tag: automatic-speech-recognition
6
+ thumbnail: null
7
+ tags:
8
+ - automatic-speech-recognition
9
+ - hf-asr-leaderboard
10
+ datasets:
11
+ - mozilla-foundation/common_voice_13_0
12
+ - facebook/multilingual_librispeech
13
+ - facebook/voxpopuli
14
+ - google/fleurs
15
+ - gigant/african_accented_french
16
+ metrics:
17
+ - wer
18
+ model-index:
19
+ - name: whisper-large-v3-french-distil-dec8
20
+ results:
21
+ - task:
22
+ name: Automatic Speech Recognition
23
+ type: automatic-speech-recognition
24
+ dataset:
25
+ name: Common Voice 13.0
26
+ type: mozilla-foundation/common_voice_13_0
27
+ config: fr
28
+ split: test
29
+ args:
30
+ language: fr
31
+ metrics:
32
+ - name: WER
33
+ type: wer
34
+ value: 7.62
35
+ - task:
36
+ name: Automatic Speech Recognition
37
+ type: automatic-speech-recognition
38
+ dataset:
39
+ name: Multilingual LibriSpeech (MLS)
40
+ type: facebook/multilingual_librispeech
41
+ config: french
42
+ split: test
43
+ args:
44
+ language: fr
45
+ metrics:
46
+ - name: WER
47
+ type: wer
48
+ value: 3.80
49
+ - task:
50
+ name: Automatic Speech Recognition
51
+ type: automatic-speech-recognition
52
+ dataset:
53
+ name: VoxPopuli
54
+ type: facebook/voxpopuli
55
+ config: fr
56
+ split: test
57
+ args:
58
+ language: fr
59
+ metrics:
60
+ - name: WER
61
+ type: wer
62
+ value: 8.85
63
+ - task:
64
+ name: Automatic Speech Recognition
65
+ type: automatic-speech-recognition
66
+ dataset:
67
+ name: Fleurs
68
+ type: google/fleurs
69
+ config: fr_fr
70
+ split: test
71
+ args:
72
+ language: fr
73
+ metrics:
74
+ - name: WER
75
+ type: wer
76
+ value: 5.40
77
+ - task:
78
+ name: Automatic Speech Recognition
79
+ type: automatic-speech-recognition
80
+ dataset:
81
+ name: African Accented French
82
+ type: gigant/african_accented_french
83
+ config: fr
84
+ split: test
85
+ args:
86
+ language: fr
87
+ metrics:
88
+ - name: WER
89
+ type: wer
90
+ value: 4.18
91
+ ---
92
+
93
+ # Whisper-Large-V3-French-Distil-Dec8
94
+
95
+ Whisper-Large-V3-French-Distil represents a series of distilled versions of [Whisper-Large-V3-French](https://huggingface.co/bofenghuang/whisper-large-v3-french), achieved by reducing the number of decoder layers from 32 to 16, 8, 4, or 2 and distilling using a large-scale dataset, as outlined in this [paper](https://arxiv.org/abs/2311.00430).
96
+
97
+ The distilled variants reduce memory usage and inference time while maintaining performance (based on the retained number of layers) and mitigating the risk of hallucinations, particularly in long-form transcriptions. Moreover, they can be seamlessly combined with the original Whisper-Large-V3-French model for speculative decoding, resulting in improved inference speed and consistent outputs compared to using the standalone model.
98
+
99
+ This model has been converted into various formats, facilitating its usage across different libraries, including transformers, openai-whisper, fasterwhisper, whisper.cpp, candle, mlx, etc.
100
+
101
+ ## Table of Contents
102
+
103
+ - [Performance](#performance)
104
+ - [Usage](#usage)
105
+ - [Hugging Face Pipeline](#hugging-face-pipeline)
106
+ - [Hugging Face Low-level APIs](#hugging-face-low-level-apis)
107
+ - [Speculative Decoding](#speculative-decoding)
108
+ - [OpenAI Whisper](#openai-whisper)
109
+ - [Faster Whisper](#faster-whisper)
110
+ - [Whisper.cpp](#whispercpp)
111
+ - [Candle](#candle)
112
+ - [MLX](#mlx)
113
+ - [Training details](#training-details)
114
+ - [Acknowledgements](#acknowledgements)
115
+
116
+ ## Performance
117
+
118
+ We evaluated our model on both short and long-form transcriptions, and also tested it on both in-distribution and out-of-distribution datasets to conduct a comprehensive analysis assessing its accuracy, generalizability, and robustness.
119
+
120
+ Please note that the reported WER is the result after converting numbers to text, removing punctuation (except for apostrophes and hyphens), and converting all characters to lowercase.
121
+
122
+ All evaluation results on the public datasets can be found [here](https://drive.google.com/drive/folders/1rFIh6yXRVa9RZ0ieZoKiThFZgQ4STPPI?usp=drive_link).
123
+
124
+ ### Short-Form Transcription
125
+
126
+ ![eval-short-form](https://huggingface.co/bofenghuang/whisper-large-v3-french/resolve/main/assets/whisper_fr_eval_short_form.png)
127
+
128
+ Due to the lack of readily available out-of-domain (OOD) and long-form test sets in French, we evaluated using internal test sets from [Zaion Lab](https://zaion.ai/). These sets comprise human-annotated audio-transcription pairs from call center conversations, which are notable for their significant background noise and domain-specific terminology.
129
+
130
+ ### Long-Form Transcription
131
+
132
+ ![eval-long-form](https://huggingface.co/bofenghuang/whisper-large-v3-french/resolve/main/assets/whisper_fr_eval_long_form.png)
133
+
134
+ The long-form transcription was run using the 🤗 Hugging Face pipeline for quicker evaluation. Audio files were segmented into 30-second chunks and processed in parallel.
135
+
136
+ ## Usage
137
+
138
+ ### Hugging Face Pipeline
139
+
140
+ The model can easily used with the 🤗 Hugging Face [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline) class for audio transcription.
141
+
142
+ For long-form transcription (> 30 seconds), you can activate the process by passing the `chunk_length_s` argument. This approach segments the audio into smaller segments, processes them in parallel, and then joins them at the strides by finding the longest common sequence. While this chunked long-form approach may have a slight compromise in performance compared to OpenAI's sequential algorithm, it provides 9x faster inference speed.
143
+
144
+ ```python
145
+ import torch
146
+ from datasets import load_dataset
147
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
148
+
149
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
150
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
151
+
152
+ # Load model
153
+ model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec8"
154
+ processor = AutoProcessor.from_pretrained(model_name_or_path)
155
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
156
+ model_name_or_path,
157
+ torch_dtype=torch_dtype,
158
+ low_cpu_mem_usage=True,
159
+ )
160
+ model.to(device)
161
+
162
+ # Init pipeline
163
+ pipe = pipeline(
164
+ "automatic-speech-recognition",
165
+ model=model,
166
+ feature_extractor=processor.feature_extractor,
167
+ tokenizer=processor.tokenizer,
168
+ torch_dtype=torch_dtype,
169
+ device=device,
170
+ # chunk_length_s=30, # for long-form transcription
171
+ max_new_tokens=128,
172
+ )
173
+
174
+ # Example audio
175
+ dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
176
+ sample = dataset[0]["audio"]
177
+
178
+ # Run pipeline
179
+ result = pipe(sample)
180
+ print(result["text"])
181
+ ```
182
+
183
+ ### Hugging Face Low-level APIs
184
+
185
+ You can also use the 🤗 Hugging Face low-level APIs for transcription, offering greater control over the process, as demonstrated below:
186
+
187
+ ```python
188
+ import torch
189
+ from datasets import load_dataset
190
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
191
+
192
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
193
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
194
+
195
+ # Load model
196
+ model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec8"
197
+ processor = AutoProcessor.from_pretrained(model_name_or_path)
198
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
199
+ model_name_or_path,
200
+ torch_dtype=torch_dtype,
201
+ low_cpu_mem_usage=True,
202
+ )
203
+ model.to(device)
204
+
205
+ # Example audio
206
+ dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
207
+ sample = dataset[0]["audio"]
208
+
209
+ # Extract feautres
210
+ input_features = processor(
211
+ sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
212
+ ).input_features
213
+
214
+
215
+ # Generate tokens
216
+ predicted_ids = model.generate(
217
+ input_features.to(dtype=torch_dtype).to(device), max_new_tokens=128
218
+ )
219
+
220
+ # Detokenize to text
221
+ transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
222
+ print(transcription)
223
+ ```
224
+
225
+ ### Speculative Decoding
226
+
227
+ [Speculative decoding](https://huggingface.co/blog/whisper-speculative-decoding) can be achieved using a draft model, essentially a distilled version of Whisper. This approach guarantees identical outputs to using the main Whisper model alone, offers a 2x faster inference speed, and incurs only a slight increase in memory overhead.
228
+
229
+ Since the distilled Whisper has the same encoder as the original, only its decoder need to be loaded, and encoder outputs are shared between the main and draft models during inference.
230
+
231
+ Using speculative decoding with the Hugging Face pipeline is simple - just specify the `assistant_model` within the generation configurations.
232
+
233
+ ```python
234
+ import torch
235
+ from datasets import load_dataset
236
+ from transformers import (
237
+ AutoModelForCausalLM,
238
+ AutoModelForSpeechSeq2Seq,
239
+ AutoProcessor,
240
+ pipeline,
241
+ )
242
+
243
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
244
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
245
+
246
+ # Load model
247
+ model_name_or_path = "bofenghuang/whisper-large-v3-french"
248
+ processor = AutoProcessor.from_pretrained(model_name_or_path)
249
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
250
+ model_name_or_path,
251
+ torch_dtype=torch_dtype,
252
+ low_cpu_mem_usage=True,
253
+ )
254
+ model.to(device)
255
+
256
+ # Load draft model
257
+ assistant_model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec2"
258
+ assistant_model = AutoModelForCausalLM.from_pretrained(
259
+ assistant_model_name_or_path,
260
+ torch_dtype=torch_dtype,
261
+ low_cpu_mem_usage=True,
262
+ )
263
+ assistant_model.to(device)
264
+
265
+ # Init pipeline
266
+ pipe = pipeline(
267
+ "automatic-speech-recognition",
268
+ model=model,
269
+ feature_extractor=processor.feature_extractor,
270
+ tokenizer=processor.tokenizer,
271
+ torch_dtype=torch_dtype,
272
+ device=device,
273
+ generate_kwargs={"assistant_model": assistant_model},
274
+ max_new_tokens=128,
275
+ )
276
+
277
+ # Example audio
278
+ dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
279
+ sample = dataset[0]["audio"]
280
+
281
+ # Run pipeline
282
+ result = pipe(sample)
283
+ print(result["text"])
284
+ ```
285
+
286
+ ### OpenAI Whisper
287
+
288
+ You can also employ the sequential long-form decoding algorithm with a sliding window and temperature fallback, as outlined by OpenAI in their original [paper](https://arxiv.org/abs/2212.04356).
289
+
290
+ First, install the [openai-whisper](https://github.com/openai/whisper) package:
291
+
292
+ ```bash
293
+ pip install -U openai-whisper
294
+ ```
295
+
296
+ Then, download the converted model:
297
+
298
+ ```bash
299
+ python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"
300
+ ```
301
+
302
+ Now, you can transcirbe audio files by following the usage instructions provided in the repository:
303
+
304
+ ```python
305
+ import whisper
306
+ from datasets import load_dataset
307
+
308
+ # Load model
309
+ model = whisper.load_model("./models/whisper-large-v3-french-distil-dec8/original_model.pt")
310
+
311
+ # Example audio
312
+ dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
313
+ sample = dataset[0]["audio"]["array"].astype("float32")
314
+
315
+ # Transcribe
316
+ result = model.transcribe(sample, language="fr")
317
+ print(result["text"])
318
+ ```
319
+
320
+ ### Faster Whisper
321
+
322
+ Faster Whisper is a reimplementation of OpenAI's Whisper models and the sequential long-form decoding algorithm in the [CTranslate2](https://github.com/OpenNMT/CTranslate2) format.
323
+
324
+ Compared to openai-whisper, it offers up to 4x faster inference speed, while consuming less memory. Additionally, the model can be quantized into int8, further enhancing its efficiency on both CPU and GPU.
325
+
326
+ First, install the [faster-whisper](https://github.com/SYSTRAN/faster-whisper) package:
327
+
328
+ ```bash
329
+ pip install faster-whisper
330
+ ```
331
+
332
+ Then, download the model converted to the CTranslate2 format:
333
+
334
+ ```bash
335
+ python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', local_dir='./models/whisper-large-v3-french-distil-dec8', allow_patterns='ctranslate2/*')"
336
+ ```
337
+
338
+ Now, you can transcirbe audio files by following the usage instructions provided in the repository:
339
+
340
+ ```python
341
+ from datasets import load_dataset
342
+ from faster_whisper import WhisperModel
343
+
344
+ # Load model
345
+ model = WhisperModel("./models/whisper-large-v3-french-distil-dec8/ctranslate2", device="cuda", compute_type="float16") # Run on GPU with FP16
346
+
347
+ # Example audio
348
+ dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
349
+ sample = dataset[0]["audio"]["array"].astype("float32")
350
+
351
+ segments, info = model.transcribe(sample, beam_size=5, language="fr")
352
+
353
+ for segment in segments:
354
+ print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
355
+ ```
356
+
357
+ ### Whisper.cpp
358
+
359
+ Whisper.cpp is a reimplementation of OpenAI's Whisper models, crafted in plain C/C++ without any dependencies. It offers compatibility with various backends and platforms.
360
+
361
+ Additionally, the model can be quantized to either 4-bit or 5-bit integers, further enhancing its efficiency.
362
+
363
+ First, clone and build the [whisper.cpp](https://github.com/ggerganov/whisper.cpp) repository:
364
+
365
+ ```bash
366
+ git clone https://github.com/ggerganov/whisper.cpp.git
367
+ cd whisper.cpp
368
+
369
+ # build the main example
370
+ make
371
+ ```
372
+
373
+ Next, download the converted ggml weights from the Hugging Face Hub:
374
+
375
+ ```bash
376
+ # Download model quantized with Q5_0 method
377
+ python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='ggml-model-q5_0.bin', local_dir='./models/whisper-large-v3-french-distil-dec8')"
378
+ ```
379
+
380
+ Now, you can transcribe an audio file using the following command:
381
+
382
+ ```bash
383
+ ./main -m ./models/whisper-large-v3-french-distil-dec8/ggml-model-q5_0.bin -l fr -f /path/to/audio/file --print-colors
384
+ ```
385
+
386
+ ### Candle
387
+
388
+ [Candle-whisper](https://github.com/huggingface/candle/tree/main/candle-examples/examples/whisper) is a reimplementation of OpenAI's Whisper models in the candle format - a lightweight ML framework built in Rust.
389
+
390
+ First, clone the [candle](https://github.com/huggingface/candle) repository:
391
+
392
+ ```bash
393
+ git clone https://github.com/huggingface/candle.git
394
+ cd candle/candle-examples/examples/whisper
395
+ ```
396
+
397
+ Transcribe an audio file using the following command:
398
+
399
+ ```bash
400
+ cargo run --example whisper --release -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec8 --language fr --input /path/to/audio/file
401
+ ```
402
+
403
+ In order to use CUDA add `--features cuda` to the example command line:
404
+
405
+ ```bash
406
+ cargo run --example whisper --release --features cuda -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec8 --language fr --input /path/to/audio/file
407
+ ```
408
+
409
+ ### MLX
410
+
411
+ [MLX-Whisper](https://github.com/ml-explore/mlx-examples/tree/main/whisper) is a reimplementation of OpenAI's Whisper models in the [MLX](https://github.com/ml-explore/mlx) format - a ML framework on Apple silicon. It supports features like lazy computation, unified memory management, etc.
412
+
413
+ First, clone the [MLX Examples](https://github.com/ml-explore/mlx-examples) repository:
414
+
415
+ ```bash
416
+ git clone https://github.com/ml-explore/mlx-examples.git
417
+ cd mlx-examples/whisper
418
+ ```
419
+
420
+ Next, install the dependencies:
421
+
422
+ ```bash
423
+ pip install -r requirements.txt
424
+ ```
425
+
426
+ Download the pytorch checkpoint in the original OpenAI format and convert it into MLX format (We haven't included the converted version here since the repository is already heavy and the conversion is very fast):
427
+
428
+ ```bash
429
+ # Download
430
+ python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"
431
+ # Convert into .npz
432
+ python convert.py --torch-name-or-path ./models/whisper-large-v3-french-distil-dec8/original_model.pt --mlx-path ./mlx_models/whisper-large-v3-french-distil-dec8
433
+ ```
434
+
435
+ Now, you can transcribe audio with:
436
+
437
+ ```python
438
+ import whisper
439
+
440
+ result = whisper.transcribe("/path/to/audio/file", path_or_hf_repo="mlx_models/whisper-large-v3-french-distil-dec8", language="fr")
441
+ print(result["text"])
442
+ ```
443
+
444
+ ## Training details
445
+
446
+ We've collected a composite dataset consisting of over 2,500 hours of French speech recognition data, which incldues datasets such as [Common Voice 13.0](https://huggingface.co/datasets/mozilla-foundation/common_voice_13_0), [Multilingual LibriSpeech](https://huggingface.co/datasets/facebook/multilingual_librispeech), [Voxpopuli](https://huggingface.co/datasets/facebook/voxpopuli), [Fleurs](https://huggingface.co/datasets/google/fleurs), [Multilingual TEDx](https://www.openslr.org/100/), [MediaSpeech](https://www.openslr.org/108/), [African Accented French](https://huggingface.co/datasets/gigant/african_accented_french), etc.
447
+
448
+ Given that some datasets, like MLS, only offer text without case or punctuation, we employed a customized version of 🤗 [Speechbox](https://github.com/huggingface/speechbox) to restore case and punctuation from a limited set of symbols using the [bofenghuang/whisper-large-v2-cv11-french](bofenghuang/whisper-large-v2-cv11-french) model.
449
+
450
+ However, even within these datasets, we observed certain quality issues. These ranged from mismatches between audio and transcription in terms of language or content, poorly segmented utterances, to missing words in scripted speech, etc. We've built a pipeline to filter out many of these problematic utterances, aiming to enhance the dataset's quality. As a result, we excluded more than 10% of the data, and when we retrained the model, we noticed a significant reduction of hallucination.
451
+
452
+ For training, we employed the [script](https://github.com/huggingface/distil-whisper/blob/main/training/run_distillation.py) available in the 🤗 Distil-Whisper repository. The model training took place on the [Jean-Zay supercomputer](http://www.idris.fr/eng/jean-zay/jean-zay-presentation-eng.html) at GENCI, and we extend our gratitude to the IDRIS team for their responsive support throughout the project.
453
+
454
+ ## Acknowledgements
455
+
456
+ - OpenAI for creating and open-sourcing the [Whisper model](https://arxiv.org/abs/2212.04356)
457
+ - 🤗 Hugging Face for integrating the Whisper model and providing the training codebase within the [Transformers](https://github.com/huggingface/transformers) and [Distil-Whisper](https://github.com/huggingface/distil-whisper) repository
458
+ - [Genci](https://genci.fr/) for their generous contribution of GPU hours to this project