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