import{s as $t,n as wt,o as bt}from"../chunks/scheduler.f7e1785c.js";import{S as gt,i as qt,g as p,s as n,r as u,A as Ct,h as i,f as e,c as a,j as dt,u as o,x as m,k as Ut,y as It,a as l,v as r,d as c,t as y,w as f}from"../chunks/index.9f8f0838.js";import{C as W}from"../chunks/CodeBlock.b3510e34.js";import{H as xt,E as _t}from"../chunks/EditOnGithub.5a9bb8c5.js";function vt(mt){let M,Z,E,Q,J,F,T,Mt="音频分类任务需要根据音频的内容对其进行单个和多个标签的识别。这些标签可以代表不同的声音类别，如音乐、语音或噪音，也可以代表更细分的分类，如鸟叫声和引擎声等。",B,j,ut="在深入了解音频Transformer的细节和微调（fine-tuning）之前，我们先来看看如何使用🤗 Transformers和现成的预训练模型，在几行代码中构建一个音频分类器。",R,h,ot='我们使用和前几个单元相同的<a href="https://huggingface.co/datasets/PolyAI/minds14" rel="nofollow">MINDS-14</a> 数据集。回忆一下，MINDS-14数据集的内容是许多不同语言和方言的使用者向一个网银系统提问的录音。其标签包含了<code>intent_class</code>，记录了该次对话的目的。dataset that you have explored',D,d,rt="和之前一样，我们先加载<code>en-AU</code>子集来测试我们的pipeline，将其上采样至音频模型常见的16千赫兹采样率。",S,U,H,$,ct="我们可以使用🤗 Transformers中的<code>audio-classification</code> pipeline来构建一个将音频分入一个类别集的任务。在我们的设定下，我们需要一个已经针对音频的目的分类在MINDS-14数据集上微调过的模型。运气好的是，在🤗 Hub中已经有了一个这样的模型！让我们使用<code>pipeline()</code>函数来加载该模型：",L,w,P,b,yt="这个pipeline需要以NumPy数组形式输入的音频数据。对于原始音频数据的预处理操作则已经包含在了该pipeline中。让我们拿一个样本来测试一下：",V,g,X,q,ft="回忆一下数据集的结构，我们的原始音频数据是以NumPy数组的形式存储在<code>[&quot;audio&quot;][&quot;array&quot;]</code>中的。我们将其直接传递给<code>classifier</code>:",Y,C,O,I,Jt="<strong>输出：</strong>",K,x,tt,_,Tt="模型非常确信，在这个样本中，顾客的目的是了解关于账单的信息。让我们来看看该样本的真实标签：",st,v,et,z,jt="<strong>输出</strong>",lt,k,nt,A,ht="好耶！模型预测正确！我们很幸运地找到了一个预测标签和我们需要的标签完全相同的预训练模型。很多时候，我们所找的预训练模型可以预测的标签集和我们所需要的标签集不会完全相同。这种情况下，我们需要对该预训练模型进行微调（fine-tuning），来将其“校准”到我们需要的标签集上。我们在接下来的单元中会学到微调相关的知识。现在，我们来看看另一个语音处理中常见的任务，<em>自动语音识别</em>。",at,N,pt,G,it;return J=new xt({props:{title:"利用pipeline进行音频分类",local:"利用pipeline进行音频分类",headingTag:"h1"}}),U=new W({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}}),w=new W({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}}),g=new W({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RA==",highlighted:'example = minds[<span class="hljs-number">0</span>]',wrap:!1}}),C=new W({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 W({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 W({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}}),k=new W({props:{code:"JTIycGF5X2JpbGwlMjI=",highlighted:'<span class="hljs-string">&quot;pay_bill&quot;</span>',wrap:!1}}),N=new _t({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/zh-CN/chapter2/audio_classification_pipeline.mdx"}}),{c(){M=p("meta"),Z=n(),E=p("p"),Q=n(),u(J.$$.fragment),F=n(),T=p("p"),T.textContent=Mt,B=n(),j=p("p"),j.textContent=ut,R=n(),h=p("p"),h.innerHTML=ot,D=n(),d=p("p"),d.innerHTML=rt,S=n(),u(U.$$.fragment),H=n(),$=p("p"),$.innerHTML=ct,L=n(),u(w.$$.fragment),P=n(),b=p("p"),b.textContent=yt,V=n(),u(g.$$.fragment),X=n(),q=p("p"),q.innerHTML=ft,Y=n(),u(C.$$.fragment),O=n(),I=p("p"),I.innerHTML=Jt,K=n(),u(x.$$.fragment),tt=n(),_=p("p"),_.textContent=Tt,st=n(),u(v.$$.fragment),et=n(),z=p("p"),z.innerHTML=jt,lt=n(),u(k.$$.fragment),nt=n(),A=p("p"),A.innerHTML=ht,at=n(),u(N.$$.fragment),pt=n(),G=p("p"),this.h()},l(t){const s=Ct("svelte-u9bgzb",document.head);M=i(s,"META",{name:!0,content:!0}),s.forEach(e),Z=a(t),E=i(t,"P",{}),dt(E).forEach(e),Q=a(t),o(J.$$.fragment,t),F=a(t),T=i(t,"P",{"data-svelte-h":!0}),m(T)!=="svelte-1vq11ga"&&(T.textContent=Mt),B=a(t),j=i(t,"P",{"data-svelte-h":!0}),m(j)!=="svelte-ui5ngh"&&(j.textContent=ut),R=a(t),h=i(t,"P",{"data-svelte-h":!0}),m(h)!=="svelte-8v6uxl"&&(h.innerHTML=ot),D=a(t),d=i(t,"P",{"data-svelte-h":!0}),m(d)!=="svelte-owzqsv"&&(d.innerHTML=rt),S=a(t),o(U.$$.fragment,t),H=a(t),$=i(t,"P",{"data-svelte-h":!0}),m($)!=="svelte-gmemzv"&&($.innerHTML=ct),L=a(t),o(w.$$.fragment,t),P=a(t),b=i(t,"P",{"data-svelte-h":!0}),m(b)!=="svelte-kl1p6b"&&(b.textContent=yt),V=a(t),o(g.$$.fragment,t),X=a(t),q=i(t,"P",{"data-svelte-h":!0}),m(q)!=="svelte-13l7u95"&&(q.innerHTML=ft),Y=a(t),o(C.$$.fragment,t),O=a(t),I=i(t,"P",{"data-svelte-h":!0}),m(I)!=="svelte-1yevus4"&&(I.innerHTML=Jt),K=a(t),o(x.$$.fragment,t),tt=a(t),_=i(t,"P",{"data-svelte-h":!0}),m(_)!=="svelte-zv0vxn"&&(_.textContent=Tt),st=a(t),o(v.$$.fragment,t),et=a(t),z=i(t,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1n6w44y"&&(z.innerHTML=jt),lt=a(t),o(k.$$.fragment,t),nt=a(t),A=i(t,"P",{"data-svelte-h":!0}),m(A)!=="svelte-1b182kz"&&(A.innerHTML=ht),at=a(t),o(N.$$.fragment,t),pt=a(t),G=i(t,"P",{}),dt(G).forEach(e),this.h()},h(){Ut(M,"name","hf:doc:metadata"),Ut(M,"content",zt)},m(t,s){It(document.head,M),l(t,Z,s),l(t,E,s),l(t,Q,s),r(J,t,s),l(t,F,s),l(t,T,s),l(t,B,s),l(t,j,s),l(t,R,s),l(t,h,s),l(t,D,s),l(t,d,s),l(t,S,s),r(U,t,s),l(t,H,s),l(t,$,s),l(t,L,s),r(w,t,s),l(t,P,s),l(t,b,s),l(t,V,s),r(g,t,s),l(t,X,s),l(t,q,s),l(t,Y,s),r(C,t,s),l(t,O,s),l(t,I,s),l(t,K,s),r(x,t,s),l(t,tt,s),l(t,_,s),l(t,st,s),r(v,t,s),l(t,et,s),l(t,z,s),l(t,lt,s),r(k,t,s),l(t,nt,s),l(t,A,s),l(t,at,s),r(N,t,s),l(t,pt,s),l(t,G,s),it=!0},p:wt,i(t){it||(c(J.$$.fragment,t),c(U.$$.fragment,t),c(w.$$.fragment,t),c(g.$$.fragment,t),c(C.$$.fragment,t),c(x.$$.fragment,t),c(v.$$.fragment,t),c(k.$$.fragment,t),c(N.$$.fragment,t),it=!0)},o(t){y(J.$$.fragment,t),y(U.$$.fragment,t),y(w.$$.fragment,t),y(g.$$.fragment,t),y(C.$$.fragment,t),y(x.$$.fragment,t),y(v.$$.fragment,t),y(k.$$.fragment,t),y(N.$$.fragment,t),it=!1},d(t){t&&(e(Z),e(E),e(Q),e(F),e(T),e(B),e(j),e(R),e(h),e(D),e(d),e(S),e(H),e($),e(L),e(P),e(b),e(V),e(X),e(q),e(Y),e(O),e(I),e(K),e(tt),e(_),e(st),e(et),e(z),e(lt),e(nt),e(A),e(at),e(pt),e(G)),e(M),f(J,t),f(U,t),f(w,t),f(g,t),f(C,t),f(x,t),f(v,t),f(k,t),f(N,t)}}}const zt='{"title":"利用pipeline进行音频分类","local":"利用pipeline进行音频分类","sections":[],"depth":1}';function kt(mt){return bt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Gt extends gt{constructor(M){super(),qt(this,M,kt,vt,$t,{})}}export{Gt as component};
