Rakib commited on
Commit
c184a2b
β€’
1 Parent(s): 94a5b38

update model card README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -1244
README.md CHANGED
@@ -1,1244 +1,80 @@
1
- # Whisper Fine-Tuning Event πŸ€—
2
-
3
- Welcome to the Whisper fine-tuning event πŸŽ™οΈ!
4
-
5
- For two weeks, we will endeavour to fine-tune the Whisper model to build state-of-the-art speech recognition systems in
6
- the languages of our choice πŸ—£. We will work together as a community to achieve this, helping others and learning where
7
- we can πŸ€—. If necessary and available, free access to A100 40 GB GPUs will kindly be provided by our cloud compute
8
- partners, [Lambda](https://lambdalabs.com) πŸš€.
9
-
10
- This document summarises all the relevant information required for the event πŸ“‹. Please read it thoroughly
11
- and make sure to:
12
- - Sign-up using the [Google form](https://forms.gle/F2bpouvhDpKKisM39)
13
- - Join the [Hugging Face Discord server](https://hf.co/join/discord) and make sure to assign yourself **@ml-4-audio** role in #role-assignment so that you can access #events channel.
14
-
15
- ## Table of Contents
16
-
17
- - [Introduction](#introduction)
18
- - [Important Dates](#important-dates)
19
- - [Launch a Lambda Cloud GPU](#launch-a-lambda-cloud-gpu)
20
- - [Set Up an Environment](#set-up-an-environment)
21
- - [Data and Pre-Processing](#data-and-pre-processing)
22
- - [Fine-Tune a Whisper Model](#fine-tune-whisper)
23
- - [Evaluation](#evaluation)
24
- - [Building a Demo](#building-a-demo)
25
- - [Communication and Problems](#communication-and-problems)
26
- - [Talks](#talks)
27
- - [Tips and Tricks](#tips-and-tricks)
28
- - [Feedback](#feedback)
29
-
30
- ## Introduction
31
- Whisper is a pre-trained model for automatic speech recognition (ASR) published in [September 2022](https://openai.com/blog/whisper/)
32
- by the authors Radford et al. from OpenAI. Pre-trained on 680,000 hours of labelled data, it demonstrates a strong ability
33
- to generalise to different datasets and domains. Through fine-tuning, the performance of this model can be significantly
34
- boosted for a given language.
35
-
36
- In this event, we're bringing the community together to fine-tune Whisper in as many languages as possible. Our aim is
37
- to achieve state-of-the-art on the languages spoken by the community. Together, we can democratise speech recognition
38
- for all.
39
-
40
- We are providing training scripts, notebooks, blog posts, talks and compute (where available), so you have all the
41
- resources you need to participate! You are free to chose your level of participation, from using the template script and setting
42
- it to your language, right the way through to exploring advanced training methods. We encourage you to participate to
43
- level that suits you best. We'll be on hand to facilitate this!
44
-
45
- Participants are allowed to fine-tune their systems on the training data of their choice, including datasets from the
46
- Hugging Face Hub, web-scraped data from the internet, or private datasets. Whisper models will be evaluated
47
- on the "test" split of the [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)
48
- dataset for the participant's chosen language.
49
-
50
- We believe that framing the event as a competition is fun! But at the core, the event is about
51
- fine-tuning Whisper in as many languages as possible as a community. We want to foster an environment where we
52
- work together, help each other solve bugs, share important findings and ultimately learn something new.
53
-
54
- This README contains all the information you need for the event. It is structured such that you can read it sequentially,
55
- section-by-section. **We recommend that you read the document once from start to finish before running any code.** This will
56
- give you an idea of where to look for the relevant information and an idea of how the event is going to run.
57
-
58
- ## Important Dates
59
-
60
- - *Introduction Talk*: 2nd December 2022
61
- - *Sprint start*: 5th December 2022
62
- - *Speaker Events*: 5th December 2022
63
- - *Sprint end*: 19th December 2022
64
- - *Results*: 23rd December 2022
65
-
66
- ## Launch a Lambda Cloud GPU
67
- Where possible, we encourage you to fine-tune Whisper on a local GPU machine. This will mean a faster set-up and more
68
- familiarity with your device. If you are running on a local GPU machine, you can skip ahead to the next section: [Set Up an Environment](#set-up-an-environment).
69
-
70
- The training scripts can also be run as a notebook through Google Colab. We recommend you train on Google Colab if you
71
- have a "Colab Pro" or "Pro+" subscription. This is to ensure that you receive a sufficiently powerful GPU on your Colab for
72
- fine-tuning Whisper. If you wish to fine-tune Whisper through Google Colab, you can skip ahead to the section: [Data and Pre-Processing](#data-and-pre-processing).
73
-
74
- If you do not have access to a local GPU or Colab Pro/Pro+, we'll endeavour to provide you with a cloud GPU instance.
75
- We've partnered up with Lambda to provide cloud compute for this event. They'll be providing the latest NVIDIA A100
76
- 40 GB GPUs, so you'll be loaded with some serious firepower! The Lambda API makes it easy to spin-up and launch
77
- a GPU instance. In this section, we'll go through the steps for spinning up an instance one-by-one.
78
-
79
- <p align="center" width="100%">
80
- <img width="50%" src="https://raw.githubusercontent.com/sanchit-gandhi/codesnippets/main/hf_x_lambda.jpg">
81
- </p>
82
-
83
- This section is split into three parts:
84
-
85
- 1. [Signing-Up with Lambda](#signing-up-with-lambda)
86
- 2. [Creating a Cloud Instance](#creating-a-cloud-instance)
87
- 3. [Deleting a Cloud Instance](#deleting-a-cloud-instance)
88
-
89
- ### Signing-Up with Lambda
90
-
91
- 1. Create an account with Lambda using your email address of choice: https://cloud.lambdalabs.com/sign-up. If you already have an account, skip to step 2.
92
- 2. Using this same email address, email `cloud@lambdal.com` with the Subject line: `Lambda cloud account for HuggingFace Whisper event - payment authentication and credit request`.
93
- 3. Each user who emails as above will receive $110 in credits (amounting to 100 hours of 1x A100 usage).
94
- 4. Register a valid payment method with Lambda in order to redeem the credits (see instructions below).
95
-
96
- 100 hours of 1x A100 usage should enable you to complete 5-10 fine-tuning runs. To redeem these credits, you will need to
97
- authorise a valid payment method with Lambda. Provided that you remain within $110 of compute spending, your card **will not**
98
- be charged πŸ’Έ. Registering your card with Lambda is a mandatory sign-up step that we unfortunately cannot bypass. But we
99
- reiterate: you will not be charged provided you remain within $110 of compute spending!
100
-
101
- Follow steps 1-4 in the next section [Creating a Cloud Instance](#creating-a-cloud-instance) to register your
102
- card. If you experience issues with registering your card, contact the Lambda team on Discord (see [Communications and Problems](#communication-and-problems)).
103
-
104
- In order to maximise the free GPU hours you have available for training, we advise that you shut down GPUs when you are
105
- not using them and closely monitor your GPU usage. We've detailed the steps you can follow to achieve this in [Deleting a Cloud Instance](#deleting-a-cloud-instance).
106
-
107
- ### Creating a Cloud Instance
108
- Estimated time to complete: 5 mins
109
-
110
- *You can also follow our video tutorial to set up a cloud instance on Lambda* πŸ‘‰οΈ [YouTube Video](https://www.youtube.com/watch?v=Ndm9CROuk5g&list=PLo2EIpI_JMQtncHQHdHq2cinRVk_VZdGW)
111
-
112
- 1. Click the link: https://cloud.lambdalabs.com/instances
113
- 2. You'll be asked to sign in to your Lambda account (if you haven't done so already).
114
- 3. Once on the GPU instance page, click the purple button "Launch instance" in the top right.
115
- 4. Verify a payment method if you haven't done so already. IMPORTANT: if you have followed the instructions in the previous section, you will have received $110 in GPU credits. Exceeding 100 hours of 1x A100 usage may incur charges on your credit card. Contact the Lambda team on Discord if you have issues authenticating your payment method (see [Communications and Problems](#communication-and-problems))
116
- 5. Launching an instance:
117
- 1. In "Instance type", select the instance type "1x A100 (40 GB SXM4)"
118
- 2. In "Select region", select the region with availability closest to you.
119
- 3. In "Select filesystem", select "Don't attach a filesystem".
120
- 6. You will be asked to provide your public SSH key. This will allow you to SSH into the GPU device from your local machine.
121
- 1. If you’ve not already created an SSH key pair, you can do so with the following command from your local device:
122
- ```bash
123
- ssh-keygen
124
- ```
125
- 2. You can find your public SSH key using the command:
126
- ```bash
127
- cat ~/.ssh/id_rsa.pub
128
- ```
129
- (Windows: `type C:UsersUSERNAME.sshid_rsa.pub` where `USERNAME` is the name of your user)
130
- 4. Copy and paste the output of this command into the first text box
131
- 5. Give your SSH key a memorable name (e.g. `sanchits-mbp`)
132
- 6. Click "Add SSH Key"
133
- 7. Select the SSH key from the drop-down menu and click "Launch instance"
134
- 8. Read the terms of use and agree
135
- 9. We can now see on the "GPU instances" page that our device is booting up!
136
- 10. Once the device status changes to "βœ… Running", click on the SSH login ("ssh ubuntu@..."). This will copy the SSH login to your clipboard.
137
- 11. Now open a new command line window, paste the SSH login, and hit Enter.
138
- 12. If asked "Are you sure you want to continue connecting?", type "yes" and press Enter.
139
- 13. Great! You're now SSH'd into your A100 device! We're now ready to set up our Python environment!
140
-
141
- You can see your total GPU usage from the Lambda cloud interface: https://cloud.lambdalabs.com/usage
142
-
143
- Here, you can see the total charges that you have incurred since the start of the event. We advise that you check your
144
- total on a daily basis to make sure that it remains below the credit allocation of $110. This ensures that you are
145
- not inadvertently charged for GPU hours.
146
-
147
- If you are unable to SSH into your Lambda GPU in step 11, there is a workaround that you can try. On the [GPU instances page](https://cloud.lambdalabs.com/instances),
148
- under the column "Cloud IDE", click the button "Launch". This will launch a Jupyter Lab on your GPU which will be displayed in your browser. In the
149
- top left-hand corner, click "File" -> "New" -> "Terminal". This will open up a new terminal window. You can use this
150
- terminal window to set up your Python environment in the next section [Set Up an Environment](#set-up-an-environment).
151
-
152
- ### Deleting a Cloud Instance
153
-
154
- 100 1x A100 hours should provide you with enough time for 5-10 fine-tuning runs (depending on how long you train for
155
- and which size models). To maximise the GPU time you have for training, we advise that you shut down GPUs over prolonged
156
- periods of time when they are not in use. Leaving a GPU running accidentally over the weekend will incur 48 hours of
157
- wasted GPU hours. That's nearly half of your compute allocation! So be smart and shut down your GPU when you're not training.
158
-
159
- Creating an instance and setting it up for the first time may take up to 20 minutes. Subsequently, this process will
160
- be much faster as you gain familiarity with the steps, so you shouldn't worry about having to delete a GPU and spinning one
161
- up the next time you need one. You can expect to spin-up and delete 2-3 GPUs over the course of the fine-tuning event.
162
-
163
-
164
- We'll quickly run through the steps for deleting a Lambda GPU. You can come back to these steps after you've
165
- performed your first training run and you want to shut down the GPU:
166
-
167
- 1. Go to the instances page: https://cloud.lambdalabs.com/instances
168
- 2. Click the checkbox on the left next to the GPU device you want to delete
169
- 3. Click the button "Terminate" in the top right-hand side of your screen (under the purple button "Launch instance")
170
- 4. Type "erase data on instance" in the text box and press "ok"
171
-
172
- Your GPU device is now deleted and will stop consuming GPU credits.
173
-
174
- ## Set Up an Environment
175
- Estimated time to complete: 5 mins
176
-
177
- *Follow along our video tutorial detailing the set up* πŸ‘‰οΈ [YouTube Video](https://www.youtube.com/playlist?list=PLo2EIpI_JMQtzC5feNpqQL7eToYKcOxYf)
178
-
179
- The Whisper model should be fine-tuned using **PyTorch**, **πŸ€— Transformers**, and, **πŸ€— Datasets**. In this
180
- section, we'll cover how to set up an environment with the required libraries. This section assumes that you are SSH'd
181
- into your GPU device. This section does not apply if you are fine-tuning the Whisper model in a Google Colab.
182
-
183
- If you are returning to this section having read through it previously and want to quickly set up an environment, you
184
- can do so in one call by executing the following code cell. If this is your first time setting up an environment, we
185
- recommend you read this section to understand the steps involved.
186
-
187
- ```bash
188
- sudo add-apt-repository -y ppa:jonathonf/ffmpeg-4
189
- sudo apt update
190
- sudo apt install -y ffmpeg
191
-
192
- sudo apt-get install git-lfs
193
-
194
- python3 -m venv hf_env
195
- source hf_env/bin/activate
196
- echo "source ~/hf_env/bin/activate" >> ~/.bashrc
197
-
198
- git clone https://github.com/huggingface/community-events.git
199
- pip install -r community-events/whisper-fine-tuning-event/requirements.txt
200
-
201
- git config --global credential.helper store
202
- huggingface-cli login
203
- ```
204
-
205
- ### Unix Libraries
206
-
207
- First, we need to make sure we have the required NVIDIA drivers installed. We can check that we have these drivers
208
- through the following command:
209
-
210
- ```bash
211
- nvidia-smi
212
- ```
213
-
214
- This should print a table with our NVIDIA driver version and CUDA version, and should work out of the box for Lambda GPUs!
215
- If you get an error running this command, refer to your device manual for installing the required NVIDIA driver.
216
-
217
- Before installing the required libraries, we'd need to install and update the Unix package `ffmpeg` to version 4:
218
-
219
- ```bash
220
- sudo add-apt-repository -y ppa:jonathonf/ffmpeg-4
221
- sudo apt update
222
- sudo apt install -y ffmpeg
223
- ```
224
-
225
- We'll also need the package `git-lfs` to push large model weights to the Hugging Face Hub. To check whether
226
- `git-lfs` is installed, simply run:
227
-
228
- ```bash
229
- git-lfs -v
230
- ```
231
-
232
- The output should show something like `git-lfs/2.13.2 (GitHub; linux amd64; go 1.15.4)`. If your console states that
233
- the `git-lfs` command was not found, you can install it via:
234
-
235
- ```bash
236
- sudo apt-get install git-lfs
237
- ```
238
-
239
- ### Python Libraries
240
-
241
- We recommend installing the required libraries in a Python virtual environment. If you're unfamiliar with Python virtual
242
- environments, check out the [official user guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
243
-
244
- Let's define a variable that denotes the name of the environment we're going to create:
245
-
246
- ```bash
247
- env_name=<your-venv-name>
248
- ```
249
-
250
- We can create a virtual environment (venv) with this name using the following command:
251
-
252
- ```bash
253
- python3 -m venv $env_name
254
- ```
255
-
256
- We'll instruct our bash shell to activate the venv by default by placing the venv source command in `.bashrc`:
257
-
258
- ```bash
259
- echo "source ~/$env_name/bin/activate" >> ~/.bashrc
260
- ```
261
-
262
- Re-launching the bash shell will activate the venv:
263
-
264
- ```bash
265
- bash
266
- ```
267
-
268
- Great! We can see that our venv name is at the start of our command line - this means that we're operating from
269
- within the venv. We can now go ahead and start installing the required Python packages to our venv.
270
-
271
- The [`requirements.txt`](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/requirements.txt)
272
- file in this directory has all the necessary Python packages we need to fine-tune Whisper, including PyTorch, Transformers
273
- and Datasets. We'll install all the packages in this file through one `pip install` command.
274
-
275
- First, let's clone the `community-events` repository to our device:
276
-
277
- ```bash
278
- git clone https://github.com/huggingface/community-events.git
279
- ```
280
-
281
- Now we can install the packages from the `requirements.txt` file using the following command:
282
-
283
- ```bash
284
- pip install -r community-events/whisper-fine-tuning-event/requirements.txt
285
- ```
286
-
287
- Note: when installing packages, you might see warnings such as:
288
-
289
- ```bash
290
- error: invalid command 'bdist_wheel'
291
- ----------------------------------------
292
- ERROR: Failed building wheel for audioread
293
- ```
294
-
295
- This is perfectly ok! It does not affect our installation.
296
-
297
- We can check that above steps installed the correct version of PyTorch to match our CUDA version. The following command should return True:
298
-
299
- ```python
300
- python -c "import torch; print(torch.cuda.is_available())"
301
- ```
302
-
303
- If the above command does not return True, refer to the [official instructions](https://pytorch.org/get-started/locally/) for installing PyTorch.
304
-
305
- We can now verify that `transformers` and `datasets` have been correctly installed. First, launch a Python shell:
306
-
307
- ```bash
308
- python
309
- ```
310
-
311
- Running the following code cell will load one sample of the [Common Voice](https://huggingface.co/datasets/common_voice)
312
- dataset from the Hugging Face Hub and perform a forward pass of the "tiny" Whisper model:
313
-
314
- ```python
315
- import torch
316
- from transformers import WhisperFeatureExtractor, WhisperForConditionalGeneration
317
- from datasets import load_dataset
318
-
319
- model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny")
320
- feature_extractor = WhisperFeatureExtractor.from_pretrained("openai/whisper-tiny")
321
-
322
- common_voice = load_dataset("common_voice", "en", split="validation", streaming=True)
323
-
324
- inputs = feature_extractor(next(iter(common_voice))["audio"]["array"], sampling_rate=16000, return_tensors="pt")
325
- input_features = inputs.input_features
326
-
327
- decoder_input_ids = torch.tensor([[1, 1]]) * model.config.decoder_start_token_id
328
- logits = model(input_features, decoder_input_ids=decoder_input_ids).logits
329
-
330
- print("Environment set up successful?", logits.shape[-1] == 51865)
331
-
332
- ```
333
-
334
- If the final check returns True, the libraries have been installed correctly. Finally, exit the Python shell:
335
-
336
- ```python
337
- quit()
338
- ```
339
-
340
- The last thing we need to do is link our Hugging Face account. Run the command:
341
-
342
- ```bash
343
- git config --global credential.helper store
344
- huggingface-cli login
345
- ```
346
-
347
- And then enter an authentication token from https://huggingface.co/settings/tokens. Create a new token if you do not have
348
- one already. You should make sure that this token has "write" privileges.
349
-
350
- ## Data and Pre-Processing
351
-
352
- In this section, we will cover how to find suitable training data and the necessary steps to pre-process it.
353
- If you are new to the πŸ€— Datasets library, we highly recommend reading the comprehensive blog post: [A Complete Guide To Audio Datasets](https://huggingface.co/blog/audio-datasets).
354
- This blog post will tell you everything you need to know about πŸ€— Datasets and its one-line API.
355
-
356
- ### Data
357
-
358
- Whisper models will be evaluated on the `"test"` split of the [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)
359
- dataset. Any data can be used to fine-tune the Whisper model **except Common Voice's `"test"` split**. This exception
360
- extends to all Common Voice versions, as the test split of legacy Common Voice releases often overlaps with the
361
- latest one. For instance, the test split of Common Voice 10 is largely the same as that of Common Voice 11.
362
-
363
- So, the test data:
364
-
365
- ```python
366
- load_dataset("mozilla-foundation/common_voice_11_0", "en", split="test", use_auth_token=True)
367
- ```
368
-
369
- More or less includes the same data as:
370
-
371
- ```python
372
- load_dataset("mozilla-foundation/common_voice_10_0", "en", split="test", use_auth_token=True)
373
- ```
374
-
375
- And **neither** are allowed for training purposes. However, we strongly encourage participants to make use of the other
376
- Common Voice splits for training data, such as the `"train"` and `"validation"` splits:
377
-
378
- ```python
379
- load_dataset("mozilla-foundation/common_voice_10_0", "en", split="train", use_auth_token=True)
380
- ```
381
-
382
- For most languages, the `"train"` split of Common Voice 11 dataset offers a reasonable amount of training data.
383
- For low-resource languages, it is normal procedure to combine the `"train"` and `"validation"` splits to give a larger
384
- training corpus:
385
-
386
- ```python
387
- load_dataset("mozilla-foundation/common_voice_10_0", "en", split="train+validation", use_auth_token=True)
388
- ```
389
-
390
- This notation for combining splits (`"split_a+split_b"`) is consistent for all resources in the event. You can combine
391
- splits in this same way using the fine-tuning scripts in the following section [Fine-Tune Whisper](#fine-tune-whisper).
392
-
393
- If combining the `"train"` and `"validation"` splits of the Common Voice 11 dataset still gives insufficient training
394
- data for your language, you can explore using other datasets on the Hub to train your model and try
395
- [Mixing Datasets](#mixing-datasets-optional) to give larger training splits.
396
-
397
- ### Streaming Mode
398
-
399
- Audio datasets are very large. This causes two issues:
400
- 1. They require a significant amount of **storage space** to download.
401
- 2. They take a significant amount of **time** to download and process.
402
-
403
- The storage and time requirements present limitations to most speech researchers. For example, downloading the English
404
- subset of the Common Voice 11 dataset (2,300 hours) requires upwards of 200GB of disk space and up to several hours
405
- of download time. For these reasons, we **do not** recommend that you run the following code cell!
406
- ```python
407
- from datasets import load_dataset
408
-
409
- common_voice = load_dataset("mozilla-foundation/common_voice_11_0", "en", use_auth_token=True)
410
-
411
- # we have to wait several hours until the entire dataset is downloaded before we can access the first sample...
412
- print(next(iter(common_voice["train"])))
413
- ```
414
-
415
- However, both these issues can be solved with πŸ€— Datasets. Rather than downloading the whole dataset at once, we
416
- load individual samples as we cycle over the dataset, in a process called _streaming_. Since the data is loaded
417
- progressively as we iterate over the dataset, we can get started with a dataset as soon as the first sample is ready.
418
- This way, we don't have to wait for the entire dataset to download before we can run our code! We are also free of any
419
- disk space contraints: once we're done with a sample, we discard it and load the next one to memory. This way, we only
420
- have the data when we need it, and not when we don't!
421
-
422
- Streaming is enabled by passing the argument `streaming=True` to the `load_dataset` function. We can then use our
423
- audio datasets in much the same way as before! For these reasons, **we highly recommend** that you try out the following
424
- code cell! Just make sure you've accepted the Common Voice 11 [terms of use](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0) on the Hugging Face Hub.
425
-
426
- ```python
427
- from datasets import load_dataset
428
-
429
- common_voice = load_dataset("mozilla-foundation/common_voice_11_0", "en", use_auth_token=True, streaming=True)
430
-
431
- # get the first sample of the dataset straight away!
432
- print(next(iter(common_voice["train"])))
433
- ```
434
-
435
- The examples for this event rely heavily on streaming mode to fine-tune Whisper. With streaming mode, we can use **any
436
- speech recognition dataset on the Hub with just 20GB of disk space**. As a speech recognition practitioner, this is
437
- game changing! The largest speech recognition datasets are available to us regardless of our device disk space. We are
438
- extremely excited to be showcasing streaming mode in this event and hope that you will enjoy using it.
439
-
440
- There is one caveat to streaming mode. When downloading a dataset to disk, the processed data is saved to our cache. If
441
- we want to re-use this data, we can directly load the processed data from cache, skipping the download and processing
442
- steps. Consequently, we only have to perform the downloading and processing operations once. With streaming mode, the
443
- data is not downloaded to disk. Thus, neither the download nor pre-processing are cached. If we want to re-use the data,
444
- the streaming steps must be repeated, with the audio files loaded and pre-processed again. Therefore, we recommend not
445
- using streaming mode if your dataset is small (< 10 hours). In this case, it is faster to download and pre-process the
446
- dataset in the conventional way once at the start, and then re-use it at each epoch. We provide pointers for disabling
447
- streaming mode in the section [Fine-Tune Whisper](#fine-tune-whisper).
448
-
449
- If you want to read more about streaming mode, we
450
- recommend you check out the aforementioned blog post: [A Complete Guide To Audio Datasets](https://huggingface.co/blog/audio-datasets).
451
-
452
- ### Pre-Processing
453
-
454
- Data pre-processing is a very grey area when it comes to speech recognition. In this section, we'll try to make the
455
- situation as clear as possible for you as participants.
456
-
457
- The Common Voice dataset is both cased and punctuated:
458
-
459
- ```python
460
- print(next(iter(common_voice["train"]))["sentence"])
461
- ```
462
- **Print Output:**
463
- ```
464
- Why does Melissandre look like she wants to consume Jon Snow on the ride up the wall?
465
- ```
466
-
467
- If we train the Whisper model on the raw Common Voice dataset, it will learn to predict casing and punctuation. This is
468
- great when we want to use out model for actual speech recognition applications, such as transcribing meetings or
469
- dictation, as the predicted transcriptions will be formatted with casing and punctuation.
470
-
471
- However, we also have the option of 'normalising' the dataset to remove any casing and punctuation. Normalising the
472
- dataset makes the speech recognition task easier: the model no longer needs to distinguish between upper and lower case
473
- characters, or have to predict punctuation from the audio data alone. Because of this, the word error rates are
474
- naturally lower (meaning the results are better). The Whisper paper demonstrates the drastic effect that normalising
475
- transcriptions can have on WER results (_c.f._ Section 4.4 of the [Whisper paper](https://cdn.openai.com/papers/whisper.pdf)).
476
- But while we get lower WERs, we can't necessarily use our model in production. The lack of casing and punctuation makes
477
- the predicted text from the model much harder to read. We would need additional post-processing models to restore casing and
478
- punctuation in our predictions if we wanted to use it for downstream applications.
479
-
480
- There is a happy medium between the two: we can train our systems on cased and normalised transcriptions, and then
481
- evaluate them on normalised text. This way, we train our systems to predict fully formatted text, but also benefit from
482
- the WER improvements we get by normalising the transcriptions.
483
-
484
- The choice of whether you normalise the transcriptions is ultimately down to you. We recommend training on un-normalised
485
- text and evaluating on normalised text to get the best of both worlds. Since those choices are not always obvious, feel
486
- free to ask on Discord or (even better) post your question on the [forum](https://discuss.huggingface.co).
487
-
488
- | Train | Eval | Pros | Cons |
489
- |---------------|---------------|----------------------------------------------------------------|------------------------------------------|
490
- | Un-normalised | Un-normalised | * Predict casing + punctuation<br>* One logic for train / eval | * WERs are higher |
491
- | Un-normalised | Normalised | * Predict casing + punctuation<br>* WERs are lower | * Different logic for train / eval |
492
- | Normalised | Normalised | * One logic for train / eval<br>* WERs are lower | * No casing / punctuation in predictions |
493
-
494
- With the provided training scripts, it is trivial to toggle between removing or retaining punctuation and casing,
495
- requiring at most three lines of code change. Switching between the different modes is explained in more detail in the
496
- following section [Fine-Tune Whisper](#fine-tune-whisper).
497
-
498
- If you want to find out more about pre- and post-processing for speech recognition, we refer you in the direction of
499
- the paper: [ESB: A Benchmark For Multi-Domain End-to-End Speech Recognition](https://arxiv.org/abs/2210.13352).
500
-
501
- The following two subsections are optional. They cover how you can mix datasets to form larger training splits and how
502
- you can use custom data to fine-tune your model. If the Common Voice 11 dataset has sufficient data in your language to
503
- fine-tune your model, you can skip to the next section [Fine-Tune Whisper](#fine-tune-whisper).
504
-
505
- ### Mixing Datasets (optional)
506
-
507
- If the Common Voice 11 dataset contains insufficient training data to fine-tune Whisper in your language, you can explore mixing
508
- different datasets to create a larger combined training set. Incorporating supplementary training data is almost always beneficial for training.
509
- The Whisper paper demonstrates the significant effect that increasing the amount of training data can have on downstream
510
- performance (_c.f._ Section 4.2 of the [paper](https://cdn.openai.com/papers/whisper.pdf)). There are a number of datasets
511
- that are available on the Hugging Face Hub that can be downloaded via the πŸ€— Datasets library in much the same way as
512
- Common Voice 11.
513
-
514
- We recommend selecting from the following four datasets on the Hugging Face Hub for multilingual speech recognition:
515
-
516
- | Dataset | Languages | Casing | Punctuation |
517
- |-----------------------------------------------------------------------------------------------|-----------|--------|-------------|
518
- | [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0) | 100+ | βœ… | βœ… |
519
- | [VoxPopuli](https://huggingface.co/datasets/facebook/voxpopuli) | 15 | ❌ | βœ… |
520
- | [Multilingual LibriSpeech](https://huggingface.co/datasets/facebook/multilingual_librispeech) | 6 | ❌ | ❌ |
521
- | [FLEURS](https://huggingface.co/datasets/google/fleurs) | 100+ | βœ… | βœ… |
522
-
523
-
524
- <!---
525
- <details>
526
- <summary>
527
-
528
- #### Common Voice 11
529
-
530
- </summary>
531
-
532
- [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0) is a crowd-sourced
533
- open-licensed speech dataset where speakers record text from Wikipedia in various languages. Since anyone can contribute
534
- recordings, there is significant variation in both audio quality and speakers. The audio conditions are challenging, with
535
- recording artefacts, accented speech, hesitations, and the presence of foreign words. The transcriptions are both cased
536
- and punctuated. As of version 11, there are over 100 languages available, both low and high-resource.
537
- </details>
538
- <details>
539
- <summary>
540
-
541
- #### VoxPopuli
542
-
543
- </summary>
544
-
545
- [VoxPopuli](https://huggingface.co/datasets/facebook/voxpopuli) is a large-scale multilingual speech corpus consisting
546
- of data sourced from 2009-2020 European Parliament event recordings. Consequently, it occupies the unique domain of
547
- oratory, political speech, largely sourced from non-native speakers. It contains labelled audio-transcription data for
548
- 15 European languages. The transcriptions are punctuated but not cased.
549
- </details>
550
- <details>
551
- <summary>
552
-
553
- #### Multilingual LibriSpeech
554
-
555
- </summary>
556
-
557
- [Multilingual LibriSpeech](https://huggingface.co/datasets/facebook/multilingual_librispeech) is the multilingual
558
- equivalent of the [LibriSpeech ASR](https://huggingface.co/datasets/librispeech_asr) corpus. It comprises a large corpus
559
- of read audiobooks taken from the [LibriVox](https://librivox.org/) project, making it a suitable dataset for academic
560
- research. It contains data split into eight high-resource languages - English, German, Dutch, Spanish, French, Italian,
561
- Portuguese and Polish. The transcriptions are neither punctuated nor cased.
562
- </details>
563
- <details>
564
- <summary>
565
-
566
- #### FLEURS
567
-
568
- </summary>
569
-
570
- [FLEURS](https://huggingface.co/datasets/google/fleurs) (Few-shot Learning Evaluation of Universal Representations of
571
- Speech) is a dataset for evaluating speech recognition systems in 102 languages, including many that are classified as
572
- 'low-resource'. The data is derived from the [FLoRes-101](https://arxiv.org/abs/2106.03193) dataset, a machine
573
- translation corpus with 3001 sentence translations from English to 101 other languages. Native speakers are recorded
574
- narrating the sentence transcriptions in their native language. The recorded audio data is paired with the sentence
575
- transcriptions to yield a multilingual speech recognition over all 101 languages. The training sets contain
576
- approximately 10 hours of supervised audio-transcription data per language. Transcriptions come in two formats: un-normalised
577
- (`"raw_transcription"`) and normalised (`"transcription"`).
578
- </details>
579
-
580
- The previously mentioned blog post provides a more in-depth explanation of the main English speech recognition,
581
- multilingual speech recognition and speech translation datasets on the Hub: [A Complete Guide To Audio Datasets](https://huggingface.co/blog/audio-datasets#a-tour-of-audio-datasets-on-the-hub)
582
-
583
- You can also explore all speech recognition datasets on the Hub to find one suited for your language and needs: [ASR datasets on the Hub](https://huggingface.co/datasets?task_categories=task_categories:automatic-speech-recognition&sort=downloads).
584
- --->
585
-
586
- You can try training on these datasets individually, or mix them to form larger train sets.
587
-
588
- When mixing datasets, you should ensure the transcription format is consistent across datasets. For example, if you mix
589
- Common Voice 11 (cased + punctuated) with VoxPopuli (un-cased + punctuated), you will need to lower-case **all the text**
590
- for both training and evaluation, such that the transcriptions are consistent across training samples (un-cased + punctuated).
591
-
592
- Likewise, if mixing Common Voice 11 (cased + punctuated) with Multilingual LibriSpeech (un-cased + un-punctuated), you
593
- should make sure to remove all casing and punctuation in **all the text** for both training and evaluation, such that
594
- all transcriptions are un-cased and un-punctuated for all training samples.
595
-
596
- Having a mismatch in formatting for different training samples can reduce the final performance of your fine-tuned Whisper
597
- model.
598
-
599
- If you want to combine multiple datasets for training, you can refer to the code-snippet provided for interleaving
600
- datasets with streaming mode: [interleave_streaming_datasets.ipynb](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/interleave_streaming_datasets.ipynb).
601
-
602
- ### Custom Data (optional)
603
-
604
- In addition to publicly available data on the Hugging Face Hub, participants can also make use of their own audio data
605
- for training. When using your own audio data, please make sure that you **are allowed to use the audio data**. For
606
- instance, if the audio data is taken from media platforms, such as YouTube, please verify that the media platform and
607
- the owner of the data have given their approval to use the audio data in the context of machine learning research. If
608
- you are not sure whether the data you want to use has the appropriate licensing, please contact the Hugging Face team
609
- on Discord.
610
-
611
- <!--- TODO: VB - tutorial for adding own data via audio folder --->
612
-
613
- ## Fine-Tune Whisper
614
-
615
- Throughout the event, participants are encouraged to leverage the official pre-trained [Whisper checkpoints](https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&sort=downloads&search=whisper).
616
- The Whisper checkpoints come in five configurations of varying model sizes.
617
- The smallest four are trained on either English-only or multilingual data.
618
- The largest checkpoint is multilingual only. The checkpoints are summarised in the following table with links to the
619
- models on the Hugging Face Hub:
620
-
621
- | Size | Layers | Width | Heads | Parameters | English-only | Multilingual |
622
- |--------|--------|-------|-------|------------|------------------------------------------------------|---------------------------------------------------|
623
- | tiny | 4 | 384 | 6 | 39 M | [βœ“](https://huggingface.co/openai/whisper-tiny.en) | [βœ“](https://huggingface.co/openai/whisper-tiny) |
624
- | base | 6 | 512 | 8 | 74 M | [βœ“](https://huggingface.co/openai/whisper-base.en) | [βœ“](https://huggingface.co/openai/whisper-base) |
625
- | small | 12 | 768 | 12 | 244 M | [βœ“](https://huggingface.co/openai/whisper-small.en) | [βœ“](https://huggingface.co/openai/whisper-small) |
626
- | medium | 24 | 1024 | 16 | 769 M | [βœ“](https://huggingface.co/openai/whisper-medium.en) | [βœ“](https://huggingface.co/openai/whisper-medium) |
627
- | large | 32 | 1280 | 20 | 1550 M | x | [βœ“](https://huggingface.co/openai/whisper-large) |
628
-
629
- The English-only checkpoints should be used for English speech recognition. For all other languages, one should use the
630
- multilingual checkpoints.
631
-
632
- We recommend using the tiny model for rapid prototyping. **We advise that the small or medium checkpoints are used for
633
- fine-tuning**. These checkpoints achieve comparable performance to the large checkpoint, but can be trained much faster
634
- (and hence for much longer!).
635
-
636
- A complete guide to Whisper fine-tuning can be found in the blog post: [Fine-Tune Whisper with πŸ€— Transformers](https://huggingface.co/blog/fine-tune-whisper).
637
- While it is not necessary to have read this blog post before fine-tuning Whisper, it is strongly advised to gain
638
- familiarity with the fine-tuning code.
639
-
640
- There are three ways in which you can execute the fine-tuning code:
641
- 1. [Python Script](#python-script)
642
- 2. [Jupyter Notebook](#jupyter-notebook)
643
- 3. [Google Colab](#google-colab)
644
-
645
- 1 and 2 are applicable when running on a local GPU or cloud GPU instance (such as on Lambda). 3 applies if you have
646
- a Google Colab Pro/Pro+ subscription and want to run training in a Google Colab. The proceeding instructions for running
647
- each of these methods are quite lengthy. Feel free to read through each of them to get a better idea for which one you
648
- want to use for training. Once you've read through, we advise you pick one method and stick to it!
649
-
650
- For the walk-through, we'll assume that we're fine-tuning the Whisper model on Spanish ("es") on the Common Voice 11
651
- dataset. We'll point out where you'll need to change variables to run the script for your language of choice.
652
-
653
- Before jumping into any training, make sure you've accepted the Common Voice 11 [terms of use](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)
654
- on the Hugging Face Hub.
655
-
656
- ### Python Script
657
- *Checkout the video tutorial detailing how to fine-tune your whisper model via the CLI* πŸ‘‰οΈ [YouTube Video](https://www.youtube.com/playlist?list=PLo2EIpI_JMQuKpnFm1ntcLKP6gq0l0f1Q)
658
-
659
- 1. **Create a model repository**
660
-
661
- The steps for running training with a Python script assume that you are SSH'd into your GPU device and have set up
662
- your environment according to the previous section [Set Up an Environment](#set-up-an-environment).
663
-
664
- First, we need to create a model repository on the Hugging Face Hub. This repository will contain all the required files
665
- to reproduce the training run, alongside model weights, training logs and a README.md card. You can either create a model
666
- repository directly on the Hugging Face Hub using the link: https://huggingface.co/new Or, via the CLI. Here, we'll show
667
- how to use the CLI.
668
-
669
- Let's pick a name for our fine-tuned Whisper model: *whisper-small-es*. We can run the following command to create a
670
- repository under this name.
671
-
672
- ```bash
673
- huggingface-cli repo create whisper-small-es
674
- ```
675
- (change "es" to your language code)
676
-
677
- We can now see the model on the Hub, *e.g.* under https://huggingface.co/sanchit-gandhi/whisper-small-es
678
-
679
- Let's clone the repository so that we can place our training script and model weights inside:
680
-
681
- ```bash
682
- git lfs install
683
- git clone https://huggingface.co/sanchit-gandhi/whisper-small-es
684
- ```
685
-
686
- (be sure to change the repo address to `https://huggingface.co/<your-user-name>/<your-repo-name>`)
687
-
688
- We can then enter the repository using the `cd` command:
689
-
690
- ```bash
691
- cd whisper-small-es
692
- ```
693
-
694
- 2. **Add training script and `run` command**
695
-
696
- We encourage participants to add all the relevant files for training directly to the model repository. This way,
697
- training runs are fully reproducible.
698
-
699
- We provide a Python training script for fine-tuning Whisper with πŸ€— Datasets' streaming mode: [`run_speech_recognition_seq2seq_streaming.py`](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/run_speech_recognition_streaming.py)
700
- This script can be copied to your model repository with the following command:
701
-
702
- ```bash
703
- cp ~/community-events/whisper-fine-tuning-event/run_speech_recognition_seq2seq_streaming.py .
704
- ```
705
-
706
- This will download a copy of the training script to your model repository.
707
-
708
- We can then define the model, training and data arguments for fine-tuning:
709
-
710
- ```bash
711
- echo 'python run_speech_recognition_seq2seq_streaming.py \
712
- --model_name_or_path="openai/whisper-small" \
713
- --dataset_name="mozilla-foundation/common_voice_11_0" \
714
- --dataset_config_name="es" \
715
- --language="spanish" \
716
- --train_split_name="train+validation" \
717
- --eval_split_name="test" \
718
- --model_index_name="Whisper Small Spanish" \
719
- --max_steps="5000" \
720
- --output_dir="./" \
721
- --per_device_train_batch_size="64" \
722
- --per_device_eval_batch_size="32" \
723
- --logging_steps="25" \
724
- --learning_rate="1e-5" \
725
- --warmup_steps="500" \
726
- --evaluation_strategy="steps" \
727
- --eval_steps="1000" \
728
- --save_strategy="steps" \
729
- --save_steps="1000" \
730
- --generation_max_length="225" \
731
- --length_column_name="input_length" \
732
- --max_duration_in_seconds="30" \
733
- --text_column_name="sentence" \
734
- --freeze_feature_encoder="False" \
735
- --report_to="tensorboard" \
736
- --metric_for_best_model="wer" \
737
- --greater_is_better="False" \
738
- --load_best_model_at_end \
739
- --gradient_checkpointing \
740
- --fp16 \
741
- --overwrite_output_dir \
742
- --do_train \
743
- --do_eval \
744
- --predict_with_generate \
745
- --do_normalize_eval \
746
- --streaming \
747
- --use_auth_token \
748
- --push_to_hub' >> run.sh
749
- ```
750
-
751
- Make sure to change the `--dataset_config_name` and `--language` to the correct values for your language! See also how
752
- we combine the train and validation splits as `--train_split_name="train+validation"`. This is recommended for low-resource
753
- languages (it probably isn't strictly necessary for Spanish, where the `"train"` split for Common Voice 11 contains
754
- ample training data). We also assign a `"model_index_name"` - a pretty name that will go on the model card. If you are
755
- training on a very small dataset (< 10 hours), it is advisable to disable streaming mode: `--streaming="False"`.
756
-
757
- We provide the train/eval batch sizes for the "small" checkpoint fine-tuned on a 1x A100 device. Depending on your device and checkpoint,
758
- you might need to lower these values. Refer to the subsection [Recommended Training Configurations](#recommended-training-configurations)
759
- for suggested batch-sizes for other devices and checkpoints.
760
-
761
- 3. **Launch training πŸš€**
762
-
763
- We recommend running training through a `tmux` session. This means that training won't be interrupted when you close
764
- your SSH connection. To start a `tmux` session named `mysession`:
765
-
766
- ```bash
767
- tmux new -s mysession
768
- ```
769
- (if `tmux` is not installed, you can install it through: `sudo apt-get install tmux`)
770
-
771
- Once in the `tmux` session, we can launch training:
772
-
773
- ```bash
774
- bash run.sh
775
- ```
776
-
777
- Training should take approximately 8 hours, with a final cross-entropy loss of **1e-4** and word error rate of **32.6%**.
778
-
779
- Since we're in a `tmux` session, we're free to close our SSH window without stopping training!
780
-
781
- If you close your SSH connection and want to rejoin the `tmux` window, you can SSH into your GPU and then connect to
782
- your session with the following command:
783
-
784
- ```bash
785
- tmux a -t mysession
786
- ```
787
-
788
- It will be like you never left!
789
-
790
- `tmux` guide: https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/
791
-
792
- ### Jupyter Notebook
793
- *We've detailed these steps in a video tutorial to help you get up to speed faster* πŸ‘‰οΈ [YouTube Video](https://www.youtube.com/playlist?list=PLo2EIpI_JMQs9z-N4v8L_Jb4KF6kAkylX)
794
-
795
- 1. **SSH port forwarding**
796
-
797
- The steps for running training with a Python script assume that you have set up your environment according to the
798
- previous section [Set Up an Environment](#set-up-an-environment) and are **not** SSH'd into your GPU device. If you are
799
- SSH'd into your GPU device, you can close this SSH window and start from your local machine.
800
-
801
- The command to SSH into our GPU looked something as follows:
802
-
803
- ```bash
804
- ssh ubuntu@104.171.202.236
805
- ```
806
-
807
- When running a Jupyter Notebook, we need to "forward" the SSH port from the remote port to the local one. This amounts
808
- to adding `-L 8888:localhost:8888` to the end of our SSH command. We can SSH into our remote machine using this modified
809
- SSH command:
810
-
811
- ```bash
812
- ssh ubuntu@104.171.202.236 -L 8888:localhost:8888
813
- ```
814
-
815
- Be sure to change the `ssh ubuntu@...` part to your corresponding SSH command, it's simply the `-L 8888:localhost:8888`
816
- part added onto the end that is new. If you want to find out more about SSH port forwarding, we recommend you read the guide:
817
- [SSH/OpenSSH/PortForwarding](https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding).
818
-
819
- 2. **Create a model repository (copied from previous subsection [Python Script](#python-script))**
820
-
821
- First, we need to create a model repository on the Hugging Face Hub. This repository will contain all the required files
822
- to reproduce the training run, alongside model weights, training logs and a README.md card.
823
-
824
- You can either create a model repository directly on the Hugging Face Hub using the link: https://huggingface.co/new
825
- Or, via the CLI. Here, we'll show how to use the CLI.
826
-
827
- Let's pick a name for our fine-tuned Whisper model: *whisper-small-es*. We can run the following command to create a
828
- repository under this name.
829
-
830
- ```bash
831
- huggingface-cli repo create whisper-small-es
832
- ```
833
- (change "es" to your language code)
834
-
835
- We can now see the model on the Hub, *e.g.* under https://huggingface.co/sanchit-gandhi/whisper-small-es
836
-
837
- Let's clone the repository so that we can place our training script and model weights inside:
838
-
839
- ```bash
840
- git lfs install
841
- git clone https://huggingface.co/sanchit-gandhi/whisper-small-es
842
- ```
843
-
844
- (be sure to change the repo address to `https://huggingface.co/<your-user-name>/<your-repo-name>`)
845
-
846
- We can then enter the repository using the `cd` command:
847
-
848
- ```bash
849
- cd whisper-small-es
850
- ```
851
-
852
- 3. **Add notebook**
853
-
854
- We encourage participants to add all the training notebook directly to the model repository. This way,
855
- training runs are fully reproducible.
856
-
857
- We provide an iPython notebook for fine-tuning Whisper with πŸ€— Datasets' streaming mode: [`fine-tune-whisper-streaming.ipynb`](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/fine-tune-whisper-streaming.ipynb)
858
- This notebook can be copied to your model repository with the following command:
859
-
860
- ```bash
861
- cp ~/community-events/whisper-fine-tuning-event/fine-tune-whisper-streaming.ipynb .
862
- ```
863
-
864
- If you are fine-tuning Whisper on a very small dataset (< 10 hours), it is advised that you use the non-streaming notebook
865
- [`fine-tune-whisper-non-streaming.ipynb`](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/fine-tune-whisper-non-streaming.ipynb)
866
- (see section [Streaming Mode](#streaming-mode)). This notebook can be copied to your model repository with the following
867
- command:
868
-
869
- ```bash
870
- cp ~/community-events/whisper-fine-tuning-event/fine-tune-whisper-non-streaming.ipynb .
871
- ```
872
-
873
- 4. **Launch Jupyter**
874
-
875
- First, we need to make sure `jupyterlab` is installed:
876
-
877
- ```bash
878
- pip install jupyterlab
879
- ```
880
-
881
- We can then link `jupyter lab` to our venv:
882
- ```bash
883
- python -m ipykernel install --user --name=<your-venv-name>
884
- ```
885
-
886
- We recommend running training through a `tmux` session. This means that training won't be interrupted when you close
887
- your SSH connection. To start a `tmux` session named `mysession`:
888
-
889
- ```bash
890
- tmux new -s mysession
891
- ```
892
- (if `tmux` is not installed, you can install it through: `sudo apt-get install tmux`)
893
-
894
- Once in the `tmux` session, we can launch `jupyter lab`:
895
-
896
- ```bash
897
- jupyter lab --port 8888
898
- ```
899
-
900
- 5. **Open Jupyter in browser**
901
-
902
- Now, this is the hardest step of running training from a Jupyter Notebook! Open a second terminal window on your local
903
- machine and SSH into your GPU again. This time, it doesn't matter whether we include the `-L 8888:localhost:8888` part,
904
- the important thing is that you re-enter your GPU device in a new SSH window.
905
-
906
- Once SSH'd into your GPU, view all running `jupyter lab` sessions:
907
-
908
- ```bash
909
- jupyter lab list
910
- ```
911
-
912
- Copy the URL for the lab corresponding to port 8888 your clipboard, it will take the form `http://localhost:8888/?token=...`.
913
- On your local desktop, open a web browser window (Safari, Firefox, Chrome, etc.). Paste the URL into the browser web
914
- address bar and press Enter.
915
-
916
- VoilΓ ! We're now running a Jupyter Notebook on our GPU machine through the web browser on our local device!
917
-
918
- 6. **Open fine-tuning notebook**
919
-
920
- We can use the file explorer on the left to go to our model repository and open the Jupyter notebook `fine_tune_whisper_streaming.ipynb`.
921
- In the top right of the notebook, you'll see a small window that says "Python 3". Clicking on this window will open a
922
- dropdown menu, from which we can select a Python kernel. Select your venv from this dropdown menu. This will ensure that
923
- you run the notebook in the venv we previously set up.
924
-
925
- You can now run this notebook from start to finish and fine-tune the Whisper model as you desire πŸ€— The notebook
926
- contains pointers for where you need to change variables for your language.
927
-
928
- Since we're operating within a `tmux` session, we're free to close our SSH connection and browser window when we desire.
929
- Training won't be interrupted by closing this window. However, the notebook will cease to update, so you should make
930
- sure that training is working before closing the notebook. You can monitor training progress through your model repo
931
- on the Hugging Face Hub under the "Training Metrics" tab.
932
-
933
- ### Google Colab
934
- The Google Colab for fine-tuning Whisper is entirely self-contained. No need to set up an environment or sping up a GPU.
935
- You can access it through the following link:
936
-
937
- <a target="_blank" href="https://colab.research.google.com/github/huggingface/community-events/blob/main/whisper-fine-tuning-event/fine_tune_whisper_streaming_colab.ipynb">
938
- <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
939
- </a>
940
-
941
- ### Recommended Training Configurations
942
-
943
- In this section, we provide guidance for appropriate training and evaluation batch sizes depending on your GPU device.
944
- Since the Whisper model expects log-Mel input features of a fixed dimension, the GPU memory required by the models is
945
- the same for audio samples of any length. Thus, these recommendations should stand for all 16/40GB GPU devices. However,
946
- if you experience out-of-memory errors, we recommend reducing the `per_device_train_batch_size` by factors of 2 and
947
- increasing the `gradient_accumulation_steps` to compensate.
948
-
949
- If you want to explore methods for reducing the memory of the Whisper model, check out the section [Tips and Tricks](#tips-and-tricks).
950
-
951
- #### V100 / 16 GB GPU
952
-
953
- | Model | Train Batch Size | Gradient Acc Steps | Eval Batch size |
954
- |--------|------------------|--------------------|-----------------|
955
- | small | 16 | 2 | 8 |
956
- | medium | 2 | 16 | 1 |
957
-
958
- It is advised to run the "small" checkpoint if training on a V100 device. Running the medium checkpoint will take
959
- upwards of 12 hours for 5k training steps. We reckon you're better off training the "small" checkpoint for longer!
960
-
961
- #### A100 / 40GB GPU
962
-
963
- | Model | Train Batch Size | Gradient Acc Steps | Eval Batch size |
964
- |--------|------------------|--------------------|-----------------|
965
- | small | 64 | 1 | 32 |
966
- | medium | 32 | 1 | 16 |
967
-
968
- ### Punctuation, Casing and Normalisation
969
-
970
- When using the Python training script, removing casing for the training data is enabled by passing the flag `--do_lower_case`.
971
- Removing punctuation in the training data is achieved by passing the flag `--do_remove_punctuation`. Both of these flags
972
- default to False, and we **do not** recommend setting either of them to True. This will ensure your fine-tuned model
973
- learns to predict casing and punctuation. Normalisation is only applied during evaluation by setting the flag
974
- `--do_normalize_eval` (which defaults to True and recommend setting). Normalisation is performed according to the
975
- 'official' Whisper normaliser. This normaliser applies the following basic standardisation for non-English text:
976
- 1. Remove any phrases between matching brackets ([, ]).
977
- 2. Remove any phrases between matching parentheses ((, )).
978
- 3. Replace any markers, symbols, and punctuation characters with a space, i.e. when the Unicode category of each character in the NFKC-normalized string starts with M, S, or P.
979
- 4. Make the text lowercase.
980
- 5. Replace any successive whitespace characters with a space.
981
-
982
- Similarly, in the notebooks, removing casing in the training data is enabled by setting the variable `do_lower_case = True`,
983
- and punctuation by `do_remove_punctuation = True`. We do not recommend setting either of these to True to ensure that
984
- your model learns to predict casing and punctuation. Thus, they are set to False by default. Normalisation is only
985
- applied during evaluation by setting the variable `do_normalize_eval=True` (which we do recommend setting).
986
-
987
- ## Evaluation
988
-
989
- We'll be running a live leaderboard throughout the event to track the best performing models across all languages. The leaderboard will track your models performance across *all* the speech recognition models available on the hub for your chosen language and dataset.
990
-
991
- You can find the leaderboard [here](https://huggingface.co/spaces/autoevaluate/leaderboards?dataset=common_voice_11_0&only_verified=0&task=automatic-speech-recognition&config=th&split=train%2Bvalidation&metric=wer) πŸ“ˆ.
992
-
993
- Each participant should evaluate their fine-tuned Whisper checkpoint on the `"test"` split of the Common Voice 11
994
- dataset for their respective language. For languages that are not part of the Common Voice 11 dataset, please contact
995
- the organisers on Discord so that we can work together to find suitable evaluation data.
996
-
997
- We recommend running evaluation during training by setting your eval dataset to the `"test"` split of Common Voice 11.
998
- We'll also provide you with a standalone evaluation script so that you can test your model after training on Common Voice
999
- or other datasets of your choice.
1000
-
1001
- In addition to running evaluation while training, you can noe use your Whisper checkpoints to run evaluation on *any* speech recognition dataset on the hub. The [run_eval_whisper_streaming.py](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/run_eval_whisper_streaming.py) script loads your whisper checkpoints, runs batch inference on your specified dataset and returns the WER.
1002
-
1003
- You can use the script as follows:
1004
- ```bash
1005
- python run_eval_whisper_streaming.py --model_id="openai/whisper-tiny" --dataset="google/fleurs" --config="ar_eg" --device=0 --language="ar"
1006
- ```
1007
-
1008
- The evaluation script can be customised with the following parameters:
1009
- 1. `model_id` - Whisper model identifier e.g. `openai/whisper-tiny`
1010
- 2. `dataset` - Dataset name to evaluate the `model_id` on. Default value: `mozilla-foundation/common_voice_11_0`
1011
- 3. `config` - Config of the dataset. e.g. `'en'` for the English split of Common Voice
1012
- 4. `split` - Split of the dataset. Default value: `test`
1013
- 5. `batch_size` - Number of samples to go through each streamed batch for inference. Default value: `16`
1014
- 6. `max_eval_samples` - Max number of samples to be evaluated from the dataset. Put a lower number e.g. `64` for testing this script. **Only use this for testing the script**
1015
- 7. `streaming` - Whether you'd like to download the entire dataset or stream it during the evaluation. Default value: `True`
1016
- 8. `language` - Language you want the `model_id` to transcribe the audio in.
1017
- 9. `device` - The device to run the pipeline on. e.g. `0` for running on GPU 0. Default value: -1 for CPU.
1018
-
1019
- ## Building a Demo
1020
-
1021
- Finally, on to the fun part! Time to sit back and watch the model transcribe audio. We've created a [template Gradio demo](https://huggingface.co/spaces/whisper-event/whisper-demo)
1022
- that you can use to showcase your fine-tuned Whisper model πŸ“’
1023
-
1024
- Click the link to duplicate the template demo to your account: https://huggingface.co/spaces/whisper-event/whisper-demo?duplicate=true
1025
-
1026
- We recommend giving your space a similar name to your fine-tuned model (e.g. `whisper-demo-es`) and setting the visibility
1027
- to "Public".
1028
-
1029
- Once you've duplicated the Space to your account, click "Files and versions" -> "app.py" -> "edit". Change the model
1030
- identifier to your fine-tuned model (line 9). Scroll to the bottom of the page and click "Commit changes to `main`".
1031
- The demo will reboot, this time using your fine-tuned model. You can share this demo with your friends and family so
1032
- that they can use the model that you've trained!
1033
-
1034
- *Checkout our video tutorial to get a better understanding πŸ‘‰οΈ [YouTube Video](https://www.youtube.com/watch?v=VQYuvl6-9VE)*
1035
-
1036
- ## Communication and Problems
1037
-
1038
- If you encounter any problems or have any questions, you should use one of the following platforms
1039
- depending on your type of problem. Hugging Face is an "open-source-first" organisation, meaning
1040
- that we'll try to solve all problems in the most public and transparent way possible so that everybody
1041
- in the community benefits.
1042
-
1043
- The following paragraph summarises the platform to use for each kind of problem:
1044
-
1045
- - Problem/question/bug with the πŸ€— Datasets library that you think is a general problem that also impacts other people, please open an [Issue on Datasets](https://github.com/huggingface/datasets/issues/new?assignees=&labels=bug&template=bug-report.md&title=) and ping @sanchit-gandhi and @vaibhavs10.
1046
- - Problem/question/bug with the πŸ€— Transformers library that you think is a general problem that also impacts other people, please open an [Issue on Transformers](https://github.com/huggingface/transformers/issues/new?assignees=&labels=&template=bug-report.md&title=) and ping @sanchit-gandhi and @vaibhavs10.
1047
- - Problem/question with a modified, customised training script that is less likely to impact other people, please post your problem/question [on the forum](https://discuss.huggingface.co/) and ping @sanchit-gandhi and @vaibhavs10.
1048
- - Problem/question regarding access or set up of a Lambda GPU, please ask in the Discord channel **#lambdalabs-infra-support**.
1049
- - Other questions regarding the event, rules of the event, or if you are unsure where to post your question, please ask in the Discord channel **#events**.
1050
-
1051
- ## Talks
1052
-
1053
- We are very excited to be hosting talks from Open AI, Meta AI and Hugging Face to help you get a better understanding of the Whisper model, the VoxPopuli dataset and details about the fine-tuning event itself!
1054
-
1055
- | **Speaker** | **Topic** | **Time** | **Video** |
1056
- |------------------------------|------------------------------------------------------------|-------------------------------|---------------------------------------------------------------------------------------------------------------------------|
1057
- | Sanchit Gandhi, Hugging Face | Introduction to Whisper Fine-Tuning Event | 15:00 UTC, 2nd December, 2022 | [![Youtube](https://www.youtube.com/s/desktop/f506bd45/img/favicon_32.png)](https://www.youtube.com/watch?v=1cVBLOMlv3w) |
1058
- | Jong Wook Kim, OpenAI | [Whisper Model](https://cdn.openai.com/papers/whisper.pdf) | 16:30 UTC, 5th December, 2022 | [![Youtube](https://www.youtube.com/s/desktop/f506bd45/img/favicon_32.png)](https://www.youtube.com/watch?v=fZMiD8sDzzg ) |
1059
- | Changhan Wang, MetaAI | [VoxPopuli Dataset](https://arxiv.org/abs/2101.00390) | 17:30 UTC, 5th December, 2022 | [![Youtube](https://www.youtube.com/s/desktop/f506bd45/img/favicon_32.png)](https://www.youtube.com/watch?v=fZMiD8sDzzg ) |
1060
-
1061
- ## Tips and Tricks
1062
-
1063
- We include three memory saving tricks that you can explore to run the fine-tuning scripts with larger batch-sizes and
1064
- potentially larger checkpoints.
1065
-
1066
- ### Adam 8bit
1067
- The [Adam optimiser](https://arxiv.org/abs/1412.6980a) requires two params (betas) for every model parameter. So the memory requirement of the optimiser is
1068
- **two times** that of the model. You can switch to using an 8bit version of the Adam optimiser from [`bitsandbytes`](https://github.com/TimDettmers/bitsandbytes#bitsandbytes).
1069
- This will cast the optimiser parameters into 8bit precision, saving you a lot of memory and potentially allowing you to run bigger batch sizes.
1070
- To use Adam 8bit, you first need to pip install `bitsandbytes`:
1071
-
1072
- ```bash
1073
- pip install bitsandbytes
1074
- ```
1075
-
1076
- Then, set `optim="adamw_bnb_8bit"`, either in your `run.sh` file if running from a Python script, or when you
1077
- instantiate the Seq2SeqTrainingArguments from a Jupyter Notebook or Google Colab:
1078
-
1079
- ```python
1080
- from transformers import Seq2SeqTrainingArguments
1081
-
1082
- training_args = Seq2SeqTrainingArguments(
1083
- output_dir="./",
1084
- per_device_train_batch_size=64,
1085
- gradient_accumulation_steps=1, # increase by 2x for every 2x decrease in batch size
1086
- learning_rate=1e-5,
1087
- warmup_steps=500,
1088
- max_steps=5000,
1089
- gradient_checkpointing=True,
1090
- fp16=True,
1091
- evaluation_strategy="steps",
1092
- per_device_eval_batch_size=8,
1093
- predict_with_generate=True,
1094
- generation_max_length=225,
1095
- save_steps=1000,
1096
- eval_steps=1000,
1097
- logging_steps=25,
1098
- report_to=["tensorboard"],
1099
- load_best_model_at_end=True,
1100
- metric_for_best_model="wer",
1101
- greater_is_better=False,
1102
- push_to_hub=True,
1103
- optim="adamw_bnb_8bit"
1104
- )
1105
- ```
1106
-
1107
- ### Adafactor
1108
-
1109
- Rather than using Adam, you can use a different optimiser all together. Adam requires two optimiser params per one model
1110
- param, but [Adafactor](https://arxiv.org/abs/1804.04235) uses only one. To enable Adafactor, set `optim="adafactor"` in the
1111
- `Seq2SeqTrainingArguments`. You can expect to double your training batch size when using Adafactor compared to Adam.
1112
-
1113
- A word of caution: Adafactor is untested for fine-tuning Whisper, so we are unsure sure how
1114
- Adafactor performance compares to Adam! Typically, using Adafactor results in **slower convergence** than using Adam or
1115
- Adam 8bit. For this reason, we recommend Adafactor as an **experimental feature** only.
1116
-
1117
- ### DeepSpeed
1118
-
1119
- DeepSpeed is a framework for training larger deep learning models with limited GPU resources by optimising GPU utilisation.
1120
- We provide implementation details for DeepSpeed ZeRo Stage 2, which partitions the optimiser states (ZeRO stage 1) and gradients
1121
- (ZeRO stage 2). With DeepSpeed, it is more than possible to train the medium Whisper checkpoint on a V100, or the large
1122
- checkpoint on an A100. For more details, we refer you to the blog post by the original authors: [DeepSpeed ZeRO](https://www.microsoft.com/en-us/research/blog/zero-deepspeed-new-system-optimizations-enable-training-models-with-over-100-billion-parameters/).
1123
-
1124
- Using DeepSpeed with πŸ€— Transformers is straightforward. First, we need to install the packages πŸ€— Accelerate and DeepSpeed:
1125
-
1126
- ```bash
1127
- pip install -U accelerate deepspeed
1128
- ```
1129
-
1130
- The DeepSpeed configuration file specifies precisely what form of optimiser/gradient offloading we are going to perform.
1131
- The key to getting a huge improvement on a single GPU with DeepSpeed is to have at least the provided DeepSpeed configuration
1132
- in the configuration file [`ds_config.json`](https://github.com/huggingface/community-events/blob/main/whisper-fine-tuning-event/ds_config.json).
1133
-
1134
- You can copy the DeepSpeed configuration file to your model repository as follows:
1135
-
1136
- ```bash
1137
- cp ~/community-events/whisper-fine-tuning-event/ds_config.json .
1138
- ```
1139
-
1140
- ### Python Script
1141
-
1142
- Using DeepSpeed with the Python training script requires two changes to the `run.sh` file. Firstly, we launch the script using `deepspeed`
1143
- instead of Python. Secondly, we pass the DeepSpeed config `ds_config.json` as a training argument. The remainder of the `run.sh`
1144
- file takes the same format as using the native Trainer configuration:
1145
-
1146
- ```bash
1147
- deepspeed run_speech_recognition_seq2seq_streaming.py \
1148
- --deepspeed="ds_config.json" \
1149
- --model_name_or_path="openai/whisper-small" \
1150
- --dataset_name="mozilla-foundation/common_voice_11_0" \
1151
- --dataset_config_name="es" \
1152
- --language="spanish" \
1153
- --train_split_name="train+validation" \
1154
- --eval_split_name="test" \
1155
- --model_index_name="Whisper Small Spanish" \
1156
- --max_steps="5000" \
1157
- --output_dir="./" \
1158
- --per_device_train_batch_size="64" \
1159
- --per_device_eval_batch_size="32" \
1160
- --logging_steps="25" \
1161
- --learning_rate="1e-5" \
1162
- --warmup_steps="500" \
1163
- --evaluation_strategy="steps" \
1164
- --eval_steps="1000" \
1165
- --save_strategy="steps" \
1166
- --save_steps="1000" \
1167
- --generation_max_length="225" \
1168
- --length_column_name="input_length" \
1169
- --max_duration_in_seconds="30" \
1170
- --text_column_name="sentence" \
1171
- --freeze_feature_encoder="False" \
1172
- --report_to="tensorboard" \
1173
- --metric_for_best_model="wer" \
1174
- --greater_is_better="False" \
1175
- --load_best_model_at_end \
1176
- --gradient_checkpointing \
1177
- --fp16 \
1178
- --overwrite_output_dir \
1179
- --do_train \
1180
- --do_eval \
1181
- --predict_with_generate \
1182
- --do_normalize_eval \
1183
- --streaming \
1184
- --use_auth_token \
1185
- --push_to_hub
1186
- ```
1187
-
1188
- ### Jupyter Notebook
1189
-
1190
- Using DeepSpeed with the template Jupyter Notebooks requires two changes. Firstly, we add the following code cell at the
1191
- start of the notebook to configure the DeepSpeed environment:
1192
-
1193
- ```python
1194
- # DeepSpeed requires a distributed environment even when only one process is used.
1195
- # This emulates a launcher in the notebook
1196
- import os
1197
-
1198
- os.environ["MASTER_ADDR"] = "localhost"
1199
- os.environ["MASTER_PORT"] = "9994" # modify if RuntimeError: Address already in use
1200
- os.environ["RANK"] = "0"
1201
- os.environ["LOCAL_RANK"] = "0"
1202
- os.environ["WORLD_SIZE"] = "1"
1203
- ```
1204
-
1205
- Secondly, we pass the DeepSpeed config file to the training args:
1206
-
1207
- ```python
1208
- training_args = Seq2SeqTrainingArguments(..., deepspeed="ds_config.json")
1209
- ```
1210
-
1211
- ### Recommended Batch Sizes with DeepSpeed
1212
-
1213
- Using DeepSpeed, it is possible to fit larger batch sizes and even larger checkpoints on your device, be it a V100 or
1214
- A100. We provide recommended batch sizes for the three checkpoint sizes of interest for 16GB GPUs and 40GB GPUs. As before,
1215
- these batch sizes are only indicative: you should tune the batch size depending on your device, checkpoint and language.
1216
-
1217
- #### V100 / 16 GB GPU
1218
-
1219
- | Model | Train Batch Size | Gradient Acc Steps | Eval Batch size | Speed |
1220
- |--------|------------------|--------------------|-----------------|---------|
1221
- | small | 32 | 1 | 16 | 1.3s/it |
1222
- | medium | 16 | 1 or 2 | 8 | 2.0s/it |
1223
- | large | 8 | 2 or 4 | 4 | 3.8s/it |
1224
-
1225
- #### A100 / 40GB GPU
1226
-
1227
- | Model | Train Batch Size | Gradient Acc Steps | Eval Batch size | Speed |
1228
- |--------|------------------|--------------------|-----------------|---------|
1229
- | small | 64 | 1 | 32 | 2.3s/it |
1230
- | medium | 64 | 1 | 32 | 5.8s/it |
1231
- | large | 32 | 1 or 2 | 16 | 5.9s/it |
1232
-
1233
-
1234
- ## Scripts & Colabs
1235
-
1236
- 1. [Whirlwind tour of Whispering with πŸ€—Transformers](https://colab.research.google.com/drive/1l290cRv4RdvuLNlSeo9WexByHaNWs3s3?usp=sharing)
1237
- 2. [8bit inference for Whisper large model (6.5 gig VRAM) 🀯](https://colab.research.google.com/drive/1EMOwwfm1V1fHxH7eT1LLg7yBjhTooB6j?usp=sharing)
1238
-
1239
- <!--- TODO: VB - Move these colabs to a GitHub repo --->
1240
-
1241
- ## Feedback
1242
-
1243
- We would love to get your feedback on the event! If you have a spare ten minutes, we'd appreciate you filling out the
1244
- feedback form at: https://forms.gle/7hvrTE8NaSdQwwU68
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - generated_from_trainer
5
+ datasets:
6
+ - common_voice_11_0
7
+ metrics:
8
+ - wer
9
+ model-index:
10
+ - name: openai/whisper-tiny
11
+ results:
12
+ - task:
13
+ name: Automatic Speech Recognition
14
+ type: automatic-speech-recognition
15
+ dataset:
16
+ name: common_voice_11_0
17
+ type: common_voice_11_0
18
+ config: bn
19
+ split: test
20
+ args: bn
21
+ metrics:
22
+ - name: Wer
23
+ type: wer
24
+ value: 32.89771261927907
25
+ ---
26
+
27
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
28
+ should probably proofread and complete it, then remove this comment. -->
29
+
30
+ # openai/whisper-tiny
31
+
32
+ This model is a fine-tuned version of [openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) on the common_voice_11_0 dataset.
33
+ It achieves the following results on the evaluation set:
34
+ - Loss: 0.2314
35
+ - Wer: 32.8977
36
+
37
+ ## Model description
38
+
39
+ More information needed
40
+
41
+ ## Intended uses & limitations
42
+
43
+ More information needed
44
+
45
+ ## Training and evaluation data
46
+
47
+ More information needed
48
+
49
+ ## Training procedure
50
+
51
+ ### Training hyperparameters
52
+
53
+ The following hyperparameters were used during training:
54
+ - learning_rate: 1e-05
55
+ - train_batch_size: 16
56
+ - eval_batch_size: 8
57
+ - seed: 42
58
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
59
+ - lr_scheduler_type: linear
60
+ - lr_scheduler_warmup_steps: 500
61
+ - training_steps: 5000
62
+ - mixed_precision_training: Native AMP
63
+
64
+ ### Training results
65
+
66
+ | Training Loss | Epoch | Step | Validation Loss | Wer |
67
+ |:-------------:|:-----:|:----:|:---------------:|:-------:|
68
+ | 0.3362 | 0.96 | 1000 | 0.3536 | 45.0860 |
69
+ | 0.2395 | 1.91 | 2000 | 0.2745 | 37.1714 |
70
+ | 0.205 | 2.87 | 3000 | 0.2485 | 34.7353 |
71
+ | 0.1795 | 3.83 | 4000 | 0.2352 | 33.2469 |
72
+ | 0.1578 | 4.78 | 5000 | 0.2314 | 32.8977 |
73
+
74
+
75
+ ### Framework versions
76
+
77
+ - Transformers 4.26.0.dev0
78
+ - Pytorch 1.13.1+cu117
79
+ - Datasets 2.8.1.dev0
80
+ - Tokenizers 0.13.2