diff --git "a/fine_tune_whisper_mac.ipynb" "b/fine_tune_whisper_mac.ipynb" new file mode 100644--- /dev/null +++ "b/fine_tune_whisper_mac.ipynb" @@ -0,0 +1,1581 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "75b58048-7d14-4fc6-8085-1fc08c81b4a6", + "metadata": { + "id": "75b58048-7d14-4fc6-8085-1fc08c81b4a6" + }, + "source": [ + "# Fine-Tune Whisper For Multilingual ASR with πŸ€— Transformers" + ] + }, + { + "cell_type": "markdown", + "id": "fbfa8ad5-4cdc-4512-9058-836cbbf65e1a", + "metadata": { + "id": "fbfa8ad5-4cdc-4512-9058-836cbbf65e1a" + }, + "source": [ + "In this Colab, we present a step-by-step guide on how to fine-tune Whisper \n", + "for any multilingual ASR dataset using Hugging Face πŸ€— Transformers. This is a \n", + "more \"hands-on\" version of the accompanying [blog post](https://huggingface.co/blog/fine-tune-whisper). \n", + "For a more in-depth explanation of Whisper, the Common Voice dataset and the theory behind fine-tuning, the reader is advised to refer to the blog post." + ] + }, + { + "cell_type": "markdown", + "id": "afe0d503-ae4e-4aa7-9af4-dbcba52db41e", + "metadata": { + "id": "afe0d503-ae4e-4aa7-9af4-dbcba52db41e" + }, + "source": [ + "## Introduction" + ] + }, + { + "cell_type": "markdown", + "id": "9ae91ed4-9c3e-4ade-938e-f4c2dcfbfdc0", + "metadata": { + "id": "9ae91ed4-9c3e-4ade-938e-f4c2dcfbfdc0" + }, + "source": [ + "Whisper is a pre-trained model for automatic speech recognition (ASR) \n", + "published in [September 2022](https://openai.com/blog/whisper/) by the authors \n", + "Alec Radford et al. from OpenAI. Unlike many of its predecessors, such as \n", + "[Wav2Vec 2.0](https://arxiv.org/abs/2006.11477), which are pre-trained \n", + "on un-labelled audio data, Whisper is pre-trained on a vast quantity of \n", + "**labelled** audio-transcription data, 680,000 hours to be precise. \n", + "This is an order of magnitude more data than the un-labelled audio data used \n", + "to train Wav2Vec 2.0 (60,000 hours). What is more, 117,000 hours of this \n", + "pre-training data is multilingual ASR data. This results in checkpoints \n", + "that can be applied to over 96 languages, many of which are considered \n", + "_low-resource_.\n", + "\n", + "When scaled to 680,000 hours of labelled pre-training data, Whisper models \n", + "demonstrate a strong ability to generalise to many datasets and domains.\n", + "The pre-trained checkpoints achieve competitive results to state-of-the-art \n", + "ASR systems, with near 3% word error rate (WER) on the test-clean subset of \n", + "LibriSpeech ASR and a new state-of-the-art on TED-LIUM with 4.7% WER (_c.f._ \n", + "Table 8 of the [Whisper paper](https://cdn.openai.com/papers/whisper.pdf)).\n", + "The extensive multilingual ASR knowledge acquired by Whisper during pre-training \n", + "can be leveraged for other low-resource languages; through fine-tuning, the \n", + "pre-trained checkpoints can be adapted for specific datasets and languages \n", + "to further improve upon these results. We'll show just how Whisper can be fine-tuned \n", + "for low-resource languages in this Colab." + ] + }, + { + "cell_type": "markdown", + "id": "e59b91d6-be24-4b5e-bb38-4977ea143a72", + "metadata": { + "id": "e59b91d6-be24-4b5e-bb38-4977ea143a72" + }, + "source": [ + "
\n", + "\"Trulli\"\n", + "
Figure 1: Whisper model. The architecture \n", + "follows the standard Transformer-based encoder-decoder model. A \n", + "log-Mel spectrogram is input to the encoder. The last encoder \n", + "hidden states are input to the decoder via cross-attention mechanisms. The \n", + "decoder autoregressively predicts text tokens, jointly conditional on the \n", + "encoder hidden states and previously predicted tokens. Figure source: \n", + "OpenAI Whisper Blog.
\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "21b6316e-8a55-4549-a154-66d3da2ab74a", + "metadata": { + "id": "21b6316e-8a55-4549-a154-66d3da2ab74a" + }, + "source": [ + "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", + "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 a low-resource language \n", + "taken from the [Common Voice](https://huggingface.co/datasets/mozilla-foundation/common_voice_11_0)\n", + "dataset. We'll show that with as little as 8 hours of fine-tuning data, we can achieve \n", + "strong performance in this language." + ] + }, + { + "cell_type": "markdown", + "id": "3a680dfc-cbba-4f6c-8a1f-e1a5ff3f123a", + "metadata": { + "id": "3a680dfc-cbba-4f6c-8a1f-e1a5ff3f123a" + }, + "source": [ + "------------------------------------------------------------------------\n", + "\n", + "\\\\({}^1\\\\) The name Whisper follows from the acronym β€œWSPSR”, which stands for β€œWeb-scale Supervised Pre-training for Speech Recognition”." + ] + }, + { + "cell_type": "markdown", + "id": "55fb8d21-df06-472a-99dd-b59567be6dad", + "metadata": { + "id": "55fb8d21-df06-472a-99dd-b59567be6dad" + }, + "source": [ + "## Prepare Environment" + ] + }, + { + "cell_type": "markdown", + "id": "9cd52dc1-ade1-44bb-a2d7-2ed98f110fed", + "metadata": { + "id": "9cd52dc1-ade1-44bb-a2d7-2ed98f110fed" + }, + "source": [ + "Next, we need to update the Unix package `ffmpeg` to version 4:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "69ee227d-60c5-44bf-b04d-c2092f997454", + "metadata": { + "id": "69ee227d-60c5-44bf-b04d-c2092f997454" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Running `brew update --auto-update`...\n", + "\u001b[34m==>\u001b[0m \u001b[1mAuto-updated Homebrew!\u001b[0m\n", + "Updated 2 taps (homebrew/core and homebrew/cask).\n", + "\u001b[34m==>\u001b[0m \u001b[1mNew Formulae\u001b[0m\n", + "macpine pbzx socket_vmnet\n", + "\u001b[34m==>\u001b[0m \u001b[1mNew Casks\u001b[0m\n", + "blurscreen buzz tageditor\n", + "\n", + "You have \u001b[1m17\u001b[0m outdated formulae installed.\n", + "You can upgrade them with \u001b[1mbrew upgrade\u001b[0m\n", + "or list them with \u001b[1mbrew outdated\u001b[0m.\n", + "\n", + "\u001b[33mWarning:\u001b[0m ffmpeg 5.1.2 is already installed and up-to-date.\n", + "To reinstall 5.1.2, run:\n", + " brew reinstall ffmpeg\n" + ] + } + ], + "source": [ + "!brew install ffmpeg" + ] + }, + { + "cell_type": "markdown", + "id": "1d85d613-1c7e-46ac-9134-660bbe7ebc9d", + "metadata": { + "id": "1d85d613-1c7e-46ac-9134-660bbe7ebc9d" + }, + "source": [ + "We'll employ several popular Python packages to fine-tune the Whisper model.\n", + "We'll use `datasets` to download and prepare our training data and \n", + "`transformers` to load and train our Whisper model. We'll also require\n", + "the `soundfile` package to pre-process audio files, `evaluate` and `jiwer` to\n", + "assess the performance of our model. Finally, we'll\n", + "use `gradio` to build a flashy demo of our fine-tuned model." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "e68ea9f8-9b61-414e-8885-3033b67c2850", + "metadata": { + "id": "e68ea9f8-9b61-414e-8885-3033b67c2850" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: datasets==2.6.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (2.6.1)\n", + "Requirement already satisfied: numpy>=1.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (1.21.5)\n", + "Requirement already satisfied: dill<0.3.6 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (0.3.5.1)\n", + "Requirement already satisfied: xxhash in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (3.1.0)\n", + "Requirement already satisfied: pyyaml>=5.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (6.0)\n", + "Requirement already satisfied: tqdm>=4.62.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (4.64.1)\n", + "Requirement already satisfied: fsspec[http]>=2021.11.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (2022.7.1)\n", + "Requirement already satisfied: multiprocess in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (0.70.13)\n", + "Requirement already satisfied: pandas in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (1.4.4)\n", + "Requirement already satisfied: requests>=2.19.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (2.28.1)\n", + "Requirement already satisfied: pyarrow>=6.0.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (10.0.1)\n", + "Requirement already satisfied: huggingface-hub<1.0.0,>=0.2.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (0.11.1)\n", + "Requirement already satisfied: packaging in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (21.3)\n", + "Requirement already satisfied: aiohttp in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (3.8.3)\n", + "Requirement already satisfied: responses<0.19 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from datasets==2.6.1) (0.18.0)\n", + "Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets==2.6.1) (4.3.0)\n", + "Requirement already satisfied: filelock in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets==2.6.1) (3.6.0)\n", + "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from packaging->datasets==2.6.1) (3.0.9)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->datasets==2.6.1) (3.3)\n", + "Requirement already satisfied: charset-normalizer<3,>=2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->datasets==2.6.1) (2.0.4)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->datasets==2.6.1) (1.26.11)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->datasets==2.6.1) (2022.9.24)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (4.0.2)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (1.3.3)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (1.3.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (6.0.2)\n", + "Requirement already satisfied: attrs>=17.3.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (21.4.0)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->datasets==2.6.1) (1.8.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from pandas->datasets==2.6.1) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from pandas->datasets==2.6.1) (2022.1)\n", + "Requirement already satisfied: six>=1.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from python-dateutil>=2.8.1->pandas->datasets==2.6.1) (1.16.0)\n", + "Collecting git+https://github.com/huggingface/transformers\n", + " Cloning https://github.com/huggingface/transformers to /private/var/folders/06/v7ccx_h57977_9w493b_k9gh0000gn/T/pip-req-build-ftcjclte\n", + " Running command git clone --filter=blob:none --quiet https://github.com/huggingface/transformers /private/var/folders/06/v7ccx_h57977_9w493b_k9gh0000gn/T/pip-req-build-ftcjclte\n", + " Resolved https://github.com/huggingface/transformers to commit cc3d0e1b017dbb8dcbba1eb01be77aef7bacee1a\n", + " Installing build dependencies ... \u001b[?25ldone\n", + "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n", + "\u001b[?25h Preparing metadata (pyproject.toml) ... \u001b[?25ldone\n", + "\u001b[?25hRequirement already satisfied: pyyaml>=5.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (6.0)\n", + "Requirement already satisfied: tqdm>=4.27 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (4.64.1)\n", + "Requirement already satisfied: requests in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (2.28.1)\n", + "Requirement already satisfied: huggingface-hub<1.0,>=0.10.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (0.11.1)\n", + "Requirement already satisfied: packaging>=20.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (21.3)\n", + "Requirement already satisfied: numpy>=1.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (1.21.5)\n", + "Requirement already satisfied: regex!=2019.12.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (2022.7.9)\n", + "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (0.13.2)\n", + "Requirement already satisfied: filelock in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from transformers==4.26.0.dev0) (3.6.0)\n", + "Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from huggingface-hub<1.0,>=0.10.0->transformers==4.26.0.dev0) (4.3.0)\n", + "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from packaging>=20.0->transformers==4.26.0.dev0) (3.0.9)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->transformers==4.26.0.dev0) (2022.9.24)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->transformers==4.26.0.dev0) (1.26.11)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->transformers==4.26.0.dev0) (3.3)\n", + "Requirement already satisfied: charset-normalizer<3,>=2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->transformers==4.26.0.dev0) (2.0.4)\n", + "Requirement already satisfied: librosa in /opt/homebrew/anaconda3/lib/python3.9/site-packages (0.9.2)\n", + "Requirement already satisfied: numba>=0.45.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (0.55.1)\n", + "Requirement already satisfied: numpy>=1.17.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (1.21.5)\n", + "Requirement already satisfied: soundfile>=0.10.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (0.11.0)\n", + "Requirement already satisfied: scipy>=1.2.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (1.9.1)\n", + "Requirement already satisfied: packaging>=20.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (21.3)\n", + "Requirement already satisfied: joblib>=0.14 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (1.1.0)\n", + "Requirement already satisfied: pooch>=1.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (1.6.0)\n", + "Requirement already satisfied: audioread>=2.1.9 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (3.0.0)\n", + "Requirement already satisfied: scikit-learn>=0.19.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (1.1.1)\n", + "Requirement already satisfied: decorator>=4.0.10 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (5.1.1)\n", + "Requirement already satisfied: resampy>=0.2.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from librosa) (0.4.2)\n", + "Requirement already satisfied: setuptools in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from numba>=0.45.1->librosa) (63.4.1)\n", + "Requirement already satisfied: llvmlite<0.39,>=0.38.0rc1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from numba>=0.45.1->librosa) (0.38.0)\n", + "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from packaging>=20.0->librosa) (3.0.9)\n", + "Requirement already satisfied: requests>=2.19.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from pooch>=1.0->librosa) (2.28.1)\n", + "Requirement already satisfied: appdirs>=1.3.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from pooch>=1.0->librosa) (1.4.4)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from scikit-learn>=0.19.1->librosa) (2.2.0)\n", + "Requirement already satisfied: cffi>=1.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from soundfile>=0.10.2->librosa) (1.15.1)\n", + "Requirement already satisfied: pycparser in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from cffi>=1.0->soundfile>=0.10.2->librosa) (2.21)\n", + "Requirement already satisfied: charset-normalizer<3,>=2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.0->librosa) (2.0.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.0->librosa) (3.3)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.0->librosa) (2022.9.24)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.0->librosa) (1.26.11)\n", + "\u001b[31mERROR: Could not find a version that satisfies the requirement evaluate==0.30 (from versions: 0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.2.1, 0.2.2, 0.3.0)\u001b[0m\u001b[31m\n", + "\u001b[0m\u001b[31mERROR: No matching distribution found for evaluate==0.30\u001b[0m\u001b[31m\n", + "\u001b[0mRequirement already satisfied: jiwer in /opt/homebrew/anaconda3/lib/python3.9/site-packages (2.5.1)\n", + "Requirement already satisfied: levenshtein==0.20.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from jiwer) (0.20.2)\n", + "Requirement already satisfied: rapidfuzz<3.0.0,>=2.3.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from levenshtein==0.20.2->jiwer) (2.13.2)\n", + "Requirement already satisfied: gradio in /opt/homebrew/anaconda3/lib/python3.9/site-packages (3.12.0)\n", + "Requirement already satisfied: python-multipart in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.0.5)\n", + "Requirement already satisfied: matplotlib in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (3.5.2)\n", + "Requirement already satisfied: uvicorn in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.20.0)\n", + "Requirement already satisfied: pyyaml in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (6.0)\n", + "Requirement already satisfied: numpy in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (1.21.5)\n", + "Requirement already satisfied: jinja2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (2.11.3)\n", + "Requirement already satisfied: paramiko in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (2.12.0)\n", + "Requirement already satisfied: pillow in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (9.2.0)\n", + "Requirement already satisfied: h11<0.13,>=0.11 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.12.0)\n", + "Requirement already satisfied: orjson in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (3.8.2)\n", + "Requirement already satisfied: requests in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (2.28.1)\n", + "Requirement already satisfied: markdown-it-py[linkify,plugins] in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (2.1.0)\n", + "Requirement already satisfied: pandas in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (1.4.4)\n", + "Requirement already satisfied: aiohttp in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (3.8.3)\n", + "Requirement already satisfied: ffmpy in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.3.0)\n", + "Requirement already satisfied: websockets>=10.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (10.4)\n", + "Requirement already satisfied: fastapi in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.88.0)\n", + "Requirement already satisfied: fsspec in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (2022.7.1)\n", + "Requirement already satisfied: pydantic in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (1.10.2)\n", + "Requirement already satisfied: pydub in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.25.1)\n", + "Requirement already satisfied: httpx in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (0.23.1)\n", + "Requirement already satisfied: pycryptodome in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from gradio) (3.16.0)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (1.8.1)\n", + "Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (2.0.4)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (6.0.2)\n", + "Requirement already satisfied: attrs>=17.3.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (21.4.0)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (1.3.1)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (1.3.3)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from aiohttp->gradio) (4.0.2)\n", + "Requirement already satisfied: starlette==0.22.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from fastapi->gradio) (0.22.0)\n", + "Requirement already satisfied: typing-extensions>=3.10.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from starlette==0.22.0->fastapi->gradio) (4.3.0)\n", + "Requirement already satisfied: anyio<5,>=3.4.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from starlette==0.22.0->fastapi->gradio) (3.5.0)\n", + "Requirement already satisfied: sniffio in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from httpx->gradio) (1.2.0)\n", + "Requirement already satisfied: rfc3986[idna2008]<2,>=1.3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from httpx->gradio) (1.5.0)\n", + "Requirement already satisfied: httpcore<0.17.0,>=0.15.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from httpx->gradio) (0.15.0)\n", + "Requirement already satisfied: certifi in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from httpx->gradio) (2022.9.24)\n", + "Requirement already satisfied: MarkupSafe>=0.23 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from jinja2->gradio) (2.0.1)\n", + "Requirement already satisfied: mdurl~=0.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from markdown-it-py[linkify,plugins]->gradio) (0.1.2)\n", + "Requirement already satisfied: mdit-py-plugins in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from markdown-it-py[linkify,plugins]->gradio) (0.3.1)\n", + "Requirement already satisfied: linkify-it-py~=1.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from markdown-it-py[linkify,plugins]->gradio) (1.0.3)\n", + "Requirement already satisfied: packaging>=20.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (21.3)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (4.25.0)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (2.8.2)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (1.4.2)\n", + "Requirement already satisfied: cycler>=0.10 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (0.11.0)\n", + "Requirement already satisfied: pyparsing>=2.2.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from matplotlib->gradio) (3.0.9)\n", + "Requirement already satisfied: pytz>=2020.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from pandas->gradio) (2022.1)\n", + "Requirement already satisfied: bcrypt>=3.1.3 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from paramiko->gradio) (3.2.0)\n", + "Requirement already satisfied: six in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from paramiko->gradio) (1.16.0)\n", + "Requirement already satisfied: pynacl>=1.0.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from paramiko->gradio) (1.5.0)\n", + "Requirement already satisfied: cryptography>=2.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from paramiko->gradio) (37.0.1)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->gradio) (1.26.11)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from requests->gradio) (3.3)\n", + "Requirement already satisfied: click>=7.0 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from uvicorn->gradio) (8.0.4)\n", + "Requirement already satisfied: cffi>=1.1 in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from bcrypt>=3.1.3->paramiko->gradio) (1.15.1)\n", + "Requirement already satisfied: uc-micro-py in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from linkify-it-py~=1.0->markdown-it-py[linkify,plugins]->gradio) (1.0.1)\n", + "Requirement already satisfied: pycparser in /opt/homebrew/anaconda3/lib/python3.9/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko->gradio) (2.21)\n" + ] + } + ], + "source": [ + "!pip install datasets==2.6.1\n", + "!pip install git+https://github.com/huggingface/transformers\n", + "!pip install librosa\n", + "!pip install evaluate==0.30\n", + "!pip install jiwer\n", + "!pip install gradio" + ] + }, + { + "cell_type": "markdown", + "id": "1f60d173-8de1-4ed7-bc9a-d281cf237203", + "metadata": { + "id": "1f60d173-8de1-4ed7-bc9a-d281cf237203" + }, + "source": [ + "We strongly advise you to upload model checkpoints directly the [Hugging Face Hub](https://huggingface.co/) \n", + "whilst training. The Hub provides:\n", + "- Integrated version control: you can be sure that no model checkpoint is lost during training.\n", + "- Tensorboard logs: track important metrics over the course of training.\n", + "- Model cards: document what a model does and its intended use cases.\n", + "- Community: an easy way to share and collaborate with the community!\n", + "\n", + "Linking the notebook to the Hub is straightforward - it simply requires entering your \n", + "Hub authentication token when prompted. Find your Hub authentication token [here](https://huggingface.co/settings/tokens):" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "b045a39e-2a3e-4153-bdb5-281500bcd348", + "metadata": { + "id": "b045a39e-2a3e-4153-bdb5-281500bcd348" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Token is valid.\n", + "Your token has been saved in your configured git credential helpers (osxkeychain).\n", + "Your token has been saved to /Users/ali/.huggingface/token\n", + "Login successful\n" + ] + } + ], + "source": [ + "from huggingface_hub import notebook_login\n", + "\n", + "notebook_login()" + ] + }, + { + "cell_type": "markdown", + "id": "b219c9dd-39b6-4a95-b2a1-3f547a1e7bc0", + "metadata": { + "id": "b219c9dd-39b6-4a95-b2a1-3f547a1e7bc0" + }, + "source": [ + "## Load Dataset" + ] + }, + { + "cell_type": "markdown", + "id": "674429c5-0ab4-4adf-975b-621bb69eca38", + "metadata": { + "id": "674429c5-0ab4-4adf-975b-621bb69eca38" + }, + "source": [ + "Using πŸ€— Datasets, downloading and preparing data is extremely simple. \n", + "We can download and prepare the Common Voice splits in just one line of code. \n", + "\n", + "First, ensure you have accepted 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). Once you have accepted the terms, you will have full access to the dataset and be able to download the data locally.\n", + "\n", + "Since Hindi is very low-resource, we'll combine the `train` and `validation` \n", + "splits to give approximately 8 hours of training data. We'll use the 4 hours \n", + "of `test` data as our held-out test set:" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "a2787582-554f-44ce-9f38-4180a5ed6b44", + "metadata": { + "id": "a2787582-554f-44ce-9f38-4180a5ed6b44" + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2c2a2c7b130f451d928495f64cfcd39c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Resolving data files: 0%| | 0/68519 [00:00\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m common_voice \u001b[39m=\u001b[39m DatasetDict()\n\u001b[1;32m 5\u001b[0m col_names \u001b[39m=\u001b[39m [\u001b[39m'\u001b[39m\u001b[39mwav_filename\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mwav_filesize\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[1;32m 6\u001b[0m \u001b[39m'\u001b[39m\u001b[39mtranscript\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mquran_id\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mreciter\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mbitrate\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39msplit\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39msubset\u001b[39m\u001b[39m'\u001b[39m]\n\u001b[0;32m----> 8\u001b[0m common_voice[\u001b[39m\"\u001b[39m\u001b[39mtrain\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m load_dataset(\u001b[39m\"\u001b[39;49m\u001b[39mcsv\u001b[39;49m\u001b[39m\"\u001b[39;49m, \u001b[39m\"\u001b[39;49m\u001b[39mmetadata.csv\u001b[39;49m\u001b[39m\"\u001b[39;49m, split\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39mtrain\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[1;32m 9\u001b[0m \u001b[39m# common_voice[\"test\"] = load_dataset(\"users_mixed.tsv\", split=\"test\")\u001b[39;00m\n\u001b[1;32m 11\u001b[0m \u001b[39mprint\u001b[39m(common_voice)\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/load.py:1742\u001b[0m, in \u001b[0;36mload_dataset\u001b[0;34m(path, name, data_dir, data_files, split, cache_dir, features, download_config, download_mode, ignore_verifications, keep_in_memory, save_infos, revision, use_auth_token, task, streaming, **config_kwargs)\u001b[0m\n\u001b[1;32m 1739\u001b[0m try_from_hf_gcs \u001b[39m=\u001b[39m path \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m _PACKAGED_DATASETS_MODULES\n\u001b[1;32m 1741\u001b[0m \u001b[39m# Download and prepare data\u001b[39;00m\n\u001b[0;32m-> 1742\u001b[0m builder_instance\u001b[39m.\u001b[39;49mdownload_and_prepare(\n\u001b[1;32m 1743\u001b[0m download_config\u001b[39m=\u001b[39;49mdownload_config,\n\u001b[1;32m 1744\u001b[0m download_mode\u001b[39m=\u001b[39;49mdownload_mode,\n\u001b[1;32m 1745\u001b[0m ignore_verifications\u001b[39m=\u001b[39;49mignore_verifications,\n\u001b[1;32m 1746\u001b[0m try_from_hf_gcs\u001b[39m=\u001b[39;49mtry_from_hf_gcs,\n\u001b[1;32m 1747\u001b[0m use_auth_token\u001b[39m=\u001b[39;49muse_auth_token,\n\u001b[1;32m 1748\u001b[0m )\n\u001b[1;32m 1750\u001b[0m \u001b[39m# Build dataset for splits\u001b[39;00m\n\u001b[1;32m 1751\u001b[0m keep_in_memory \u001b[39m=\u001b[39m (\n\u001b[1;32m 1752\u001b[0m keep_in_memory \u001b[39mif\u001b[39;00m keep_in_memory \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m is_small_dataset(builder_instance\u001b[39m.\u001b[39minfo\u001b[39m.\u001b[39mdataset_size)\n\u001b[1;32m 1753\u001b[0m )\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/builder.py:814\u001b[0m, in \u001b[0;36mDatasetBuilder.download_and_prepare\u001b[0;34m(self, output_dir, download_config, download_mode, ignore_verifications, try_from_hf_gcs, dl_manager, base_path, use_auth_token, file_format, max_shard_size, storage_options, **download_and_prepare_kwargs)\u001b[0m\n\u001b[1;32m 808\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m downloaded_from_gcs:\n\u001b[1;32m 809\u001b[0m prepare_split_kwargs \u001b[39m=\u001b[39m {\n\u001b[1;32m 810\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfile_format\u001b[39m\u001b[39m\"\u001b[39m: file_format,\n\u001b[1;32m 811\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmax_shard_size\u001b[39m\u001b[39m\"\u001b[39m: max_shard_size,\n\u001b[1;32m 812\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mdownload_and_prepare_kwargs,\n\u001b[1;32m 813\u001b[0m }\n\u001b[0;32m--> 814\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_download_and_prepare(\n\u001b[1;32m 815\u001b[0m dl_manager\u001b[39m=\u001b[39;49mdl_manager,\n\u001b[1;32m 816\u001b[0m verify_infos\u001b[39m=\u001b[39;49mverify_infos,\n\u001b[1;32m 817\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mprepare_split_kwargs,\n\u001b[1;32m 818\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mdownload_and_prepare_kwargs,\n\u001b[1;32m 819\u001b[0m )\n\u001b[1;32m 820\u001b[0m \u001b[39m# Sync info\u001b[39;00m\n\u001b[1;32m 821\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minfo\u001b[39m.\u001b[39mdataset_size \u001b[39m=\u001b[39m \u001b[39msum\u001b[39m(split\u001b[39m.\u001b[39mnum_bytes \u001b[39mfor\u001b[39;00m split \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minfo\u001b[39m.\u001b[39msplits\u001b[39m.\u001b[39mvalues())\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/builder.py:883\u001b[0m, in \u001b[0;36mDatasetBuilder._download_and_prepare\u001b[0;34m(self, dl_manager, verify_infos, **prepare_split_kwargs)\u001b[0m\n\u001b[1;32m 881\u001b[0m split_dict \u001b[39m=\u001b[39m SplitDict(dataset_name\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mname)\n\u001b[1;32m 882\u001b[0m split_generators_kwargs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_make_split_generators_kwargs(prepare_split_kwargs)\n\u001b[0;32m--> 883\u001b[0m split_generators \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_split_generators(dl_manager, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msplit_generators_kwargs)\n\u001b[1;32m 885\u001b[0m \u001b[39m# Checksums verification\u001b[39;00m\n\u001b[1;32m 886\u001b[0m \u001b[39mif\u001b[39;00m verify_infos \u001b[39mand\u001b[39;00m dl_manager\u001b[39m.\u001b[39mrecord_checksums:\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/packaged_modules/csv/csv.py:139\u001b[0m, in \u001b[0;36mCsv._split_generators\u001b[0;34m(self, dl_manager)\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mconfig\u001b[39m.\u001b[39mdata_files:\n\u001b[1;32m 138\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mAt least one data file must be specified, but got data_files=\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mconfig\u001b[39m.\u001b[39mdata_files\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 139\u001b[0m data_files \u001b[39m=\u001b[39m dl_manager\u001b[39m.\u001b[39;49mdownload_and_extract(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mconfig\u001b[39m.\u001b[39;49mdata_files)\n\u001b[1;32m 140\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(data_files, (\u001b[39mstr\u001b[39m, \u001b[39mlist\u001b[39m, \u001b[39mtuple\u001b[39m)):\n\u001b[1;32m 141\u001b[0m files \u001b[39m=\u001b[39m data_files\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/download/download_manager.py:433\u001b[0m, in \u001b[0;36mDownloadManager.download_and_extract\u001b[0;34m(self, url_or_urls)\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdownload_and_extract\u001b[39m(\u001b[39mself\u001b[39m, url_or_urls):\n\u001b[1;32m 418\u001b[0m \u001b[39m\"\"\"Download and extract given url_or_urls.\u001b[39;00m\n\u001b[1;32m 419\u001b[0m \n\u001b[1;32m 420\u001b[0m \u001b[39m Is roughly equivalent to:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[39m extracted_path(s): `str`, extracted paths of given URL(s).\u001b[39;00m\n\u001b[1;32m 432\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 433\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mextract(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mdownload(url_or_urls))\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/download/download_manager.py:405\u001b[0m, in \u001b[0;36mDownloadManager.extract\u001b[0;34m(self, path_or_paths, num_proc)\u001b[0m\n\u001b[1;32m 403\u001b[0m \u001b[39mif\u001b[39;00m download_config\u001b[39m.\u001b[39mdownload_desc \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 404\u001b[0m download_config\u001b[39m.\u001b[39mdownload_desc \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mDownloading data\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m--> 405\u001b[0m extracted_paths \u001b[39m=\u001b[39m map_nested(\n\u001b[1;32m 406\u001b[0m partial(cached_path, download_config\u001b[39m=\u001b[39;49mdownload_config),\n\u001b[1;32m 407\u001b[0m path_or_paths,\n\u001b[1;32m 408\u001b[0m num_proc\u001b[39m=\u001b[39;49mnum_proc,\n\u001b[1;32m 409\u001b[0m disable_tqdm\u001b[39m=\u001b[39;49m\u001b[39mnot\u001b[39;49;00m is_progress_bar_enabled(),\n\u001b[1;32m 410\u001b[0m desc\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39mExtracting data files\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m 411\u001b[0m )\n\u001b[1;32m 412\u001b[0m path_or_paths \u001b[39m=\u001b[39m NestedDataStructure(path_or_paths)\n\u001b[1;32m 413\u001b[0m extracted_paths \u001b[39m=\u001b[39m NestedDataStructure(extracted_paths)\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/py_utils.py:429\u001b[0m, in \u001b[0;36mmap_nested\u001b[0;34m(function, data_struct, dict_only, map_list, map_tuple, map_numpy, num_proc, parallel_min_length, types, disable_tqdm, desc)\u001b[0m\n\u001b[1;32m 427\u001b[0m num_proc \u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n\u001b[1;32m 428\u001b[0m \u001b[39mif\u001b[39;00m num_proc \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m \u001b[39mor\u001b[39;00m \u001b[39mlen\u001b[39m(iterable) \u001b[39m<\u001b[39m parallel_min_length:\n\u001b[0;32m--> 429\u001b[0m mapped \u001b[39m=\u001b[39m [\n\u001b[1;32m 430\u001b[0m _single_map_nested((function, obj, types, \u001b[39mNone\u001b[39;00m, \u001b[39mTrue\u001b[39;00m, \u001b[39mNone\u001b[39;00m))\n\u001b[1;32m 431\u001b[0m \u001b[39mfor\u001b[39;00m obj \u001b[39min\u001b[39;00m logging\u001b[39m.\u001b[39mtqdm(iterable, disable\u001b[39m=\u001b[39mdisable_tqdm, desc\u001b[39m=\u001b[39mdesc)\n\u001b[1;32m 432\u001b[0m ]\n\u001b[1;32m 433\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 434\u001b[0m num_proc \u001b[39m=\u001b[39m num_proc \u001b[39mif\u001b[39;00m num_proc \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(iterable) \u001b[39melse\u001b[39;00m \u001b[39mlen\u001b[39m(iterable)\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/py_utils.py:430\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 427\u001b[0m num_proc \u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n\u001b[1;32m 428\u001b[0m \u001b[39mif\u001b[39;00m num_proc \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m \u001b[39mor\u001b[39;00m \u001b[39mlen\u001b[39m(iterable) \u001b[39m<\u001b[39m parallel_min_length:\n\u001b[1;32m 429\u001b[0m mapped \u001b[39m=\u001b[39m [\n\u001b[0;32m--> 430\u001b[0m _single_map_nested((function, obj, types, \u001b[39mNone\u001b[39;49;00m, \u001b[39mTrue\u001b[39;49;00m, \u001b[39mNone\u001b[39;49;00m))\n\u001b[1;32m 431\u001b[0m \u001b[39mfor\u001b[39;00m obj \u001b[39min\u001b[39;00m logging\u001b[39m.\u001b[39mtqdm(iterable, disable\u001b[39m=\u001b[39mdisable_tqdm, desc\u001b[39m=\u001b[39mdesc)\n\u001b[1;32m 432\u001b[0m ]\n\u001b[1;32m 433\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 434\u001b[0m num_proc \u001b[39m=\u001b[39m num_proc \u001b[39mif\u001b[39;00m num_proc \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(iterable) \u001b[39melse\u001b[39;00m \u001b[39mlen\u001b[39m(iterable)\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/py_utils.py:349\u001b[0m, in \u001b[0;36m_single_map_nested\u001b[0;34m(args)\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[39mreturn\u001b[39;00m {k: _single_map_nested((function, v, types, \u001b[39mNone\u001b[39;00m, \u001b[39mTrue\u001b[39;00m, \u001b[39mNone\u001b[39;00m)) \u001b[39mfor\u001b[39;00m k, v \u001b[39min\u001b[39;00m pbar}\n\u001b[1;32m 348\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 349\u001b[0m mapped \u001b[39m=\u001b[39m [_single_map_nested((function, v, types, \u001b[39mNone\u001b[39;00m, \u001b[39mTrue\u001b[39;00m, \u001b[39mNone\u001b[39;00m)) \u001b[39mfor\u001b[39;00m v \u001b[39min\u001b[39;00m pbar]\n\u001b[1;32m 350\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(data_struct, \u001b[39mlist\u001b[39m):\n\u001b[1;32m 351\u001b[0m \u001b[39mreturn\u001b[39;00m mapped\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/py_utils.py:349\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[39mreturn\u001b[39;00m {k: _single_map_nested((function, v, types, \u001b[39mNone\u001b[39;00m, \u001b[39mTrue\u001b[39;00m, \u001b[39mNone\u001b[39;00m)) \u001b[39mfor\u001b[39;00m k, v \u001b[39min\u001b[39;00m pbar}\n\u001b[1;32m 348\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 349\u001b[0m mapped \u001b[39m=\u001b[39m [_single_map_nested((function, v, types, \u001b[39mNone\u001b[39;49;00m, \u001b[39mTrue\u001b[39;49;00m, \u001b[39mNone\u001b[39;49;00m)) \u001b[39mfor\u001b[39;00m v \u001b[39min\u001b[39;00m pbar]\n\u001b[1;32m 350\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(data_struct, \u001b[39mlist\u001b[39m):\n\u001b[1;32m 351\u001b[0m \u001b[39mreturn\u001b[39;00m mapped\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/py_utils.py:331\u001b[0m, in \u001b[0;36m_single_map_nested\u001b[0;34m(args)\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[39m# Singleton first to spare some computation\u001b[39;00m\n\u001b[1;32m 330\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(data_struct, \u001b[39mdict\u001b[39m) \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(data_struct, types):\n\u001b[0;32m--> 331\u001b[0m \u001b[39mreturn\u001b[39;00m function(data_struct)\n\u001b[1;32m 333\u001b[0m \u001b[39m# Reduce logging to keep things readable in multiprocessing with tqdm\u001b[39;00m\n\u001b[1;32m 334\u001b[0m \u001b[39mif\u001b[39;00m rank \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m logging\u001b[39m.\u001b[39mget_verbosity() \u001b[39m<\u001b[39m logging\u001b[39m.\u001b[39mWARNING:\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/file_utils.py:216\u001b[0m, in \u001b[0;36mcached_path\u001b[0;34m(url_or_filename, download_config, **download_kwargs)\u001b[0m\n\u001b[1;32m 213\u001b[0m \u001b[39mreturn\u001b[39;00m output_path\n\u001b[1;32m 215\u001b[0m \u001b[39mif\u001b[39;00m download_config\u001b[39m.\u001b[39mextract_compressed_file:\n\u001b[0;32m--> 216\u001b[0m output_path \u001b[39m=\u001b[39m ExtractManager(cache_dir\u001b[39m=\u001b[39;49mdownload_config\u001b[39m.\u001b[39;49mcache_dir)\u001b[39m.\u001b[39;49mextract(\n\u001b[1;32m 217\u001b[0m output_path, force_extract\u001b[39m=\u001b[39;49mdownload_config\u001b[39m.\u001b[39;49mforce_extract\n\u001b[1;32m 218\u001b[0m )\n\u001b[1;32m 220\u001b[0m \u001b[39mreturn\u001b[39;00m output_path\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/extract.py:50\u001b[0m, in \u001b[0;36mExtractManager.extract\u001b[0;34m(self, input_path, force_extract)\u001b[0m\n\u001b[1;32m 48\u001b[0m output_path \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_get_output_path(input_path)\n\u001b[1;32m 49\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_do_extract(output_path, force_extract):\n\u001b[0;32m---> 50\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mextractor\u001b[39m.\u001b[39;49mextract(input_path, output_path, extractor_format)\n\u001b[1;32m 51\u001b[0m \u001b[39mreturn\u001b[39;00m output_path\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/extract.py:316\u001b[0m, in \u001b[0;36mExtractor.extract\u001b[0;34m(cls, input_path, output_path, extractor_format, extractor)\u001b[0m\n\u001b[1;32m 314\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 315\u001b[0m extractor \u001b[39m=\u001b[39m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39mextractors[extractor_format]\n\u001b[0;32m--> 316\u001b[0m \u001b[39mreturn\u001b[39;00m extractor\u001b[39m.\u001b[39;49mextract(input_path, output_path)\n\u001b[1;32m 317\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 318\u001b[0m warnings\u001b[39m.\u001b[39mwarn(\n\u001b[1;32m 319\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mParameter \u001b[39m\u001b[39m'\u001b[39m\u001b[39mextractor_format\u001b[39m\u001b[39m'\u001b[39m\u001b[39m was made required in version 2.4.0 and not passing it will raise an \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 320\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mexception in 3.0.0.\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 321\u001b[0m category\u001b[39m=\u001b[39m\u001b[39mFutureWarning\u001b[39;00m,\n\u001b[1;32m 322\u001b[0m )\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/datasets/utils/extract.py:129\u001b[0m, in \u001b[0;36mTarExtractor.extract\u001b[0;34m(input_path, output_path)\u001b[0m\n\u001b[1;32m 127\u001b[0m os\u001b[39m.\u001b[39mmakedirs(output_path, exist_ok\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m 128\u001b[0m tar_file \u001b[39m=\u001b[39m tarfile\u001b[39m.\u001b[39mopen(input_path)\n\u001b[0;32m--> 129\u001b[0m tar_file\u001b[39m.\u001b[39;49mextractall(output_path, members\u001b[39m=\u001b[39;49mTarExtractor\u001b[39m.\u001b[39;49msafemembers(tar_file))\n\u001b[1;32m 130\u001b[0m tar_file\u001b[39m.\u001b[39mclose()\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/tarfile.py:2045\u001b[0m, in \u001b[0;36mTarFile.extractall\u001b[0;34m(self, path, members, numeric_owner)\u001b[0m\n\u001b[1;32m 2043\u001b[0m tarinfo\u001b[39m.\u001b[39mmode \u001b[39m=\u001b[39m \u001b[39m0o700\u001b[39m\n\u001b[1;32m 2044\u001b[0m \u001b[39m# Do not set_attrs directories, as we will do that further down\u001b[39;00m\n\u001b[0;32m-> 2045\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mextract(tarinfo, path, set_attrs\u001b[39m=\u001b[39;49m\u001b[39mnot\u001b[39;49;00m tarinfo\u001b[39m.\u001b[39;49misdir(),\n\u001b[1;32m 2046\u001b[0m numeric_owner\u001b[39m=\u001b[39;49mnumeric_owner)\n\u001b[1;32m 2048\u001b[0m \u001b[39m# Reverse sort directories.\u001b[39;00m\n\u001b[1;32m 2049\u001b[0m directories\u001b[39m.\u001b[39msort(key\u001b[39m=\u001b[39m\u001b[39mlambda\u001b[39;00m a: a\u001b[39m.\u001b[39mname)\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/tarfile.py:2086\u001b[0m, in \u001b[0;36mTarFile.extract\u001b[0;34m(self, member, path, set_attrs, numeric_owner)\u001b[0m\n\u001b[1;32m 2083\u001b[0m tarinfo\u001b[39m.\u001b[39m_link_target \u001b[39m=\u001b[39m os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mjoin(path, tarinfo\u001b[39m.\u001b[39mlinkname)\n\u001b[1;32m 2085\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 2086\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_extract_member(tarinfo, os\u001b[39m.\u001b[39;49mpath\u001b[39m.\u001b[39;49mjoin(path, tarinfo\u001b[39m.\u001b[39;49mname),\n\u001b[1;32m 2087\u001b[0m set_attrs\u001b[39m=\u001b[39;49mset_attrs,\n\u001b[1;32m 2088\u001b[0m numeric_owner\u001b[39m=\u001b[39;49mnumeric_owner)\n\u001b[1;32m 2089\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mOSError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 2090\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39merrorlevel \u001b[39m>\u001b[39m \u001b[39m0\u001b[39m:\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/tarfile.py:2151\u001b[0m, in \u001b[0;36mTarFile._extract_member\u001b[0;34m(self, tarinfo, targetpath, set_attrs, numeric_owner)\u001b[0m\n\u001b[1;32m 2147\u001b[0m upperdirs \u001b[39m=\u001b[39m os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mdirname(targetpath)\n\u001b[1;32m 2148\u001b[0m \u001b[39mif\u001b[39;00m upperdirs \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mexists(upperdirs):\n\u001b[1;32m 2149\u001b[0m \u001b[39m# Create directories that are not part of the archive with\u001b[39;00m\n\u001b[1;32m 2150\u001b[0m \u001b[39m# default permissions.\u001b[39;00m\n\u001b[0;32m-> 2151\u001b[0m os\u001b[39m.\u001b[39;49mmakedirs(upperdirs)\n\u001b[1;32m 2153\u001b[0m \u001b[39mif\u001b[39;00m tarinfo\u001b[39m.\u001b[39mislnk() \u001b[39mor\u001b[39;00m tarinfo\u001b[39m.\u001b[39missym():\n\u001b[1;32m 2154\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_dbg(\u001b[39m1\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m -> \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m (tarinfo\u001b[39m.\u001b[39mname, tarinfo\u001b[39m.\u001b[39mlinkname))\n", + "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/os.py:225\u001b[0m, in \u001b[0;36mmakedirs\u001b[0;34m(name, mode, exist_ok)\u001b[0m\n\u001b[1;32m 223\u001b[0m \u001b[39mreturn\u001b[39;00m\n\u001b[1;32m 224\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 225\u001b[0m mkdir(name, mode)\n\u001b[1;32m 226\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mOSError\u001b[39;00m:\n\u001b[1;32m 227\u001b[0m \u001b[39m# Cannot rely on checking for EEXIST, since the operating system\u001b[39;00m\n\u001b[1;32m 228\u001b[0m \u001b[39m# could give priority to other errors like EACCES or EROFS\u001b[39;00m\n\u001b[1;32m 229\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m exist_ok \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m path\u001b[39m.\u001b[39misdir(name):\n", + "\u001b[0;31mOSError\u001b[0m: [Errno 92] Illegal byte sequence: '/Users/ali/.cache/huggingface/datasets/downloads/extracted/33b8e8ba9ea0e760f74dbab2ec01c58969ab285bfee800fc61478672897acb43/\\udcff&'" + ] + } + ], + "source": [ + "from datasets import load_dataset, DatasetDict\n", + "\n", + "common_voice = DatasetDict()\n", + "\n", + "common_voice[\"train\"] = load_dataset(\"csv\", \"metadata.csv\", split=\"train\")\n", + "# common_voice[\"test\"] = load_dataset(\"users_mixed.tsv\", split=\"test\")\n", + "\n", + "print(common_voice)" + ] + }, + { + "cell_type": "markdown", + "id": "d5c7c3d6-7197-41e7-a088-49b753c1681f", + "metadata": { + "id": "d5c7c3d6-7197-41e7-a088-49b753c1681f" + }, + "source": [ + "Most ASR datasets only provide input audio samples (`audio`) and the \n", + "corresponding transcribed text (`sentence`). Common Voice contains additional \n", + "metadata information, such as `accent` and `locale`, which we can disregard for ASR.\n", + "Keeping the notebook as general as possible, we only consider the input audio and\n", + "transcribed text for fine-tuning, discarding the additional metadata information:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20ba635d-518c-47ac-97ee-3cad25f1e0ce", + "metadata": { + "id": "20ba635d-518c-47ac-97ee-3cad25f1e0ce" + }, + "outputs": [], + "source": [ + "common_voice = common_voice.remove_columns([\"accent\", \"age\", \"client_id\", \"down_votes\", \"gender\", \"locale\", \"path\", \"segment\", \"up_votes\"])\n", + "\n", + "print(common_voice)" + ] + }, + { + "cell_type": "markdown", + "id": "2d63b2d2-f68a-4d74-b7f1-5127f6d16605", + "metadata": { + "id": "2d63b2d2-f68a-4d74-b7f1-5127f6d16605" + }, + "source": [ + "## Prepare Feature Extractor, Tokenizer and Data" + ] + }, + { + "cell_type": "markdown", + "id": "601c3099-1026-439e-93e2-5635b3ba5a73", + "metadata": { + "id": "601c3099-1026-439e-93e2-5635b3ba5a73" + }, + "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.\n", + "\n", + "We'll go through details for setting-up the feature extractor and tokenizer one-by-one!" + ] + }, + { + "cell_type": "markdown", + "id": "560332eb-3558-41a1-b500-e83a9f695f84", + "metadata": { + "id": "560332eb-3558-41a1-b500-e83a9f695f84" + }, + "source": [ + "### Load WhisperFeatureExtractor" + ] + }, + { + "cell_type": "markdown", + "id": "32ec8068-0bd7-412d-b662-0edb9d1e7365", + "metadata": { + "id": "32ec8068-0bd7-412d-b662-0edb9d1e7365" + }, + "source": [ + "The Whisper feature extractor performs two operations:\n", + "1. Pads / truncates the audio inputs to 30s: any audio inputs shorter than 30s are padded to 30s with silence (zeros), and those longer that 30s are truncated to 30s\n", + "2. Converts the audio inputs to _log-Mel spectrogram_ input features, a visual representation of the audio and the form of the input expected by the Whisper model" + ] + }, + { + "cell_type": "markdown", + "id": "589d9ec1-d12b-4b64-93f7-04c63997da19", + "metadata": { + "id": "589d9ec1-d12b-4b64-93f7-04c63997da19" + }, + "source": [ + "
\n", + "\"Trulli\"\n", + "
Figure 2: Conversion of sampled audio array to log-Mel spectrogram.\n", + "Left: sampled 1-dimensional audio signal. Right: corresponding log-Mel spectrogram. Figure source:\n", + "Google SpecAugment Blog.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "b2ef54d5-b946-4c1d-9fdc-adc5d01b46aa", + "metadata": { + "id": "b2ef54d5-b946-4c1d-9fdc-adc5d01b46aa" + }, + "source": [ + "We'll load the feature extractor from the pre-trained checkpoint with the default values:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc77d7bb-f9e2-47f5-b663-30f7a4321ce5", + "metadata": { + "id": "bc77d7bb-f9e2-47f5-b663-30f7a4321ce5" + }, + "outputs": [], + "source": [ + "from transformers import WhisperFeatureExtractor\n", + "\n", + "feature_extractor = WhisperFeatureExtractor.from_pretrained(\"openai/whisper-small\")" + ] + }, + { + "cell_type": "markdown", + "id": "93748af7-b917-4ecf-a0c8-7d89077ff9cb", + "metadata": { + "id": "93748af7-b917-4ecf-a0c8-7d89077ff9cb" + }, + "source": [ + "### Load WhisperTokenizer" + ] + }, + { + "cell_type": "markdown", + "id": "2bc82609-a9fb-447a-a2af-99597c864029", + "metadata": { + "id": "2bc82609-a9fb-447a-a2af-99597c864029" + }, + "source": [ + "The Whisper model outputs a sequence of _token ids_. The tokenizer maps each of these token ids to their corresponding text string. For Hindi, we can load the pre-trained tokenizer and use it for fine-tuning without any further modifications. We simply have to \n", + "specify the target language and the task. These arguments inform the \n", + "tokenizer to prefix the language and task tokens to the start of encoded \n", + "label sequences:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7b07f9b-ae0e-4f89-98f0-0c50d432eab6", + "metadata": { + "id": "c7b07f9b-ae0e-4f89-98f0-0c50d432eab6", + "outputId": "5c004b44-86e7-4e00-88be-39e0af5eed69" + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "90d056e20b3e4f14ae0199a1a4ab1bb0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Downloading: 0%| | 0.00/829 [00:00 1 will enable multiprocessing. If the `.map` method hangs with multiprocessing, set `num_proc=1` and process the dataset sequentially." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7b73ab39-ffaf-4b9e-86e5-782963c6134b", + "metadata": { + "id": "7b73ab39-ffaf-4b9e-86e5-782963c6134b" + }, + "outputs": [], + "source": [ + "common_voice = common_voice.map(prepare_dataset, remove_columns=common_voice.column_names[\"train\"], num_proc=2)" + ] + }, + { + "cell_type": "markdown", + "id": "263a5a58-0239-4a25-b0df-c625fc9c5810", + "metadata": { + "id": "263a5a58-0239-4a25-b0df-c625fc9c5810" + }, + "source": [ + "## Training and Evaluation" + ] + }, + { + "cell_type": "markdown", + "id": "a693e768-c5a6-453f-89a1-b601dcf7daf7", + "metadata": { + "id": "a693e768-c5a6-453f-89a1-b601dcf7daf7" + }, + "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.\n", + "\n", + "Once we've fine-tuned the model, we will evaluate it on the test data to verify that we have correctly trained it \n", + "to transcribe speech in Hindi." + ] + }, + { + "cell_type": "markdown", + "id": "8d230e6d-624c-400a-bbf5-fa660881df25", + "metadata": { + "id": "8d230e6d-624c-400a-bbf5-fa660881df25" + }, + "source": [ + "### Define a Data Collator" + ] + }, + { + "cell_type": "markdown", + "id": "04def221-0637-4a69-b242-d3f0c1d0ee78", + "metadata": { + "id": "04def221-0637-4a69-b242-d3f0c1d0ee78" + }, + "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": null, + "id": "8326221e-ec13-4731-bb4e-51e5fc1486c5", + "metadata": { + "id": "8326221e-ec13-4731-bb4e-51e5fc1486c5" + }, + "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": { + "id": "3cae7dbf-8a50-456e-a3a8-7fd005390f86" + }, + "source": [ + "Let's initialise the data collator we've just defined:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc834702-c0d3-4a96-b101-7b87be32bf42", + "metadata": { + "id": "fc834702-c0d3-4a96-b101-7b87be32bf42" + }, + "outputs": [], + "source": [ + "data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)" + ] + }, + { + "cell_type": "markdown", + "id": "d62bb2ab-750a-45e7-82e9-61d6f4805698", + "metadata": { + "id": "d62bb2ab-750a-45e7-82e9-61d6f4805698" + }, + "source": [ + "### Evaluation Metrics" + ] + }, + { + "cell_type": "markdown", + "id": "66fee1a7-a44c-461e-b047-c3917221572e", + "metadata": { + "id": "66fee1a7-a44c-461e-b047-c3917221572e" + }, + "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": null, + "id": "b22b4011-f31f-4b57-b684-c52332f92890", + "metadata": { + "id": "b22b4011-f31f-4b57-b684-c52332f92890" + }, + "outputs": [], + "source": [ + "import evaluate\n", + "\n", + "metric = evaluate.load(\"wer\")" + ] + }, + { + "cell_type": "markdown", + "id": "4f32cab6-31f0-4cb9-af4c-40ba0f5fc508", + "metadata": { + "id": "4f32cab6-31f0-4cb9-af4c-40ba0f5fc508" + }, + "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:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23959a70-22d0-4ffe-9fa1-72b61e75bb52", + "metadata": { + "id": "23959a70-22d0-4ffe-9fa1-72b61e75bb52" + }, + "outputs": [], + "source": [ + "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] = tokenizer.pad_token_id\n", + "\n", + " # we do not want to group tokens when computing the metrics\n", + " pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)\n", + " label_str = tokenizer.batch_decode(label_ids, skip_special_tokens=True)\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": { + "id": "daf2a825-6d9f-4a23-b145-c37c0039075b" + }, + "source": [ + "###Β Load a Pre-Trained Checkpoint" + ] + }, + { + "cell_type": "markdown", + "id": "437a97fa-4864-476b-8abc-f28b8166cfa5", + "metadata": { + "id": "437a97fa-4864-476b-8abc-f28b8166cfa5" + }, + "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": null, + "id": "5a10cc4b-07ec-4ebd-ac1d-7c601023594f", + "metadata": { + "id": "5a10cc4b-07ec-4ebd-ac1d-7c601023594f" + }, + "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": { + "id": "a15ead5f-2277-4a39-937b-585c2497b2df" + }, + "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)):" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62038ba3-88ed-4fce-84db-338f50dcd04f", + "metadata": { + "id": "62038ba3-88ed-4fce-84db-338f50dcd04f" + }, + "outputs": [], + "source": [ + "model.config.forced_decoder_ids = None\n", + "model.config.suppress_tokens = []" + ] + }, + { + "cell_type": "markdown", + "id": "2178dea4-80ca-47b6-b6ea-ba1915c90c06", + "metadata": { + "id": "2178dea4-80ca-47b6-b6ea-ba1915c90c06" + }, + "source": [ + "### Define the Training Configuration" + ] + }, + { + "cell_type": "markdown", + "id": "c21af1e9-0188-4134-ac82-defc7bdcc436", + "metadata": { + "id": "c21af1e9-0188-4134-ac82-defc7bdcc436" + }, + "source": [ + "In the final step, we define all the parameters related to training. 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": null, + "id": "0ae3e9af-97b7-4aa0-ae85-20b23b5bcb3a", + "metadata": { + "id": "0ae3e9af-97b7-4aa0-ae85-20b23b5bcb3a" + }, + "outputs": [], + "source": [ + "from transformers import Seq2SeqTrainingArguments\n", + "\n", + "training_args = Seq2SeqTrainingArguments(\n", + " output_dir=\"./whisper-small-hi\", # change to a repo name of your choice\n", + " per_device_train_batch_size=16,\n", + " gradient_accumulation_steps=1, # increase by 2x for every 2x decrease in batch size\n", + " learning_rate=1e-5,\n", + " warmup_steps=500,\n", + " max_steps=4000,\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=True,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "b3a944d8-3112-4552-82a0-be25988b3857", + "metadata": { + "id": "b3a944d8-3112-4552-82a0-be25988b3857" + }, + "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": "bac29114-d226-4f54-97cf-8718c9f94e1e", + "metadata": { + "id": "bac29114-d226-4f54-97cf-8718c9f94e1e" + }, + "source": [ + "We can forward the training arguments to the πŸ€— Trainer along with our model,\n", + "dataset, data collator and `compute_metrics` function:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d546d7fe-0543-479a-b708-2ebabec19493", + "metadata": { + "id": "d546d7fe-0543-479a-b708-2ebabec19493" + }, + "outputs": [], + "source": [ + "from transformers import Seq2SeqTrainer\n", + "\n", + "trainer = Seq2SeqTrainer(\n", + " args=training_args,\n", + " model=model,\n", + " train_dataset=common_voice[\"train\"],\n", + " eval_dataset=common_voice[\"test\"],\n", + " data_collator=data_collator,\n", + " compute_metrics=compute_metrics,\n", + " tokenizer=processor.feature_extractor,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "uOrRhDGtN5S4", + "metadata": { + "id": "uOrRhDGtN5S4" + }, + "source": [ + "We'll save the processor object once before starting training. Since the processor is not trainable, it won't change over the course of training:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "-2zQwMfEOBJq", + "metadata": { + "id": "-2zQwMfEOBJq" + }, + "outputs": [], + "source": [ + "processor.save_pretrained(training_args.output_dir)" + ] + }, + { + "cell_type": "markdown", + "id": "7f404cf9-4345-468c-8196-4bd101d9bd51", + "metadata": { + "id": "7f404cf9-4345-468c-8196-4bd101d9bd51" + }, + "source": [ + "### Training" + ] + }, + { + "cell_type": "markdown", + "id": "5e8b8d56-5a70-4f68-bd2e-f0752d0bd112", + "metadata": { + "id": "5e8b8d56-5a70-4f68-bd2e-f0752d0bd112" + }, + "source": [ + "Training will take approximately 5-10 hours depending on your GPU or the one \n", + "allocated to this Google Colab. If using this Google Colab directly to \n", + "fine-tune a Whisper model, you should make sure that training isn't \n", + "interrupted due to inactivity. A simple workaround to prevent this is \n", + "to paste the following code into the console of this tab (_right mouse click_ \n", + "-> _inspect_ -> _Console tab_ -> _insert code_)." + ] + }, + { + "cell_type": "markdown", + "id": "890a63ed-e87b-4e53-a35a-6ec1eca560af", + "metadata": { + "id": "890a63ed-e87b-4e53-a35a-6ec1eca560af" + }, + "source": [ + "```javascript\n", + "function ConnectButton(){\n", + " console.log(\"Connect pushed\"); \n", + " document.querySelector(\"#top-toolbar > colab-connect-button\").shadowRoot.querySelector(\"#connect\").click() \n", + "}\n", + "setInterval(ConnectButton, 60000);\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "5a55168b-2f46-4678-afa0-ff22257ec06d", + "metadata": { + "id": "5a55168b-2f46-4678-afa0-ff22257ec06d" + }, + "source": [ + "The peak GPU memory for the given training configuration is approximately 15.8GB. \n", + "Depending on the GPU allocated to the Google Colab, 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": null, + "id": "ee8b7b8e-1c9a-4d77-9137-1778a629e6de", + "metadata": { + "id": "ee8b7b8e-1c9a-4d77-9137-1778a629e6de" + }, + "outputs": [], + "source": [ + "trainer.train()" + ] + }, + { + "cell_type": "markdown", + "id": "810ced54-7187-4a06-b2fe-ba6dcca94dc3", + "metadata": { + "id": "810ced54-7187-4a06-b2fe-ba6dcca94dc3" + }, + "source": [ + "Our best WER is 32.0% - not bad for 8h of training data! We can submit our checkpoint to the [`hf-speech-bench`](https://huggingface.co/spaces/huggingface/hf-speech-bench) on push by setting the appropriate key-word arguments (kwargs):" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c704f91e-241b-48c9-b8e0-f0da396a9663", + "metadata": { + "id": "c704f91e-241b-48c9-b8e0-f0da396a9663" + }, + "outputs": [], + "source": [ + "kwargs = {\n", + " \"dataset_tags\": \"mozilla-foundation/common_voice_11_0\",\n", + " \"dataset\": \"Common Voice 11.0\", # a 'pretty' name for the training dataset\n", + " \"dataset_args\": \"config: hi, split: test\",\n", + " \"language\": \"hi\",\n", + " \"model_name\": \"Whisper Small Hi - Sanchit Gandhi\", # a 'pretty' name for our model\n", + " \"finetuned_from\": \"openai/whisper-small\",\n", + " \"tasks\": \"automatic-speech-recognition\",\n", + " \"tags\": \"hf-asr-leaderboard\",\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "090d676a-f944-4297-a938-a40eda0b2b68", + "metadata": { + "id": "090d676a-f944-4297-a938-a40eda0b2b68" + }, + "source": [ + "The training results can now be uploaded to the Hub. To do so, execute the `push_to_hub` command and save the preprocessor object we created:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7030622-caf7-4039-939b-6195cdaa2585", + "metadata": { + "id": "d7030622-caf7-4039-939b-6195cdaa2585" + }, + "outputs": [], + "source": [ + "trainer.push_to_hub(**kwargs)" + ] + }, + { + "cell_type": "markdown", + "id": "34d4360d-5721-426e-b6ac-178f833fedeb", + "metadata": { + "id": "34d4360d-5721-426e-b6ac-178f833fedeb" + }, + "source": [ + "## Building a Demo" + ] + }, + { + "cell_type": "markdown", + "id": "e65489b7-18d1-447c-ba69-cd28dd80dad9", + "metadata": { + "id": "e65489b7-18d1-447c-ba69-cd28dd80dad9" + }, + "source": [ + "Now that we've fine-tuned our model we can build a demo to show \n", + "off its ASR capabilities! We'll make use of πŸ€— Transformers \n", + "`pipeline`, which will take care of the entire ASR pipeline, \n", + "right from pre-processing the audio inputs to decoding the \n", + "model predictions.\n", + "\n", + "Running the example below will generate a Gradio demo where we \n", + "can record speech through the microphone of our computer and input it to \n", + "our fine-tuned Whisper model to transcribe the corresponding text:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0ace3aa-1ef3-45cb-933f-6ddca037c5aa", + "metadata": { + "id": "e0ace3aa-1ef3-45cb-933f-6ddca037c5aa" + }, + "outputs": [], + "source": [ + "from transformers import pipeline\n", + "import gradio as gr\n", + "\n", + "pipe = pipeline(model=\"sanchit-gandhi/whisper-small-hi\") # change to \"your-username/the-name-you-picked\"\n", + "\n", + "def transcribe(audio):\n", + " text = pipe(audio)[\"text\"]\n", + " return text\n", + "\n", + "iface = gr.Interface(\n", + " fn=transcribe, \n", + " inputs=gr.Audio(source=\"microphone\", type=\"filepath\"), \n", + " outputs=\"text\",\n", + " title=\"Whisper Small Hindi\",\n", + " description=\"Realtime demo for Hindi speech recognition using a fine-tuned Whisper small model.\",\n", + ")\n", + "\n", + "iface.launch()" + ] + }, + { + "cell_type": "markdown", + "id": "ca743fbd-602c-48d4-ba8d-a2fe60af64ba", + "metadata": { + "id": "ca743fbd-602c-48d4-ba8d-a2fe60af64ba" + }, + "source": [ + "## Closing Remarks" + ] + }, + { + "cell_type": "markdown", + "id": "7f737783-2870-4e35-aa11-86a42d7d997a", + "metadata": { + "id": "7f737783-2870-4e35-aa11-86a42d7d997a" + }, + "source": [ + "In this blog, we covered a step-by-step guide on fine-tuning Whisper for multilingual ASR \n", + "using πŸ€— Datasets, Transformers and the Hugging Face Hub. For more details on the Whisper model, the Common Voice dataset and the theory behind fine-tuning, refere to the accompanying [blog post](https://huggingface.co/blog/fine-tune-whisper). If you're interested in fine-tuning other \n", + "Transformers models, both for English and multilingual ASR, be sure to check out the \n", + "examples scripts at [examples/pytorch/speech-recognition](https://github.com/huggingface/transformers/tree/main/examples/pytorch/speech-recognition)." + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3.9.13", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + }, + "vscode": { + "interpreter": { + "hash": "38cca0c38332a56087b24af0bc80247f4fced29cb4f7f437d91dc159adec9c4e" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}