farsipal commited on
Commit
243ee10
1 Parent(s): 582d4f6

Upload fine-tune-whisper-streaming-cf11-el-v2.ipynb

Browse files

THe notebook used to run this from my laptop. It uses a whole-file local copy instead of streaming.

fine-tune-whisper-streaming-cf11-el-v2.ipynb ADDED
@@ -0,0 +1,1692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "4c6bb591",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Modifications Note\n",
9
+ "By Michael Kamfonas \\\n",
10
+ "December 3, 2022"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 1,
16
+ "id": "7f9e743c",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "import pandas as pd \n",
21
+ "from tqdm.notebook import tqdm"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "markdown",
26
+ "id": "75b58048-7d14-4fc6-8085-1fc08c81b4a6",
27
+ "metadata": {},
28
+ "source": [
29
+ "# Fine-Tune Whisper With 🤗 Transformers and Streaming Mode"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "markdown",
34
+ "id": "fbfa8ad5-4cdc-4512-9058-836cbbf65e1a",
35
+ "metadata": {},
36
+ "source": [
37
+ " This notebook is an adaptation of the colab notebook provided by Hugging Face team during the Whisper fine tuning event (December 2022). The initial version simply uses the Greek Language (el) instead of the spanish of the [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0) along with some additional comments.\n",
38
+ "Otherwise it is a near-repetition of the original. We present a step-by-step guide on fine-tuning Whisper with Hugging Face 🤗 Transformers on speech data in the Greek language (ελληνικα)! We use streaming modeto minimize local storage requirements. "
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "markdown",
43
+ "id": "afe0d503-ae4e-4aa7-9af4-dbcba52db41e",
44
+ "metadata": {},
45
+ "source": [
46
+ "## Introduction"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "markdown",
51
+ "id": "9ae91ed4-9c3e-4ade-938e-f4c2dcfbfdc0",
52
+ "metadata": {},
53
+ "source": [
54
+ "Speech recognition datasets are large. A typical speech dataset consists of approximately 100 hours of audio-transcription data, requiring upwards of 130GB of storage space for download and preparation. For most ASR researchers, this is already at the upper limit of what is feasible for disk space. So what happens when we want to train on a larger dataset? The full [LibriSpeech](https://huggingface.co/datasets/librispeech_asr) dataset consists of 960 hours of audio data. Kensho's [SPGISpeech](https://huggingface.co/datasets/kensho/spgispeech) contains 5,000 hours of audio data. ML Commons [People's Speech](https://huggingface.co/datasets/MLCommons/peoples_speech) contains **30,000+** hours of audio data! Do we need to bite the bullet and buy additional storage? Or is there a way we can train on all of these datasets with no disk drive requirements?\n",
55
+ "\n",
56
+ "When training machine learning systems, we rarely use the entire dataset at once. We typically _batch_ our data into smaller subsets of data, and pass these incrementally through our training pipeline. This is because we train our system on an accelerator device, such as a GPU or TPU, which has a memory limit typically around 16GB. We have to fit our model, optimiser and training data all on the same accelerator device, so we usually have to divide the dataset up into smaller batches and move them from the CPU to the GPU when required.\n",
57
+ "\n",
58
+ "Consequently, we don't require the entire dataset to be downloaded at once; we simply need the batch of data that we pass to our model at any one go. We can leverage this principle of partial dataset loading when preparing our dataset: rather than downloading the entire dataset at the start, we can load each piece of data as and when we need it. For each batch, we load the relevant data from a remote server and pass it through the training pipeline. For the next batch, we load the next items and again pass them through the training pipeline. At no point do we have to save data to our disk drive, we simply load them in memory and use them in our pipeline. In doing so, we only ever need as much memory as each individual batch requires.\n",
59
+ "\n",
60
+ "This is analogous to downloading a TV show versus streaming it 📺 When we download a TV show, we download the entire video offline and save it to our disk. Compare this to when we stream a TV show. Here, we don't download any part of the video to memory, but iterate over the video file and load each part in real-time as required. It's this same principle that we can apply to our ML training pipeline! We want to iterate over the dataset and load each sample of data as required.\n",
61
+ "\n",
62
+ "While the principle of partial dataset loading sounds ideal, it also seems **pretty** difficult to do. Luckily for us, 🤗 Datasets allows us to do this with minimal code changes! We'll make use of the principle of [_streaming_](https://huggingface.co/docs/datasets/stream), depicted graphically in Figure 1. Streaming does exactly this: the data is loaded progressively as we iterate over the dataset, meaning it is only loaded as and when we need it. If you're familiar with 🤗 Transformers and Datasets, the content of this notebook will be very familiar, with some small extensions to support streaming mode."
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "markdown",
67
+ "id": "1c87f76e-47be-4a5d-bc52-7b1c2e9d4f5a",
68
+ "metadata": {},
69
+ "source": [
70
+ "<figure>\n",
71
+ "<img src=\"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/streaming.gif\" alt=\"Trulli\" style=\"width:100%\">\n",
72
+ "<figcaption align = \"center\"><b>Figure 1:</b> Streaming mode. The dataset is divided into smaller subsets, with subsets loaded progressively as we iterate over the dataset. </figcaption>\n",
73
+ "</figure>"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "markdown",
78
+ "id": "21b6316e-8a55-4549-a154-66d3da2ab74a",
79
+ "metadata": {},
80
+ "source": [
81
+ "This notebook provides a guide to fine-tuning on the task of _speech recognition_, which involves learning a\n",
82
+ "mapping from speech to text. Speech recognition is divided into two categories: English-only or multilingual (all other languages). \n",
83
+ "This notebook applies to both categories, with pointers for changing between languages and datasets.\n",
84
+ "\n",
85
+ "As for our model, we'll fine-tune the Whisper model released in [September 2022](https://openai.com/blog/whisper/) by the authors \n",
86
+ "Alec Radford et al. from OpenAI. Whisper is an encoder-decoder model pre-trained on 680k hours of labelled audio-transcription data. \n",
87
+ "It achieves strong performance on many speech recognition and speech translation datasets without fine-tuning. With fine-tuning, \n",
88
+ "we aim to improve upon these results further, with many SoTA results up for grabs! For a full explanation on the Whisper model, the \n",
89
+ "reader is advised to read the blog post [Fine-Tune Whisper with 🤗 Transformers](https://huggingface.co/blog/fine-tune-whisper#introduction).\n",
90
+ "\n",
91
+ "The Whisper checkpoints come in five configurations of varying model sizes.\n",
92
+ "The smallest four are trained on either English-only or multilingual data.\n",
93
+ "The largest checkpoint is multilingual only. All nine of the pre-trained checkpoints \n",
94
+ "are available on the [Hugging Face Hub](https://huggingface.co/models?search=openai/whisper). The \n",
95
+ "checkpoints are summarised in the following table with links to the models on the Hub:\n",
96
+ "\n",
97
+ "| Size | Layers | Width | Heads | Parameters | English-only | Multilingual |\n",
98
+ "|--------|--------|-------|-------|------------|------------------------------------------------------|---------------------------------------------------|\n",
99
+ "| tiny | 4 | 384 | 6 | 39 M | [✓](https://huggingface.co/openai/whisper-tiny.en) | [✓](https://huggingface.co/openai/whisper-tiny.) |\n",
100
+ "| base | 6 | 512 | 8 | 74 M | [✓](https://huggingface.co/openai/whisper-base.en) | [✓](https://huggingface.co/openai/whisper-base) |\n",
101
+ "| small | 12 | 768 | 12 | 244 M | [✓](https://huggingface.co/openai/whisper-small.en) | [✓](https://huggingface.co/openai/whisper-small) |\n",
102
+ "| medium | 24 | 1024 | 16 | 769 M | [✓](https://huggingface.co/openai/whisper-medium.en) | [✓](https://huggingface.co/openai/whisper-medium) |\n",
103
+ "| large | 32 | 1280 | 20 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large) |\n",
104
+ "\n",
105
+ "When fine-tuning on an English dataset for speech recognition, it is recommeneded to select one of the English-only checkpoints. For any other language, it is recommended to select a multilingual checkpoint.\n",
106
+ "\n",
107
+ "For demonstration purposes, we'll fine-tune the multilingual version of the \n",
108
+ "[`\"small\"`](https://huggingface.co/openai/whisper-small) checkpoint with 244M params (~= 1GB). \n",
109
+ "As for our data, we'll train and evaluate our system on 400 hours of multilingual speech recognition data\n",
110
+ "taken from the [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)\n",
111
+ "dataset. We'll show how we can train a model on 400 hours of training data using the default disk space \n",
112
+ "that comes with a standard GPU device or Google Colab."
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "markdown",
117
+ "id": "b219c9dd-39b6-4a95-b2a1-3f547a1e7bc0",
118
+ "metadata": {},
119
+ "source": [
120
+ "## Load Dataset with or without Streaming"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "markdown",
125
+ "id": "b17a4763-4381-4157-ae38-b04a8b5f1c43",
126
+ "metadata": {},
127
+ "source": [
128
+ "This is where the magic happens! We'll first write a wrapper function around 🤗 Datasets `load_dataset` method. This function downloads the required splits using streaming mode by forcing `streaming=True` in the `load_dataset` method. Multiple splits can be combined (interleaved) by concatenating them with the \"+\" symbol when specifying the split name, e.g. `split=train+validation` will return a single split with the training and validation splits interleaved together. The function has the same arguments and key-word arguments as 🤗 Datasets `load_dataset` method, so we can use it in exactly the same way!"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": 2,
134
+ "id": "f14d4693",
135
+ "metadata": {},
136
+ "outputs": [],
137
+ "source": [
138
+ "from datasets import interleave_datasets, load_dataset\n",
139
+ "\n",
140
+ "def load_whole_dataset(dataset_name, dataset_config_name, split, **kwargs):\n",
141
+ " if \"+\" in split:\n",
142
+ " # load multiple splits separated by the `+` symbol *with* streaming mode\n",
143
+ " dataset_splits = [load_dataset(dataset_name, dataset_config_name, split=split_name, streaming=False, **kwargs) for split_name in split.split(\"+\")]\n",
144
+ " # interleave multiple splits to form one dataset\n",
145
+ " interleaved_dataset = interleave_datasets(dataset_splits)\n",
146
+ " return interleaved_dataset\n",
147
+ " else:\n",
148
+ " # load a single split *with* streaming mode\n",
149
+ " dataset = load_dataset(dataset_name, dataset_config_name, split=split, streaming=False, **kwargs)\n",
150
+ " return dataset"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": 3,
156
+ "id": "065a8cf7-e54f-4ac3-900e-609c80714fca",
157
+ "metadata": {},
158
+ "outputs": [],
159
+ "source": [
160
+ "from datasets import interleave_datasets, load_dataset\n",
161
+ "\n",
162
+ "def load_streaming_dataset(dataset_name, dataset_config_name, split, **kwargs):\n",
163
+ " if \"+\" in split:\n",
164
+ " # load multiple splits separated by the `+` symbol *with* streaming mode\n",
165
+ " dataset_splits = [load_dataset(dataset_name, dataset_config_name, split=split_name, streaming=True, **kwargs) for split_name in split.split(\"+\")]\n",
166
+ " # interleave multiple splits to form one dataset\n",
167
+ " interleaved_dataset = interleave_datasets(dataset_splits)\n",
168
+ " return interleaved_dataset\n",
169
+ " else:\n",
170
+ " # load a single split *with* streaming mode\n",
171
+ " dataset = load_dataset(dataset_name, dataset_config_name, split=split, streaming=True, **kwargs)\n",
172
+ " return dataset"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "markdown",
177
+ "id": "674429c5-0ab4-4adf-975b-621bb69eca38",
178
+ "metadata": {},
179
+ "source": [
180
+ "We'll train our system on the Greek (el) split of [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0). We can see how much training data we have by viewing the [language page](https://commonvoice.mozilla.org/en/datasets) on the Common Voice website. The Greek split has just a few hours of labelled training data. This is why we will skip streaming mode and cache the dataset on the local machine. This is useful to avoid streaming interuptions when a laptop turns off the wifi. To run in streaming mode it is best to have a LAN cable connection.\n",
181
+ "\n",
182
+ "Greek is a relatively low-resource, so we will use the `split=\"train+validation\"` for training and the `test` split for evaluation. \n",
183
+ "\n",
184
+ "Also, Common Voice 11 is a gated dataset, so we had to sign-in and accept the terms of use on the Hugging Face Hub: [mozilla-foundation/common_voice_11_0](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0). To access the dataset we use a read-access token."
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "execution_count": 4,
190
+ "id": "088fbe80",
191
+ "metadata": {},
192
+ "outputs": [
193
+ {
194
+ "name": "stderr",
195
+ "output_type": "stream",
196
+ "text": [
197
+ "Found cached dataset common_voice_11_0 (/home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f)\n",
198
+ "Found cached dataset common_voice_11_0 (/home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f)\n",
199
+ "Found cached dataset common_voice_11_0 (/home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f)\n"
200
+ ]
201
+ }
202
+ ],
203
+ "source": [
204
+ "from datasets import IterableDatasetDict\n",
205
+ "# Please use a read access token below\"\n",
206
+ "access_token = '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'\n",
207
+ "raw_datasets = IterableDatasetDict()\n",
208
+ "\n",
209
+ "raw_datasets[\"train\"] = load_whole_dataset(\"mozilla-foundation/common_voice_11_0\", \"el\", split=\"train+validation\", use_auth_token=access_token) \n",
210
+ "raw_datasets[\"test\"] = load_whole_dataset(\"mozilla-foundation/common_voice_11_0\", \"el\", split=\"test\", use_auth_token=access_token)"
211
+ ]
212
+ },
213
+ {
214
+ "cell_type": "markdown",
215
+ "id": "2d63b2d2-f68a-4d74-b7f1-5127f6d16605",
216
+ "metadata": {},
217
+ "source": [
218
+ "## Prepare Processor and Pre-Process Data"
219
+ ]
220
+ },
221
+ {
222
+ "cell_type": "markdown",
223
+ "id": "601c3099-1026-439e-93e2-5635b3ba5a73",
224
+ "metadata": {},
225
+ "source": [
226
+ "The ASR pipeline can be de-composed into three stages: \n",
227
+ "1) A feature extractor which pre-processes the raw audio-inputs\n",
228
+ "2) The model which performs the sequence-to-sequence mapping \n",
229
+ "3) A tokenizer which post-processes the model outputs to text format\n",
230
+ "\n",
231
+ "In 🤗 Transformers, the Whisper model has an associated feature extractor and tokenizer, \n",
232
+ "called [WhisperFeatureExtractor](https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperFeatureExtractor)\n",
233
+ "and [WhisperTokenizer](https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperTokenizer) \n",
234
+ "respectively. To make our lives simple, these two objects are wrapped under a single class, called the [WhisperProcessor](https://huggingface.co/docs/transformers/model_doc/whisper#transformers.WhisperProcessor). We can call the WhisperProcessor to perform \n",
235
+ "both the audio pre-processing and the text token post-processing. In doing so, we only need to keep track of two objects during training: \n",
236
+ "the `processor` and the `model`.\n",
237
+ "\n",
238
+ "If using a multilingual checkpoint, you should set the `\"language\"` to your target text language. You should also set the task to `\"transcribe\"` for speech recogntition and `\"translate\"` for speech translation. These arguments modify the behaviour of the tokenizer - they should be set correctly to ensure the target labels are encoded properly. These arguments should be omitted for English-only fine-tuning."
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "code",
243
+ "execution_count": 5,
244
+ "id": "77d9f0c5-8607-4642-a8ac-c3ab2e223ea6",
245
+ "metadata": {},
246
+ "outputs": [],
247
+ "source": [
248
+ "from transformers import WhisperProcessor\n",
249
+ "\n",
250
+ "processor = WhisperProcessor.from_pretrained(\"openai/whisper-small\", language=\"Greek\", task=\"transcribe\")"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "markdown",
255
+ "id": "381acd09-0b0f-4d04-9eb3-f028ac0e5f2c",
256
+ "metadata": {},
257
+ "source": [
258
+ "### Pre-Process Data"
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "markdown",
263
+ "id": "bf10cd3e-924e-44fc-8790-46e413de7b3d",
264
+ "metadata": {},
265
+ "source": [
266
+ "Let's have a look at the dataset features. Pay particular attention to the `\"audio\"` column - this details the sampling rate of our audio inputs:"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "code",
271
+ "execution_count": 6,
272
+ "id": "ab5a13b4-9bd4-4aa0-aef2-b3de9b762988",
273
+ "metadata": {},
274
+ "outputs": [
275
+ {
276
+ "data": {
277
+ "text/plain": [
278
+ "{'client_id': Value(dtype='string', id=None),\n",
279
+ " 'path': Value(dtype='string', id=None),\n",
280
+ " 'audio': Audio(sampling_rate=48000, mono=True, decode=True, id=None),\n",
281
+ " 'sentence': Value(dtype='string', id=None),\n",
282
+ " 'up_votes': Value(dtype='int64', id=None),\n",
283
+ " 'down_votes': Value(dtype='int64', id=None),\n",
284
+ " 'age': Value(dtype='string', id=None),\n",
285
+ " 'gender': Value(dtype='string', id=None),\n",
286
+ " 'accent': Value(dtype='string', id=None),\n",
287
+ " 'locale': Value(dtype='string', id=None),\n",
288
+ " 'segment': Value(dtype='string', id=None)}"
289
+ ]
290
+ },
291
+ "execution_count": 6,
292
+ "metadata": {},
293
+ "output_type": "execute_result"
294
+ }
295
+ ],
296
+ "source": [
297
+ "raw_datasets[\"train\"].features"
298
+ ]
299
+ },
300
+ {
301
+ "cell_type": "markdown",
302
+ "id": "5a679f05-063d-41b3-9b58-4fc9c6ccf4fd",
303
+ "metadata": {},
304
+ "source": [
305
+ "Since our input audio is sampled at 48kHz, we need to _downsample_ it to\n",
306
+ "16kHz prior to passing it to the Whisper feature extractor, 16kHz being the sampling rate expected by the Whisper model. \n",
307
+ "\n",
308
+ "We'll set the audio inputs to the correct sampling rate using dataset's \n",
309
+ "[`cast_column`](https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=cast_column#datasets.DatasetDict.cast_column)\n",
310
+ "method. This operation does not change the audio in-place, \n",
311
+ "but rather signals to `datasets` to resample audio samples _on the fly_ the \n",
312
+ "first time that they are loaded:"
313
+ ]
314
+ },
315
+ {
316
+ "cell_type": "code",
317
+ "execution_count": 7,
318
+ "id": "3ab6a724-3d1e-478b-a9e9-d2f85feb6c39",
319
+ "metadata": {},
320
+ "outputs": [],
321
+ "source": [
322
+ "from datasets import Audio\n",
323
+ "\n",
324
+ "raw_datasets = raw_datasets.cast_column(\"audio\", Audio(sampling_rate=16000))"
325
+ ]
326
+ },
327
+ {
328
+ "cell_type": "markdown",
329
+ "id": "161322c2-94f3-4d26-9e1d-d9d5202ca3cf",
330
+ "metadata": {},
331
+ "source": [
332
+ "We'll define our pre-processing strategy. We advise that you **do not** lower-case the transcriptions or remove punctuation unless mixing different datasets. This will enable you to fine-tune Whisper models that can predict punctuation and casing. Later, you will see how we can evaluate the predictions without punctuation or casing, so that the models benefit from the WER improvement obtained by normalising the transcriptions while still predicting fully formatted transcriptions."
333
+ ]
334
+ },
335
+ {
336
+ "cell_type": "code",
337
+ "execution_count": 8,
338
+ "id": "d041650e-1c48-4439-87b3-5b6f4a514107",
339
+ "metadata": {},
340
+ "outputs": [],
341
+ "source": [
342
+ "import string\n",
343
+ "import re\n",
344
+ "\n",
345
+ "do_lower_case = False\n",
346
+ "do_remove_punctuation = False\n",
347
+ "\n",
348
+ "punctuation_to_remove = string.punctuation.replace(\"'\", \"\") # don't remove apostrophes\n",
349
+ "punctuation_to_remove_regex = f\"[{''.join(punctuation_to_remove)}]\"\n",
350
+ "\n",
351
+ "if do_remove_punctuation:\n",
352
+ " print(\"Removing punctuation: \", punctuation_to_remove)"
353
+ ]
354
+ },
355
+ {
356
+ "cell_type": "markdown",
357
+ "id": "bfaa935b-a11d-497c-88c1-0c4d1bb3247b",
358
+ "metadata": {},
359
+ "source": [
360
+ "Now we can write a function to prepare our data ready for the model:\n",
361
+ "1. We load and resample the audio data by calling `batch[\"audio\"]`. As explained above, 🤗 Datasets performs any necessary resampling operations on the fly.\n",
362
+ "2. We use the feature extractor to compute the log-Mel spectrogram input features from our 1-dimensional audio array.\n",
363
+ "3. We perform any optional pre-processing (lower-case or remove punctuation).\n",
364
+ "4. We encode the transcriptions to label ids through the use of the tokenizer."
365
+ ]
366
+ },
367
+ {
368
+ "cell_type": "code",
369
+ "execution_count": 9,
370
+ "id": "c085911c-a10a-41ef-8874-306e0503e9bb",
371
+ "metadata": {},
372
+ "outputs": [],
373
+ "source": [
374
+ "def prepare_dataset(batch):\n",
375
+ " # load and (possibly) resample audio datato 16kHz\n",
376
+ " audio = batch[\"audio\"]\n",
377
+ "\n",
378
+ " # compute log-Mel input features from input audio array \n",
379
+ " batch[\"input_features\"] = processor.feature_extractor(audio[\"array\"], sampling_rate=audio[\"sampling_rate\"]).input_features[0]\n",
380
+ " # compute input length of audio sample in seconds\n",
381
+ " batch[\"input_length\"] = len(audio[\"array\"]) / audio[\"sampling_rate\"]\n",
382
+ " \n",
383
+ " # optional pre-processing steps\n",
384
+ " transcription = batch[\"sentence\"]\n",
385
+ " if do_lower_case:\n",
386
+ " transcription = transcription.lower()\n",
387
+ " if do_remove_punctuation:\n",
388
+ " transcription = re.sub(punctuation_to_remove_regex, \" \", transcription).strip()\n",
389
+ " \n",
390
+ " # encode target text to label ids\n",
391
+ " batch[\"labels\"] = processor.tokenizer(transcription).input_ids\n",
392
+ " return batch"
393
+ ]
394
+ },
395
+ {
396
+ "cell_type": "markdown",
397
+ "id": "70b319fb-2439-4ef6-a70d-a47bf41c4a13",
398
+ "metadata": {},
399
+ "source": [
400
+ "We can apply the data preparation function to all of our training examples using 🤗 Datasets' `.map` method. We'll remove all of the columns from the raw training data, leaving just the `input_features` and `labels` defined in the `prepare_dataset` function:"
401
+ ]
402
+ },
403
+ {
404
+ "cell_type": "code",
405
+ "execution_count": 10,
406
+ "id": "a37a7cdb-9013-427f-8de9-6a8d0e9dc684",
407
+ "metadata": {},
408
+ "outputs": [
409
+ {
410
+ "name": "stderr",
411
+ "output_type": "stream",
412
+ "text": [
413
+ "Loading cached processed dataset at /home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f/cache-9f32cbbc12eacd2b.arrow\n"
414
+ ]
415
+ },
416
+ {
417
+ "data": {
418
+ "application/vnd.jupyter.widget-view+json": {
419
+ "model_id": "7755f2e69af2478294688f119faef5f1",
420
+ "version_major": 2,
421
+ "version_minor": 0
422
+ },
423
+ "text/plain": [
424
+ " 0%| | 0/1696 [00:00<?, ?ex/s]"
425
+ ]
426
+ },
427
+ "metadata": {},
428
+ "output_type": "display_data"
429
+ }
430
+ ],
431
+ "source": [
432
+ "vectorized_datasets = raw_datasets.map(prepare_dataset, remove_columns=list(next(iter(raw_datasets.values())).features)).with_format(\"torch\")"
433
+ ]
434
+ },
435
+ {
436
+ "cell_type": "markdown",
437
+ "id": "3d59b37e-4950-47ec-9e3e-2cf2ec7fc750",
438
+ "metadata": {},
439
+ "source": [
440
+ "We can now define how we shuffle the data in the train split. The size of the subset we load is set by the variable `buffer_size`. You can increase or decrease this depending on your memory constraints. In this example, the `buffer_size` is set to 500, meaning 500 samples are loaded before shuffling across the subset. The larger we set this value, the closer to True offline shuffling. The `seed` is set for reproducibility:"
441
+ ]
442
+ },
443
+ {
444
+ "cell_type": "code",
445
+ "execution_count": 11,
446
+ "id": "1b145699-acfc-4b1d-93a2-a2ad3d62674c",
447
+ "metadata": {},
448
+ "outputs": [],
449
+ "source": [
450
+ "vectorized_datasets[\"train\"] = vectorized_datasets[\"train\"].shuffle(\n",
451
+ "# buffer_size=500,\n",
452
+ " seed=0,\n",
453
+ ")"
454
+ ]
455
+ },
456
+ {
457
+ "cell_type": "markdown",
458
+ "id": "666b9ef0-7909-4e1e-a419-87604d233e29",
459
+ "metadata": {},
460
+ "source": [
461
+ "Finally, we filter any training data with audio samples longer than 30s. These samples would otherwise be truncated by the Whisper feature-extractor which could affect the stability of training. We define a function that returns `True` for samples that are less than 30s, and `False` for those that are longer:"
462
+ ]
463
+ },
464
+ {
465
+ "cell_type": "code",
466
+ "execution_count": 12,
467
+ "id": "01cb25ef-4bb0-4325-9461-f59198acadf6",
468
+ "metadata": {},
469
+ "outputs": [],
470
+ "source": [
471
+ "max_input_length = 30.0\n",
472
+ "\n",
473
+ "def is_audio_in_length_range(length):\n",
474
+ " return length < max_input_length"
475
+ ]
476
+ },
477
+ {
478
+ "cell_type": "markdown",
479
+ "id": "28e37ac3-b1c5-465b-8586-7cfd8d76b0f1",
480
+ "metadata": {},
481
+ "source": [
482
+ "We apply our filter function to all samples of our training dataset through 🤗 Datasets' `.filter` method:"
483
+ ]
484
+ },
485
+ {
486
+ "cell_type": "code",
487
+ "execution_count": 13,
488
+ "id": "333f7f6e-6053-4d3b-8924-c733c79b82ac",
489
+ "metadata": {},
490
+ "outputs": [
491
+ {
492
+ "data": {
493
+ "application/vnd.jupyter.widget-view+json": {
494
+ "model_id": "92088c8534e1450187dcc57c8dfa64d8",
495
+ "version_major": 2,
496
+ "version_minor": 0
497
+ },
498
+ "text/plain": [
499
+ " 0%| | 0/4 [00:00<?, ?ba/s]"
500
+ ]
501
+ },
502
+ "metadata": {},
503
+ "output_type": "display_data"
504
+ }
505
+ ],
506
+ "source": [
507
+ "vectorized_datasets[\"train\"] = vectorized_datasets[\"train\"].filter(\n",
508
+ " is_audio_in_length_range,\n",
509
+ " input_columns=[\"input_length\"],\n",
510
+ ")"
511
+ ]
512
+ },
513
+ {
514
+ "cell_type": "markdown",
515
+ "id": "263a5a58-0239-4a25-b0df-c625fc9c5810",
516
+ "metadata": {},
517
+ "source": [
518
+ "## Training and Evaluation"
519
+ ]
520
+ },
521
+ {
522
+ "cell_type": "markdown",
523
+ "id": "a693e768-c5a6-453f-89a1-b601dcf7daf7",
524
+ "metadata": {},
525
+ "source": [
526
+ "Now that we've prepared our data, we're ready to dive into the training pipeline. \n",
527
+ "The [🤗 Trainer](https://huggingface.co/transformers/master/main_classes/trainer.html?highlight=trainer)\n",
528
+ "will do much of the heavy lifting for us. All we have to do is:\n",
529
+ "\n",
530
+ "- Define a data collator: the data collator takes our pre-processed data and prepares PyTorch tensors ready for the model.\n",
531
+ "\n",
532
+ "- Evaluation metrics: during evaluation, we want to evaluate the model using the [word error rate (WER)](https://huggingface.co/metrics/wer) metric. We need to define a `compute_metrics` function that handles this computation.\n",
533
+ "\n",
534
+ "- Load a pre-trained checkpoint: we need to load a pre-trained checkpoint and configure it correctly for training.\n",
535
+ "\n",
536
+ "- Define the training configuration: this will be used by the 🤗 Trainer to define the training schedule."
537
+ ]
538
+ },
539
+ {
540
+ "cell_type": "markdown",
541
+ "id": "8d230e6d-624c-400a-bbf5-fa660881df25",
542
+ "metadata": {},
543
+ "source": [
544
+ "### Define a Data Collator"
545
+ ]
546
+ },
547
+ {
548
+ "cell_type": "markdown",
549
+ "id": "04def221-0637-4a69-b242-d3f0c1d0ee78",
550
+ "metadata": {},
551
+ "source": [
552
+ "The data collator for a sequence-to-sequence speech model is unique in the sense that it \n",
553
+ "treats the `input_features` and `labels` independently: the `input_features` must be \n",
554
+ "handled by the feature extractor and the `labels` by the tokenizer.\n",
555
+ "\n",
556
+ "The `input_features` are already padded to 30s and converted to a log-Mel spectrogram \n",
557
+ "of fixed dimension by action of the feature extractor, so all we have to do is convert the `input_features`\n",
558
+ "to batched PyTorch tensors. We do this using the feature extractor's `.pad` method with `return_tensors=pt`.\n",
559
+ "\n",
560
+ "The `labels` on the other hand are un-padded. We first pad the sequences\n",
561
+ "to the maximum length in the batch using the tokenizer's `.pad` method. The padding tokens \n",
562
+ "are then replaced by `-100` so that these tokens are **not** taken into account when \n",
563
+ "computing the loss. We then cut the BOS token from the start of the label sequence as we \n",
564
+ "append it later during training.\n",
565
+ "\n",
566
+ "We can leverage the `WhisperProcessor` we defined earlier to perform both the \n",
567
+ "feature extractor and the tokenizer operations:"
568
+ ]
569
+ },
570
+ {
571
+ "cell_type": "code",
572
+ "execution_count": 14,
573
+ "id": "8326221e-ec13-4731-bb4e-51e5fc1486c5",
574
+ "metadata": {},
575
+ "outputs": [],
576
+ "source": [
577
+ "import torch\n",
578
+ "\n",
579
+ "from dataclasses import dataclass\n",
580
+ "from typing import Any, Dict, List, Union\n",
581
+ "\n",
582
+ "@dataclass\n",
583
+ "class DataCollatorSpeechSeq2SeqWithPadding:\n",
584
+ " processor: Any\n",
585
+ "\n",
586
+ " def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:\n",
587
+ " # split inputs and labels since they have to be of different lengths and need different padding methods\n",
588
+ " # first treat the audio inputs by simply returning torch tensors\n",
589
+ " input_features = [{\"input_features\": feature[\"input_features\"]} for feature in features]\n",
590
+ " batch = self.processor.feature_extractor.pad(input_features, return_tensors=\"pt\")\n",
591
+ "\n",
592
+ " # get the tokenized label sequences\n",
593
+ " label_features = [{\"input_ids\": feature[\"labels\"]} for feature in features]\n",
594
+ " # pad the labels to max length\n",
595
+ " labels_batch = self.processor.tokenizer.pad(label_features, return_tensors=\"pt\")\n",
596
+ "\n",
597
+ " # replace padding with -100 to ignore loss correctly\n",
598
+ " labels = labels_batch[\"input_ids\"].masked_fill(labels_batch.attention_mask.ne(1), -100)\n",
599
+ "\n",
600
+ " # if bos token is appended in previous tokenization step,\n",
601
+ " # cut bos token here as it's append later anyways\n",
602
+ " if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().cpu().item():\n",
603
+ " labels = labels[:, 1:]\n",
604
+ "\n",
605
+ " batch[\"labels\"] = labels\n",
606
+ "\n",
607
+ " return batch"
608
+ ]
609
+ },
610
+ {
611
+ "cell_type": "markdown",
612
+ "id": "3cae7dbf-8a50-456e-a3a8-7fd005390f86",
613
+ "metadata": {},
614
+ "source": [
615
+ "Let's initialise the data collator we've just defined:"
616
+ ]
617
+ },
618
+ {
619
+ "cell_type": "code",
620
+ "execution_count": 15,
621
+ "id": "fc834702-c0d3-4a96-b101-7b87be32bf42",
622
+ "metadata": {},
623
+ "outputs": [],
624
+ "source": [
625
+ "data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)"
626
+ ]
627
+ },
628
+ {
629
+ "cell_type": "markdown",
630
+ "id": "d62bb2ab-750a-45e7-82e9-61d6f4805698",
631
+ "metadata": {},
632
+ "source": [
633
+ "### Evaluation Metrics"
634
+ ]
635
+ },
636
+ {
637
+ "cell_type": "markdown",
638
+ "id": "66fee1a7-a44c-461e-b047-c3917221572e",
639
+ "metadata": {},
640
+ "source": [
641
+ "We'll use the word error rate (WER) metric, the 'de-facto' metric for assessing \n",
642
+ "ASR systems. For more information, refer to the WER [docs](https://huggingface.co/metrics/wer). We'll load the WER metric from 🤗 Evaluate:"
643
+ ]
644
+ },
645
+ {
646
+ "cell_type": "code",
647
+ "execution_count": 16,
648
+ "id": "b22b4011-f31f-4b57-b684-c52332f92890",
649
+ "metadata": {},
650
+ "outputs": [],
651
+ "source": [
652
+ "import evaluate\n",
653
+ "\n",
654
+ "metric = evaluate.load(\"wer\")"
655
+ ]
656
+ },
657
+ {
658
+ "cell_type": "markdown",
659
+ "id": "509f96d7-3f11-4f37-add9-f74a0c44f3fc",
660
+ "metadata": {},
661
+ "source": [
662
+ "We then simply have to define a function that takes our model \n",
663
+ "predictions and returns the WER metric. This function, called\n",
664
+ "`compute_metrics`, first replaces `-100` with the `pad_token_id`\n",
665
+ "in the `label_ids` (undoing the step we applied in the \n",
666
+ "data collator to ignore padded tokens correctly in the loss).\n",
667
+ "It then decodes the predicted and label ids to strings. Finally,\n",
668
+ "it computes the WER between the predictions and reference labels. \n",
669
+ "Here, we have the option of evaluating with the 'normalised' transcriptions \n",
670
+ "and predictions. We recommend you set this to `True` to benefit from the WER \n",
671
+ "improvement obtained by normalising the transcriptions."
672
+ ]
673
+ },
674
+ {
675
+ "cell_type": "code",
676
+ "execution_count": 17,
677
+ "id": "a11d1bfc-9e28-460f-a287-72d8f7bc1acb",
678
+ "metadata": {},
679
+ "outputs": [],
680
+ "source": [
681
+ "# evaluate with the 'normalised' WER\n",
682
+ "do_normalize_eval = True\n",
683
+ "\n",
684
+ "def compute_metrics(pred):\n",
685
+ " pred_ids = pred.predictions\n",
686
+ " label_ids = pred.label_ids\n",
687
+ "\n",
688
+ " # replace -100 with the pad_token_id\n",
689
+ " label_ids[label_ids == -100] = processor.tokenizer.pad_token_id\n",
690
+ "\n",
691
+ " # we do not want to group tokens when computing the metrics\n",
692
+ " pred_str = processor.tokenizer.batch_decode(pred_ids, skip_special_tokens=True, normalize=do_normalize_eval)\n",
693
+ " label_str = processor.tokenizer.batch_decode(label_ids, skip_special_tokens=True, normalize=do_normalize_eval)\n",
694
+ "\n",
695
+ " wer = 100 * metric.compute(predictions=pred_str, references=label_str)\n",
696
+ "\n",
697
+ " return {\"wer\": wer}"
698
+ ]
699
+ },
700
+ {
701
+ "cell_type": "markdown",
702
+ "id": "daf2a825-6d9f-4a23-b145-c37c0039075b",
703
+ "metadata": {},
704
+ "source": [
705
+ "### Load a Pre-Trained Checkpoint"
706
+ ]
707
+ },
708
+ {
709
+ "cell_type": "markdown",
710
+ "id": "437a97fa-4864-476b-8abc-f28b8166cfa5",
711
+ "metadata": {},
712
+ "source": [
713
+ "Now let's load the pre-trained Whisper `small` checkpoint. Again, this \n",
714
+ "is trivial through use of 🤗 Transformers!"
715
+ ]
716
+ },
717
+ {
718
+ "cell_type": "code",
719
+ "execution_count": 18,
720
+ "id": "5a10cc4b-07ec-4ebd-ac1d-7c601023594f",
721
+ "metadata": {},
722
+ "outputs": [],
723
+ "source": [
724
+ "from transformers import WhisperForConditionalGeneration\n",
725
+ "\n",
726
+ "model = WhisperForConditionalGeneration.from_pretrained(\"openai/whisper-small\")"
727
+ ]
728
+ },
729
+ {
730
+ "cell_type": "markdown",
731
+ "id": "a15ead5f-2277-4a39-937b-585c2497b2df",
732
+ "metadata": {},
733
+ "source": [
734
+ "Override generation arguments - no tokens are forced as decoder outputs (see [`forced_decoder_ids`](https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.generation_utils.GenerationMixin.generate.forced_decoder_ids)), no tokens are suppressed during generation (see [`suppress_tokens`](https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.generation_utils.GenerationMixin.generate.suppress_tokens)). Set `use_cache` to False since we're using gradient checkpointing, and the two are incompatible:"
735
+ ]
736
+ },
737
+ {
738
+ "cell_type": "code",
739
+ "execution_count": 19,
740
+ "id": "62038ba3-88ed-4fce-84db-338f50dcd04f",
741
+ "metadata": {},
742
+ "outputs": [],
743
+ "source": [
744
+ "model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language=\"el\", task=\"transcribe\")\n",
745
+ "model.config.suppress_tokens = []\n",
746
+ "model.config.use_cache = False"
747
+ ]
748
+ },
749
+ {
750
+ "cell_type": "markdown",
751
+ "id": "2178dea4-80ca-47b6-b6ea-ba1915c90c06",
752
+ "metadata": {},
753
+ "source": [
754
+ "### Define the Training Configuration"
755
+ ]
756
+ },
757
+ {
758
+ "cell_type": "markdown",
759
+ "id": "58ab7740",
760
+ "metadata": {},
761
+ "source": [
762
+ "Check to see that the GPU is available."
763
+ ]
764
+ },
765
+ {
766
+ "cell_type": "code",
767
+ "execution_count": 33,
768
+ "id": "0b483d84",
769
+ "metadata": {},
770
+ "outputs": [
771
+ {
772
+ "data": {
773
+ "text/plain": [
774
+ "True"
775
+ ]
776
+ },
777
+ "execution_count": 33,
778
+ "metadata": {},
779
+ "output_type": "execute_result"
780
+ }
781
+ ],
782
+ "source": [
783
+ "torch.cuda.is_available()"
784
+ ]
785
+ },
786
+ {
787
+ "cell_type": "markdown",
788
+ "id": "c21af1e9-0188-4134-ac82-defc7bdcc436",
789
+ "metadata": {},
790
+ "source": [
791
+ "In the final step, we define all the parameters related to training. Here, you can set the `max_steps` to train for longer. For more detail on the training arguments, refer to the Seq2SeqTrainingArguments [docs](https://huggingface.co/docs/transformers/main_classes/trainer#transformers.Seq2SeqTrainingArguments)."
792
+ ]
793
+ },
794
+ {
795
+ "cell_type": "code",
796
+ "execution_count": 47,
797
+ "id": "0ae3e9af-97b7-4aa0-ae85-20b23b5bcb3a",
798
+ "metadata": {},
799
+ "outputs": [
800
+ {
801
+ "name": "stderr",
802
+ "output_type": "stream",
803
+ "text": [
804
+ "PyTorch: setting up devices\n"
805
+ ]
806
+ }
807
+ ],
808
+ "source": [
809
+ "from transformers import Seq2SeqTrainingArguments\n",
810
+ "\n",
811
+ "training_args = Seq2SeqTrainingArguments(\n",
812
+ " output_dir=\"./whisper-small-el\",\n",
813
+ " per_device_train_batch_size=16,\n",
814
+ " gradient_accumulation_steps=4, # increase by 2x for every 2x decrease in batch size\n",
815
+ " learning_rate=1e-5,\n",
816
+ " warmup_steps=500,\n",
817
+ " max_steps=5000,\n",
818
+ " gradient_checkpointing=True,\n",
819
+ " fp16=True,\n",
820
+ " evaluation_strategy=\"steps\",\n",
821
+ " per_device_eval_batch_size=8,\n",
822
+ " predict_with_generate=True,\n",
823
+ " generation_max_length=225,\n",
824
+ " save_steps=1000,\n",
825
+ " eval_steps=1000,\n",
826
+ " logging_steps=25,\n",
827
+ " report_to=[\"tensorboard\"],\n",
828
+ " load_best_model_at_end=True,\n",
829
+ " metric_for_best_model=\"wer\",\n",
830
+ " greater_is_better=False,\n",
831
+ " push_to_hub=True,\n",
832
+ ")"
833
+ ]
834
+ },
835
+ {
836
+ "cell_type": "markdown",
837
+ "id": "b3a944d8-3112-4552-82a0-be25988b3857",
838
+ "metadata": {},
839
+ "source": [
840
+ "**Note**: if one does not want to upload the model checkpoints to the Hub, \n",
841
+ "set `push_to_hub=False`."
842
+ ]
843
+ },
844
+ {
845
+ "cell_type": "markdown",
846
+ "id": "393c883e-3e50-492c-bd58-f51dbf15ee56",
847
+ "metadata": {},
848
+ "source": [
849
+ "We then define a custom [Callback](https://huggingface.co/docs/transformers/main_classes/callback) that is called by the 🤗 Trainer on the end of each epoch. The Callback reinitialises and reshuffles the streaming dataset at the beginning of each new epoch - this gives different shuffling across our subsets for every epoch."
850
+ ]
851
+ },
852
+ {
853
+ "cell_type": "code",
854
+ "execution_count": 48,
855
+ "id": "3ac16b62-b3c0-4c68-8f3d-9ecf471534b2",
856
+ "metadata": {},
857
+ "outputs": [],
858
+ "source": [
859
+ "from transformers import TrainerCallback\n",
860
+ "from transformers.trainer_pt_utils import IterableDatasetShard\n",
861
+ "from torch.utils.data import IterableDataset\n",
862
+ "\n",
863
+ "# trainer callback to reinitialise and reshuffle the streamable datasets at the beginning of each epoch\n",
864
+ "class ShuffleCallback(TrainerCallback):\n",
865
+ " def on_epoch_begin(self, args, state, control, train_dataloader, **kwargs):\n",
866
+ " if isinstance(train_dataloader.dataset, IterableDatasetShard):\n",
867
+ " pass # set_epoch() is handled by the Trainer\n",
868
+ " elif isinstance(train_dataloader.dataset, IterableDataset):\n",
869
+ " train_dataloader.dataset.set_epoch(train_dataloader.dataset._epoch + 1)"
870
+ ]
871
+ },
872
+ {
873
+ "cell_type": "markdown",
874
+ "id": "bac29114-d226-4f54-97cf-8718c9f94e1e",
875
+ "metadata": {},
876
+ "source": [
877
+ "We can forward the training arguments to the 🤗 Trainer along with our model,\n",
878
+ "dataset, data collator, `compute_metrics` function and custom callback:"
879
+ ]
880
+ },
881
+ {
882
+ "cell_type": "code",
883
+ "execution_count": 63,
884
+ "id": "67a221dd",
885
+ "metadata": {},
886
+ "outputs": [
887
+ {
888
+ "name": "stdout",
889
+ "output_type": "stream",
890
+ "text": [
891
+ "Successfully logged out.\n",
892
+ "Token is valid.\n",
893
+ "Your token has been saved in your configured git credential helpers (store).\n",
894
+ "Your token has been saved to /home/farsipal/.huggingface/token\n",
895
+ "Login successful\n"
896
+ ]
897
+ }
898
+ ],
899
+ "source": [
900
+ "from huggingface_hub import logout,login,create_repo\n",
901
+ "logout()\n",
902
+ "access_token='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'\n",
903
+ "login(access_token,add_to_git_credential=True)\n"
904
+ ]
905
+ },
906
+ {
907
+ "cell_type": "code",
908
+ "execution_count": 64,
909
+ "id": "d546d7fe-0543-479a-b708-2ebabec19493",
910
+ "metadata": {},
911
+ "outputs": [
912
+ {
913
+ "name": "stderr",
914
+ "output_type": "stream",
915
+ "text": [
916
+ "Cloning https://huggingface.co/farsipal/whisper-small-el into local empty directory.\n",
917
+ "max_steps is given, it will override any value given in num_train_epochs\n",
918
+ "Using cuda_amp half precision backend\n"
919
+ ]
920
+ }
921
+ ],
922
+ "source": [
923
+ "from transformers import Seq2SeqTrainer\n",
924
+ "\n",
925
+ "trainer = Seq2SeqTrainer(\n",
926
+ " args=training_args,\n",
927
+ " model=model,\n",
928
+ " train_dataset=vectorized_datasets[\"train\"],\n",
929
+ " eval_dataset=vectorized_datasets[\"test\"],\n",
930
+ " data_collator=data_collator,\n",
931
+ " compute_metrics=compute_metrics,\n",
932
+ " tokenizer=processor,\n",
933
+ " callbacks=[ShuffleCallback()],\n",
934
+ ")"
935
+ ]
936
+ },
937
+ {
938
+ "cell_type": "code",
939
+ "execution_count": 65,
940
+ "id": "ef64a928",
941
+ "metadata": {},
942
+ "outputs": [
943
+ {
944
+ "data": {
945
+ "text/plain": [
946
+ "'./whisper-small-el'"
947
+ ]
948
+ },
949
+ "execution_count": 65,
950
+ "metadata": {},
951
+ "output_type": "execute_result"
952
+ }
953
+ ],
954
+ "source": [
955
+ "training_args.output_dir"
956
+ ]
957
+ },
958
+ {
959
+ "cell_type": "markdown",
960
+ "id": "67ab88c3-7091-4e51-8ad5-f5cacbe18449",
961
+ "metadata": {},
962
+ "source": [
963
+ "We'll save the model and processor to the output directory before training:"
964
+ ]
965
+ },
966
+ {
967
+ "cell_type": "code",
968
+ "execution_count": 66,
969
+ "id": "a1ccb9ed-cbc8-4419-91c0-651e9424b672",
970
+ "metadata": {},
971
+ "outputs": [
972
+ {
973
+ "name": "stderr",
974
+ "output_type": "stream",
975
+ "text": [
976
+ "Configuration saved in ./whisper-small-el/config.json\n",
977
+ "Model weights saved in ./whisper-small-el/pytorch_model.bin\n",
978
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
979
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
980
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
981
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n"
982
+ ]
983
+ }
984
+ ],
985
+ "source": [
986
+ "model.save_pretrained(training_args.output_dir)\n",
987
+ "processor.save_pretrained(training_args.output_dir)"
988
+ ]
989
+ },
990
+ {
991
+ "cell_type": "markdown",
992
+ "id": "7f404cf9-4345-468c-8196-4bd101d9bd51",
993
+ "metadata": {},
994
+ "source": [
995
+ "### Training"
996
+ ]
997
+ },
998
+ {
999
+ "cell_type": "markdown",
1000
+ "id": "5e8b8d56-5a70-4f68-bd2e-f0752d0bd112",
1001
+ "metadata": {},
1002
+ "source": [
1003
+ "Training will take approximately 5-10 hours depending on your GPU. The peak GPU memory for the given training configuration is approximately 36GB. \n",
1004
+ "Depending on your GPU, it is possible that you will encounter a CUDA `\"out-of-memory\"` error when you launch training. \n",
1005
+ "In this case, you can reduce the `per_device_train_batch_size` incrementally by factors of 2 \n",
1006
+ "and employ [`gradient_accumulation_steps`](https://huggingface.co/docs/transformers/main_classes/trainer#transformers.Seq2SeqTrainingArguments.gradient_accumulation_steps)\n",
1007
+ "to compensate.\n",
1008
+ "\n",
1009
+ "To launch training, simply execute:"
1010
+ ]
1011
+ },
1012
+ {
1013
+ "cell_type": "code",
1014
+ "execution_count": 67,
1015
+ "id": "ee8b7b8e-1c9a-4d77-9137-1778a629e6de",
1016
+ "metadata": {},
1017
+ "outputs": [
1018
+ {
1019
+ "name": "stderr",
1020
+ "output_type": "stream",
1021
+ "text": [
1022
+ "The following columns in the training set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1023
+ "/home/farsipal/miniconda3/envs/whisper/lib/python3.10/site-packages/transformers/optimization.py:306: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning\n",
1024
+ " warnings.warn(\n",
1025
+ "***** Running training *****\n",
1026
+ " Num examples = 3402\n",
1027
+ " Num Epochs = 95\n",
1028
+ " Instantaneous batch size per device = 16\n",
1029
+ " Total train batch size (w. parallel, distributed & accumulation) = 64\n",
1030
+ " Gradient Accumulation steps = 4\n",
1031
+ " Total optimization steps = 5000\n",
1032
+ " Number of trainable parameters = 241734912\n"
1033
+ ]
1034
+ },
1035
+ {
1036
+ "data": {
1037
+ "application/vnd.jupyter.widget-view+json": {
1038
+ "model_id": "3115582278564297898102c9e3604bc9",
1039
+ "version_major": 2,
1040
+ "version_minor": 0
1041
+ },
1042
+ "text/plain": [
1043
+ " 0%| | 0/5000 [00:00<?, ?it/s]"
1044
+ ]
1045
+ },
1046
+ "metadata": {},
1047
+ "output_type": "display_data"
1048
+ },
1049
+ {
1050
+ "name": "stdout",
1051
+ "output_type": "stream",
1052
+ "text": [
1053
+ "{'loss': 2.9261, 'learning_rate': 4.6000000000000004e-07, 'epoch': 0.47}\n",
1054
+ "{'loss': 2.3236, 'learning_rate': 9.600000000000001e-07, 'epoch': 0.94}\n",
1055
+ "{'loss': 1.5525, 'learning_rate': 1.46e-06, 'epoch': 1.41}\n",
1056
+ "{'loss': 1.0065, 'learning_rate': 1.9600000000000003e-06, 'epoch': 1.88}\n",
1057
+ "{'loss': 0.8887, 'learning_rate': 2.46e-06, 'epoch': 2.36}\n",
1058
+ "{'loss': 0.7771, 'learning_rate': 2.96e-06, 'epoch': 2.83}\n",
1059
+ "{'loss': 0.6976, 'learning_rate': 3.46e-06, 'epoch': 3.3}\n",
1060
+ "{'loss': 0.5892, 'learning_rate': 3.96e-06, 'epoch': 3.77}\n",
1061
+ "{'loss': 0.4458, 'learning_rate': 4.440000000000001e-06, 'epoch': 4.24}\n",
1062
+ "{'loss': 0.208, 'learning_rate': 4.92e-06, 'epoch': 4.71}\n",
1063
+ "{'loss': 0.154, 'learning_rate': 5.420000000000001e-06, 'epoch': 5.19}\n",
1064
+ "{'loss': 0.1177, 'learning_rate': 5.92e-06, 'epoch': 5.66}\n",
1065
+ "{'loss': 0.1037, 'learning_rate': 6.42e-06, 'epoch': 6.13}\n",
1066
+ "{'loss': 0.0691, 'learning_rate': 6.92e-06, 'epoch': 6.6}\n",
1067
+ "{'loss': 0.064, 'learning_rate': 7.420000000000001e-06, 'epoch': 7.08}\n",
1068
+ "{'loss': 0.0423, 'learning_rate': 7.92e-06, 'epoch': 7.54}\n",
1069
+ "{'loss': 0.0419, 'learning_rate': 8.42e-06, 'epoch': 8.02}\n",
1070
+ "{'loss': 0.025, 'learning_rate': 8.920000000000001e-06, 'epoch': 8.49}\n",
1071
+ "{'loss': 0.0296, 'learning_rate': 9.42e-06, 'epoch': 8.96}\n",
1072
+ "{'loss': 0.0151, 'learning_rate': 9.920000000000002e-06, 'epoch': 9.43}\n",
1073
+ "{'loss': 0.0171, 'learning_rate': 9.953333333333333e-06, 'epoch': 9.9}\n",
1074
+ "{'loss': 0.0137, 'learning_rate': 9.89777777777778e-06, 'epoch': 10.38}\n",
1075
+ "{'loss': 0.012, 'learning_rate': 9.842222222222223e-06, 'epoch': 10.85}\n",
1076
+ "{'loss': 0.0107, 'learning_rate': 9.786666666666667e-06, 'epoch': 11.32}\n",
1077
+ "{'loss': 0.0131, 'learning_rate': 9.731111111111113e-06, 'epoch': 11.79}\n",
1078
+ "{'loss': 0.0086, 'learning_rate': 9.675555555555555e-06, 'epoch': 12.26}\n",
1079
+ "{'loss': 0.0065, 'learning_rate': 9.620000000000001e-06, 'epoch': 12.73}\n",
1080
+ "{'loss': 0.0068, 'learning_rate': 9.564444444444445e-06, 'epoch': 13.21}\n",
1081
+ "{'loss': 0.0068, 'learning_rate': 9.508888888888889e-06, 'epoch': 13.68}\n",
1082
+ "{'loss': 0.0065, 'learning_rate': 9.453333333333335e-06, 'epoch': 14.15}\n",
1083
+ "{'loss': 0.0054, 'learning_rate': 9.397777777777779e-06, 'epoch': 14.62}\n",
1084
+ "{'loss': 0.0049, 'learning_rate': 9.342222222222223e-06, 'epoch': 15.09}\n",
1085
+ "{'loss': 0.0051, 'learning_rate': 9.286666666666667e-06, 'epoch': 15.56}\n",
1086
+ "{'loss': 0.0046, 'learning_rate': 9.231111111111111e-06, 'epoch': 16.04}\n",
1087
+ "{'loss': 0.0035, 'learning_rate': 9.175555555555557e-06, 'epoch': 16.51}\n",
1088
+ "{'loss': 0.0047, 'learning_rate': 9.12e-06, 'epoch': 16.98}\n",
1089
+ "{'loss': 0.0031, 'learning_rate': 9.064444444444447e-06, 'epoch': 17.45}\n",
1090
+ "{'loss': 0.004, 'learning_rate': 9.008888888888889e-06, 'epoch': 17.92}\n",
1091
+ "{'loss': 0.0025, 'learning_rate': 8.953333333333335e-06, 'epoch': 18.39}\n"
1092
+ ]
1093
+ },
1094
+ {
1095
+ "name": "stderr",
1096
+ "output_type": "stream",
1097
+ "text": [
1098
+ "The following columns in the evaluation set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1099
+ "***** Running Evaluation *****\n",
1100
+ " Num examples = 1696\n",
1101
+ " Batch size = 8\n"
1102
+ ]
1103
+ },
1104
+ {
1105
+ "name": "stdout",
1106
+ "output_type": "stream",
1107
+ "text": [
1108
+ "{'loss': 0.0024, 'learning_rate': 8.897777777777779e-06, 'epoch': 18.86}\n"
1109
+ ]
1110
+ },
1111
+ {
1112
+ "data": {
1113
+ "application/vnd.jupyter.widget-view+json": {
1114
+ "model_id": "6ce81b2f44ef4da2abc48c2fce67df86",
1115
+ "version_major": 2,
1116
+ "version_minor": 0
1117
+ },
1118
+ "text/plain": [
1119
+ " 0%| | 0/212 [00:00<?, ?it/s]"
1120
+ ]
1121
+ },
1122
+ "metadata": {},
1123
+ "output_type": "display_data"
1124
+ },
1125
+ {
1126
+ "name": "stderr",
1127
+ "output_type": "stream",
1128
+ "text": [
1129
+ "Saving model checkpoint to ./whisper-small-el/checkpoint-1000\n",
1130
+ "Configuration saved in ./whisper-small-el/checkpoint-1000/config.json\n"
1131
+ ]
1132
+ },
1133
+ {
1134
+ "name": "stdout",
1135
+ "output_type": "stream",
1136
+ "text": [
1137
+ "{'eval_loss': 0.4176926016807556, 'eval_wer': 20.50520059435364, 'eval_runtime': 1208.8349, 'eval_samples_per_second': 1.403, 'eval_steps_per_second': 0.175, 'epoch': 18.86}\n"
1138
+ ]
1139
+ },
1140
+ {
1141
+ "name": "stderr",
1142
+ "output_type": "stream",
1143
+ "text": [
1144
+ "Model weights saved in ./whisper-small-el/checkpoint-1000/pytorch_model.bin\n",
1145
+ "Feature extractor saved in ./whisper-small-el/checkpoint-1000/preprocessor_config.json\n",
1146
+ "tokenizer config file saved in ./whisper-small-el/checkpoint-1000/tokenizer_config.json\n",
1147
+ "Special tokens file saved in ./whisper-small-el/checkpoint-1000/special_tokens_map.json\n",
1148
+ "added tokens file saved in ./whisper-small-el/checkpoint-1000/added_tokens.json\n",
1149
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
1150
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
1151
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
1152
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n"
1153
+ ]
1154
+ },
1155
+ {
1156
+ "name": "stdout",
1157
+ "output_type": "stream",
1158
+ "text": [
1159
+ "{'loss': 0.0026, 'learning_rate': 8.842222222222223e-06, 'epoch': 19.34}\n",
1160
+ "{'loss': 0.002, 'learning_rate': 8.786666666666668e-06, 'epoch': 19.81}\n",
1161
+ "{'loss': 0.0022, 'learning_rate': 8.73111111111111e-06, 'epoch': 20.28}\n",
1162
+ "{'loss': 0.0021, 'learning_rate': 8.675555555555556e-06, 'epoch': 20.75}\n",
1163
+ "{'loss': 0.0013, 'learning_rate': 8.62e-06, 'epoch': 21.23}\n",
1164
+ "{'loss': 0.0013, 'learning_rate': 8.564444444444445e-06, 'epoch': 21.69}\n",
1165
+ "{'loss': 0.0018, 'learning_rate': 8.50888888888889e-06, 'epoch': 22.17}\n",
1166
+ "{'loss': 0.0026, 'learning_rate': 8.453333333333334e-06, 'epoch': 22.64}\n",
1167
+ "{'loss': 0.0014, 'learning_rate': 8.397777777777778e-06, 'epoch': 23.11}\n",
1168
+ "{'loss': 0.0019, 'learning_rate': 8.342222222222222e-06, 'epoch': 23.58}\n",
1169
+ "{'loss': 0.002, 'learning_rate': 8.286666666666668e-06, 'epoch': 24.06}\n",
1170
+ "{'loss': 0.0017, 'learning_rate': 8.231111111111112e-06, 'epoch': 24.53}\n",
1171
+ "{'loss': 0.0017, 'learning_rate': 8.175555555555556e-06, 'epoch': 25.0}\n",
1172
+ "{'loss': 0.0016, 'learning_rate': 8.120000000000002e-06, 'epoch': 25.47}\n",
1173
+ "{'loss': 0.0013, 'learning_rate': 8.064444444444444e-06, 'epoch': 25.94}\n",
1174
+ "{'loss': 0.0012, 'learning_rate': 8.00888888888889e-06, 'epoch': 26.41}\n",
1175
+ "{'loss': 0.0019, 'learning_rate': 7.953333333333334e-06, 'epoch': 26.88}\n",
1176
+ "{'loss': 0.0019, 'learning_rate': 7.897777777777778e-06, 'epoch': 27.36}\n",
1177
+ "{'loss': 0.0021, 'learning_rate': 7.842222222222224e-06, 'epoch': 27.83}\n",
1178
+ "{'loss': 0.0019, 'learning_rate': 7.786666666666666e-06, 'epoch': 28.3}\n",
1179
+ "{'loss': 0.001, 'learning_rate': 7.731111111111112e-06, 'epoch': 28.77}\n",
1180
+ "{'loss': 0.0016, 'learning_rate': 7.675555555555556e-06, 'epoch': 29.24}\n",
1181
+ "{'loss': 0.001, 'learning_rate': 7.620000000000001e-06, 'epoch': 29.71}\n",
1182
+ "{'loss': 0.0008, 'learning_rate': 7.564444444444446e-06, 'epoch': 30.19}\n",
1183
+ "{'loss': 0.0007, 'learning_rate': 7.50888888888889e-06, 'epoch': 30.66}\n",
1184
+ "{'loss': 0.0006, 'learning_rate': 7.453333333333334e-06, 'epoch': 31.13}\n",
1185
+ "{'loss': 0.0007, 'learning_rate': 7.3977777777777786e-06, 'epoch': 31.6}\n",
1186
+ "{'loss': 0.0009, 'learning_rate': 7.342222222222223e-06, 'epoch': 32.08}\n",
1187
+ "{'loss': 0.001, 'learning_rate': 7.2866666666666675e-06, 'epoch': 32.54}\n",
1188
+ "{'loss': 0.001, 'learning_rate': 7.231111111111112e-06, 'epoch': 33.02}\n",
1189
+ "{'loss': 0.0024, 'learning_rate': 7.1755555555555556e-06, 'epoch': 33.49}\n",
1190
+ "{'loss': 0.0016, 'learning_rate': 7.1200000000000004e-06, 'epoch': 33.96}\n",
1191
+ "{'loss': 0.0009, 'learning_rate': 7.0644444444444445e-06, 'epoch': 34.43}\n",
1192
+ "{'loss': 0.001, 'learning_rate': 7.008888888888889e-06, 'epoch': 34.9}\n",
1193
+ "{'loss': 0.0008, 'learning_rate': 6.953333333333334e-06, 'epoch': 35.38}\n",
1194
+ "{'loss': 0.0006, 'learning_rate': 6.897777777777779e-06, 'epoch': 35.85}\n",
1195
+ "{'loss': 0.0006, 'learning_rate': 6.842222222222222e-06, 'epoch': 36.32}\n",
1196
+ "{'loss': 0.0006, 'learning_rate': 6.786666666666667e-06, 'epoch': 36.79}\n",
1197
+ "{'loss': 0.0005, 'learning_rate': 6.731111111111111e-06, 'epoch': 37.26}\n"
1198
+ ]
1199
+ },
1200
+ {
1201
+ "name": "stderr",
1202
+ "output_type": "stream",
1203
+ "text": [
1204
+ "The following columns in the evaluation set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1205
+ "***** Running Evaluation *****\n",
1206
+ " Num examples = 1696\n",
1207
+ " Batch size = 8\n"
1208
+ ]
1209
+ },
1210
+ {
1211
+ "name": "stdout",
1212
+ "output_type": "stream",
1213
+ "text": [
1214
+ "{'loss': 0.0008, 'learning_rate': 6.675555555555556e-06, 'epoch': 37.73}\n"
1215
+ ]
1216
+ },
1217
+ {
1218
+ "data": {
1219
+ "application/vnd.jupyter.widget-view+json": {
1220
+ "model_id": "2157ca403a984a209a3d514c3a181cc4",
1221
+ "version_major": 2,
1222
+ "version_minor": 0
1223
+ },
1224
+ "text/plain": [
1225
+ " 0%| | 0/212 [00:00<?, ?it/s]"
1226
+ ]
1227
+ },
1228
+ "metadata": {},
1229
+ "output_type": "display_data"
1230
+ },
1231
+ {
1232
+ "name": "stderr",
1233
+ "output_type": "stream",
1234
+ "text": [
1235
+ "Saving model checkpoint to ./whisper-small-el/checkpoint-2000\n",
1236
+ "Configuration saved in ./whisper-small-el/checkpoint-2000/config.json\n"
1237
+ ]
1238
+ },
1239
+ {
1240
+ "name": "stdout",
1241
+ "output_type": "stream",
1242
+ "text": [
1243
+ "{'eval_loss': 0.4465649724006653, 'eval_wer': 20.50520059435364, 'eval_runtime': 1066.3393, 'eval_samples_per_second': 1.59, 'eval_steps_per_second': 0.199, 'epoch': 37.73}\n"
1244
+ ]
1245
+ },
1246
+ {
1247
+ "name": "stderr",
1248
+ "output_type": "stream",
1249
+ "text": [
1250
+ "Model weights saved in ./whisper-small-el/checkpoint-2000/pytorch_model.bin\n",
1251
+ "Feature extractor saved in ./whisper-small-el/checkpoint-2000/preprocessor_config.json\n",
1252
+ "tokenizer config file saved in ./whisper-small-el/checkpoint-2000/tokenizer_config.json\n",
1253
+ "Special tokens file saved in ./whisper-small-el/checkpoint-2000/special_tokens_map.json\n",
1254
+ "added tokens file saved in ./whisper-small-el/checkpoint-2000/added_tokens.json\n",
1255
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
1256
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
1257
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
1258
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n"
1259
+ ]
1260
+ },
1261
+ {
1262
+ "name": "stdout",
1263
+ "output_type": "stream",
1264
+ "text": [
1265
+ "{'loss': 0.0004, 'learning_rate': 6.620000000000001e-06, 'epoch': 38.21}\n",
1266
+ "{'loss': 0.0004, 'learning_rate': 6.564444444444446e-06, 'epoch': 38.68}\n",
1267
+ "{'loss': 0.0003, 'learning_rate': 6.508888888888889e-06, 'epoch': 39.15}\n",
1268
+ "{'loss': 0.0003, 'learning_rate': 6.453333333333334e-06, 'epoch': 39.62}\n",
1269
+ "{'loss': 0.0003, 'learning_rate': 6.397777777777778e-06, 'epoch': 40.09}\n",
1270
+ "{'loss': 0.0003, 'learning_rate': 6.342222222222223e-06, 'epoch': 40.56}\n",
1271
+ "{'loss': 0.0003, 'learning_rate': 6.286666666666668e-06, 'epoch': 41.04}\n",
1272
+ "{'loss': 0.0003, 'learning_rate': 6.231111111111111e-06, 'epoch': 41.51}\n",
1273
+ "{'loss': 0.0003, 'learning_rate': 6.175555555555556e-06, 'epoch': 41.98}\n",
1274
+ "{'loss': 0.0003, 'learning_rate': 6.120000000000001e-06, 'epoch': 42.45}\n",
1275
+ "{'loss': 0.0003, 'learning_rate': 6.064444444444445e-06, 'epoch': 42.92}\n",
1276
+ "{'loss': 0.0002, 'learning_rate': 6.00888888888889e-06, 'epoch': 43.39}\n",
1277
+ "{'loss': 0.0002, 'learning_rate': 5.9533333333333345e-06, 'epoch': 43.86}\n",
1278
+ "{'loss': 0.0002, 'learning_rate': 5.897777777777778e-06, 'epoch': 44.34}\n",
1279
+ "{'loss': 0.0002, 'learning_rate': 5.8422222222222226e-06, 'epoch': 44.81}\n",
1280
+ "{'loss': 0.0002, 'learning_rate': 5.7866666666666674e-06, 'epoch': 45.28}\n",
1281
+ "{'loss': 0.0002, 'learning_rate': 5.7311111111111115e-06, 'epoch': 45.75}\n",
1282
+ "{'loss': 0.0002, 'learning_rate': 5.675555555555556e-06, 'epoch': 46.23}\n",
1283
+ "{'loss': 0.0002, 'learning_rate': 5.620000000000001e-06, 'epoch': 46.69}\n",
1284
+ "{'loss': 0.0002, 'learning_rate': 5.5644444444444444e-06, 'epoch': 47.17}\n",
1285
+ "{'loss': 0.0002, 'learning_rate': 5.508888888888889e-06, 'epoch': 47.64}\n",
1286
+ "{'loss': 0.0002, 'learning_rate': 5.453333333333334e-06, 'epoch': 48.11}\n",
1287
+ "{'loss': 0.0002, 'learning_rate': 5.397777777777778e-06, 'epoch': 48.58}\n",
1288
+ "{'loss': 0.0002, 'learning_rate': 5.342222222222223e-06, 'epoch': 49.06}\n",
1289
+ "{'loss': 0.0002, 'learning_rate': 5.286666666666666e-06, 'epoch': 49.53}\n",
1290
+ "{'loss': 0.0002, 'learning_rate': 5.231111111111111e-06, 'epoch': 50.0}\n",
1291
+ "{'loss': 0.0002, 'learning_rate': 5.175555555555556e-06, 'epoch': 50.47}\n",
1292
+ "{'loss': 0.0002, 'learning_rate': 5.12e-06, 'epoch': 50.94}\n",
1293
+ "{'loss': 0.0002, 'learning_rate': 5.064444444444445e-06, 'epoch': 51.41}\n",
1294
+ "{'loss': 0.0002, 'learning_rate': 5.00888888888889e-06, 'epoch': 51.88}\n",
1295
+ "{'loss': 0.0002, 'learning_rate': 4.953333333333334e-06, 'epoch': 52.36}\n",
1296
+ "{'loss': 0.0002, 'learning_rate': 4.897777777777778e-06, 'epoch': 52.83}\n",
1297
+ "{'loss': 0.0002, 'learning_rate': 4.842222222222223e-06, 'epoch': 53.3}\n",
1298
+ "{'loss': 0.0002, 'learning_rate': 4.786666666666667e-06, 'epoch': 53.77}\n",
1299
+ "{'loss': 0.0002, 'learning_rate': 4.731111111111112e-06, 'epoch': 54.24}\n",
1300
+ "{'loss': 0.0002, 'learning_rate': 4.675555555555556e-06, 'epoch': 54.71}\n",
1301
+ "{'loss': 0.0002, 'learning_rate': 4.620000000000001e-06, 'epoch': 55.19}\n",
1302
+ "{'loss': 0.0002, 'learning_rate': 4.564444444444445e-06, 'epoch': 55.66}\n",
1303
+ "{'loss': 0.0002, 'learning_rate': 4.50888888888889e-06, 'epoch': 56.13}\n"
1304
+ ]
1305
+ },
1306
+ {
1307
+ "name": "stderr",
1308
+ "output_type": "stream",
1309
+ "text": [
1310
+ "The following columns in the evaluation set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1311
+ "***** Running Evaluation *****\n",
1312
+ " Num examples = 1696\n",
1313
+ " Batch size = 8\n"
1314
+ ]
1315
+ },
1316
+ {
1317
+ "name": "stdout",
1318
+ "output_type": "stream",
1319
+ "text": [
1320
+ "{'loss': 0.0002, 'learning_rate': 4.453333333333334e-06, 'epoch': 56.6}\n"
1321
+ ]
1322
+ },
1323
+ {
1324
+ "data": {
1325
+ "application/vnd.jupyter.widget-view+json": {
1326
+ "model_id": "33958e66c2404b7385d2fa2f4fb83d60",
1327
+ "version_major": 2,
1328
+ "version_minor": 0
1329
+ },
1330
+ "text/plain": [
1331
+ " 0%| | 0/212 [00:00<?, ?it/s]"
1332
+ ]
1333
+ },
1334
+ "metadata": {},
1335
+ "output_type": "display_data"
1336
+ },
1337
+ {
1338
+ "name": "stderr",
1339
+ "output_type": "stream",
1340
+ "text": [
1341
+ "Saving model checkpoint to ./whisper-small-el/checkpoint-3000\n",
1342
+ "Configuration saved in ./whisper-small-el/checkpoint-3000/config.json\n"
1343
+ ]
1344
+ },
1345
+ {
1346
+ "name": "stdout",
1347
+ "output_type": "stream",
1348
+ "text": [
1349
+ "{'eval_loss': 0.4917678236961365, 'eval_wer': 20.28231797919762, 'eval_runtime': 1056.0083, 'eval_samples_per_second': 1.606, 'eval_steps_per_second': 0.201, 'epoch': 56.6}\n"
1350
+ ]
1351
+ },
1352
+ {
1353
+ "name": "stderr",
1354
+ "output_type": "stream",
1355
+ "text": [
1356
+ "Model weights saved in ./whisper-small-el/checkpoint-3000/pytorch_model.bin\n",
1357
+ "Feature extractor saved in ./whisper-small-el/checkpoint-3000/preprocessor_config.json\n",
1358
+ "tokenizer config file saved in ./whisper-small-el/checkpoint-3000/tokenizer_config.json\n",
1359
+ "Special tokens file saved in ./whisper-small-el/checkpoint-3000/special_tokens_map.json\n",
1360
+ "added tokens file saved in ./whisper-small-el/checkpoint-3000/added_tokens.json\n",
1361
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
1362
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
1363
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
1364
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n"
1365
+ ]
1366
+ },
1367
+ {
1368
+ "name": "stdout",
1369
+ "output_type": "stream",
1370
+ "text": [
1371
+ "{'loss': 0.0002, 'learning_rate': 4.397777777777778e-06, 'epoch': 57.08}\n",
1372
+ "{'loss': 0.0001, 'learning_rate': 4.3422222222222225e-06, 'epoch': 57.54}\n",
1373
+ "{'loss': 0.0002, 'learning_rate': 4.2866666666666666e-06, 'epoch': 58.02}\n",
1374
+ "{'loss': 0.0001, 'learning_rate': 4.2311111111111114e-06, 'epoch': 58.49}\n",
1375
+ "{'loss': 0.0001, 'learning_rate': 4.175555555555556e-06, 'epoch': 58.96}\n",
1376
+ "{'loss': 0.0001, 'learning_rate': 4.12e-06, 'epoch': 59.43}\n",
1377
+ "{'loss': 0.0001, 'learning_rate': 4.064444444444444e-06, 'epoch': 59.9}\n",
1378
+ "{'loss': 0.0001, 'learning_rate': 4.008888888888889e-06, 'epoch': 60.38}\n",
1379
+ "{'loss': 0.0001, 'learning_rate': 3.953333333333333e-06, 'epoch': 60.85}\n",
1380
+ "{'loss': 0.0001, 'learning_rate': 3.897777777777778e-06, 'epoch': 61.32}\n",
1381
+ "{'loss': 0.0001, 'learning_rate': 3.842222222222223e-06, 'epoch': 61.79}\n",
1382
+ "{'loss': 0.0001, 'learning_rate': 3.7866666666666667e-06, 'epoch': 62.26}\n",
1383
+ "{'loss': 0.0001, 'learning_rate': 3.7311111111111116e-06, 'epoch': 62.73}\n",
1384
+ "{'loss': 0.0001, 'learning_rate': 3.675555555555556e-06, 'epoch': 63.21}\n",
1385
+ "{'loss': 0.0001, 'learning_rate': 3.62e-06, 'epoch': 63.68}\n",
1386
+ "{'loss': 0.0001, 'learning_rate': 3.564444444444445e-06, 'epoch': 64.15}\n",
1387
+ "{'loss': 0.0001, 'learning_rate': 3.508888888888889e-06, 'epoch': 64.62}\n",
1388
+ "{'loss': 0.0001, 'learning_rate': 3.4533333333333334e-06, 'epoch': 65.09}\n",
1389
+ "{'loss': 0.0001, 'learning_rate': 3.3977777777777783e-06, 'epoch': 65.56}\n",
1390
+ "{'loss': 0.0001, 'learning_rate': 3.3422222222222224e-06, 'epoch': 66.04}\n",
1391
+ "{'loss': 0.0001, 'learning_rate': 3.286666666666667e-06, 'epoch': 66.51}\n",
1392
+ "{'loss': 0.0001, 'learning_rate': 3.2311111111111117e-06, 'epoch': 66.98}\n",
1393
+ "{'loss': 0.0001, 'learning_rate': 3.1755555555555557e-06, 'epoch': 67.45}\n",
1394
+ "{'loss': 0.0001, 'learning_rate': 3.12e-06, 'epoch': 67.92}\n",
1395
+ "{'loss': 0.0001, 'learning_rate': 3.064444444444445e-06, 'epoch': 68.39}\n",
1396
+ "{'loss': 0.0001, 'learning_rate': 3.008888888888889e-06, 'epoch': 68.86}\n",
1397
+ "{'loss': 0.0001, 'learning_rate': 2.9533333333333336e-06, 'epoch': 69.34}\n",
1398
+ "{'loss': 0.0001, 'learning_rate': 2.8977777777777785e-06, 'epoch': 69.81}\n",
1399
+ "{'loss': 0.0001, 'learning_rate': 2.8422222222222225e-06, 'epoch': 70.28}\n",
1400
+ "{'loss': 0.0001, 'learning_rate': 2.786666666666667e-06, 'epoch': 70.75}\n",
1401
+ "{'loss': 0.0001, 'learning_rate': 2.7311111111111114e-06, 'epoch': 71.23}\n",
1402
+ "{'loss': 0.0001, 'learning_rate': 2.675555555555556e-06, 'epoch': 71.69}\n",
1403
+ "{'loss': 0.0001, 'learning_rate': 2.6200000000000003e-06, 'epoch': 72.17}\n",
1404
+ "{'loss': 0.0001, 'learning_rate': 2.5644444444444444e-06, 'epoch': 72.64}\n",
1405
+ "{'loss': 0.0001, 'learning_rate': 2.5088888888888892e-06, 'epoch': 73.11}\n",
1406
+ "{'loss': 0.0001, 'learning_rate': 2.4533333333333333e-06, 'epoch': 73.58}\n",
1407
+ "{'loss': 0.0001, 'learning_rate': 2.397777777777778e-06, 'epoch': 74.06}\n",
1408
+ "{'loss': 0.0001, 'learning_rate': 2.342222222222222e-06, 'epoch': 74.53}\n",
1409
+ "{'loss': 0.0001, 'learning_rate': 2.2866666666666667e-06, 'epoch': 75.0}\n"
1410
+ ]
1411
+ },
1412
+ {
1413
+ "name": "stderr",
1414
+ "output_type": "stream",
1415
+ "text": [
1416
+ "The following columns in the evaluation set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1417
+ "***** Running Evaluation *****\n",
1418
+ " Num examples = 1696\n",
1419
+ " Batch size = 8\n"
1420
+ ]
1421
+ },
1422
+ {
1423
+ "name": "stdout",
1424
+ "output_type": "stream",
1425
+ "text": [
1426
+ "{'loss': 0.0001, 'learning_rate': 2.2311111111111115e-06, 'epoch': 75.47}\n"
1427
+ ]
1428
+ },
1429
+ {
1430
+ "data": {
1431
+ "application/vnd.jupyter.widget-view+json": {
1432
+ "model_id": "507f9932304c4c0da0e7b5a6f73ebabc",
1433
+ "version_major": 2,
1434
+ "version_minor": 0
1435
+ },
1436
+ "text/plain": [
1437
+ " 0%| | 0/212 [00:00<?, ?it/s]"
1438
+ ]
1439
+ },
1440
+ "metadata": {},
1441
+ "output_type": "display_data"
1442
+ },
1443
+ {
1444
+ "name": "stderr",
1445
+ "output_type": "stream",
1446
+ "text": [
1447
+ "Saving model checkpoint to ./whisper-small-el/checkpoint-4000\n",
1448
+ "Configuration saved in ./whisper-small-el/checkpoint-4000/config.json\n"
1449
+ ]
1450
+ },
1451
+ {
1452
+ "name": "stdout",
1453
+ "output_type": "stream",
1454
+ "text": [
1455
+ "{'eval_loss': 0.5101690888404846, 'eval_wer': 20.22659732540862, 'eval_runtime': 1395.457, 'eval_samples_per_second': 1.215, 'eval_steps_per_second': 0.152, 'epoch': 75.47}\n"
1456
+ ]
1457
+ },
1458
+ {
1459
+ "name": "stderr",
1460
+ "output_type": "stream",
1461
+ "text": [
1462
+ "Model weights saved in ./whisper-small-el/checkpoint-4000/pytorch_model.bin\n",
1463
+ "Feature extractor saved in ./whisper-small-el/checkpoint-4000/preprocessor_config.json\n",
1464
+ "tokenizer config file saved in ./whisper-small-el/checkpoint-4000/tokenizer_config.json\n",
1465
+ "Special tokens file saved in ./whisper-small-el/checkpoint-4000/special_tokens_map.json\n",
1466
+ "added tokens file saved in ./whisper-small-el/checkpoint-4000/added_tokens.json\n",
1467
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
1468
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
1469
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
1470
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n"
1471
+ ]
1472
+ },
1473
+ {
1474
+ "name": "stdout",
1475
+ "output_type": "stream",
1476
+ "text": [
1477
+ "{'loss': 0.0001, 'learning_rate': 2.1755555555555556e-06, 'epoch': 75.94}\n",
1478
+ "{'loss': 0.0001, 'learning_rate': 2.12e-06, 'epoch': 76.41}\n",
1479
+ "{'loss': 0.0001, 'learning_rate': 2.064444444444445e-06, 'epoch': 76.88}\n",
1480
+ "{'loss': 0.0001, 'learning_rate': 2.008888888888889e-06, 'epoch': 77.36}\n",
1481
+ "{'loss': 0.0001, 'learning_rate': 1.9533333333333334e-06, 'epoch': 77.83}\n",
1482
+ "{'loss': 0.0001, 'learning_rate': 1.8977777777777779e-06, 'epoch': 78.3}\n",
1483
+ "{'loss': 0.0001, 'learning_rate': 1.8422222222222225e-06, 'epoch': 78.77}\n",
1484
+ "{'loss': 0.0001, 'learning_rate': 1.7866666666666668e-06, 'epoch': 79.24}\n",
1485
+ "{'loss': 0.0001, 'learning_rate': 1.7311111111111112e-06, 'epoch': 79.71}\n",
1486
+ "{'loss': 0.0001, 'learning_rate': 1.675555555555556e-06, 'epoch': 80.19}\n",
1487
+ "{'loss': 0.0001, 'learning_rate': 1.6200000000000002e-06, 'epoch': 80.66}\n",
1488
+ "{'loss': 0.0001, 'learning_rate': 1.5644444444444446e-06, 'epoch': 81.13}\n",
1489
+ "{'loss': 0.0001, 'learning_rate': 1.5088888888888889e-06, 'epoch': 81.6}\n",
1490
+ "{'loss': 0.0001, 'learning_rate': 1.4533333333333335e-06, 'epoch': 82.08}\n",
1491
+ "{'loss': 0.0001, 'learning_rate': 1.397777777777778e-06, 'epoch': 82.54}\n",
1492
+ "{'loss': 0.0001, 'learning_rate': 1.3422222222222222e-06, 'epoch': 83.02}\n",
1493
+ "{'loss': 0.0001, 'learning_rate': 1.286666666666667e-06, 'epoch': 83.49}\n",
1494
+ "{'loss': 0.0001, 'learning_rate': 1.2311111111111112e-06, 'epoch': 83.96}\n",
1495
+ "{'loss': 0.0001, 'learning_rate': 1.1755555555555556e-06, 'epoch': 84.43}\n",
1496
+ "{'loss': 0.0001, 'learning_rate': 1.12e-06, 'epoch': 84.9}\n",
1497
+ "{'loss': 0.0001, 'learning_rate': 1.0644444444444445e-06, 'epoch': 85.38}\n",
1498
+ "{'loss': 0.0001, 'learning_rate': 1.008888888888889e-06, 'epoch': 85.85}\n",
1499
+ "{'loss': 0.0001, 'learning_rate': 9.533333333333335e-07, 'epoch': 86.32}\n",
1500
+ "{'loss': 0.0001, 'learning_rate': 8.977777777777778e-07, 'epoch': 86.79}\n",
1501
+ "{'loss': 0.0001, 'learning_rate': 8.422222222222224e-07, 'epoch': 87.26}\n",
1502
+ "{'loss': 0.0001, 'learning_rate': 7.866666666666667e-07, 'epoch': 87.73}\n",
1503
+ "{'loss': 0.0001, 'learning_rate': 7.311111111111112e-07, 'epoch': 88.21}\n",
1504
+ "{'loss': 0.0001, 'learning_rate': 6.755555555555555e-07, 'epoch': 88.68}\n",
1505
+ "{'loss': 0.0001, 'learning_rate': 6.200000000000001e-07, 'epoch': 89.15}\n",
1506
+ "{'loss': 0.0001, 'learning_rate': 5.644444444444445e-07, 'epoch': 89.62}\n",
1507
+ "{'loss': 0.0001, 'learning_rate': 5.088888888888889e-07, 'epoch': 90.09}\n",
1508
+ "{'loss': 0.0001, 'learning_rate': 4.533333333333334e-07, 'epoch': 90.56}\n",
1509
+ "{'loss': 0.0001, 'learning_rate': 3.9777777777777783e-07, 'epoch': 91.04}\n",
1510
+ "{'loss': 0.0001, 'learning_rate': 3.422222222222223e-07, 'epoch': 91.51}\n",
1511
+ "{'loss': 0.0001, 'learning_rate': 2.866666666666667e-07, 'epoch': 91.98}\n",
1512
+ "{'loss': 0.0001, 'learning_rate': 2.3111111111111112e-07, 'epoch': 92.45}\n",
1513
+ "{'loss': 0.0001, 'learning_rate': 1.7555555555555558e-07, 'epoch': 92.92}\n",
1514
+ "{'loss': 0.0001, 'learning_rate': 1.2000000000000002e-07, 'epoch': 93.39}\n",
1515
+ "{'loss': 0.0001, 'learning_rate': 6.444444444444445e-08, 'epoch': 93.86}\n"
1516
+ ]
1517
+ },
1518
+ {
1519
+ "name": "stderr",
1520
+ "output_type": "stream",
1521
+ "text": [
1522
+ "The following columns in the evaluation set don't have a corresponding argument in `WhisperForConditionalGeneration.forward` and have been ignored: input_length. If input_length are not expected by `WhisperForConditionalGeneration.forward`, you can safely ignore this message.\n",
1523
+ "***** Running Evaluation *****\n",
1524
+ " Num examples = 1696\n",
1525
+ " Batch size = 8\n"
1526
+ ]
1527
+ },
1528
+ {
1529
+ "name": "stdout",
1530
+ "output_type": "stream",
1531
+ "text": [
1532
+ "{'loss': 0.0001, 'learning_rate': 8.88888888888889e-09, 'epoch': 94.34}\n"
1533
+ ]
1534
+ },
1535
+ {
1536
+ "data": {
1537
+ "application/vnd.jupyter.widget-view+json": {
1538
+ "model_id": "f3e87f05b92f4a9cb548389a5bf114e4",
1539
+ "version_major": 2,
1540
+ "version_minor": 0
1541
+ },
1542
+ "text/plain": [
1543
+ " 0%| | 0/212 [00:00<?, ?it/s]"
1544
+ ]
1545
+ },
1546
+ "metadata": {},
1547
+ "output_type": "display_data"
1548
+ },
1549
+ {
1550
+ "name": "stderr",
1551
+ "output_type": "stream",
1552
+ "text": [
1553
+ "Saving model checkpoint to ./whisper-small-el/checkpoint-5000\n",
1554
+ "Configuration saved in ./whisper-small-el/checkpoint-5000/config.json\n"
1555
+ ]
1556
+ },
1557
+ {
1558
+ "name": "stdout",
1559
+ "output_type": "stream",
1560
+ "text": [
1561
+ "{'eval_loss': 0.5180559158325195, 'eval_wer': 20.208023774145616, 'eval_runtime': 1172.7039, 'eval_samples_per_second': 1.446, 'eval_steps_per_second': 0.181, 'epoch': 94.34}\n"
1562
+ ]
1563
+ },
1564
+ {
1565
+ "name": "stderr",
1566
+ "output_type": "stream",
1567
+ "text": [
1568
+ "Model weights saved in ./whisper-small-el/checkpoint-5000/pytorch_model.bin\n",
1569
+ "Feature extractor saved in ./whisper-small-el/checkpoint-5000/preprocessor_config.json\n",
1570
+ "tokenizer config file saved in ./whisper-small-el/checkpoint-5000/tokenizer_config.json\n",
1571
+ "Special tokens file saved in ./whisper-small-el/checkpoint-5000/special_tokens_map.json\n",
1572
+ "added tokens file saved in ./whisper-small-el/checkpoint-5000/added_tokens.json\n",
1573
+ "Feature extractor saved in ./whisper-small-el/preprocessor_config.json\n",
1574
+ "tokenizer config file saved in ./whisper-small-el/tokenizer_config.json\n",
1575
+ "Special tokens file saved in ./whisper-small-el/special_tokens_map.json\n",
1576
+ "added tokens file saved in ./whisper-small-el/added_tokens.json\n",
1577
+ "\n",
1578
+ "\n",
1579
+ "Training completed. Do not forget to share your model on huggingface.co/models =)\n",
1580
+ "\n",
1581
+ "\n",
1582
+ "Loading best model from ./whisper-small-el/checkpoint-5000 (score: 20.208023774145616).\n"
1583
+ ]
1584
+ },
1585
+ {
1586
+ "name": "stdout",
1587
+ "output_type": "stream",
1588
+ "text": [
1589
+ "{'train_runtime': 73232.697, 'train_samples_per_second': 4.37, 'train_steps_per_second': 0.068, 'train_loss': 0.06146362095708027, 'epoch': 94.34}\n"
1590
+ ]
1591
+ },
1592
+ {
1593
+ "data": {
1594
+ "text/plain": [
1595
+ "TrainOutput(global_step=5000, training_loss=0.06146362095708027, metrics={'train_runtime': 73232.697, 'train_samples_per_second': 4.37, 'train_steps_per_second': 0.068, 'train_loss': 0.06146362095708027, 'epoch': 94.34})"
1596
+ ]
1597
+ },
1598
+ "execution_count": 67,
1599
+ "metadata": {},
1600
+ "output_type": "execute_result"
1601
+ }
1602
+ ],
1603
+ "source": [
1604
+ "trainer.train()"
1605
+ ]
1606
+ },
1607
+ {
1608
+ "cell_type": "markdown",
1609
+ "id": "747c6a6e",
1610
+ "metadata": {
1611
+ "pycharm": {
1612
+ "name": "#%% md\n"
1613
+ }
1614
+ },
1615
+ "source": [
1616
+ "(note that training may take some time to commence as we load the first training data samples with streaming mode)"
1617
+ ]
1618
+ },
1619
+ {
1620
+ "cell_type": "markdown",
1621
+ "id": "810ced54-7187-4a06-b2fe-ba6dcca94dc3",
1622
+ "metadata": {},
1623
+ "source": [
1624
+ "We can label our checkpoint with the `whisper-event` tag on push by setting the appropriate key-word arguments (kwargs):"
1625
+ ]
1626
+ },
1627
+ {
1628
+ "cell_type": "code",
1629
+ "execution_count": null,
1630
+ "id": "6dd0e310-9b07-4133-ac14-2ed2d7524e22",
1631
+ "metadata": {},
1632
+ "outputs": [],
1633
+ "source": [
1634
+ "kwargs = {\n",
1635
+ " \"dataset_tags\": \"mozilla-foundation/common_voice_11_0\",\n",
1636
+ " \"dataset\": \"Common Voice 11.0\", \n",
1637
+ " \"language\": \"el\",\n",
1638
+ " \"model_name\": \"Whisper Small - Greek (el)\", \n",
1639
+ " \"finetuned_from\": \"openai/whisper-small\",\n",
1640
+ " \"tasks\": \"automatic-speech-recognition\",\n",
1641
+ " \"tags\": \"whisper-event\",\n",
1642
+ " #\"output_dir\": \"./save\",\n",
1643
+ "}"
1644
+ ]
1645
+ },
1646
+ {
1647
+ "cell_type": "markdown",
1648
+ "id": "090d676a-f944-4297-a938-a40eda0b2b68",
1649
+ "metadata": {},
1650
+ "source": [
1651
+ "The training results can now be uploaded to the Hub. To do so, execute the `push_to_hub` command:"
1652
+ ]
1653
+ },
1654
+ {
1655
+ "cell_type": "code",
1656
+ "execution_count": null,
1657
+ "id": "95737cda-c5dd-4887-a4d0-dfcb0d61d977",
1658
+ "metadata": {},
1659
+ "outputs": [],
1660
+ "source": [
1661
+ "\n",
1662
+ "trainer.push_to_hub(**kwargs)"
1663
+ ]
1664
+ }
1665
+ ],
1666
+ "metadata": {
1667
+ "kernelspec": {
1668
+ "display_name": "Python 3.10.8 ('whisper')",
1669
+ "language": "python",
1670
+ "name": "python3"
1671
+ },
1672
+ "language_info": {
1673
+ "codemirror_mode": {
1674
+ "name": "ipython",
1675
+ "version": 3
1676
+ },
1677
+ "file_extension": ".py",
1678
+ "mimetype": "text/x-python",
1679
+ "name": "python",
1680
+ "nbconvert_exporter": "python",
1681
+ "pygments_lexer": "ipython3",
1682
+ "version": "3.10.8"
1683
+ },
1684
+ "vscode": {
1685
+ "interpreter": {
1686
+ "hash": "56df8cc7a7ee396247f1aaa79087483e047b61a4716ebb1fc601848c69339422"
1687
+ }
1688
+ }
1689
+ },
1690
+ "nbformat": 4,
1691
+ "nbformat_minor": 5
1692
+ }