import{S as zu,i as Du,s as Yu,e as o,k as c,w as M,t as l,M as Vu,c as r,d as t,m as u,a as i,x as f,h as n,b as h,N as Fu,G as s,g as p,y as m,q as y,o as w,B as T,v as Su}from"../../chunks/vendor-hf-doc-builder.js";import{T as Ya}from"../../chunks/Tip-hf-doc-builder.js";import{I as Ge}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as j}from"../../chunks/CodeBlock-hf-doc-builder.js";function Xu(R){let d,U;return{c(){d=o("p"),U=l(`One of the recordings in GTZAN is corrupted, so it\u2019s been removed from the dataset. That\u2019s why we have 999 examples
instead of 1,000.`)},l(J){d=r(J,"P",{});var g=i(d);U=n(g,`One of the recordings in GTZAN is corrupted, so it\u2019s been removed from the dataset. That\u2019s why we have 999 examples
instead of 1,000.`),g.forEach(t)},m(J,g){p(J,d,g),s(d,U)},d(J){J&&t(d)}}}function Hu(R){let d,U;return{c(){d=o("p"),U=l(`Note how we\u2019ve passed the sampling rate of our audio data to our feature extractor. This is good practice, as the feature
extractor performs a check under-the-hood to make sure the sampling rate of our audio data matches the sampling rate
expected by the model. If the sampling rate of our audio data did not match the sampling rate of our model, we\u2019d need to
up-sample or down-sample the audio data to the correct sampling rate.`)},l(J){d=r(J,"P",{});var g=i(d);U=n(g,`Note how we\u2019ve passed the sampling rate of our audio data to our feature extractor. This is good practice, as the feature
extractor performs a check under-the-hood to make sure the sampling rate of our audio data matches the sampling rate
expected by the model. If the sampling rate of our audio data did not match the sampling rate of our model, we\u2019d need to
up-sample or down-sample the audio data to the correct sampling rate.`),g.forEach(t)},m(J,g){p(J,d,g),s(d,U)},d(J){J&&t(d)}}}function qu(R){let d;return{c(){d=l("If you exhaust your device's RAM executing the above code, you can adjust the batch parameters to reduce the peak\n    RAM usage. In particular, the following two arguments can be modified:\n    * `batch_size`: defaults to 1000, but set to 100 above. Try reducing by a factor of 2 again to 50\n    * `writer_batch_size`: defaults to 1000. Try reducing it to 500, and if that doesn't work, then reduce it by a factor of 2 again to 250")},l(U){d=n(U,"If you exhaust your device's RAM executing the above code, you can adjust the batch parameters to reduce the peak\n    RAM usage. In particular, the following two arguments can be modified:\n    * `batch_size`: defaults to 1000, but set to 100 above. Try reducing by a factor of 2 again to 50\n    * `writer_batch_size`: defaults to 1000. Try reducing it to 500, and if that doesn't work, then reduce it by a factor of 2 again to 250")},m(U,J){p(U,d,J)},d(U){U&&t(d)}}}function Ou(R){let d,U,J,g,N,C,S,Z;return{c(){d=o("p"),U=l("Here we have set "),J=o("code"),g=l("push_to_hub=True"),N=l(` to enable automatic upload of our fine-tuned checkpoints during training. Should you
not wish for your checkpoints to be uploaded to the Hub, you can set this to `),C=o("code"),S=l("False"),Z=l(".")},l(E){d=r(E,"P",{});var A=i(d);U=n(A,"Here we have set "),J=r(A,"CODE",{});var B=i(J);g=n(B,"push_to_hub=True"),B.forEach(t),N=n(A,` to enable automatic upload of our fine-tuned checkpoints during training. Should you
not wish for your checkpoints to be uploaded to the Hub, you can set this to `),C=r(A,"CODE",{});var H=i(C);S=n(H,"False"),H.forEach(t),Z=n(A,"."),A.forEach(t)},m(E,A){p(E,d,A),s(d,U),s(d,J),s(J,g),s(d,N),s(d,C),s(C,S),s(d,Z)},d(E){E&&t(d)}}}function Pu(R){let d,U,J,g,N,C,S,Z,E,A,B,H;return{c(){d=o("p"),U=l("Depending on your GPU, it is possible that you will encounter a CUDA "),J=o("code"),g=l('"out-of-memory"'),N=l(` error when you start training.
In this case, you can reduce the `),C=o("code"),S=l("batch_size"),Z=l(" incrementally by factors of 2 and employ "),E=o("a"),A=o("code"),B=l("gradient_accumulation_steps"),H=l(`
to compensate.`),this.h()},l(q){d=r(q,"P",{});var I=i(d);U=n(I,"Depending on your GPU, it is possible that you will encounter a CUDA "),J=r(I,"CODE",{});var X=i(J);g=n(X,'"out-of-memory"'),X.forEach(t),N=n(I,` error when you start training.
In this case, you can reduce the `),C=r(I,"CODE",{});var ue=i(C);S=n(ue,"batch_size"),ue.forEach(t),Z=n(I," incrementally by factors of 2 and employ "),E=r(I,"A",{href:!0,rel:!0});var O=i(E);A=r(O,"CODE",{});var Qt=i(A);B=n(Qt,"gradient_accumulation_steps"),Qt.forEach(t),O.forEach(t),H=n(I,`
to compensate.`),I.forEach(t),this.h()},h(){h(E,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments.gradient_accumulation_steps"),h(E,"rel","nofollow")},m(q,I){p(q,d,I),s(d,U),s(d,J),s(J,g),s(d,N),s(d,C),s(C,S),s(d,Z),s(d,E),s(E,A),s(A,B),s(d,H)},d(q){q&&t(d)}}}function Lu(R){let d,U,J,g,N,C,S,Z,E,A,B,H,q,I,X,ue,O,Qt,ws,to,Va,P,so,Qe,ao,lo,Ts,no,oo,Sa,Re,Xa,Rt,Js,ro,Ha,xe,qa,he,Oa,de,io,js,po,co,Pa,Fe,La,xt,Us,uo,Ka,ze,el,Ft,ho,tl,De,sl,zt,gs,Mo,al,Ye,ll,$,fo,Dt,mo,yo,bs,wo,To,Is,Jo,jo,Cs,Uo,go,nl,Ve,ol,Yt,As,bo,rl,Se,il,Me,Io,vs,Co,Ao,pl,Xe,cl,G,bp,ul,Vt,vo,hl,ne,fe,Es,He,Eo,ks,ko,dl,k,_o,qe,$o,Wo,Oe,No,Zo,_s,Bo,Go,$s,Qo,Ro,Pe,xo,Fo,Ml,Q,Ip,fl,oe,me,Ws,Le,zo,Ns,Do,ml,re,ye,Zs,Ke,Yo,Bs,Vo,yl,L,So,Gs,Xo,Ho,Qs,qo,Oo,wl,et,Tl,St,Po,Jl,tt,jl,Xt,Rs,Lo,Ul,st,gl,K,Ko,xs,er,tr,Fs,sr,ar,bl,at,Il,we,lr,zs,nr,or,Cl,lt,Al,Ht,Ds,rr,vl,nt,El,qt,ir,kl,Ot,pr,_l,Pt,cr,$l,Lt,ur,Wl,ee,hr,Ys,dr,Mr,Vs,fr,mr,Nl,Kt,yr,Zl,ot,Bl,es,Ss,wr,Gl,rt,Ql,ts,Tr,Rl,it,xl,ss,Xs,Jr,F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yJTJDJTIwJTIyYWxsJTIyKSUwQWd0emFu",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

gtzan = load_dataset(<span class="hljs-string">&quot;marsyas/gtzan&quot;</span>, <span class="hljs-string">&quot;all&quot;</span>)
gtzan`}}),xe=new j({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidmaWxlJyUyQyUyMCdhdWRpbyclMkMlMjAnZ2VucmUnJTVEJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjA5OTklMEElN0Qp",highlighted:`<span class="hljs-built_in">Dataset</span>({
    features: <span class="hljs-selector-attr">[<span class="hljs-string">&#x27;file&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;genre&#x27;</span>]</span>,
    num_rows: <span class="hljs-number">999</span>
})`}}),he=new Ya({props:{warning:!0,$$slots:{default:[Xu]},$$scope:{ctx:R}}}),Fe=new j({props:{code:"Z3R6YW4lMjAlM0QlMjBndHphbi50cmFpbl90ZXN0X3NwbGl0KHNlZWQlM0Q0MiUyQyUyMHNodWZmbGUlM0RUcnVlJTJDJTIwdGVzdF9zaXplJTNEMC4xKSUwQWd0emFu",highlighted:`gtzan = gtzan.train_test_split(seed=<span class="hljs-number">42</span>, shuffle=<span class="hljs-literal">True</span>, test_size=<span class="hljs-number">0.1</span>)
gtzan`}}),ze=new j({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2ZpbGUnJTJDJTIwJ2F1ZGlvJyUyQyUyMCdnZW5yZSclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDg5OSUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidmaWxlJyUyQyUyMCdhdWRpbyclMkMlMjAnZ2VucmUnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjAxMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;file&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;genre&#x27;</span>],
        num_rows: <span class="hljs-number">899</span>
    })
    test: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;file&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;genre&#x27;</span>],
        num_rows: <span class="hljs-number">100</span>
    })
})`}}),De=new j({props:{code:"Z3R6YW4lNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:'gtzan[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]'}}),Ye=new j({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZmlsZSUyMiUzQSUyMCUyMn4lMkYuY2FjaGUlMkZodWdnaW5nZmFjZSUyRmRhdGFzZXRzJTJGZG93bmxvYWRzJTJGZXh0cmFjdGVkJTJGZmEwNmNlNDYxMzBkMzQ2NzY4MzEwMGFjYTk0NWQ2ZGVhZmI2NDIzMTU3NjVhNzg0NDU2ZTFkODFjOTQ3MTVhOCUyRmdlbnJlcyUyRnBvcCUyRnBvcC4wMDA5OC53YXYlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJhdWRpbyUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBhdGglMjIlM0ElMjAlMjJ+JT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MjAlMjBkdHlwZSUzRGZsb2F0MzIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc2FtcGxpbmdfcmF0ZSUyMiUzQSUyMDIyMDUwJTJDJTBBJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIyZ2VucmUlMjIlM0ElMjA3JTJDJTBBJTdE",highlighted:`{
    <span class="hljs-string">&quot;file&quot;</span>: <span class="hljs-string">&quot;~/.cache/huggingface/datasets/downloads/extracted/fa06ce46130d3467683100aca945d6deafb642315765a784456e1d81c94715a8/genres/pop/pop.00098.wav&quot;</span>,
    <span class="hljs-string">&quot;audio&quot;</span>: {
        <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;~/.cache/huggingface/datasets/downloads/extracted/fa06ce46130d3467683100aca945d6deafb642315765a784456e1d81c94715a8/genres/pop/pop.00098.wav&quot;</span>,
        <span class="hljs-string">&quot;array&quot;</span>: array(
            [
                <span class="hljs-number">0.10720825</span>,
                <span class="hljs-number">0.16122437</span>,
                <span class="hljs-number">0.28585815</span>,
                ...,
                <span class="hljs-number">-0.22924805</span>,
                <span class="hljs-number">-0.20629883</span>,
                <span class="hljs-number">-0.11334229</span>,
            ],
            d<span class="hljs-keyword">type</span>=float32,
        ),
        <span class="hljs-string">&quot;sampling_rate&quot;</span>: <span class="hljs-number">22050</span>,
    },
    <span class="hljs-string">&quot;genre&quot;</span>: <span class="hljs-number">7</span>,
}`}}),Ve=new j({props:{code:"aWQybGFiZWxfZm4lMjAlM0QlMjBndHphbiU1QiUyMnRyYWluJTIyJTVELmZlYXR1cmVzJTVCJTIyZ2VucmUlMjIlNUQuaW50MnN0ciUwQWlkMmxhYmVsX2ZuKGd0emFuJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIyZ2VucmUlMjIlNUQp",highlighted:`id2label_fn = gtzan[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;genre&quot;</span>].int2str
id2label_fn(gtzan[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;genre&quot;</span>])`}}),Se=new j({props:{code:"J3BvcCc=",highlighted:'<span class="hljs-symbol">&#x27;pop</span>&#x27;'}}),Xe=new j({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQSUwQWRlZiUyMGdlbmVyYXRlX2F1ZGlvKCklM0ElMEElMjAlMjAlMjAlMjBleGFtcGxlJTIwJTNEJTIwZ3R6YW4lNUIlMjJ0cmFpbiUyMiU1RC5zaHVmZmxlKCklNUIwJTVEJTBBJTIwJTIwJTIwJTIwYXVkaW8lMjAlM0QlMjBleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjAoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXVkaW8lNUIlMjJzYW1wbGluZ19yYXRlJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXVkaW8lNUIlMjJhcnJheSUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCklMkMlMjBpZDJsYWJlbF9mbihleGFtcGxlJTVCJTIyZ2VucmUlMjIlNUQpJTBBJTBBJTBBd2l0aCUyMGdyLkJsb2NrcygpJTIwYXMlMjBkZW1vJTNBJTBBJTIwJTIwJTIwJTIwd2l0aCUyMGdyLkNvbHVtbigpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZm9yJTIwXyUyMGluJTIwcmFuZ2UoNCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhdWRpbyUyQyUyMGxhYmVsJTIwJTNEJTIwZ2VuZXJhdGVfYXVkaW8oKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dCUyMCUzRCUyMGdyLkF1ZGlvKGF1ZGlvJTJDJTIwbGFiZWwlM0RsYWJlbCklMEElMEFkZW1vLmxhdW5jaChkZWJ1ZyUzRFRydWUp",highlighted:`<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr


<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_audio</span>():
    example = gtzan[<span class="hljs-string">&quot;train&quot;</span>].shuffle()[<span class="hljs-number">0</span>]
    audio = example[<span class="hljs-string">&quot;audio&quot;</span>]
    <span class="hljs-keyword">return</span> (
        audio[<span class="hljs-string">&quot;sampling_rate&quot;</span>],
        audio[<span class="hljs-string">&quot;array&quot;</span>],
    ), id2label_fn(example[<span class="hljs-string">&quot;genre&quot;</span>])


<span class="hljs-keyword">with</span> gr.Blocks() <span class="hljs-keyword">as</span> demo:
    <span class="hljs-keyword">with</span> gr.Column():
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">4</span>):
            audio, label = generate_audio()
            output = gr.Audio(audio, label=label)

demo.launch(debug=<span class="hljs-literal">True</span>)`}}),He=new Ge({}),Le=new Ge({}),Ke=new Ge({}),et=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9GZWF0dXJlRXh0cmFjdG9yJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJudHUtc3BtbCUyRmRpc3RpbGh1YmVydCUyMiUwQWZlYXR1cmVfZXh0cmFjdG9yJTIwJTNEJTIwQXV0b0ZlYXR1cmVFeHRyYWN0b3IuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTIwZG9fbm9ybWFsaXplJTNEVHJ1ZSUyQyUyMHJldHVybl9hdHRlbnRpb25fbWFzayUzRFRydWUlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoFeatureExtractor

model_id = <span class="hljs-string">&quot;ntu-spml/distilhubert&quot;</span>
feature_extractor = AutoFeatureExtractor.from_pretrained(
    model_id, do_normalize=<span class="hljs-literal">True</span>, return_attention_mask=<span class="hljs-literal">True</span>
)`}}),tt=new j({props:{code:"c2FtcGxpbmdfcmF0ZSUyMCUzRCUyMGZlYXR1cmVfZXh0cmFjdG9yLnNhbXBsaW5nX3JhdGUlMEFzYW1wbGluZ19yYXRl",highlighted:`sampling_rate = feature_extractor.sampling_rate
sampling_rate`}}),st=new j({props:{code:"MTYwMDA=",highlighted:"16000"}}),at=new j({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwQXVkaW8lMEElMEFndHphbiUyMCUzRCUyMGd0emFuLmNhc3RfY29sdW1uKCUyMmF1ZGlvJTIyJTJDJTIwQXVkaW8oc2FtcGxpbmdfcmF0ZSUzRHNhbXBsaW5nX3JhdGUpKQ==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Audio

gtzan = gtzan.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=sampling_rate))`}}),lt=new j({props:{code:"Z3R6YW4lNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:'gtzan[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]'}}),nt=new j({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZmlsZSUyMiUzQSUyMCUyMn4lMkYuY2FjaGUlMkZodWdnaW5nZmFjZSUyRmRhdGFzZXRzJTJGZG93bmxvYWRzJTJGZXh0cmFjdGVkJTJGZmEwNmNlNDYxMzBkMzQ2NzY4MzEwMGFjYTk0NWQ2ZGVhZmI2NDIzMTU3NjVhNzg0NDU2ZTFkODFjOTQ3MTVhOCUyRmdlbnJlcyUyRnBvcCUyRnBvcC4wMDA5OC53YXYlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJhdWRpbyUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUy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IwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZHR5cGUlM0RmbG9hdDMyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnNhbXBsaW5nX3JhdGUlMjIlM0ElMjAxNjAwMCUyQyUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMmdlbnJlJTIyJTNBJTIwNyUyQyUwQSU3RA==",highlighted:`{
    <span class="hljs-string">&quot;file&quot;</span>: <span class="hljs-string">&quot;~/.cache/huggingface/datasets/downloads/extracted/fa06ce46130d3467683100aca945d6deafb642315765a784456e1d81c94715a8/genres/pop/pop.00098.wav&quot;</span>,
    <span class="hljs-string">&quot;audio&quot;</span>: {
        <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;~/.cache/huggingface/datasets/downloads/extracted/fa06ce46130d3467683100aca945d6deafb642315765a784456e1d81c94715a8/genres/pop/pop.00098.wav&quot;</span>,
        <span class="hljs-string">&quot;array&quot;</span>: array(
            [
                <span class="hljs-number">0.0873509</span>,
                <span class="hljs-number">0.20183384</span>,
                <span class="hljs-number">0.4790867</span>,
                ...,
                <span class="hljs-number">-0.18743178</span>,
                <span class="hljs-number">-0.23294401</span>,
                <span class="hljs-number">-0.13517427</span>,
            ],
            d<span class="hljs-keyword">type</span>=float32,
        ),
        <span class="hljs-string">&quot;sampling_rate&quot;</span>: <span class="hljs-number">16000</span>,
    },
    <span class="hljs-string">&quot;genre&quot;</span>: <span class="hljs-number">7</span>,
}`}}),ot=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBc2FtcGxlJTIwJTNEJTIwZ3R6YW4lNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQlNUIlMjJhdWRpbyUyMiU1RCUwQSUwQXByaW50KGYlMjJNZWFuJTNBJTIwJTdCbnAubWVhbihzYW1wbGUlNUInYXJyYXknJTVEKSUzQS4zJTdEJTJDJTIwVmFyaWFuY2UlM0ElMjAlN0JucC52YXIoc2FtcGxlJTVCJ2FycmF5JyU1RCklM0EuMyU3RCUyMik=",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

sample = gtzan[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>]

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Mean: <span class="hljs-subst">{np.mean(sample[<span class="hljs-string">&#x27;array&#x27;</span>]):<span class="hljs-number">.3</span>}</span>, Variance: <span class="hljs-subst">{np.var(sample[<span class="hljs-string">&#x27;array&#x27;</span>]):<span class="hljs-number">.3</span>}</span>&quot;</span>)`}}),rt=new j({props:{code:"TWVhbiUzQSUyMDAuMDAwMTg1JTJDJTIwVmFyaWFuY2UlM0ElMjAwLjA0OTM=",highlighted:'<span class="hljs-attribute">Mean</span>: <span class="hljs-number">0</span>.<span class="hljs-number">000185</span>, Variance: <span class="hljs-number">0</span>.<span class="hljs-number">0493</span>'}}),it=new j({props:{code:"aW5wdXRzJTIwJTNEJTIwZmVhdHVyZV9leHRyYWN0b3Ioc2FtcGxlJTVCJTIyYXJyYXklMjIlNUQlMkMlMjBzYW1wbGluZ19yYXRlJTNEc2FtcGxlJTVCJTIyc2FtcGxpbmdfcmF0ZSUyMiU1RCklMEElMEFwcmludChmJTIyaW5wdXRzJTIwa2V5cyUzQSUyMCU3Qmxpc3QoaW5wdXRzLmtleXMoKSklN0QlMjIpJTBBJTBBcHJpbnQoJTBBJTIwJTIwJTIwJTIwZiUyMk1lYW4lM0ElMjAlN0JucC5tZWFuKGlucHV0cyU1QidpbnB1dF92YWx1ZXMnJTVEKSUzQS4zJTdEJTJDJTIwVmFyaWFuY2UlM0ElMjAlN0JucC52YXIoaW5wdXRzJTVCJ2lucHV0X3ZhbHVlcyclNUQpJTNBLjMlN0QlMjIlMEEp",highlighted:`inputs = feature_extractor(sample[<span class="hljs-string">&quot;array&quot;</span>], sampling_rate=sample[<span class="hljs-string">&quot;sampling_rate&quot;</span>])

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;inputs keys: <span class="hljs-subst">{<span class="hljs-built_in">list</span>(inputs.keys())}</span>&quot;</span>)

<span class="hljs-built_in">print</span>(
    <span class="hljs-string">f&quot;Mean: <span class="hljs-subst">{np.mean(inputs[<span class="hljs-string">&#x27;input_values&#x27;</span>]):<span class="hljs-number">.3</span>}</span>, Variance: <span class="hljs-subst">{np.var(inputs[<span class="hljs-string">&#x27;input_values&#x27;</span>]):<span class="hljs-number">.3</span>}</span>&quot;</span>
)`}}),pt=new j({props:{code:"aW5wdXRzJTIwa2V5cyUzQSUyMCU1QidpbnB1dF92YWx1ZXMnJTJDJTIwJ2F0dGVudGlvbl9tYXNrJyU1RCUwQU1lYW4lM0ElMjAtNC41M2UtMDklMkMlMjBWYXJpYW5jZSUzQSUyMDEuMA==",highlighted:`<span class="hljs-attribute">inputs</span> keys:<span class="hljs-meta"> [&#x27;input_values&#x27;, &#x27;attention_mask&#x27;]</span>
<span class="hljs-attribute">Mean</span>: -<span class="hljs-number">4</span>.<span class="hljs-number">53</span>e-<span class="hljs-number">09</span>, Variance: <span class="hljs-number">1</span>.<span class="hljs-number">0</span>`}}),Te=new Ya({props:{warning:!0,$$slots:{default:[Hu]},$$scope:{ctx:R}}}),ut=new j({props:{code:"bWF4X2R1cmF0aW9uJTIwJTNEJTIwMzAuMCUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfZnVuY3Rpb24oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwYXVkaW9fYXJyYXlzJTIwJTNEJTIwJTVCeCU1QiUyMmFycmF5JTIyJTVEJTIwZm9yJTIweCUyMGluJTIwZXhhbXBsZXMlNUIlMjJhdWRpbyUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMGZlYXR1cmVfZXh0cmFjdG9yKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGF1ZGlvX2FycmF5cyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNhbXBsaW5nX3JhdGUlM0RmZWF0dXJlX2V4dHJhY3Rvci5zYW1wbGluZ19yYXRlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRGludChmZWF0dXJlX2V4dHJhY3Rvci5zYW1wbGluZ19yYXRlJTIwKiUyMG1heF9kdXJhdGlvbiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybl9hdHRlbnRpb25fbWFzayUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW5wdXRz",highlighted:`max_duration = <span class="hljs-number">30.0</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
    audio_arrays = [x[<span class="hljs-string">&quot;array&quot;</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;audio&quot;</span>]]
    inputs = feature_extractor(
        audio_arrays,
        sampling_rate=feature_extractor.sampling_rate,
        max_length=<span class="hljs-built_in">int</span>(feature_extractor.sampling_rate * max_duration),
        truncation=<span class="hljs-literal">True</span>,
        return_attention_mask=<span class="hljs-literal">True</span>,
    )
    <span class="hljs-keyword">return</span> inputs`}}),dt=new j({props:{code:"Z3R6YW5fZW5jb2RlZCUyMCUzRCUyMGd0emFuLm1hcCglMEElMjAlMjAlMjAlMjBwcmVwcm9jZXNzX2Z1bmN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwcmVtb3ZlX2NvbHVtbnMlM0QlNUIlMjJhdWRpbyUyMiUyQyUyMCUyMmZpbGUlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxMDAlMkMlMEElMjAlMjAlMjAlMjBudW1fcHJvYyUzRDElMkMlMEEpJTBBZ3R6YW5fZW5jb2RlZA==",highlighted:`gtzan_encoded = gtzan.<span class="hljs-built_in">map</span>(
    preprocess_function,
    remove_columns=[<span class="hljs-string">&quot;audio&quot;</span>, <span class="hljs-string">&quot;file&quot;</span>],
    batched=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">100</span>,
    num_proc=<span class="hljs-number">1</span>,
)
gtzan_encoded`}}),Mt=new j({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2dlbnJlJyUyQyUyMCdpbnB1dF92YWx1ZXMnJTJDJ2F0dGVudGlvbl9tYXNrJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwODk5JTBBJTIwJTIwJTIwJTIwJTdEKSUwQSUyMCUyMCUyMCUyMHRlc3QlM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2dlbnJlJyUyQyUyMCdpbnB1dF92YWx1ZXMnJTJDJ2F0dGVudGlvbl9tYXNrJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMTAwJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSU3RCk=",highlighted:`DatasetDict({
    train: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;genre&#x27;</span>, <span class="hljs-string">&#x27;input_values&#x27;</span>,<span class="hljs-string">&#x27;attention_mask&#x27;</span>],
        num_rows: <span class="hljs-number">899</span>
    })
    test: <span class="hljs-built_in">Dataset</span>({
        features: [<span class="hljs-string">&#x27;genre&#x27;</span>, <span class="hljs-string">&#x27;input_values&#x27;</span>,<span class="hljs-string">&#x27;attention_mask&#x27;</span>],
        num_rows: <span class="hljs-number">100</span>
    })
})`}}),Je=new Ya({props:{warning:!0,$$slots:{default:[qu]},$$scope:{ctx:R}}}),ft=new j({props:{code:"Z3R6YW5fZW5jb2RlZCUyMCUzRCUyMGd0emFuX2VuY29kZWQucmVuYW1lX2NvbHVtbiglMjJnZW5yZSUyMiUyQyUyMCUyMmxhYmVsJTIyKQ==",highlighted:'gtzan_encoded = gtzan_encoded.rename_column(<span class="hljs-string">&quot;genre&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>)'}}),mt=new j({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjBzdHIoaSklM0ElMjBpZDJsYWJlbF9mbihpKSUwQSUyMCUyMCUyMCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKGxlbihndHphbl9lbmNvZGVkJTVCJTIydHJhaW4lMjIlNUQuZmVhdHVyZXMlNUIlMjJsYWJlbCUyMiU1RC5uYW1lcykpJTBBJTdEJTBBbGFiZWwyaWQlMjAlM0QlMjAlN0J2JTNBJTIwayUyMGZvciUyMGslMkMlMjB2JTIwaW4lMjBpZDJsYWJlbC5pdGVtcygpJTdEJTBBJTBBaWQybGFiZWwlNUIlMjI3JTIyJTVE",highlighted:`id2label = {
    <span class="hljs-built_in">str</span>(i): id2label_fn(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>(gtzan_encoded[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;label&quot;</span>].names))
}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}

id2label[<span class="hljs-string">&quot;7&quot;</span>]`}}),yt=new j({props:{code:"J3BvcCc=",highlighted:'<span class="hljs-symbol">&#x27;pop</span>&#x27;'}}),wt=new Ge({}),Tt=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckF1ZGlvQ2xhc3NpZmljYXRpb24lMEElMEFudW1fbGFiZWxzJTIwJTNEJTIwbGVuKGlkMmxhYmVsKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQXVkaW9DbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfaWQlMkMlMEElMjAlMjAlMjAlMjBudW1fbGFiZWxzJTNEbnVtX2xhYmVscyUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEElMjAlMjAlMjAlMjBpZDJsYWJlbCUzRGlkMmxhYmVsJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForAudioClassification

num_labels = <span class="hljs-built_in">len</span>(id2label)

model = AutoModelForAudioClassification.from_pretrained(
    model_id,
    num_labels=num_labels,
    label2id=label2id,
    id2label=id2label,
)`}}),Ut=new j({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`}}),gt=new j({props:{code:"TG9naW4lMjBzdWNjZXNzZnVsJTBBWW91ciUyMHRva2VuJTIwaGFzJTIwYmVlbiUyMHNhdmVkJTIwdG8lMjAlMkZyb290JTJGLmh1Z2dpbmdmYWNlJTJGdG9rZW4=",highlighted:`Login successful
Your token has been saved to /root/.huggingface/token`}}),bt=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMF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m9yX2Jlc3RfbW9kZWwlM0QlMjJhY2N1cmFjeSUyMiUyQyUwQSUyMCUyMCUyMCUyMGZwMTYlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

model_name = model_id.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>]
batch_size = <span class="hljs-number">8</span>
gradient_accumulation_steps = <span class="hljs-number">1</span>
num_train_epochs = <span class="hljs-number">10</span>

training_args = TrainingArguments(
    <span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-gtzan&quot;</span>,
    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">5e-5</span>,
    per_device_train_batch_size=batch_size,
    gradient_accumulation_steps=gradient_accumulation_steps,
    per_device_eval_batch_size=batch_size,
    num_train_epochs=num_train_epochs,
    warmup_ratio=<span class="hljs-number">0.1</span>,
    logging_steps=<span class="hljs-number">5</span>,
    load_best_model_at_end=<span class="hljs-literal">True</span>,
    metric_for_best_model=<span class="hljs-string">&quot;accuracy&quot;</span>,
    fp16=<span class="hljs-literal">True</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`}}),be=new Ya({props:{warning:!0,$$slots:{default:[Ou]},$$scope:{ctx:R}}}),It=new j({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmFjY3VyYWN5JTIyKSUwQSUwQSUwQWRlZiUyMGNvbXB1dGVfbWV0cmljcyhldmFsX3ByZWQpJTNBJTBBJTIwJTIwJTIwJTIwJTIyJTIyJTIyQ29tcHV0ZXMlMjBhY2N1cmFjeSUyMG9uJTIwYSUyMGJhdGNoJTIwb2YlMjBwcmVkaWN0aW9ucyUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwbnAuYXJnbWF4KGV2YWxfcHJlZC5wcmVkaWN0aW9ucyUyQyUyMGF4aXMlM0QxKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEZXZhbF9wcmVkLmxhYmVsX2lkcyk=",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
    <span class="hljs-string">&quot;&quot;&quot;Computes accuracy on a batch of predictions&quot;&quot;&quot;</span>
    predictions = np.argmax(eval_pred.predictions, axis=<span class="hljs-number">1</span>)
    <span class="hljs-keyword">return</span> metric.compute(predictions=predictions, references=eval_pred.label_ids)`}}),Ct=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEZ3R6YW5fZW5jb2RlZCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEZ3R6YW5fZW5jb2RlZCU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0RmZWF0dXJlX2V4dHJhY3RvciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

trainer = Trainer(
    model,
    training_args,
    train_dataset=gtzan_encoded[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=gtzan_encoded[<span class="hljs-string">&quot;test&quot;</span>],
    tokenizer=feature_extractor,
    compute_metrics=compute_metrics,
)

trainer.train()`}}),Ce=new Ya({props:{warning:!0,$$slots:{default:[Pu]},$$scope:{ctx:R}}}),At=new j({props:{code:"JTdDJTIwVHJhaW5pbmclMjBMb3NzJTIwJTdDJTIwRXBvY2glMjAlN0MlMjBTdGVwJTIwJTdDJTIwVmFsaWRhdGlvbiUyMExvc3MlMjAlN0MlMjBBY2N1cmFjeSUyMCU3QyUwQSU3QyUzQS0tLS0tLS0tLS0tLS0lM0ElN0MlM0EtLS0tLSUzQSU3QyUzQS0tLS0lM0ElN0MlM0EtLS0tLS0tLS0tLS0tLS0lM0ElN0MlM0EtLS0tLS0tLSUzQSU3QyUwQSU3QyUyMDEuNzI5NyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUyMDEuMCUyMCUyMCUyMCU3QyUyMDExMyUyMCUyMCU3QyUyMDEuODAxMSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUyMDAuNDQlMjAlMjAlMjAlMjAlMjAlN0MlMEElN0MlMjAxLjI0JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdDJTIwMi4wJTIwJTIwJTIwJTdDJTIwMjI2JTIwJTIwJTdDJTIwMS4zMDQ1JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdDJTIwMC42NCUyMCUyMCUyMCUyMCUyMCU3QyUwQSU3QyUyMDAuOTgwNSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUyMDMuMCUyMCUyMCUyMCU3QyUyMDMzOSUyMCUyMCU3QyUyMDAuOTg4OCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU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TIwJTIwJTIwJTdDJTIwOS4wJTIwJTIwJTIwJTdDJTIwMTAxNyUyMCU3QyUyMDAuNTM1NSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUyMDAuODMlMjAlMjAlMjAlMjAlMjAlN0MlMEElN0MlMjAwLjExOTglMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0MlMjAxMC4wJTIwJTIwJTdDJTIwMTEzMCUyMCU3QyUyMDAuNTcxNiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUyMDAuODIlMjAlMjAlMjAlMjAlMjAlN0M=",highlighted:`|<span class="hljs-string"> Training Loss </span>|<span class="hljs-string"> Epoch </span>|<span class="hljs-string"> Step </span>|<span class="hljs-string"> Validation Loss </span>|<span class="hljs-string"> Accuracy </span>|
|<span class="hljs-string">:-------------:</span>|<span class="hljs-string">:-----:</span>|<span class="hljs-string">:----:</span>|<span class="hljs-string">:---------------:</span>|<span class="hljs-string">:--------:</span>|
|<span class="hljs-string"> 1.7297        </span>|<span class="hljs-string"> 1.0   </span>|<span class="hljs-string"> 113  </span>|<span class="hljs-string"> 1.8011          </span>|<span class="hljs-string"> 0.44     </span>|
|<span class="hljs-string"> 1.24          </span>|<span class="hljs-string"> 2.0   </span>|<span class="hljs-string"> 226  </span>|<span class="hljs-string"> 1.3045          </span>|<span class="hljs-string"> 0.64     </span>|
|<span class="hljs-string"> 0.9805        </span>|<span class="hljs-string"> 3.0   </span>|<span class="hljs-string"> 339  </span>|<span class="hljs-string"> 0.9888          </span>|<span class="hljs-string"> 0.7      </span>|
|<span class="hljs-string"> 0.6853        </span>|<span class="hljs-string"> 4.0   </span>|<span class="hljs-string"> 452  </span>|<span class="hljs-string"> 0.7508          </span>|<span class="hljs-string"> 0.79     </span>|
|<span class="hljs-string"> 0.4502        </span>|<span class="hljs-string"> 5.0   </span>|<span class="hljs-string"> 565  </span>|<span class="hljs-string"> 0.6224          </span>|<span class="hljs-string"> 0.81     </span>|
|<span class="hljs-string"> 0.3015        </span>|<span class="hljs-string"> 6.0   </span>|<span class="hljs-string"> 678  </span>|<span class="hljs-string"> 0.5411          </span>|<span class="hljs-string"> 0.83     </span>|
|<span class="hljs-string"> 0.2244        </span>|<span class="hljs-string"> 7.0   </span>|<span class="hljs-string"> 791  </span>|<span class="hljs-string"> 0.6293          </span>|<span class="hljs-string"> 0.78     </span>|
|<span class="hljs-string"> 0.3108        </span>|<span class="hljs-string"> 8.0   </span>|<span class="hljs-string"> 904  </span>|<span class="hljs-string"> 0.5857          </span>|<span class="hljs-string"> 0.81     </span>|
|<span class="hljs-string"> 0.1644        </span>|<span class="hljs-string"> 9.0   </span>|<span class="hljs-string"> 1017 </span>|<span class="hljs-string"> 0.5355          </span>|<span class="hljs-string"> 0.83     </span>|
|<span class="hljs-string"> 0.1198        </span>|<span class="hljs-string"> 10.0  </span>|<span class="hljs-string"> 1130 </span>|<span class="hljs-string"> 0.5716          </span>|<span class="hljs-string"> 0.82     </span>|`}}),Et=new j({props:{code:"a3dhcmdzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIyZGF0YXNldF90YWdzJTIyJTNBJTIwJTIybWFyc3lhcyUyRmd0emFuJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyZGF0YXNldCUyMiUzQSUyMCUyMkdUWkFOJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIybW9kZWxfbmFtZSUyMiUzQSUyMGYlMjIlN0Jtb2RlbF9uYW1lJTdELWZpbmV0dW5lZC1ndHphbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMmZpbmV0dW5lZF9mcm9tJTIyJTNBJTIwbW9kZWxfaWQlMkMlMEElMjAlMjAlMjAlMjAlMjJ0YXNrcyUyMiUzQSUyMCUyMmF1ZGlvLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTBBJTdE",highlighted:`kwargs = {
    <span class="hljs-string">&quot;dataset_tags&quot;</span>: <span class="hljs-string">&quot;marsyas/gtzan&quot;</span>,
    <span class="hljs-string">&quot;dataset&quot;</span>: <span class="hljs-string">&quot;GTZAN&quot;</span>,
    <span class="hljs-string">&quot;model_name&quot;</span>: <span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-gtzan&quot;</span>,
    <span class="hljs-string">&quot;finetuned_from&quot;</span>: model_id,
    <span class="hljs-string">&quot;tasks&quot;</span>: <span class="hljs-string">&quot;audio-classification&quot;</span>,
}`}}),kt=new j({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1YigqKmt3YXJncyk=",highlighted:"trainer.push_to_hub(**kwargs)"}}),$t=new Ge({}),Nt=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMHBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMCUyMmF1ZGlvLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTIwbW9kZWwlM0QlMjJzYW5jaGl0LWdhbmRoaSUyRmRpc3RpbGh1YmVydC1maW5ldHVuZWQtZ3R6YW4lMjIlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

pipe = pipeline(
    <span class="hljs-string">&quot;audio-classification&quot;</span>, model=<span class="hljs-string">&quot;sanchit-gandhi/distilhubert-finetuned-gtzan&quot;</span>
)`}}),Zt=new Ge({}),{c(){d=o("meta"),U=c(),J=o("h1"),g=o("a"),N=o("span"),M(C.$$.fragment),S=c(),Z=o("span"),E=l("Fine-tuning a model for music classification"),A=c(),B=o("p"),H=l(`In this section, we\u2019ll present a step-by-step guide on fine-tuning an encoder-only transformer model for music classification.
We\u2019ll use a lightweight model for this demonstration and fairly small dataset, meaning the code is runnable end-to-end
on any consumer grade GPU, including the T4 16GB GPU provided in the Google Colab free tier. The section includes various
tips that you can try should you have a smaller GPU and encounter memory issues along the way.`),q=c(),I=o("h2"),X=o("a"),ue=o("span"),M(O.$$.fragment),Qt=c(),ws=o("span"),to=l("The Dataset"),Va=c(),P=o("p"),so=l("To train our model, we\u2019ll use the "),Qe=o("a"),ao=l("GTZAN"),lo=l(` dataset, which is a popular
dataset of 1,000 songs for music genre classification. Each song is a 30-second clip from one of 10 genres of music,
spanning disco to metal. We can get the audio files and their corresponding labels from the Hugging Face Hub with the
`),Ts=o("code"),no=l("load_dataset()"),oo=l(" function from \u{1F917} Datasets:"),Sa=c(),M(Re.$$.fragment),Xa=c(),Rt=o("p"),Js=o("strong"),ro=l("Output:"),Ha=c(),M(xe.$$.fragment),qa=c(),M(he.$$.fragment),Oa=c(),de=o("p"),io=l(`GTZAN doesn\u2019t provide a predefined validation set, so we\u2019ll have to create one ourselves. The dataset is balanced across
genres, so we can use the `),js=o("code"),po=l("train_test_split()"),co=l(" method to quickly create a 90/10 split as follows:"),Pa=c(),M(Fe.$$.fragment),La=c(),xt=o("p"),Us=o("strong"),uo=l("Output:"),Ka=c(),M(ze.$$.fragment),el=c(),Ft=o("p"),ho=l("Great, now that we\u2019ve got our training and validation sets, let\u2019s take a look at one of the audio files:"),tl=c(),M(De.$$.fragment),sl=c(),zt=o("p"),gs=o("strong"),Mo=l("Output:"),al=c(),M(Ye.$$.fragment),ll=c(),$=o("p"),fo=l("As we saw in "),Dt=o("a"),mo=l("Unit 1"),yo=l(`, the audio files are represented as 1-dimensional NumPy arrays,
where the value of the array represents the amplitude at that timestep. For these songs, the sampling rate is 22,050 Hz,
meaning there are 22,050 amplitude values sampled per second. We\u2019ll have to keep this in mind when using a pretrained model
with a different sampling rate, converting the sampling rates ourselves to ensure they match. We can also see the genre
is represented as an integer, or `),bs=o("em"),wo=l("class label"),To=l(`, which is the format the model will make it\u2019s predictions in. Let\u2019s use the
`),Is=o("code"),Jo=l("int2str()"),jo=l(" method of the "),Cs=o("code"),Uo=l("genre"),go=l(" feature to map these integers to human-readable names:"),nl=c(),M(Ve.$$.fragment),ol=c(),Yt=o("p"),As=o("strong"),bo=l("Output:"),rl=c(),M(Se.$$.fragment),il=c(),Me=o("p"),Io=l(`This label looks correct, since it matches the filename of the audio file. Let\u2019s now listen to a few more examples by
using Gradio to create a simple interface with the `),vs=o("code"),Co=l("Blocks"),Ao=l(" API:"),pl=c(),M(Xe.$$.fragment),cl=c(),G=o("iframe"),ul=c(),Vt=o("p"),vo=l(`From these samples we can certainly hear the difference between genres, but can a transformer do this too? Let\u2019s train a
model to find out! First, we\u2019ll need to find a suitable pretrained model for this task. Let\u2019s see how we can do that.`),hl=c(),ne=o("h2"),fe=o("a"),Es=o("span"),M(He.$$.fragment),Eo=c(),ks=o("span"),ko=l("Picking a pretrained model for audio classification"),dl=c(),k=o("p"),_o=l(`To get started, let\u2019s pick a suitable pretrained model for audio classification. In this domain, pretraining is typically
carried out on large amounts of unlabeled audio data, using datasets like `),qe=o("a"),$o=l("LibriSpeech"),Wo=l(`
and `),Oe=o("a"),No=l("Voxpopuli"),Zo=l(`. The best way to find these models on the Hugging
Face Hub is to use the \u201CAudio Classification\u201D filter, as described in the previous section. Although models like Wav2Vec2 and
HuBERT are very popular, we\u2019ll use a model called `),_s=o("em"),Bo=l("DistilHuBERT"),Go=l(". This is a much smaller (or "),$s=o("em"),Qo=l("distilled"),Ro=l(") version of the "),Pe=o("a"),xo=l("HuBERT"),Fo=l(`
model, which trains around 73% faster, yet preserves most of the performance.`),Ml=c(),Q=o("iframe"),fl=c(),oe=o("h2"),me=o("a"),Ws=o("span"),M(Le.$$.fragment),zo=c(),Ns=o("span"),Do=l("From audio to machine learning features"),ml=c(),re=o("h2"),ye=o("a"),Zs=o("span"),M(Ke.$$.fragment),Yo=c(),Bs=o("span"),Vo=l("Preprocessing the data"),yl=c(),L=o("p"),So=l(`Similar to tokenization in NLP, audio and speech models require the input to be encoded in a format that the model
can process. In \u{1F917} Transformers, the conversion from audio to the input format is handled by the `),Gs=o("em"),Xo=l("feature extractor"),Ho=l(` of
the model. Similar to tokenizers, \u{1F917} Transformers provides a convenient `),Qs=o("code"),qo=l("AutoFeatureExtractor"),Oo=l(` class that can automatically
select the correct feature extractor for a given model. To see how we can process our audio files, let\u2019s begin by instantiating
the feature extractor for DistilHuBERT from the pre-trained checkpoint:`),wl=c(),M(et.$$.fragment),Tl=c(),St=o("p"),Po=l(`Since the sampling rate of the model and the dataset are different, we\u2019ll have to resample the audio file to 16,000
Hz before passing it to the feature extractor. We can do this by first obtaining the model\u2019s sample rate from the feature
extractor:`),Jl=c(),M(tt.$$.fragment),jl=c(),Xt=o("p"),Rs=o("strong"),Lo=l("Output:"),Ul=c(),M(st.$$.fragment),gl=c(),K=o("p"),Ko=l("Next, we resample the dataset using the "),xs=o("code"),er=l("cast_column()"),tr=l(" method and "),Fs=o("code"),sr=l("Audio"),ar=l(" feature from \u{1F917} Datasets:"),bl=c(),M(at.$$.fragment),Il=c(),we=o("p"),lr=l(`We can now check the first sample of the train-split of our dataset to verify that it is indeed at 16,000 Hz. \u{1F917} Datasets
will resample the audio file `),zs=o("em"),nr=l("on-the-fly"),or=l(" when we load each audio sample:"),Cl=c(),M(lt.$$.fragment),Al=c(),Ht=o("p"),Ds=o("strong"),rr=l("Output:"),vl=c(),M(nt.$$.fragment),El=c(),qt=o("p"),ir=l(`Great! We can see that the sampling rate has been downsampled to 16kHz. The array values are also different, as we\u2019ve
now only got approximately one amplitude value for every 1.5 that we had before.`),kl=c(),Ot=o("p"),pr=l(`A defining feature of Wav2Vec2 and HuBERT like models is that they accept a float array corresponding to the raw waveform
of the speech signal as an input. This is in contrast to other models, like Whisper, where we pre-process the raw audio waveform
to spectrogram format.`),_l=c(),Pt=o("p"),cr=l(`We mentioned that the audio data is represented as a 1-dimensional array, so it\u2019s already in the right format to be read
by the model (a set of continuous inputs at discrete time steps). So, what exactly does the feature extractor do?`),$l=c(),Lt=o("p"),ur=l(`Well, the audio data is in the right format, but we\u2019ve imposed no restrictions on the values it can take. For our model to
work optimally, we want to keep all the inputs within the same dynamic range. This is going to make sure we get a similar
range of activations and gradients for our samples, helping with stability and convergence during training.`),Wl=c(),ee=o("p"),hr=l("To do this, we "),Ys=o("em"),dr=l("normalise"),Mr=l(` our audio data, by rescaling each sample to zero mean and unit variance, a process called
`),Vs=o("em"),fr=l("feature scaling"),mr=l(". It\u2019s exactly this feature normalisation that our feature extractor performs!"),Nl=c(),Kt=o("p"),yr=l(`We can take a look at the feature extractor in operation by applying it to our first audio sample. First, let\u2019s compute
the mean and variance of our raw audio data:`),Zl=c(),M(ot.$$.fragment),Bl=c(),es=o("p"),Ss=o("strong"),wr=l("Output:"),Gl=c(),M(rt.$$.fragment),Ql=c(),ts=o("p"),Tr=l(`We can see that the mean is close to zero already, but the variance is closer to 0.05. If the variance for the sample was
larger, it could cause our model problems, since the dynamic range of the audio data would be very small and thus difficult to
separate. Let\u2019s apply the feature extractor and see what the outputs look like:`),Rl=c(),M(it.$$.fragment),xl=c(),ss=o("p"),Xs=o("strong"),Jr=l("Output:"),Fl=c(),M(pt.$$.fragment),zl=c(),_=o("p"),jr=l("Alright! Our feature extractor returns a dictionary of two arrays: "),Hs=o("code"),Ur=l("input_values"),gr=l(" and "),qs=o("code"),br=l("attention_mask"),Ir=l(". The "),Os=o("code"),Cr=l("input_values"),Ar=l(`
are the preprocessed audio inputs that we\u2019d pass to the HuBERT model. The `),ct=o("a"),Ps=o("code"),vr=l("attention_mask"),Er=l(`
is used when we process a `),Ls=o("em"),kr=l("batch"),_r=l(` of audio inputs at once - it is used to tell the model where we have padded inputs of
different lengths.`),Dl=c(),as=o("p"),$r=l(`We can see that the mean value is now very much closer to zero, and the variance bang-on one! This is exactly the form we
want our audio samples in prior to feeding them to the HuBERT model.`),Yl=c(),M(Te.$$.fragment),Vl=c(),te=o("p"),Wr=l(`Great, so now we know how to process our resampled audio files, the last thing to do is define a function that we can
apply to all the examples in the dataset. Since we expect the audio clips to be 30 seconds in length, we\u2019ll also
truncate any longer clips by using the `),Ks=o("code"),Nr=l("max_length"),Zr=l(" and "),ea=o("code"),Br=l("truncation"),Gr=l(" arguments of the feature extractor as follows:"),Sl=c(),M(ut.$$.fragment),Xl=c(),x=o("p"),Qr=l("With this function defined, we can now apply it to the dataset using the "),ht=o("a"),ta=o("code"),Rr=l("map()"),xr=l(`
method. The `),sa=o("code"),Fr=l(".map()"),zr=l(" method supports working with batches of examples, which we\u2019ll enable by setting "),aa=o("code"),Dr=l("batched=True"),Yr=l(`.
The default batch size is 1000, but we\u2019ll reduce it to 100 to ensure the peak RAM stays within a sensible range for
Google Colab\u2019s free tier:`),Hl=c(),M(dt.$$.fragment),ql=c(),ls=o("p"),la=o("strong"),Vr=l("Output:"),Ol=c(),M(Mt.$$.fragment),Pl=c(),M(Je.$$.fragment),Ll=c(),b=o("p"),Sr=l("To simplify the training, we\u2019ve removed the "),na=o("code"),Xr=l("audio"),Hr=l(" and "),oa=o("code"),qr=l("file"),Or=l(" columns from the dataset. The "),ra=o("code"),Pr=l("input_values"),Lr=l(` column contains
the encoded audio files, the `),ia=o("code"),Kr=l("attention_mask"),ei=l(` a binary mask of 0/1 values that indicate where we have padded the audio input,
and the `),pa=o("code"),ti=l("genre"),si=l(" column contains the corresponding labels (or targets). To enable the "),ca=o("code"),ai=l("Trainer"),li=l(` to process the class labels,
we need to rename the `),ua=o("code"),ni=l("genre"),oi=l(" column to "),ha=o("code"),ri=l("label"),ii=l(":"),Kl=c(),M(ft.$$.fragment),en=c(),F=o("p"),pi=l("Finally, we need to obtain the label mappings from the dataset. This mapping will take us from integer ids (e.g. "),da=o("code"),ci=l("7"),ui=l(`) to
human-readable class labels (e.g. `),Ma=o("code"),hi=l('"pop"'),di=l(`) and back again. In doing so, we can convert our model\u2019s integer id prediction
into human-readable format, enabling us to use the model in any downstream application. We can do this by using the `),fa=o("code"),Mi=l("int2str()"),fi=l(`
method as follows:`),tn=c(),M(mt.$$.fragment),sn=c(),M(yt.$$.fragment),an=c(),ns=o("p"),mi=l("OK, we\u2019ve now got a dataset that\u2019s ready for training! Let\u2019s take a look at how we can train a model on this dataset."),ln=c(),ie=o("h2"),je=o("a"),ma=o("span"),M(wt.$$.fragment),yi=c(),ya=o("span"),wi=l("Fine-tuning the model"),nn=c(),W=o("p"),Ti=l("To fine-tune the model, we\u2019ll use the "),wa=o("code"),Ji=l("Trainer"),ji=l(" class from \u{1F917} Transformers. As we\u2019ve seen in other chapters, the "),Ta=o("code"),Ui=l("Trainer"),gi=l(`
is a high-level API that is designed to handle the most common training scenarios. In this case, we\u2019ll use the `),Ja=o("code"),bi=l("Trainer"),Ii=l(`
to fine-tune the model on GTZAN. To do this, we\u2019ll first need to load a model for this task. We can do this by using the
`),ja=o("code"),Ci=l("AutoModelForAudioClassification"),Ai=l(` class, which will automatically add the appropriate classification head to our pretrained
DistilHuBERT model. Let\u2019s go ahead and instantiate the model:`),on=c(),M(Tt.$$.fragment),rn=c(),Ue=o("p"),vi=l("We strongly advise you to upload model checkpoints directly the "),Jt=o("a"),Ei=l("Hugging Face Hub"),ki=l(` while training.
The Hub provides:`),pn=c(),z=o("ul"),Ua=o("li"),_i=l("Integrated version control: you can be sure that no model checkpoint is lost during training."),$i=c(),ga=o("li"),Wi=l("Tensorboard logs: track important metrics over the course of training."),Ni=c(),ba=o("li"),Zi=l("Model cards: document what a model does and its intended use cases."),Bi=c(),Ia=o("li"),Gi=l("Community: an easy way to share and collaborate with the community! \u{1F917}"),cn=c(),ge=o("p"),Qi=l(`Linking the notebook to the Hub is straightforward - it simply requires entering your Hub authentication token when prompted.
Find your Hub authentication token `),jt=o("a"),Ri=l("here"),xi=l(":"),un=c(),M(Ut.$$.fragment),hn=c(),os=o("p"),Ca=o("strong"),Fi=l("Output:"),dn=c(),M(gt.$$.fragment),Mn=c(),rs=o("p"),zi=l(`The next step is to define the training arguments, including the batch size, gradient accumulation steps, number of
training epochs and learning rate:`),fn=c(),M(bt.$$.fragment),mn=c(),M(be.$$.fragment),yn=c(),is=o("p"),Di=l(`The last thing we need to do is define the metrics. Since the dataset is balanced, we\u2019ll use accuracy as our metric and
load it using the \u{1F917} Evaluate library:`),wn=c(),M(It.$$.fragment),Tn=c(),Ie=o("p"),Yi=l("We\u2019ve now got all the pieces! Let\u2019s instantiate the "),Aa=o("code"),Vi=l("Trainer"),Si=l(" and train the model:"),Jn=c(),M(Ct.$$.fragment),jn=c(),M(Ce.$$.fragment),Un=c(),ps=o("p"),va=o("strong"),Xi=l("Output:"),gn=c(),M(At.$$.fragment),bn=c(),Ae=o("p"),Hi=l(`Training will take approximately 1 hour depending on your GPU or the one allocated to the Google Colab. Our best
evaluation accuracy is 83% - not bad for just 10 epochs with 899 examples of training data! We could certainly improve
upon this result by training for more epochs, using regularisation techniques such as `),Ea=o("em"),qi=l("dropout"),Oi=l(`, or sub-diving each
audio example from 30s into 15s segments to use a more efficient data pre-processing strategy.`),In=c(),ve=o("p"),Pi=l(`The big question is how this compares to other music classification systems \u{1F914}
For that, we can view the `),vt=o("a"),Li=l("autoevaluate leaderboard"),Ki=l(`,
a leaderboard that categorises models by language and dataset, and subsequently ranks them according to their accuracy.`),Cn=c(),cs=o("p"),ep=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:`),An=c(),M(Et.$$.fragment),vn=c(),Ee=o("p"),tp=l("The training results can now be uploaded to the Hub. To do so, execute the "),ka=o("code"),sp=l(".push_to_hub"),ap=l(" command:"),En=c(),M(kt.$$.fragment),kn=c(),se=o("p"),lp=l("This will save the training logs and model weights under "),_a=o("code"),np=l('"your-username/distilhubert-finetuned-gtzan"'),op=l(`. For this example,
check out the upload at `),_t=o("a"),$a=o("code"),rp=l('"sanchit-gandhi/distilhubert-finetuned-gtzan"'),ip=l("."),_n=c(),pe=o("h2"),ke=o("a"),Wa=o("span"),M($t.$$.fragment),pp=c(),Na=o("span"),cp=l("Share Model"),$n=c(),D=o("p"),up=l("You can now share this model with anyone using the link on the Hub. They can load it with the identifier "),Za=o("code"),hp=l('"your-username/distilhubert-finetuned-gtzan"'),dp=l(`
directly into the `),Ba=o("code"),Mp=l("pipeline()"),fp=l(" class. For instance, to load the fine-tuned checkpoint "),Wt=o("a"),Ga=o("code"),mp=l('"sanchit-gandhi/distilhubert-finetuned-gtzan"'),yp=l(":"),Wn=c(),M(Nt.$$.fragment),Nn=c(),ce=o("h2"),_e=o("a"),Qa=o("span"),M(Zt.$$.fragment),wp=c(),Ra=o("span"),Tp=l("Conclusion"),Zn=c(),$e=o("p"),Jp=l(`In this section, we\u2019ve covered a step-by-step guide for fine-tuning the DistilHuBERT model for music classification. While
we focussed on the task of music classification and the GTZAN dataset, the steps presented here apply more generally to any
audio classification task - the same script can be used for spoken language audio classification tasks like keyword spotting
or language identification. You just need to swap out the dataset for one that corresponds to your task of interest! If
you\u2019re interested in fine-tuning other Hugging Face Hub models for audio classification, we encourage you to check out the
other `),Bt=o("a"),jp=l("examples"),Up=l(` in the \u{1F917}
Transformers repository.`),Bn=c(),us=o("p"),gp=l(`In the next section, we\u2019ll take the model that you just fine-tuned and build a music classification demo that you can share
on the Hugging Face Hub.`),this.h()},l(e){const a=Vu('[data-svelte="svelte-1phssyn"]',document.head);d=r(a,"META",{name:!0,content:!0}),a.forEach(t),U=u(e),J=r(e,"H1",{class:!0});var Gt=i(J);g=r(Gt,"A",{id:!0,class:!0,href:!0});var xa=i(g);N=r(xa,"SPAN",{});var Fa=i(N);f(C.$$.fragment,Fa),Fa.forEach(t),xa.forEach(t),S=u(Gt),Z=r(Gt,"SPAN",{});var za=i(Z);E=n(za,"Fine-tuning a model for music classification"),za.forEach(t),Gt.forEach(t),A=u(e),B=r(e,"P",{});var Da=i(B);H=n(Da,`In this section, we\u2019ll present a step-by-step guide on fine-tuning an encoder-only transformer model for music classification.
We\u2019ll use a lightweight model for this demonstration and fairly small dataset, meaning the code is runnable end-to-end
on any consumer grade GPU, including the T4 16GB GPU provided in the Google Colab free tier. The section includes various
tips that you can try should you have a smaller GPU and encounter memory issues along the way.`),Da.forEach(t),q=u(e),I=r(e,"H2",{class:!0});var Qn=i(I);X=r(Qn,"A",{id:!0,class:!0,href:!0});var Cp=i(X);ue=r(Cp,"SPAN",{});var Ap=i(ue);f(O.$$.fragment,Ap),Ap.forEach(t),Cp.forEach(t),Qt=u(Qn),ws=r(Qn,"SPAN",{});var vp=i(ws);to=n(vp,"The Dataset"),vp.forEach(t),Qn.forEach(t),Va=u(e),P=r(e,"P",{});var hs=i(P);so=n(hs,"To train our model, we\u2019ll use the "),Qe=r(hs,"A",{href:!0,rel:!0});var Ep=i(Qe);ao=n(Ep,"GTZAN"),Ep.forEach(t),lo=n(hs,` dataset, which is a popular
dataset of 1,000 songs for music genre classification. Each song is a 30-second clip from one of 10 genres of music,
spanning disco to metal. We can get the audio files and their corresponding labels from the Hugging Face Hub with the
`),Ts=r(hs,"CODE",{});var kp=i(Ts);no=n(kp,"load_dataset()"),kp.forEach(t),oo=n(hs," function from \u{1F917} Datasets:"),hs.forEach(t),Sa=u(e),f(Re.$$.fragment,e),Xa=u(e),Rt=r(e,"P",{});var _p=i(Rt);Js=r(_p,"STRONG",{});var $p=i(Js);ro=n($p,"Output:"),$p.forEach(t),_p.forEach(t),Ha=u(e),f(xe.$$.fragment,e),qa=u(e),f(he.$$.fragment,e),Oa=u(e),de=r(e,"P",{});var Rn=i(de);io=n(Rn,`GTZAN doesn\u2019t provide a predefined validation set, so we\u2019ll have to create one ourselves. The dataset is balanced across
genres, so we can use the `),js=r(Rn,"CODE",{});var Wp=i(js);po=n(Wp,"train_test_split()"),Wp.forEach(t),co=n(Rn," method to quickly create a 90/10 split as follows:"),Rn.forEach(t),Pa=u(e),f(Fe.$$.fragment,e),La=u(e),xt=r(e,"P",{});var Np=i(xt);Us=r(Np,"STRONG",{});var Zp=i(Us);uo=n(Zp,"Output:"),Zp.forEach(t),Np.forEach(t),Ka=u(e),f(ze.$$.fragment,e),el=u(e),Ft=r(e,"P",{});var Bp=i(Ft);ho=n(Bp,"Great, now that we\u2019ve got our training and validation sets, let\u2019s take a look at one of the audio files:"),Bp.forEach(t),tl=u(e),f(De.$$.fragment,e),sl=u(e),zt=r(e,"P",{});var Gp=i(zt);gs=r(Gp,"STRONG",{});var Qp=i(gs);Mo=n(Qp,"Output:"),Qp.forEach(t),Gp.forEach(t),al=u(e),f(Ye.$$.fragment,e),ll=u(e),$=r(e,"P",{});var ae=i($);fo=n(ae,"As we saw in "),Dt=r(ae,"A",{href:!0});var Rp=i(Dt);mo=n(Rp,"Unit 1"),Rp.forEach(t),yo=n(ae,`, the audio files are represented as 1-dimensional NumPy arrays,
where the value of the array represents the amplitude at that timestep. For these songs, the sampling rate is 22,050 Hz,
meaning there are 22,050 amplitude values sampled per second. We\u2019ll have to keep this in mind when using a pretrained model
with a different sampling rate, converting the sampling rates ourselves to ensure they match. We can also see the genre
is represented as an integer, or `),bs=r(ae,"EM",{});var xp=i(bs);wo=n(xp,"class label"),xp.forEach(t),To=n(ae,`, which is the format the model will make it\u2019s predictions in. Let\u2019s use the
`),Is=r(ae,"CODE",{});var Fp=i(Is);Jo=n(Fp,"int2str()"),Fp.forEach(t),jo=n(ae," method of the "),Cs=r(ae,"CODE",{});var zp=i(Cs);Uo=n(zp,"genre"),zp.forEach(t),go=n(ae," feature to map these integers to human-readable names:"),ae.forEach(t),nl=u(e),f(Ve.$$.fragment,e),ol=u(e),Yt=r(e,"P",{});var Dp=i(Yt);As=r(Dp,"STRONG",{});var Yp=i(As);bo=n(Yp,"Output:"),Yp.forEach(t),Dp.forEach(t),rl=u(e),f(Se.$$.fragment,e),il=u(e),Me=r(e,"P",{});var xn=i(Me);Io=n(xn,`This label looks correct, since it matches the filename of the audio file. Let\u2019s now listen to a few more examples by
using Gradio to create a simple interface with the `),vs=r(xn,"CODE",{});var Vp=i(vs);Co=n(Vp,"Blocks"),Vp.forEach(t),Ao=n(xn," API:"),xn.forEach(t),pl=u(e),f(Xe.$$.fragment,e),cl=u(e),G=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),i(G).forEach(t),ul=u(e),Vt=r(e,"P",{});var Sp=i(Vt);vo=n(Sp,`From these samples we can certainly hear the difference between genres, but can a transformer do this too? Let\u2019s train a
model to find out! First, we\u2019ll need to find a suitable pretrained model for this task. Let\u2019s see how we can do that.`),Sp.forEach(t),hl=u(e),ne=r(e,"H2",{class:!0});var Fn=i(ne);fe=r(Fn,"A",{id:!0,class:!0,href:!0});var Xp=i(fe);Es=r(Xp,"SPAN",{});var Hp=i(Es);f(He.$$.fragment,Hp),Hp.forEach(t),Xp.forEach(t),Eo=u(Fn),ks=r(Fn,"SPAN",{});var qp=i(ks);ko=n(qp,"Picking a pretrained model for audio classification"),qp.forEach(t),Fn.forEach(t),dl=u(e),k=r(e,"P",{});var Y=i(k);_o=n(Y,`To get started, let\u2019s pick a suitable pretrained model for audio classification. In this domain, pretraining is typically
carried out on large amounts of unlabeled audio data, using datasets like `),qe=r(Y,"A",{href:!0,rel:!0});var Op=i(qe);$o=n(Op,"LibriSpeech"),Op.forEach(t),Wo=n(Y,`
and `),Oe=r(Y,"A",{href:!0,rel:!0});var Pp=i(Oe);No=n(Pp,"Voxpopuli"),Pp.forEach(t),Zo=n(Y,`. The best way to find these models on the Hugging
Face Hub is to use the \u201CAudio Classification\u201D filter, as described in the previous section. Although models like Wav2Vec2 and
HuBERT are very popular, we\u2019ll use a model called `),_s=r(Y,"EM",{});var Lp=i(_s);Bo=n(Lp,"DistilHuBERT"),Lp.forEach(t),Go=n(Y,". This is a much smaller (or "),$s=r(Y,"EM",{});var Kp=i($s);Qo=n(Kp,"distilled"),Kp.forEach(t),Ro=n(Y,") version of the "),Pe=r(Y,"A",{href:!0,rel:!0});var ec=i(Pe);xo=n(ec,"HuBERT"),ec.forEach(t),Fo=n(Y,`
model, which trains around 73% faster, yet preserves most of the performance.`),Y.forEach(t),Ml=u(e),Q=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),i(Q).forEach(t),fl=u(e),oe=r(e,"H2",{class:!0});var zn=i(oe);me=r(zn,"A",{id:!0,class:!0,href:!0});var tc=i(me);Ws=r(tc,"SPAN",{});var sc=i(Ws);f(Le.$$.fragment,sc),sc.forEach(t),tc.forEach(t),zo=u(zn),Ns=r(zn,"SPAN",{});var ac=i(Ns);Do=n(ac,"From audio to machine learning features"),ac.forEach(t),zn.forEach(t),ml=u(e),re=r(e,"H2",{class:!0});var Dn=i(re);ye=r(Dn,"A",{id:!0,class:!0,href:!0});var lc=i(ye);Zs=r(lc,"SPAN",{});var nc=i(Zs);f(Ke.$$.fragment,nc),nc.forEach(t),lc.forEach(t),Yo=u(Dn),Bs=r(Dn,"SPAN",{});var oc=i(Bs);Vo=n(oc,"Preprocessing the data"),oc.forEach(t),Dn.forEach(t),yl=u(e),L=r(e,"P",{});var ds=i(L);So=n(ds,`Similar to tokenization in NLP, audio and speech models require the input to be encoded in a format that the model
can process. In \u{1F917} Transformers, the conversion from audio to the input format is handled by the `),Gs=r(ds,"EM",{});var rc=i(Gs);Xo=n(rc,"feature extractor"),rc.forEach(t),Ho=n(ds,` of
the model. Similar to tokenizers, \u{1F917} Transformers provides a convenient `),Qs=r(ds,"CODE",{});var ic=i(Qs);qo=n(ic,"AutoFeatureExtractor"),ic.forEach(t),Oo=n(ds,` class that can automatically
select the correct feature extractor for a given model. To see how we can process our audio files, let\u2019s begin by instantiating
the feature extractor for DistilHuBERT from the pre-trained checkpoint:`),ds.forEach(t),wl=u(e),f(et.$$.fragment,e),Tl=u(e),St=r(e,"P",{});var pc=i(St);Po=n(pc,`Since the sampling rate of the model and the dataset are different, we\u2019ll have to resample the audio file to 16,000
Hz before passing it to the feature extractor. We can do this by first obtaining the model\u2019s sample rate from the feature
extractor:`),pc.forEach(t),Jl=u(e),f(tt.$$.fragment,e),jl=u(e),Xt=r(e,"P",{});var cc=i(Xt);Rs=r(cc,"STRONG",{});var uc=i(Rs);Lo=n(uc,"Output:"),uc.forEach(t),cc.forEach(t),Ul=u(e),f(st.$$.fragment,e),gl=u(e),K=r(e,"P",{});var Ms=i(K);Ko=n(Ms,"Next, we resample the dataset using the "),xs=r(Ms,"CODE",{});var hc=i(xs);er=n(hc,"cast_column()"),hc.forEach(t),tr=n(Ms," method and "),Fs=r(Ms,"CODE",{});var dc=i(Fs);sr=n(dc,"Audio"),dc.forEach(t),ar=n(Ms," feature from \u{1F917} Datasets:"),Ms.forEach(t),bl=u(e),f(at.$$.fragment,e),Il=u(e),we=r(e,"P",{});var Yn=i(we);lr=n(Yn,`We can now check the first sample of the train-split of our dataset to verify that it is indeed at 16,000 Hz. \u{1F917} Datasets
will resample the audio file `),zs=r(Yn,"EM",{});var Mc=i(zs);nr=n(Mc,"on-the-fly"),Mc.forEach(t),or=n(Yn," when we load each audio sample:"),Yn.forEach(t),Cl=u(e),f(lt.$$.fragment,e),Al=u(e),Ht=r(e,"P",{});var fc=i(Ht);Ds=r(fc,"STRONG",{});var mc=i(Ds);rr=n(mc,"Output:"),mc.forEach(t),fc.forEach(t),vl=u(e),f(nt.$$.fragment,e),El=u(e),qt=r(e,"P",{});var yc=i(qt);ir=n(yc,`Great! We can see that the sampling rate has been downsampled to 16kHz. The array values are also different, as we\u2019ve
now only got approximately one amplitude value for every 1.5 that we had before.`),yc.forEach(t),kl=u(e),Ot=r(e,"P",{});var wc=i(Ot);pr=n(wc,`A defining feature of Wav2Vec2 and HuBERT like models is that they accept a float array corresponding to the raw waveform
of the speech signal as an input. This is in contrast to other models, like Whisper, where we pre-process the raw audio waveform
to spectrogram format.`),wc.forEach(t),_l=u(e),Pt=r(e,"P",{});var Tc=i(Pt);cr=n(Tc,`We mentioned that the audio data is represented as a 1-dimensional array, so it\u2019s already in the right format to be read
by the model (a set of continuous inputs at discrete time steps). So, what exactly does the feature extractor do?`),Tc.forEach(t),$l=u(e),Lt=r(e,"P",{});var Jc=i(Lt);ur=n(Jc,`Well, the audio data is in the right format, but we\u2019ve imposed no restrictions on the values it can take. For our model to
work optimally, we want to keep all the inputs within the same dynamic range. This is going to make sure we get a similar
range of activations and gradients for our samples, helping with stability and convergence during training.`),Jc.forEach(t),Wl=u(e),ee=r(e,"P",{});var fs=i(ee);hr=n(fs,"To do this, we "),Ys=r(fs,"EM",{});var jc=i(Ys);dr=n(jc,"normalise"),jc.forEach(t),Mr=n(fs,` our audio data, by rescaling each sample to zero mean and unit variance, a process called
`),Vs=r(fs,"EM",{});var Uc=i(Vs);fr=n(Uc,"feature scaling"),Uc.forEach(t),mr=n(fs,". It\u2019s exactly this feature normalisation that our feature extractor performs!"),fs.forEach(t),Nl=u(e),Kt=r(e,"P",{});var gc=i(Kt);yr=n(gc,`We can take a look at the feature extractor in operation by applying it to our first audio sample. First, let\u2019s compute
the mean and variance of our raw audio data:`),gc.forEach(t),Zl=u(e),f(ot.$$.fragment,e),Bl=u(e),es=r(e,"P",{});var bc=i(es);Ss=r(bc,"STRONG",{});var Ic=i(Ss);wr=n(Ic,"Output:"),Ic.forEach(t),bc.forEach(t),Gl=u(e),f(rt.$$.fragment,e),Ql=u(e),ts=r(e,"P",{});var Cc=i(ts);Tr=n(Cc,`We can see that the mean is close to zero already, but the variance is closer to 0.05. If the variance for the sample was
larger, it could cause our model problems, since the dynamic range of the audio data would be very small and thus difficult to
separate. Let\u2019s apply the feature extractor and see what the outputs look like:`),Cc.forEach(t),Rl=u(e),f(it.$$.fragment,e),xl=u(e),ss=r(e,"P",{});var Ac=i(ss);Xs=r(Ac,"STRONG",{});var vc=i(Xs);Jr=n(vc,"Output:"),vc.forEach(t),Ac.forEach(t),Fl=u(e),f(pt.$$.fragment,e),zl=u(e),_=r(e,"P",{});var V=i(_);jr=n(V,"Alright! Our feature extractor returns a dictionary of two arrays: "),Hs=r(V,"CODE",{});var Ec=i(Hs);Ur=n(Ec,"input_values"),Ec.forEach(t),gr=n(V," and "),qs=r(V,"CODE",{});var kc=i(qs);br=n(kc,"attention_mask"),kc.forEach(t),Ir=n(V,". The "),Os=r(V,"CODE",{});var _c=i(Os);Cr=n(_c,"input_values"),_c.forEach(t),Ar=n(V,`
are the preprocessed audio inputs that we\u2019d pass to the HuBERT model. The `),ct=r(V,"A",{href:!0,rel:!0});var $c=i(ct);Ps=r($c,"CODE",{});var Wc=i(Ps);vr=n(Wc,"attention_mask"),Wc.forEach(t),$c.forEach(t),Er=n(V,`
is used when we process a `),Ls=r(V,"EM",{});var Nc=i(Ls);kr=n(Nc,"batch"),Nc.forEach(t),_r=n(V,` of audio inputs at once - it is used to tell the model where we have padded inputs of
different lengths.`),V.forEach(t),Dl=u(e),as=r(e,"P",{});var Zc=i(as);$r=n(Zc,`We can see that the mean value is now very much closer to zero, and the variance bang-on one! This is exactly the form we
want our audio samples in prior to feeding them to the HuBERT model.`),Zc.forEach(t),Yl=u(e),f(Te.$$.fragment,e),Vl=u(e),te=r(e,"P",{});var ms=i(te);Wr=n(ms,`Great, so now we know how to process our resampled audio files, the last thing to do is define a function that we can
apply to all the examples in the dataset. Since we expect the audio clips to be 30 seconds in length, we\u2019ll also
truncate any longer clips by using the `),Ks=r(ms,"CODE",{});var Bc=i(Ks);Nr=n(Bc,"max_length"),Bc.forEach(t),Zr=n(ms," and "),ea=r(ms,"CODE",{});var Gc=i(ea);Br=n(Gc,"truncation"),Gc.forEach(t),Gr=n(ms," arguments of the feature extractor as follows:"),ms.forEach(t),Sl=u(e),f(ut.$$.fragment,e),Xl=u(e),x=r(e,"P",{});var We=i(x);Qr=n(We,"With this function defined, we can now apply it to the dataset using the "),ht=r(We,"A",{href:!0,rel:!0});var Qc=i(ht);ta=r(Qc,"CODE",{});var Rc=i(ta);Rr=n(Rc,"map()"),Rc.forEach(t),Qc.forEach(t),xr=n(We,`
method. The `),sa=r(We,"CODE",{});var xc=i(sa);Fr=n(xc,".map()"),xc.forEach(t),zr=n(We," method supports working with batches of examples, which we\u2019ll enable by setting "),aa=r(We,"CODE",{});var Fc=i(aa);Dr=n(Fc,"batched=True"),Fc.forEach(t),Yr=n(We,`.
The default batch size is 1000, but we\u2019ll reduce it to 100 to ensure the peak RAM stays within a sensible range for
Google Colab\u2019s free tier:`),We.forEach(t),Hl=u(e),f(dt.$$.fragment,e),ql=u(e),ls=r(e,"P",{});var zc=i(ls);la=r(zc,"STRONG",{});var Dc=i(la);Vr=n(Dc,"Output:"),Dc.forEach(t),zc.forEach(t),Ol=u(e),f(Mt.$$.fragment,e),Pl=u(e),f(Je.$$.fragment,e),Ll=u(e),b=r(e,"P",{});var v=i(b);Sr=n(v,"To simplify the training, we\u2019ve removed the "),na=r(v,"CODE",{});var Yc=i(na);Xr=n(Yc,"audio"),Yc.forEach(t),Hr=n(v," and "),oa=r(v,"CODE",{});var Vc=i(oa);qr=n(Vc,"file"),Vc.forEach(t),Or=n(v," columns from the dataset. The "),ra=r(v,"CODE",{});var Sc=i(ra);Pr=n(Sc,"input_values"),Sc.forEach(t),Lr=n(v,` column contains
the encoded audio files, the `),ia=r(v,"CODE",{});var Xc=i(ia);Kr=n(Xc,"attention_mask"),Xc.forEach(t),ei=n(v,` a binary mask of 0/1 values that indicate where we have padded the audio input,
and the `),pa=r(v,"CODE",{});var Hc=i(pa);ti=n(Hc,"genre"),Hc.forEach(t),si=n(v," column contains the corresponding labels (or targets). To enable the "),ca=r(v,"CODE",{});var qc=i(ca);ai=n(qc,"Trainer"),qc.forEach(t),li=n(v,` to process the class labels,
we need to rename the `),ua=r(v,"CODE",{});var Oc=i(ua);ni=n(Oc,"genre"),Oc.forEach(t),oi=n(v," column to "),ha=r(v,"CODE",{});var Pc=i(ha);ri=n(Pc,"label"),Pc.forEach(t),ii=n(v,":"),v.forEach(t),Kl=u(e),f(ft.$$.fragment,e),en=u(e),F=r(e,"P",{});var Ne=i(F);pi=n(Ne,"Finally, we need to obtain the label mappings from the dataset. This mapping will take us from integer ids (e.g. "),da=r(Ne,"CODE",{});var Lc=i(da);ci=n(Lc,"7"),Lc.forEach(t),ui=n(Ne,`) to
human-readable class labels (e.g. `),Ma=r(Ne,"CODE",{});var Kc=i(Ma);hi=n(Kc,'"pop"'),Kc.forEach(t),di=n(Ne,`) and back again. In doing so, we can convert our model\u2019s integer id prediction
into human-readable format, enabling us to use the model in any downstream application. We can do this by using the `),fa=r(Ne,"CODE",{});var eu=i(fa);Mi=n(eu,"int2str()"),eu.forEach(t),fi=n(Ne,`
method as follows:`),Ne.forEach(t),tn=u(e),f(mt.$$.fragment,e),sn=u(e),f(yt.$$.fragment,e),an=u(e),ns=r(e,"P",{});var tu=i(ns);mi=n(tu,"OK, we\u2019ve now got a dataset that\u2019s ready for training! Let\u2019s take a look at how we can train a model on this dataset."),tu.forEach(t),ln=u(e),ie=r(e,"H2",{class:!0});var Vn=i(ie);je=r(Vn,"A",{id:!0,class:!0,href:!0});var su=i(je);ma=r(su,"SPAN",{});var au=i(ma);f(wt.$$.fragment,au),au.forEach(t),su.forEach(t),yi=u(Vn),ya=r(Vn,"SPAN",{});var lu=i(ya);wi=n(lu,"Fine-tuning the model"),lu.forEach(t),Vn.forEach(t),nn=u(e),W=r(e,"P",{});var le=i(W);Ti=n(le,"To fine-tune the model, we\u2019ll use the "),wa=r(le,"CODE",{});var nu=i(wa);Ji=n(nu,"Trainer"),nu.forEach(t),ji=n(le," class from \u{1F917} Transformers. As we\u2019ve seen in other chapters, the "),Ta=r(le,"CODE",{});var ou=i(Ta);Ui=n(ou,"Trainer"),ou.forEach(t),gi=n(le,`
is a high-level API that is designed to handle the most common training scenarios. In this case, we\u2019ll use the `),Ja=r(le,"CODE",{});var ru=i(Ja);bi=n(ru,"Trainer"),ru.forEach(t),Ii=n(le,`
to fine-tune the model on GTZAN. To do this, we\u2019ll first need to load a model for this task. We can do this by using the
`),ja=r(le,"CODE",{});var iu=i(ja);Ci=n(iu,"AutoModelForAudioClassification"),iu.forEach(t),Ai=n(le,` class, which will automatically add the appropriate classification head to our pretrained
DistilHuBERT model. Let\u2019s go ahead and instantiate the model:`),le.forEach(t),on=u(e),f(Tt.$$.fragment,e),rn=u(e),Ue=r(e,"P",{});var Sn=i(Ue);vi=n(Sn,"We strongly advise you to upload model checkpoints directly the "),Jt=r(Sn,"A",{href:!0,rel:!0});var pu=i(Jt);Ei=n(pu,"Hugging Face Hub"),pu.forEach(t),ki=n(Sn,` while training.
The Hub provides:`),Sn.forEach(t),pn=u(e),z=r(e,"UL",{});var Ze=i(z);Ua=r(Ze,"LI",{});var cu=i(Ua);_i=n(cu,"Integrated version control: you can be sure that no model checkpoint is lost during training."),cu.forEach(t),$i=u(Ze),ga=r(Ze,"LI",{});var uu=i(ga);Wi=n(uu,"Tensorboard logs: track important metrics over the course of training."),uu.forEach(t),Ni=u(Ze),ba=r(Ze,"LI",{});var hu=i(ba);Zi=n(hu,"Model cards: document what a model does and its intended use cases."),hu.forEach(t),Bi=u(Ze),Ia=r(Ze,"LI",{});var du=i(Ia);Gi=n(du,"Community: an easy way to share and collaborate with the community! \u{1F917}"),du.forEach(t),Ze.forEach(t),cn=u(e),ge=r(e,"P",{});var Xn=i(ge);Qi=n(Xn,`Linking the notebook to the Hub is straightforward - it simply requires entering your Hub authentication token when prompted.
Find your Hub authentication token `),jt=r(Xn,"A",{href:!0,rel:!0});var Mu=i(jt);Ri=n(Mu,"here"),Mu.forEach(t),xi=n(Xn,":"),Xn.forEach(t),un=u(e),f(Ut.$$.fragment,e),hn=u(e),os=r(e,"P",{});var fu=i(os);Ca=r(fu,"STRONG",{});var mu=i(Ca);Fi=n(mu,"Output:"),mu.forEach(t),fu.forEach(t),dn=u(e),f(gt.$$.fragment,e),Mn=u(e),rs=r(e,"P",{});var yu=i(rs);zi=n(yu,`The next step is to define the training arguments, including the batch size, gradient accumulation steps, number of
training epochs and learning rate:`),yu.forEach(t),fn=u(e),f(bt.$$.fragment,e),mn=u(e),f(be.$$.fragment,e),yn=u(e),is=r(e,"P",{});var wu=i(is);Di=n(wu,`The last thing we need to do is define the metrics. Since the dataset is balanced, we\u2019ll use accuracy as our metric and
load it using the \u{1F917} Evaluate library:`),wu.forEach(t),wn=u(e),f(It.$$.fragment,e),Tn=u(e),Ie=r(e,"P",{});var Hn=i(Ie);Yi=n(Hn,"We\u2019ve now got all the pieces! Let\u2019s instantiate the "),Aa=r(Hn,"CODE",{});var Tu=i(Aa);Vi=n(Tu,"Trainer"),Tu.forEach(t),Si=n(Hn," and train the model:"),Hn.forEach(t),Jn=u(e),f(Ct.$$.fragment,e),jn=u(e),f(Ce.$$.fragment,e),Un=u(e),ps=r(e,"P",{});var Ju=i(ps);va=r(Ju,"STRONG",{});var ju=i(va);Xi=n(ju,"Output:"),ju.forEach(t),Ju.forEach(t),gn=u(e),f(At.$$.fragment,e),bn=u(e),Ae=r(e,"P",{});var qn=i(Ae);Hi=n(qn,`Training will take approximately 1 hour depending on your GPU or the one allocated to the Google Colab. Our best
evaluation accuracy is 83% - not bad for just 10 epochs with 899 examples of training data! We could certainly improve
upon this result by training for more epochs, using regularisation techniques such as `),Ea=r(qn,"EM",{});var Uu=i(Ea);qi=n(Uu,"dropout"),Uu.forEach(t),Oi=n(qn,`, or sub-diving each
audio example from 30s into 15s segments to use a more efficient data pre-processing strategy.`),qn.forEach(t),In=u(e),ve=r(e,"P",{});var On=i(ve);Pi=n(On,`The big question is how this compares to other music classification systems \u{1F914}
For that, we can view the `),vt=r(On,"A",{href:!0,rel:!0});var gu=i(vt);Li=n(gu,"autoevaluate leaderboard"),gu.forEach(t),Ki=n(On,`,
a leaderboard that categorises models by language and dataset, and subsequently ranks them according to their accuracy.`),On.forEach(t),Cn=u(e),cs=r(e,"P",{});var bu=i(cs);ep=n(bu,`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:`),bu.forEach(t),An=u(e),f(Et.$$.fragment,e),vn=u(e),Ee=r(e,"P",{});var Pn=i(Ee);tp=n(Pn,"The training results can now be uploaded to the Hub. To do so, execute the "),ka=r(Pn,"CODE",{});var Iu=i(ka);sp=n(Iu,".push_to_hub"),Iu.forEach(t),ap=n(Pn," command:"),Pn.forEach(t),En=u(e),f(kt.$$.fragment,e),kn=u(e),se=r(e,"P",{});var ys=i(se);lp=n(ys,"This will save the training logs and model weights under "),_a=r(ys,"CODE",{});var Cu=i(_a);np=n(Cu,'"your-username/distilhubert-finetuned-gtzan"'),Cu.forEach(t),op=n(ys,`. For this example,
check out the upload at `),_t=r(ys,"A",{href:!0,rel:!0});var Au=i(_t);$a=r(Au,"CODE",{});var vu=i($a);rp=n(vu,'"sanchit-gandhi/distilhubert-finetuned-gtzan"'),vu.forEach(t),Au.forEach(t),ip=n(ys,"."),ys.forEach(t),_n=u(e),pe=r(e,"H2",{class:!0});var Ln=i(pe);ke=r(Ln,"A",{id:!0,class:!0,href:!0});var Eu=i(ke);Wa=r(Eu,"SPAN",{});var ku=i(Wa);f($t.$$.fragment,ku),ku.forEach(t),Eu.forEach(t),pp=u(Ln),Na=r(Ln,"SPAN",{});var _u=i(Na);cp=n(_u,"Share Model"),_u.forEach(t),Ln.forEach(t),$n=u(e),D=r(e,"P",{});var Be=i(D);up=n(Be,"You can now share this model with anyone using the link on the Hub. They can load it with the identifier "),Za=r(Be,"CODE",{});var $u=i(Za);hp=n($u,'"your-username/distilhubert-finetuned-gtzan"'),$u.forEach(t),dp=n(Be,`
directly into the `),Ba=r(Be,"CODE",{});var Wu=i(Ba);Mp=n(Wu,"pipeline()"),Wu.forEach(t),fp=n(Be," class. For instance, to load the fine-tuned checkpoint "),Wt=r(Be,"A",{href:!0,rel:!0});var Nu=i(Wt);Ga=r(Nu,"CODE",{});var Zu=i(Ga);mp=n(Zu,'"sanchit-gandhi/distilhubert-finetuned-gtzan"'),Zu.forEach(t),Nu.forEach(t),yp=n(Be,":"),Be.forEach(t),Wn=u(e),f(Nt.$$.fragment,e),Nn=u(e),ce=r(e,"H2",{class:!0});var Kn=i(ce);_e=r(Kn,"A",{id:!0,class:!0,href:!0});var Bu=i(_e);Qa=r(Bu,"SPAN",{});var Gu=i(Qa);f(Zt.$$.fragment,Gu),Gu.forEach(t),Bu.forEach(t),wp=u(Kn),Ra=r(Kn,"SPAN",{});var Qu=i(Ra);Tp=n(Qu,"Conclusion"),Qu.forEach(t),Kn.forEach(t),Zn=u(e),$e=r(e,"P",{});var eo=i($e);Jp=n(eo,`In this section, we\u2019ve covered a step-by-step guide for fine-tuning the DistilHuBERT model for music classification. While
we focussed on the task of music classification and the GTZAN dataset, the steps presented here apply more generally to any
audio classification task - the same script can be used for spoken language audio classification tasks like keyword spotting
or language identification. You just need to swap out the dataset for one that corresponds to your task of interest! If
you\u2019re interested in fine-tuning other Hugging Face Hub models for audio classification, we encourage you to check out the
other `),Bt=r(eo,"A",{href:!0,rel:!0});var Ru=i(Bt);jp=n(Ru,"examples"),Ru.forEach(t),Up=n(eo,` in the \u{1F917}
Transformers repository.`),eo.forEach(t),Bn=u(e),us=r(e,"P",{});var xu=i(us);gp=n(xu,`In the next section, we\u2019ll take the model that you just fine-tuned and build a music classification demo that you can share
on the Hugging Face Hub.`),xu.forEach(t),this.h()},h(){h(d,"name","hf:doc:metadata"),h(d,"content",JSON.stringify(Ku)),h(g,"id","finetuning-a-model-for-music-classification"),h(g,"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"),h(g,"href","#finetuning-a-model-for-music-classification"),h(J,"class","relative group"),h(X,"id","the-dataset"),h(X,"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"),h(X,"href","#the-dataset"),h(I,"class","relative group"),h(Qe,"href","https://huggingface.co/datasets/marsyas/gtzan"),h(Qe,"rel","nofollow"),h(Dt,"href","../chapter1/audio_data"),Fu(G.src,bp="https://course-demos-gtzan-samples.hf.space")||h(G,"src",bp),h(G,"frameborder","0"),h(G,"height","450"),h(G,"title","Gradio app"),h(G,"class","container p-0 flex-grow space-iframe"),h(G,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),h(G,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),h(fe,"id","picking-a-pretrained-model-for-audio-classification"),h(fe,"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"),h(fe,"href","#picking-a-pretrained-model-for-audio-classification"),h(ne,"class","relative group"),h(qe,"href","https://huggingface.co/datasets/librispeech_asr"),h(qe,"rel","nofollow"),h(Oe,"href","https://huggingface.co/datasets/facebook/voxpopuli"),h(Oe,"rel","nofollow"),h(Pe,"href","https://huggingface.co/docs/transformers/model_doc/hubert"),h(Pe,"rel","nofollow"),Fu(Q.src,Ip="https://autoevaluate-leaderboards.hf.space")||h(Q,"src",Ip),h(Q,"frameborder","0"),h(Q,"height","450"),h(Q,"title","Gradio app"),h(Q,"class","container p-0 flex-grow space-iframe"),h(Q,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),h(Q,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),h(me,"id","from-audio-to-machine-learning-features"),h(me,"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"),h(me,"href","#from-audio-to-machine-learning-features"),h(oe,"class","relative group"),h(ye,"id","preprocessing-the-data"),h(ye,"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"),h(ye,"href","#preprocessing-the-data"),h(re,"class","relative group"),h(ct,"href","https://huggingface.co/docs/transformers/glossary#attention-mask"),h(ct,"rel","nofollow"),h(ht,"href","https://huggingface.co/docs/datasets/v2.14.0/en/package_reference/main_classes#datasets.Dataset.map"),h(ht,"rel","nofollow"),h(je,"id","finetuning-the-model"),h(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"),h(je,"href","#finetuning-the-model"),h(ie,"class","relative group"),h(Jt,"href","https://huggingface.co/"),h(Jt,"rel","nofollow"),h(jt,"href","https://huggingface.co/settings/tokens"),h(jt,"rel","nofollow"),h(vt,"href","https://huggingface.co/spaces/autoevaluate/leaderboards?dataset=marsyas%2Fgtzan&only_verified=0&task=audio-classification&config=all&split=train&metric=accuracy"),h(vt,"rel","nofollow"),h(_t,"href","https://huggingface.co/sanchit-gandhi/distilhubert-finetuned-gtzan"),h(_t,"rel","nofollow"),h(ke,"id","share-model"),h(ke,"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"),h(ke,"href","#share-model"),h(pe,"class","relative group"),h(Wt,"href","https://huggingface.co/sanchit-gandhi/distilhubert-finetuned-gtzan"),h(Wt,"rel","nofollow"),h(_e,"id","conclusion"),h(_e,"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"),h(_e,"href","#conclusion"),h(ce,"class","relative group"),h(Bt,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/audio-classification"),h(Bt,"rel","nofollow")},m(e,a){s(document.head,d),p(e,U,a),p(e,J,a),s(J,g),s(g,N),m(C,N,null),s(J,S),s(J,Z),s(Z,E),p(e,A,a),p(e,B,a),s(B,H),p(e,q,a),p(e,I,a),s(I,X),s(X,ue),m(O,ue,null),s(I,Qt),s(I,ws),s(ws,to),p(e,Va,a),p(e,P,a),s(P,so),s(P,Qe),s(Qe,ao),s(P,lo),s(P,Ts),s(Ts,no),s(P,oo),p(e,Sa,a),m(Re,e,a),p(e,Xa,a),p(e,Rt,a),s(Rt,Js),s(Js,ro),p(e,Ha,a),m(xe,e,a),p(e,qa,a),m(he,e,a),p(e,Oa,a),p(e,de,a),s(de,io),s(de,js),s(js,po),s(de,co),p(e,Pa,a),m(Fe,e,a),p(e,La,a),p(e,xt,a),s(xt,Us),s(Us,uo),p(e,Ka,a),m(ze,e,a),p(e,el,a),p(e,Ft,a),s(Ft,ho),p(e,tl,a),m(De,e,a),p(e,sl,a),p(e,zt,a),s(zt,gs),s(gs,Mo),p(e,al,a),m(Ye,e,a),p(e,ll,a),p(e,$,a),s($,fo),s($,Dt),s(Dt,mo),s($,yo),s($,bs),s(bs,wo),s($,To),s($,Is),s(Is,Jo),s($,jo),s($,Cs),s(Cs,Uo),s($,go),p(e,nl,a),m(Ve,e,a),p(e,ol,a),p(e,Yt,a),s(Yt,As),s(As,bo),p(e,rl,a),m(Se,e,a),p(e,il,a),p(e,Me,a),s(Me,Io),s(Me,vs),s(vs,Co),s(Me,Ao),p(e,pl,a),m(Xe,e,a),p(e,cl,a),p(e,G,a),p(e,ul,a),p(e,Vt,a),s(Vt,vo),p(e,hl,a),p(e,ne,a),s(ne,fe),s(fe,Es),m(He,Es,null),s(ne,Eo),s(ne,ks),s(ks,ko),p(e,dl,a),p(e,k,a),s(k,_o),s(k,qe),s(qe,$o),s(k,Wo),s(k,Oe),s(Oe,No),s(k,Zo),s(k,_s),s(_s,Bo),s(k,Go),s(k,$s),s($s,Qo),s(k,Ro),s(k,Pe),s(Pe,xo),s(k,Fo),p(e,Ml,a),p(e,Q,a),p(e,fl,a),p(e,oe,a),s(oe,me),s(me,Ws),m(Le,Ws,null),s(oe,zo),s(oe,Ns),s(Ns,Do),p(e,ml,a),p(e,re,a),s(re,ye),s(ye,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p),Gn=!0},p(e,[a]){const Gt={};a&2&&(Gt.$$scope={dirty:a,ctx:e}),he.$set(Gt);const xa={};a&2&&(xa.$$scope={dirty:a,ctx:e}),Te.$set(xa);const Fa={};a&2&&(Fa.$$scope={dirty:a,ctx:e}),Je.$set(Fa);const za={};a&2&&(za.$$scope={dirty:a,ctx:e}),be.$set(za);const Da={};a&2&&(Da.$$scope={dirty:a,ctx:e}),Ce.$set(Da)},i(e){Gn||(y(C.$$.fragment,e),y(O.$$.fragment,e),y(Re.$$.fragment,e),y(xe.$$.fragment,e),y(he.$$.fragment,e),y(Fe.$$.fragment,e),y(ze.$$.fragment,e),y(De.$$.fragment,e),y(Ye.$$.fragment,e),y(Ve.$$.fragment,e),y(Se.$$.fragment,e),y(Xe.$$.fragment,e),y(He.$$.fragment,e),y(Le.$$.fragment,e),y(Ke.$$.fragment,e),y(et.$$.fragment,e),y(tt.$$.fragment,e),y(st.$$.fragment,e),y(at.$$.fragment,e),y(lt.$$.fragment,e),y(nt.$$.fragment,e),y(ot.$$.fragment,e),y(rt.$$.fragment,e),y(it.$$.fragment,e),y(pt.$$.fragment,e),y(Te.$$.fragment,e),y(ut.$$.fragment,e),y(dt.$$.fragment,e),y(Mt.$$.fragment,e),y(Je.$$.fragment,e),y(ft.$$.fragment,e),y(mt.$$.fragment,e),y(yt.$$.fragment,e),y(wt.$$.fragment,e),y(Tt.$$.fragment,e),y(Ut.$$.fragment,e),y(gt.$$.fragment,e),y(bt.$$.fragment,e),y(be.$$.fragment,e),y(It.$$.fragment,e),y(Ct.$$.fragment,e),y(Ce.$$.fragment,e),y(At.$$.fragment,e),y(Et.$$.fragment,e),y(kt.$$.fragment,e),y($t.$$.fragment,e),y(Nt.$$.fragment,e),y(Zt.$$.fragment,e),Gn=!0)},o(e){w(C.$$.fragment,e),w(O.$$.fragment,e),w(Re.$$.fragment,e),w(xe.$$.fragment,e),w(he.$$.fragment,e),w(Fe.$$.fragment,e),w(ze.$$.fragment,e),w(De.$$.fragment,e),w(Ye.$$.fragment,e),w(Ve.$$.fragment,e),w(Se.$$.fragment,e),w(Xe.$$.fragment,e),w(He.$$.fragment,e),w(Le.$$.fragment,e),w(Ke.$$.fragment,e),w(et.$$.fragment,e),w(tt.$$.fragment,e),w(st.$$.fragment,e),w(at.$$.fragment,e),w(lt.$$.fragment,e),w(nt.$$.fragment,e),w(ot.$$.fragment,e),w(rt.$$.fragment,e),w(it.$$.fragment,e),w(pt.$$.fragment,e),w(Te.$$.fragment,e),w(ut.$$.fragment,e),w(dt.$$.fragment,e),w(Mt.$$.fragment,e),w(Je.$$.fragment,e),w(ft.$$.fragment,e),w(mt.$$.fragment,e),w(yt.$$.fragment,e),w(wt.$$.fragment,e),w(Tt.$$.fragment,e),w(Ut.$$.fragment,e),w(gt.$$.fragment,e),w(bt.$$.fragment,e),w(be.$$.fragment,e),w(It.$$.fragment,e),w(Ct.$$.fragment,e),w(Ce.$$.fragment,e),w(At.$$.fragment,e),w(Et.$$.fragment,e),w(kt.$$.fragment,e),w($t.$$.fragment,e),w(Nt.$$.fragment,e),w(Zt.$$.fragment,e),Gn=!1},d(e){t(d),e&&t(U),e&&t(J),T(C),e&&t(A),e&&t(B),e&&t(q),e&&t(I),T(O),e&&t(Va),e&&t(P),e&&t(Sa),T(Re,e),e&&t(Xa),e&&t(Rt),e&&t(Ha),T(xe,e),e&&t(qa),T(he,e),e&&t(Oa),e&&t(de),e&&t(Pa),T(Fe,e),e&&t(La),e&&t(xt),e&&t(Ka),T(ze,e),e&&t(el),e&&t(Ft),e&&t(tl),T(De,e),e&&t(sl),e&&t(zt),e&&t(al),T(Ye,e),e&&t(ll),e&&t($),e&&t(nl),T(Ve,e),e&&t(ol),e&&t(Yt),e&&t(rl),T(Se,e),e&&t(il),e&&t(Me),e&&t(pl),T(Xe,e),e&&t(cl),e&&t(G),e&&t(ul),e&&t(Vt),e&&t(hl),e&&t(ne),T(He),e&&t(dl),e&&t(k),e&&t(Ml),e&&t(Q),e&&t(fl),e&&t(oe),T(Le),e&&t(ml),e&&t(re),T(Ke),e&&t(yl),e&&t(L),e&&t(wl),T(et,e),e&&t(Tl),e&&t(St),e&&t(Jl),T(tt,e),e&&t(jl),e&&t(Xt),e&&t(Ul),T(st,e),e&&t(gl),e&&t(K),e&&t(bl),T(at,e),e&&t(Il),e&&t(we),e&&t(Cl),T(lt,e),e&&t(Al),e&&t(Ht),e&&t(vl),T(nt,e),e&&t(El),e&&t(qt),e&&t(kl),e&&t(Ot),e&&t(_l),e&&t(Pt),e&&t($l),e&&t(Lt),e&&t(Wl),e&&t(ee),e&&t(Nl),e&&t(Kt),e&&t(Zl),T(ot,e),e&&t(Bl),e&&t(es),e&&t(Gl),T(rt,e),e&&t(Ql),e&&t(ts),e&&t(Rl),T(it,e),e&&t(xl),e&&t(ss),e&&t(Fl),T(pt,e),e&&t(zl),e&&t(_),e&&t(Dl),e&&t(as),e&&t(Yl),T(Te,e),e&&t(Vl),e&&t(te),e&&t(Sl),T(ut,e),e&&t(Xl),e&&t(x),e&&t(Hl),T(dt,e),e&&t(ql),e&&t(ls),e&&t(Ol),T(Mt,e),e&&t(Pl),T(Je,e),e&&t(Ll),e&&t(b),e&&t(Kl),T(ft,e),e&&t(en),e&&t(F),e&&t(tn),T(mt,e),e&&t(sn),T(yt,e),e&&t(an),e&&t(ns),e&&t(ln),e&&t(ie),T(wt),e&&t(nn),e&&t(W),e&&t(on),T(Tt,e),e&&t(rn),e&&t(Ue),e&&t(pn),e&&t(z),e&&t(cn),e&&t(ge),e&&t(un),T(Ut,e),e&&t(hn),e&&t(os),e&&t(dn),T(gt,e),e&&t(Mn),e&&t(rs),e&&t(fn),T(bt,e),e&&t(mn),T(be,e),e&&t(yn),e&&t(is),e&&t(wn),T(It,e),e&&t(Tn),e&&t(Ie),e&&t(Jn),T(Ct,e),e&&t(jn),T(Ce,e),e&&t(Un),e&&t(ps),e&&t(gn),T(At,e),e&&t(bn),e&&t(Ae),e&&t(In),e&&t(ve),e&&t(Cn),e&&t(cs),e&&t(An),T(Et,e),e&&t(vn),e&&t(Ee),e&&t(En),T(kt,e),e&&t(kn),e&&t(se),e&&t(_n),e&&t(pe),T($t),e&&t($n),e&&t(D),e&&t(Wn),T(Nt,e),e&&t(Nn),e&&t(ce),T(Zt),e&&t(Zn),e&&t($e),e&&t(Bn),e&&t(us)}}}const Ku={local:"finetuning-a-model-for-music-classification",sections:[{local:"the-dataset",title:"The Dataset"},{local:"picking-a-pretrained-model-for-audio-classification",title:"Picking a pretrained model for audio classification"},{local:"from-audio-to-machine-learning-features",title:"From audio to machine learning features"},{local:"preprocessing-the-data",title:"Preprocessing the data"},{local:"finetuning-the-model",title:"Fine-tuning the model"},{local:"share-model",title:"Share Model"},{local:"conclusion",title:"Conclusion"}],title:"Fine-tuning a model for music classification"};function eh(R){return Su(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class nh extends zu{constructor(d){super();Du(this,d,eh,Lu,Yu,{})}}export{nh as default,Ku as metadata};
