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