{ "cells": [ { "cell_type": "markdown", "id": "4c6bb591", "metadata": {}, "source": [ "# Modifications Note\n", "By Michael Kamfonas \\\n", "December 3, 2022" ] }, { "cell_type": "markdown", "id": "7f9e743c", "metadata": {}, "source": [] }, { "cell_type": "markdown", "id": "75b58048-7d14-4fc6-8085-1fc08c81b4a6", "metadata": {}, "source": [ "# Fine-Tune Whisper With 🤗 Transformers and Streaming Mode" ] }, { "cell_type": "markdown", "id": "fbfa8ad5-4cdc-4512-9058-836cbbf65e1a", "metadata": {}, "source": [ " 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", "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. " ] }, { "cell_type": "markdown", "id": "afe0d503-ae4e-4aa7-9af4-dbcba52db41e", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "id": "9ae91ed4-9c3e-4ade-938e-f4c2dcfbfdc0", "metadata": {}, "source": [ "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", "\n", "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", "\n", "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", "\n", "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", "\n", "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." ] }, { "cell_type": "markdown", "id": "1c87f76e-47be-4a5d-bc52-7b1c2e9d4f5a", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "id": "21b6316e-8a55-4549-a154-66d3da2ab74a", "metadata": {}, "source": [ "This notebook provides a guide to fine-tuning on the task of _speech recognition_, which involves learning a\n", "mapping from speech to text. Speech recognition is divided into two categories: English-only or multilingual (all other languages). \n", "This notebook applies to both categories, with pointers for changing between languages and datasets.\n", "\n", "As for our model, we'll fine-tune the Whisper model released in [September 2022](https://openai.com/blog/whisper/) by the authors \n", "Alec Radford et al. from OpenAI. Whisper is an encoder-decoder model pre-trained on 680k hours of labelled audio-transcription data. \n", "It achieves strong performance on many speech recognition and speech translation datasets without fine-tuning. With fine-tuning, \n", "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", "reader is advised to read the blog post [Fine-Tune Whisper with 🤗 Transformers](https://huggingface.co/blog/fine-tune-whisper#introduction).\n", "\n", "The Whisper checkpoints come in five configurations of varying model sizes.\n", "The smallest four are trained on either English-only or multilingual data.\n", "The largest checkpoint is multilingual only. All nine of the pre-trained checkpoints \n", "are available on the [Hugging Face Hub](https://huggingface.co/models?search=openai/whisper). The \n", "checkpoints are summarised in the following table with links to the models on the Hub:\n", "\n", "| Size | Layers | Width | Heads | Parameters | English-only | Multilingual |\n", "|--------|--------|-------|-------|------------|------------------------------------------------------|---------------------------------------------------|\n", "| tiny | 4 | 384 | 6 | 39 M | [✓](https://huggingface.co/openai/whisper-tiny.en) | [✓](https://huggingface.co/openai/whisper-tiny.) |\n", "| base | 6 | 512 | 8 | 74 M | [✓](https://huggingface.co/openai/whisper-base.en) | [✓](https://huggingface.co/openai/whisper-base) |\n", "| small | 12 | 768 | 12 | 244 M | [✓](https://huggingface.co/openai/whisper-small.en) | [✓](https://huggingface.co/openai/whisper-small) |\n", "| medium | 24 | 1024 | 16 | 769 M | [✓](https://huggingface.co/openai/whisper-medium.en) | [✓](https://huggingface.co/openai/whisper-medium) |\n", "| large | 32 | 1280 | 20 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large) |\n", "\n", "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", "\n", "For demonstration purposes, we'll fine-tune the multilingual version of the \n", "[`\"small\"`](https://huggingface.co/openai/whisper-small) checkpoint with 244M params (~= 1GB). \n", "As for our data, we'll train and evaluate our system on 400 hours of multilingual speech recognition data\n", "taken from the [Common Voice 11](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)\n", "dataset. We'll show how we can train a model on 400 hours of training data using the default disk space \n", "that comes with a standard GPU device or Google Colab." ] }, { "cell_type": "markdown", "id": "b219c9dd-39b6-4a95-b2a1-3f547a1e7bc0", "metadata": {}, "source": [ "## Load Dataset with or without Streaming" ] }, { "cell_type": "markdown", "id": "b17a4763-4381-4157-ae38-b04a8b5f1c43", "metadata": {}, "source": [ "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!" ] }, { "cell_type": "code", "execution_count": 2, "id": "f14d4693", "metadata": {}, "outputs": [], "source": [ "from datasets import interleave_datasets, load_dataset\n", "\n", "def load_whole_dataset(dataset_name, dataset_config_name, split, **kwargs):\n", " if \"+\" in split:\n", " # load multiple splits separated by the `+` symbol *with* streaming mode\n", " dataset_splits = [load_dataset(dataset_name, dataset_config_name, split=split_name, streaming=False, **kwargs) for split_name in split.split(\"+\")]\n", " # interleave multiple splits to form one dataset\n", " interleaved_dataset = interleave_datasets(dataset_splits)\n", " return interleaved_dataset\n", " else:\n", " # load a single split *with* streaming mode\n", " dataset = load_dataset(dataset_name, dataset_config_name, split=split, streaming=False, **kwargs)\n", " return dataset" ] }, { "cell_type": "code", "execution_count": 3, "id": "065a8cf7-e54f-4ac3-900e-609c80714fca", "metadata": {}, "outputs": [], "source": [ "from datasets import interleave_datasets, load_dataset\n", "\n", "def load_streaming_dataset(dataset_name, dataset_config_name, split, **kwargs):\n", " if \"+\" in split:\n", " # load multiple splits separated by the `+` symbol *with* streaming mode\n", " dataset_splits = [load_dataset(dataset_name, dataset_config_name, split=split_name, streaming=True, **kwargs) for split_name in split.split(\"+\")]\n", " # interleave multiple splits to form one dataset\n", " interleaved_dataset = interleave_datasets(dataset_splits)\n", " return interleaved_dataset\n", " else:\n", " # load a single split *with* streaming mode\n", " dataset = load_dataset(dataset_name, dataset_config_name, split=split, streaming=True, **kwargs)\n", " return dataset" ] }, { "cell_type": "markdown", "id": "674429c5-0ab4-4adf-975b-621bb69eca38", "metadata": {}, "source": [ "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", "\n", "Greek is a relatively low-resource, so we will use the `split=\"train+validation\"` for training and the `test` split for evaluation. \n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 4, "id": "088fbe80", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading and preparing dataset common_voice_11_0/el to /home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2a11974336c749c4a9511bf4b1e56239", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/12.2k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b4bc8de2022a485c94a42475ed95dc00", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data files: 0%| | 0/5 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "738b251ba0674ce8a9f21c34237f8af6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/57.4M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b9f7b07fad0843deb65f3596a41b12f1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/51.0M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e7a5610b156e42c5bb678522a4b62e40", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/50.9M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "51fa43dacd8e4086b4039f4b95d74dc7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/238M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1cf192a319b341b783eec8dec55c92bb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/23.3M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " " ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d2b89d2b4b8542dea9d4941f86a8b491", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #4: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b735034e5be74885ad91c803af3fc355", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #2: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e00ff4c4439f4169bf88f566dd197a62", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #1: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ec15eb805c1c44869a1c1427fa4c6ebf", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #3: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "13cd667dc1f2473fbb1bc9b054c77d3f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #0: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "435ad1f24a4c49df901bb681f1d76ba8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data files: 0%| | 0/5 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "93a452c0264e4804b022bf27232aeedc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/482k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "99120139f4444c8083a44c7f303b4c20", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/423k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bf369c2c838e43d68715c8c621f20281", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/410k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "85bf983d315342b6b378fa430f19b5a2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/2.22M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ca193ca6b4ea4abea33668d1360912c3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/201k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " " ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "83cd4fac64da475c92bb8286f1a9b366", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #1: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b48661dbe3884f4fabd5cf508a38cdaf", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #2: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6205b8eb95cf4fb38c3b0aae48f6989b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #0: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9b106ecdef9d41d393493ee6512a93cf", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #3: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1766b709d7e84ad1ba16707f9215796a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files #4: 0%| | 0/1 [00:00, ?obj/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3252a83206254b56bc447f8590a8b333", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating train split: 0 examples [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Reading metadata...: 1914it [00:00, 173628.73it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9d5be3ec79f843649b8c03d2ac368aa0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating validation split: 0 examples [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "Reading metadata...: 1701it [00:00, 206152.08it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fc40a1f0d22342c3874d1181ab9593eb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating test split: 0 examples [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "Reading metadata...: 1696it [00:00, 207597.61it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "77217528f7494996ae30717031d317f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating other split: 0 examples [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "\n", "Reading metadata...: 9072it [00:00, 214168.79it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8a63a61c8bf948f09a93267910735d42", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating invalidated split: 0 examples [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "Reading metadata...: 797it [00:00, 195649.09it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Dataset common_voice_11_0 downloaded and prepared to /home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f. Subsequent calls will reuse this data.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Found cached dataset common_voice_11_0 (/home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f)\n", "Found cached dataset common_voice_11_0 (/home/farsipal/.cache/huggingface/datasets/mozilla-foundation___common_voice_11_0/el/11.0.0/f8e47235d9b4e68fa24ed71d63266a02018ccf7194b2a8c9c598a5f3ab304d9f)\n" ] } ], "source": [ "from datasets import IterableDatasetDict\n", "# Please use a read access token below\"\n", "access_token = 'use your token here'\n", "raw_datasets = IterableDatasetDict()\n", "\n", "raw_datasets[\"train\"] = load_whole_dataset(\"mozilla-foundation/common_voice_11_0\", \"el\", split=\"train+validation\", use_auth_token=access_token) \n", "raw_datasets[\"test\"] = load_whole_dataset(\"mozilla-foundation/common_voice_11_0\", \"el\", split=\"test\", use_auth_token=access_token)" ] }, { "cell_type": "markdown", "id": "2d63b2d2-f68a-4d74-b7f1-5127f6d16605", "metadata": {}, "source": [ "## Prepare Processor and Pre-Process Data" ] }, { "cell_type": "markdown", "id": "601c3099-1026-439e-93e2-5635b3ba5a73", "metadata": {}, "source": [ "The ASR pipeline can be de-composed into three stages: \n", "1) A feature extractor which pre-processes the raw audio-inputs\n", "2) The model which performs the sequence-to-sequence mapping \n", "3) A tokenizer which post-processes the model outputs to text format\n", "\n", "In 🤗 Transformers, the Whisper model has an associated feature extractor and tokenizer, \n", "called [WhisperFeatureExtractor](https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperFeatureExtractor)\n", "and [WhisperTokenizer](https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperTokenizer) \n", "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", "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", "the `processor` and the `model`.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 5, "id": "77d9f0c5-8607-4642-a8ac-c3ab2e223ea6", "metadata": {}, "outputs": [], "source": [ "from transformers import WhisperProcessor\n", "\n", "processor = WhisperProcessor.from_pretrained(\"openai/whisper-small\", language=\"Greek\", task=\"transcribe\")" ] }, { "cell_type": "markdown", "id": "381acd09-0b0f-4d04-9eb3-f028ac0e5f2c", "metadata": {}, "source": [ "### Pre-Process Data" ] }, { "cell_type": "markdown", "id": "bf10cd3e-924e-44fc-8790-46e413de7b3d", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 6, "id": "ab5a13b4-9bd4-4aa0-aef2-b3de9b762988", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'client_id': Value(dtype='string', id=None),\n", " 'path': Value(dtype='string', id=None),\n", " 'audio': Audio(sampling_rate=48000, mono=True, decode=True, id=None),\n", " 'sentence': Value(dtype='string', id=None),\n", " 'up_votes': Value(dtype='int64', id=None),\n", " 'down_votes': Value(dtype='int64', id=None),\n", " 'age': Value(dtype='string', id=None),\n", " 'gender': Value(dtype='string', id=None),\n", " 'accent': Value(dtype='string', id=None),\n", " 'locale': Value(dtype='string', id=None),\n", " 'segment': Value(dtype='string', id=None)}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw_datasets[\"train\"].features" ] }, { "cell_type": "markdown", "id": "5a679f05-063d-41b3-9b58-4fc9c6ccf4fd", "metadata": {}, "source": [ "Since our input audio is sampled at 48kHz, we need to _downsample_ it to\n", "16kHz prior to passing it to the Whisper feature extractor, 16kHz being the sampling rate expected by the Whisper model. \n", "\n", "We'll set the audio inputs to the correct sampling rate using dataset's \n", "[`cast_column`](https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=cast_column#datasets.DatasetDict.cast_column)\n", "method. This operation does not change the audio in-place, \n", "but rather signals to `datasets` to resample audio samples _on the fly_ the \n", "first time that they are loaded:" ] }, { "cell_type": "code", "execution_count": 7, "id": "3ab6a724-3d1e-478b-a9e9-d2f85feb6c39", "metadata": {}, "outputs": [], "source": [ "from datasets import Audio\n", "\n", "raw_datasets = raw_datasets.cast_column(\"audio\", Audio(sampling_rate=16000))" ] }, { "cell_type": "markdown", "id": "161322c2-94f3-4d26-9e1d-d9d5202ca3cf", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 8, "id": "d041650e-1c48-4439-87b3-5b6f4a514107", "metadata": {}, "outputs": [], "source": [ "import string\n", "import re\n", "\n", "do_lower_case = False\n", "do_remove_punctuation = False\n", "\n", "punctuation_to_remove = string.punctuation.replace(\"'\", \"\") # don't remove apostrophes\n", "punctuation_to_remove_regex = f\"[{''.join(punctuation_to_remove)}]\"\n", "\n", "if do_remove_punctuation:\n", " print(\"Removing punctuation: \", punctuation_to_remove)" ] }, { "cell_type": "markdown", "id": "bfaa935b-a11d-497c-88c1-0c4d1bb3247b", "metadata": {}, "source": [ "Now we can write a function to prepare our data ready for the model:\n", "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", "2. We use the feature extractor to compute the log-Mel spectrogram input features from our 1-dimensional audio array.\n", "3. We perform any optional pre-processing (lower-case or remove punctuation).\n", "4. We encode the transcriptions to label ids through the use of the tokenizer." ] }, { "cell_type": "code", "execution_count": 9, "id": "c085911c-a10a-41ef-8874-306e0503e9bb", "metadata": {}, "outputs": [], "source": [ "def prepare_dataset(batch):\n", " # load and (possibly) resample audio datato 16kHz\n", " audio = batch[\"audio\"]\n", "\n", " # compute log-Mel input features from input audio array \n", " batch[\"input_features\"] = processor.feature_extractor(audio[\"array\"], sampling_rate=audio[\"sampling_rate\"]).input_features[0]\n", " # compute input length of audio sample in seconds\n", " batch[\"input_length\"] = len(audio[\"array\"]) / audio[\"sampling_rate\"]\n", " \n", " # optional pre-processing steps\n", " transcription = batch[\"sentence\"]\n", " if do_lower_case:\n", " transcription = transcription.lower()\n", " if do_remove_punctuation:\n", " transcription = re.sub(punctuation_to_remove_regex, \" \", transcription).strip()\n", " \n", " # encode target text to label ids\n", " batch[\"labels\"] = processor.tokenizer(transcription).input_ids\n", " return batch" ] }, { "cell_type": "markdown", "id": "70b319fb-2439-4ef6-a70d-a47bf41c4a13", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 12, "id": "a37a7cdb-9013-427f-8de9-6a8d0e9dc684", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b4fcdb8eca604c3fbcfff33c5a78fa16", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/3402 [00:00, ?ex/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "33a50cf0e42e49bab450385c65122168", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1696 [00:00, ?ex/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vectorized_datasets = raw_datasets.map(prepare_dataset, remove_columns=list(next(iter(raw_datasets.values())).features)).with_format(\"torch\")" ] }, { "cell_type": "markdown", "id": "3d59b37e-4950-47ec-9e3e-2cf2ec7fc750", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 13, "id": "1b145699-acfc-4b1d-93a2-a2ad3d62674c", "metadata": {}, "outputs": [], "source": [ "vectorized_datasets[\"train\"] = vectorized_datasets[\"train\"].shuffle(\n", "# buffer_size=500,\n", " seed=0,\n", ")" ] }, { "cell_type": "markdown", "id": "666b9ef0-7909-4e1e-a419-87604d233e29", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 14, "id": "01cb25ef-4bb0-4325-9461-f59198acadf6", "metadata": {}, "outputs": [], "source": [ "max_input_length = 30.0\n", "\n", "def is_audio_in_length_range(length):\n", " return length < max_input_length" ] }, { "cell_type": "markdown", "id": "28e37ac3-b1c5-465b-8586-7cfd8d76b0f1", "metadata": {}, "source": [ "We apply our filter function to all samples of our training dataset through 🤗 Datasets' `.filter` method:" ] }, { "cell_type": "code", "execution_count": 15, "id": "333f7f6e-6053-4d3b-8924-c733c79b82ac", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "382beecce61947f0a612b4b8573af5de", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/4 [00:00, ?ba/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vectorized_datasets[\"train\"] = vectorized_datasets[\"train\"].filter(\n", " is_audio_in_length_range,\n", " input_columns=[\"input_length\"],\n", ")" ] }, { "cell_type": "markdown", "id": "263a5a58-0239-4a25-b0df-c625fc9c5810", "metadata": {}, "source": [ "## Training and Evaluation" ] }, { "cell_type": "markdown", "id": "a693e768-c5a6-453f-89a1-b601dcf7daf7", "metadata": {}, "source": [ "Now that we've prepared our data, we're ready to dive into the training pipeline. \n", "The [🤗 Trainer](https://huggingface.co/transformers/master/main_classes/trainer.html?highlight=trainer)\n", "will do much of the heavy lifting for us. All we have to do is:\n", "\n", "- Define a data collator: the data collator takes our pre-processed data and prepares PyTorch tensors ready for the model.\n", "\n", "- 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", "\n", "- Load a pre-trained checkpoint: we need to load a pre-trained checkpoint and configure it correctly for training.\n", "\n", "- Define the training configuration: this will be used by the 🤗 Trainer to define the training schedule." ] }, { "cell_type": "markdown", "id": "8d230e6d-624c-400a-bbf5-fa660881df25", "metadata": {}, "source": [ "### Define a Data Collator" ] }, { "cell_type": "markdown", "id": "04def221-0637-4a69-b242-d3f0c1d0ee78", "metadata": {}, "source": [ "The data collator for a sequence-to-sequence speech model is unique in the sense that it \n", "treats the `input_features` and `labels` independently: the `input_features` must be \n", "handled by the feature extractor and the `labels` by the tokenizer.\n", "\n", "The `input_features` are already padded to 30s and converted to a log-Mel spectrogram \n", "of fixed dimension by action of the feature extractor, so all we have to do is convert the `input_features`\n", "to batched PyTorch tensors. We do this using the feature extractor's `.pad` method with `return_tensors=pt`.\n", "\n", "The `labels` on the other hand are un-padded. We first pad the sequences\n", "to the maximum length in the batch using the tokenizer's `.pad` method. The padding tokens \n", "are then replaced by `-100` so that these tokens are **not** taken into account when \n", "computing the loss. We then cut the BOS token from the start of the label sequence as we \n", "append it later during training.\n", "\n", "We can leverage the `WhisperProcessor` we defined earlier to perform both the \n", "feature extractor and the tokenizer operations:" ] }, { "cell_type": "code", "execution_count": 16, "id": "8326221e-ec13-4731-bb4e-51e5fc1486c5", "metadata": {}, "outputs": [], "source": [ "import torch\n", "\n", "from dataclasses import dataclass\n", "from typing import Any, Dict, List, Union\n", "\n", "@dataclass\n", "class DataCollatorSpeechSeq2SeqWithPadding:\n", " processor: Any\n", "\n", " def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:\n", " # split inputs and labels since they have to be of different lengths and need different padding methods\n", " # first treat the audio inputs by simply returning torch tensors\n", " input_features = [{\"input_features\": feature[\"input_features\"]} for feature in features]\n", " batch = self.processor.feature_extractor.pad(input_features, return_tensors=\"pt\")\n", "\n", " # get the tokenized label sequences\n", " label_features = [{\"input_ids\": feature[\"labels\"]} for feature in features]\n", " # pad the labels to max length\n", " labels_batch = self.processor.tokenizer.pad(label_features, return_tensors=\"pt\")\n", "\n", " # replace padding with -100 to ignore loss correctly\n", " labels = labels_batch[\"input_ids\"].masked_fill(labels_batch.attention_mask.ne(1), -100)\n", "\n", " # if bos token is appended in previous tokenization step,\n", " # cut bos token here as it's append later anyways\n", " if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().cpu().item():\n", " labels = labels[:, 1:]\n", "\n", " batch[\"labels\"] = labels\n", "\n", " return batch" ] }, { "cell_type": "markdown", "id": "3cae7dbf-8a50-456e-a3a8-7fd005390f86", "metadata": {}, "source": [ "Let's initialise the data collator we've just defined:" ] }, { "cell_type": "code", "execution_count": 17, "id": "fc834702-c0d3-4a96-b101-7b87be32bf42", "metadata": {}, "outputs": [], "source": [ "data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)" ] }, { "cell_type": "markdown", "id": "d62bb2ab-750a-45e7-82e9-61d6f4805698", "metadata": {}, "source": [ "### Evaluation Metrics" ] }, { "cell_type": "markdown", "id": "66fee1a7-a44c-461e-b047-c3917221572e", "metadata": {}, "source": [ "We'll use the word error rate (WER) metric, the 'de-facto' metric for assessing \n", "ASR systems. For more information, refer to the WER [docs](https://huggingface.co/metrics/wer). We'll load the WER metric from 🤗 Evaluate:" ] }, { "cell_type": "code", "execution_count": 18, "id": "b22b4011-f31f-4b57-b684-c52332f92890", "metadata": {}, "outputs": [], "source": [ "import evaluate\n", "\n", "metric = evaluate.load(\"wer\")" ] }, { "cell_type": "markdown", "id": "509f96d7-3f11-4f37-add9-f74a0c44f3fc", "metadata": {}, "source": [ "We then simply have to define a function that takes our model \n", "predictions and returns the WER metric. This function, called\n", "`compute_metrics`, first replaces `-100` with the `pad_token_id`\n", "in the `label_ids` (undoing the step we applied in the \n", "data collator to ignore padded tokens correctly in the loss).\n", "It then decodes the predicted and label ids to strings. Finally,\n", "it computes the WER between the predictions and reference labels. \n", "Here, we have the option of evaluating with the 'normalised' transcriptions \n", "and predictions. We recommend you set this to `True` to benefit from the WER \n", "improvement obtained by normalising the transcriptions." ] }, { "cell_type": "code", "execution_count": 19, "id": "a11d1bfc-9e28-460f-a287-72d8f7bc1acb", "metadata": {}, "outputs": [], "source": [ "# evaluate with the 'normalised' WER\n", "do_normalize_eval = True\n", "\n", "def compute_metrics(pred):\n", " pred_ids = pred.predictions\n", " label_ids = pred.label_ids\n", "\n", " # replace -100 with the pad_token_id\n", " label_ids[label_ids == -100] = processor.tokenizer.pad_token_id\n", "\n", " # we do not want to group tokens when computing the metrics\n", " pred_str = processor.tokenizer.batch_decode(pred_ids, skip_special_tokens=True, normalize=do_normalize_eval)\n", " label_str = processor.tokenizer.batch_decode(label_ids, skip_special_tokens=True, normalize=do_normalize_eval)\n", "\n", " wer = 100 * metric.compute(predictions=pred_str, references=label_str)\n", "\n", " return {\"wer\": wer}" ] }, { "cell_type": "markdown", "id": "daf2a825-6d9f-4a23-b145-c37c0039075b", "metadata": {}, "source": [ "### Load a Pre-Trained Checkpoint" ] }, { "cell_type": "markdown", "id": "437a97fa-4864-476b-8abc-f28b8166cfa5", "metadata": {}, "source": [ "Now let's load the pre-trained Whisper `small` checkpoint. Again, this \n", "is trivial through use of 🤗 Transformers!" ] }, { "cell_type": "code", "execution_count": 20, "id": "5a10cc4b-07ec-4ebd-ac1d-7c601023594f", "metadata": {}, "outputs": [], "source": [ "from transformers import WhisperForConditionalGeneration\n", "\n", "model = WhisperForConditionalGeneration.from_pretrained(\"openai/whisper-small\")" ] }, { "cell_type": "markdown", "id": "a15ead5f-2277-4a39-937b-585c2497b2df", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 21, "id": "62038ba3-88ed-4fce-84db-338f50dcd04f", "metadata": {}, "outputs": [], "source": [ "model.config.forced_decoder_ids = None\n", "model.config.suppress_tokens = []\n", "model.config.use_cache = False" ] }, { "cell_type": "markdown", "id": "2178dea4-80ca-47b6-b6ea-ba1915c90c06", "metadata": {}, "source": [ "### Define the Training Configuration" ] }, { "cell_type": "markdown", "id": "58ab7740", "metadata": {}, "source": [ "Check to see that the GPU is available." ] }, { "cell_type": "code", "execution_count": 18, "id": "0b483d84", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "torch.cuda.is_available()" ] }, { "cell_type": "markdown", "id": "c21af1e9-0188-4134-ac82-defc7bdcc436", "metadata": {}, "source": [ "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)." ] }, { "cell_type": "code", "execution_count": 22, "id": "0ae3e9af-97b7-4aa0-ae85-20b23b5bcb3a", "metadata": {}, "outputs": [], "source": [ "from transformers import Seq2SeqTrainingArguments\n", "\n", "training_args = Seq2SeqTrainingArguments(\n", " output_dir=\"./save/\",\n", " per_device_train_batch_size=16,\n", " gradient_accumulation_steps=4, # increase by 2x for every 2x decrease in batch size\n", " learning_rate=1e-5,\n", " warmup_steps=500,\n", " max_steps=5000,\n", " gradient_checkpointing=True,\n", " fp16=True,\n", " evaluation_strategy=\"steps\",\n", " per_device_eval_batch_size=8,\n", " predict_with_generate=True,\n", " generation_max_length=225,\n", " save_steps=1000,\n", " eval_steps=1000,\n", " logging_steps=25,\n", " report_to=[\"tensorboard\"],\n", " load_best_model_at_end=True,\n", " metric_for_best_model=\"wer\",\n", " greater_is_better=False,\n", " push_to_hub=False,\n", ")" ] }, { "cell_type": "markdown", "id": "b3a944d8-3112-4552-82a0-be25988b3857", "metadata": {}, "source": [ "**Note**: if one does not want to upload the model checkpoints to the Hub, \n", "set `push_to_hub=False`." ] }, { "cell_type": "markdown", "id": "393c883e-3e50-492c-bd58-f51dbf15ee56", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 23, "id": "3ac16b62-b3c0-4c68-8f3d-9ecf471534b2", "metadata": {}, "outputs": [], "source": [ "from transformers import TrainerCallback\n", "from transformers.trainer_pt_utils import IterableDatasetShard\n", "from torch.utils.data import IterableDataset\n", "\n", "# trainer callback to reinitialise and reshuffle the streamable datasets at the beginning of each epoch\n", "class ShuffleCallback(TrainerCallback):\n", " def on_epoch_begin(self, args, state, control, train_dataloader, **kwargs):\n", " if isinstance(train_dataloader.dataset, IterableDatasetShard):\n", " pass # set_epoch() is handled by the Trainer\n", " elif isinstance(train_dataloader.dataset, IterableDataset):\n", " train_dataloader.dataset.set_epoch(train_dataloader.dataset._epoch + 1)" ] }, { "cell_type": "markdown", "id": "bac29114-d226-4f54-97cf-8718c9f94e1e", "metadata": {}, "source": [ "We can forward the training arguments to the 🤗 Trainer along with our model,\n", "dataset, data collator, `compute_metrics` function and custom callback:" ] }, { "cell_type": "code", "execution_count": 24, "id": "d546d7fe-0543-479a-b708-2ebabec19493", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "max_steps is given, it will override any value given in num_train_epochs\n", "Using cuda_amp half precision backend\n" ] } ], "source": [ "from transformers import Seq2SeqTrainer\n", "\n", "trainer = Seq2SeqTrainer(\n", " args=training_args,\n", " model=model,\n", " train_dataset=vectorized_datasets[\"train\"],\n", " eval_dataset=vectorized_datasets[\"test\"],\n", " data_collator=data_collator,\n", " compute_metrics=compute_metrics,\n", " tokenizer=processor,\n", " callbacks=[ShuffleCallback()],\n", ")" ] }, { "cell_type": "markdown", "id": "67ab88c3-7091-4e51-8ad5-f5cacbe18449", "metadata": {}, "source": [ "We'll save the model and processor to the output directory before training:" ] }, { "cell_type": "code", "execution_count": 26, "id": "a1ccb9ed-cbc8-4419-91c0-651e9424b672", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Configuration saved in ./save/config.json\n", "Model weights saved in ./save/pytorch_model.bin\n", "Feature extractor saved in ./save/preprocessor_config.json\n", "tokenizer config file saved in ./save/tokenizer_config.json\n", "Special tokens file saved in ./save/special_tokens_map.json\n", "added tokens file saved in ./save/added_tokens.json\n" ] } ], "source": [ "model.save_pretrained(training_args.output_dir)\n", "processor.save_pretrained(training_args.output_dir)" ] }, { "cell_type": "markdown", "id": "7f404cf9-4345-468c-8196-4bd101d9bd51", "metadata": {}, "source": [ "### Training" ] }, { "cell_type": "markdown", "id": "5e8b8d56-5a70-4f68-bd2e-f0752d0bd112", "metadata": {}, "source": [ "Training will take approximately 5-10 hours depending on your GPU. The peak GPU memory for the given training configuration is approximately 36GB. \n", "Depending on your GPU, it is possible that you will encounter a CUDA `\"out-of-memory\"` error when you launch training. \n", "In this case, you can reduce the `per_device_train_batch_size` incrementally by factors of 2 \n", "and employ [`gradient_accumulation_steps`](https://huggingface.co/docs/transformers/main_classes/trainer#transformers.Seq2SeqTrainingArguments.gradient_accumulation_steps)\n", "to compensate.\n", "\n", "To launch training, simply execute:" ] }, { "cell_type": "code", "execution_count": 27, "id": "ee8b7b8e-1c9a-4d77-9137-1778a629e6de", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "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", "/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", " warnings.warn(\n", "***** Running training *****\n", " Num examples = 3402\n", " Num Epochs = 95\n", " Instantaneous batch size per device = 16\n", " Total train batch size (w. parallel, distributed & accumulation) = 64\n", " Gradient Accumulation steps = 4\n", " Total optimization steps = 5000\n", " Number of trainable parameters = 241734912\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "db1bc62a33754630a47c82ec0ebfd7ce", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/5000 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 2.9261, 'learning_rate': 4.6000000000000004e-07, 'epoch': 0.47}\n", "{'loss': 2.3236, 'learning_rate': 9.600000000000001e-07, 'epoch': 0.94}\n", "{'loss': 1.5525, 'learning_rate': 1.46e-06, 'epoch': 1.41}\n", "{'loss': 1.0065, 'learning_rate': 1.9600000000000003e-06, 'epoch': 1.88}\n", "{'loss': 0.8887, 'learning_rate': 2.46e-06, 'epoch': 2.36}\n", "{'loss': 0.7771, 'learning_rate': 2.96e-06, 'epoch': 2.83}\n", "{'loss': 0.6976, 'learning_rate': 3.46e-06, 'epoch': 3.3}\n", "{'loss': 0.5892, 'learning_rate': 3.96e-06, 'epoch': 3.77}\n", "{'loss': 0.4458, 'learning_rate': 4.440000000000001e-06, 'epoch': 4.24}\n", "{'loss': 0.208, 'learning_rate': 4.92e-06, 'epoch': 4.71}\n", "{'loss': 0.154, 'learning_rate': 5.420000000000001e-06, 'epoch': 5.19}\n", "{'loss': 0.1177, 'learning_rate': 5.92e-06, 'epoch': 5.66}\n", "{'loss': 0.1037, 'learning_rate': 6.42e-06, 'epoch': 6.13}\n", "{'loss': 0.0691, 'learning_rate': 6.92e-06, 'epoch': 6.6}\n", "{'loss': 0.064, 'learning_rate': 7.420000000000001e-06, 'epoch': 7.08}\n", "{'loss': 0.0423, 'learning_rate': 7.92e-06, 'epoch': 7.54}\n", "{'loss': 0.0419, 'learning_rate': 8.42e-06, 'epoch': 8.02}\n", "{'loss': 0.025, 'learning_rate': 8.920000000000001e-06, 'epoch': 8.49}\n", "{'loss': 0.0296, 'learning_rate': 9.42e-06, 'epoch': 8.96}\n", "{'loss': 0.0151, 'learning_rate': 9.920000000000002e-06, 'epoch': 9.43}\n", "{'loss': 0.0171, 'learning_rate': 9.953333333333333e-06, 'epoch': 9.9}\n", "{'loss': 0.0137, 'learning_rate': 9.89777777777778e-06, 'epoch': 10.38}\n", "{'loss': 0.012, 'learning_rate': 9.842222222222223e-06, 'epoch': 10.85}\n", "{'loss': 0.0107, 'learning_rate': 9.786666666666667e-06, 'epoch': 11.32}\n", "{'loss': 0.0131, 'learning_rate': 9.731111111111113e-06, 'epoch': 11.79}\n", "{'loss': 0.0086, 'learning_rate': 9.675555555555555e-06, 'epoch': 12.26}\n", "{'loss': 0.0065, 'learning_rate': 9.620000000000001e-06, 'epoch': 12.73}\n", "{'loss': 0.0068, 'learning_rate': 9.564444444444445e-06, 'epoch': 13.21}\n", "{'loss': 0.0068, 'learning_rate': 9.508888888888889e-06, 'epoch': 13.68}\n", "{'loss': 0.0065, 'learning_rate': 9.453333333333335e-06, 'epoch': 14.15}\n", "{'loss': 0.0054, 'learning_rate': 9.397777777777779e-06, 'epoch': 14.62}\n", "{'loss': 0.0049, 'learning_rate': 9.342222222222223e-06, 'epoch': 15.09}\n", "{'loss': 0.0051, 'learning_rate': 9.286666666666667e-06, 'epoch': 15.56}\n", "{'loss': 0.0046, 'learning_rate': 9.231111111111111e-06, 'epoch': 16.04}\n", "{'loss': 0.0035, 'learning_rate': 9.175555555555557e-06, 'epoch': 16.51}\n", "{'loss': 0.0047, 'learning_rate': 9.12e-06, 'epoch': 16.98}\n", "{'loss': 0.0031, 'learning_rate': 9.064444444444447e-06, 'epoch': 17.45}\n", "{'loss': 0.004, 'learning_rate': 9.008888888888889e-06, 'epoch': 17.92}\n", "{'loss': 0.0025, 'learning_rate': 8.953333333333335e-06, 'epoch': 18.39}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "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", "***** Running Evaluation *****\n", " Num examples = 1696\n", " Batch size = 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0024, 'learning_rate': 8.897777777777779e-06, 'epoch': 18.86}\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "908baeec73784b429a4927223dcd8947", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/212 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Saving model checkpoint to ./save/checkpoint-1000\n", "Configuration saved in ./save/checkpoint-1000/config.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'eval_loss': 0.4176926016807556, 'eval_wer': 20.24517087667162, 'eval_runtime': 1086.9683, 'eval_samples_per_second': 1.56, 'eval_steps_per_second': 0.195, 'epoch': 18.86}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Model weights saved in ./save/checkpoint-1000/pytorch_model.bin\n", "Feature extractor saved in ./save/checkpoint-1000/preprocessor_config.json\n", "tokenizer config file saved in ./save/checkpoint-1000/tokenizer_config.json\n", "Special tokens file saved in ./save/checkpoint-1000/special_tokens_map.json\n", "added tokens file saved in ./save/checkpoint-1000/added_tokens.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0026, 'learning_rate': 8.842222222222223e-06, 'epoch': 19.34}\n", "{'loss': 0.002, 'learning_rate': 8.786666666666668e-06, 'epoch': 19.81}\n", "{'loss': 0.0022, 'learning_rate': 8.73111111111111e-06, 'epoch': 20.28}\n", "{'loss': 0.0021, 'learning_rate': 8.675555555555556e-06, 'epoch': 20.75}\n", "{'loss': 0.0013, 'learning_rate': 8.62e-06, 'epoch': 21.23}\n", "{'loss': 0.0013, 'learning_rate': 8.564444444444445e-06, 'epoch': 21.69}\n", "{'loss': 0.0018, 'learning_rate': 8.50888888888889e-06, 'epoch': 22.17}\n", "{'loss': 0.0026, 'learning_rate': 8.453333333333334e-06, 'epoch': 22.64}\n", "{'loss': 0.0014, 'learning_rate': 8.397777777777778e-06, 'epoch': 23.11}\n", "{'loss': 0.0019, 'learning_rate': 8.342222222222222e-06, 'epoch': 23.58}\n", "{'loss': 0.002, 'learning_rate': 8.286666666666668e-06, 'epoch': 24.06}\n", "{'loss': 0.0017, 'learning_rate': 8.231111111111112e-06, 'epoch': 24.53}\n", "{'loss': 0.0017, 'learning_rate': 8.175555555555556e-06, 'epoch': 25.0}\n", "{'loss': 0.0016, 'learning_rate': 8.120000000000002e-06, 'epoch': 25.47}\n", "{'loss': 0.0013, 'learning_rate': 8.064444444444444e-06, 'epoch': 25.94}\n", "{'loss': 0.0012, 'learning_rate': 8.00888888888889e-06, 'epoch': 26.41}\n", "{'loss': 0.0019, 'learning_rate': 7.953333333333334e-06, 'epoch': 26.88}\n", "{'loss': 0.0019, 'learning_rate': 7.897777777777778e-06, 'epoch': 27.36}\n", "{'loss': 0.0021, 'learning_rate': 7.842222222222224e-06, 'epoch': 27.83}\n", "{'loss': 0.0019, 'learning_rate': 7.786666666666666e-06, 'epoch': 28.3}\n", "{'loss': 0.001, 'learning_rate': 7.731111111111112e-06, 'epoch': 28.77}\n", "{'loss': 0.0016, 'learning_rate': 7.675555555555556e-06, 'epoch': 29.24}\n", "{'loss': 0.001, 'learning_rate': 7.620000000000001e-06, 'epoch': 29.71}\n", "{'loss': 0.0008, 'learning_rate': 7.564444444444446e-06, 'epoch': 30.19}\n", "{'loss': 0.0007, 'learning_rate': 7.50888888888889e-06, 'epoch': 30.66}\n", "{'loss': 0.0006, 'learning_rate': 7.453333333333334e-06, 'epoch': 31.13}\n", "{'loss': 0.0007, 'learning_rate': 7.3977777777777786e-06, 'epoch': 31.6}\n", "{'loss': 0.0009, 'learning_rate': 7.342222222222223e-06, 'epoch': 32.08}\n", "{'loss': 0.001, 'learning_rate': 7.2866666666666675e-06, 'epoch': 32.54}\n", "{'loss': 0.001, 'learning_rate': 7.231111111111112e-06, 'epoch': 33.02}\n", "{'loss': 0.0024, 'learning_rate': 7.1755555555555556e-06, 'epoch': 33.49}\n", "{'loss': 0.0016, 'learning_rate': 7.1200000000000004e-06, 'epoch': 33.96}\n", "{'loss': 0.0009, 'learning_rate': 7.0644444444444445e-06, 'epoch': 34.43}\n", "{'loss': 0.001, 'learning_rate': 7.008888888888889e-06, 'epoch': 34.9}\n", "{'loss': 0.0008, 'learning_rate': 6.953333333333334e-06, 'epoch': 35.38}\n", "{'loss': 0.0006, 'learning_rate': 6.897777777777779e-06, 'epoch': 35.85}\n", "{'loss': 0.0006, 'learning_rate': 6.842222222222222e-06, 'epoch': 36.32}\n", "{'loss': 0.0006, 'learning_rate': 6.786666666666667e-06, 'epoch': 36.79}\n", "{'loss': 0.0005, 'learning_rate': 6.731111111111111e-06, 'epoch': 37.26}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "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", "***** Running Evaluation *****\n", " Num examples = 1696\n", " Batch size = 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0008, 'learning_rate': 6.675555555555556e-06, 'epoch': 37.73}\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "032a96b9ba5e419eb86bc530eec6c66a", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/212 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Saving model checkpoint to ./save/checkpoint-2000\n", "Configuration saved in ./save/checkpoint-2000/config.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'eval_loss': 0.4465649724006653, 'eval_wer': 20.161589895988115, 'eval_runtime': 1090.0709, 'eval_samples_per_second': 1.556, 'eval_steps_per_second': 0.194, 'epoch': 37.73}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Model weights saved in ./save/checkpoint-2000/pytorch_model.bin\n", "Feature extractor saved in ./save/checkpoint-2000/preprocessor_config.json\n", "tokenizer config file saved in ./save/checkpoint-2000/tokenizer_config.json\n", "Special tokens file saved in ./save/checkpoint-2000/special_tokens_map.json\n", "added tokens file saved in ./save/checkpoint-2000/added_tokens.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0004, 'learning_rate': 6.620000000000001e-06, 'epoch': 38.21}\n", "{'loss': 0.0004, 'learning_rate': 6.564444444444446e-06, 'epoch': 38.68}\n", "{'loss': 0.0003, 'learning_rate': 6.508888888888889e-06, 'epoch': 39.15}\n", "{'loss': 0.0003, 'learning_rate': 6.453333333333334e-06, 'epoch': 39.62}\n", "{'loss': 0.0003, 'learning_rate': 6.397777777777778e-06, 'epoch': 40.09}\n", "{'loss': 0.0003, 'learning_rate': 6.342222222222223e-06, 'epoch': 40.56}\n", "{'loss': 0.0003, 'learning_rate': 6.286666666666668e-06, 'epoch': 41.04}\n", "{'loss': 0.0003, 'learning_rate': 6.231111111111111e-06, 'epoch': 41.51}\n", "{'loss': 0.0003, 'learning_rate': 6.175555555555556e-06, 'epoch': 41.98}\n", "{'loss': 0.0003, 'learning_rate': 6.120000000000001e-06, 'epoch': 42.45}\n", "{'loss': 0.0003, 'learning_rate': 6.064444444444445e-06, 'epoch': 42.92}\n", "{'loss': 0.0002, 'learning_rate': 6.00888888888889e-06, 'epoch': 43.39}\n", "{'loss': 0.0002, 'learning_rate': 5.9533333333333345e-06, 'epoch': 43.86}\n", "{'loss': 0.0002, 'learning_rate': 5.897777777777778e-06, 'epoch': 44.34}\n", "{'loss': 0.0002, 'learning_rate': 5.8422222222222226e-06, 'epoch': 44.81}\n", "{'loss': 0.0002, 'learning_rate': 5.7866666666666674e-06, 'epoch': 45.28}\n", "{'loss': 0.0002, 'learning_rate': 5.7311111111111115e-06, 'epoch': 45.75}\n", "{'loss': 0.0002, 'learning_rate': 5.675555555555556e-06, 'epoch': 46.23}\n", "{'loss': 0.0002, 'learning_rate': 5.620000000000001e-06, 'epoch': 46.69}\n", "{'loss': 0.0002, 'learning_rate': 5.5644444444444444e-06, 'epoch': 47.17}\n", "{'loss': 0.0002, 'learning_rate': 5.508888888888889e-06, 'epoch': 47.64}\n", "{'loss': 0.0002, 'learning_rate': 5.453333333333334e-06, 'epoch': 48.11}\n", "{'loss': 0.0002, 'learning_rate': 5.397777777777778e-06, 'epoch': 48.58}\n", "{'loss': 0.0002, 'learning_rate': 5.342222222222223e-06, 'epoch': 49.06}\n", "{'loss': 0.0002, 'learning_rate': 5.286666666666666e-06, 'epoch': 49.53}\n", "{'loss': 0.0002, 'learning_rate': 5.231111111111111e-06, 'epoch': 50.0}\n", "{'loss': 0.0002, 'learning_rate': 5.175555555555556e-06, 'epoch': 50.47}\n", "{'loss': 0.0002, 'learning_rate': 5.12e-06, 'epoch': 50.94}\n", "{'loss': 0.0002, 'learning_rate': 5.064444444444445e-06, 'epoch': 51.41}\n", "{'loss': 0.0002, 'learning_rate': 5.00888888888889e-06, 'epoch': 51.88}\n", "{'loss': 0.0002, 'learning_rate': 4.953333333333334e-06, 'epoch': 52.36}\n", "{'loss': 0.0002, 'learning_rate': 4.897777777777778e-06, 'epoch': 52.83}\n", "{'loss': 0.0002, 'learning_rate': 4.842222222222223e-06, 'epoch': 53.3}\n", "{'loss': 0.0002, 'learning_rate': 4.786666666666667e-06, 'epoch': 53.77}\n", "{'loss': 0.0002, 'learning_rate': 4.731111111111112e-06, 'epoch': 54.24}\n", "{'loss': 0.0002, 'learning_rate': 4.675555555555556e-06, 'epoch': 54.71}\n", "{'loss': 0.0002, 'learning_rate': 4.620000000000001e-06, 'epoch': 55.19}\n", "{'loss': 0.0002, 'learning_rate': 4.564444444444445e-06, 'epoch': 55.66}\n", "{'loss': 0.0002, 'learning_rate': 4.50888888888889e-06, 'epoch': 56.13}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "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", "***** Running Evaluation *****\n", " Num examples = 1696\n", " Batch size = 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0002, 'learning_rate': 4.453333333333334e-06, 'epoch': 56.6}\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a73fc5f9c2fb486a83d1663e203cc69c", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/212 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Saving model checkpoint to ./save/checkpoint-3000\n", "Configuration saved in ./save/checkpoint-3000/config.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'eval_loss': 0.4917678236961365, 'eval_wer': 20.0222882615156, 'eval_runtime': 1291.8911, 'eval_samples_per_second': 1.313, 'eval_steps_per_second': 0.164, 'epoch': 56.6}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Model weights saved in ./save/checkpoint-3000/pytorch_model.bin\n", "Feature extractor saved in ./save/checkpoint-3000/preprocessor_config.json\n", "tokenizer config file saved in ./save/checkpoint-3000/tokenizer_config.json\n", "Special tokens file saved in ./save/checkpoint-3000/special_tokens_map.json\n", "added tokens file saved in ./save/checkpoint-3000/added_tokens.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0002, 'learning_rate': 4.397777777777778e-06, 'epoch': 57.08}\n", "{'loss': 0.0001, 'learning_rate': 4.3422222222222225e-06, 'epoch': 57.54}\n", "{'loss': 0.0002, 'learning_rate': 4.2866666666666666e-06, 'epoch': 58.02}\n", "{'loss': 0.0001, 'learning_rate': 4.2311111111111114e-06, 'epoch': 58.49}\n", "{'loss': 0.0001, 'learning_rate': 4.175555555555556e-06, 'epoch': 58.96}\n", "{'loss': 0.0001, 'learning_rate': 4.12e-06, 'epoch': 59.43}\n", "{'loss': 0.0001, 'learning_rate': 4.064444444444444e-06, 'epoch': 59.9}\n", "{'loss': 0.0001, 'learning_rate': 4.008888888888889e-06, 'epoch': 60.38}\n", "{'loss': 0.0001, 'learning_rate': 3.953333333333333e-06, 'epoch': 60.85}\n", "{'loss': 0.0001, 'learning_rate': 3.897777777777778e-06, 'epoch': 61.32}\n", "{'loss': 0.0001, 'learning_rate': 3.842222222222223e-06, 'epoch': 61.79}\n", "{'loss': 0.0001, 'learning_rate': 3.7866666666666667e-06, 'epoch': 62.26}\n", "{'loss': 0.0001, 'learning_rate': 3.7311111111111116e-06, 'epoch': 62.73}\n", "{'loss': 0.0001, 'learning_rate': 3.675555555555556e-06, 'epoch': 63.21}\n", "{'loss': 0.0001, 'learning_rate': 3.62e-06, 'epoch': 63.68}\n", "{'loss': 0.0001, 'learning_rate': 3.564444444444445e-06, 'epoch': 64.15}\n", "{'loss': 0.0001, 'learning_rate': 3.508888888888889e-06, 'epoch': 64.62}\n", "{'loss': 0.0001, 'learning_rate': 3.4533333333333334e-06, 'epoch': 65.09}\n", "{'loss': 0.0001, 'learning_rate': 3.3977777777777783e-06, 'epoch': 65.56}\n", "{'loss': 0.0001, 'learning_rate': 3.3422222222222224e-06, 'epoch': 66.04}\n", "{'loss': 0.0001, 'learning_rate': 3.286666666666667e-06, 'epoch': 66.51}\n", "{'loss': 0.0001, 'learning_rate': 3.2311111111111117e-06, 'epoch': 66.98}\n", "{'loss': 0.0001, 'learning_rate': 3.1755555555555557e-06, 'epoch': 67.45}\n", "{'loss': 0.0001, 'learning_rate': 3.12e-06, 'epoch': 67.92}\n", "{'loss': 0.0001, 'learning_rate': 3.064444444444445e-06, 'epoch': 68.39}\n", "{'loss': 0.0001, 'learning_rate': 3.008888888888889e-06, 'epoch': 68.86}\n", "{'loss': 0.0001, 'learning_rate': 2.9533333333333336e-06, 'epoch': 69.34}\n", "{'loss': 0.0001, 'learning_rate': 2.8977777777777785e-06, 'epoch': 69.81}\n", "{'loss': 0.0001, 'learning_rate': 2.8422222222222225e-06, 'epoch': 70.28}\n", "{'loss': 0.0001, 'learning_rate': 2.786666666666667e-06, 'epoch': 70.75}\n", "{'loss': 0.0001, 'learning_rate': 2.7311111111111114e-06, 'epoch': 71.23}\n", "{'loss': 0.0001, 'learning_rate': 2.675555555555556e-06, 'epoch': 71.69}\n", "{'loss': 0.0001, 'learning_rate': 2.6200000000000003e-06, 'epoch': 72.17}\n", "{'loss': 0.0001, 'learning_rate': 2.5644444444444444e-06, 'epoch': 72.64}\n", "{'loss': 0.0001, 'learning_rate': 2.5088888888888892e-06, 'epoch': 73.11}\n", "{'loss': 0.0001, 'learning_rate': 2.4533333333333333e-06, 'epoch': 73.58}\n", "{'loss': 0.0001, 'learning_rate': 2.397777777777778e-06, 'epoch': 74.06}\n", "{'loss': 0.0001, 'learning_rate': 2.342222222222222e-06, 'epoch': 74.53}\n", "{'loss': 0.0001, 'learning_rate': 2.2866666666666667e-06, 'epoch': 75.0}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "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", "***** Running Evaluation *****\n", " Num examples = 1696\n", " Batch size = 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0001, 'learning_rate': 2.2311111111111115e-06, 'epoch': 75.47}\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6c33e1cbd9d94858907c56a4d8a22ec4", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/212 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Saving model checkpoint to ./save/checkpoint-4000\n", "Configuration saved in ./save/checkpoint-4000/config.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'eval_loss': 0.5101690888404846, 'eval_wer': 19.9665676077266, 'eval_runtime': 1417.0702, 'eval_samples_per_second': 1.197, 'eval_steps_per_second': 0.15, 'epoch': 75.47}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Model weights saved in ./save/checkpoint-4000/pytorch_model.bin\n", "Feature extractor saved in ./save/checkpoint-4000/preprocessor_config.json\n", "tokenizer config file saved in ./save/checkpoint-4000/tokenizer_config.json\n", "Special tokens file saved in ./save/checkpoint-4000/special_tokens_map.json\n", "added tokens file saved in ./save/checkpoint-4000/added_tokens.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0001, 'learning_rate': 2.1755555555555556e-06, 'epoch': 75.94}\n", "{'loss': 0.0001, 'learning_rate': 2.12e-06, 'epoch': 76.41}\n", "{'loss': 0.0001, 'learning_rate': 2.064444444444445e-06, 'epoch': 76.88}\n", "{'loss': 0.0001, 'learning_rate': 2.008888888888889e-06, 'epoch': 77.36}\n", "{'loss': 0.0001, 'learning_rate': 1.9533333333333334e-06, 'epoch': 77.83}\n", "{'loss': 0.0001, 'learning_rate': 1.8977777777777779e-06, 'epoch': 78.3}\n", "{'loss': 0.0001, 'learning_rate': 1.8422222222222225e-06, 'epoch': 78.77}\n", "{'loss': 0.0001, 'learning_rate': 1.7866666666666668e-06, 'epoch': 79.24}\n", "{'loss': 0.0001, 'learning_rate': 1.7311111111111112e-06, 'epoch': 79.71}\n", "{'loss': 0.0001, 'learning_rate': 1.675555555555556e-06, 'epoch': 80.19}\n", "{'loss': 0.0001, 'learning_rate': 1.6200000000000002e-06, 'epoch': 80.66}\n", "{'loss': 0.0001, 'learning_rate': 1.5644444444444446e-06, 'epoch': 81.13}\n", "{'loss': 0.0001, 'learning_rate': 1.5088888888888889e-06, 'epoch': 81.6}\n", "{'loss': 0.0001, 'learning_rate': 1.4533333333333335e-06, 'epoch': 82.08}\n", "{'loss': 0.0001, 'learning_rate': 1.397777777777778e-06, 'epoch': 82.54}\n", "{'loss': 0.0001, 'learning_rate': 1.3422222222222222e-06, 'epoch': 83.02}\n", "{'loss': 0.0001, 'learning_rate': 1.286666666666667e-06, 'epoch': 83.49}\n", "{'loss': 0.0001, 'learning_rate': 1.2311111111111112e-06, 'epoch': 83.96}\n", "{'loss': 0.0001, 'learning_rate': 1.1755555555555556e-06, 'epoch': 84.43}\n", "{'loss': 0.0001, 'learning_rate': 1.12e-06, 'epoch': 84.9}\n", "{'loss': 0.0001, 'learning_rate': 1.0644444444444445e-06, 'epoch': 85.38}\n", "{'loss': 0.0001, 'learning_rate': 1.008888888888889e-06, 'epoch': 85.85}\n", "{'loss': 0.0001, 'learning_rate': 9.533333333333335e-07, 'epoch': 86.32}\n", "{'loss': 0.0001, 'learning_rate': 8.977777777777778e-07, 'epoch': 86.79}\n", "{'loss': 0.0001, 'learning_rate': 8.422222222222224e-07, 'epoch': 87.26}\n", "{'loss': 0.0001, 'learning_rate': 7.866666666666667e-07, 'epoch': 87.73}\n", "{'loss': 0.0001, 'learning_rate': 7.311111111111112e-07, 'epoch': 88.21}\n", "{'loss': 0.0001, 'learning_rate': 6.755555555555555e-07, 'epoch': 88.68}\n", "{'loss': 0.0001, 'learning_rate': 6.200000000000001e-07, 'epoch': 89.15}\n", "{'loss': 0.0001, 'learning_rate': 5.644444444444445e-07, 'epoch': 89.62}\n", "{'loss': 0.0001, 'learning_rate': 5.088888888888889e-07, 'epoch': 90.09}\n", "{'loss': 0.0001, 'learning_rate': 4.533333333333334e-07, 'epoch': 90.56}\n", "{'loss': 0.0001, 'learning_rate': 3.9777777777777783e-07, 'epoch': 91.04}\n", "{'loss': 0.0001, 'learning_rate': 3.422222222222223e-07, 'epoch': 91.51}\n", "{'loss': 0.0001, 'learning_rate': 2.866666666666667e-07, 'epoch': 91.98}\n", "{'loss': 0.0001, 'learning_rate': 2.3111111111111112e-07, 'epoch': 92.45}\n", "{'loss': 0.0001, 'learning_rate': 1.7555555555555558e-07, 'epoch': 92.92}\n", "{'loss': 0.0001, 'learning_rate': 1.2000000000000002e-07, 'epoch': 93.39}\n", "{'loss': 0.0001, 'learning_rate': 6.444444444444445e-08, 'epoch': 93.86}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "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", "***** Running Evaluation *****\n", " Num examples = 1696\n", " Batch size = 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'loss': 0.0001, 'learning_rate': 8.88888888888889e-09, 'epoch': 94.34}\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "018681a54baa4241a1c4e0b3dd88e1c2", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/212 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Saving model checkpoint to ./save/checkpoint-5000\n", "Configuration saved in ./save/checkpoint-5000/config.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'eval_loss': 0.5180559158325195, 'eval_wer': 20.0222882615156, 'eval_runtime': 1134.5515, 'eval_samples_per_second': 1.495, 'eval_steps_per_second': 0.187, 'epoch': 94.34}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Model weights saved in ./save/checkpoint-5000/pytorch_model.bin\n", "Feature extractor saved in ./save/checkpoint-5000/preprocessor_config.json\n", "tokenizer config file saved in ./save/checkpoint-5000/tokenizer_config.json\n", "Special tokens file saved in ./save/checkpoint-5000/special_tokens_map.json\n", "added tokens file saved in ./save/checkpoint-5000/added_tokens.json\n", "\n", "\n", "Training completed. Do not forget to share your model on huggingface.co/models =)\n", "\n", "\n", "Loading best model from ./save/checkpoint-4000 (score: 19.9665676077266).\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'train_runtime': 73855.3942, 'train_samples_per_second': 4.333, 'train_steps_per_second': 0.068, 'train_loss': 0.06146362095708027, 'epoch': 94.34}\n" ] }, { "data": { "text/plain": [ "TrainOutput(global_step=5000, training_loss=0.06146362095708027, metrics={'train_runtime': 73855.3942, 'train_samples_per_second': 4.333, 'train_steps_per_second': 0.068, 'train_loss': 0.06146362095708027, 'epoch': 94.34})" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trainer.train()" ] }, { "cell_type": "markdown", "id": "747c6a6e", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "(note that training may take some time to commence as we load the first training data samples with streaming mode)" ] }, { "cell_type": "markdown", "id": "810ced54-7187-4a06-b2fe-ba6dcca94dc3", "metadata": {}, "source": [ "We can label our checkpoint with the `whisper-event` tag on push by setting the appropriate key-word arguments (kwargs):" ] }, { "cell_type": "code", "execution_count": 50, "id": "6dd0e310-9b07-4133-ac14-2ed2d7524e22", "metadata": {}, "outputs": [], "source": [ "kwargs = {\n", " \"dataset_tags\": \"mozilla-foundation/common_voice_11_0\",\n", " \"dataset\": \"Common Voice 11.0\", \n", " \"language\": \"el\",\n", " \"model_name\": \"Whisper Small - Greek (el) - Michael Kamfonas\", \n", " \"finetuned_from\": \"openai/whisper-small\",\n", " \"tasks\": \"automatic-speech-recognition\",\n", " \"tags\": \"whisper-event\",\n", " #\"output_dir\": \"./save\",\n", "}" ] }, { "cell_type": "markdown", "id": "090d676a-f944-4297-a938-a40eda0b2b68", "metadata": {}, "source": [ "The training results can now be uploaded to the Hub. To do so, execute the `push_to_hub` command:" ] }, { "cell_type": "code", "execution_count": 51, "id": "95737cda-c5dd-4887-a4d0-dfcb0d61d977", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "04cfdee6ab3d43c892e175310d72fcef", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='