import{S as qy,i as Py,s as Oy,e as n,k as h,w as u,t as l,M as Ly,c as o,d as a,m as c,a as r,x as f,h as s,b as d,G as t,g as p,y as m,q as y,o as M,B as w,v as Ky}from"../../chunks/vendor-hf-doc-builder.js";import{T as Dy}from"../../chunks/Tip-hf-doc-builder.js";import{I as $}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as g}from"../../chunks/CodeBlock-hf-doc-builder.js";function eM(ia){let b;return{c(){b=l('You can change the language identifier from `"dv"` to a language identifier of your choice. To see all possible languages\n    in Common Voice 13, check out the dataset card on the Hugging Face Hub: https://huggingface.co/datasets/mozilla-foundation/common_voice_13_0')},l(J){b=s(J,'You can change the language identifier from `"dv"` to a language identifier of your choice. To see all possible languages\n    in Common Voice 13, check out the dataset card on the Hugging Face Hub: https://huggingface.co/datasets/mozilla-foundation/common_voice_13_0')},m(J,G){p(J,b,G)},d(J){J&&a(b)}}}function tM(ia){let b;return{c(){b=l("If you do not want to upload the model checkpoints to the Hub, set `push_to_hub=False`.")},l(J){b=s(J,"If you do not want to upload the model checkpoints to the Hub, set `push_to_hub=False`.")},m(J,G){p(J,b,G)},d(J){J&&a(b)}}}function aM(ia){let b,J,G,we,sl,lt,Pr,nl,Or,mn,pa,Lr,yn,ha,Kr,Mn,ca,ei,wn,da,ti,gn,oe,ge,ol,st,ai,rl,li,bn,be,si,nt,ni,oi,Jn,Z,il,ri,ii,pl,pi,hi,hl,ci,di,cl,ui,Tn,Je,fi,ot,mi,yi,vn,rt,Un,ua,dl,Mi,jn,it,_n,re,Te,ul,pt,wi,fl,gi,En,ht,ct,bi,Ji,In,B,Ti,ml,vi,Ui,yl,ji,_i,Ml,Ei,Ii,kn,dt,Wn,fa,wl,ki,Cn,ut,Gn,ve,$n,_,Wi,gl,Ci,Gi,bl,$i,Zi,Jl,Bi,Ai,Tl,Ni,Ri,Zn,ft,Bn,ie,Ue,vl,mt,Xi,Ul,Vi,An,ma,xi,Nn,z,jl,Si,Fi,_l,Yi,zi,El,Q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lMjBzdWNjZXNzZnVsJTBBWW91ciUyMHRva2VuJTIwaGFzJTIwYmVlbiUyMHNhdmVkJTIwdG8lMjAlMkZyb290JTJGLmh1Z2dpbmdmYWNlJTJGdG9rZW4=",highlighted:`Login successful
Your token has been saved to /root/.huggingface/token`}}),pt=new $({}),dt=new g({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTJDJTIwRGF0YXNldERpY3QlMEElMEFjb21tb25fdm9pY2UlMjAlM0QlMjBEYXRhc2V0RGljdCgpJTBBJTBBY29tbW9uX3ZvaWNlJTVCJTIydHJhaW4lMjIlNUQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwJTIybW96aWxsYS1mb3VuZGF0aW9uJTJGY29tbW9uX3ZvaWNlXzEzXzAlMjIlMkMlMjAlMjJkdiUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMkJ2YWxpZGF0aW9uJTIyJTBBKSUwQWNvbW1vbl92b2ljZSU1QiUyMnRlc3QlMjIlNUQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwJTIybW96aWxsYS1mb3VuZGF0aW9uJTJGY29tbW9uX3ZvaWNlXzEzXzAlMjIlMkMlMjAlMjJkdiUyMiUyQyUyMHNwbGl0JTNEJTIydGVzdCUyMiUwQSklMEElMEFwcmludChjb21tb25fdm9pY2Up",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, DatasetDict

common_voice = DatasetDict()

common_voice[<span class="hljs-string">&quot;train&quot;</span>] = load_dataset(
    <span class="hljs-string">&quot;mozilla-foundation/common_voice_13_0&quot;</span>, <span class="hljs-string">&quot;dv&quot;</span>, split=<span class="hljs-string">&quot;train+validation&quot;</span>
)
common_voice[<span class="hljs-string">&quot;test&quot;</span>] = load_dataset(
    <span class="hljs-string">&quot;mozilla-foundation/common_voice_13_0&quot;</span>, <span class="hljs-string">&quot;dv&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>
)

<span class="hljs-built_in">print</span>(common_voice)`}}),ut=new g({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2NsaWVudF9pZCclMkMlMjAncGF0aCclMkMlMjAnYXVkaW8nJTJDJTIwJ3NlbnRlbmNlJyUyQyUyMCd1cF92b3RlcyclMkMlMjAnZG93bl92b3RlcyclMkMlMjAnYWdlJyUyQyUyMCdnZW5kZXInJTJDJTIwJ2FjY2VudCclMkMlMjAnbG9jYWxlJyUyQyUyMCdzZWdtZW50JyUyQyUyMCd2YXJpYW50JyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNDkwNCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidjbGllbnRfaWQnJTJDJTIwJ3BhdGgnJTJDJTIwJ2F1ZGlvJyUyQyUyMCdzZW50ZW5jZSclMkMlMjAndXBfdm90ZXMnJTJDJTIwJ2Rvd25fdm90ZXMnJTJDJTIwJ2FnZSclMkMlMjAnZ2VuZGVyJyUyQyUyMCdhY2NlbnQnJTJDJTIwJ2xvY2FsZSclMkMlMjAnc2VnbWVudCclMkMlMjAndmFyaWFudCclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIyMTIlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;client_id&#x27;</span>, <span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;sentence&#x27;</span>, <span class="hljs-string">&#x27;up_votes&#x27;</span>, <span class="hljs-string">&#x27;down_votes&#x27;</span>, <span class="hljs-string">&#x27;age&#x27;</span>, <span class="hljs-string">&#x27;gender&#x27;</span>, <span class="hljs-string">&#x27;accent&#x27;</span>, <span class="hljs-string">&#x27;locale&#x27;</span>, <span class="hljs-string">&#x27;segment&#x27;</span>, <span class="hljs-string">&#x27;variant&#x27;</span>],
        num_rows: <span class="hljs-number">4904</span>
    })
    test: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;client_id&#x27;</span>, <span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;sentence&#x27;</span>, <span class="hljs-string">&#x27;up_votes&#x27;</span>, <span class="hljs-string">&#x27;down_votes&#x27;</span>, <span class="hljs-string">&#x27;age&#x27;</span>, <span class="hljs-string">&#x27;gender&#x27;</span>, <span class="hljs-string">&#x27;accent&#x27;</span>, <span class="hljs-string">&#x27;locale&#x27;</span>, <span class="hljs-string">&#x27;segment&#x27;</span>, <span class="hljs-string">&#x27;variant&#x27;</span>],
        num_rows: <span class="hljs-number">2212</span>
    })
})`}}),ve=new Dy({props:{$$slots:{default:[eM]},$$scope:{ctx:ia}}}),ft=new g({props:{code:"Y29tbW9uX3ZvaWNlJTIwJTNEJTIwY29tbW9uX3ZvaWNlLnNlbGVjdF9jb2x1bW5zKCU1QiUyMmF1ZGlvJTIyJTJDJTIwJTIyc2VudGVuY2UlMjIlNUQp",highlighted:'common_voice = common_voice.select_columns([<span class="hljs-string">&quot;audio&quot;</span>, <span class="hljs-string">&quot;sentence&quot;</span>])'}}),mt=new $({}),gt=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5tb2RlbHMud2hpc3Blci50b2tlbml6YXRpb25fd2hpc3BlciUyMGltcG9ydCUyMFRPX0xBTkdVQUdFX0NPREUlMEElMEFUT19MQU5HVUFHRV9DT0RF",highlighted:`<span class="hljs-keyword">from</span> transformers.models.whisper.tokenization_whisper <span class="hljs-keyword">import</span> TO_LANGUAGE_CODE

TO_LANGUAGE_CODE`}}),bt=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFdoaXNwZXJQcm9jZXNzb3IlMEElMEFwcm9jZXNzb3IlMjAlM0QlMjBXaGlzcGVyUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJvcGVuYWklMkZ3aGlzcGVyLXNtYWxsJTIyJTJDJTIwbGFuZ3VhZ2UlM0QlMjJzaW5oYWxlc2UlMjIlMkMlMjB0YXNrJTNEJTIydHJhbnNjcmliZSUyMiUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> WhisperProcessor

processor = WhisperProcessor.from_pretrained(
    <span class="hljs-string">&quot;openai/whisper-small&quot;</span>, language=<span class="hljs-string">&quot;sinhalese&quot;</span>, task=<span class="hljs-string">&quot;transcribe&quot;</span>
)`}}),Jt=new $({}),Tt=new g({props:{code:"Y29tbW9uX3ZvaWNlJTVCJTIydHJhaW4lMjIlNUQuZmVhdHVyZXM=",highlighted:'common_voice[<span class="hljs-string">&quot;train&quot;</span>].features'}}),vt=new g({props:{code:"JTdCJ2F1ZGlvJyUzQSUyMEF1ZGlvKHNhbXBsaW5nX3JhdGUlM0Q0ODAwMCUyQyUyMG1vbm8lM0RUcnVlJTJDJTIwZGVjb2RlJTNEVHJ1ZSUyQyUyMGlkJTNETm9uZSklMkMlMEElMjAnc2VudGVuY2UnJTNBJTIwVmFsdWUoZHR5cGUlM0Qnc3RyaW5nJyUyQyUyMGlkJTNETm9uZSklN0Q=",highlighted:`{<span class="hljs-string">&#x27;audio&#x27;</span>: Audio(<span class="hljs-attribute">sampling_rate</span>=48000, <span class="hljs-attribute">mono</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">decode</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">id</span>=None),
 <span class="hljs-string">&#x27;sentence&#x27;</span>: Value(<span class="hljs-attribute">dtype</span>=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-attribute">id</span>=None)}`}}),jt=new g({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwQXVkaW8lMEElMEFzYW1wbGluZ19yYXRlJTIwJTNEJTIwcHJvY2Vzc29yLmZlYXR1cmVfZXh0cmFjdG9yLnNhbXBsaW5nX3JhdGUlMEFjb21tb25fdm9pY2UlMjAlM0QlMjBjb21tb25fdm9pY2UuY2FzdF9jb2x1bW4oJTIyYXVkaW8lMjIlMkMlMjBBdWRpbyhzYW1wbGluZ19yYXRlJTNEc2FtcGxpbmdfcmF0ZSkp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Audio

sampling_rate = processor.feature_extractor.sampling_rate
common_voice = common_voice.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=sampling_rate))`}}),Et=new g({props:{code:"ZGVmJTIwcHJlcGFyZV9kYXRhc2V0KGV4YW1wbGUpJTNBJTBBJTIwJTIwJTIwJTIwYXVkaW8lMjAlM0QlMjBleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlMEElMEElMjAlMjAlMjAlMjBleGFtcGxlJTIwJTNEJTIwcHJvY2Vzc29yKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGF1ZGlvJTNEYXVkaW8lNUIlMjJhcnJheSUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNhbXBsaW5nX3JhdGUlM0RhdWRpbyU1QiUyMnNhbXBsaW5nX3JhdGUlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0ZXh0JTNEZXhhbXBsZSU1QiUyMnNlbnRlbmNlJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMGNvbXB1dGUlMjBpbnB1dCUyMGxlbmd0aCUyMG9mJTIwYXVkaW8lMjBzYW1wbGUlMjBpbiUyMHNlY29uZHMlMEElMjAlMjAlMjAlMjBleGFtcGxlJTVCJTIyaW5wdXRfbGVuZ3RoJTIyJTVEJTIwJTNEJTIwbGVuKGF1ZGlvJTVCJTIyYXJyYXklMjIlNUQpJTIwJTJGJTIwYXVkaW8lNUIlMjJzYW1wbGluZ19yYXRlJTIyJTVEJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZXhhbXBsZQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">prepare_dataset</span>(<span class="hljs-params">example</span>):
    audio = example[<span class="hljs-string">&quot;audio&quot;</span>]

    example = processor(
        audio=audio[<span class="hljs-string">&quot;array&quot;</span>],
        sampling_rate=audio[<span class="hljs-string">&quot;sampling_rate&quot;</span>],
        text=example[<span class="hljs-string">&quot;sentence&quot;</span>],
    )

    <span class="hljs-comment"># compute input length of audio sample in seconds</span>
    example[<span class="hljs-string">&quot;input_length&quot;</span>] = <span class="hljs-built_in">len</span>(audio[<span class="hljs-string">&quot;array&quot;</span>]) / audio[<span class="hljs-string">&quot;sampling_rate&quot;</span>]

    <span class="hljs-keyword">return</span> example`}}),It=new g({props:{code:"Y29tbW9uX3ZvaWNlJTIwJTNEJTIwY29tbW9uX3ZvaWNlLm1hcCglMEElMjAlMjAlMjAlMjBwcmVwYXJlX2RhdGFzZXQlMkMlMjByZW1vdmVfY29sdW1ucyUzRGNvbW1vbl92b2ljZS5jb2x1bW5fbmFtZXMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUyMG51bV9wcm9jJTNEMSUwQSk=",highlighted:`common_voice = common_voice.<span class="hljs-built_in">map</span>(
    prepare_dataset, remove_columns=common_voice.column_names[<span class="hljs-string">&quot;train&quot;</span>], num_proc=<span class="hljs-number">1</span>
)`}}),kt=new g({props:{code:"bWF4X2lucHV0X2xlbmd0aCUyMCUzRCUyMDMwLjAlMEElMEElMEFkZWYlMjBpc19hdWRpb19pbl9sZW5ndGhfcmFuZ2UobGVuZ3RoKSUzQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGxlbmd0aCUyMCUzQyUyMG1heF9pbnB1dF9sZW5ndGg=",highlighted:`max_input_length = <span class="hljs-number">30.0</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">is_audio_in_length_range</span>(<span class="hljs-params">length</span>):
    <span class="hljs-keyword">return</span> length &lt; max_input_length`}}),Wt=new g({props:{code:"Y29tbW9uX3ZvaWNlJTVCJTIydHJhaW4lMjIlNUQlMjAlM0QlMjBjb21tb25fdm9pY2UlNUIlMjJ0cmFpbiUyMiU1RC5maWx0ZXIoJTBBJTIwJTIwJTIwJTIwaXNfYXVkaW9faW5fbGVuZ3RoX3JhbmdlJTJDJTBBJTIwJTIwJTIwJTIwaW5wdXRfY29sdW1ucyUzRCU1QiUyMmlucHV0X2xlbmd0aCUyMiU1RCUyQyUwQSk=",highlighted:`common_voice[<span class="hljs-string">&quot;train&quot;</span>] = common_voice[<span class="hljs-string">&quot;train&quot;</span>].<span class="hljs-built_in">filter</span>(
    is_audio_in_length_range,
    input_columns=[<span class="hljs-string">&quot;input_length&quot;</span>],
)`}}),Ct=new g({props:{code:"Y29tbW9uX3ZvaWNlJTVCJTIydHJhaW4lMjIlNUQ=",highlighted:'common_voice[<span class="hljs-string">&quot;train&quot;</span>]'}}),Gt=new g({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidpbnB1dF9mZWF0dXJlcyclMkMlMjAnbGFiZWxzJyUyQyUyMCdpbnB1dF9sZW5ndGgnJTVEJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjA0OTA0JTBBJTdEKQ==",highlighted:`<span class="hljs-built_in">Dataset</span>({
    features: <span class="hljs-selector-attr">[<span class="hljs-string">&#x27;input_features&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;input_length&#x27;</span>]</span>,
    num_rows: <span class="hljs-number">4904</span>
})`}}),$t=new $({}),At=new $({}),Nt=new g({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGF0YWNsYXNzZXMlMjBpbXBvcnQlMjBkYXRhY2xhc3MlMEFmcm9tJTIwdHlwaW5nJTIwaW1wb3J0JTIwQW55JTJDJTIwRGljdCUyQyUyMExpc3QlMkMlMjBVbmlvbiUwQSUwQSUwQSU0MGRhdGFjbGFzcyUwQWNsYXNzJTIwRGF0YUNvbGxhdG9yU3BlZWNoU2VxMlNlcVdpdGhQYWRkaW5nJTNBJTBBJTIwJTIwJTIwJTIwcHJvY2Vzc29yJTNBJTIwQW55JTBBJTBBJTIwJTIwJTIwJTIwZGVmJTIwX19jYWxsX18oJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VsZiUyQyUyMGZlYXR1cmVzJTNBJTIwTGlzdCU1QkRpY3QlNUJzdHIlMkMlMjBVbmlvbiU1Qkxpc3QlNUJpbnQlNUQlMkMlMjB0b3JjaC5UZW5zb3IlNUQlNUQlNUQlMEElMjAlMjAlMjAlMjApJTIwLSUzRSUyMERpY3QlNUJzdHIlMkMlMjB0b3JjaC5UZW5zb3IlNUQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBzcGxpdCUyMGlucHV0cyUyMGFuZCUyMGxhYmVscyUyMHNpbmNlJTIwdGhleSUyMGhhdmUlMjB0byUyMGJlJTIwb2YlMjBkaWZmZXJlbnQlMjBsZW5ndGhzJTIwYW5kJTIwbmVlZCUyMGRpZmZlcmVudCUyMHBhZGRpbmclMjBtZXRob2RzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwZmlyc3QlMjB0cmVhdCUyMHRoZSUyMGF1ZGlvJTIwaW5wdXRzJT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UyMGxhYmVscyUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMGJhdGNo",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Any</span>, <span class="hljs-type">Dict</span>, <span class="hljs-type">List</span>, <span class="hljs-type">Union</span>


<span class="hljs-meta">@dataclass</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">DataCollatorSpeechSeq2SeqWithPadding</span>:
    processor: <span class="hljs-type">Any</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">
        self, features: <span class="hljs-type">List</span>[<span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Union</span>[<span class="hljs-type">List</span>[<span class="hljs-built_in">int</span>], torch.Tensor]]]
    </span>) -&gt; <span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]:
        <span class="hljs-comment"># split inputs and labels since they have to be of different lengths and need different padding methods</span>
        <span class="hljs-comment"># first treat the audio inputs by simply returning torch tensors</span>
        input_features = [
            {<span class="hljs-string">&quot;input_features&quot;</span>: feature[<span class="hljs-string">&quot;input_features&quot;</span>][<span class="hljs-number">0</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features
        ]
        batch = self.processor.feature_extractor.pad(input_features, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

        <span class="hljs-comment"># get the tokenized label sequences</span>
        label_features = [{<span class="hljs-string">&quot;input_ids&quot;</span>: feature[<span class="hljs-string">&quot;labels&quot;</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]
        <span class="hljs-comment"># pad the labels to max length</span>
        labels_batch = self.processor.tokenizer.pad(label_features, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

        <span class="hljs-comment"># replace padding with -100 to ignore loss correctly</span>
        labels = labels_batch[<span class="hljs-string">&quot;input_ids&quot;</span>].masked_fill(
            labels_batch.attention_mask.ne(<span class="hljs-number">1</span>), -<span class="hljs-number">100</span>
        )

        <span class="hljs-comment"># if bos token is appended in previous tokenization step,</span>
        <span class="hljs-comment"># cut bos token here as it&#x27;s append later anyways</span>
        <span class="hljs-keyword">if</span> (labels[:, <span class="hljs-number">0</span>] == self.processor.tokenizer.bos_token_id).<span class="hljs-built_in">all</span>().cpu().item():
            labels = labels[:, <span class="hljs-number">1</span>:]

        batch[<span class="hljs-string">&quot;labels&quot;</span>] = labels

        <span class="hljs-keyword">return</span> batch`}}),Rt=new g({props:{code:"ZGF0YV9jb2xsYXRvciUyMCUzRCUyMERhdGFDb2xsYXRvclNwZWVjaFNlcTJTZXFXaXRoUGFkZGluZyhwcm9jZXNzb3IlM0Rwcm9jZXNzb3Ip",highlighted:"data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)"}}),Xt=new $({}),Vt=new g({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMndlciUyMik=",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;wer&quot;</span>)`}}),xt=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5tb2RlbHMud2hpc3Blci5lbmdsaXNoX25vcm1hbGl6ZXIlMjBpbXBvcnQlMjBCYXNpY1RleHROb3JtYWxpemVyJTBBJTBBbm9ybWFsaXplciUyMCUzRCUyMEJhc2ljVGV4dE5vcm1hbGl6ZXIoKSUwQSUwQSUwQWRlZiUyMGNvbXB1dGVfbWV0cmljcyhwcmVkKSUzQSUwQSUyMCUyMCUyMCUyMHByZWRfaWRzJTIwJTNEJTIwcHJlZC5wcmVkaWN0aW9ucyUwQSUyMCUyMCUyMCUyMGxhYmVsX2lkcyUyMCUzRCUyMHByZWQubGFiZWxfaWRzJTBBJT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TIwd2VyX29ydGhvJTJDJTIwJTIyd2VyJTIyJTNBJTIwd2VyJTdE",highlighted:`<span class="hljs-keyword">from</span> transformers.models.whisper.english_normalizer <span class="hljs-keyword">import</span> BasicTextNormalizer

normalizer = BasicTextNormalizer()


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">pred</span>):
    pred_ids = pred.predictions
    label_ids = pred.label_ids

    <span class="hljs-comment"># replace -100 with the pad_token_id</span>
    label_ids[label_ids == -<span class="hljs-number">100</span>] = processor.tokenizer.pad_token_id

    <span class="hljs-comment"># we do not want to group tokens when computing the metrics</span>
    pred_str = processor.batch_decode(pred_ids, skip_special_tokens=<span class="hljs-literal">True</span>)
    label_str = processor.batch_decode(label_ids, skip_special_tokens=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># compute orthographic wer</span>
    wer_ortho = <span class="hljs-number">100</span> * metric.compute(predictions=pred_str, references=label_str)

    <span class="hljs-comment"># compute normalised WER</span>
    pred_str_norm = [normalizer(pred) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> pred_str]
    label_str_norm = [normalizer(label) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> label_str]
    <span class="hljs-comment"># filtering step to only evaluate the samples that correspond to non-zero references:</span>
    pred_str_norm = [
        pred_str_norm[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(pred_str_norm)) <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(label_str_norm[i]) &gt; <span class="hljs-number">0</span>
    ]
    label_str_norm = [
        label_str_norm[i]
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(label_str_norm))
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(label_str_norm[i]) &gt; <span class="hljs-number">0</span>
    ]

    wer = <span class="hljs-number">100</span> * metric.compute(predictions=pred_str_norm, references=label_str_norm)

    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;wer_ortho&quot;</span>: wer_ortho, <span class="hljs-string">&quot;wer&quot;</span>: wer}`}}),St=new $({}),Ft=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFdoaXNwZXJGb3JDb25kaXRpb25hbEdlbmVyYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMFdoaXNwZXJGb3JDb25kaXRpb25hbEdlbmVyYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMm9wZW5haSUyRndoaXNwZXItc21hbGwlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> WhisperForConditionalGeneration

model = WhisperForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;openai/whisper-small&quot;</span>)`}}),zt=new g({props:{code:"ZnJvbSUyMGZ1bmN0b29scyUyMGltcG9ydCUyMHBhcnRpYWwlMEElMEElMjMlMjBkaXNhYmxlJTIwY2FjaGUlMjBkdXJpbmclMjB0cmFpbmluZyUyMHNpbmNlJTIwaXQncyUyMGluY29tcGF0aWJsZSUyMHdpdGglMjBncmFkaWVudCUyMGNoZWNrcG9pbnRpbmclMEFtb2RlbC5jb25maWcudXNlX2NhY2hlJTIwJTNEJTIwRmFsc2UlMEElMEElMjMlMjBzZXQlMjBsYW5ndWFnZSUyMGFuZCUyMHRhc2slMjBmb3IlMjBnZW5lcmF0aW9uJTIwYW5kJTIwcmUtZW5hYmxlJTIwY2FjaGUlMEFtb2RlbC5nZW5lcmF0ZSUyMCUzRCUyMHBhcnRpYWwoJTBBJTIwJTIwJTIwJTIwbW9kZWwuZ2VuZXJhdGUlMkMlMjBsYW5ndWFnZSUzRCUyMnNpbmhhbGVzZSUyMiUyQyUyMHRhc2slM0QlMjJ0cmFuc2NyaWJlJTIyJTJDJTIwdXNlX2NhY2hlJTNEVHJ1ZSUwQSk=",highlighted:`<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial

<span class="hljs-comment"># disable cache during training since it&#x27;s incompatible with gradient checkpointing</span>
model.config.use_cache = <span class="hljs-literal">False</span>

<span class="hljs-comment"># set language and task for generation and re-enable cache</span>
model.generate = partial(
    model.generate, language=<span class="hljs-string">&quot;sinhalese&quot;</span>, task=<span class="hljs-string">&quot;transcribe&quot;</span>, use_cache=<span class="hljs-literal">True</span>
)`}}),Qt=new $({}),Dt=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBTZXEyU2VxVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMi4lMkZ3aGlzcGVyLXNtYWxsLWR2JTIyJTJDJTIwJTIwJTIzJTIwbmFtZSUyMG9uJTIwdGhlJTIwSEYlMjBIdWIlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDElMkMlMjAlMjAlMjMlMjBpbmNyZWFzZSUyMGJ5JTIwMnglMjBmb3IlMjBldmVyeSUyMDJ4JTIwZGVjcmVhc2UlMjBpbiUyMGJhdGNoJTIwc2l6ZSUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QxZS01JTJDJTBBJTIwJTIwJTIwJTIwbHJfc2NoZWR1bGVyX3R5cGUlM0QlMjJjb25zdGFudF93aXRoX3dhcm11cCUyMiUyQyUwQSUyMCUyMCUyMCUyMHdhcm11cF9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3N0ZXBzJTNENTAwJTJDJTIwJTIwJTIzJTIwaW5jcmVhc2UlMjB0byUyMDQwMDAlMjBpZiUyMHlvdSUyMGhhdmUlMjB5b3VyJTIwb3duJTIwR1BVJTIwb3IlMjBhJTIwQ29sYWIlMjBwYWlkJTIwcGxhbiUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2NoZWNrcG9pbnRpbmclM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZnAxNiUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBmcDE2X2Z1bGxfZXZhbCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwcHJlZGljdF93aXRoX2dlbmVyYXRlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRpb25fbWF4X2xlbmd0aCUzRDIyNSUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RlcHMlM0Q1MDAlMkMlMEElMjAlMjAlMjAlMjBldmFsX3N0ZXBzJTNENTAwJTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19zdGVwcyUzRDI1JTJDJTBBJTIwJTIwJTIwJTIwcmVwb3J0X3RvJTNEJTVCJTIydGVuc29yYm9hcmQlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMG1ldHJpY19mb3JfYmVzdF9tb2RlbCUzRCUyMndlciUyMiUyQyUwQSUyMCUyMCUyMCUyMGdyZWF0ZXJfaXNfYmV0dGVyJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBwdXNoX3RvX2h1YiUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainingArguments

training_args = Seq2SeqTrainingArguments(
    output_dir=<span class="hljs-string">&quot;./whisper-small-dv&quot;</span>,  <span class="hljs-comment"># name on the HF Hub</span>
    per_device_train_batch_size=<span class="hljs-number">16</span>,
    gradient_accumulation_steps=<span class="hljs-number">1</span>,  <span class="hljs-comment"># increase by 2x for every 2x decrease in batch size</span>
    learning_rate=<span class="hljs-number">1e-5</span>,
    lr_scheduler_type=<span class="hljs-string">&quot;constant_with_warmup&quot;</span>,
    warmup_steps=<span class="hljs-number">50</span>,
    max_steps=<span class="hljs-number">500</span>,  <span class="hljs-comment"># increase to 4000 if you have your own GPU or a Colab paid plan</span>
    gradient_checkpointing=<span class="hljs-literal">True</span>,
    fp16=<span class="hljs-literal">True</span>,
    fp16_full_eval=<span class="hljs-literal">True</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    per_device_eval_batch_size=<span class="hljs-number">16</span>,
    predict_with_generate=<span class="hljs-literal">True</span>,
    generation_max_length=<span class="hljs-number">225</span>,
    save_steps=<span class="hljs-number">500</span>,
    eval_steps=<span class="hljs-number">500</span>,
    logging_steps=<span class="hljs-number">25</span>,
    report_to=[<span class="hljs-string">&quot;tensorboard&quot;</span>],
    load_best_model_at_end=<span class="hljs-literal">True</span>,
    metric_for_best_model=<span class="hljs-string">&quot;wer&quot;</span>,
    greater_is_better=<span class="hljs-literal">False</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`}}),Xe=new Dy({props:{$$slots:{default:[tM]},$$scope:{ctx:ia}}}),qt=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBdHJhaW5lciUyMCUzRCUyMFNlcTJTZXFUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0Rjb21tb25fdm9pY2UlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRGNvbW1vbl92b2ljZSU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHByb2Nlc3NvciUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    args=training_args,
    model=model,
    train_dataset=common_voice[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=common_voice[<span class="hljs-string">&quot;test&quot;</span>],
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    tokenizer=processor,
)`}}),Pt=new $({}),Ot=new g({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()"}}),ta=new g({props:{code:"a3dhcmdzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIyZGF0YXNldF90YWdzJTIyJTNBJTIwJTIybW96aWxsYS1mb3VuZGF0aW9uJTJGY29tbW9uX3ZvaWNlXzEzXzAlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJkYXRhc2V0JTIyJTNBJTIwJTIyQ29tbW9uJTIwVm9pY2UlMjAxMyUyMiUyQyUyMCUyMCUyMyUyMGElMjAncHJldHR5JyUyMG5hbWUlMjBmb3IlMjB0aGUlMjB0cmFpbmluZyUyMGRhdGFzZXQlMEElMjAlMjAlMjAlMjAlMjJsYW5ndWFnZSUyMiUzQSUyMCUyMmR2JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIybW9kZWxfbmFtZSUyMiUzQSUyMCUyMldoaXNwZXIlMjBTbWFsbCUyMER2JTIwLSUyMFNhbmNoaXQlMjBHYW5kaGklMjIlMkMlMjAlMjAlMjMlMjBhJTIwJ3ByZXR0eSclMjBuYW1lJTIwZm9yJTIweW91ciUyMG1vZGVsJTBBJTIwJTIwJTIwJTIwJTIyZmluZXR1bmVkX2Zyb20lMjIlM0ElMjAlMjJvcGVuYWklMkZ3aGlzcGVyLXNtYWxsJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIydGFza3MlMjIlM0ElMjAlMjJhdXRvbWF0aWMtc3BlZWNoLXJlY29nbml0aW9uJTIyJTJDJTBBJTdE",highlighted:`kwargs = {
    <span class="hljs-string">&quot;dataset_tags&quot;</span>: <span class="hljs-string">&quot;mozilla-foundation/common_voice_13_0&quot;</span>,
    <span class="hljs-string">&quot;dataset&quot;</span>: <span class="hljs-string">&quot;Common Voice 13&quot;</span>,  <span class="hljs-comment"># a &#x27;pretty&#x27; name for the training dataset</span>
    <span class="hljs-string">&quot;language&quot;</span>: <span class="hljs-string">&quot;dv&quot;</span>,
    <span class="hljs-string">&quot;model_name&quot;</span>: <span class="hljs-string">&quot;Whisper Small Dv - Sanchit Gandhi&quot;</span>,  <span class="hljs-comment"># a &#x27;pretty&#x27; name for your model</span>
    <span class="hljs-string">&quot;finetuned_from&quot;</span>: <span class="hljs-string">&quot;openai/whisper-small&quot;</span>,
    <span class="hljs-string">&quot;tasks&quot;</span>: <span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>,
}`}}),aa=new g({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1YigqKmt3YXJncyk=",highlighted:"trainer.push_to_hub(**kwargs)"}}),la=new $({}),na=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMHBpcGVsaW5lKCUyMmF1dG9tYXRpYy1zcGVlY2gtcmVjb2duaXRpb24lMjIlMkMlMjBtb2RlbCUzRCUyMnNhbmNoaXQtZ2FuZGhpJTJGd2hpc3Blci1zbWFsbC1kdiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

pipe = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>, model=<span class="hljs-string">&quot;sanchit-gandhi/whisper-small-dv&quot;</span>)`}}),oa=new $({}),{c(){b=n("meta"),J=h(),G=n("h1"),we=n("a"),sl=n("span"),u(lt.$$.fragment),Pr=h(),nl=n("span"),Or=l("Fine-tuning the ASR model"),mn=h(),pa=n("p"),Lr=l(`In this section, we\u2019ll cover a step-by-step guide on fine-tuning Whisper for speech recognition on the Common Voice 13
dataset. We\u2019ll use the \u2018small\u2019 version of the model and a relatively lightweight dataset, enabling you to run fine-tuning
fairly quickly on any 16GB+ GPU with low disk space requirements, such as the 16GB T4 GPU provided in the Google Colab free
tier.`),yn=h(),ha=n("p"),Kr=l(`Should you have a smaller GPU or encounter memory issues during training, you can follow the suggestions provided for
reducing memory usage. Conversely, should you have access to a larger GPU, you can amend the training arguments to maximise
your throughput. Thus, this guide is accessible regardless of your GPU specifications!`),Mn=h(),ca=n("p"),ei=l(`Likewise, this guide outlines how to fine-tune the Whisper model for the Dhivehi language. However, the steps covered here
generalise to any language in the Common Voice dataset, and more generally to any ASR dataset on the Hugging Face Hub.
You can tweak the code to quickly switch to a language of your choice and fine-tune a Whisper model in your native tongue \u{1F30D}`),wn=h(),da=n("p"),ti=l("Right! Now that\u2019s out the way, let\u2019s get started and kick-off our fine-tuning pipeline!"),gn=h(),oe=n("h2"),ge=n("a"),ol=n("span"),u(st.$$.fragment),ai=h(),rl=n("span"),li=l("Prepare Environment"),bn=h(),be=n("p"),si=l("We strongly advise you to upload model checkpoints directly the "),nt=n("a"),ni=l("Hugging Face Hub"),oi=l(` while training.
The Hub provides:`),Jn=h(),Z=n("ul"),il=n("li"),ri=l("Integrated version control: you can be sure that no model checkpoint is lost during training."),ii=h(),pl=n("li"),pi=l("Tensorboard logs: track important metrics over the course of training."),hi=h(),hl=n("li"),ci=l("Model cards: document what a model does and its intended use cases."),di=h(),cl=n("li"),ui=l("Community: an easy way to share and collaborate with the community! \u{1F917}"),Tn=h(),Je=n("p"),fi=l(`Linking the notebook to the Hub is straightforward - it simply requires entering your Hub authentication token when prompted.
Find your Hub authentication token `),ot=n("a"),mi=l("here"),yi=l(" and enter it when prompted:"),vn=h(),u(rt.$$.fragment),Un=h(),ua=n("p"),dl=n("strong"),Mi=l("Output:"),jn=h(),u(it.$$.fragment),_n=h(),re=n("h2"),Te=n("a"),ul=n("span"),u(pt.$$.fragment),wi=h(),fl=n("span"),gi=l("Load Dataset"),En=h(),ht=n("p"),ct=n("a"),bi=l("Common Voice 13"),Ji=l(` contains approximately ten
hours of labelled Dhivehi data, three of which is held-out test data. This is extremely little data for fine-tuning, so
we\u2019ll be relying on leveraging the extensive multilingual ASR knowledge acquired by Whisper during pre-training for the
low-resource Dhivehi language.`),In=h(),B=n("p"),Ti=l(`Using \u{1F917} Datasets, downloading and preparing data is extremely simple. We can download and prepare the Common Voice 13
splits in just one line of code. Since Dhivehi is very low-resource, we\u2019ll combine the `),ml=n("code"),vi=l("train"),Ui=l(" and "),yl=n("code"),ji=l("validation"),_i=l(` splits
to give approximately seven hours of training data. We\u2019ll use the three hours of `),Ml=n("code"),Ei=l("test"),Ii=l(" data as our held-out test set:"),kn=h(),u(dt.$$.fragment),Wn=h(),fa=n("p"),wl=n("strong"),ki=l("Output:"),Cn=h(),u(ut.$$.fragment),Gn=h(),u(ve.$$.fragment),$n=h(),_=n("p"),Wi=l("Most ASR datasets only provide input audio samples ("),gl=n("code"),Ci=l("audio"),Gi=l(") and the corresponding transcribed text ("),bl=n("code"),$i=l("sentence"),Zi=l(`).
Common Voice contains additional metadata information, such as `),Jl=n("code"),Bi=l("accent"),Ai=l(" and "),Tl=n("code"),Ni=l("locale"),Ri=l(`, which we can disregard for ASR.
Keeping the notebook as general as possible, we only consider the input audio and transcribed text for fine-tuning,
discarding the additional metadata information:`),Zn=h(),u(ft.$$.fragment),Bn=h(),ie=n("h2"),Ue=n("a"),vl=n("span"),u(mt.$$.fragment),Xi=h(),Ul=n("span"),Vi=l("Feature Extractor, Tokenizer and Processor"),An=h(),ma=n("p"),xi=l("The ASR pipeline can be de-composed into three stages:"),Nn=h(),z=n("ol"),jl=n("li"),Si=l("The feature extractor which pre-processes the raw audio-inputs to log-mel spectrograms"),Fi=h(),_l=n("li"),Yi=l("The model which performs the sequence-to-sequence mapping"),zi=h(),El=n("li"),Qi=l("The tokenizer which post-processes the predicted tokens to text"),Rn=h(),A=n("p"),Hi=l("In \u{1F917} Transformers, the Whisper model has an associated feature extractor and tokenizer, called "),yt=n("a"),Di=l("WhisperFeatureExtractor"),qi=l(" and "),Mt=n("a"),Pi=l("WhisperTokenizer"),Oi=l(`
respectively. To make our lives simple, these two objects are wrapped under a single class, called the `),wt=n("a"),Li=l("WhisperProcessor"),Ki=l(`.
We can call the WhisperProcessor to perform 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: the processor and the model.`),Xn=h(),T=n("p"),ep=l("When performing multilingual fine-tuning, we need to set the "),Il=n("code"),tp=l('"language"'),ap=l(" and "),kl=n("code"),lp=l('"task"'),sp=l(` when instantiating the processor.
The `),Wl=n("code"),np=l('"language"'),op=l(" should be set to the source audio language, and the task to "),Cl=n("code"),rp=l('"transcribe"'),ip=l(` for speech recognition or
`),Gl=n("code"),pp=l('"translate"'),hp=l(` for speech translation. These arguments modify the behaviour of the tokenizer, and should be set correctly
to ensure the target labels are encoded properly.`),Vn=h(),ya=n("p"),cp=l("We can see all possible languages supported by Whisper by importing the list of languages:"),xn=h(),u(gt.$$.fragment),Sn=h(),Ma=n("p"),dp=l(`If you scroll through this list, you\u2019ll notice that many languages are present, but Dhivehi is one of few that is not!
This means that Whisper was not pre-trained on Dhivehi. However, this doesn\u2019t mean that we can\u2019t fine tune Whisper on it.
In doing so, we\u2019ll be teaching Whisper a new language, one that the pre-trained checkpoint does not support. That\u2019s pretty
cool, right!`),Fn=h(),wa=n("p"),up=l(`When you fine-tune it on a new language, Whisper does a good job at leveraging its knowledge of the other 96 languages
it\u2019s pre-trained on. Largely speaking, all modern languages will be linguistically similar to at least one of the
96 languages Whisper already knows, so we\u2019ll fall under this paradigm of cross-lingual knowledge representation.`),Yn=h(),Q=n("p"),fp=l("What we need to do to fine-tune Whisper on a new language is find the language "),$l=n("strong"),mp=l("most similar"),yp=l(` that Whisper was
pre-trained on. The Wikipedia article for Dhivehi states that Dhivehi is closely related to the Sinhalese language of Sri Lanka.
If we check the language codes again, we can see that Sinhalese is present in the Whisper language set,
so we can safely set our language argument to `),Zl=n("code"),Mp=l('"sinhalese"'),wp=l("."),zn=h(),H=n("p"),gp=l("Right! We\u2019ll load our processor from the pre-trained checkpoint, setting the language to "),Bl=n("code"),bp=l('"sinhalese"'),Jp=l(" and task to "),Al=n("code"),Tp=l('"transcribe"'),vp=l(`
as explained above:`),Qn=h(),u(bt.$$.fragment),Hn=h(),D=n("p"),Up=l(`It\u2019s worth reiterating that in most circumstances, you\u2019ll find that the language you want to fine-tune on is in the set of
pre-training languages, in which case you can simply set the language directly as your source audio language! Note that
both of these arguments should be omitted for English-only fine-tuning, where there is only one option for the language
(`),Nl=n("code"),jp=l('"English"'),_p=l(") and task ("),Rl=n("code"),Ep=l('"transcribe"'),Ip=l(")."),Dn=h(),pe=n("h2"),je=n("a"),Xl=n("span"),u(Jt.$$.fragment),kp=h(),Vl=n("span"),Wp=l("Pre-Process the Data"),qn=h(),_e=n("p"),Cp=l("Let\u2019s have a look at the dataset features. Pay particular attention to the "),xl=n("code"),Gp=l('"audio"'),$p=l(` column - this details the sampling
rate of our audio inputs:`),Pn=h(),u(Tt.$$.fragment),On=h(),ga=n("p"),Sl=n("strong"),Zp=l("Output:"),Ln=h(),u(vt.$$.fragment),Kn=h(),Ee=n("p"),Bp=l("Since our input audio is sampled at 48kHz, we need to "),Fl=n("em"),Ap=l("downsample"),Np=l(` it to 16kHz prior to passing it to the Whisper feature
extractor, 16kHz being the sampling rate expected by the Whisper model.`),eo=h(),Ie=n("p"),Rp=l("We\u2019ll set the audio inputs to the correct sampling rate using dataset\u2019s "),Ut=n("a"),Yl=n("code"),Xp=l("cast_column"),Vp=l(`
method. This operation does not change the audio in-place, but rather signals to datasets to resample audio samples
on-the-fly when they are loaded:`),to=h(),u(jt.$$.fragment),ao=h(),ba=n("p"),xp=l("Now we can write a function to prepare our data ready for the model:"),lo=h(),q=n("ol"),_t=n("li"),Sp=l("We load and resample the audio data on a sample-by-sample basis by calling "),zl=n("code"),Fp=l('sample["audio"]'),Yp=l(". As explained above, \u{1F917} Datasets performs any necessary resampling operations on the fly."),zp=h(),Ql=n("li"),Qp=l("We use the feature extractor to compute the log-mel spectrogram input features from our 1-dimensional audio array."),Hp=h(),Hl=n("li"),Dp=l("We encode the transcriptions to label ids through the use of the tokenizer."),so=h(),u(Et.$$.fragment),no=h(),P=n("p"),qp=l("We can apply the data preparation function to all of our training examples using \u{1F917} Datasets\u2019 "),Dl=n("code"),Pp=l(".map"),Op=l(` method. We\u2019ll
remove the columns from the raw training data (the audio and text), leaving just the columns returned by the
`),ql=n("code"),Lp=l("prepare_dataset"),Kp=l(" function:"),oo=h(),u(It.$$.fragment),ro=h(),O=n("p"),eh=l(`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 `),Pl=n("code"),th=l("True"),ah=l(` for
samples that are less than 30s, and `),Ol=n("code"),lh=l("False"),sh=l(" for those that are longer:"),io=h(),u(kt.$$.fragment),po=h(),ke=n("p"),nh=l("We apply our filter function to all samples of our training dataset through \u{1F917} Datasets\u2019 "),Ll=n("code"),oh=l(".filter"),rh=l(" method:"),ho=h(),u(Wt.$$.fragment),co=h(),Ja=n("p"),ih=l("Let\u2019s check how much training data we removed through this filtering step:"),uo=h(),u(Ct.$$.fragment),fo=h(),Ta=n("p"),Kl=n("strong"),ph=l("Output"),mo=h(),u(Gt.$$.fragment),yo=h(),va=n("p"),hh=l(`Alright! In this case we actually have the same number of samples as before, so there were no samples longer than 30s.
This might not be the case if you switch languages, so it\u2019s best to keep this filter step in-place for robustness. With
that, we have our data fully prepared for training! Let\u2019s continue and take a look at how we can use this data to fine-tune
Whisper.`),Mo=h(),he=n("h2"),We=n("a"),es=n("span"),u($t.$$.fragment),ch=h(),ts=n("span"),dh=l("Training and Evaluation"),wo=h(),Ce=n("p"),uh=l(`Now that we\u2019ve prepared our data, we\u2019re ready to dive into the training pipeline.
The `),Zt=n("a"),fh=l("\u{1F917} Trainer"),mh=l(`
will do much of the heavy lifting for us. All we have to do is:`),go=h(),N=n("ul"),as=n("li"),ls=n("p"),yh=l("Define a data collator: the data collator takes our pre-processed data and prepares PyTorch tensors ready for the model."),Mh=h(),ss=n("li"),Bt=n("p"),wh=l("Evaluation metrics: during evaluation, we want to evaluate the model using the word error rate (WER) metric. We need to define a "),ns=n("code"),gh=l("compute_metrics"),bh=l(" function that handles this computation."),Jh=h(),os=n("li"),rs=n("p"),Th=l("Load a pre-trained checkpoint: we need to load a pre-trained checkpoint and configure it correctly for training."),vh=h(),is=n("li"),ps=n("p"),Uh=l("Define the training arguments: these will be used by the \u{1F917} Trainer in constructing the training schedule."),bo=h(),Ua=n("p"),jh=l(`Once we\u2019ve fine-tuned the model, we will evaluate it on the test data to verify that we have correctly trained it
to transcribe speech in Dhivehi.`),Jo=h(),ce=n("h3"),Ge=n("a"),hs=n("span"),u(At.$$.fragment),_h=h(),cs=n("span"),Eh=l("Define a Data Collator"),To=h(),E=n("p"),Ih=l("The data collator for a sequence-to-sequence speech model is unique in the sense that it treats the "),ds=n("code"),kh=l("input_features"),Wh=l(`
and `),us=n("code"),Ch=l("labels"),Gh=l(" independently: the  "),fs=n("code"),$h=l("input_features"),Zh=l(" must be handled by the feature extractor and the "),ms=n("code"),Bh=l("labels"),Ah=l(" by the tokenizer."),vo=h(),I=n("p"),Nh=l("The "),ys=n("code"),Rh=l("input_features"),Xh=l(` are already padded to 30s and converted to a log-Mel spectrogram of fixed dimension, so all we
have to do is convert them to batched PyTorch tensors. We do this using the feature extractor\u2019s `),Ms=n("code"),Vh=l(".pad"),xh=l(` method with
`),ws=n("code"),Sh=l("return_tensors=pt"),Fh=l(`. Note that no additional padding is applied here since the inputs are of fixed dimension, the
`),gs=n("code"),Yh=l("input_features"),zh=l(" are simply converted to PyTorch tensors."),Uo=h(),k=n("p"),Qh=l("On the other hand, the "),bs=n("code"),Hh=l("labels"),Dh=l(` are un-padded. We first pad the sequences to the maximum length in the batch using
the tokenizer\u2019s `),Js=n("code"),qh=l(".pad"),Ph=l(" method. The padding tokens are then replaced by "),Ts=n("code"),Oh=l("-100"),Lh=l(" so that these tokens are "),vs=n("strong"),Kh=l("not"),ec=l(` taken
into account when computing the loss. We then cut the start of transcript token from the beginning of the label sequence
as we append it later during training.`),jo=h(),$e=n("p"),tc=l("We can leverage the "),Us=n("code"),ac=l("WhisperProcessor"),lc=l(" we defined earlier to perform both the feature extractor and the tokenizer operations:"),_o=h(),u(Nt.$$.fragment),Eo=h(),ja=n("p"),sc=l("We can now initialise the data collator we\u2019ve just defined:"),Io=h(),u(Rt.$$.fragment),ko=h(),_a=n("p"),nc=l("Onwards!"),Wo=h(),de=n("h3"),Ze=n("a"),js=n("span"),u(Xt.$$.fragment),oc=h(),_s=n("span"),rc=l("Evaluation Metrics"),Co=h(),Be=n("p"),ic=l(`Next, we define the evaluation metric we\u2019ll use on our evaluation set. We\u2019ll use the Word Error Rate (WER) metric introduced
in the section on `),Ea=n("a"),pc=l("Evaluation"),hc=l(", the \u2018de-facto\u2019 metric for assessing ASR systems."),Go=h(),Ia=n("p"),cc=l("We\u2019ll load the WER metric from \u{1F917} Evaluate:"),$o=h(),u(Vt.$$.fragment),Zo=h(),W=n("p"),dc=l(`We then simply have to define a function that takes our model predictions and returns the WER metric. This function, called
`),Es=n("code"),uc=l("compute_metrics"),fc=l(", first replaces "),Is=n("code"),mc=l("-100"),yc=l(" with the "),ks=n("code"),Mc=l("pad_token_id"),wc=l(" in the "),Ws=n("code"),gc=l("label_ids"),bc=l(` (undoing the step we applied in the
data collator to ignore padded tokens correctly in the loss). It then decodes the predicted and label ids to strings. Finally,
it computes the WER between the predictions and reference labels. Here, we have the option of evaluating with the \u2018normalised\u2019
transcriptions and predictions, which have punctuation and casing removed. We recommend you follow this to benefit
from the WER improvement obtained by normalising the transcriptions.`),Bo=h(),u(xt.$$.fragment),Ao=h(),ue=n("h3"),Ae=n("a"),Cs=n("span"),u(St.$$.fragment),Jc=h(),Gs=n("span"),Tc=l("Load a Pre-Trained Checkpoint"),No=h(),ka=n("p"),vc=l("Now let\u2019s load the pre-trained Whisper small checkpoint. Again, this is trivial through use of \u{1F917} Transformers!"),Ro=h(),u(Ft.$$.fragment),Xo=h(),v=n("p"),Uc=l("We\u2019ll set "),$s=n("code"),jc=l("use_cache"),_c=l(" to "),Zs=n("code"),Ec=l("False"),Ic=l(" for training since we\u2019re using "),Yt=n("a"),kc=l("gradient checkpointing"),Wc=l(`
and the two are incompatible. We\u2019ll also override two generation arguments to control the behaviour of the model during inference:
we\u2019ll force the language and task tokens during generation by setting the `),Bs=n("code"),Cc=l("language"),Gc=l(" and "),As=n("code"),$c=l("task"),Zc=l(` arguments, and also re-enable
cache for generation to speed-up inference time:`),Vo=h(),u(zt.$$.fragment),xo=h(),fe=n("h2"),Ne=n("a"),Ns=n("span"),u(Qt.$$.fragment),Bc=h(),Rs=n("span"),Ac=l("Define the Training Configuration"),So=h(),Re=n("p"),Nc=l(`In the final step, we define all the parameters related to training. Here, we set the number of training steps to 500.
This is enough steps to see a big WER improvement compared to the pre-trained Whisper model, while ensuring that fine-tuning can
be run in approximately 45 minutes on a Google Colab free tier. For more detail on the training arguments, refer to the
Seq2SeqTrainingArguments `),Ht=n("a"),Rc=l("docs"),Xc=l("."),Fo=h(),u(Dt.$$.fragment),Yo=h(),u(Xe.$$.fragment),zo=h(),Ve=n("p"),Vc=l("We can forward the training arguments to the \u{1F917} Trainer along with our model, dataset, data collator and "),Xs=n("code"),xc=l("compute_metrics"),Sc=l(" function:"),Qo=h(),u(qt.$$.fragment),Ho=h(),Wa=n("p"),Fc=l("And with that, we\u2019re ready to start training!"),Do=h(),me=n("h3"),xe=n("a"),Vs=n("span"),u(Pt.$$.fragment),Yc=h(),xs=n("span"),zc=l("Training"),qo=h(),Ca=n("p"),Qc=l("To launch training, simply execute:"),Po=h(),u(Ot.$$.fragment),Oo=h(),R=n("p"),Hc=l(`Training will take approximately 45 minutes depending on your GPU or the one allocated to the Google Colab. Depending on
your GPU, it is possible that you will encounter a CUDA `),Ss=n("code"),Dc=l('"out-of-memory"'),qc=l(` error when you start training. In this case,
you can reduce the `),Fs=n("code"),Pc=l("per_device_train_batch_size"),Oc=l(" incrementally by factors of 2 and employ "),Lt=n("a"),Ys=n("code"),Lc=l("gradient_accumulation_steps"),Kc=l(`
to compensate.`),Lo=h(),Ga=n("p"),zs=n("strong"),ed=l("Output:"),Ko=h(),Se=n("table"),Qs=n("thead"),U=n("tr"),$a=n("th"),td=l("Training Loss"),ad=h(),Za=n("th"),ld=l("Epoch"),sd=h(),Ba=n("th"),nd=l("Step"),od=h(),Aa=n("th"),rd=l("Validation Loss"),id=h(),Na=n("th"),pd=l("Wer Ortho"),hd=h(),Ra=n("th"),cd=l("Wer"),dd=h(),Hs=n("tbody"),j=n("tr"),Xa=n("td"),ud=l("0.136"),fd=h(),Va=n("td"),md=l("1.63"),yd=h(),xa=n("td"),Md=l("500"),wd=h(),Sa=n("td"),gd=l("0.1727"),bd=h(),Fa=n("td"),Jd=l("63.8972"),Td=h(),Ya=n("td"),vd=l("14.0661"),er=h(),za=n("p"),Ud=l(`Our final WER is 14.1% - not bad for seven hours of training data and just 500 training steps! That amounts to a 112%
improvement versus the pre-trained model! That means we\u2019ve taken a model that previously had no knowledge about Dhivehi,
and fine-tuned it to recognise Dhivehi speech with adequate accuracy in under one hour \u{1F92F}`),tr=h(),Fe=n("p"),jd=l("The big question is how this compares to other ASR systems. For that, we can view the autoevaluate "),Kt=n("a"),_d=l("leaderboard"),Ed=l(`,
a leaderboard that categorises models by language and dataset, and subsequently ranks them according to their WER.`),ar=h(),Ye=n("p"),Id=l("Looking at the leaderboard, we see that our model trained for 500 steps convincingly beats the pre-trained "),ea=n("a"),kd=l("Whisper Small"),Wd=l(`
checkpoint that we evaluated in the previous section. Nice job \u{1F44F}`),lr=h(),L=n("p"),Cd=l(`We see that there are a few checkpoints that do better than the one we trained. The beauty of the Hugging Face Hub is that
it\u2019s a `),Ds=n("em"),Gd=l("collaborative"),$d=l(` platform - if we don\u2019t have the time or resources to perform a longer training run ourselves, we
can load a checkpoint that someone else in the community has trained and been kind enough to share (making sure to thank them for it!).
You\u2019ll be able to load these checkpoints in exactly the same way as the pre-trained ones using the `),qs=n("code"),Zd=l("pipeline"),Bd=l(` class as we
did previously! So there\u2019s nothing stopping you cherry-picking the best model on the leaderboard to use for your task!`),sr=h(),Qa=n("p"),Ad=l(`We can automatically submit our checkpoint to the leaderboard when we push the training results to the Hub - we simply
have to set the appropriate key-word arguments (kwargs). You can change these values to match your dataset, language and
model name accordingly:`),nr=h(),u(ta.$$.fragment),or=h(),ze=n("p"),Nd=l("The training results can now be uploaded to the Hub. To do so, execute the "),Ps=n("code"),Rd=l("push_to_hub"),Xd=l(" command:"),rr=h(),u(aa.$$.fragment),ir=h(),K=n("p"),Vd=l("This will save the training logs and model weights under "),Os=n("code"),xd=l('"your-username/the-name-you-picked"'),Sd=l(`. For this example, check
out the upload at `),Ls=n("code"),Fd=l("sanchit-gandhi/whisper-small-dv"),Yd=l("."),pr=h(),Ha=n("p"),zd=l(`While the fine-tuned model yields satisfactory results on the Common Voice 13 Dhivehi test data, it is by no means optimal.
The purpose of this guide is to demonstrate how to fine-tune an ASR model using the \u{1F917} Trainer for multilingual speech
recognition.`),hr=h(),X=n("p"),Qd=l("If you have access to your own GPU or are subscribed to a Google Colab paid plan, you can increase "),Ks=n("code"),Hd=l("max_steps"),Dd=l(` to 4000 steps
to improve the WER further by training for more steps. Training for 4000 steps will take approximately 3-5 hours depending
on your GPU and yield WER results approximately 3% lower than training for 500 steps. If you decide to train for 4000 steps,
we also recommend changing the learning rate scheduler to a `),en=n("em"),qd=l("linear"),Pd=l(" schedule (set "),tn=n("code"),Od=l('lr_scheduler_type="linear"'),Ld=l(`), as this will
yield an additional performance boost over long training runs.`),cr=h(),C=n("p"),Kd=l("The results could likely be improved further by optimising the training hyperparameters, such as "),an=n("em"),eu=l("learning rate"),tu=l(` and
`),ln=n("em"),au=l("dropout"),lu=l(", and using a larger pre-trained checkpoint ("),sn=n("code"),su=l("medium"),nu=l(" or "),nn=n("code"),ou=l("large"),ru=l("). We leave this as an exercise to the reader."),dr=h(),ye=n("h2"),Qe=n("a"),on=n("span"),u(la.$$.fragment),iu=h(),rn=n("span"),pu=l("Sharing Your Model"),ur=h(),V=n("p"),hu=l("You can now share this model with anyone using the link on the Hub. They can load it with the identifier "),pn=n("code"),cu=l('"your-username/the-name-you-picked"'),du=l(`
directly into the `),hn=n("code"),uu=l("pipeline()"),fu=l(" object. For instance, to load the fine-tuned checkpoint "),sa=n("a"),mu=l("\u201Csanchit-gandhi/whisper-small-dv\u201D"),yu=l(":"),fr=h(),u(na.$$.fragment),mr=h(),Me=n("h2"),He=n("a"),cn=n("span"),u(oa.$$.fragment),Mu=h(),dn=n("span"),wu=l("Conclusion"),yr=h(),De=n("p"),gu=l(`In this section, we covered a step-by-step guide on fine-tuning the Whisper model for speech recognition \u{1F917} Datasets,
Transformers and the Hugging Face Hub. We first loaded the Dhivehi subset of the Common Voice 13 dataset and pre-processed
it by computing log-mel spectrograms and tokenising the text. We then defined a data collator, evaluation metric and
training arguments, before using the \u{1F917} Trainer to train and evaluate our model. We finished by uploading the fine-tuned
model to the Hugging Face Hub, and showcased how to share and use it with the `),un=n("code"),bu=l("pipeline()"),Ju=l(" class."),Mr=h(),qe=n("p"),Tu=l(`If you followed through to this point, you should now have a fine-tuned checkpoint for speech recognition, well done! \u{1F973}
Even more importantly, you\u2019re equipped with all the tools you need to fine-tune the Whisper model on any speech recognition
dataset or domain. So what are you waiting for! Pick one of the datasets covered in the section `),Da=n("a"),vu=l("Choosing a Dataset"),Uu=l(`
or select a dataset of your own, and see whether you can get state-of-the-art performance! The leaderboard is waiting for you\u2026`),this.h()},l(e){const i=Ly('[data-svelte="svelte-1phssyn"]',document.head);b=o(i,"META",{name:!0,content:!0}),i.forEach(a),J=c(e),G=o(e,"H1",{class:!0});var ra=r(G);we=o(ra,"A",{id:!0,class:!0,href:!0});var fn=r(we);sl=o(fn,"SPAN",{});var _u=r(sl);f(lt.$$.fragment,_u),_u.forEach(a),fn.forEach(a),Pr=c(ra),nl=o(ra,"SPAN",{});var Eu=r(nl);Or=s(Eu,"Fine-tuning the ASR model"),Eu.forEach(a),ra.forEach(a),mn=c(e),pa=o(e,"P",{});var Iu=r(pa);Lr=s(Iu,`In this section, we\u2019ll cover a step-by-step guide on fine-tuning Whisper for speech recognition on the Common Voice 13
dataset. We\u2019ll use the \u2018small\u2019 version of the model and a relatively lightweight dataset, enabling you to run fine-tuning
fairly quickly on any 16GB+ GPU with low disk space requirements, such as the 16GB T4 GPU provided in the Google Colab free
tier.`),Iu.forEach(a),yn=c(e),ha=o(e,"P",{});var ku=r(ha);Kr=s(ku,`Should you have a smaller GPU or encounter memory issues during training, you can follow the suggestions provided for
reducing memory usage. Conversely, should you have access to a larger GPU, you can amend the training arguments to maximise
your throughput. Thus, this guide is accessible regardless of your GPU specifications!`),ku.forEach(a),Mn=c(e),ca=o(e,"P",{});var Wu=r(ca);ei=s(Wu,`Likewise, this guide outlines how to fine-tune the Whisper model for the Dhivehi language. However, the steps covered here
generalise to any language in the Common Voice dataset, and more generally to any ASR dataset on the Hugging Face Hub.
You can tweak the code to quickly switch to a language of your choice and fine-tune a Whisper model in your native tongue \u{1F30D}`),Wu.forEach(a),wn=c(e),da=o(e,"P",{});var Cu=r(da);ti=s(Cu,"Right! Now that\u2019s out the way, let\u2019s get started and kick-off our fine-tuning pipeline!"),Cu.forEach(a),gn=c(e),oe=o(e,"H2",{class:!0});var gr=r(oe);ge=o(gr,"A",{id:!0,class:!0,href:!0});var Gu=r(ge);ol=o(Gu,"SPAN",{});var $u=r(ol);f(st.$$.fragment,$u),$u.forEach(a),Gu.forEach(a),ai=c(gr),rl=o(gr,"SPAN",{});var Zu=r(rl);li=s(Zu,"Prepare Environment"),Zu.forEach(a),gr.forEach(a),bn=c(e),be=o(e,"P",{});var br=r(be);si=s(br,"We strongly advise you to upload model checkpoints directly the "),nt=o(br,"A",{href:!0,rel:!0});var Bu=r(nt);ni=s(Bu,"Hugging Face Hub"),Bu.forEach(a),oi=s(br,` while training.
The Hub provides:`),br.forEach(a),Jn=c(e),Z=o(e,"UL",{});var Pe=r(Z);il=o(Pe,"LI",{});var Au=r(il);ri=s(Au,"Integrated version control: you can be sure that no model checkpoint is lost during training."),Au.forEach(a),ii=c(Pe),pl=o(Pe,"LI",{});var Nu=r(pl);pi=s(Nu,"Tensorboard logs: track important metrics over the course of training."),Nu.forEach(a),hi=c(Pe),hl=o(Pe,"LI",{});var Ru=r(hl);ci=s(Ru,"Model cards: document what a model does and its intended use cases."),Ru.forEach(a),di=c(Pe),cl=o(Pe,"LI",{});var Xu=r(cl);ui=s(Xu,"Community: an easy way to share and collaborate with the community! \u{1F917}"),Xu.forEach(a),Pe.forEach(a),Tn=c(e),Je=o(e,"P",{});var Jr=r(Je);fi=s(Jr,`Linking the notebook to the Hub is straightforward - it simply requires entering your Hub authentication token when prompted.
Find your Hub authentication token `),ot=o(Jr,"A",{href:!0,rel:!0});var Vu=r(ot);mi=s(Vu,"here"),Vu.forEach(a),yi=s(Jr," and enter it when prompted:"),Jr.forEach(a),vn=c(e),f(rt.$$.fragment,e),Un=c(e),ua=o(e,"P",{});var xu=r(ua);dl=o(xu,"STRONG",{});var Su=r(dl);Mi=s(Su,"Output:"),Su.forEach(a),xu.forEach(a),jn=c(e),f(it.$$.fragment,e),_n=c(e),re=o(e,"H2",{class:!0});var Tr=r(re);Te=o(Tr,"A",{id:!0,class:!0,href:!0});var Fu=r(Te);ul=o(Fu,"SPAN",{});var Yu=r(ul);f(pt.$$.fragment,Yu),Yu.forEach(a),Fu.forEach(a),wi=c(Tr),fl=o(Tr,"SPAN",{});var zu=r(fl);gi=s(zu,"Load Dataset"),zu.forEach(a),Tr.forEach(a),En=c(e),ht=o(e,"P",{});var ju=r(ht);ct=o(ju,"A",{href:!0,rel:!0});var Qu=r(ct);bi=s(Qu,"Common Voice 13"),Qu.forEach(a),Ji=s(ju,` contains approximately ten
hours of labelled Dhivehi data, three of which is held-out test data. This is extremely little data for fine-tuning, so
we\u2019ll be relying on leveraging the extensive multilingual ASR knowledge acquired by Whisper during pre-training for the
low-resource Dhivehi language.`),ju.forEach(a),In=c(e),B=o(e,"P",{});var Oe=r(B);Ti=s(Oe,`Using \u{1F917} Datasets, downloading and preparing data is extremely simple. We can download and prepare the Common Voice 13
splits in just one line of code. Since Dhivehi is very low-resource, we\u2019ll combine the `),ml=o(Oe,"CODE",{});var Hu=r(ml);vi=s(Hu,"train"),Hu.forEach(a),Ui=s(Oe," and "),yl=o(Oe,"CODE",{});var Du=r(yl);ji=s(Du,"validation"),Du.forEach(a),_i=s(Oe,` splits
to give approximately seven hours of training data. We\u2019ll use the three hours of `),Ml=o(Oe,"CODE",{});var qu=r(Ml);Ei=s(qu,"test"),qu.forEach(a),Ii=s(Oe," data as our held-out test set:"),Oe.forEach(a),kn=c(e),f(dt.$$.fragment,e),Wn=c(e),fa=o(e,"P",{});var Pu=r(fa);wl=o(Pu,"STRONG",{});var Ou=r(wl);ki=s(Ou,"Output:"),Ou.forEach(a),Pu.forEach(a),Cn=c(e),f(ut.$$.fragment,e),Gn=c(e),f(ve.$$.fragment,e),$n=c(e),_=o(e,"P",{});var ee=r(_);Wi=s(ee,"Most ASR datasets only provide input audio samples ("),gl=o(ee,"CODE",{});var Lu=r(gl);Ci=s(Lu,"audio"),Lu.forEach(a),Gi=s(ee,") and the corresponding transcribed text ("),bl=o(ee,"CODE",{});var Ku=r(bl);$i=s(Ku,"sentence"),Ku.forEach(a),Zi=s(ee,`).
Common Voice contains additional metadata information, such as `),Jl=o(ee,"CODE",{});var ef=r(Jl);Bi=s(ef,"accent"),ef.forEach(a),Ai=s(ee," and "),Tl=o(ee,"CODE",{});var tf=r(Tl);Ni=s(tf,"locale"),tf.forEach(a),Ri=s(ee,`, which we can disregard for ASR.
Keeping the notebook as general as possible, we only consider the input audio and transcribed text for fine-tuning,
discarding the additional metadata information:`),ee.forEach(a),Zn=c(e),f(ft.$$.fragment,e),Bn=c(e),ie=o(e,"H2",{class:!0});var vr=r(ie);Ue=o(vr,"A",{id:!0,class:!0,href:!0});var af=r(Ue);vl=o(af,"SPAN",{});var lf=r(vl);f(mt.$$.fragment,lf),lf.forEach(a),af.forEach(a),Xi=c(vr),Ul=o(vr,"SPAN",{});var sf=r(Ul);Vi=s(sf,"Feature Extractor, Tokenizer and Processor"),sf.forEach(a),vr.forEach(a),An=c(e),ma=o(e,"P",{});var nf=r(ma);xi=s(nf,"The ASR pipeline can be de-composed into three stages:"),nf.forEach(a),Nn=c(e),z=o(e,"OL",{});var qa=r(z);jl=o(qa,"LI",{});var of=r(jl);Si=s(of,"The feature extractor which pre-processes the raw audio-inputs to log-mel spectrograms"),of.forEach(a),Fi=c(qa),_l=o(qa,"LI",{});var rf=r(_l);Yi=s(rf,"The model which performs the sequence-to-sequence mapping"),rf.forEach(a),zi=c(qa),El=o(qa,"LI",{});var pf=r(El);Qi=s(pf,"The tokenizer which post-processes the predicted tokens to text"),pf.forEach(a),qa.forEach(a),Rn=c(e),A=o(e,"P",{});var Le=r(A);Hi=s(Le,"In \u{1F917} Transformers, the Whisper model has an associated feature extractor and tokenizer, called "),yt=o(Le,"A",{href:!0,rel:!0});var hf=r(yt);Di=s(hf,"WhisperFeatureExtractor"),hf.forEach(a),qi=s(Le," and "),Mt=o(Le,"A",{href:!0,rel:!0});var cf=r(Mt);Pi=s(cf,"WhisperTokenizer"),cf.forEach(a),Oi=s(Le,`
respectively. To make our lives simple, these two objects are wrapped under a single class, called the `),wt=o(Le,"A",{href:!0,rel:!0});var df=r(wt);Li=s(df,"WhisperProcessor"),df.forEach(a),Ki=s(Le,`.
We can call the WhisperProcessor to perform 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: the processor and the model.`),Le.forEach(a),Xn=c(e),T=o(e,"P",{});var x=r(T);ep=s(x,"When performing multilingual fine-tuning, we need to set the "),Il=o(x,"CODE",{});var uf=r(Il);tp=s(uf,'"language"'),uf.forEach(a),ap=s(x," and "),kl=o(x,"CODE",{});var ff=r(kl);lp=s(ff,'"task"'),ff.forEach(a),sp=s(x,` when instantiating the processor.
The `),Wl=o(x,"CODE",{});var mf=r(Wl);np=s(mf,'"language"'),mf.forEach(a),op=s(x," should be set to the source audio language, and the task to "),Cl=o(x,"CODE",{});var yf=r(Cl);rp=s(yf,'"transcribe"'),yf.forEach(a),ip=s(x,` for speech recognition or
`),Gl=o(x,"CODE",{});var Mf=r(Gl);pp=s(Mf,'"translate"'),Mf.forEach(a),hp=s(x,` for speech translation. These arguments modify the behaviour of the tokenizer, and should be set correctly
to ensure the target labels are encoded properly.`),x.forEach(a),Vn=c(e),ya=o(e,"P",{});var wf=r(ya);cp=s(wf,"We can see all possible languages supported by Whisper by importing the list of languages:"),wf.forEach(a),xn=c(e),f(gt.$$.fragment,e),Sn=c(e),Ma=o(e,"P",{});var gf=r(Ma);dp=s(gf,`If you scroll through this list, you\u2019ll notice that many languages are present, but Dhivehi is one of few that is not!
This means that Whisper was not pre-trained on Dhivehi. However, this doesn\u2019t mean that we can\u2019t fine tune Whisper on it.
In doing so, we\u2019ll be teaching Whisper a new language, one that the pre-trained checkpoint does not support. That\u2019s pretty
cool, right!`),gf.forEach(a),Fn=c(e),wa=o(e,"P",{});var bf=r(wa);up=s(bf,`When you fine-tune it on a new language, Whisper does a good job at leveraging its knowledge of the other 96 languages
it\u2019s pre-trained on. Largely speaking, all modern languages will be linguistically similar to at least one of the
96 languages Whisper already knows, so we\u2019ll fall under this paradigm of cross-lingual knowledge representation.`),bf.forEach(a),Yn=c(e),Q=o(e,"P",{});var Pa=r(Q);fp=s(Pa,"What we need to do to fine-tune Whisper on a new language is find the language "),$l=o(Pa,"STRONG",{});var Jf=r($l);mp=s(Jf,"most similar"),Jf.forEach(a),yp=s(Pa,` that Whisper was
pre-trained on. The Wikipedia article for Dhivehi states that Dhivehi is closely related to the Sinhalese language of Sri Lanka.
If we check the language codes again, we can see that Sinhalese is present in the Whisper language set,
so we can safely set our language argument to `),Zl=o(Pa,"CODE",{});var Tf=r(Zl);Mp=s(Tf,'"sinhalese"'),Tf.forEach(a),wp=s(Pa,"."),Pa.forEach(a),zn=c(e),H=o(e,"P",{});var Oa=r(H);gp=s(Oa,"Right! We\u2019ll load our processor from the pre-trained checkpoint, setting the language to "),Bl=o(Oa,"CODE",{});var vf=r(Bl);bp=s(vf,'"sinhalese"'),vf.forEach(a),Jp=s(Oa," and task to "),Al=o(Oa,"CODE",{});var Uf=r(Al);Tp=s(Uf,'"transcribe"'),Uf.forEach(a),vp=s(Oa,`
as explained above:`),Oa.forEach(a),Qn=c(e),f(bt.$$.fragment,e),Hn=c(e),D=o(e,"P",{});var La=r(D);Up=s(La,`It\u2019s worth reiterating that in most circumstances, you\u2019ll find that the language you want to fine-tune on is in the set of
pre-training languages, in which case you can simply set the language directly as your source audio language! Note that
both of these arguments should be omitted for English-only fine-tuning, where there is only one option for the language
(`),Nl=o(La,"CODE",{});var jf=r(Nl);jp=s(jf,'"English"'),jf.forEach(a),_p=s(La,") and task ("),Rl=o(La,"CODE",{});var _f=r(Rl);Ep=s(_f,'"transcribe"'),_f.forEach(a),Ip=s(La,")."),La.forEach(a),Dn=c(e),pe=o(e,"H2",{class:!0});var Ur=r(pe);je=o(Ur,"A",{id:!0,class:!0,href:!0});var Ef=r(je);Xl=o(Ef,"SPAN",{});var If=r(Xl);f(Jt.$$.fragment,If),If.forEach(a),Ef.forEach(a),kp=c(Ur),Vl=o(Ur,"SPAN",{});var kf=r(Vl);Wp=s(kf,"Pre-Process the Data"),kf.forEach(a),Ur.forEach(a),qn=c(e),_e=o(e,"P",{});var jr=r(_e);Cp=s(jr,"Let\u2019s have a look at the dataset features. Pay particular attention to the "),xl=o(jr,"CODE",{});var Wf=r(xl);Gp=s(Wf,'"audio"'),Wf.forEach(a),$p=s(jr,` column - this details the sampling
rate of our audio inputs:`),jr.forEach(a),Pn=c(e),f(Tt.$$.fragment,e),On=c(e),ga=o(e,"P",{});var Cf=r(ga);Sl=o(Cf,"STRONG",{});var Gf=r(Sl);Zp=s(Gf,"Output:"),Gf.forEach(a),Cf.forEach(a),Ln=c(e),f(vt.$$.fragment,e),Kn=c(e),Ee=o(e,"P",{});var _r=r(Ee);Bp=s(_r,"Since our input audio is sampled at 48kHz, we need to "),Fl=o(_r,"EM",{});var $f=r(Fl);Ap=s($f,"downsample"),$f.forEach(a),Np=s(_r,` it to 16kHz prior to passing it to the Whisper feature
extractor, 16kHz being the sampling rate expected by the Whisper model.`),_r.forEach(a),eo=c(e),Ie=o(e,"P",{});var Er=r(Ie);Rp=s(Er,"We\u2019ll set the audio inputs to the correct sampling rate using dataset\u2019s "),Ut=o(Er,"A",{href:!0,rel:!0});var Zf=r(Ut);Yl=o(Zf,"CODE",{});var Bf=r(Yl);Xp=s(Bf,"cast_column"),Bf.forEach(a),Zf.forEach(a),Vp=s(Er,`
method. This operation does not change the audio in-place, but rather signals to datasets to resample audio samples
on-the-fly when they are loaded:`),Er.forEach(a),to=c(e),f(jt.$$.fragment,e),ao=c(e),ba=o(e,"P",{});var Af=r(ba);xp=s(Af,"Now we can write a function to prepare our data ready for the model:"),Af.forEach(a),lo=c(e),q=o(e,"OL",{});var Ka=r(q);_t=o(Ka,"LI",{});var Ir=r(_t);Sp=s(Ir,"We load and resample the audio data on a sample-by-sample basis by calling "),zl=o(Ir,"CODE",{});var Nf=r(zl);Fp=s(Nf,'sample["audio"]'),Nf.forEach(a),Yp=s(Ir,". As explained above, \u{1F917} Datasets performs any necessary resampling operations on the fly."),Ir.forEach(a),zp=c(Ka),Ql=o(Ka,"LI",{});var Rf=r(Ql);Qp=s(Rf,"We use the feature extractor to compute the log-mel spectrogram input features from our 1-dimensional audio array."),Rf.forEach(a),Hp=c(Ka),Hl=o(Ka,"LI",{});var Xf=r(Hl);Dp=s(Xf,"We encode the transcriptions to label ids through the use of the tokenizer."),Xf.forEach(a),Ka.forEach(a),so=c(e),f(Et.$$.fragment,e),no=c(e),P=o(e,"P",{});var el=r(P);qp=s(el,"We can apply the data preparation function to all of our training examples using \u{1F917} Datasets\u2019 "),Dl=o(el,"CODE",{});var Vf=r(Dl);Pp=s(Vf,".map"),Vf.forEach(a),Op=s(el,` method. We\u2019ll
remove the columns from the raw training data (the audio and text), leaving just the columns returned by the
`),ql=o(el,"CODE",{});var xf=r(ql);Lp=s(xf,"prepare_dataset"),xf.forEach(a),Kp=s(el," function:"),el.forEach(a),oo=c(e),f(It.$$.fragment,e),ro=c(e),O=o(e,"P",{});var tl=r(O);eh=s(tl,`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 `),Pl=o(tl,"CODE",{});var Sf=r(Pl);th=s(Sf,"True"),Sf.forEach(a),ah=s(tl,` for
samples that are less than 30s, and `),Ol=o(tl,"CODE",{});var Ff=r(Ol);lh=s(Ff,"False"),Ff.forEach(a),sh=s(tl," for those that are longer:"),tl.forEach(a),io=c(e),f(kt.$$.fragment,e),po=c(e),ke=o(e,"P",{});var kr=r(ke);nh=s(kr,"We apply our filter function to all samples of our training dataset through \u{1F917} Datasets\u2019 "),Ll=o(kr,"CODE",{});var Yf=r(Ll);oh=s(Yf,".filter"),Yf.forEach(a),rh=s(kr," method:"),kr.forEach(a),ho=c(e),f(Wt.$$.fragment,e),co=c(e),Ja=o(e,"P",{});var zf=r(Ja);ih=s(zf,"Let\u2019s check how much training data we removed through this filtering step:"),zf.forEach(a),uo=c(e),f(Ct.$$.fragment,e),fo=c(e),Ta=o(e,"P",{});var Qf=r(Ta);Kl=o(Qf,"STRONG",{});var Hf=r(Kl);ph=s(Hf,"Output"),Hf.forEach(a),Qf.forEach(a),mo=c(e),f(Gt.$$.fragment,e),yo=c(e),va=o(e,"P",{});var Df=r(va);hh=s(Df,`Alright! In this case we actually have the same number of samples as before, so there were no samples longer than 30s.
This might not be the case if you switch languages, so it\u2019s best to keep this filter step in-place for robustness. With
that, we have our data fully prepared for training! Let\u2019s continue and take a look at how we can use this data to fine-tune
Whisper.`),Df.forEach(a),Mo=c(e),he=o(e,"H2",{class:!0});var Wr=r(he);We=o(Wr,"A",{id:!0,class:!0,href:!0});var qf=r(We);es=o(qf,"SPAN",{});var Pf=r(es);f($t.$$.fragment,Pf),Pf.forEach(a),qf.forEach(a),ch=c(Wr),ts=o(Wr,"SPAN",{});var Of=r(ts);dh=s(Of,"Training and Evaluation"),Of.forEach(a),Wr.forEach(a),wo=c(e),Ce=o(e,"P",{});var Cr=r(Ce);uh=s(Cr,`Now that we\u2019ve prepared our data, we\u2019re ready to dive into the training pipeline.
The `),Zt=o(Cr,"A",{href:!0,rel:!0});var Lf=r(Zt);fh=s(Lf,"\u{1F917} Trainer"),Lf.forEach(a),mh=s(Cr,`
will do much of the heavy lifting for us. All we have to do is:`),Cr.forEach(a),go=c(e),N=o(e,"UL",{});var Ke=r(N);as=o(Ke,"LI",{});var Kf=r(as);ls=o(Kf,"P",{});var em=r(ls);yh=s(em,"Define a data collator: the data collator takes our pre-processed data and prepares PyTorch tensors ready for the model."),em.forEach(a),Kf.forEach(a),Mh=c(Ke),ss=o(Ke,"LI",{});var tm=r(ss);Bt=o(tm,"P",{});var Gr=r(Bt);wh=s(Gr,"Evaluation metrics: during evaluation, we want to evaluate the model using the word error rate (WER) metric. We need to define a "),ns=o(Gr,"CODE",{});var am=r(ns);gh=s(am,"compute_metrics"),am.forEach(a),bh=s(Gr," function that handles this computation."),Gr.forEach(a),tm.forEach(a),Jh=c(Ke),os=o(Ke,"LI",{});var lm=r(os);rs=o(lm,"P",{});var sm=r(rs);Th=s(sm,"Load a pre-trained checkpoint: we need to load a pre-trained checkpoint and configure it correctly for training."),sm.forEach(a),lm.forEach(a),vh=c(Ke),is=o(Ke,"LI",{});var nm=r(is);ps=o(nm,"P",{});var om=r(ps);Uh=s(om,"Define the training arguments: these will be used by the \u{1F917} Trainer in constructing the training schedule."),om.forEach(a),nm.forEach(a),Ke.forEach(a),bo=c(e),Ua=o(e,"P",{});var rm=r(Ua);jh=s(rm,`Once we\u2019ve fine-tuned the model, we will evaluate it on the test data to verify that we have correctly trained it
to transcribe speech in Dhivehi.`),rm.forEach(a),Jo=c(e),ce=o(e,"H3",{class:!0});var $r=r(ce);Ge=o($r,"A",{id:!0,class:!0,href:!0});var im=r(Ge);hs=o(im,"SPAN",{});var pm=r(hs);f(At.$$.fragment,pm),pm.forEach(a),im.forEach(a),_h=c($r),cs=o($r,"SPAN",{});var hm=r(cs);Eh=s(hm,"Define a Data Collator"),hm.forEach(a),$r.forEach(a),To=c(e),E=o(e,"P",{});var te=r(E);Ih=s(te,"The data collator for a sequence-to-sequence speech model is unique in the sense that it treats the "),ds=o(te,"CODE",{});var cm=r(ds);kh=s(cm,"input_features"),cm.forEach(a),Wh=s(te,`
and `),us=o(te,"CODE",{});var dm=r(us);Ch=s(dm,"labels"),dm.forEach(a),Gh=s(te," independently: the  "),fs=o(te,"CODE",{});var um=r(fs);$h=s(um,"input_features"),um.forEach(a),Zh=s(te," must be handled by the feature extractor and the "),ms=o(te,"CODE",{});var fm=r(ms);Bh=s(fm,"labels"),fm.forEach(a),Ah=s(te," by the tokenizer."),te.forEach(a),vo=c(e),I=o(e,"P",{});var ae=r(I);Nh=s(ae,"The "),ys=o(ae,"CODE",{});var mm=r(ys);Rh=s(mm,"input_features"),mm.forEach(a),Xh=s(ae,` are already padded to 30s and converted to a log-Mel spectrogram of fixed dimension, so all we
have to do is convert them to batched PyTorch tensors. We do this using the feature extractor\u2019s `),Ms=o(ae,"CODE",{});var ym=r(Ms);Vh=s(ym,".pad"),ym.forEach(a),xh=s(ae,` method with
`),ws=o(ae,"CODE",{});var Mm=r(ws);Sh=s(Mm,"return_tensors=pt"),Mm.forEach(a),Fh=s(ae,`. Note that no additional padding is applied here since the inputs are of fixed dimension, the
`),gs=o(ae,"CODE",{});var wm=r(gs);Yh=s(wm,"input_features"),wm.forEach(a),zh=s(ae," are simply converted to PyTorch tensors."),ae.forEach(a),Uo=c(e),k=o(e,"P",{});var le=r(k);Qh=s(le,"On the other hand, the "),bs=o(le,"CODE",{});var gm=r(bs);Hh=s(gm,"labels"),gm.forEach(a),Dh=s(le,` are un-padded. We first pad the sequences to the maximum length in the batch using
the tokenizer\u2019s `),Js=o(le,"CODE",{});var bm=r(Js);qh=s(bm,".pad"),bm.forEach(a),Ph=s(le," method. The padding tokens are then replaced by "),Ts=o(le,"CODE",{});var Jm=r(Ts);Oh=s(Jm,"-100"),Jm.forEach(a),Lh=s(le," so that these tokens are "),vs=o(le,"STRONG",{});var Tm=r(vs);Kh=s(Tm,"not"),Tm.forEach(a),ec=s(le,` taken
into account when computing the loss. We then cut the start of transcript token from the beginning of the label sequence
as we append it later during training.`),le.forEach(a),jo=c(e),$e=o(e,"P",{});var Zr=r($e);tc=s(Zr,"We can leverage the "),Us=o(Zr,"CODE",{});var vm=r(Us);ac=s(vm,"WhisperProcessor"),vm.forEach(a),lc=s(Zr," we defined earlier to perform both the feature extractor and the tokenizer operations:"),Zr.forEach(a),_o=c(e),f(Nt.$$.fragment,e),Eo=c(e),ja=o(e,"P",{});var Um=r(ja);sc=s(Um,"We can now initialise the data collator we\u2019ve just defined:"),Um.forEach(a),Io=c(e),f(Rt.$$.fragment,e),ko=c(e),_a=o(e,"P",{});var jm=r(_a);nc=s(jm,"Onwards!"),jm.forEach(a),Wo=c(e),de=o(e,"H3",{class:!0});var Br=r(de);Ze=o(Br,"A",{id:!0,class:!0,href:!0});var _m=r(Ze);js=o(_m,"SPAN",{});var Em=r(js);f(Xt.$$.fragment,Em),Em.forEach(a),_m.forEach(a),oc=c(Br),_s=o(Br,"SPAN",{});var Im=r(_s);rc=s(Im,"Evaluation Metrics"),Im.forEach(a),Br.forEach(a),Co=c(e),Be=o(e,"P",{});var Ar=r(Be);ic=s(Ar,`Next, we define the evaluation metric we\u2019ll use on our evaluation set. We\u2019ll use the Word Error Rate (WER) metric introduced
in the section on `),Ea=o(Ar,"A",{href:!0});var km=r(Ea);pc=s(km,"Evaluation"),km.forEach(a),hc=s(Ar,", the \u2018de-facto\u2019 metric for assessing ASR systems."),Ar.forEach(a),Go=c(e),Ia=o(e,"P",{});var Wm=r(Ia);cc=s(Wm,"We\u2019ll load the WER metric from \u{1F917} Evaluate:"),Wm.forEach(a),$o=c(e),f(Vt.$$.fragment,e),Zo=c(e),W=o(e,"P",{});var se=r(W);dc=s(se,`We then simply have to define a function that takes our model predictions and returns the WER metric. This function, called
`),Es=o(se,"CODE",{});var Cm=r(Es);uc=s(Cm,"compute_metrics"),Cm.forEach(a),fc=s(se,", first replaces "),Is=o(se,"CODE",{});var Gm=r(Is);mc=s(Gm,"-100"),Gm.forEach(a),yc=s(se," with the "),ks=o(se,"CODE",{});var $m=r(ks);Mc=s($m,"pad_token_id"),$m.forEach(a),wc=s(se," in the "),Ws=o(se,"CODE",{});var Zm=r(Ws);gc=s(Zm,"label_ids"),Zm.forEach(a),bc=s(se,` (undoing the step we applied in the
data collator to ignore padded tokens correctly in the loss). It then decodes the predicted and label ids to strings. Finally,
it computes the WER between the predictions and reference labels. Here, we have the option of evaluating with the \u2018normalised\u2019
transcriptions and predictions, which have punctuation and casing removed. We recommend you follow this to benefit
from the WER improvement obtained by normalising the transcriptions.`),se.forEach(a),Bo=c(e),f(xt.$$.fragment,e),Ao=c(e),ue=o(e,"H3",{class:!0});var Nr=r(ue);Ae=o(Nr,"A",{id:!0,class:!0,href:!0});var Bm=r(Ae);Cs=o(Bm,"SPAN",{});var Am=r(Cs);f(St.$$.fragment,Am),Am.forEach(a),Bm.forEach(a),Jc=c(Nr),Gs=o(Nr,"SPAN",{});var Nm=r(Gs);Tc=s(Nm,"Load a Pre-Trained Checkpoint"),Nm.forEach(a),Nr.forEach(a),No=c(e),ka=o(e,"P",{});var Rm=r(ka);vc=s(Rm,"Now let\u2019s load the pre-trained Whisper small checkpoint. Again, this is trivial through use of \u{1F917} Transformers!"),Rm.forEach(a),Ro=c(e),f(Ft.$$.fragment,e),Xo=c(e),v=o(e,"P",{});var S=r(v);Uc=s(S,"We\u2019ll set "),$s=o(S,"CODE",{});var Xm=r($s);jc=s(Xm,"use_cache"),Xm.forEach(a),_c=s(S," to "),Zs=o(S,"CODE",{});var Vm=r(Zs);Ec=s(Vm,"False"),Vm.forEach(a),Ic=s(S," for training since we\u2019re using "),Yt=o(S,"A",{href:!0,rel:!0});var xm=r(Yt);kc=s(xm,"gradient checkpointing"),xm.forEach(a),Wc=s(S,`
and the two are incompatible. We\u2019ll also override two generation arguments to control the behaviour of the model during inference:
we\u2019ll force the language and task tokens during generation by setting the `),Bs=o(S,"CODE",{});var Sm=r(Bs);Cc=s(Sm,"language"),Sm.forEach(a),Gc=s(S," and "),As=o(S,"CODE",{});var Fm=r(As);$c=s(Fm,"task"),Fm.forEach(a),Zc=s(S,` arguments, and also re-enable
cache for generation to speed-up inference time:`),S.forEach(a),Vo=c(e),f(zt.$$.fragment,e),xo=c(e),fe=o(e,"H2",{class:!0});var Rr=r(fe);Ne=o(Rr,"A",{id:!0,class:!0,href:!0});var Ym=r(Ne);Ns=o(Ym,"SPAN",{});var zm=r(Ns);f(Qt.$$.fragment,zm),zm.forEach(a),Ym.forEach(a),Bc=c(Rr),Rs=o(Rr,"SPAN",{});var Qm=r(Rs);Ac=s(Qm,"Define the Training Configuration"),Qm.forEach(a),Rr.forEach(a),So=c(e),Re=o(e,"P",{});var Xr=r(Re);Nc=s(Xr,`In the final step, we define all the parameters related to training. Here, we set the number of training steps to 500.
This is enough steps to see a big WER improvement compared to the pre-trained Whisper model, while ensuring that fine-tuning can
be run in approximately 45 minutes on a Google Colab free tier. For more detail on the training arguments, refer to the
Seq2SeqTrainingArguments `),Ht=o(Xr,"A",{href:!0,rel:!0});var Hm=r(Ht);Rc=s(Hm,"docs"),Hm.forEach(a),Xc=s(Xr,"."),Xr.forEach(a),Fo=c(e),f(Dt.$$.fragment,e),Yo=c(e),f(Xe.$$.fragment,e),zo=c(e),Ve=o(e,"P",{});var Vr=r(Ve);Vc=s(Vr,"We can forward the training arguments to the \u{1F917} Trainer along with our model, dataset, data collator and "),Xs=o(Vr,"CODE",{});var Dm=r(Xs);xc=s(Dm,"compute_metrics"),Dm.forEach(a),Sc=s(Vr," function:"),Vr.forEach(a),Qo=c(e),f(qt.$$.fragment,e),Ho=c(e),Wa=o(e,"P",{});var qm=r(Wa);Fc=s(qm,"And with that, we\u2019re ready to start training!"),qm.forEach(a),Do=c(e),me=o(e,"H3",{class:!0});var xr=r(me);xe=o(xr,"A",{id:!0,class:!0,href:!0});var Pm=r(xe);Vs=o(Pm,"SPAN",{});var Om=r(Vs);f(Pt.$$.fragment,Om),Om.forEach(a),Pm.forEach(a),Yc=c(xr),xs=o(xr,"SPAN",{});var Lm=r(xs);zc=s(Lm,"Training"),Lm.forEach(a),xr.forEach(a),qo=c(e),Ca=o(e,"P",{});var Km=r(Ca);Qc=s(Km,"To launch training, simply execute:"),Km.forEach(a),Po=c(e),f(Ot.$$.fragment,e),Oo=c(e),R=o(e,"P",{});var et=r(R);Hc=s(et,`Training will take approximately 45 minutes depending on your GPU or the one allocated to the Google Colab. Depending on
your GPU, it is possible that you will encounter a CUDA `),Ss=o(et,"CODE",{});var ey=r(Ss);Dc=s(ey,'"out-of-memory"'),ey.forEach(a),qc=s(et,` error when you start training. In this case,
you can reduce the `),Fs=o(et,"CODE",{});var ty=r(Fs);Pc=s(ty,"per_device_train_batch_size"),ty.forEach(a),Oc=s(et," incrementally by factors of 2 and employ "),Lt=o(et,"A",{href:!0,rel:!0});var ay=r(Lt);Ys=o(ay,"CODE",{});var ly=r(Ys);Lc=s(ly,"gradient_accumulation_steps"),ly.forEach(a),ay.forEach(a),Kc=s(et,`
to compensate.`),et.forEach(a),Lo=c(e),Ga=o(e,"P",{});var sy=r(Ga);zs=o(sy,"STRONG",{});var ny=r(zs);ed=s(ny,"Output:"),ny.forEach(a),sy.forEach(a),Ko=c(e),Se=o(e,"TABLE",{});var Sr=r(Se);Qs=o(Sr,"THEAD",{});var oy=r(Qs);U=o(oy,"TR",{});var F=r(U);$a=o(F,"TH",{align:!0});var ry=r($a);td=s(ry,"Training Loss"),ry.forEach(a),ad=c(F),Za=o(F,"TH",{align:!0});var iy=r(Za);ld=s(iy,"Epoch"),iy.forEach(a),sd=c(F),Ba=o(F,"TH",{align:!0});var py=r(Ba);nd=s(py,"Step"),py.forEach(a),od=c(F),Aa=o(F,"TH",{align:!0});var hy=r(Aa);rd=s(hy,"Validation Loss"),hy.forEach(a),id=c(F),Na=o(F,"TH",{align:!0});var cy=r(Na);pd=s(cy,"Wer Ortho"),cy.forEach(a),hd=c(F),Ra=o(F,"TH",{align:!0});var dy=r(Ra);cd=s(dy,"Wer"),dy.forEach(a),F.forEach(a),oy.forEach(a),dd=c(Sr),Hs=o(Sr,"TBODY",{});var uy=r(Hs);j=o(uy,"TR",{});var Y=r(j);Xa=o(Y,"TD",{align:!0});var fy=r(Xa);ud=s(fy,"0.136"),fy.forEach(a),fd=c(Y),Va=o(Y,"TD",{align:!0});var my=r(Va);md=s(my,"1.63"),my.forEach(a),yd=c(Y),xa=o(Y,"TD",{align:!0});var yy=r(xa);Md=s(yy,"500"),yy.forEach(a),wd=c(Y),Sa=o(Y,"TD",{align:!0});var My=r(Sa);gd=s(My,"0.1727"),My.forEach(a),bd=c(Y),Fa=o(Y,"TD",{align:!0});var wy=r(Fa);Jd=s(wy,"63.8972"),wy.forEach(a),Td=c(Y),Ya=o(Y,"TD",{align:!0});var gy=r(Ya);vd=s(gy,"14.0661"),gy.forEach(a),Y.forEach(a),uy.forEach(a),Sr.forEach(a),er=c(e),za=o(e,"P",{});var by=r(za);Ud=s(by,`Our final WER is 14.1% - not bad for seven hours of training data and just 500 training steps! That amounts to a 112%
improvement versus the pre-trained model! That means we\u2019ve taken a model that previously had no knowledge about Dhivehi,
and fine-tuned it to recognise Dhivehi speech with adequate accuracy in under one hour \u{1F92F}`),by.forEach(a),tr=c(e),Fe=o(e,"P",{});var Fr=r(Fe);jd=s(Fr,"The big question is how this compares to other ASR systems. For that, we can view the autoevaluate "),Kt=o(Fr,"A",{href:!0,rel:!0});var Jy=r(Kt);_d=s(Jy,"leaderboard"),Jy.forEach(a),Ed=s(Fr,`,
a leaderboard that categorises models by language and dataset, and subsequently ranks them according to their WER.`),Fr.forEach(a),ar=c(e),Ye=o(e,"P",{});var Yr=r(Ye);Id=s(Yr,"Looking at the leaderboard, we see that our model trained for 500 steps convincingly beats the pre-trained "),ea=o(Yr,"A",{href:!0,rel:!0});var Ty=r(ea);kd=s(Ty,"Whisper Small"),Ty.forEach(a),Wd=s(Yr,`
checkpoint that we evaluated in the previous section. Nice job \u{1F44F}`),Yr.forEach(a),lr=c(e),L=o(e,"P",{});var al=r(L);Cd=s(al,`We see that there are a few checkpoints that do better than the one we trained. The beauty of the Hugging Face Hub is that
it\u2019s a `),Ds=o(al,"EM",{});var vy=r(Ds);Gd=s(vy,"collaborative"),vy.forEach(a),$d=s(al,` platform - if we don\u2019t have the time or resources to perform a longer training run ourselves, we
can load a checkpoint that someone else in the community has trained and been kind enough to share (making sure to thank them for it!).
You\u2019ll be able to load these checkpoints in exactly the same way as the pre-trained ones using the `),qs=o(al,"CODE",{});var Uy=r(qs);Zd=s(Uy,"pipeline"),Uy.forEach(a),Bd=s(al,` class as we
did previously! So there\u2019s nothing stopping you cherry-picking the best model on the leaderboard to use for your task!`),al.forEach(a),sr=c(e),Qa=o(e,"P",{});var jy=r(Qa);Ad=s(jy,`We can automatically submit our checkpoint to the leaderboard when we push the training results to the Hub - we simply
have to set the appropriate key-word arguments (kwargs). You can change these values to match your dataset, language and
model name accordingly:`),jy.forEach(a),nr=c(e),f(ta.$$.fragment,e),or=c(e),ze=o(e,"P",{});var zr=r(ze);Nd=s(zr,"The training results can now be uploaded to the Hub. To do so, execute the "),Ps=o(zr,"CODE",{});var _y=r(Ps);Rd=s(_y,"push_to_hub"),_y.forEach(a),Xd=s(zr," command:"),zr.forEach(a),rr=c(e),f(aa.$$.fragment,e),ir=c(e),K=o(e,"P",{});var ll=r(K);Vd=s(ll,"This will save the training logs and model weights under "),Os=o(ll,"CODE",{});var Ey=r(Os);xd=s(Ey,'"your-username/the-name-you-picked"'),Ey.forEach(a),Sd=s(ll,`. For this example, check
out the upload at `),Ls=o(ll,"CODE",{});var Iy=r(Ls);Fd=s(Iy,"sanchit-gandhi/whisper-small-dv"),Iy.forEach(a),Yd=s(ll,"."),ll.forEach(a),pr=c(e),Ha=o(e,"P",{});var ky=r(Ha);zd=s(ky,`While the fine-tuned model yields satisfactory results on the Common Voice 13 Dhivehi test data, it is by no means optimal.
The purpose of this guide is to demonstrate how to fine-tune an ASR model using the \u{1F917} Trainer for multilingual speech
recognition.`),ky.forEach(a),hr=c(e),X=o(e,"P",{});var tt=r(X);Qd=s(tt,"If you have access to your own GPU or are subscribed to a Google Colab paid plan, you can increase "),Ks=o(tt,"CODE",{});var Wy=r(Ks);Hd=s(Wy,"max_steps"),Wy.forEach(a),Dd=s(tt,` to 4000 steps
to improve the WER further by training for more steps. Training for 4000 steps will take approximately 3-5 hours depending
on your GPU and yield WER results approximately 3% lower than training for 500 steps. If you decide to train for 4000 steps,
we also recommend changing the learning rate scheduler to a `),en=o(tt,"EM",{});var Cy=r(en);qd=s(Cy,"linear"),Cy.forEach(a),Pd=s(tt," schedule (set "),tn=o(tt,"CODE",{});var Gy=r(tn);Od=s(Gy,'lr_scheduler_type="linear"'),Gy.forEach(a),Ld=s(tt,`), as this will
yield an additional performance boost over long training runs.`),tt.forEach(a),cr=c(e),C=o(e,"P",{});var ne=r(C);Kd=s(ne,"The results could likely be improved further by optimising the training hyperparameters, such as "),an=o(ne,"EM",{});var $y=r(an);eu=s($y,"learning rate"),$y.forEach(a),tu=s(ne,` and
`),ln=o(ne,"EM",{});var Zy=r(ln);au=s(Zy,"dropout"),Zy.forEach(a),lu=s(ne,", and using a larger pre-trained checkpoint ("),sn=o(ne,"CODE",{});var By=r(sn);su=s(By,"medium"),By.forEach(a),nu=s(ne," or "),nn=o(ne,"CODE",{});var Ay=r(nn);ou=s(Ay,"large"),Ay.forEach(a),ru=s(ne,"). We leave this as an exercise to the reader."),ne.forEach(a),dr=c(e),ye=o(e,"H2",{class:!0});var Qr=r(ye);Qe=o(Qr,"A",{id:!0,class:!0,href:!0});var Ny=r(Qe);on=o(Ny,"SPAN",{});var Ry=r(on);f(la.$$.fragment,Ry),Ry.forEach(a),Ny.forEach(a),iu=c(Qr),rn=o(Qr,"SPAN",{});var Xy=r(rn);pu=s(Xy,"Sharing Your Model"),Xy.forEach(a),Qr.forEach(a),ur=c(e),V=o(e,"P",{});var at=r(V);hu=s(at,"You can now share this model with anyone using the link on the Hub. They can load it with the identifier "),pn=o(at,"CODE",{});var Vy=r(pn);cu=s(Vy,'"your-username/the-name-you-picked"'),Vy.forEach(a),du=s(at,`
directly into the `),hn=o(at,"CODE",{});var xy=r(hn);uu=s(xy,"pipeline()"),xy.forEach(a),fu=s(at," object. For instance, to load the fine-tuned checkpoint "),sa=o(at,"A",{href:!0,rel:!0});var Sy=r(sa);mu=s(Sy,"\u201Csanchit-gandhi/whisper-small-dv\u201D"),Sy.forEach(a),yu=s(at,":"),at.forEach(a),fr=c(e),f(na.$$.fragment,e),mr=c(e),Me=o(e,"H2",{class:!0});var Hr=r(Me);He=o(Hr,"A",{id:!0,class:!0,href:!0});var Fy=r(He);cn=o(Fy,"SPAN",{});var Yy=r(cn);f(oa.$$.fragment,Yy),Yy.forEach(a),Fy.forEach(a),Mu=c(Hr),dn=o(Hr,"SPAN",{});var zy=r(dn);wu=s(zy,"Conclusion"),zy.forEach(a),Hr.forEach(a),yr=c(e),De=o(e,"P",{});var Dr=r(De);gu=s(Dr,`In this section, we covered a step-by-step guide on fine-tuning the Whisper model for speech recognition \u{1F917} Datasets,
Transformers and the Hugging Face Hub. We first loaded the Dhivehi subset of the Common Voice 13 dataset and pre-processed
it by computing log-mel spectrograms and tokenising the text. We then defined a data collator, evaluation metric and
training arguments, before using the \u{1F917} Trainer to train and evaluate our model. We finished by uploading the fine-tuned
model to the Hugging Face Hub, and showcased how to share and use it with the `),un=o(Dr,"CODE",{});var Qy=r(un);bu=s(Qy,"pipeline()"),Qy.forEach(a),Ju=s(Dr," class."),Dr.forEach(a),Mr=c(e),qe=o(e,"P",{});var qr=r(qe);Tu=s(qr,`If you followed through to this point, you should now have a fine-tuned checkpoint for speech recognition, well done! \u{1F973}
Even more importantly, you\u2019re equipped with all the tools you need to fine-tune the Whisper model on any speech recognition
dataset or domain. So what are you waiting for! Pick one of the datasets covered in the section `),Da=o(qr,"A",{href:!0});var Hy=r(Da);vu=s(Hy,"Choosing a Dataset"),Hy.forEach(a),Uu=s(qr,`
or select a dataset of your own, and see whether you can get state-of-the-art performance! The leaderboard is waiting for you\u2026`),qr.forEach(a),this.h()},h(){d(b,"name","hf:doc:metadata"),d(b,"content",JSON.stringify(lM)),d(we,"id","finetuning-the-asr-model"),d(we,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(we,"href","#finetuning-the-asr-model"),d(G,"class","relative group"),d(ge,"id","prepare-environment"),d(ge,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ge,"href","#prepare-environment"),d(oe,"class","relative group"),d(nt,"href","https://huggingface.co/"),d(nt,"rel","nofollow"),d(ot,"href","https://huggingface.co/settings/tokens"),d(ot,"rel","nofollow"),d(Te,"id","load-dataset"),d(Te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Te,"href","#load-dataset"),d(re,"class","relative group"),d(ct,"href","https://huggingface.co/datasets/mozilla-foundation/common_voice_13_0"),d(ct,"rel","nofollow"),d(Ue,"id","feature-extractor-tokenizer-and-processor"),d(Ue,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ue,"href","#feature-extractor-tokenizer-and-processor"),d(ie,"class","relative group"),d(yt,"href","https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperFeatureExtractor"),d(yt,"rel","nofollow"),d(Mt,"href","https://huggingface.co/docs/transformers/main/model_doc/whisper#transformers.WhisperTokenizer"),d(Mt,"rel","nofollow"),d(wt,"href","https://huggingface.co/docs/transformers/model_doc/whisper#transformers.WhisperProcessor"),d(wt,"rel","nofollow"),d(je,"id","preprocess-the-data"),d(je,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(je,"href","#preprocess-the-data"),d(pe,"class","relative group"),d(Ut,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.cast_column"),d(Ut,"rel","nofollow"),d(We,"id","training-and-evaluation"),d(We,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(We,"href","#training-and-evaluation"),d(he,"class","relative group"),d(Zt,"href","https://huggingface.co/transformers/master/main_classes/trainer.html?highlight=trainer"),d(Zt,"rel","nofollow"),d(Ge,"id","define-a-data-collator"),d(Ge,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ge,"href","#define-a-data-collator"),d(ce,"class","relative group"),d(Ze,"id","evaluation-metrics"),d(Ze,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ze,"href","#evaluation-metrics"),d(de,"class","relative group"),d(Ea,"href","evaluation"),d(Ae,"id","load-a-pretrained-checkpoint"),d(Ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ae,"href","#load-a-pretrained-checkpoint"),d(ue,"class","relative group"),d(Yt,"href","https://huggingface.co/docs/transformers/v4.18.0/en/performance#gradient-checkpointing"),d(Yt,"rel","nofollow"),d(Ne,"id","define-the-training-configuration"),d(Ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ne,"href","#define-the-training-configuration"),d(fe,"class","relative group"),d(Ht,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.Seq2SeqTrainingArguments"),d(Ht,"rel","nofollow"),d(xe,"id","training"),d(xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(xe,"href","#training"),d(me,"class","relative group"),d(Lt,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.Seq2SeqTrainingArguments.gradient_accumulation_steps"),d(Lt,"rel","nofollow"),d($a,"align","center"),d(Za,"align","center"),d(Ba,"align","center"),d(Aa,"align","center"),d(Na,"align","center"),d(Ra,"align","center"),d(Xa,"align","center"),d(Va,"align","center"),d(xa,"align","center"),d(Sa,"align","center"),d(Fa,"align","center"),d(Ya,"align","center"),d(Kt,"href","https://huggingface.co/spaces/autoevaluate/leaderboards?dataset=mozilla-foundation%2Fcommon_voice_13_0&only_verified=0&task=automatic-speech-recognition&config=dv&split=test&metric=wer"),d(Kt,"rel","nofollow"),d(ea,"href","https://huggingface.co/openai/whisper-small"),d(ea,"rel","nofollow"),d(Qe,"id","sharing-your-model"),d(Qe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Qe,"href","#sharing-your-model"),d(ye,"class","relative group"),d(sa,"href","https://huggingface.co/sanchit-gandhi/whisper-small-dv"),d(sa,"rel","nofollow"),d(He,"id","conclusion"),d(He,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(He,"href","#conclusion"),d(Me,"class","relative group"),d(Da,"href","choosing_dataset")},m(e,i){t(document.head,b),p(e,J,i),p(e,G,i),t(G,we),t(we,sl),m(lt,sl,null),t(G,Pr),t(G,nl),t(nl,Or),p(e,mn,i),p(e,pa,i),t(pa,Lr),p(e,yn,i),p(e,ha,i),t(ha,Kr),p(e,Mn,i),p(e,ca,i),t(ca,ei),p(e,wn,i),p(e,da,i),t(da,ti),p(e,gn,i),p(e,oe,i),t(oe,ge),t(ge,ol),m(st,ol,null),t(oe,ai),t(oe,rl),t(rl,li),p(e,bn,i),p(e,be,i),t(be,si),t(be,nt),t(nt,ni),t(be,oi),p(e,Jn,i),p(e,Z,i),t(Z,il),t(il,ri),t(Z,ii),t(Z,pl),t(pl,pi),t(Z,hi),t(Z,hl),t(hl,ci),t(Z,di),t(Z,cl),t(cl,ui),p(e,Tn,i),p(e,Je,i),t(Je,fi),t(Je,ot),t(ot,mi),t(Je,yi),p(e,vn,i),m(rt,e,i),p(e,Un,i),p(e,ua,i),t(ua,dl),t(dl,Mi),p(e,jn,i),m(it,e,i),p(e,_n,i),p(e,re,i),t(re,Te),t(Te,ul),m(pt,ul,null),t(re,wi),t(re,fl),t(fl,gi),p(e,En,i),p(e,ht,i),t(ht,ct),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me,He),t(He,cn),m(oa,cn,null),t(Me,Mu),t(Me,dn),t(dn,wu),p(e,yr,i),p(e,De,i),t(De,gu),t(De,un),t(un,bu),t(De,Ju),p(e,Mr,i),p(e,qe,i),t(qe,Tu),t(qe,Da),t(Da,vu),t(qe,Uu),wr=!0},p(e,[i]){const ra={};i&2&&(ra.$$scope={dirty:i,ctx:e}),ve.$set(ra);const fn={};i&2&&(fn.$$scope={dirty:i,ctx:e}),Xe.$set(fn)},i(e){wr||(y(lt.$$.fragment,e),y(st.$$.fragment,e),y(rt.$$.fragment,e),y(it.$$.fragment,e),y(pt.$$.fragment,e),y(dt.$$.fragment,e),y(ut.$$.fragment,e),y(ve.$$.fragment,e),y(ft.$$.fragment,e),y(mt.$$.fragment,e),y(gt.$$.fragment,e),y(bt.$$.fragment,e),y(Jt.$$.fragment,e),y(Tt.$$.fragment,e),y(vt.$$.fragment,e),y(jt.$$.fragment,e),y(Et.$$.fragment,e),y(It.$$.fragment,e),y(kt.$$.fragment,e),y(Wt.$$.fragment,e),y(Ct.$$.fragment,e),y(Gt.$$.fragment,e),y($t.$$.fragment,e),y(At.$$.fragment,e),y(Nt.$$.fragment,e),y(Rt.$$.fragment,e),y(Xt.$$.fragment,e),y(Vt.$$.fragment,e),y(xt.$$.fragment,e),y(St.$$.fragment,e),y(Ft.$$.fragment,e),y(zt.$$.fragment,e),y(Qt.$$.fragment,e),y(Dt.$$.fragment,e),y(Xe.$$.fragment,e),y(qt.$$.fragment,e),y(Pt.$$.fragment,e),y(Ot.$$.fragment,e),y(ta.$$.fragment,e),y(aa.$$.fragment,e),y(la.$$.fragment,e),y(na.$$.fragment,e),y(oa.$$.fragment,e),wr=!0)},o(e){M(lt.$$.fragment,e),M(st.$$.fragment,e),M(rt.$$.fragment,e),M(it.$$.fragment,e),M(pt.$$.fragment,e),M(dt.$$.fragment,e),M(ut.$$.fragment,e),M(ve.$$.fragment,e),M(ft.$$.fragment,e),M(mt.$$.fragment,e),M(gt.$$.fragment,e),M(bt.$$.fragment,e),M(Jt.$$.fragment,e),M(Tt.$$.fragment,e),M(vt.$$.fragment,e),M(jt.$$.fragment,e),M(Et.$$.fragment,e),M(It.$$.fragment,e),M(kt.$$.fragment,e),M(Wt.$$.fragment,e),M(Ct.$$.fragment,e),M(Gt.$$.fragment,e),M($t.$$.fragment,e),M(At.$$.fragment,e),M(Nt.$$.fragment,e),M(Rt.$$.fragment,e),M(Xt.$$.fragment,e),M(Vt.$$.fragment,e),M(xt.$$.fragment,e),M(St.$$.fragment,e),M(Ft.$$.fragment,e),M(zt.$$.fragment,e),M(Qt.$$.fragment,e),M(Dt.$$.fragment,e),M(Xe.$$.fragment,e),M(qt.$$.fragment,e),M(Pt.$$.fragment,e),M(Ot.$$.fragment,e),M(ta.$$.fragment,e),M(aa.$$.fragment,e),M(la.$$.fragment,e),M(na.$$.fragment,e),M(oa.$$.fragment,e),wr=!1},d(e){a(b),e&&a(J),e&&a(G),w(lt),e&&a(mn),e&&a(pa),e&&a(yn),e&&a(ha),e&&a(Mn),e&&a(ca),e&&a(wn),e&&a(da),e&&a(gn),e&&a(oe),w(st),e&&a(bn),e&&a(be),e&&a(Jn),e&&a(Z),e&&a(Tn),e&&a(Je),e&&a(vn),w(rt,e),e&&a(Un),e&&a(ua),e&&a(jn),w(it,e),e&&a(_n),e&&a(re),w(pt),e&&a(En),e&&a(ht),e&&a(In),e&&a(B),e&&a(kn),w(dt,e),e&&a(Wn),e&&a(fa),e&&a(Cn),w(ut,e),e&&a(Gn),w(ve,e),e&&a($n),e&&a(_),e&&a(Zn),w(ft,e),e&&a(Bn),e&&a(ie),w(mt),e&&a(An),e&&a(ma),e&&a(Nn),e&&a(z),e&&a(Rn),e&&a(A),e&&a(Xn),e&&a(T),e&&a(Vn),e&&a(ya),e&&a(xn),w(gt,e),e&&a(Sn),e&&a(Ma),e&&a(Fn),e&&a(wa),e&&a(Yn),e&&a(Q),e&&a(zn),e&&a(H),e&&a(Qn),w(bt,e),e&&a(Hn),e&&a(D),e&&a(Dn),e&&a(pe),w(Jt),e&&a(qn),e&&a(_e),e&&a(Pn),w(Tt,e),e&&a(On),e&&a(ga),e&&a(Ln),w(vt,e),e&&a(Kn),e&&a(Ee),e&&a(eo),e&&a(Ie),e&&a(to),w(jt,e),e&&a(ao),e&&a(ba),e&&a(lo),e&&a(q),e&&a(so),w(Et,e),e&&a(no),e&&a(P),e&&a(oo),w(It,e),e&&a(ro),e&&a(O),e&&a(io),w(kt,e),e&&a(po),e&&a(ke),e&&a(ho),w(Wt,e),e&&a(co),e&&a(Ja),e&&a(uo),w(Ct,e),e&&a(fo),e&&a(Ta),e&&a(mo),w(Gt,e),e&&a(yo),e&&a(va),e&&a(Mo),e&&a(he),w($t),e&&a(wo),e&&a(Ce),e&&a(go),e&&a(N),e&&a(bo),e&&a(Ua),e&&a(Jo),e&&a(ce),w(At),e&&a(To),e&&a(E),e&&a(vo),e&&a(I),e&&a(Uo),e&&a(k),e&&a(jo),e&&a($e),e&&a(_o),w(Nt,e),e&&a(Eo),e&&a(ja),e&&a(Io),w(Rt,e),e&&a(ko),e&&a(_a),e&&a(Wo),e&&a(de),w(Xt),e&&a(Co),e&&a(Be),e&&a(Go),e&&a(Ia),e&&a($o),w(Vt,e),e&&a(Zo),e&&a(W),e&&a(Bo),w(xt,e),e&&a(Ao),e&&a(ue),w(St),e&&a(No),e&&a(ka),e&&a(Ro),w(Ft,e),e&&a(Xo),e&&a(v),e&&a(Vo),w(zt,e),e&&a(xo),e&&a(fe),w(Qt),e&&a(So),e&&a(Re),e&&a(Fo),w(Dt,e),e&&a(Yo),w(Xe,e),e&&a(zo),e&&a(Ve),e&&a(Qo),w(qt,e),e&&a(Ho),e&&a(Wa),e&&a(Do),e&&a(me),w(Pt),e&&a(qo),e&&a(Ca),e&&a(Po),w(Ot,e),e&&a(Oo),e&&a(R),e&&a(Lo),e&&a(Ga),e&&a(Ko),e&&a(Se),e&&a(er),e&&a(za),e&&a(tr),e&&a(Fe),e&&a(ar),e&&a(Ye),e&&a(lr),e&&a(L),e&&a(sr),e&&a(Qa),e&&a(nr),w(ta,e),e&&a(or),e&&a(ze),e&&a(rr),w(aa,e),e&&a(ir),e&&a(K),e&&a(pr),e&&a(Ha),e&&a(hr),e&&a(X),e&&a(cr),e&&a(C),e&&a(dr),e&&a(ye),w(la),e&&a(ur),e&&a(V),e&&a(fr),w(na,e),e&&a(mr),e&&a(Me),w(oa),e&&a(yr),e&&a(De),e&&a(Mr),e&&a(qe)}}}const lM={local:"finetuning-the-asr-model",sections:[{local:"prepare-environment",title:"Prepare Environment"},{local:"load-dataset",title:"Load Dataset"},{local:"feature-extractor-tokenizer-and-processor",title:"Feature Extractor, Tokenizer and Processor"},{local:"preprocess-the-data",title:"Pre-Process the Data"},{local:"training-and-evaluation",sections:[{local:"define-a-data-collator",title:"Define a Data Collator"},{local:"evaluation-metrics",title:"Evaluation Metrics"},{local:"load-a-pretrained-checkpoint",title:"Load a Pre-Trained Checkpoint"}],title:"Training and Evaluation"},{local:"define-the-training-configuration",sections:[{local:"training",title:"Training"}],title:"Define the Training Configuration"},{local:"sharing-your-model",title:"Sharing Your Model"},{local:"conclusion",title:"Conclusion"}],title:"Fine-tuning the ASR model"};function sM(ia){return Ky(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pM extends qy{constructor(b){super();Py(this,b,sM,aM,Oy,{})}}export{pM as default,lM as metadata};
