import{s as gM,n as EM,o as QM}from"../chunks/scheduler.b8dd6794.js";import{S as SM,i as DM,g as a,s as U,r as B,A as BM,h as J,f as s,c as t,j as qM,u as N,x as T,k as mM,y as NM,a as y,v as b,d,t as f,w as V}from"../chunks/index.0a3e3d78.js";import{C as k}from"../chunks/CodeBlock.822b8cc6.js";import{H as bM}from"../chunks/Heading.e6dfd430.js";function dM(TM){let n,x,Z,z,C,R,j,nM="使用音频数据集的最大挑战之一是它们庞大的规模。仅仅一分钟的CD音质音频（44.1千赫兹，16比特）就需要占用约5MB的存储。一般的音频数据集会含有数个小时的音频录音。",v,w,CM='在上一小节中，我们使用了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的存储空间。对大多数人来说，这已经远远超过了我们的硬盘所能容纳的容量。我们需要剁手购买额外的硬盘吗？还是说有其他方法可以让我们绕过存储空间的限制呢？',Y,e,jM="🤗 Datasets为你提供了解决方法：流式处理模式。流式处理可以让我们在遍历数据集的过程中渐进地加载数据。与其一次性地下载完整数据集，不如将样本一个个单独加载。在遍历数据集时，我们实时地在有需要时加载和准备好每个样本。通过这样的方式，我们永远只加载我们正在使用的数据，而不加载我们暂时不需要的数据。当我们使用完一个样本时，就继续遍历数据集，加载下一个样本。",F,I,wM="相较于全量加载，流式处理模式主要有三个优点：",W,p,eM="<li>硬盘空间：样本是在遍历数据集的过程中被依次加载到内存中的。由于我们不需要将数据下载到本地，因此也没有任何对硬盘空间的要求，你可以使用任意大小的数据集。</li> <li>下载和处理时间：音频数据集极其庞大并且需要大量的数据下载和处理时间。在流式处理模式下，数据会进行实时的加载和处理，因此当第一个样本准备完成时我们就可以开始训练。</li> <li>测试简单：无需下载完整的数据集，仅用少量的样本就可以测试你的训练脚本。</li>",G,A,IM="在使用流式处理模式时，有一点需要警惕：在全量下载数据集时，所有的原始数据和处理后的数据都会在硬盘内本地存储。如果我们想要重复利用这些数据，我们可以跳过下载和处理过程，直接从硬盘中加载数据。这意味着我们在重复利用数据时，仅在第一次时需要下载和处理数据。",X,u,pM="但在流式处理模式中，数据不会被下载到硬盘内。因此，我们的下载和预处理过程都不会被保存。在重复利用数据集时，我们必须要重复进行下载和预处理才做。因此，如果你计划重复使用数据集，我们还是推荐将数据集下载到本地硬盘。",L,i,AM="如何启用流式处理模式呢？很简单！只需要在加载数据集时传入<code>streaming=True</code>参数即可。我们会帮你做好其他工作：",$,o,O,c,uM="与我们在全量下载MINDS-14子集时进行的预处理操作相同，你也可以在流式数据集上使用同样的预处理操作。",H,r,iM="唯一的区别是我们现在无法使用Python的索引功能访问单个的样本（例如<code>gigaspeech[&quot;train&quot;][sample_idx]</code>）。相反地，我们需要遍历整个数据集。你可以在流式数据集这这样访问单个样本：",P,h,K,q,oM="<strong>输出：</strong>",MM,m,lM,g,cM="你可以使用<code>take()</code>函数来预览数据集的几个样本。让我们看看gigaspeech数据集的前两个样本：",sM,E,yM,Q,rM="<strong>输出：</strong>",UM,S,tM,D,hM="流式处理模式可以助力你的研究进入更高的阶段：现在你不仅可以利用庞大的数据集，而且可以在无需担忧硬盘空间的情况下使用多个数据集来评估你的系统。与使用单个数据集进行评估相比，多数据集评估可以更好地体现系统的泛化性能。",aM,_,JM;return C=new bM({props:{title:"音频数据的流式加载",local:"音频数据的流式加载",headingTag:"h1"}}),o=new k({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}}),h=new k({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}}),m=new k({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}}),E=new k({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}}),S=new k({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}}),{c(){n=a("meta"),x=U(),Z=a("p"),z=U(),B(C.$$.fragment),R=U(),j=a("p"),j.textContent=nM,v=U(),w=a("p"),w.innerHTML=CM,Y=U(),e=a("p"),e.textContent=jM,F=U(),I=a("p"),I.textContent=wM,W=U(),p=a("ul"),p.innerHTML=eM,G=U(),A=a("p"),A.textContent=IM,X=U(),u=a("p"),u.textContent=pM,L=U(),i=a("p"),i.innerHTML=AM,$=U(),B(o.$$.fragment),O=U(),c=a("p"),c.textContent=uM,H=U(),r=a("p"),r.innerHTML=iM,P=U(),B(h.$$.fragment),K=U(),q=a("p"),q.innerHTML=oM,MM=U(),B(m.$$.fragment),lM=U(),g=a("p"),g.innerHTML=cM,sM=U(),B(E.$$.fragment),yM=U(),Q=a("p"),Q.innerHTML=rM,UM=U(),B(S.$$.fragment),tM=U(),D=a("p"),D.textContent=hM,aM=U(),_=a("p"),this.h()},l(M){const l=BM("svelte-u9bgzb",document.head);n=J(l,"META",{name:!0,content:!0}),l.forEach(s),x=t(M),Z=J(M,"P",{}),qM(Z).forEach(s),z=t(M),N(C.$$.fragment,M),R=t(M),j=J(M,"P",{"data-svelte-h":!0}),T(j)!=="svelte-clzs67"&&(j.textContent=nM),v=t(M),w=J(M,"P",{"data-svelte-h":!0}),T(w)!=="svelte-1brhrul"&&(w.innerHTML=CM),Y=t(M),e=J(M,"P",{"data-svelte-h":!0}),T(e)!=="svelte-haggy6"&&(e.textContent=jM),F=t(M),I=J(M,"P",{"data-svelte-h":!0}),T(I)!=="svelte-1av16hk"&&(I.textContent=wM),W=t(M),p=J(M,"UL",{"data-svelte-h":!0}),T(p)!=="svelte-3p579b"&&(p.innerHTML=eM),G=t(M),A=J(M,"P",{"data-svelte-h":!0}),T(A)!=="svelte-1xsrwtz"&&(A.textContent=IM),X=t(M),u=J(M,"P",{"data-svelte-h":!0}),T(u)!=="svelte-49rd2y"&&(u.textContent=pM),L=t(M),i=J(M,"P",{"data-svelte-h":!0}),T(i)!=="svelte-hbj4lj"&&(i.innerHTML=AM),$=t(M),N(o.$$.fragment,M),O=t(M),c=J(M,"P",{"data-svelte-h":!0}),T(c)!=="svelte-o08v25"&&(c.textContent=uM),H=t(M),r=J(M,"P",{"data-svelte-h":!0}),T(r)!=="svelte-1jnkvn1"&&(r.innerHTML=iM),P=t(M),N(h.$$.fragment,M),K=t(M),q=J(M,"P",{"data-svelte-h":!0}),T(q)!=="svelte-1yevus4"&&(q.innerHTML=oM),MM=t(M),N(m.$$.fragment,M),lM=t(M),g=J(M,"P",{"data-svelte-h":!0}),T(g)!=="svelte-1pz6h55"&&(g.innerHTML=cM),sM=t(M),N(E.$$.fragment,M),yM=t(M),Q=J(M,"P",{"data-svelte-h":!0}),T(Q)!=="svelte-1yevus4"&&(Q.innerHTML=rM),UM=t(M),N(S.$$.fragment,M),tM=t(M),D=J(M,"P",{"data-svelte-h":!0}),T(D)!=="svelte-jzmfgk"&&(D.textContent=hM),aM=t(M),_=J(M,"P",{}),qM(_).forEach(s),this.h()},h(){mM(n,"name","hf:doc:metadata"),mM(n,"content",fM)},m(M,l){NM(document.head,n),y(M,x,l),y(M,Z,l),y(M,z,l),b(C,M,l),y(M,R,l),y(M,j,l),y(M,v,l),y(M,w,l),y(M,Y,l),y(M,e,l),y(M,F,l),y(M,I,l),y(M,W,l),y(M,p,l),y(M,G,l),y(M,A,l),y(M,X,l),y(M,u,l),y(M,L,l),y(M,i,l),y(M,$,l),b(o,M,l),y(M,O,l),y(M,c,l),y(M,H,l),y(M,r,l),y(M,P,l),b(h,M,l),y(M,K,l),y(M,q,l),y(M,MM,l),b(m,M,l),y(M,lM,l),y(M,g,l),y(M,sM,l),b(E,M,l),y(M,yM,l),y(M,Q,l),y(M,UM,l),b(S,M,l),y(M,tM,l),y(M,D,l),y(M,aM,l),y(M,_,l),JM=!0},p:EM,i(M){JM||(d(C.$$.fragment,M),d(o.$$.fragment,M),d(h.$$.fragment,M),d(m.$$.fragment,M),d(E.$$.fragment,M),d(S.$$.fragment,M),JM=!0)},o(M){f(C.$$.fragment,M),f(o.$$.fragment,M),f(h.$$.fragment,M),f(m.$$.fragment,M),f(E.$$.fragment,M),f(S.$$.fragment,M),JM=!1},d(M){M&&(s(x),s(Z),s(z),s(R),s(j),s(v),s(w),s(Y),s(e),s(F),s(I),s(W),s(p),s(G),s(A),s(X),s(u),s(L),s(i),s($),s(O),s(c),s(H),s(r),s(P),s(K),s(q),s(MM),s(lM),s(g),s(sM),s(yM),s(Q),s(UM),s(tM),s(D),s(aM),s(_)),s(n),V(C,M),V(o,M),V(h,M),V(m,M),V(E,M),V(S,M)}}}const fM='{"title":"音频数据的流式加载","local":"音频数据的流式加载","sections":[],"depth":1}';function VM(TM){return QM(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zM extends SM{constructor(n){super(),DM(this,n,VM,dM,gM,{})}}export{zM as component};
