import{s as DM,n as BM,o as bM}from"../chunks/scheduler.cd324960.js";import{S as NM,i as fM,e as a,s as y,c as C,h as dM,a as n,d as s,b as U,f as SM,g as e,j as J,k as QM,l as VM,m as t,n as j,t as w,o as I,p}from"../chunks/index.d5c3adcc.js";import{C as ZM,H as _M,E as kM}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.7c2f06fe.js";import{C as z}from"../chunks/CodeBlock.fc816cd0.js";function xM(jM){let T,R,k,$,A,v,u,Y,i,wM="使用音频数据集的最大挑战之一是它们庞大的规模。仅仅一分钟的CD音质音频（44.1千赫兹，16比特）就需要占用约5MB的存储。一般的音频数据集会含有数个小时的音频录音。",F,o,IM='在上一小节中，我们使用了MINDS-14的一个非常小的子集，但常见的音频数据集往往要大得多。举个例子<a href="https://huggingface.co/datasets/speechcolab/gigaspeech" rel="nofollow">GigaSpeech from SpeechColab</a>的<code>xs</code>（最小）子集仅有10小时的训练数据，但需要占用超过13GB的存储空间。当我们选择更大的子集时会发生什么呢？其最大的<code>xl</code>子集含有10000小时的训练数据，需要占用超过1TB的存储空间。对大多数人来说，这已经远远超过了我们的硬盘所能容纳的容量。我们需要剁手购买额外的硬盘吗？还是说有其他方法可以让我们绕过存储空间的限制呢？',W,r,pM="🤗 Datasets为你提供了解决方法：流式处理模式。流式处理可以让我们在遍历数据集的过程中渐进地加载数据。与其一次性地下载完整数据集，不如将样本一个个单独加载。在遍历数据集时，我们实时地在有需要时加载和准备好每个样本。通过这样的方式，我们永远只加载我们正在使用的数据，而不加载我们暂时不需要的数据。当我们使用完一个样本时，就继续遍历数据集，加载下一个样本。",G,c,AM="相较于全量加载，流式处理模式主要有三个优点：",X,h,uM="<li>硬盘空间：样本是在遍历数据集的过程中被依次加载到内存中的。由于我们不需要将数据下载到本地，因此也没有任何对硬盘空间的要求，你可以使用任意大小的数据集。</li> <li>下载和处理时间：音频数据集极其庞大并且需要大量的数据下载和处理时间。在流式处理模式下，数据会进行实时的加载和处理，因此当第一个样本准备完成时我们就可以开始训练。</li> <li>测试简单：无需下载完整的数据集，仅用少量的样本就可以测试你的训练脚本。</li>",L,m,iM="在使用流式处理模式时，有一点需要警惕：在全量下载数据集时，所有的原始数据和处理后的数据都会在硬盘内本地存储。如果我们想要重复利用这些数据，我们可以跳过下载和处理过程，直接从硬盘中加载数据。这意味着我们在重复利用数据时，仅在第一次时需要下载和处理数据。",O,q,oM="但在流式处理模式中，数据不会被下载到硬盘内。因此，我们的下载和预处理过程都不会被保存。在重复利用数据集时，我们必须要重复进行下载和预处理才做。因此，如果你计划重复使用数据集，我们还是推荐将数据集下载到本地硬盘。",H,g,rM="如何启用流式处理模式呢？很简单！只需要在加载数据集时传入<code>streaming=True</code>参数即可。我们会帮你做好其他工作：",P,E,K,S,cM="与我们在全量下载MINDS-14子集时进行的预处理操作相同，你也可以在流式数据集上使用同样的预处理操作。",MM,Q,hM="唯一的区别是我们现在无法使用Python的索引功能访问单个的样本（例如<code>gigaspeech[&quot;train&quot;][sample_idx]</code>）。相反地，我们需要遍历整个数据集。你可以在流式数据集这这样访问单个样本：",lM,D,sM,B,mM="<strong>输出：</strong>",tM,b,yM,N,qM="你可以使用<code>take()</code>函数来预览数据集的几个样本。让我们看看gigaspeech数据集的前两个样本：",UM,f,aM,d,gM="<strong>输出：</strong>",nM,V,JM,Z,EM="流式处理模式可以助力你的研究进入更高的阶段：现在你不仅可以利用庞大的数据集，而且可以在无需担忧硬盘空间的情况下使用多个数据集来评估你的系统。与使用单个数据集进行评估相比，多数据集评估可以更好地体现系统的泛化性能。",TM,_,CM,x,eM;return A=new ZM({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),u=new _M({props:{title:"音频数据的流式加载",local:"音频数据的流式加载",headingTag:"h1"}}),E=new z({props:{code:"Z2lnYXNwZWVjaCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJzcGVlY2hjb2xhYiUyRmdpZ2FzcGVlY2glMjIlMkMlMjAlMjJ4cyUyMiUyQyUyMHN0cmVhbWluZyUzRFRydWUp",highlighted:'gigaspeech = load_dataset(<span class="hljs-string">&quot;speechcolab/gigaspeech&quot;</span>, <span class="hljs-string">&quot;xs&quot;</span>, streaming=<span class="hljs-literal">True</span>)',wrap:!1}}),D=new z({props:{code:"bmV4dChpdGVyKGdpZ2FzcGVlY2glNUIlMjJ0cmFpbiUyMiU1RCkp",highlighted:'<span class="hljs-built_in">next</span>(<span class="hljs-built_in">iter</span>(gigaspeech[<span class="hljs-string">&quot;train&quot;</span>]))',wrap:!1}}),b=new z({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyc2VnbWVudF9pZCUyMiUzQSUyMCUyMllPVTAwMDAwMDAzMTVfUzAwMDA2NjAlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJzcGVha2VyJTIyJTNBJTIwJTIyTiUyRkElMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJ0ZXh0JTIyJTNBJTIwJTIyQVMlMjBUSEVZJ1JFJTIwTEVBVklORyUyMCUzQ0NPTU1BJTNFJTIwQ0FOJTIwS0FTSCUyMFBVTEwlMjBaQUhSQSUyMEFTSURFJTIwUkVBTExZJTIwUVVJQ0tMWSUyMCUzQ1FVRVNUSU9OTUFSSyUzRSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMmF1ZGlvJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycGF0aCUyMiUzQSUyMCUyMnhzX2NodW5rc18wMDAwJTJGWU9VMDAwMDAwMDMxNV9TMDAwMDY2MC53YXYlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJhcnJheSUyMiUzQSUyMGFycmF5KCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QjAuMDAwNTE4OCUyQyUyMDAuMDAwODU0NDklMkMlMjAwLjAwMDEyMjA3JTJDJTIwLi4uJTJDJTIwMC4wMDEyNTEyMiUyQyUyMDAuMDAwNzYyOTQlMkMlMjAwLjAwMDM2NjIxJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnNhbXBsaW5nX3JhdGUlMjIlM0ElMjAxNjAwMCUyQyUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMmJlZ2luX3RpbWUlMjIlM0ElMjAyOTQxLjg5JTJDJTBBJTIwJTIwJTIwJTIwJTIyZW5kX3RpbWUlMjIlM0ElMjAyOTQ1LjA3JTJDJTBBJTIwJTIwJTIwJTIwJTIyYXVkaW9faWQlMjIlM0ElMjAlMjJZT1UwMDAwMDAwMzE1JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIydGl0bGUlMjIlM0ElMjAlMjJSZXR1cm4lMjB0byUyMFZhc3NlbGhlaW0lMjAlN0MlMjBDcml0aWNhbCUyMFJvbGUlM0ElMjBWT1glMjBNQUNISU5BJTIwJTdDJTIwRXBpc29kZSUyMDQzJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIydXJsJTIyJTNBJTIwJTIyaHR0cHMlM0ElMkYlMkZ3d3cueW91dHViZS5jb20lMkZ3YXRjaCUzRnYlM0R6cjJuMWZMVmFzVSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnNvdXJjZSUyMiUzQSUyMDIlMkMlMEElMjAlMjAlMjAlMjAlMjJjYXRlZ29yeSUyMiUzQSUyMDI0JTJDJTBBJTIwJTIwJTIwJTIwJTIyb3JpZ2luYWxfZnVsbF9wYXRoJTIyJTNBJTIwJTIyYXVkaW8lMkZ5b3V0dWJlJTJGUDAwMDQlMkZZT1UwMDAwMDAwMzE1Lm9wdXMlMjIlMkMlMEElN0Q=",highlighted:`{
    <span class="hljs-string">&quot;segment_id&quot;</span>: <span class="hljs-string">&quot;YOU0000000315_S0000660&quot;</span>,
    <span class="hljs-string">&quot;speaker&quot;</span>: <span class="hljs-string">&quot;N/A&quot;</span>,
    <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;AS THEY&#x27;RE LEAVING &lt;COMMA&gt; CAN KASH PULL ZAHRA ASIDE REALLY QUICKLY &lt;QUESTIONMARK&gt;&quot;</span>,
    <span class="hljs-string">&quot;audio&quot;</span>: {
        <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;xs_chunks_0000/YOU0000000315_S0000660.wav&quot;</span>,
        <span class="hljs-string">&quot;array&quot;</span>: <span class="hljs-built_in">array</span>(
            <span class="hljs-selector-attr">[0.0005188, 0.00085449, 0.00012207, ..., 0.00125122, 0.00076294, 0.00036621]</span>
        ),
        <span class="hljs-string">&quot;sampling_rate&quot;</span>: <span class="hljs-number">16000</span>,
    },
    <span class="hljs-string">&quot;begin_time&quot;</span>: <span class="hljs-number">2941.89</span>,
    <span class="hljs-string">&quot;end_time&quot;</span>: <span class="hljs-number">2945.07</span>,
    <span class="hljs-string">&quot;audio_id&quot;</span>: <span class="hljs-string">&quot;YOU0000000315&quot;</span>,
    <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;Return to Vasselheim | Critical Role: VOX MACHINA | Episode 43&quot;</span>,
    <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">&quot;https://www.youtube.com/watch?v=zr2n1fLVasU&quot;</span>,
    <span class="hljs-string">&quot;source&quot;</span>: <span class="hljs-number">2</span>,
    <span class="hljs-string">&quot;category&quot;</span>: <span class="hljs-number">24</span>,
    <span class="hljs-string">&quot;original_full_path&quot;</span>: <span class="hljs-string">&quot;audio/youtube/P0004/YOU0000000315.opus&quot;</span>,
}`,wrap:!1}}),f=new z({props:{code:"Z2lnYXNwZWVjaF9oZWFkJTIwJTNEJTIwZ2lnYXNwZWVjaCU1QiUyMnRyYWluJTIyJTVELnRha2UoMiklMEFsaXN0KGdpZ2FzcGVlY2hfaGVhZCk=",highlighted:`gigaspeech_head = gigaspeech[<span class="hljs-string">&quot;train&quot;</span>].take(<span class="hljs-number">2</span>)
<span class="hljs-built_in">list</span>(gigaspeech_head)`,wrap:!1}}),V=new z({props:{code:" ",highlighted:`[
    {
        <span class="hljs-string">&quot;segment_id&quot;</span>: <span class="hljs-string">&quot;YOU0000000315_S0000660&quot;</span>,
        <span class="hljs-string">&quot;speaker&quot;</span>: <span class="hljs-string">&quot;N/A&quot;</span>,
        <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;AS THEY&#x27;RE LEAVING &lt;COMMA&gt; CAN KASH PULL ZAHRA ASIDE REALLY QUICKLY &lt;QUESTIONMARK&gt;&quot;</span>,
        <span class="hljs-string">&quot;audio&quot;</span>: {
            <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;xs_chunks_0000/YOU0000000315_S0000660.wav&quot;</span>,
            <span class="hljs-string">&quot;array&quot;</span>: array(
                [
                    <span class="hljs-number">0.0005188</span>,
                    <span class="hljs-number">0.00085449</span>,
                    <span class="hljs-number">0.00012207</span>,
                    ...,
                    <span class="hljs-number">0.00125122</span>,
                    <span class="hljs-number">0.00076294</span>,
                    <span class="hljs-number">0.00036621</span>,
                ]
            ),
            <span class="hljs-string">&quot;sampling_rate&quot;</span>: <span class="hljs-number">16000</span>,
        },
        <span class="hljs-string">&quot;begin_time&quot;</span>: <span class="hljs-number">2941.89</span>,
        <span class="hljs-string">&quot;end_time&quot;</span>: <span class="hljs-number">2945.07</span>,
        <span class="hljs-string">&quot;audio_id&quot;</span>: <span class="hljs-string">&quot;YOU0000000315&quot;</span>,
        <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;Return to Vasselheim | Critical Role: VOX MACHINA | Episode 43&quot;</span>,
        <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">&quot;https://www.youtube.com/watch?v=zr2n1fLVasU&quot;</span>,
        <span class="hljs-string">&quot;source&quot;</span>: <span class="hljs-number">2</span>,
        <span class="hljs-string">&quot;category&quot;</span>: <span class="hljs-number">24</span>,
        <span class="hljs-string">&quot;original_full_path&quot;</span>: <span class="hljs-string">&quot;audio/youtube/P0004/YOU0000000315.opus&quot;</span>,
    },
    {
        <span class="hljs-string">&quot;segment_id&quot;</span>: <span class="hljs-string">&quot;AUD0000001043_S0000775&quot;</span>,
        <span class="hljs-string">&quot;speaker&quot;</span>: <span class="hljs-string">&quot;N/A&quot;</span>,
        <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;SIX TOMATOES &lt;PERIOD&gt;&quot;</span>,
        <span class="hljs-string">&quot;audio&quot;</span>: {
            <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;xs_chunks_0000/AUD0000001043_S0000775.wav&quot;</span>,
            <span class="hljs-string">&quot;array&quot;</span>: array(
                [
                    <span class="hljs-number">1.43432617</span>e-03,
                    <span class="hljs-number">1.37329102</span>e-03,
                    <span class="hljs-number">1.31225586</span>e-03,
                    ...,
                    <span class="hljs-number">-6.10351562</span>e-05,
                    <span class="hljs-number">-1.22070312</span>e-04,
                    <span class="hljs-number">-1.83105469</span>e-04,
                ]
            ),
            <span class="hljs-string">&quot;sampling_rate&quot;</span>: <span class="hljs-number">16000</span>,
        },
        <span class="hljs-string">&quot;begin_time&quot;</span>: <span class="hljs-number">3673.96</span>,
        <span class="hljs-string">&quot;end_time&quot;</span>: <span class="hljs-number">3675.26</span>,
        <span class="hljs-string">&quot;audio_id&quot;</span>: <span class="hljs-string">&quot;AUD0000001043&quot;</span>,
        <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;Asteroid of Fear&quot;</span>,
        <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">&quot;http//www.archive.org/download/asteroid_of_fear_1012_librivox/asteroid_of_fear_1012_librivox_64kb_mp3.zip&quot;</span>,
        <span class="hljs-string">&quot;source&quot;</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">&quot;category&quot;</span>: <span class="hljs-number">28</span>,
        <span class="hljs-string">&quot;original_full_path&quot;</span>: <span class="hljs-string">&quot;audio/audiobook/P0011/AUD0000001043.opus&quot;</span>,
    },
]`,wrap:!1}}),_=new kM({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/zh-CN/chapter1/streaming.mdx"}}),{c(){T=a("meta"),R=y(),k=a("p"),$=y(),C(A.$$.fragment),v=y(),C(u.$$.fragment),Y=y(),i=a("p"),i.textContent=wM,F=y(),o=a("p"),o.innerHTML=IM,W=y(),r=a("p"),r.textContent=pM,G=y(),c=a("p"),c.textContent=AM,X=y(),h=a("ul"),h.innerHTML=uM,L=y(),m=a("p"),m.textContent=iM,O=y(),q=a("p"),q.textContent=oM,H=y(),g=a("p"),g.innerHTML=rM,P=y(),C(E.$$.fragment),K=y(),S=a("p"),S.textContent=cM,MM=y(),Q=a("p"),Q.innerHTML=hM,lM=y(),C(D.$$.fragment),sM=y(),B=a("p"),B.innerHTML=mM,tM=y(),C(b.$$.fragment),yM=y(),N=a("p"),N.innerHTML=qM,UM=y(),C(f.$$.fragment),aM=y(),d=a("p"),d.innerHTML=gM,nM=y(),C(V.$$.fragment),JM=y(),Z=a("p"),Z.textContent=EM,TM=y(),C(_.$$.fragment),CM=y(),x=a("p"),this.h()},l(M){const l=dM("svelte-u9bgzb",document.head);T=n(l,"META",{name:!0,content:!0}),l.forEach(s),R=U(M),k=n(M,"P",{}),SM(k).forEach(s),$=U(M),e(A.$$.fragment,M),v=U(M),e(u.$$.fragment,M),Y=U(M),i=n(M,"P",{"data-svelte-h":!0}),J(i)!=="svelte-clzs67"&&(i.textContent=wM),F=U(M),o=n(M,"P",{"data-svelte-h":!0}),J(o)!=="svelte-1brhrul"&&(o.innerHTML=IM),W=U(M),r=n(M,"P",{"data-svelte-h":!0}),J(r)!=="svelte-haggy6"&&(r.textContent=pM),G=U(M),c=n(M,"P",{"data-svelte-h":!0}),J(c)!=="svelte-1av16hk"&&(c.textContent=AM),X=U(M),h=n(M,"UL",{"data-svelte-h":!0}),J(h)!=="svelte-3p579b"&&(h.innerHTML=uM),L=U(M),m=n(M,"P",{"data-svelte-h":!0}),J(m)!=="svelte-1xsrwtz"&&(m.textContent=iM),O=U(M),q=n(M,"P",{"data-svelte-h":!0}),J(q)!=="svelte-49rd2y"&&(q.textContent=oM),H=U(M),g=n(M,"P",{"data-svelte-h":!0}),J(g)!=="svelte-hbj4lj"&&(g.innerHTML=rM),P=U(M),e(E.$$.fragment,M),K=U(M),S=n(M,"P",{"data-svelte-h":!0}),J(S)!=="svelte-o08v25"&&(S.textContent=cM),MM=U(M),Q=n(M,"P",{"data-svelte-h":!0}),J(Q)!=="svelte-1jnkvn1"&&(Q.innerHTML=hM),lM=U(M),e(D.$$.fragment,M),sM=U(M),B=n(M,"P",{"data-svelte-h":!0}),J(B)!=="svelte-1yevus4"&&(B.innerHTML=mM),tM=U(M),e(b.$$.fragment,M),yM=U(M),N=n(M,"P",{"data-svelte-h":!0}),J(N)!=="svelte-1pz6h55"&&(N.innerHTML=qM),UM=U(M),e(f.$$.fragment,M),aM=U(M),d=n(M,"P",{"data-svelte-h":!0}),J(d)!=="svelte-1yevus4"&&(d.innerHTML=gM),nM=U(M),e(V.$$.fragment,M),JM=U(M),Z=n(M,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-jzmfgk"&&(Z.textContent=EM),TM=U(M),e(_.$$.fragment,M),CM=U(M),x=n(M,"P",{}),SM(x).forEach(s),this.h()},h(){QM(T,"name","hf:doc:metadata"),QM(T,"content",zM)},m(M,l){VM(document.head,T),t(M,R,l),t(M,k,l),t(M,$,l),j(A,M,l),t(M,v,l),j(u,M,l),t(M,Y,l),t(M,i,l),t(M,F,l),t(M,o,l),t(M,W,l),t(M,r,l),t(M,G,l),t(M,c,l),t(M,X,l),t(M,h,l),t(M,L,l),t(M,m,l),t(M,O,l),t(M,q,l),t(M,H,l),t(M,g,l),t(M,P,l),j(E,M,l),t(M,K,l),t(M,S,l),t(M,MM,l),t(M,Q,l),t(M,lM,l),j(D,M,l),t(M,sM,l),t(M,B,l),t(M,tM,l),j(b,M,l),t(M,yM,l),t(M,N,l),t(M,UM,l),j(f,M,l),t(M,aM,l),t(M,d,l),t(M,nM,l),j(V,M,l),t(M,JM,l),t(M,Z,l),t(M,TM,l),j(_,M,l),t(M,CM,l),t(M,x,l),eM=!0},p:BM,i(M){eM||(w(A.$$.fragment,M),w(u.$$.fragment,M),w(E.$$.fragment,M),w(D.$$.fragment,M),w(b.$$.fragment,M),w(f.$$.fragment,M),w(V.$$.fragment,M),w(_.$$.fragment,M),eM=!0)},o(M){I(A.$$.fragment,M),I(u.$$.fragment,M),I(E.$$.fragment,M),I(D.$$.fragment,M),I(b.$$.fragment,M),I(f.$$.fragment,M),I(V.$$.fragment,M),I(_.$$.fragment,M),eM=!1},d(M){M&&(s(R),s(k),s($),s(v),s(Y),s(i),s(F),s(o),s(W),s(r),s(G),s(c),s(X),s(h),s(L),s(m),s(O),s(q),s(H),s(g),s(P),s(K),s(S),s(MM),s(Q),s(lM),s(sM),s(B),s(tM),s(yM),s(N),s(UM),s(aM),s(d),s(nM),s(JM),s(Z),s(TM),s(CM),s(x)),s(T),p(A,M),p(u,M),p(E,M),p(D,M),p(b,M),p(f,M),p(V,M),p(_,M)}}}const zM='{"title":"音频数据的流式加载","local":"音频数据的流式加载","sections":[],"depth":1}';function RM(jM){return bM(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class WM extends NM{constructor(T){super(),fM(this,T,RM,xM,DM,{})}}export{WM as component};
