import{s as be,n as ge,o as Ue}from"../chunks/scheduler.f7e1785c.js";import{S as $e,i as Ie,g as i,s as l,r as c,A as qe,h as o,f as s,c as n,j as Je,u,x as p,k as je,y as Ce,a,v as m,d,t as h,w as f}from"../chunks/index.9f8f0838.js";import{C as N}from"../chunks/CodeBlock.4baef5d7.js";import{H as xe,E as ke}from"../chunks/getInferenceSnippets.ba5f4cd0.js";function ve(pe){let r,Z,E,Q,M,F,y,re=`Audio classification involves assigning one or more labels to an audio recording based on its content. The labels
could correspond to different sound categories, such as music, speech, or noise, or more specific categories like
bird song or car engine sounds.`,B,T,ce=`Before diving into details on how the most popular audio transformers work, and before fine-tuning a custom model, let’s
see how you can use an off-the-shelf pre-trained model for audio classification with only a few lines of code with 🤗 Transformers.`,R,w,ue=`Let’s go ahead and use the same <a href="https://huggingface.co/datasets/PolyAI/minds14" rel="nofollow">MINDS-14</a> dataset that you have explored
in the previous unit. If you recall, MINDS-14 contains recordings of people asking an e-banking system questions in several
languages and dialects, and has the <code>intent_class</code> for each recording. We can classify the recordings by intent of the call.`,L,J,me=`Just as before, let’s start by loading the <code>en-AU</code> subset of the data to try out the pipeline, and upsample it to 16kHz
sampling rate which is what most speech models require.`,H,j,D,b,de=`To classify an audio recording into a set of classes, we can use the <code>audio-classification</code> pipeline from 🤗 Transformers.
In our case, we need a model that’s been fine-tuned for intent classification, and specifically on
the MINDS-14 dataset. Luckily for us, the Hub has a model that does just that! Let’s load it by using the <code>pipeline()</code> function:`,S,g,P,U,he=`This pipeline expects the audio data as a NumPy array. All the preprocessing of the raw audio data will be conveniently
handled for us by the pipeline. Let’s pick an example to try it out:`,V,$,X,I,fe=`If you recall the structure of the dataset, the raw audio data is stored in a NumPy array under <code>[&quot;audio&quot;][&quot;array&quot;]</code>, let’s
pass it straight to the <code>classifier</code>:`,Y,q,O,C,Me="<strong>Output:</strong>",K,x,ee,k,ye=`The model is very confident that the caller intended to learn about paying their bill. Let’s see what the actual label for
this example is:`,te,v,se,_,Te="<strong>Output:</strong>",ae,z,le,A,we=`Hooray! The predicted label was correct! Here we were lucky to find a model that can classify the exact labels that we need.
A lot of the times, when dealing with a classification task, a pre-trained model’s set of classes is not exactly the same
as the classes you need the model to distinguish. In this case, you can fine-tune a pre-trained model to “calibrate” it to
your exact set of class labels. We’ll learn how to do this in the upcoming units. Now, let’s take a look at another very
common task in speech processing, <em>automatic speech recognition</em>.`,ne,W,ie,G,oe;return M=new xe({props:{title:"Audio classification with a pipeline",local:"audio-classification-with-a-pipeline",headingTag:"h1"}}),j=new N({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwQXVkaW8lMEElMEFtaW5kcyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJQb2x5QUklMkZtaW5kczE0JTIyJTJDJTIwbmFtZSUzRCUyMmVuLUFVJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFtaW5kcyUyMCUzRCUyMG1pbmRzLmNhc3RfY29sdW1uKCUyMmF1ZGlvJTIyJTJDJTIwQXVkaW8oc2FtcGxpbmdfcmF0ZSUzRDE2XzAwMCkp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Audio

minds = load_dataset(<span class="hljs-string">&quot;PolyAI/minds14&quot;</span>, name=<span class="hljs-string">&quot;en-AU&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
minds = minds.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16_000</span>))`,wrap:!1}}),g=new N({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMCUyMmF1ZGlvLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0QlMjJhbnRvbi1sJTJGeHRyZW1lX3NfeGxzcl8zMDBtX21pbmRzMTQlMjIlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

classifier = pipeline(
    <span class="hljs-string">&quot;audio-classification&quot;</span>,
    model=<span class="hljs-string">&quot;anton-l/xtreme_s_xlsr_300m_minds14&quot;</span>,
)`,wrap:!1}}),$=new N({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RA==",highlighted:'example = minds[<span class="hljs-number">0</span>]',wrap:!1}}),q=new N({props:{code:"Y2xhc3NpZmllcihleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlNUIlMjJhcnJheSUyMiU1RCk=",highlighted:'classifier(example[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>])',wrap:!1}}),x=new N({props:{code:"JTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIyc2NvcmUlMjIlM0ElMjAwLjk2MzE1MjUyNzgwOTE0MzElMkMlMjAlMjJsYWJlbCUyMiUzQSUyMCUyMnBheV9iaWxsJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIyc2NvcmUlMjIlM0ElMjAwLjAyODE5Njk4MzAzOTM3OTEyJTJDJTIwJTIybGFiZWwlMjIlM0ElMjAlMjJmcmVlemUlMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJzY29yZSUyMiUzQSUyMDAuMDAzMjc4NzQ5Mjk2NDQxNjc0MiUyQyUyMCUyMmxhYmVsJTIyJTNBJTIwJTIyY2FyZF9pc3N1ZXMlMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJzY29yZSUyMiUzQSUyMDAuMDAxOTQxNDQ0NTg1MDk5ODE2MyUyQyUyMCUyMmxhYmVsJTIyJTNBJTIwJTIyYWJyb2FkJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIyc2NvcmUlMjIlM0ElMjAwLjAwMDgzNzg2OTM2MDExMTY1MzglMkMlMjAlMjJsYWJlbCUyMiUzQSUyMCUyMmhpZ2hfdmFsdWVfcGF5bWVudCUyMiU3RCUyQyUwQSU1RA==",highlighted:`[
    {<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-number">0.9631525278091431</span>, <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-string">&quot;pay_bill&quot;</span>},
    {<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-number">0.02819698303937912</span>, <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-string">&quot;freeze&quot;</span>},
    {<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-number">0.0032787492964416742</span>, <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-string">&quot;card_issues&quot;</span>},
    {<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-number">0.0019414445850998163</span>, <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-string">&quot;abroad&quot;</span>},
    {<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-number">0.0008378693601116538</span>, <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-string">&quot;high_value_payment&quot;</span>},
]`,wrap:!1}}),v=new N({props:{code:"aWQybGFiZWwlMjAlM0QlMjBtaW5kcy5mZWF0dXJlcyU1QiUyMmludGVudF9jbGFzcyUyMiU1RC5pbnQyc3RyJTBBaWQybGFiZWwoZXhhbXBsZSU1QiUyMmludGVudF9jbGFzcyUyMiU1RCk=",highlighted:`id2label = minds.features[<span class="hljs-string">&quot;intent_class&quot;</span>].int2str
id2label(example[<span class="hljs-string">&quot;intent_class&quot;</span>])`,wrap:!1}}),z=new N({props:{code:"JTIycGF5X2JpbGwlMjI=",highlighted:'<span class="hljs-string">&quot;pay_bill&quot;</span>',wrap:!1}}),W=new ke({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter2/audio_classification_pipeline.mdx"}}),{c(){r=i("meta"),Z=l(),E=i("p"),Q=l(),c(M.$$.fragment),F=l(),y=i("p"),y.textContent=re,B=l(),T=i("p"),T.textContent=ce,R=l(),w=i("p"),w.innerHTML=ue,L=l(),J=i("p"),J.innerHTML=me,H=l(),c(j.$$.fragment),D=l(),b=i("p"),b.innerHTML=de,S=l(),c(g.$$.fragment),P=l(),U=i("p"),U.textContent=he,V=l(),c($.$$.fragment),X=l(),I=i("p"),I.innerHTML=fe,Y=l(),c(q.$$.fragment),O=l(),C=i("p"),C.innerHTML=Me,K=l(),c(x.$$.fragment),ee=l(),k=i("p"),k.textContent=ye,te=l(),c(v.$$.fragment),se=l(),_=i("p"),_.innerHTML=Te,ae=l(),c(z.$$.fragment),le=l(),A=i("p"),A.innerHTML=we,ne=l(),c(W.$$.fragment),ie=l(),G=i("p"),this.h()},l(e){const t=qe("svelte-u9bgzb",document.head);r=o(t,"META",{name:!0,content:!0}),t.forEach(s),Z=n(e),E=o(e,"P",{}),Je(E).forEach(s),Q=n(e),u(M.$$.fragment,e),F=n(e),y=o(e,"P",{"data-svelte-h":!0}),p(y)!=="svelte-j9r3i6"&&(y.textContent=re),B=n(e),T=o(e,"P",{"data-svelte-h":!0}),p(T)!=="svelte-dub6at"&&(T.textContent=ce),R=n(e),w=o(e,"P",{"data-svelte-h":!0}),p(w)!=="svelte-1jsn8wa"&&(w.innerHTML=ue),L=n(e),J=o(e,"P",{"data-svelte-h":!0}),p(J)!=="svelte-15x65jw"&&(J.innerHTML=me),H=n(e),u(j.$$.fragment,e),D=n(e),b=o(e,"P",{"data-svelte-h":!0}),p(b)!=="svelte-1gi5ja6"&&(b.innerHTML=de),S=n(e),u(g.$$.fragment,e),P=n(e),U=o(e,"P",{"data-svelte-h":!0}),p(U)!=="svelte-h7hari"&&(U.textContent=he),V=n(e),u($.$$.fragment,e),X=n(e),I=o(e,"P",{"data-svelte-h":!0}),p(I)!=="svelte-nl73ko"&&(I.innerHTML=fe),Y=n(e),u(q.$$.fragment,e),O=n(e),C=o(e,"P",{"data-svelte-h":!0}),p(C)!=="svelte-1mvdyro"&&(C.innerHTML=Me),K=n(e),u(x.$$.fragment,e),ee=n(e),k=o(e,"P",{"data-svelte-h":!0}),p(k)!=="svelte-1xhxyyp"&&(k.textContent=ye),te=n(e),u(v.$$.fragment,e),se=n(e),_=o(e,"P",{"data-svelte-h":!0}),p(_)!=="svelte-1mvdyro"&&(_.innerHTML=Te),ae=n(e),u(z.$$.fragment,e),le=n(e),A=o(e,"P",{"data-svelte-h":!0}),p(A)!=="svelte-66lxjm"&&(A.innerHTML=we),ne=n(e),u(W.$$.fragment,e),ie=n(e),G=o(e,"P",{}),Je(G).forEach(s),this.h()},h(){je(r,"name","hf:doc:metadata"),je(r,"content",_e)},m(e,t){Ce(document.head,r),a(e,Z,t),a(e,E,t),a(e,Q,t),m(M,e,t),a(e,F,t),a(e,y,t),a(e,B,t),a(e,T,t),a(e,R,t),a(e,w,t),a(e,L,t),a(e,J,t),a(e,H,t),m(j,e,t),a(e,D,t),a(e,b,t),a(e,S,t),m(g,e,t),a(e,P,t),a(e,U,t),a(e,V,t),m($,e,t),a(e,X,t),a(e,I,t),a(e,Y,t),m(q,e,t),a(e,O,t),a(e,C,t),a(e,K,t),m(x,e,t),a(e,ee,t),a(e,k,t),a(e,te,t),m(v,e,t),a(e,se,t),a(e,_,t),a(e,ae,t),m(z,e,t),a(e,le,t),a(e,A,t),a(e,ne,t),m(W,e,t),a(e,ie,t),a(e,G,t),oe=!0},p:ge,i(e){oe||(d(M.$$.fragment,e),d(j.$$.fragment,e),d(g.$$.fragment,e),d($.$$.fragment,e),d(q.$$.fragment,e),d(x.$$.fragment,e),d(v.$$.fragment,e),d(z.$$.fragment,e),d(W.$$.fragment,e),oe=!0)},o(e){h(M.$$.fragment,e),h(j.$$.fragment,e),h(g.$$.fragment,e),h($.$$.fragment,e),h(q.$$.fragment,e),h(x.$$.fragment,e),h(v.$$.fragment,e),h(z.$$.fragment,e),h(W.$$.fragment,e),oe=!1},d(e){e&&(s(Z),s(E),s(Q),s(F),s(y),s(B),s(T),s(R),s(w),s(L),s(J),s(H),s(D),s(b),s(S),s(P),s(U),s(V),s(X),s(I),s(Y),s(O),s(C),s(K),s(ee),s(k),s(te),s(se),s(_),s(ae),s(le),s(A),s(ne),s(ie),s(G)),s(r),f(M,e),f(j,e),f(g,e),f($,e),f(q,e),f(x,e),f(v,e),f(z,e),f(W,e)}}}const _e='{"title":"Audio classification with a pipeline","local":"audio-classification-with-a-pipeline","sections":[],"depth":1}';function ze(pe){return Ue(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ge extends $e{constructor(r){super(),Ie(this,r,ze,ve,be,{})}}export{Ge as component};
