import{S as fs,i as ms,s as cs,e as l,k as u,w as c,t as r,M as hs,c as o,d as t,m as f,a as n,x as h,h as p,b as $,G as i,g as a,y,L as ys,q as d,o as w,B as b,v as ds}from"../../chunks/vendor-hf-doc-builder.js";import{I as ws}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as g}from"../../chunks/CodeBlock-hf-doc-builder.js";function bs(xt){let M,de,U,T,ie,G,De,ae,Qe,we,V,Ke,be,J,et,le,tt,st,ve,k,it,F,at,lt,ge,I,ot,oe,nt,rt,Me,_,Ue,z,pt,$e,S,Te,X,ne,ut,Je,j,ke,Y,ft,Ie,C,Ee,P,re,mt,Ge,R,_e,L,ct,Se,v,ht,x,yt,dt,pe,wt,bt,je,O,vt,Ce,q,Re,H,gt,xe,W,qe,D,ue,Mt,We,Z,Ze,Q,Ut,Ne,N,Be,K,fe,$t,Ae,B,Ve,ee,Tt,Fe,te,Jt,ze,m,me,kt,It,ce,Et,Gt,he,_t,St,A,jt,ye,Ct,Rt,Xe;return G=new ws({}),_=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBYXNyJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXV0b21hdGljLXNwZWVjaC1yZWNvZ25pdGlvbiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

asr = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>)`}}),S=new g({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RCUwQWFzcihleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlNUIlMjJhcnJheSUyMiU1RCk=",highlighted:`example = minds[<span class="hljs-number">0</span>]
asr(example[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>])`}}),j=new g({props:{code:"JTdCJTIydGV4dCUyMiUzQSUyMCUyMkklMjBXT1VMRCUyMExJS0UlMjBUTyUyMFBBWSUyME1ZJTIwRUxFQ1RSSUNJVFklMjBCSUxMJTIwVVNJTkclMjBNWSUyMENPRCUyMENBTiUyMFlPVSUyMFBMRUFTRSUyMEFTU0lTVCUyMiU3RA==",highlighted:'<span class="hljs-comment">{&quot;text&quot;: &quot;I WOULD LIKE TO PAY MY ELECTRICITY BILL USING MY COD CAN YOU PLEASE ASSIST&quot;}</span>'}}),C=new g({props:{code:"ZXhhbXBsZSU1QiUyMmVuZ2xpc2hfdHJhbnNjcmlwdGlvbiUyMiU1RA==",highlighted:'example[<span class="hljs-string">&quot;english_transcription&quot;</span>]'}}),R=new g({props:{code:"JTIySSUyMHdvdWxkJTIwbGlrZSUyMHRvJTIwcGF5JTIwbXklMjBlbGVjdHJpY2l0eSUyMGJpbGwlMjB1c2luZyUyMG15JTIwY2FyZCUyMGNhbiUyMHlvdSUyMHBsZWFzZSUyMGFzc2lzdCUyMg==",highlighted:'<span class="hljs-comment">&quot;I would like to pay my electricity bill using my card can you please assist&quot;</span>'}}),q=new g({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwQXVkaW8lMEElMEFtaW5kcyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJQb2x5QUklMkZtaW5kczE0JTIyJTJDJTIwbmFtZSUzRCUyMmRlLURFJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFtaW5kcyUyMCUzRCUyMG1pbmRzLmNhc3RfY29sdW1uKCUyMmF1ZGlvJTIyJTJDJTIwQXVkaW8oc2FtcGxpbmdfcmF0ZSUzRDE2XzAwMCkp",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;de-DE&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>))`}}),W=new g({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RCUwQWV4YW1wbGUlNUIlMjJ0cmFuc2NyaXB0aW9uJTIyJTVE",highlighted:`example = minds[<span class="hljs-number">0</span>]
example[<span class="hljs-string">&quot;transcription&quot;</span>]`}}),Z=new g({props:{code:"JTIyaWNoJTIwbSVDMyVCNmNodGUlMjBnZXJuZSUyMEdlbGQlMjBhdWYlMjBtZWluJTIwS29udG8lMjBlaW56YWhsZW4lMjI=",highlighted:'<span class="hljs-comment">&quot;ich m\xF6chte gerne Geld auf mein Konto einzahlen&quot;</span>'}}),N=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBYXNyJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXV0b21hdGljLXNwZWVjaC1yZWNvZ25pdGlvbiUyMiUyQyUyMG1vZGVsJTNEJTIybWF4aWRsJTJGd2F2MnZlYzItbGFyZ2UteGxzci1nZXJtYW4lMjIpJTBBYXNyKGV4YW1wbGUlNUIlMjJhdWRpbyUyMiU1RCU1QiUyMmFycmF5JTIyJTVEKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

asr = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>, model=<span class="hljs-string">&quot;maxidl/wav2vec2-large-xlsr-german&quot;</span>)
asr(example[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>])`}}),B=new g({props:{code:"JTdCJTIydGV4dCUyMiUzQSUyMCUyMmljaCUyMG0lQzMlQjZjaHRlJTIwZ2VybmUlMjBnZWxkJTIwYXVmJTIwbWVpbiUyMGtvbnRvJTIwZWluemFsbGVuJTIyJTdE",highlighted:'{&quot;text&quot;: <span class="hljs-string">&quot;ich m\xF6chte gerne geld auf mein konto einzallen&quot;</span>}'}}),{c(){M=l("meta"),de=u(),U=l("h1"),T=l("a"),ie=l("span"),c(G.$$.fragment),De=u(),ae=l("span"),Qe=r("Automatic speech recognition with a pipeline"),we=u(),V=l("p"),Ke=r(`Automatic Speech Recognition (ASR) is a task that involves transcribing speech audio recording into text.
This task has has numerous practical applications, from creating closed captions for videos to enabling voice commands
for virtual assistants like Siri and Alexa.`),be=u(),J=l("p"),et=r("In this section, we\u2019ll use the "),le=l("code"),tt=r("automatic-speech-recognition"),st=r(` pipeline to transcribe an audio recording of a person
asking a question about paying a bill using the same MINDS-14 dataset as before.`),ve=u(),k=l("p"),it=r("To get started, load the dataset and upsample it to 16kHz as described in "),F=l("a"),at=r("Audio classification with a pipeline"),lt=r(`,
if you haven\u2019t done that yet.`),ge=u(),I=l("p"),ot=r("To transcribe an audio recording, we can use the "),oe=l("code"),nt=r("automatic-speech-recognition"),rt=r(` pipeline from \u{1F917} Transformers. Let\u2019s
instantiate the pipeline:`),Me=u(),c(_.$$.fragment),Ue=u(),z=l("p"),pt=r("Next, we\u2019ll take an example from the dataset and pass its raw data to the pipeline:"),$e=u(),c(S.$$.fragment),Te=u(),X=l("p"),ne=l("strong"),ut=r("Output:"),Je=u(),c(j.$$.fragment),ke=u(),Y=l("p"),ft=r("Let\u2019s compare this output to what the actual transcription for this example is:"),Ie=u(),c(C.$$.fragment),Ee=u(),P=l("p"),re=l("strong"),mt=r("Output:"),Ge=u(),c(R.$$.fragment),_e=u(),L=l("p"),ct=r(`The model seems to have done a pretty good job at transcribing the audio! It only got one word wrong (\u201Ccard\u201D) compared
to the original transcription, which is pretty good considering the speaker has an Australian accent, where the letter \u201Cr\u201D
is often silent. Having said that, I wouldn\u2019t recommend trying to pay your next electricity bill with a fish!`),Se=u(),v=l("p"),ht=r(`By default, this pipeline uses a model trained for automatic speech recognition for English language, which is fine in
this example. If you\u2019d like to try transcribing other subsets of MINDS-14 in different language, you can find a pre-trained
ASR model `),x=l("a"),yt=r("on the \u{1F917} Hub"),dt=r(`.
You can filter the models list by task first, then by language. Once you have found the model you like, pass it\u2019s name as
the `),pe=l("code"),wt=r("model"),bt=r(" argument to the pipeline."),je=u(),O=l("p"),vt=r("Let\u2019s try this for the German split of the MINDS-14. Load the \u201Cde-DE\u201D subset:"),Ce=u(),c(q.$$.fragment),Re=u(),H=l("p"),gt=r("Get an example and see what the transcription is supposed to be:"),xe=u(),c(W.$$.fragment),qe=u(),D=l("p"),ue=l("strong"),Mt=r("Output:"),We=u(),c(Z.$$.fragment),Ze=u(),Q=l("p"),Ut=r("Find a pre-trained ASR model for German language on the \u{1F917} Hub, instantiate a pipeline, and transcribe the example:"),Ne=u(),c(N.$$.fragment),Be=u(),K=l("p"),fe=l("strong"),$t=r("Output:"),Ae=u(),c(B.$$.fragment),Ve=u(),ee=l("p"),Tt=r("Also, stimmt\u2019s!"),Fe=u(),te=l("p"),Jt=r(`When working on solving your own task, starting with a simple pipeline like the ones we\u2019ve shown in this unit is a valuable
tool that offers several benefits:`),ze=u(),m=l("ul"),me=l("li"),kt=r("a pre-trained model may exist that already solves your task really well, saving you plenty of time"),It=u(),ce=l("li"),Et=r(`pipeline() takes care of all the pre/post-processing for you, so you don\u2019t have to worry about getting the data into
the right format for a model`),Gt=u(),he=l("li"),_t=r("if the result isn\u2019t ideal, this still gives you a quick baseline for future fine-tuning"),St=u(),A=l("li"),jt=r(`once you fine-tune a model on your custom data and share it on Hub, the whole community will be able to use it quickly
and effortlessly via the `),ye=l("code"),Ct=r("pipeline()"),Rt=r(" method making AI more accessible."),this.h()},l(e){const s=hs('[data-svelte="svelte-1phssyn"]',document.head);M=o(s,"META",{name:!0,content:!0}),s.forEach(t),de=f(e),U=o(e,"H1",{class:!0});var Ye=n(U);T=o(Ye,"A",{id:!0,class:!0,href:!0});var qt=n(T);ie=o(qt,"SPAN",{});var Wt=n(ie);h(G.$$.fragment,Wt),Wt.forEach(t),qt.forEach(t),De=f(Ye),ae=o(Ye,"SPAN",{});var Zt=n(ae);Qe=p(Zt,"Automatic speech recognition with a pipeline"),Zt.forEach(t),Ye.forEach(t),we=f(e),V=o(e,"P",{});var Nt=n(V);Ke=p(Nt,`Automatic Speech Recognition (ASR) is a task that involves transcribing speech audio recording into text.
This task has has numerous practical applications, from creating closed captions for videos to enabling voice commands
for virtual assistants like Siri and Alexa.`),Nt.forEach(t),be=f(e),J=o(e,"P",{});var Pe=n(J);et=p(Pe,"In this section, we\u2019ll use the "),le=o(Pe,"CODE",{});var Bt=n(le);tt=p(Bt,"automatic-speech-recognition"),Bt.forEach(t),st=p(Pe,` pipeline to transcribe an audio recording of a person
asking a question about paying a bill using the same MINDS-14 dataset as before.`),Pe.forEach(t),ve=f(e),k=o(e,"P",{});var Le=n(k);it=p(Le,"To get started, load the dataset and upsample it to 16kHz as described in "),F=o(Le,"A",{href:!0});var At=n(F);at=p(At,"Audio classification with a pipeline"),At.forEach(t),lt=p(Le,`,
if you haven\u2019t done that yet.`),Le.forEach(t),ge=f(e),I=o(e,"P",{});var Oe=n(I);ot=p(Oe,"To transcribe an audio recording, we can use the "),oe=o(Oe,"CODE",{});var Vt=n(oe);nt=p(Vt,"automatic-speech-recognition"),Vt.forEach(t),rt=p(Oe,` pipeline from \u{1F917} Transformers. Let\u2019s
instantiate the pipeline:`),Oe.forEach(t),Me=f(e),h(_.$$.fragment,e),Ue=f(e),z=o(e,"P",{});var Ft=n(z);pt=p(Ft,"Next, we\u2019ll take an example from the dataset and pass its raw data to the pipeline:"),Ft.forEach(t),$e=f(e),h(S.$$.fragment,e),Te=f(e),X=o(e,"P",{});var zt=n(X);ne=o(zt,"STRONG",{});var Xt=n(ne);ut=p(Xt,"Output:"),Xt.forEach(t),zt.forEach(t),Je=f(e),h(j.$$.fragment,e),ke=f(e),Y=o(e,"P",{});var Yt=n(Y);ft=p(Yt,"Let\u2019s compare this output to what the actual transcription for this example is:"),Yt.forEach(t),Ie=f(e),h(C.$$.fragment,e),Ee=f(e),P=o(e,"P",{});var Pt=n(P);re=o(Pt,"STRONG",{});var Lt=n(re);mt=p(Lt,"Output:"),Lt.forEach(t),Pt.forEach(t),Ge=f(e),h(R.$$.fragment,e),_e=f(e),L=o(e,"P",{});var Ot=n(L);ct=p(Ot,`The model seems to have done a pretty good job at transcribing the audio! It only got one word wrong (\u201Ccard\u201D) compared
to the original transcription, which is pretty good considering the speaker has an Australian accent, where the letter \u201Cr\u201D
is often silent. Having said that, I wouldn\u2019t recommend trying to pay your next electricity bill with a fish!`),Ot.forEach(t),Se=f(e),v=o(e,"P",{});var se=n(v);ht=p(se,`By default, this pipeline uses a model trained for automatic speech recognition for English language, which is fine in
this example. If you\u2019d like to try transcribing other subsets of MINDS-14 in different language, you can find a pre-trained
ASR model `),x=o(se,"A",{href:!0,rel:!0});var Ht=n(x);yt=p(Ht,"on the \u{1F917} Hub"),Ht.forEach(t),dt=p(se,`.
You can filter the models list by task first, then by language. Once you have found the model you like, pass it\u2019s name as
the `),pe=o(se,"CODE",{});var Dt=n(pe);wt=p(Dt,"model"),Dt.forEach(t),bt=p(se," argument to the pipeline."),se.forEach(t),je=f(e),O=o(e,"P",{});var Qt=n(O);vt=p(Qt,"Let\u2019s try this for the German split of the MINDS-14. Load the \u201Cde-DE\u201D subset:"),Qt.forEach(t),Ce=f(e),h(q.$$.fragment,e),Re=f(e),H=o(e,"P",{});var Kt=n(H);gt=p(Kt,"Get an example and see what the transcription is supposed to be:"),Kt.forEach(t),xe=f(e),h(W.$$.fragment,e),qe=f(e),D=o(e,"P",{});var es=n(D);ue=o(es,"STRONG",{});var ts=n(ue);Mt=p(ts,"Output:"),ts.forEach(t),es.forEach(t),We=f(e),h(Z.$$.fragment,e),Ze=f(e),Q=o(e,"P",{});var ss=n(Q);Ut=p(ss,"Find a pre-trained ASR model for German language on the \u{1F917} Hub, instantiate a pipeline, and transcribe the example:"),ss.forEach(t),Ne=f(e),h(N.$$.fragment,e),Be=f(e),K=o(e,"P",{});var is=n(K);fe=o(is,"STRONG",{});var as=n(fe);$t=p(as,"Output:"),as.forEach(t),is.forEach(t),Ae=f(e),h(B.$$.fragment,e),Ve=f(e),ee=o(e,"P",{});var ls=n(ee);Tt=p(ls,"Also, stimmt\u2019s!"),ls.forEach(t),Fe=f(e),te=o(e,"P",{});var os=n(te);Jt=p(os,`When working on solving your own task, starting with a simple pipeline like the ones we\u2019ve shown in this unit is a valuable
tool that offers several benefits:`),os.forEach(t),ze=f(e),m=o(e,"UL",{});var E=n(m);me=o(E,"LI",{});var ns=n(me);kt=p(ns,"a pre-trained model may exist that already solves your task really well, saving you plenty of time"),ns.forEach(t),It=f(E),ce=o(E,"LI",{});var rs=n(ce);Et=p(rs,`pipeline() takes care of all the pre/post-processing for you, so you don\u2019t have to worry about getting the data into
the right format for a model`),rs.forEach(t),Gt=f(E),he=o(E,"LI",{});var ps=n(he);_t=p(ps,"if the result isn\u2019t ideal, this still gives you a quick baseline for future fine-tuning"),ps.forEach(t),St=f(E),A=o(E,"LI",{});var He=n(A);jt=p(He,`once you fine-tune a model on your custom data and share it on Hub, the whole community will be able to use it quickly
and effortlessly via the `),ye=o(He,"CODE",{});var us=n(ye);Ct=p(us,"pipeline()"),us.forEach(t),Rt=p(He," method making AI more accessible."),He.forEach(t),E.forEach(t),this.h()},h(){$(M,"name","hf:doc:metadata"),$(M,"content",JSON.stringify(vs)),$(T,"id","automatic-speech-recognition-with-a-pipeline"),$(T,"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"),$(T,"href","#automatic-speech-recognition-with-a-pipeline"),$(U,"class","relative group"),$(F,"href","audio_classification_pipeline"),$(x,"href","https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&language=fr&sort=downloads"),$(x,"rel","nofollow")},m(e,s){i(document.head,M),a(e,de,s),a(e,U,s),i(U,T),i(T,ie),y(G,ie,null),i(U,De),i(U,ae),i(ae,Qe),a(e,we,s),a(e,V,s),i(V,Ke),a(e,be,s),a(e,J,s),i(J,et),i(J,le),i(le,tt),i(J,st),a(e,ve,s),a(e,k,s),i(k,it),i(k,F),i(F,at),i(k,lt),a(e,ge,s),a(e,I,s),i(I,ot),i(I,oe),i(oe,nt),i(I,rt),a(e,Me,s),y(_,e,s),a(e,Ue,s),a(e,z,s),i(z,pt),a(e,$e,s),y(S,e,s),a(e,Te,s),a(e,X,s),i(X,ne),i(ne,ut),a(e,Je,s),y(j,e,s),a(e,ke,s),a(e,Y,s),i(Y,ft),a(e,Ie,s),y(C,e,s),a(e,Ee,s),a(e,P,s),i(P,re),i(re,mt),a(e,Ge,s),y(R,e,s),a(e,_e,s),a(e,L,s),i(L,ct),a(e,Se,s),a(e,v,s),i(v,ht),i(v,x),i(x,yt),i(v,dt),i(v,pe),i(pe,wt),i(v,bt),a(e,je,s),a(e,O,s),i(O,vt),a(e,Ce,s),y(q,e,s),a(e,Re,s),a(e,H,s),i(H,gt),a(e,xe,s),y(W,e,s),a(e,qe,s),a(e,D,s),i(D,ue),i(ue,Mt),a(e,We,s),y(Z,e,s),a(e,Ze,s),a(e,Q,s),i(Q,Ut),a(e,Ne,s),y(N,e,s),a(e,Be,s),a(e,K,s),i(K,fe),i(fe,$t),a(e,Ae,s),y(B,e,s),a(e,Ve,s),a(e,ee,s),i(ee,Tt),a(e,Fe,s),a(e,te,s),i(te,Jt),a(e,ze,s),a(e,m,s),i(m,me),i(me,kt),i(m,It),i(m,ce),i(ce,Et),i(m,Gt),i(m,he),i(he,_t),i(m,St),i(m,A),i(A,jt),i(A,ye),i(ye,Ct),i(A,Rt),Xe=!0},p:ys,i(e){Xe||(d(G.$$.fragment,e),d(_.$$.fragment,e),d(S.$$.fragment,e),d(j.$$.fragment,e),d(C.$$.fragment,e),d(R.$$.fragment,e),d(q.$$.fragment,e),d(W.$$.fragment,e),d(Z.$$.fragment,e),d(N.$$.fragment,e),d(B.$$.fragment,e),Xe=!0)},o(e){w(G.$$.fragment,e),w(_.$$.fragment,e),w(S.$$.fragment,e),w(j.$$.fragment,e),w(C.$$.fragment,e),w(R.$$.fragment,e),w(q.$$.fragment,e),w(W.$$.fragment,e),w(Z.$$.fragment,e),w(N.$$.fragment,e),w(B.$$.fragment,e),Xe=!1},d(e){t(M),e&&t(de),e&&t(U),b(G),e&&t(we),e&&t(V),e&&t(be),e&&t(J),e&&t(ve),e&&t(k),e&&t(ge),e&&t(I),e&&t(Me),b(_,e),e&&t(Ue),e&&t(z),e&&t($e),b(S,e),e&&t(Te),e&&t(X),e&&t(Je),b(j,e),e&&t(ke),e&&t(Y),e&&t(Ie),b(C,e),e&&t(Ee),e&&t(P),e&&t(Ge),b(R,e),e&&t(_e),e&&t(L),e&&t(Se),e&&t(v),e&&t(je),e&&t(O),e&&t(Ce),b(q,e),e&&t(Re),e&&t(H),e&&t(xe),b(W,e),e&&t(qe),e&&t(D),e&&t(We),b(Z,e),e&&t(Ze),e&&t(Q),e&&t(Ne),b(N,e),e&&t(Be),e&&t(K),e&&t(Ae),b(B,e),e&&t(Ve),e&&t(ee),e&&t(Fe),e&&t(te),e&&t(ze),e&&t(m)}}}const vs={local:"automatic-speech-recognition-with-a-pipeline",title:"Automatic speech recognition with a pipeline"};function gs(xt){return ds(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ts extends fs{constructor(M){super();ms(this,M,gs,bs,cs,{})}}export{Ts as default,vs as metadata};
