import{S as ar,i as tr,s as lr,e as r,k as c,w as $,t,M as nr,c as o,d as s,m as u,a as i,x as v,h as l,b as h,G as a,g as p,y as b,q as j,o as y,B as w,v as rr,L as or}from"../../chunks/vendor-hf-doc-builder.js";import{T as Gl}from"../../chunks/Tip-hf-doc-builder.js";import{Y as ir}from"../../chunks/Youtube-hf-doc-builder.js";import{I as Us}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as S}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as er,M as sr}from"../../chunks/Markdown-hf-doc-builder.js";function pr(H){let m,k,f,g,E;return{c(){m=r("p"),k=t("See the audio classification "),f=r("a"),g=t("task page"),E=t(" for more information about its associated models, datasets, and metrics."),this.h()},l(x){m=o(x,"P",{});var A=i(m);k=l(A,"See the audio classification "),f=o(A,"A",{href:!0,rel:!0});var q=i(f);g=l(q,"task page"),q.forEach(s),E=l(A," for more information about its associated models, datasets, and metrics."),A.forEach(s),this.h()},h(){h(f,"href","https://huggingface.co/tasks/audio-classification"),h(f,"rel","nofollow")},m(x,A){p(x,m,A),a(m,k),a(m,f),a(f,g),a(m,E)},d(x){x&&s(m)}}}function cr(H){let m,k,f,g,E,x,A,q;return{c(){m=r("p"),k=t("If you aren\u2019t familiar with finetuning a model with the "),f=r("a"),g=t("Trainer"),E=t(", take a look at the basic tutorial "),x=r("a"),A=t("here"),q=t("!"),this.h()},l(T){m=o(T,"P",{});var F=i(m);k=l(F,"If you aren\u2019t familiar with finetuning a model with the "),f=o(F,"A",{href:!0});var I=i(f);g=l(I,"Trainer"),I.forEach(s),E=l(F,", take a look at the basic tutorial "),x=o(F,"A",{href:!0});var O=i(x);A=l(O,"here"),O.forEach(s),q=l(F,"!"),F.forEach(s),this.h()},h(){h(f,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),h(x,"href","../training#train-with-pytorch-trainer")},m(T,F){p(T,m,F),a(m,k),a(m,f),a(f,g),a(m,E),a(m,x),a(x,A),a(m,q)},d(T){T&&s(m)}}}function ur(H){let m,k,f,g,E,x,A,q,T,F,I,O,V,M,se,Y,X,ae,L,P,te,_,C,z,J,G,de,Ge,ue,Be,Ae,le,ne,_e,ge,qe,me,ye,K,Te,Z,fe,he,ee,re,$e,B,Pe;return m=new Gl({props:{$$slots:{default:[cr]},$$scope:{ctx:H}}}),f=new S({props:{code:`from transformers import AutoModelForAudioClassification, TrainingArguments, Trainer

num_labels = len(id2label)
model = AutoModelForAudioClassification.from_pretrained(
    "facebook/wav2vec2-base", num_labels=num_labels, label2id=label2id, id2label=id2label
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForAudioClassification, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>num_labels = <span class="hljs-built_in">len</span>(id2label)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForAudioClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/wav2vec2-base&quot;</span>, num_labels=num_labels, label2id=label2id, id2label=id2label
<span class="hljs-meta">... </span>)`}}),K=new S({props:{code:`training_args = TrainingArguments(
    output_dir="my_awesome_mind_model",
    evaluation_strategy="epoch",
    save_strategy="epoch",
    learning_rate=3e-5,
    per_device_train_batch_size=32,
    gradient_accumulation_steps=4,
    per_device_eval_batch_size=32,
    num_train_epochs=10,
    warmup_ratio=0.1,
    logging_steps=10,
    load_best_model_at_end=True,
    metric_for_best_model="accuracy",
    push_to_hub=True,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=encoded_minds["train"],
    eval_dataset=encoded_minds["test"],
    tokenizer=feature_extractor,
    compute_metrics=compute_metrics,
)

trainer.train()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_mind_model&quot;</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">3e-5</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">32</span>,
<span class="hljs-meta">... </span>    gradient_accumulation_steps=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">32</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">10</span>,
<span class="hljs-meta">... </span>    warmup_ratio=<span class="hljs-number">0.1</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">10</span>,
<span class="hljs-meta">... </span>    load_best_model_at_end=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    metric_for_best_model=<span class="hljs-string">&quot;accuracy&quot;</span>,
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)

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

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),B=new S({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){$(m.$$.fragment),k=t(`
You're ready to start training your model now! Load Wav2Vec2 with [AutoModelForAudioClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForAudioClassification) along with the number of expected labels, and the label mappings:

	`),$(f.$$.fragment),g=c(),E=r("p"),x=t("At this point, only three steps remain:"),A=c(),q=r("ol"),T=r("li"),F=t("Define your training hyperparameters in "),I=r("a"),O=t("TrainingArguments"),V=t(". The only required parameter is "),M=r("code"),se=t("output_dir"),Y=t(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),X=r("code"),ae=t("push_to_hub=True"),L=t(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),P=r("a"),te=t("Trainer"),_=t(" will evaluate the accuracy and save the training checkpoint."),C=c(),z=r("li"),J=t("Pass the training arguments to "),G=r("a"),de=t("Trainer"),Ge=t(" along with the model, dataset, tokenizer, data collator, and "),ue=r("code"),Be=t("compute_metrics"),Ae=t(" function."),le=c(),ne=r("li"),_e=t("Call "),ge=r("a"),qe=t("train()"),me=t(" to finetune your model."),ye=c(),$(K.$$.fragment),Te=c(),Z=r("p"),fe=t("Once training is completed, share your model to the Hub with the "),he=r("a"),ee=t("push_to_hub()"),re=t(" method so everyone can use your model:"),$e=c(),$(B.$$.fragment),this.h()},l(d){v(m.$$.fragment,d),k=l(d,`
You're ready to start training your model now! Load Wav2Vec2 with [AutoModelForAudioClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForAudioClassification) along with the number of expected labels, and the label mappings:

	`),v(f.$$.fragment,d),g=u(d),E=o(d,"P",{});var D=i(E);x=l(D,"At this point, only three steps remain:"),D.forEach(s),A=u(d),q=o(d,"OL",{});var Q=i(q);T=o(Q,"LI",{});var N=i(T);F=l(N,"Define your training hyperparameters in "),I=o(N,"A",{href:!0});var Es=i(I);O=l(Es,"TrainingArguments"),Es.forEach(s),V=l(N,". The only required parameter is "),M=o(N,"CODE",{});var Je=i(M);se=l(Je,"output_dir"),Je.forEach(s),Y=l(N," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),X=o(N,"CODE",{});var ve=i(X);ae=l(ve,"push_to_hub=True"),ve.forEach(s),L=l(N," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),P=o(N,"A",{href:!0});var Ke=i(P);te=l(Ke,"Trainer"),Ke.forEach(s),_=l(N," will evaluate the accuracy and save the training checkpoint."),N.forEach(s),C=u(Q),z=o(Q,"LI",{});var W=i(z);J=l(W,"Pass the training arguments to "),G=o(W,"A",{href:!0});var As=i(G);de=l(As,"Trainer"),As.forEach(s),Ge=l(W," along with the model, dataset, tokenizer, data collator, and "),ue=o(W,"CODE",{});var Ce=i(ue);Be=l(Ce,"compute_metrics"),Ce.forEach(s),Ae=l(W," function."),W.forEach(s),le=u(Q),ne=o(Q,"LI",{});var De=i(ne);_e=l(De,"Call "),ge=o(De,"A",{href:!0});var qs=i(ge);qe=l(qs,"train()"),qs.forEach(s),me=l(De," to finetune your model."),De.forEach(s),Q.forEach(s),ye=u(d),v(K.$$.fragment,d),Te=u(d),Z=o(d,"P",{});var oe=i(Z);fe=l(oe,"Once training is completed, share your model to the Hub with the "),he=o(oe,"A",{href:!0});var Ts=i(he);ee=l(Ts,"push_to_hub()"),Ts.forEach(s),re=l(oe," method so everyone can use your model:"),oe.forEach(s),$e=u(d),v(B.$$.fragment,d),this.h()},h(){h(I,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.TrainingArguments"),h(P,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),h(G,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),h(ge,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.train"),h(he,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(d,D){b(m,d,D),p(d,k,D),b(f,d,D),p(d,g,D),p(d,E,D),a(E,x),p(d,A,D),p(d,q,D),a(q,T),a(T,F),a(T,I),a(I,O),a(T,V),a(T,M),a(M,se),a(T,Y),a(T,X),a(X,ae),a(T,L),a(T,P),a(P,te),a(T,_),a(q,C),a(q,z),a(z,J),a(z,G),a(G,de),a(z,Ge),a(z,ue),a(ue,Be),a(z,Ae),a(q,le),a(q,ne),a(ne,_e),a(ne,ge),a(ge,qe),a(ne,me),p(d,ye,D),b(K,d,D),p(d,Te,D),p(d,Z,D),a(Z,fe),a(Z,he),a(he,ee),a(Z,re),p(d,$e,D),b(B,d,D),Pe=!0},p(d,D){const Q={};D&2&&(Q.$$scope={dirty:D,ctx:d}),m.$set(Q)},i(d){Pe||(j(m.$$.fragment,d),j(f.$$.fragment,d),j(K.$$.fragment,d),j(B.$$.fragment,d),Pe=!0)},o(d){y(m.$$.fragment,d),y(f.$$.fragment,d),y(K.$$.fragment,d),y(B.$$.fragment,d),Pe=!1},d(d){w(m,d),d&&s(k),w(f,d),d&&s(g),d&&s(E),d&&s(A),d&&s(q),d&&s(ye),w(K,d),d&&s(Te),d&&s(Z),d&&s($e),w(B,d)}}}function mr(H){let m,k;return m=new sr({props:{$$slots:{default:[ur]},$$scope:{ctx:H}}}),{c(){$(m.$$.fragment)},l(f){v(m.$$.fragment,f)},m(f,g){b(m,f,g),k=!0},p(f,g){const E={};g&2&&(E.$$scope={dirty:g,ctx:f}),m.$set(E)},i(f){k||(j(m.$$.fragment,f),k=!0)},o(f){y(m.$$.fragment,f),k=!1},d(f){w(m,f)}}}function fr(H){let m,k,f,g,E;return{c(){m=r("p"),k=t("For a more in-depth example of how to finetune a model for audio classification, take a look at the corresponding "),f=r("a"),g=t("PyTorch notebook"),E=t("."),this.h()},l(x){m=o(x,"P",{});var A=i(m);k=l(A,"For a more in-depth example of how to finetune a model for audio classification, take a look at the corresponding "),f=o(A,"A",{href:!0,rel:!0});var q=i(f);g=l(q,"PyTorch notebook"),q.forEach(s),E=l(A,"."),A.forEach(s),this.h()},h(){h(f,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/audio_classification.ipynb"),h(f,"rel","nofollow")},m(x,A){p(x,m,A),a(m,k),a(m,f),a(f,g),a(m,E)},d(x){x&&s(m)}}}function hr(H){let m,k,f,g,E,x,A,q,T,F,I,O,V,M,se,Y,X,ae,L,P,te;return A=new S({props:{code:`from transformers import AutoFeatureExtractor

feature_extractor = AutoFeatureExtractor.from_pretrained("stevhliu/my_awesome_minds_model")
inputs = feature_extractor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoFeatureExtractor

<span class="hljs-meta">&gt;&gt;&gt; </span>feature_extractor = AutoFeatureExtractor.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_minds_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = feature_extractor(dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>], sampling_rate=sampling_rate, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),O=new S({props:{code:`from transformers import AutoModelForAudioClassification

model = AutoModelForAudioClassification.from_pretrained("stevhliu/my_awesome_minds_model")
with torch.no_grad():
    logits = model(**inputs).logits`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForAudioClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForAudioClassification.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_minds_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits`}}),P=new S({props:{code:`import torch

predicted_class_ids = torch.argmax(logits).item()
predicted_label = model.config.id2label[predicted_class_ids]
predicted_label`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_ids = torch.argmax(logits).item()
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label = model.config.id2label[predicted_class_ids]
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label
<span class="hljs-string">&#x27;cash_deposit&#x27;</span>`}}),{c(){m=r("p"),k=t("Load a feature extractor to preprocess the audio file and return the "),f=r("code"),g=t("input"),E=t(" as PyTorch tensors:"),x=c(),$(A.$$.fragment),q=c(),T=r("p"),F=t("Pass your inputs to the model and return the logits:"),I=c(),$(O.$$.fragment),V=c(),M=r("p"),se=t("Get the class with the highest probability, and use the model\u2019s "),Y=r("code"),X=t("id2label"),ae=t(" mapping to convert it to a label:"),L=c(),$(P.$$.fragment)},l(_){m=o(_,"P",{});var C=i(m);k=l(C,"Load a feature extractor to preprocess the audio file and return the "),f=o(C,"CODE",{});var z=i(f);g=l(z,"input"),z.forEach(s),E=l(C," as PyTorch tensors:"),C.forEach(s),x=u(_),v(A.$$.fragment,_),q=u(_),T=o(_,"P",{});var J=i(T);F=l(J,"Pass your inputs to the model and return the logits:"),J.forEach(s),I=u(_),v(O.$$.fragment,_),V=u(_),M=o(_,"P",{});var G=i(M);se=l(G,"Get the class with the highest probability, and use the model\u2019s "),Y=o(G,"CODE",{});var de=i(Y);X=l(de,"id2label"),de.forEach(s),ae=l(G," mapping to convert it to a label:"),G.forEach(s),L=u(_),v(P.$$.fragment,_)},m(_,C){p(_,m,C),a(m,k),a(m,f),a(f,g),a(m,E),p(_,x,C),b(A,_,C),p(_,q,C),p(_,T,C),a(T,F),p(_,I,C),b(O,_,C),p(_,V,C),p(_,M,C),a(M,se),a(M,Y),a(Y,X),a(M,ae),p(_,L,C),b(P,_,C),te=!0},p:or,i(_){te||(j(A.$$.fragment,_),j(O.$$.fragment,_),j(P.$$.fragment,_),te=!0)},o(_){y(A.$$.fragment,_),y(O.$$.fragment,_),y(P.$$.fragment,_),te=!1},d(_){_&&s(m),_&&s(x),w(A,_),_&&s(q),_&&s(T),_&&s(I),w(O,_),_&&s(V),_&&s(M),_&&s(L),w(P,_)}}}function dr(H){let m,k;return m=new sr({props:{$$slots:{default:[hr]},$$scope:{ctx:H}}}),{c(){$(m.$$.fragment)},l(f){v(m.$$.fragment,f)},m(f,g){b(m,f,g),k=!0},p(f,g){const E={};g&2&&(E.$$scope={dirty:g,ctx:f}),m.$set(E)},i(f){k||(j(m.$$.fragment,f),k=!0)},o(f){y(m.$$.fragment,f),k=!1},d(f){w(m,f)}}}function _r(H){let m,k,f,g,E,x,A,q,T,F,I,O,V,M,se,Y,X,ae,L,P,te,_,C,z,J,G,de,Ge,ue,Be,Ae,le,ne,_e,ge,qe,me,ye,K,Te,Z,fe,he,ee,re,$e,B,Pe,d,D,Q,N,Es,Je,ve,Ke,W,As,Ce,De,qs,oe,Ts,bt,ba,Qe,ja,Ps,jt,ya,Xe,wa,R,yt,Vs,wt,kt,Gs,xt,Et,Bs,At,qt,Js,Tt,Pt,Ze,Ct,Dt,ka,es,xa,Cs,St,Ea,ss,Aa,Ds,It,qa,Se,Ie,Ks,Ft,Ot,Qs,Mt,Lt,Nt,Ss,Xs,Wt,Ht,Ta,Is,Yt,Pa,as,Ca,Fs,zt,Da,ts,Sa,we,Fe,Zs,ls,Rt,ea,Ut,Ia,Os,Vt,Fa,ns,Oa,Oe,Gt,rs,Bt,Jt,Ma,os,La,Ms,Kt,Na,be,is,Qt,sa,Xt,Zt,el,ps,sl,cs,al,tl,ll,aa,nl,Wa,us,Ha,U,rl,ms,ol,il,ta,pl,cl,la,ul,ml,na,fl,hl,ra,dl,_l,Ya,fs,za,ke,Me,oa,hs,gl,ia,$l,Ra,ie,vl,ds,bl,jl,_s,yl,wl,gs,kl,xl,Ua,$s,Va,Le,El,vs,Al,ql,Ga,bs,Ba,Ne,Tl,pa,Pl,Cl,Ja,xe,We,ca,js,Dl,ua,Sl,Ka,He,Qa,Ye,Xa,Ee,ze,ma,ys,Il,fa,Fl,Za,Ls,Ol,et,Ns,Ml,st,ws,at,je,Ll,Ws,Nl,Wl,ha,Hl,Yl,tt,ks,lt,Re,zl,da,Rl,Ul,nt,Ue,rt;return x=new Us({}),I=new ir({props:{id:"KWwzcmG98Ds"}}),le=new Gl({props:{$$slots:{default:[pr]},$$scope:{ctx:H}}}),me=new S({props:{code:"pip install transformers datasets evaluate",highlighted:"pip install transformers datasets evaluate"}}),fe=new S({props:{code:`from huggingface_hub import notebook_login

notebook_login()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),B=new Us({}),ve=new S({props:{code:`from datasets import load_dataset, Audio

minds = load_dataset("PolyAI/minds14", name="en-US", split="train")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, Audio

<span class="hljs-meta">&gt;&gt;&gt; </span>minds = load_dataset(<span class="hljs-string">&quot;PolyAI/minds14&quot;</span>, name=<span class="hljs-string">&quot;en-US&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)`}}),Qe=new S({props:{code:"minds = minds.train_test_split(test_size=0.2)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>minds = minds.train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),Xe=new S({props:{code:"minds",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>minds
DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;transcription&#x27;</span>, <span class="hljs-string">&#x27;english_transcription&#x27;</span>, <span class="hljs-string">&#x27;intent_class&#x27;</span>, <span class="hljs-string">&#x27;lang_id&#x27;</span>],
        num_rows: <span class="hljs-number">450</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;audio&#x27;</span>, <span class="hljs-string">&#x27;transcription&#x27;</span>, <span class="hljs-string">&#x27;english_transcription&#x27;</span>, <span class="hljs-string">&#x27;intent_class&#x27;</span>, <span class="hljs-string">&#x27;lang_id&#x27;</span>],
        num_rows: <span class="hljs-number">113</span>
    })
})`}}),es=new S({props:{code:'minds = minds.remove_columns(["path", "transcription", "english_transcription", "lang_id"])',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>minds = minds.remove_columns([<span class="hljs-string">&quot;path&quot;</span>, <span class="hljs-string">&quot;transcription&quot;</span>, <span class="hljs-string">&quot;english_transcription&quot;</span>, <span class="hljs-string">&quot;lang_id&quot;</span>])'}}),ss=new S({props:{code:'minds["train"][0]',highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>minds[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;audio&#x27;</span>: {<span class="hljs-string">&#x27;array&#x27;</span>: array([ <span class="hljs-number">0.</span>        ,  <span class="hljs-number">0.</span>        ,  <span class="hljs-number">0.</span>        , ..., -<span class="hljs-number">0.00048828</span>,
         -<span class="hljs-number">0.00024414</span>, -<span class="hljs-number">0.00024414</span>], dtype=float32),
  <span class="hljs-string">&#x27;path&#x27;</span>: <span class="hljs-string">&#x27;/root/.cache/huggingface/datasets/downloads/extracted/f14948e0e84be638dd7943ac36518a4cf3324e8b7aa331c5ab11541518e9368c/en-US~APP_ERROR/602b9a5fbb1e6d0fbce91f52.wav&#x27;</span>,
  <span class="hljs-string">&#x27;sampling_rate&#x27;</span>: <span class="hljs-number">8000</span>},
 <span class="hljs-string">&#x27;intent_class&#x27;</span>: <span class="hljs-number">2</span>}`}}),as=new S({props:{code:`labels = minds["train"].features["intent_class"].names
label2id, id2label = dict(), dict()
for i, label in enumerate(labels):
    label2id[label] = str(i)
    id2label[str(i)] = label`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>labels = minds[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;intent_class&quot;</span>].names
<span class="hljs-meta">&gt;&gt;&gt; </span>label2id, id2label = <span class="hljs-built_in">dict</span>(), <span class="hljs-built_in">dict</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(labels):
<span class="hljs-meta">... </span>    label2id[label] = <span class="hljs-built_in">str</span>(i)
<span class="hljs-meta">... </span>    id2label[<span class="hljs-built_in">str</span>(i)] = label`}}),ts=new S({props:{code:"id2label[str(2)]",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>id2label[<span class="hljs-built_in">str</span>(<span class="hljs-number">2</span>)]
<span class="hljs-string">&#x27;app_error&#x27;</span>`}}),ls=new Us({}),ns=new S({props:{code:`from transformers import AutoFeatureExtractor

feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoFeatureExtractor

<span class="hljs-meta">&gt;&gt;&gt; </span>feature_extractor = AutoFeatureExtractor.from_pretrained(<span class="hljs-string">&quot;facebook/wav2vec2-base&quot;</span>)`}}),os=new S({props:{code:`minds = minds.cast_column("audio", Audio(sampling_rate=16_000))
minds["train"][0]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>minds = minds.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16_000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>minds[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;audio&#x27;</span>: {<span class="hljs-string">&#x27;array&#x27;</span>: array([ <span class="hljs-number">2.2098757e-05</span>,  <span class="hljs-number">4.6582241e-05</span>, -<span class="hljs-number">2.2803260e-05</span>, ...,
         -<span class="hljs-number">2.8419291e-04</span>, -<span class="hljs-number">2.3305941e-04</span>, -<span class="hljs-number">1.1425107e-04</span>], dtype=float32),
  <span class="hljs-string">&#x27;path&#x27;</span>: <span class="hljs-string">&#x27;/root/.cache/huggingface/datasets/downloads/extracted/f14948e0e84be638dd7943ac36518a4cf3324e8b7aa331c5ab11541518e9368c/en-US~APP_ERROR/602b9a5fbb1e6d0fbce91f52.wav&#x27;</span>,
  <span class="hljs-string">&#x27;sampling_rate&#x27;</span>: <span class="hljs-number">16000</span>},
 <span class="hljs-string">&#x27;intent_class&#x27;</span>: <span class="hljs-number">2</span>}`}}),us=new S({props:{code:`def preprocess_function(examples):
    audio_arrays = [x["array"] for x in examples["audio"]]
    inputs = feature_extractor(
        audio_arrays, sampling_rate=feature_extractor.sampling_rate, max_length=16000, truncation=True
    )
    return inputs`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </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>]]
<span class="hljs-meta">... </span>    inputs = feature_extractor(
<span class="hljs-meta">... </span>        audio_arrays, sampling_rate=feature_extractor.sampling_rate, max_length=<span class="hljs-number">16000</span>, truncation=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs`}}),fs=new S({props:{code:`encoded_minds = minds.map(preprocess_function, remove_columns="audio", batched=True)
encoded_minds = encoded_minds.rename_column("intent_class", "label")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>encoded_minds = minds.<span class="hljs-built_in">map</span>(preprocess_function, remove_columns=<span class="hljs-string">&quot;audio&quot;</span>, batched=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>encoded_minds = encoded_minds.rename_column(<span class="hljs-string">&quot;intent_class&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>)`}}),hs=new Us({}),$s=new S({props:{code:`import evaluate

accuracy = evaluate.load("accuracy")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>accuracy = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)`}}),bs=new S({props:{code:`import numpy as np


def compute_metrics(eval_pred):
    predictions = np.argmax(eval_pred.predictions, axis=1)
    return accuracy.compute(predictions=predictions, references=eval_pred.label_ids)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-meta">&gt;&gt;&gt; </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-meta">... </span>    predictions = np.argmax(eval_pred.predictions, axis=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> accuracy.compute(predictions=predictions, references=eval_pred.label_ids)`}}),js=new Us({}),He=new er({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[mr]},$$scope:{ctx:H}}}),Ye=new Gl({props:{$$slots:{default:[fr]},$$scope:{ctx:H}}}),ys=new Us({}),ws=new S({props:{code:`from datasets import load_dataset, Audio

dataset = load_dataset("PolyAI/minds14", name="en-US", split="train")
dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))
sampling_rate = dataset.features["audio"].sampling_rate
audio_file = dataset[0]["audio"]["path"]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, Audio

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;PolyAI/minds14&quot;</span>, name=<span class="hljs-string">&quot;en-US&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>sampling_rate = dataset.features[<span class="hljs-string">&quot;audio&quot;</span>].sampling_rate
<span class="hljs-meta">&gt;&gt;&gt; </span>audio_file = dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;path&quot;</span>]`}}),ks=new S({props:{code:`from transformers import pipeline

classifier = pipeline("audio-classification", model="stevhliu/my_awesome_minds_model")
classifier(audio_file)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>classifier = pipeline(<span class="hljs-string">&quot;audio-classification&quot;</span>, model=<span class="hljs-string">&quot;stevhliu/my_awesome_minds_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>classifier(audio_file)
[
    {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.09766869246959686</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;cash_deposit&#x27;</span>},
    {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.07998877018690109</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;app_error&#x27;</span>},
    {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0781070664525032</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;joint_account&#x27;</span>},
    {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.07667109370231628</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;pay_bill&#x27;</span>},
    {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0755252093076706</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;balance&#x27;</span>}
]`}}),Ue=new er({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[dr]},$$scope:{ctx:H}}}),{c(){m=r("meta"),k=c(),f=r("h1"),g=r("a"),E=r("span"),$(x.$$.fragment),A=c(),q=r("span"),T=t("Audio classification"),F=c(),$(I.$$.fragment),O=c(),V=r("p"),M=t("Audio classification - just like with text - assigns a class label output from the input data. The only difference is instead of text inputs, you have raw audio waveforms. Some practical applications of audio classification include identifying speaker intent, language classification, and even animal species by their sounds."),se=c(),Y=r("p"),X=t("This guide will show you how to:"),ae=c(),L=r("ol"),P=r("li"),te=t("Finetune "),_=r("a"),C=t("Wav2Vec2"),z=t(" on the "),J=r("a"),G=t("MInDS-14"),de=t(" dataset to classify speaker intent."),Ge=c(),ue=r("li"),Be=t("Use your finetuned model for inference."),Ae=c(),$(le.$$.fragment),ne=c(),_e=r("p"),ge=t("Before you begin, make sure you have all the necessary libraries installed:"),qe=c(),$(me.$$.fragment),ye=c(),K=r("p"),Te=t("We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),Z=c(),$(fe.$$.fragment),he=c(),ee=r("h2"),re=r("a"),$e=r("span"),$(B.$$.fragment),Pe=c(),d=r("span"),D=t("Load MInDS-14 dataset"),Q=c(),N=r("p"),Es=t("Start by loading the MInDS-14 dataset from the \u{1F917} Datasets library:"),Je=c(),$(ve.$$.fragment),Ke=c(),W=r("p"),As=t("Split the dataset\u2019s "),Ce=r("code"),De=t("train"),qs=t(" split into a smaller train and test set with the "),oe=r("a"),Ts=t("train_test_split"),bt=t(" method. This\u2019ll give you a chance to experiment and make sure everything works before spending more time on the full dataset."),ba=c(),$(Qe.$$.fragment),ja=c(),Ps=r("p"),jt=t("Then take a look at the dataset:"),ya=c(),$(Xe.$$.fragment),wa=c(),R=r("p"),yt=t("While the dataset contains a lot of useful information, like "),Vs=r("code"),wt=t("lang_id"),kt=t(" and "),Gs=r("code"),xt=t("english_transcription"),Et=t(", you\u2019ll focus on the "),Bs=r("code"),At=t("audio"),qt=t(" and "),Js=r("code"),Tt=t("intent_class"),Pt=t(" in this guide. Remove the other columns with the "),Ze=r("a"),Ct=t("remove_columns"),Dt=t(" method:"),ka=c(),$(es.$$.fragment),xa=c(),Cs=r("p"),St=t("Take a look at an example now:"),Ea=c(),$(ss.$$.fragment),Aa=c(),Ds=r("p"),It=t("There are two fields:"),qa=c(),Se=r("ul"),Ie=r("li"),Ks=r("code"),Ft=t("audio"),Ot=t(": a 1-dimensional "),Qs=r("code"),Mt=t("array"),Lt=t(" of the speech signal that must be called to load and resample the audio file."),Nt=c(),Ss=r("li"),Xs=r("code"),Wt=t("intent_class"),Ht=t(": represents the class id of the speaker\u2019s intent."),Ta=c(),Is=r("p"),Yt=t("To make it easier for the model to get the label name from the label id, create a dictionary that maps the label name to an integer and vice versa:"),Pa=c(),$(as.$$.fragment),Ca=c(),Fs=r("p"),zt=t("Now you can convert the label id to a label name:"),Da=c(),$(ts.$$.fragment),Sa=c(),we=r("h2"),Fe=r("a"),Zs=r("span"),$(ls.$$.fragment),Rt=c(),ea=r("span"),Ut=t("Preprocess"),Ia=c(),Os=r("p"),Vt=t("The next step is to load a Wav2Vec2 feature extractor to process the audio signal:"),Fa=c(),$(ns.$$.fragment),Oa=c(),Oe=r("p"),Gt=t("The MInDS-14 dataset has a sampling rate of 8000khz (you can find this information in it\u2019s "),rs=r("a"),Bt=t("dataset card"),Jt=t("), which means you\u2019ll need to resample the dataset to 16000kHz to use the pretrained Wav2Vec2 model:"),Ma=c(),$(os.$$.fragment),La=c(),Ms=r("p"),Kt=t("Now create a preprocessing function that:"),Na=c(),be=r("ol"),is=r("li"),Qt=t("Calls the "),sa=r("code"),Xt=t("audio"),Zt=t(" column to load, and if necessary, resample the audio file."),el=c(),ps=r("li"),sl=t("Checks if the sampling rate of the audio file matches the sampling rate of the audio data a model was pretrained with. You can find this information in the Wav2Vec2 "),cs=r("a"),al=t("model card"),tl=t("."),ll=c(),aa=r("li"),nl=t("Set a maximum input length to batch longer inputs without truncating them."),Wa=c(),$(us.$$.fragment),Ha=c(),U=r("p"),rl=t("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),ms=r("a"),ol=t("map"),il=t(" function. You can speed up "),ta=r("code"),pl=t("map"),cl=t(" by setting "),la=r("code"),ul=t("batched=True"),ml=t(" to process multiple elements of the dataset at once. Remove the columns you don\u2019t need, and rename "),na=r("code"),fl=t("intent_class"),hl=t(" to "),ra=r("code"),dl=t("label"),_l=t(" because that\u2019s the name the model expects:"),Ya=c(),$(fs.$$.fragment),za=c(),ke=r("h2"),Me=r("a"),oa=r("span"),$(hs.$$.fragment),gl=c(),ia=r("span"),$l=t("Evaluate"),Ra=c(),ie=r("p"),vl=t("Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),ds=r("a"),bl=t("Evaluate"),jl=t(" library. For this task, load the "),_s=r("a"),yl=t("accuracy"),wl=t(" metric (see the \u{1F917} Evaluate "),gs=r("a"),kl=t("quick tour"),xl=t(" to learn more about how to load and compute a metric):"),Ua=c(),$($s.$$.fragment),Va=c(),Le=r("p"),El=t("Then create a function that passes your predictions and labels to "),vs=r("a"),Al=t("compute"),ql=t(" to calculate the accuracy:"),Ga=c(),$(bs.$$.fragment),Ba=c(),Ne=r("p"),Tl=t("Your "),pa=r("code"),Pl=t("compute_metrics"),Cl=t(" function is ready to go now, and you\u2019ll return to it when you setup your training."),Ja=c(),xe=r("h2"),We=r("a"),ca=r("span"),$(js.$$.fragment),Dl=c(),ua=r("span"),Sl=t("Train"),Ka=c(),$(He.$$.fragment),Qa=c(),$(Ye.$$.fragment),Xa=c(),Ee=r("h2"),ze=r("a"),ma=r("span"),$(ys.$$.fragment),Il=c(),fa=r("span"),Fl=t("Inference"),Za=c(),Ls=r("p"),Ol=t("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),et=c(),Ns=r("p"),Ml=t("Load an audio file you\u2019d like to run inference on. Remember to resample the sampling rate of the audio file to match the sampling rate of the model if you need to!"),st=c(),$(ws.$$.fragment),at=c(),je=r("p"),Ll=t("The simplest way to try out your finetuned model for inference is to use it in a "),Ws=r("a"),Nl=t("pipeline()"),Wl=t(". Instantiate a "),ha=r("code"),Hl=t("pipeline"),Yl=t(" for audio classification with your model, and pass your audio file to it:"),tt=c(),$(ks.$$.fragment),lt=c(),Re=r("p"),zl=t("You can also manually replicate the results of the "),da=r("code"),Rl=t("pipeline"),Ul=t(" if you\u2019d like:"),nt=c(),$(Ue.$$.fragment),this.h()},l(e){const n=nr('[data-svelte="svelte-1phssyn"]',document.head);m=o(n,"META",{name:!0,content:!0}),n.forEach(s),k=u(e),f=o(e,"H1",{class:!0});var xs=i(f);g=o(xs,"A",{id:!0,class:!0,href:!0});var _a=i(g);E=o(_a,"SPAN",{});var ga=i(E);v(x.$$.fragment,ga),ga.forEach(s),_a.forEach(s),A=u(xs),q=o(xs,"SPAN",{});var $a=i(q);T=l($a,"Audio classification"),$a.forEach(s),xs.forEach(s),F=u(e),v(I.$$.fragment,e),O=u(e),V=o(e,"P",{});var Bl=i(V);M=l(Bl,"Audio classification - just like with text - assigns a class label output from the input data. The only difference is instead of text inputs, you have raw audio waveforms. Some practical applications of audio classification include identifying speaker intent, language classification, and even animal species by their sounds."),Bl.forEach(s),se=u(e),Y=o(e,"P",{});var Jl=i(Y);X=l(Jl,"This guide will show you how to:"),Jl.forEach(s),ae=u(e),L=o(e,"OL",{});var ot=i(L);P=o(ot,"LI",{});var Hs=i(P);te=l(Hs,"Finetune "),_=o(Hs,"A",{href:!0,rel:!0});var Kl=i(_);C=l(Kl,"Wav2Vec2"),Kl.forEach(s),z=l(Hs," on the "),J=o(Hs,"A",{href:!0,rel:!0});var Ql=i(J);G=l(Ql,"MInDS-14"),Ql.forEach(s),de=l(Hs," dataset to classify speaker intent."),Hs.forEach(s),Ge=u(ot),ue=o(ot,"LI",{});var Xl=i(ue);Be=l(Xl,"Use your finetuned model for inference."),Xl.forEach(s),ot.forEach(s),Ae=u(e),v(le.$$.fragment,e),ne=u(e),_e=o(e,"P",{});var Zl=i(_e);ge=l(Zl,"Before you begin, make sure you have all the necessary libraries installed:"),Zl.forEach(s),qe=u(e),v(me.$$.fragment,e),ye=u(e),K=o(e,"P",{});var en=i(K);Te=l(en,"We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),en.forEach(s),Z=u(e),v(fe.$$.fragment,e),he=u(e),ee=o(e,"H2",{class:!0});var it=i(ee);re=o(it,"A",{id:!0,class:!0,href:!0});var sn=i(re);$e=o(sn,"SPAN",{});var an=i($e);v(B.$$.fragment,an),an.forEach(s),sn.forEach(s),Pe=u(it),d=o(it,"SPAN",{});var tn=i(d);D=l(tn,"Load MInDS-14 dataset"),tn.forEach(s),it.forEach(s),Q=u(e),N=o(e,"P",{});var ln=i(N);Es=l(ln,"Start by loading the MInDS-14 dataset from the \u{1F917} Datasets library:"),ln.forEach(s),Je=u(e),v(ve.$$.fragment,e),Ke=u(e),W=o(e,"P",{});var Ys=i(W);As=l(Ys,"Split the dataset\u2019s "),Ce=o(Ys,"CODE",{});var nn=i(Ce);De=l(nn,"train"),nn.forEach(s),qs=l(Ys," split into a smaller train and test set with the "),oe=o(Ys,"A",{href:!0,rel:!0});var rn=i(oe);Ts=l(rn,"train_test_split"),rn.forEach(s),bt=l(Ys," method. This\u2019ll give you a chance to experiment and make sure everything works before spending more time on the full dataset."),Ys.forEach(s),ba=u(e),v(Qe.$$.fragment,e),ja=u(e),Ps=o(e,"P",{});var on=i(Ps);jt=l(on,"Then take a look at the dataset:"),on.forEach(s),ya=u(e),v(Xe.$$.fragment,e),wa=u(e),R=o(e,"P",{});var pe=i(R);yt=l(pe,"While the dataset contains a lot of useful information, like "),Vs=o(pe,"CODE",{});var pn=i(Vs);wt=l(pn,"lang_id"),pn.forEach(s),kt=l(pe," and "),Gs=o(pe,"CODE",{});var cn=i(Gs);xt=l(cn,"english_transcription"),cn.forEach(s),Et=l(pe,", you\u2019ll focus on the "),Bs=o(pe,"CODE",{});var un=i(Bs);At=l(un,"audio"),un.forEach(s),qt=l(pe," and "),Js=o(pe,"CODE",{});var mn=i(Js);Tt=l(mn,"intent_class"),mn.forEach(s),Pt=l(pe," in this guide. Remove the other columns with the "),Ze=o(pe,"A",{href:!0,rel:!0});var fn=i(Ze);Ct=l(fn,"remove_columns"),fn.forEach(s),Dt=l(pe," method:"),pe.forEach(s),ka=u(e),v(es.$$.fragment,e),xa=u(e),Cs=o(e,"P",{});var hn=i(Cs);St=l(hn,"Take a look at an example now:"),hn.forEach(s),Ea=u(e),v(ss.$$.fragment,e),Aa=u(e),Ds=o(e,"P",{});var dn=i(Ds);It=l(dn,"There are two fields:"),dn.forEach(s),qa=u(e),Se=o(e,"UL",{});var pt=i(Se);Ie=o(pt,"LI",{});var va=i(Ie);Ks=o(va,"CODE",{});var _n=i(Ks);Ft=l(_n,"audio"),_n.forEach(s),Ot=l(va,": a 1-dimensional "),Qs=o(va,"CODE",{});var gn=i(Qs);Mt=l(gn,"array"),gn.forEach(s),Lt=l(va," of the speech signal that must be called to load and resample the audio file."),va.forEach(s),Nt=u(pt),Ss=o(pt,"LI",{});var Vl=i(Ss);Xs=o(Vl,"CODE",{});var $n=i(Xs);Wt=l($n,"intent_class"),$n.forEach(s),Ht=l(Vl,": represents the class id of the speaker\u2019s intent."),Vl.forEach(s),pt.forEach(s),Ta=u(e),Is=o(e,"P",{});var vn=i(Is);Yt=l(vn,"To make it easier for the model to get the label name from the label id, create a dictionary that maps the label name to an integer and vice versa:"),vn.forEach(s),Pa=u(e),v(as.$$.fragment,e),Ca=u(e),Fs=o(e,"P",{});var bn=i(Fs);zt=l(bn,"Now you can convert the label id to a label name:"),bn.forEach(s),Da=u(e),v(ts.$$.fragment,e),Sa=u(e),we=o(e,"H2",{class:!0});var ct=i(we);Fe=o(ct,"A",{id:!0,class:!0,href:!0});var jn=i(Fe);Zs=o(jn,"SPAN",{});var yn=i(Zs);v(ls.$$.fragment,yn),yn.forEach(s),jn.forEach(s),Rt=u(ct),ea=o(ct,"SPAN",{});var wn=i(ea);Ut=l(wn,"Preprocess"),wn.forEach(s),ct.forEach(s),Ia=u(e),Os=o(e,"P",{});var kn=i(Os);Vt=l(kn,"The next step is to load a Wav2Vec2 feature extractor to process the audio signal:"),kn.forEach(s),Fa=u(e),v(ns.$$.fragment,e),Oa=u(e),Oe=o(e,"P",{});var ut=i(Oe);Gt=l(ut,"The MInDS-14 dataset has a sampling rate of 8000khz (you can find this information in it\u2019s "),rs=o(ut,"A",{href:!0,rel:!0});var xn=i(rs);Bt=l(xn,"dataset card"),xn.forEach(s),Jt=l(ut,"), which means you\u2019ll need to resample the dataset to 16000kHz to use the pretrained Wav2Vec2 model:"),ut.forEach(s),Ma=u(e),v(os.$$.fragment,e),La=u(e),Ms=o(e,"P",{});var En=i(Ms);Kt=l(En,"Now create a preprocessing function that:"),En.forEach(s),Na=u(e),be=o(e,"OL",{});var zs=i(be);is=o(zs,"LI",{});var mt=i(is);Qt=l(mt,"Calls the "),sa=o(mt,"CODE",{});var An=i(sa);Xt=l(An,"audio"),An.forEach(s),Zt=l(mt," column to load, and if necessary, resample the audio file."),mt.forEach(s),el=u(zs),ps=o(zs,"LI",{});var ft=i(ps);sl=l(ft,"Checks if the sampling rate of the audio file matches the sampling rate of the audio data a model was pretrained with. You can find this information in the Wav2Vec2 "),cs=o(ft,"A",{href:!0,rel:!0});var qn=i(cs);al=l(qn,"model card"),qn.forEach(s),tl=l(ft,"."),ft.forEach(s),ll=u(zs),aa=o(zs,"LI",{});var Tn=i(aa);nl=l(Tn,"Set a maximum input length to batch longer inputs without truncating them."),Tn.forEach(s),zs.forEach(s),Wa=u(e),v(us.$$.fragment,e),Ha=u(e),U=o(e,"P",{});var ce=i(U);rl=l(ce,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),ms=o(ce,"A",{href:!0,rel:!0});var Pn=i(ms);ol=l(Pn,"map"),Pn.forEach(s),il=l(ce," function. You can speed up "),ta=o(ce,"CODE",{});var Cn=i(ta);pl=l(Cn,"map"),Cn.forEach(s),cl=l(ce," by setting "),la=o(ce,"CODE",{});var Dn=i(la);ul=l(Dn,"batched=True"),Dn.forEach(s),ml=l(ce," to process multiple elements of the dataset at once. Remove the columns you don\u2019t need, and rename "),na=o(ce,"CODE",{});var Sn=i(na);fl=l(Sn,"intent_class"),Sn.forEach(s),hl=l(ce," to "),ra=o(ce,"CODE",{});var In=i(ra);dl=l(In,"label"),In.forEach(s),_l=l(ce," because that\u2019s the name the model expects:"),ce.forEach(s),Ya=u(e),v(fs.$$.fragment,e),za=u(e),ke=o(e,"H2",{class:!0});var ht=i(ke);Me=o(ht,"A",{id:!0,class:!0,href:!0});var Fn=i(Me);oa=o(Fn,"SPAN",{});var On=i(oa);v(hs.$$.fragment,On),On.forEach(s),Fn.forEach(s),gl=u(ht),ia=o(ht,"SPAN",{});var Mn=i(ia);$l=l(Mn,"Evaluate"),Mn.forEach(s),ht.forEach(s),Ra=u(e),ie=o(e,"P",{});var Ve=i(ie);vl=l(Ve,"Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),ds=o(Ve,"A",{href:!0,rel:!0});var Ln=i(ds);bl=l(Ln,"Evaluate"),Ln.forEach(s),jl=l(Ve," library. For this task, load the "),_s=o(Ve,"A",{href:!0,rel:!0});var Nn=i(_s);yl=l(Nn,"accuracy"),Nn.forEach(s),wl=l(Ve," metric (see the \u{1F917} Evaluate "),gs=o(Ve,"A",{href:!0,rel:!0});var Wn=i(gs);kl=l(Wn,"quick tour"),Wn.forEach(s),xl=l(Ve," to learn more about how to load and compute a metric):"),Ve.forEach(s),Ua=u(e),v($s.$$.fragment,e),Va=u(e),Le=o(e,"P",{});var dt=i(Le);El=l(dt,"Then create a function that passes your predictions and labels to "),vs=o(dt,"A",{href:!0,rel:!0});var Hn=i(vs);Al=l(Hn,"compute"),Hn.forEach(s),ql=l(dt," to calculate the accuracy:"),dt.forEach(s),Ga=u(e),v(bs.$$.fragment,e),Ba=u(e),Ne=o(e,"P",{});var _t=i(Ne);Tl=l(_t,"Your "),pa=o(_t,"CODE",{});var Yn=i(pa);Pl=l(Yn,"compute_metrics"),Yn.forEach(s),Cl=l(_t," function is ready to go now, and you\u2019ll return to it when you setup your training."),_t.forEach(s),Ja=u(e),xe=o(e,"H2",{class:!0});var gt=i(xe);We=o(gt,"A",{id:!0,class:!0,href:!0});var zn=i(We);ca=o(zn,"SPAN",{});var Rn=i(ca);v(js.$$.fragment,Rn),Rn.forEach(s),zn.forEach(s),Dl=u(gt),ua=o(gt,"SPAN",{});var Un=i(ua);Sl=l(Un,"Train"),Un.forEach(s),gt.forEach(s),Ka=u(e),v(He.$$.fragment,e),Qa=u(e),v(Ye.$$.fragment,e),Xa=u(e),Ee=o(e,"H2",{class:!0});var $t=i(Ee);ze=o($t,"A",{id:!0,class:!0,href:!0});var Vn=i(ze);ma=o(Vn,"SPAN",{});var Gn=i(ma);v(ys.$$.fragment,Gn),Gn.forEach(s),Vn.forEach(s),Il=u($t),fa=o($t,"SPAN",{});var Bn=i(fa);Fl=l(Bn,"Inference"),Bn.forEach(s),$t.forEach(s),Za=u(e),Ls=o(e,"P",{});var Jn=i(Ls);Ol=l(Jn,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Jn.forEach(s),et=u(e),Ns=o(e,"P",{});var Kn=i(Ns);Ml=l(Kn,"Load an audio file you\u2019d like to run inference on. Remember to resample the sampling rate of the audio file to match the sampling rate of the model if you need to!"),Kn.forEach(s),st=u(e),v(ws.$$.fragment,e),at=u(e),je=o(e,"P",{});var Rs=i(je);Ll=l(Rs,"The simplest way to try out your finetuned model for inference is to use it in a "),Ws=o(Rs,"A",{href:!0});var Qn=i(Ws);Nl=l(Qn,"pipeline()"),Qn.forEach(s),Wl=l(Rs,". Instantiate a "),ha=o(Rs,"CODE",{});var Xn=i(ha);Hl=l(Xn,"pipeline"),Xn.forEach(s),Yl=l(Rs," for audio classification with your model, and pass your audio file to it:"),Rs.forEach(s),tt=u(e),v(ks.$$.fragment,e),lt=u(e),Re=o(e,"P",{});var vt=i(Re);zl=l(vt,"You can also manually replicate the results of the "),da=o(vt,"CODE",{});var Zn=i(da);Rl=l(Zn,"pipeline"),Zn.forEach(s),Ul=l(vt," if you\u2019d like:"),vt.forEach(s),nt=u(e),v(Ue.$$.fragment,e),this.h()},h(){h(m,"name","hf:doc:metadata"),h(m,"content",JSON.stringify(gr)),h(g,"id","audio-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","#audio-classification"),h(f,"class","relative group"),h(_,"href","https://huggingface.co/facebook/wav2vec2-base"),h(_,"rel","nofollow"),h(J,"href","https://huggingface.co/datasets/PolyAI/minds14"),h(J,"rel","nofollow"),h(re,"id","load-minds14-dataset"),h(re,"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(re,"href","#load-minds14-dataset"),h(ee,"class","relative group"),h(oe,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.train_test_split"),h(oe,"rel","nofollow"),h(Ze,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.remove_columns"),h(Ze,"rel","nofollow"),h(Fe,"id","preprocess"),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","#preprocess"),h(we,"class","relative group"),h(rs,"href","https://huggingface.co/datasets/PolyAI/minds14"),h(rs,"rel","nofollow"),h(cs,"href","https://huggingface.co/facebook/wav2vec2-base"),h(cs,"rel","nofollow"),h(ms,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.map"),h(ms,"rel","nofollow"),h(Me,"id","evaluate"),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","#evaluate"),h(ke,"class","relative group"),h(ds,"href","https://huggingface.co/docs/evaluate/index"),h(ds,"rel","nofollow"),h(_s,"href","https://huggingface.co/spaces/evaluate-metric/accuracy"),h(_s,"rel","nofollow"),h(gs,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),h(gs,"rel","nofollow"),h(vs,"href","https://huggingface.co/docs/evaluate/v0.3.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),h(vs,"rel","nofollow"),h(We,"id","train"),h(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"),h(We,"href","#train"),h(xe,"class","relative group"),h(ze,"id","inference"),h(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"),h(ze,"href","#inference"),h(Ee,"class","relative group"),h(Ws,"href","/docs/transformers/v4.25.1/en/main_classes/pipelines#transformers.pipeline")},m(e,n){a(document.head,m),p(e,k,n),p(e,f,n),a(f,g),a(g,E),b(x,E,null),a(f,A),a(f,q),a(q,T),p(e,F,n),b(I,e,n),p(e,O,n),p(e,V,n),a(V,M),p(e,se,n),p(e,Y,n),a(Y,X),p(e,ae,n),p(e,L,n),a(L,P),a(P,te),a(P,_),a(_,C),a(P,z),a(P,J),a(J,G),a(P,de),a(L,Ge),a(L,ue),a(ue,Be),p(e,Ae,n),b(le,e,n),p(e,ne,n),p(e,_e,n),a(_e,ge),p(e,qe,n),b(me,e,n),p(e,ye,n),p(e,K,n),a(K,Te),p(e,Z,n),b(fe,e,n),p(e,he,n),p(e,ee,n),a(ee,re),a(re,$e),b(B,$e,null),a(ee,Pe),a(ee,d),a(d,D),p(e,Q,n),p(e,N,n),a(N,Es),p(e,Je,n),b(ve,e,n),p(e,Ke,n),p(e,W,n),a(W,As),a(W,Ce),a(Ce,De),a(W,qs),a(W,oe),a(oe,Ts),a(W,bt),p(e,ba,n),b(Qe,e,n),p(e,ja,n),p(e,Ps,n),a(Ps,jt),p(e,ya,n),b(Xe,e,n),p(e,wa,n),p(e,R,n),a(R,yt),a(R,Vs),a(Vs,wt),a(R,kt),a(R,Gs),a(Gs,xt),a(R,Et),a(R,Bs),a(Bs,At),a(R,qt),a(R,Js),a(Js,Tt),a(R,Pt),a(R,Ze),a(Ze,Ct),a(R,Dt),p(e,ka,n),b(es,e,n),p(e,xa,n),p(e,Cs,n),a(Cs,St),p(e,Ea,n),b(ss,e,n),p(e,Aa,n),p(e,Ds,n),a(Ds,It),p(e,qa,n),p(e,Se,n),a(Se,Ie),a(Ie,Ks),a(Ks,Ft),a(Ie,Ot),a(Ie,Qs),a(Qs,Mt),a(Ie,Lt),a(Se,Nt),a(Se,Ss),a(Ss,Xs),a(Xs,Wt),a(Ss,Ht),p(e,Ta,n),p(e,Is,n),a(Is,Yt),p(e,Pa,n),b(as,e,n),p(e,Ca,n),p(e,Fs,n),a(Fs,zt),p(e,Da,n),b(ts,e,n),p(e,Sa,n),p(e,we,n),a(we,Fe),a(Fe,Zs),b(ls,Zs,null),a(we,Rt),a(we,ea),a(ea,Ut),p(e,Ia,n),p(e,Os,n),a(Os,Vt),p(e,Fa,n),b(ns,e,n),p(e,Oa,n),p(e,Oe,n),a(Oe,Gt),a(Oe,rs),a(rs,Bt),a(Oe,Jt),p(e,Ma,n),b(os,e,n),p(e,La,n),p(e,Ms,n),a(Ms,Kt),p(e,Na,n),p(e,be,n),a(be,is),a(is,Qt),a(is,sa),a(sa,Xt),a(is,Zt),a(be,el),a(be,ps),a(ps,sl),a(ps,cs),a(cs,al),a(ps,tl),a(be,ll),a(be,aa),a(aa,nl),p(e,Wa,n),b(us,e,n),p(e,Ha,n),p(e,U,n),a(U,rl),a(U,ms),a(ms,ol),a(U,il),a(U,ta),a(ta,pl),a(U,cl),a(U,la),a(la,ul),a(U,ml),a(U,na),a(na,fl),a(U,hl),a(U,ra),a(ra,dl),a(U,_l),p(e,Ya,n),b(fs,e,n),p(e,za,n),p(e,ke,n),a(ke,Me),a(Me,oa),b(hs,oa,null),a(ke,gl),a(ke,ia),a(ia,$l),p(e,Ra,n),p(e,ie,n),a(ie,vl),a(ie,ds),a(ds,bl),a(ie,jl),a(ie,_s),a(_s,yl),a(ie,wl),a(ie,gs),a(gs,kl),a(ie,xl),p(e,Ua,n),b($s,e,n),p(e,Va,n),p(e,Le,n),a(Le,El),a(Le,vs),a(vs,Al),a(Le,ql),p(e,Ga,n),b(bs,e,n),p(e,Ba,n),p(e,Ne,n),a(Ne,Tl),a(Ne,pa),a(pa,Pl),a(Ne,Cl),p(e,Ja,n),p(e,xe,n),a(xe,We),a(We,ca),b(js,ca,null),a(xe,Dl),a(xe,ua),a(ua,Sl),p(e,Ka,n),b(He,e,n),p(e,Qa,n),b(Ye,e,n),p(e,Xa,n),p(e,Ee,n),a(Ee,ze),a(ze,ma),b(ys,ma,null),a(Ee,Il),a(Ee,fa),a(fa,Fl),p(e,Za,n),p(e,Ls,n),a(Ls,Ol),p(e,et,n),p(e,Ns,n),a(Ns,Ml),p(e,st,n),b(ws,e,n),p(e,at,n),p(e,je,n),a(je,Ll),a(je,Ws),a(Ws,Nl),a(je,Wl),a(je,ha),a(ha,Hl),a(je,Yl),p(e,tt,n),b(ks,e,n),p(e,lt,n),p(e,Re,n),a(Re,zl),a(Re,da),a(da,Rl),a(Re,Ul),p(e,nt,n),b(Ue,e,n),rt=!0},p(e,[n]){const xs={};n&2&&(xs.$$scope={dirty:n,ctx:e}),le.$set(xs);const _a={};n&2&&(_a.$$scope={dirty:n,ctx:e}),He.$set(_a);const ga={};n&2&&(ga.$$scope={dirty:n,ctx:e}),Ye.$set(ga);const $a={};n&2&&($a.$$scope={dirty:n,ctx:e}),Ue.$set($a)},i(e){rt||(j(x.$$.fragment,e),j(I.$$.fragment,e),j(le.$$.fragment,e),j(me.$$.fragment,e),j(fe.$$.fragment,e),j(B.$$.fragment,e),j(ve.$$.fragment,e),j(Qe.$$.fragment,e),j(Xe.$$.fragment,e),j(es.$$.fragment,e),j(ss.$$.fragment,e),j(as.$$.fragment,e),j(ts.$$.fragment,e),j(ls.$$.fragment,e),j(ns.$$.fragment,e),j(os.$$.fragment,e),j(us.$$.fragment,e),j(fs.$$.fragment,e),j(hs.$$.fragment,e),j($s.$$.fragment,e),j(bs.$$.fragment,e),j(js.$$.fragment,e),j(He.$$.fragment,e),j(Ye.$$.fragment,e),j(ys.$$.fragment,e),j(ws.$$.fragment,e),j(ks.$$.fragment,e),j(Ue.$$.fragment,e),rt=!0)},o(e){y(x.$$.fragment,e),y(I.$$.fragment,e),y(le.$$.fragment,e),y(me.$$.fragment,e),y(fe.$$.fragment,e),y(B.$$.fragment,e),y(ve.$$.fragment,e),y(Qe.$$.fragment,e),y(Xe.$$.fragment,e),y(es.$$.fragment,e),y(ss.$$.fragment,e),y(as.$$.fragment,e),y(ts.$$.fragment,e),y(ls.$$.fragment,e),y(ns.$$.fragment,e),y(os.$$.fragment,e),y(us.$$.fragment,e),y(fs.$$.fragment,e),y(hs.$$.fragment,e),y($s.$$.fragment,e),y(bs.$$.fragment,e),y(js.$$.fragment,e),y(He.$$.fragment,e),y(Ye.$$.fragment,e),y(ys.$$.fragment,e),y(ws.$$.fragment,e),y(ks.$$.fragment,e),y(Ue.$$.fragment,e),rt=!1},d(e){s(m),e&&s(k),e&&s(f),w(x),e&&s(F),w(I,e),e&&s(O),e&&s(V),e&&s(se),e&&s(Y),e&&s(ae),e&&s(L),e&&s(Ae),w(le,e),e&&s(ne),e&&s(_e),e&&s(qe),w(me,e),e&&s(ye),e&&s(K),e&&s(Z),w(fe,e),e&&s(he),e&&s(ee),w(B),e&&s(Q),e&&s(N),e&&s(Je),w(ve,e),e&&s(Ke),e&&s(W),e&&s(ba),w(Qe,e),e&&s(ja),e&&s(Ps),e&&s(ya),w(Xe,e),e&&s(wa),e&&s(R),e&&s(ka),w(es,e),e&&s(xa),e&&s(Cs),e&&s(Ea),w(ss,e),e&&s(Aa),e&&s(Ds),e&&s(qa),e&&s(Se),e&&s(Ta),e&&s(Is),e&&s(Pa),w(as,e),e&&s(Ca),e&&s(Fs),e&&s(Da),w(ts,e),e&&s(Sa),e&&s(we),w(ls),e&&s(Ia),e&&s(Os),e&&s(Fa),w(ns,e),e&&s(Oa),e&&s(Oe),e&&s(Ma),w(os,e),e&&s(La),e&&s(Ms),e&&s(Na),e&&s(be),e&&s(Wa),w(us,e),e&&s(Ha),e&&s(U),e&&s(Ya),w(fs,e),e&&s(za),e&&s(ke),w(hs),e&&s(Ra),e&&s(ie),e&&s(Ua),w($s,e),e&&s(Va),e&&s(Le),e&&s(Ga),w(bs,e),e&&s(Ba),e&&s(Ne),e&&s(Ja),e&&s(xe),w(js),e&&s(Ka),w(He,e),e&&s(Qa),w(Ye,e),e&&s(Xa),e&&s(Ee),w(ys),e&&s(Za),e&&s(Ls),e&&s(et),e&&s(Ns),e&&s(st),w(ws,e),e&&s(at),e&&s(je),e&&s(tt),w(ks,e),e&&s(lt),e&&s(Re),e&&s(nt),w(Ue,e)}}}const gr={local:"audio-classification",sections:[{local:"load-minds14-dataset",title:"Load MInDS-14 dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Audio classification"};function $r(H){return rr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xr extends ar{constructor(m){super();tr(this,m,$r,_r,lr,{})}}export{xr as default,gr as metadata};
