import{s as jn,o as mn,n as cn}from"../chunks/scheduler.cd324960.js";import{S as wn,i as rn,e as p,s as a,c as T,h as un,a as M,d as t,b as n,f as yn,g as U,j as J,k as la,l as fn,m as s,n as i,t as y,o as j,p as m}from"../chunks/index.d5c3adcc.js";import{T as hn}from"../chunks/Tip.889bec11.js";import{C as dn,H as u,E as on}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.e12d9735.js";import{C as c}from"../chunks/CodeBlock.111eae80.js";function Cn(We){let w,o="在我们的示例中，我们将使用大约 40 小时的训练数据。如果您想使用 Google Colab 免费版的 GPU 复现，需要将训练数据量减少到大约 10-15 小时，并减少训练步骤的数量。";return{c(){w=p("p"),w.textContent=o},l(r){w=M(r,"P",{"data-svelte-h":!0}),J(w)!=="svelte-az1j4w"&&(w.textContent=o)},m(r,Be){s(r,w,Be)},p:cn,d(r){r&&t(w)}}}function bn(We){let w,o,r,Be,C,ve,b,Ye,$,ea="现在您已经熟悉了语音合成任务和 SpeechT5 模型的内部工作原理，该模型是在英语数据上预训练的，让我们看看如何将其微调到另一种语言。",Ge,I,Ee,k,ta="如果您想复现这个示例，请确保您有一个 GPU。在笔记本中，您可以使用以下命令检查：",Xe,g,Ne,f,Fe,Z,sa="您还需要一些额外的依赖：",ze,Q,He,x,aa="最后，不要忘记登录您的 Hugging Face 账户，以便您能够上传并与社区共享您的模型：",qe,R,Se,A,De,V,na=`在这个示例中，我们将使用 <a href="https://huggingface.co/datasets/qmeeus/voxpopuli" rel="nofollow">VoxPopuli</a> 数据集的荷兰语（<code>nl</code>）子集。
<a href="https://huggingface.co/datasets/qmeeus/voxpopuli" rel="nofollow">VoxPopuli</a> 是一个大规模的多语言语音语料库，包含了 2009-2020 年欧洲议会事件的录音数据。
它包含 15 种欧洲语言的带标签的音频-转写数据。虽然我们将使用荷兰语子集，但您可以自由选择其他子集。`,Oe,B,pa="这是一个语音识别（ASR）数据集，所以，如前所述，它不是训练 TTS 模型的最佳选择。然而，对于这个练习来说，它已经足够好了。",Le,_,Ma="让我们加载数据：",Pe,W,Ke,v,Ja="<strong>输出：</strong>",lt,Y,et,G,Ta="20968 条数据应该足以进行微调。输入 SpeechT5 的音频数据应具有 16 kHz 的采样率，所以要确保我们的数据集满足这一要求：",tt,E,st,X,at,N,Ua="处理器包含了分词器和特征提取器，我们需要用它们来预处理训练数据。所以我们先定义要使用的模型检查点，并加载对应的处理器：",nt,F,pt,z,Mt,H,ia="首先，为了处理文本，我们需要处理器的分词器部分，所以让我们来获取它：",Jt,q,Tt,S,ya="让我们看一个示例：",Ut,D,it,O,ja="<strong>输出：</strong>",yt,L,jt,P,ma=`数据集包含一个 <code>text</code> 特征，我们将使用它作为文本输入。需要注意的是，SpeechT5 分词器没有任何数字的词元，
因此如果您的文本包含数字，您可能需要将它们写成文本形式。`,mt,K,ca=`因为 SpeechT5 是在英语上训练的，它可能无法识别荷兰语数据集中的某些字符。如果保持原样，这些字符将被转换为 <code>&lt;unk&gt;</code> 词元。
然而，在荷兰语中，某些字符如 <code>à</code> 用于强调音节。为了保留文本的含义，我们可以将此字符替换为普通的 <code>a</code>。`,ct,ll,wa=`要识别不支持的词元，使用 <code>SpeechT5Tokenizer</code> 提取数据集中所有独特字符，该分词器将字符视为词元。为此，我们将编写 <code>extract_all_chars</code> 映射函数，
该函数将所有数据样例的转写连接成一个字符串，然后转换为字符集。确保在 <code>dataset.map()</code> 中设置 <code>batched=True</code> 和 <code>batch_size=-1</code>，以便一次性获取所有转写并输入映射函数。`,wt,el,rt,tl,ra="现在您有两组字符：一个来自数据集，另一个来自分词器。要识别数据集中任何不支持的字符，您可以取这两组的差集，结果将包含在数据集中而不在分词器中的字符。",ut,sl,ft,al,ua="<strong>输出：</strong>",ht,nl,dt,pl,fa="为了处理上一步骤中识别的不支持字符，我们可以定义一个将这些字符映射到有效词元的函数。注意，分词器中的空格已经被替换为 <code>▁</code>，因此不需要单独处理。",ot,Ml,Ct,Jl,ha="现在我们处理好了文本中的特殊字符，是时候将注意力转移到音频数据上了。",bt,Tl,$t,Ul,da=`VoxPopuli 数据集包含多个说话人的语音，但到底有多少呢？我们可以计算一下数据集中说话人的数量以及每个说话人贡献的数据量。
数据集总共有 20,968 条数据，这些信息将帮助我们更好地了解数据中的说话人和数据样例的分布。`,It,il,kt,yl,oa="通过绘制直方图，您可以了解每个说话人的数据量。",gt,jl,Zt,h,Ca='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/tts_speakers_histogram.png" alt="Speakers histogram"/>',Qt,ml,ba="直方图显示，数据集中大约三分之一的说话人的数据少于 100 条，而大约十个说话人的数据超过 500 条。为了提高训练效率并平衡数据集，我们可以将数据限制在有 100 到 400 条数据的说话人之间。",xt,cl,Rt,wl,$a="让我们检查还剩多少个说话人：",At,rl,Vt,ul,Ia="<strong>输出：</strong>",Bt,fl,_t,hl,ka="让我们看看还剩多少条数据：",Wt,dl,vt,ol,ga="<strong>输出：</strong>",Yt,Cl,Gt,bl,Za="您留下了不到 10,000 条数据，来自大约 40 个独特的说话人，这应该足够用了。",Et,$l,Qa=`请注意，如果某些数据很长，一些看似数据样例量较少的说话人可能有比预想的更多的音频数据。然而，确定每个说话人的总音频量需要扫描整个数据集，
这是一个耗时的过程，涉及加载和解码每个音频文件。因此，我们在这里选择跳过这一步。`,Xt,Il,Nt,kl,xa=`为了使 TTS 模型能够区分多个说话人，您需要为每条数据创建一个说话人嵌入。说话人嵌入是模型的一个额外输入，用于描述特定说话人的声音特征。
要生成这些说话人嵌入，可以使用来自 SpeechBrain 的预训练模型 <a href="https://huggingface.co/speechbrain/spkrec-xvect-voxceleb" rel="nofollow">spkrec-xvect-voxceleb</a>。`,Ft,gl,Ra="创建一个 <code>create_speaker_embedding()</code> 函数，该函数接受音频波形作为输入，并输出包含相应说话人嵌入的 512 维向量。",zt,Zl,Ht,Ql,Aa=`注意，<code>speechbrain/spkrec-xvect-voxceleb</code> 模型是在 VoxCeleb 数据集的英语语音上训练的，而这个示例训练的是荷兰语。
虽然我们相信这个模型仍然可以为我们的荷兰语数据集生成合理的说话人嵌入，但这个假设可能不总是成立。`,qt,xl,Va=`为了获得最佳结果，我们需要首先在目标语音上训练 X-Vector 模型。这将确保模型能够更好地捕捉荷兰语中存在的独特声音特征。如果您想训练自己的 X-向量模型，
可以参考 <a href="https://huggingface.co/mechanicalsea/speecht5-vc/blob/main/manifest/utils/prep_cmu_arctic_spkemb.py" rel="nofollow">此脚本</a>。`,St,Rl,Dt,Al,Ba="最后，让我们将数据处理成模型能够读入的格式。创建一个 <code>prepare_dataset</code> 函数，输入单个示例并使用 <code>SpeechT5Processor</code> 对象来对输入文本进行分词，并将目标音频加载成对数梅尔谱。它还应该额外输入说话人嵌入。",Ot,Vl,Lt,Bl,_a="查看单个示例来验证处理是否正确：",Pt,_l,Kt,Wl,Wa="<strong>输出：</strong>",ls,vl,es,Yl,va="说话人嵌入应该是一个 512 维向量：",ts,Gl,ss,El,Ya="<strong>输出：</strong>",as,Xl,ns,Nl,Ga="标签应该是一个有 80 个 mel 频段的对数梅尔谱。",ps,Fl,Ms,d,Ea='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/tts_logmelspectrogram_1.png" alt="Log-mel spectrogram with 80 mel bins"/>',Js,zl,Xa="注：如果您看不明白这个频谱图，可能是因为您习惯将低频放在底部，高频放在顶部。然而，在使用 matplotlib 库将频谱图作为图像绘制时，y 轴是反过来的，频谱图看起来是倒置的。",Ts,Hl,Na="现在我们需要将处理函数应用于整个数据集。这将花费 5 到 10 分钟的时间。",Us,ql,is,Sl,Fa="您会看到一个警告说数据集中的某些数据长于模型能够处理的最大输入长度（600 词元），得从数据集中删除这些数据。在这里，我们更进一步，为了允许更大的批量大小，删除任何超过 200 词元的内容。",ys,Dl,js,Ol,za="<strong>输出：</strong>",ms,Ll,cs,Pl,Ha="接下来，把数据集分成基本的训练/测试子集：",ws,Kl,rs,le,us,ee,qa=`为了将多条数据组合成一个批次，您需要定义一个自定义数据整理器。这个整理器将使用填充词元填充较短的序列，确保所有示例都具有相同的长度。
对于频谱图标签，填充部分将被特殊值 <code>-100</code> 替换。这个特殊值指示模型在计算频谱图的损失函数时忽略那部分频谱图。`,fs,te,hs,se,Sa=`在 SpeechT5 中，模型的解码器部分的输入减少了 2 倍（reduction factor）。换句话说，它抛弃了目标序列中每两步中的一步。然后，解码器预测一个两倍长度的序列。
由于原来的目标序列长度可能是奇数，数据整理器会确保将批次的最大长度调整为 2 的倍数。`,ds,ae,os,ne,Cs,pe,Da="从与处理器相同的检查点加载预训练模型：",bs,Me,$s,Je,Oa="<code>use_cache=True</code> 选项与梯度检查点不兼容。我们在训练时禁用这个选项，并在生成时重新启用缓存以加快推理：",Is,Te,ks,Ue,La="定义训练参数。这里我们在训练过程中不计算任何评估指标，我们将在本章稍后讨论评估。这里，我们先只关注损失函数：",gs,ie,Zs,ye,Pa="实例化 <code>Trainer</code> 对象并将模型、数据集和数据整理器传递给它。",Qs,je,xs,me,Ka="有了这个，我们就准备开始训练了！训练将花费几个小时。由于 GPU 不同，当您开始训练时，可能会遇到 CUDA 报“out-of-memory”（显存不足）的错误。这时，您可以尝试将 <code>per_device_train_batch_size</code> 两倍两倍地减少，并将 <code>gradient_accumulation_steps</code> 增加到两倍以补偿。",Rs,ce,As,we,ln="将最终的模型上传到 🤗 Hub：",Vs,re,Bs,ue,_s,fe,en="一旦您微调了一个模型，您就可以使用它进行推理！从 🤗 Hub 加载模型（记得在以下代码片段中使用您的账号名）：",Ws,he,vs,de,tn="选择一个示例，这里我们将从测试数据集中取一个。获取说话人嵌入。",Ys,oe,Gs,Ce,sn="定义一些输入文本并对它进行分词。",Es,be,Xs,$e,an="预处理输入文本：",Ns,Ie,Fs,ke,nn="实例化一个声码器并生成语音：",zs,ge,Hs,Ze,pn="准备好听结果了吗？",qs,Qe,Ss,xe,Mn="用这个模型在新语言上获得的满意结果可能很有挑战性。说话人嵌入的质量可能是一个重要因素。由于 SpeechT5 是使用英语 X-Vector 预训练的，它在使用英语说话人嵌入时表现最佳。如果合成的语音听起来效果不好，尝试使用不同的说话人嵌入。",Ds,Re,Jn="增加训练时长也可能提高结果的质量。但即便不继续训练，语音也显然是荷兰语而不是英语，并且它确实学到了说话人的声音特征（与示例中的原始音频相比较）。另一个可以试验的是模型的配置。例如，尝试使用 <code>config.reduction_factor = 1</code> 来看是否能改善结果。",Os,Ae,Tn="在下一节中，我们将讨论如何评估语音合成模型。",Ls,Ve,Ps,_e,Ks;return C=new dn({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new u({props:{title:"微调 SpeechT5",local:"微调-speecht5",headingTag:"h1"}}),I=new u({props:{title:"基础准备",local:"基础准备",headingTag:"h2"}}),g=new c({props:{code:"bnZpZGlhLXNtaQ==",highlighted:"nvidia-smi",wrap:!1}}),f=new hn({props:{warning:!0,$$slots:{default:[Cn]},$$scope:{ctx:We}}}),Q=new c({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwc291bmRmaWxlJTIwc3BlZWNoYnJhaW4lMjBhY2NlbGVyYXRl",highlighted:"pip install transformers datasets soundfile speechbrain accelerate",wrap:!1}}),R=new c({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),A=new u({props:{title:"数据集",local:"数据集",headingTag:"h2"}}),W=new c({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTJDJTIwQXVkaW8lMEElMEFkYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMnFtZWV1cyUyRnZveHBvcHVsaSUyMiUyQyUyMCUyMm5sJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFsZW4oZGF0YXNldCk=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, Audio

dataset = load_dataset(<span class="hljs-string">&quot;qmeeus/voxpopuli&quot;</span>, <span class="hljs-string">&quot;nl&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-built_in">len</span>(dataset)`,wrap:!1}}),Y=new c({props:{code:"MjA5Njg=",highlighted:"20968",wrap:!1}}),E=new c({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQuY2FzdF9jb2x1bW4oJTIyYXVkaW8lMjIlMkMlMjBBdWRpbyhzYW1wbGluZ19yYXRlJTNEMTYwMDApKQ==",highlighted:'dataset = dataset.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16000</span>))',wrap:!1}}),X=new u({props:{title:"数据预处理",local:"数据预处理",headingTag:"h2"}}),F=new c({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNwZWVjaFQ1UHJvY2Vzc29yJTBBJTBBY2hlY2twb2ludCUyMCUzRCUyMCUyMm1pY3Jvc29mdCUyRnNwZWVjaHQ1X3R0cyUyMiUwQXByb2Nlc3NvciUyMCUzRCUyMFNwZWVjaFQ1UHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> SpeechT5Processor

checkpoint = <span class="hljs-string">&quot;microsoft/speecht5_tts&quot;</span>
processor = SpeechT5Processor.from_pretrained(checkpoint)`,wrap:!1}}),z=new u({props:{title:"为 SpeechT5 分词进行文本清理",local:"为-speecht5-分词进行文本清理",headingTag:"h3"}}),q=new c({props:{code:"dG9rZW5pemVyJTIwJTNEJTIwcHJvY2Vzc29yLnRva2VuaXplcg==",highlighted:"tokenizer = processor.tokenizer",wrap:!1}}),D=new c({props:{code:"ZGF0YXNldCU1QjAlNUQ=",high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yUyQyUwQSUyMCdzcGVha2VyX2lkJyUzQSUyMCcxMTIyJyUyQyUwQSUyMCdpc19nb2xkX3RyYW5zY3JpcHQnJTNBJTIwVHJ1ZSUyQyUwQSUyMCdhY2NlbnQnJTNBJTIwJ05vbmUnJTdE",highlighted:`{&#x27;audio_id&#x27;: &#x27;<span class="hljs-number">20100210-0900</span>-PLENARY-3-nl_<span class="hljs-number">20100210-09:06:43</span>_4&#x27;,
 &#x27;language&#x27;: <span class="hljs-number">9</span>,
 &#x27;audio&#x27;: {&#x27;path&#x27;: &#x27;/root/.cache/huggingface/datasets/downloads/extracted/02ec6a19d5b97c03e<span class="hljs-number">137925037845</span>4dbf3fa<span class="hljs-number">2972943504</span>a91c7da<span class="hljs-number">5045</span>aa26a89/train_part_0/<span class="hljs-number">20100210-0900</span>-PLENARY-3-nl_<span class="hljs-number">20100210-09:06:43</span>_4.wav&#x27;,
  &#x27;array&#x27;: array([ <span class="hljs-number">4.27246094</span>e-<span class="hljs-number">04</span>,  <span class="hljs-number">1.31225586</span>e-<span class="hljs-number">03</span>,  <span class="hljs-number">1.03759766</span>e-<span class="hljs-number">03</span>, ...,
         -<span class="hljs-number">9.15527344</span>e-<span class="hljs-number">05</span>,  <span class="hljs-number">7.62939453</span>e-<span class="hljs-number">04</span>, -<span class="hljs-number">2.44140625</span>e-<span class="hljs-number">04</span>]),
  &#x27;sampling_rate&#x27;: <span class="hljs-number">16000</span>},
 &#x27;text&#x27;: &#x27;dat kan naar mijn gevoel alleen met een brede meerderheid die wij samen zoeken.&#x27;,
 &#x27;gender&#x27;: &#x27;female&#x27;,
 &#x27;speaker_id&#x27;: &#x27;<span class="hljs-number">1122</span>&#x27;,
 &#x27;is_gold_transcript&#x27;: True,
 &#x27;accent&#x27;: &#x27;None&#x27;}`,wrap:!1}}),el=new c({props:{code:"ZGVmJTIwZXh0cmFjdF9hbGxfY2hhcnMoYmF0Y2gpJTNBJTBBJTIwJTIwJTIwJTIwYWxsX3RleHQlMjAlM0QlMjAlMjIlMjAlMjIuam9pbihiYXRjaCU1QiUyMnRleHQlMjIlNUQpJTBBJTIwJTIwJTIwJTIwdm9jYWIlMjAlM0QlMjBsaXN0KHNldChhbGxfdGV4dCkpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIydm9jYWIlMjIlM0ElMjAlNUJ2b2NhYiU1RCUyQyUyMCUyMmFsbF90ZXh0JTIyJTNBJTIwJTVCYWxsX3RleHQlNUQlN0QlMEElMEElMEF2b2NhYnMlMjAlM0QlMjBkYXRhc2V0Lm1hcCglMEElMjAlMjAlMjAlMjBleHRyYWN0X2FsbF9jaGFycyUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoZWQlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRC0xJTJDJTBBJTIwJTIwJTIwJTIwa2VlcF9pbl9tZW1vcnklM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmVtb3ZlX2NvbHVtbnMlM0RkYXRhc2V0LmNvbHVtbl9uYW1lcyUyQyUwQSklMEElMEFkYXRhc2V0X3ZvY2FiJTIwJTNEJTIwc2V0KHZvY2FicyU1QiUyMnZvY2FiJTIyJTVEJTVCMCU1RCklMEF0b2tlbml6ZXJfdm9jYWIlMjAlM0QlMjAlN0JrJTIwZm9yJTIwayUyQyUyMF8lMjBpbiUyMHRva2VuaXplci5nZXRfdm9jYWIoKS5pdGVtcygpJTdE",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">extract_all_chars</span>(<span class="hljs-params">batch</span>):
    all_text = <span class="hljs-string">&quot; &quot;</span>.join(batch[<span class="hljs-string">&quot;text&quot;</span>])
    vocab = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">set</span>(all_text))
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;vocab&quot;</span>: [vocab], <span class="hljs-string">&quot;all_text&quot;</span>: [all_text]}


vocabs = dataset.<span class="hljs-built_in">map</span>(
    extract_all_chars,
    batched=<span class="hljs-literal">True</span>,
    batch_size=-<span class="hljs-number">1</span>,
    keep_in_memory=<span class="hljs-literal">True</span>,
    remove_columns=dataset.column_names,
)

dataset_vocab = <span class="hljs-built_in">set</span>(vocabs[<span class="hljs-string">&quot;vocab&quot;</span>][<span class="hljs-number">0</span>])
tokenizer_vocab = {k <span class="hljs-keyword">for</span> k, _ <span class="hljs-keyword">in</span> tokenizer.get_vocab().items()}`,wrap:!1}}),sl=new c({props:{code:"ZGF0YXNldF92b2NhYiUyMC0lMjB0b2tlbml6ZXJfdm9jYWI=",highlighted:"dataset_vocab - tokenizer_vocab",wrap:!1}}),nl=new c({props:{code:"JTdCJyUyMCclMkMlMjAnJUMzJUEwJyUyQyUyMCclQzMlQTcnJTJDJTIwJyVDMyVBOCclMkMlMjAnJUMzJUFCJyUyQyUyMCclQzMlQUQnJTJDJTIwJyVDMyVBRiclMkMlMjAnJUMzJUI2JyUyQyUyMCclQzMlQkMnJTdE",highlighted:"{&#x27; &#x27;, &#x27;à&#x27;, &#x27;ç&#x27;, &#x27;è&#x27;, &#x27;ë&#x27;, &#x27;í&#x27;, &#x27;ï&#x27;, &#x27;ö&#x27;, &#x27;ü&#x27;}",wrap:!1}}),Ml=new c({props:{code:"cmVwbGFjZW1lbnRzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBMCUyMiUyQyUyMCUyMmElMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBNyUyMiUyQyUyMCUyMmMlMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBOCUyMiUyQyUyMCUyMmUlMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBQiUyMiUyQyUyMCUyMmUlMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBRCUyMiUyQyUyMCUyMmklMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVBRiUyMiUyQyUyMCUyMmklMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVCNiUyMiUyQyUyMCUyMm8lMjIpJTJDJTBBJTIwJTIwJTIwJTIwKCUyMiVDMyVCQyUyMiUyQyUyMCUyMnUlMjIpJTJDJTBBJTVEJTBBJTBBJTBBZGVmJTIwY2xlYW51cF90ZXh0KGlucHV0cyklM0ElMEElMjAlMjAlMjAlMjBmb3IlMjBzcmMlMkMlMjBkc3QlMjBpbiUyMHJlcGxhY2VtZW50cyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlucHV0cyU1QiUyMm5vcm1hbGl6ZWRfdGV4dCUyMiU1RCUyMCUzRCUyMGlucHV0cyU1QiUyMm5vcm1hbGl6ZWRfdGV4dCUyMiU1RC5yZXBsYWNlKHNyYyUyQyUyMGRzdCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHMlMEElMEElMEFkYXRhc2V0JTIwJTNEJTIwZGF0YXNldC5tYXAoY2xlYW51cF90ZXh0KQ==",highlighted:`replacements = [
    (<span class="hljs-string">&quot;à&quot;</span>, <span class="hljs-string">&quot;a&quot;</span>),
    (<span class="hljs-string">&quot;ç&quot;</span>, <span class="hljs-string">&quot;c&quot;</span>),
    (<span class="hljs-string">&quot;è&quot;</span>, <span class="hljs-string">&quot;e&quot;</span>),
    (<span class="hljs-string">&quot;ë&quot;</span>, <span class="hljs-string">&quot;e&quot;</span>),
    (<span class="hljs-string">&quot;í&quot;</span>, <span class="hljs-string">&quot;i&quot;</span>),
    (<span class="hljs-string">&quot;ï&quot;</span>, <span class="hljs-string">&quot;i&quot;</span>),
    (<span class="hljs-string">&quot;ö&quot;</span>, <span class="hljs-string">&quot;o&quot;</span>),
    (<span class="hljs-string">&quot;ü&quot;</span>, <span class="hljs-string">&quot;u&quot;</span>),
]


<span class="hljs-keyword">def</span> <span class="hljs-title function_">cleanup_text</span>(<span class="hljs-params">inputs</span>):
    <span class="hljs-keyword">for</span> src, dst <span class="hljs-keyword">in</span> replacements:
        inputs[<span class="hljs-string">&quot;normalized_text&quot;</span>] = inputs[<span class="hljs-string">&quot;normalized_text&quot;</span>].replace(src, dst)
    <span class="hljs-keyword">return</span> inputs


dataset = dataset.<span class="hljs-built_in">map</span>(cleanup_text)`,wrap:!1}}),Tl=new u({props:{title:"说话人",local:"说话人",headingTag:"h3"}}),il=new c({props:{code:"ZnJvbSUyMGNvbGxlY3Rpb25zJTIwaW1wb3J0JTIwZGVmYXVsdGRpY3QlMEElMEFzcGVha2VyX2NvdW50cyUyMCUzRCUyMGRlZmF1bHRkaWN0KGludCklMEElMEFmb3IlMjBzcGVha2VyX2lkJTIwaW4lMjBkYXRhc2V0JTVCJTIyc3BlYWtlcl9pZCUyMiU1RCUzQSUwQSUyMCUyMCUyMCUyMHNwZWFrZXJfY291bnRzJTVCc3BlYWtlcl9pZCU1RCUyMCUyQiUzRCUyMDE=",highlighted:`<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> defaultdict

speaker_counts = defaultdict(<span class="hljs-built_in">int</span>)

<span class="hljs-keyword">for</span> speaker_id <span class="hljs-keyword">in</span> dataset[<span class="hljs-string">&quot;speaker_id&quot;</span>]:
    speaker_counts[speaker_id] += <span class="hljs-number">1</span>`,wrap:!1}}),jl=new c({props:{code:"aW1wb3J0JTIwbWF0cGxvdGxpYi5weXBsb3QlMjBhcyUyMHBsdCUwQSUwQXBsdC5maWd1cmUoKSUwQXBsdC5oaXN0KHNwZWFrZXJfY291bnRzLnZhbHVlcygpJTJDJTIwYmlucyUzRDIwKSUwQXBsdC55bGFiZWwoJTIyU3BlYWtlcnMlMjIpJTBBcGx0LnhsYWJlbCglMjJFeGFtcGxlcyUyMiklMEFwbHQuc2hvdygp",highlighted:`<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

plt.figure()
plt.hist(speaker_counts.values(), bins=<span class="hljs-number">20</span>)
plt.ylabel(<span class="hljs-string">&quot;Speakers&quot;</span>)
plt.xlabel(<span class="hljs-string">&quot;Examples&quot;</span>)
plt.show()`,wrap:!1}}),cl=new c({props:{code:"ZGVmJTIwc2VsZWN0X3NwZWFrZXIoc3BlYWtlcl9pZCklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjAxMDAlMjAlM0MlM0QlMjBzcGVha2VyX2NvdW50cyU1QnNwZWFrZXJfaWQlNUQlMjAlM0MlM0QlMjA0MDAlMEElMEElMEFkYXRhc2V0JTIwJTNEJTIwZGF0YXNldC5maWx0ZXIoc2VsZWN0X3NwZWFrZXIlMkMlMjBpbnB1dF9jb2x1bW5zJTNEJTVCJTIyc3BlYWtlcl9pZCUyMiU1RCk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">select_speaker</span>(<span class="hljs-params">speaker_id</span>):
    <span class="hljs-keyword">return</span> <span class="hljs-number">100</span> &lt;= speaker_counts[speaker_id] &lt;= <span class="hljs-number">400</span>


dataset = dataset.<span class="hljs-built_in">filter</span>(select_speaker, input_columns=[<span class="hljs-string">&quot;speaker_id&quot;</span>])`,wrap:!1}}),rl=new c({props:{code:"bGVuKHNldChkYXRhc2V0JTVCJTIyc3BlYWtlcl9pZCUyMiU1RCkp",highlighted:'<span class="hljs-built_in">len</span>(<span class="hljs-built_in">set</span>(dataset[<span class="hljs-string">&quot;speaker_id&quot;</span>]))',wrap:!1}}),fl=new c({props:{code:"NDI=",highlighted:"42",wrap:!1}}),dl=new c({props:{code:"bGVuKGRhdGFzZXQp",highlighted:'<span class="hljs-built_in">len</span>(dataset)',wrap:!1}}),Cl=new c({props:{code:"OTk3Mw==",highlighted:'<span class="hljs-number">9973</span>',wrap:!1}}),Il=new u({props:{title:"说话人嵌入",local:"说话人嵌入",headingTag:"h3"}}),Zl=new c({props:{code:"aW1wb3J0JTIwb3MlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBzcGVlY2hicmFpbi5wcmV0cmFpbmVkJTIwaW1wb3J0JTIwRW5jb2RlckNsYXNzaWZpZXIlMEElMEFzcG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klMEElMjAlMjAlMjAlMjByZXR1cm4lMjBzcGVha2VyX2VtYmVkZGluZ3M=",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> speechbrain.pretrained <span class="hljs-keyword">import</span> EncoderClassifier

spk_model_name = <span class="hljs-string">&quot;speechbrain/spkrec-xvect-voxceleb&quot;</span>

device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>
speaker_model = EncoderClassifier.from_hparams(
    source=spk_model_name,
    run_opts={<span class="hljs-string">&quot;device&quot;</span>: device},
    savedir=os.path.join(<span class="hljs-string">&quot;/tmp&quot;</span>, spk_model_name),
)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_speaker_embedding</span>(<span class="hljs-params">waveform</span>):
    <span class="hljs-keyword">with</span> torch.no_grad():
        speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
        speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=<span class="hljs-number">2</span>)
        speaker_embeddings = speaker_embeddings.squeeze().cpu().numpy()
    <span class="hljs-keyword">return</span> speaker_embeddings`,wrap:!1}}),Rl=new u({props:{title:"处理数据集",local:"处理数据集",headingTag:"h3"}}),Vl=new c({props:{code:"ZGVmJTIwcHJlcGFyZV9kYXRhc2V0KGV4YW1wbGUpJTNBJTBBJTIwJTIwJTIwJTIwYXVkaW8lMjAlM0QlMjBleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlMEElMEElMjAlMjAlMjAlMjBleGFtcGxlJTIwJTNEJTIwcHJvY2Vzc29yKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRleHQlM0RleGFtcGxlJTVCJTIydGV4dCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGF1ZGlvX3RhcmdldCUzRGF1ZGlvJTVCJTIyYXJyYXklMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzYW1wbGluZ19yYXRlJTNEYXVkaW8lNUIlMjJzYW1wbGluZ19yYXRlJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuX2F0dGVudGlvbl9tYXNrJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwJUU1JThFJUJCJUU2JThFJTg5JUU2JTg5JUI5JUU5JTg3JThGJUU1JUE0JTg0JUU3JTkwJTg2JUU3JTlBJTg0JUU3JUJCJUI0JUU1JUJBJUE2JTBBJTIwJTIwJTIwJTIwZXhhbXBsZSU1QiUyMmxhYmVscyUyMiU1RCUyMCUzRCUyMGV4YW1wbGUlNUIlMjJsYWJlbHMlMjIlNUQlNUIwJTVEJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwJUU3JTk0JUE4JTIwU3BlZWNoQnJhaW4lMjAlRTglOEUlQjclRTUlOEYlOTYlMjBYLVZlY3RvciUwQSUyMCUyMCUyMCUyMGV4YW1wbGUlNUIlMjJzcGVha2VyX2VtYmVkZGluZ3MlMjIlNUQlMjAlM0QlMjBjcmVhdGVfc3BlYWtlcl9lbWJlZGRpbmcoYXVkaW8lNUIlMjJhcnJheSUyMiU1RCklMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBleGFtcGxl",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">prepare_dataset</span>(<span class="hljs-params">example</span>):
    audio = example[<span class="hljs-string">&quot;audio&quot;</span>]

    example = processor(
        text=example[<span class="hljs-string">&quot;text&quot;</span>],
        audio_target=audio[<span class="hljs-string">&quot;array&quot;</span>],
        sampling_rate=audio[<span class="hljs-string">&quot;sampling_rate&quot;</span>],
        return_attention_mask=<span class="hljs-literal">False</span>,
    )

    <span class="hljs-comment"># 去掉批量处理的维度</span>
    example[<span class="hljs-string">&quot;labels&quot;</span>] = example[<span class="hljs-string">&quot;labels&quot;</span>][<span class="hljs-number">0</span>]

    <span class="hljs-comment"># 用 SpeechBrain 获取 X-Vector</span>
    example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] = create_speaker_embedding(audio[<span class="hljs-string">&quot;array&quot;</span>])

    <span class="hljs-keyword">return</span> example`,wrap:!1}}),_l=new c({props:{code:"cHJvY2Vzc2VkX2V4YW1wbGUlMjAlM0QlMjBwcmVwYXJlX2RhdGFzZXQoZGF0YXNldCU1QjAlNUQpJTBBbGlzdChwcm9jZXNzZWRfZXhhbXBsZS5rZXlzKCkp",highlighted:`processed_example = prepare_dataset(dataset[<span class="hljs-number">0</span>])
<span class="hljs-built_in">list</span>(processed_example.keys())`,wrap:!1}}),vl=new c({props:{code:"JTVCJ2lucHV0X2lkcyclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdG9wX2xhYmVscyclMkMlMjAnc3BlYWtlcl9lbWJlZGRpbmdzJyU1RA==",highlighted:'[<span class="hljs-symbol">&#x27;input_ids</span>&#x27;, <span class="hljs-symbol">&#x27;labels</span>&#x27;, <span class="hljs-symbol">&#x27;stop_labels</span>&#x27;, <span class="hljs-symbol">&#x27;speaker_embeddings</span>&#x27;]',wrap:!1}}),Gl=new c({props:{code:"cHJvY2Vzc2VkX2V4YW1wbGUlNUIlMjJzcGVha2VyX2VtYmVkZGluZ3MlMjIlNUQuc2hhcGU=",highlighted:'processed_example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>].shape',wrap:!1}}),Xl=new c({props:{code:"KDUxMiUyQyk=",highlighted:'(<span class="hljs-number">512</span><span class="hljs-punctuation">,</span>)',wrap:!1}}),Fl=new c({props:{code:"aW1wb3J0JTIwbWF0cGxvdGxpYi5weXBsb3QlMjBhcyUyMHBsdCUwQSUwQXBsdC5maWd1cmUoKSUwQXBsdC5pbXNob3cocHJvY2Vzc2VkX2V4YW1wbGUlNUIlMjJsYWJlbHMlMjIlNUQuVCklMEFwbHQuc2hvdygp",highlighted:`<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

plt.figure()
plt.imshow(processed_example[<span class="hljs-string">&quot;labels&quot;</span>].T)
plt.show()`,wrap:!1}}),ql=new c({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQubWFwKHByZXBhcmVfZGF0YXNldCUyQyUyMHJlbW92ZV9jb2x1bW5zJTNEZGF0YXNldC5jb2x1bW5fbmFtZXMp",highlighted:'dataset = dataset.<span class="hljs-built_in">map</span>(prepare_dataset, remove_columns=dataset.column_names)',wrap:!1}}),Dl=new c({props:{code:"ZGVmJTIwaXNfbm90X3Rvb19sb25nKGlucHV0X2lkcyklM0ElMEElMjAlMjAlMjAlMjBpbnB1dF9sZW5ndGglMjAlM0QlMjBsZW4oaW5wdXRfaWRzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGlucHV0X2xlbmd0aCUyMCUzQyUyMDIwMCUwQSUwQSUwQWRhdGFzZXQlMjAlM0QlMjBkYXRhc2V0LmZpbHRlcihpc19ub3RfdG9vX2xvbmclMkMlMjBpbnB1dF9jb2x1bW5zJTNEJTVCJTIyaW5wdXRfaWRzJTIyJTVEKSUwQWxlbihkYXRhc2V0KQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">is_not_too_long</span>(<span class="hljs-params">input_ids</span>):
    input_length = <span class="hljs-built_in">len</span>(input_ids)
    <span class="hljs-keyword">return</span> input_length &lt; <span class="hljs-number">200</span>


dataset = dataset.<span class="hljs-built_in">filter</span>(is_not_too_long, input_columns=[<span class="hljs-string">&quot;input_ids&quot;</span>])
<span class="hljs-built_in">len</span>(dataset)`,wrap:!1}}),Ll=new c({props:{code:"ODI1OQ==",highlighted:'<span class="hljs-number">8259</span>',wrap:!1}}),Kl=new c({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQudHJhaW5fdGVzdF9zcGxpdCh0ZXN0X3NpemUlM0QwLjEp",highlighted:'dataset = dataset.train_test_split(test_size=<span class="hljs-number">0.1</span>)',wrap:!1}}),le=new u({props:{title:"数据整理器",local:"数据整理器",headingTag:"h3"}}),te=new c({props:{code:" ",highlighted:`<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Any</span>, <span class="hljs-type">Dict</span>, <span class="hljs-type">List</span>, <span class="hljs-type">Union</span>


<span class="hljs-meta">@dataclass</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">TTSDataCollatorWithPadding</span>:
    processor: <span class="hljs-type">Any</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">
        self, features: <span class="hljs-type">List</span>[<span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Union</span>[<span class="hljs-type">List</span>[<span class="hljs-built_in">int</span>], torch.Tensor]]]
    </span>) -&gt; <span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]:
        input_ids = [{<span class="hljs-string">&quot;input_ids&quot;</span>: feature[<span class="hljs-string">&quot;input_ids&quot;</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]
        label_features = [{<span class="hljs-string">&quot;input_values&quot;</span>: feature[<span class="hljs-string">&quot;labels&quot;</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]
        speaker_features = [feature[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]

        <span class="hljs-comment"># 把输入数据和生成目标整合进一个批次</span>
        batch = processor.pad(
            input_ids=input_ids, labels=label_features, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>
        )

        <span class="hljs-comment"># 把填充词元换成 -100 来正确地忽略这一部分的损失函数</span>
        batch[<span class="hljs-string">&quot;labels&quot;</span>] = batch[<span class="hljs-string">&quot;labels&quot;</span>].masked_fill(
            batch.decoder_attention_mask.unsqueeze(-<span class="hljs-number">1</span>).ne(<span class="hljs-number">1</span>), -<span class="hljs-number">100</span>
        )

        <span class="hljs-comment"># 在微调时用不上，删了</span>
        <span class="hljs-keyword">del</span> batch[<span class="hljs-string">&quot;decoder_attention_mask&quot;</span>]

        <span class="hljs-comment"># 把目标长度下调到 reduction factor 的整数倍</span>
        <span class="hljs-keyword">if</span> model.config.reduction_factor &gt; <span class="hljs-number">1</span>:
            target_lengths = torch.tensor(
                [<span class="hljs-built_in">len</span>(feature[<span class="hljs-string">&quot;input_values&quot;</span>]) <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> label_features]
            )
            target_lengths = target_lengths.new(
                [
                    length - length % model.config.reduction_factor
                    <span class="hljs-keyword">for</span> length <span class="hljs-keyword">in</span> target_lengths
                ]
            )
            max_length = <span class="hljs-built_in">max</span>(target_lengths)
            batch[<span class="hljs-string">&quot;labels&quot;</span>] = batch[<span class="hljs-string">&quot;labels&quot;</span>][:, :max_length]

        <span class="hljs-comment"># 加上说话人嵌入</span>
        batch[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] = torch.tensor(speaker_features)

        <span class="hljs-keyword">return</span> batch`,wrap:!1}}),ae=new c({props:{code:"ZGF0YV9jb2xsYXRvciUyMCUzRCUyMFRUU0RhdGFDb2xsYXRvcldpdGhQYWRkaW5nKHByb2Nlc3NvciUzRHByb2Nlc3Nvcik=",highlighted:"data_collator = TTSDataCollatorWithPadding(processor=processor)",wrap:!1}}),ne=new u({props:{title:"训练模型",local:"训练模型",headingTag:"h2"}}),Me=new c({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNwZWVjaFQ1Rm9yVGV4dFRvU3BlZWNoJTBBJTBBbW9kZWwlMjAlM0QlMjBTcGVlY2hUNUZvclRleHRUb1NwZWVjaC5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> SpeechT5ForTextToSpeech

model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)`,wrap:!1}}),Te=new c({props:{code:"ZnJvbSUyMGZ1bmN0b29scyUyMGltcG9ydCUyMHBhcnRpYWwlMEElMEElMjMlMjAlRTUlOUMlQTglRTglQUUlQUQlRTclQkIlODMlRTYlOTclQjYlRTclQTYlODElRTclOTQlQTglRTclQkMlOTMlRTUlQUQlOTglMEFtb2RlbC5jb25maWcudXNlX2NhY2hlJTIwJTNEJTIwRmFsc2UlMEElMEElMjMlMjAlRTglQUUlQkUlRTclQkQlQUUlRTglQUYlQUQlRTglQTglODAlRTUlOTIlOEMlRTQlQkIlQkIlRTUlOEElQTElRTUlODclODYlRTUlQTQlODclRTYlOEUlQTglRTclOTAlODYlRUYlQkMlOEMlRTUlQjklQjYlRTklODclOEQlRTYlOTYlQjAlRTUlOTAlQUYlRTclOTQlQTglRTclQkMlOTMlRTUlQUQlOTglMEFtb2RlbC5nZW5lcmF0ZSUyMCUzRCUyMHBhcnRpYWwobW9kZWwuZ2VuZXJhdGUlMkMlMjB1c2VfY2FjaGUlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial

<span class="hljs-comment"># 在训练时禁用缓存</span>
model.config.use_cache = <span class="hljs-literal">False</span>

<span class="hljs-comment"># 设置语言和任务准备推理，并重新启用缓存</span>
model.generate = partial(model.generate, use_cache=<span class="hljs-literal">True</span>)`,wrap:!1}}),ie=new c({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBTZXEyU2VxVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMnNwZWVjaHQ1X2ZpbmV0dW5lZF92b3hwb3B1bGlfbmwlMjIlMkMlMjAlMjAlMjMlMjAlRTYlOTQlQjklRTYlODgl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QSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainingArguments

training_args = Seq2SeqTrainingArguments(
    output_dir=<span class="hljs-string">&quot;speecht5_finetuned_voxpopuli_nl&quot;</span>,  <span class="hljs-comment"># 改成您选择的仓库名</span>
    per_device_train_batch_size=<span class="hljs-number">4</span>,
    gradient_accumulation_steps=<span class="hljs-number">8</span>,
    learning_rate=<span class="hljs-number">1e-5</span>,
    warmup_steps=<span class="hljs-number">500</span>,
    max_steps=<span class="hljs-number">4000</span>,
    gradient_checkpointing=<span class="hljs-literal">True</span>,
    fp16=<span class="hljs-literal">True</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    per_device_eval_batch_size=<span class="hljs-number">2</span>,
    save_steps=<span class="hljs-number">1000</span>,
    eval_steps=<span class="hljs-number">1000</span>,
    logging_steps=<span class="hljs-number">25</span>,
    report_to=[<span class="hljs-string">&quot;tensorboard&quot;</span>],
    load_best_model_at_end=<span class="hljs-literal">True</span>,
    greater_is_better=<span class="hljs-literal">False</span>,
    label_names=[<span class="hljs-string">&quot;labels&quot;</span>],
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),je=new c({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBdHJhaW5lciUyMCUzRCUyMFNlcTJTZXFUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0RkYXRhc2V0JTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0RkYXRhc2V0JTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGRhdGFfY29sbGF0b3IlM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVyJTNEcHJvY2Vzc29yJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    args=training_args,
    model=model,
    train_dataset=dataset[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=dataset[<span class="hljs-string">&quot;test&quot;</span>],
    data_collator=data_collator,
    tokenizer=processor,
)`,wrap:!1}}),ce=new c({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),re=new c({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),ue=new u({props:{title:"推理",local:"推理",headingTag:"h2"}}),he=new c({props:{code:"bW9kZWwlMjAlM0QlMjBTcGVlY2hUNUZvclRleHRUb1NwZWVjaC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyJUU2JTgyJUE4JUU3JTlBJTg0JUU4JUI0JUE2JUU1JThGJUI3JTJGc3BlZWNodDVfZmluZXR1bmVkX3ZveHBvcHVsaV9ubCUyMiUwQSk=",highlighted:`model = SpeechT5ForTextToSpeech.from_pretrained(
    <span class="hljs-string">&quot;您的账号/speecht5_finetuned_voxpopuli_nl&quot;</span>
)`,wrap:!1}}),oe=new c({props:{code:"ZXhhbXBsZSUyMCUzRCUyMGRhdGFzZXQlNUIlMjJ0ZXN0JTIyJTVEJTVCMzA0JTVEJTBBc3BlYWtlcl9lbWJlZGRpbmdzJTIwJTNEJTIwdG9yY2gudGVuc29yKGV4YW1wbGUlNUIlMjJzcGVha2VyX2VtYmVkZGluZ3MlMjIlNUQpLnVuc3F1ZWV6ZSgwKQ==",highlighted:`example = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-number">304</span>]
speaker_embeddings = torch.tensor(example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>]).unsqueeze(<span class="hljs-number">0</span>)`,wrap:!1}}),be=new c({props:{code:"dGV4dCUyMCUzRCUyMCUyMmhhbGxvJTIwYWxsZW1hYWwlMkMlMjBpayUyMHByYWF0JTIwbmVkZXJsYW5kcy4lMjBncm9ldGplcyUyMGFhbiUyMGllZGVyZWVuISUyMg==",highlighted:'text = <span class="hljs-string">&quot;hallo allemaal, ik praat nederlands. groetjes aan iedereen!&quot;</span>',wrap:!1}}),Ie=new c({props:{code:"aW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKHRleHQlM0R0ZXh0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMik=",highlighted:'inputs = processor(text=text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)',wrap:!1}}),ge=new c({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNwZWVjaFQ1SGlmaUdhbiUwQSUwQXZvY29kZXIlMjAlM0QlMjBTcGVlY2hUNUhpZmlHYW4uZnJvbV9wcmV0cmFpbmVkKCUyMm1pY3Jvc29mdCUyRnNwZWVjaHQ1X2hpZmlnYW4lMjIpJTBBc3BlZWNoJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGVfc3BlZWNoKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCUyQyUyMHNwZWFrZXJfZW1iZWRkaW5ncyUyQyUyMHZvY29kZXIlM0R2b2NvZGVyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> SpeechT5HifiGan

vocoder = SpeechT5HifiGan.from_pretrained(<span class="hljs-string">&quot;microsoft/speecht5_hifigan&quot;</span>)
speech = model.generate_speech(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>], speaker_embeddings, vocoder=vocoder)`,wrap:!1}}),Qe=new c({props:{code:"ZnJvbSUyMElQeXRob24uZGlzcGxheSUyMGltcG9ydCUyMEF1ZGlvJTBBJTBBQXVkaW8oc3BlZWNoLm51bXB5KCklMkMlMjByYXRlJTNEMTYwMDAp",highlighted:`<span class="hljs-keyword">from</span> IPython.display <span class="hljs-keyword">import</span> Audio

Audio(speech.numpy(), rate=<span class="hljs-number">16000</span>)`,wrap:!1}}),Ve=new on({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/zh-CN/chapter6/fine-tuning.mdx"}}),{c(){w=p("meta"),o=a(),r=p("p"),Be=a(),T(C.$$.fragment),ve=a(),T(b.$$.fragment),Ye=a(),$=p("p"),$.textContent=ea,Ge=a(),T(I.$$.fragment),Ee=a(),k=p("p"),k.textContent=ta,Xe=a(),T(g.$$.fragment),Ne=a(),T(f.$$.fragment),Fe=a(),Z=p("p"),Z.textContent=sa,ze=a(),T(Q.$$.fragment),He=a(),x=p("p"),x.textContent=aa,qe=a(),T(R.$$.fragment),Se=a(),T(A.$$.fragment),De=a(),V=p("p"),V.innerHTML=na,Oe=a(),B=p("p"),B.textContent=pa,Le=a(),_=p("p"),_.textContent=Ma,Pe=a(),T(W.$$.fragment),Ke=a(),v=p("p"),v.innerHTML=Ja,lt=a(),T(Y.$$.fragment),et=a(),G=p("p"),G.textContent=Ta,tt=a(),T(E.$$.fragment),st=a(),T(X.$$.fragment),at=a(),N=p("p"),N.textContent=Ua,nt=a(),T(F.$$.fragment),pt=a(),T(z.$$.fragment),Mt=a(),H=p("p"),H.textContent=ia,Jt=a(),T(q.$$.fragment),Tt=a(),S=p("p"),S.textContent=ya,Ut=a(),T(D.$$.fragment),it=a(),O=p("p"),O.innerHTML=ja,yt=a(),T(L.$$.fragment),jt=a(),P=p("p"),P.innerHTML=ma,mt=a(),K=p("p"),K.innerHTML=ca,ct=a(),ll=p("p"),ll.innerHTML=wa,wt=a(),T(el.$$.fragment),rt=a(),tl=p("p"),tl.textContent=ra,ut=a(),T(sl.$$.fragment),ft=a(),al=p("p"),al.innerHTML=ua,ht=a(),T(nl.$$.fragment),dt=a(),pl=p("p"),pl.innerHTML=fa,ot=a(),T(Ml.$$.fragment),Ct=a(),Jl=p("p"),Jl.textContent=ha,bt=a(),T(Tl.$$.fragment),$t=a(),Ul=p("p"),Ul.textContent=da,It=a(),T(il.$$.fragment),kt=a(),yl=p("p"),yl.textContent=oa,gt=a(),T(jl.$$.fragment),Zt=a(),h=p("div"),h.innerHTML=Ca,Qt=a(),ml=p("p"),ml.textContent=ba,xt=a(),T(cl.$$.fragment),Rt=a(),wl=p("p"),wl.textContent=$a,At=a(),T(rl.$$.fragment),Vt=a(),ul=p("p"),ul.innerHTML=Ia,Bt=a(),T(fl.$$.fragment),_t=a(),hl=p("p"),hl.textContent=ka,Wt=a(),T(dl.$$.fragment),vt=a(),ol=p("p"),ol.innerHTML=ga,Yt=a(),T(Cl.$$.fragment),Gt=a(),bl=p("p"),bl.textContent=Za,Et=a(),$l=p("p"),$l.textContent=Qa,Xt=a(),T(Il.$$.fragment),Nt=a(),kl=p("p"),kl.innerHTML=xa,Ft=a(),gl=p("p"),gl.innerHTML=Ra,zt=a(),T(Zl.$$.fragment),Ht=a(),Ql=p("p"),Ql.innerHTML=Aa,qt=a(),xl=p("p"),xl.innerHTML=Va,St=a(),T(Rl.$$.fragment),Dt=a(),Al=p("p"),Al.innerHTML=Ba,Ot=a(),T(Vl.$$.fragment),Lt=a(),Bl=p("p"),Bl.textContent=_a,Pt=a(),T(_l.$$.fragment),Kt=a(),Wl=p("p"),Wl.innerHTML=Wa,ls=a(),T(vl.$$.fragment),es=a(),Yl=p("p"),Yl.textContent=va,ts=a(),T(Gl.$$.fragment),ss=a(),El=p("p"),El.innerHTML=Ya,as=a(),T(Xl.$$.fragment),ns=a(),Nl=p("p"),Nl.textContent=Ga,ps=a(),T(Fl.$$.fragment),Ms=a(),d=p("div"),d.innerHTML=Ea,Js=a(),zl=p("p"),zl.textContent=Xa,Ts=a(),Hl=p("p"),Hl.textContent=Na,Us=a(),T(ql.$$.fragment),is=a(),Sl=p("p"),Sl.textContent=Fa,ys=a(),T(Dl.$$.fragment),js=a(),Ol=p("p"),Ol.innerHTML=za,ms=a(),T(Ll.$$.fragment),cs=a(),Pl=p("p"),Pl.textContent=Ha,ws=a(),T(Kl.$$.fragment),rs=a(),T(le.$$.fragment),us=a(),ee=p("p"),ee.innerHTML=qa,fs=a(),T(te.$$.fragment),hs=a(),se=p("p"),se.textContent=Sa,ds=a(),T(ae.$$.fragment),os=a(),T(ne.$$.fragment),Cs=a(),pe=p("p"),pe.textContent=Da,bs=a(),T(Me.$$.fragment),$s=a(),Je=p("p"),Je.innerHTML=Oa,Is=a(),T(Te.$$.fragment),ks=a(),Ue=p("p"),Ue.textContent=La,gs=a(),T(ie.$$.fragment),Zs=a(),ye=p("p"),ye.innerHTML=Pa,Qs=a(),T(je.$$.fragment),xs=a(),me=p("p"),me.innerHTML=Ka,Rs=a(),T(ce.$$.fragment),As=a(),we=p("p"),we.textContent=ln,Vs=a(),T(re.$$.fragment),Bs=a(),T(ue.$$.fragment),_s=a(),fe=p("p"),fe.textContent=en,Ws=a(),T(he.$$.fragment),vs=a(),de=p("p"),de.textContent=tn,Ys=a(),T(oe.$$.fragment),Gs=a(),Ce=p("p"),Ce.textContent=sn,Es=a(),T(be.$$.fragment),Xs=a(),$e=p("p"),$e.textContent=an,Ns=a(),T(Ie.$$.fragment),Fs=a(),ke=p("p"),ke.textContent=nn,zs=a(),T(ge.$$.fragment),Hs=a(),Ze=p("p"),Ze.textContent=pn,qs=a(),T(Qe.$$.fragment),Ss=a(),xe=p("p"),xe.textContent=Mn,Ds=a(),Re=p("p"),Re.innerHTML=Jn,Os=a(),Ae=p("p"),Ae.textContent=Tn,Ls=a(),T(Ve.$$.fragment),Ps=a(),_e=p("p"),this.h()},l(l){const e=un("svelte-u9bgzb",document.head);w=M(e,"META",{name:!0,content:!0}),e.forEach(t),o=n(l),r=M(l,"P",{}),yn(r).forEach(t),Be=n(l),U(C.$$.fragment,l),ve=n(l),U(b.$$.fragment,l),Ye=n(l),$=M(l,"P",{"data-svelte-h":!0}),J($)!=="svelte-1mq8wfv"&&($.textContent=ea),Ge=n(l),U(I.$$.fragment,l),Ee=n(l),k=M(l,"P",{"data-svelte-h":!0}),J(k)!=="svelte-1e5vilx"&&(k.textContent=ta),Xe=n(l),U(g.$$.fragment,l),Ne=n(l),U(f.$$.fragment,l),Fe=n(l),Z=M(l,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-f18nl2"&&(Z.textContent=sa),ze=n(l),U(Q.$$.fragment,l),He=n(l),x=M(l,"P",{"data-svelte-h":!0}),J(x)!=="svelte-j2pd5z"&&(x.textContent=aa),qe=n(l),U(R.$$.fragment,l),Se=n(l),U(A.$$.fragment,l),De=n(l),V=M(l,"P",{"data-svelte-h":!0}),J(V)!=="svelte-130pet3"&&(V.innerHTML=na),Oe=n(l),B=M(l,"P",{"data-svelte-h":!0}),J(B)!=="svelte-1mt7w1y"&&(B.textContent=pa),Le=n(l),_=M(l,"P",{"data-svelte-h":!0}),J(_)!=="svelte-1ee133t"&&(_.textContent=Ma),Pe=n(l),U(W.$$.fragment,l),Ke=n(l),v=M(l,"P",{"data-svelte-h":!0}),J(v)!=="svelte-1yevus4"&&(v.innerHTML=Ja),lt=n(l),U(Y.$$.fragment,l),et=n(l),G=M(l,"P",{"data-svelte-h":!0}),J(G)!=="svelte-14mygxn"&&(G.textContent=Ta),tt=n(l),U(E.$$.fragment,l),st=n(l),U(X.$$.fragment,l),at=n(l),N=M(l,"P",{"data-svelte-h":!0}),J(N)!=="svelte-myc28k"&&(N.textContent=Ua),nt=n(l),U(F.$$.fragment,l),pt=n(l),U(z.$$.fragment,l),Mt=n(l),H=M(l,"P",{"data-svelte-h":!0}),J(H)!=="svelte-1k6p6xo"&&(H.textContent=ia),Jt=n(l),U(q.$$.fragment,l),Tt=n(l),S=M(l,"P",{"data-svelte-h":!0}),J(S)!=="svelte-o1gog8"&&(S.textContent=ya),Ut=n(l),U(D.$$.fragment,l),it=n(l),O=M(l,"P",{"data-svelte-h":!0}),J(O)!=="svelte-1yevus4"&&(O.innerHTML=ja),yt=n(l),U(L.$$.fragment,l),jt=n(l),P=M(l,"P",{"data-svelte-h":!0}),J(P)!=="svelte-1cczdrx"&&(P.innerHTML=ma),mt=n(l),K=M(l,"P",{"data-svelte-h":!0}),J(K)!=="svelte-snkesy"&&(K.innerHTML=ca),ct=n(l),ll=M(l,"P",{"data-svelte-h":!0}),J(ll)!=="svelte-zq9kvx"&&(ll.innerHTML=wa),wt=n(l),U(el.$$.fragment,l),rt=n(l),tl=M(l,"P",{"data-svelte-h":!0}),J(tl)!=="svelte-1yggo6j"&&(tl.textContent=ra),ut=n(l),U(sl.$$.fragment,l),ft=n(l),al=M(l,"P",{"data-svelte-h":!0}),J(al)!=="svelte-1yevus4"&&(al.innerHTML=ua),ht=n(l),U(nl.$$.fragment,l),dt=n(l),pl=M(l,"P",{"data-svelte-h":!0}),J(pl)!=="svelte-18q69cr"&&(pl.innerHTML=fa),ot=n(l),U(Ml.$$.fragment,l),Ct=n(l),Jl=M(l,"P",{"data-svelte-h":!0}),J(Jl)!=="svelte-t46ksf"&&(Jl.textContent=ha),bt=n(l),U(Tl.$$.fragment,l),$t=n(l),Ul=M(l,"P",{"data-svelte-h":!0}),J(Ul)!=="svelte-si6krf"&&(Ul.textContent=da),It=n(l),U(il.$$.fragment,l),kt=n(l),yl=M(l,"P",{"data-svelte-h":!0}),J(yl)!=="svelte-1a4y7jc"&&(yl.textContent=oa),gt=n(l),U(jl.$$.fragment,l),Zt=n(l),h=M(l,"DIV",{class:!0,"data-svelte-h":!0}),J(h)!=="svelte-1uufiik"&&(h.innerHTML=Ca),Qt=n(l),ml=M(l,"P",{"data-svelte-h":!0}),J(ml)!=="svelte-1n2xy9x"&&(ml.textContent=ba),xt=n(l),U(cl.$$.fragment,l),Rt=n(l),wl=M(l,"P",{"data-svelte-h":!0}),J(wl)!=="svelte-w4zc6g"&&(wl.textContent=$a),At=n(l),U(rl.$$.fragment,l),Vt=n(l),ul=M(l,"P",{"data-svelte-h":!0}),J(ul)!=="svelte-1yevus4"&&(ul.innerHTML=Ia),Bt=n(l),U(fl.$$.fragment,l),_t=n(l),hl=M(l,"P",{"data-svelte-h":!0}),J(hl)!=="svelte-3ki28v"&&(hl.textContent=ka),Wt=n(l),U(dl.$$.fragment,l),vt=n(l),ol=M(l,"P",{"data-svelte-h":!0}),J(ol)!=="svelte-1yevus4"&&(ol.innerHTML=ga),Yt=n(l),U(Cl.$$.fragment,l),Gt=n(l),bl=M(l,"P",{"data-svelte-h":!0}),J(bl)!=="svelte-1r0ckxv"&&(bl.textContent=Za),Et=n(l),$l=M(l,"P",{"data-svelte-h":!0}),J($l)!=="svelte-115y9a6"&&($l.textContent=Qa),Xt=n(l),U(Il.$$.fragment,l),Nt=n(l),kl=M(l,"P",{"data-svelte-h":!0}),J(kl)!=="svelte-1vb1v7p"&&(kl.innerHTML=xa),Ft=n(l),gl=M(l,"P",{"data-svelte-h":!0}),J(gl)!=="svelte-15d2tc9"&&(gl.innerHTML=Ra),zt=n(l),U(Zl.$$.fragment,l),Ht=n(l),Ql=M(l,"P",{"data-svelte-h":!0}),J(Ql)!=="svelte-1ojzcke"&&(Ql.innerHTML=Aa),qt=n(l),xl=M(l,"P",{"data-svelte-h":!0}),J(xl)!=="svelte-vn616r"&&(xl.innerHTML=Va),St=n(l),U(Rl.$$.fragment,l),Dt=n(l),Al=M(l,"P",{"data-svelte-h":!0}),J(Al)!=="svelte-1blnag0"&&(Al.innerHTML=Ba),Ot=n(l),U(Vl.$$.fragment,l),Lt=n(l),Bl=M(l,"P",{"data-svelte-h":!0}),J(Bl)!=="svelte-1nl861s"&&(Bl.textContent=_a),Pt=n(l),U(_l.$$.fragment,l),Kt=n(l),Wl=M(l,"P",{"data-svelte-h":!0}),J(Wl)!=="svelte-1yevus4"&&(Wl.innerHTML=Wa),ls=n(l),U(vl.$$.fragment,l),es=n(l),Yl=M(l,"P",{"data-svelte-h":!0}),J(Yl)!=="svelte-crgj40"&&(Yl.textContent=va),ts=n(l),U(Gl.$$.fragment,l),ss=n(l),El=M(l,"P",{"data-svelte-h":!0}),J(El)!=="svelte-1yevus4"&&(El.innerHTML=Ya),as=n(l),U(Xl.$$.fragment,l),ns=n(l),Nl=M(l,"P",{"data-svelte-h":!0}),J(Nl)!=="svelte-g6mluh"&&(Nl.textContent=Ga),ps=n(l),U(Fl.$$.fragment,l),Ms=n(l),d=M(l,"DIV",{class:!0,"data-svelte-h":!0}),J(d)!=="svelte-j4o1b8"&&(d.innerHTML=Ea),Js=n(l),zl=M(l,"P",{"data-svelte-h":!0}),J(zl)!=="svelte-82ihiz"&&(zl.textContent=Xa),Ts=n(l),Hl=M(l,"P",{"data-svelte-h":!0}),J(Hl)!=="svelte-61um8j"&&(Hl.textContent=Na),Us=n(l),U(ql.$$.fragment,l),is=n(l),Sl=M(l,"P",{"data-svelte-h":!0}),J(Sl)!=="svelte-19pcez9"&&(Sl.textContent=Fa),ys=n(l),U(Dl.$$.fragment,l),js=n(l),Ol=M(l,"P",{"data-svelte-h":!0}),J(Ol)!=="svelte-1yevus4"&&(Ol.innerHTML=za),ms=n(l),U(Ll.$$.fragment,l),cs=n(l),Pl=M(l,"P",{"data-svelte-h":!0}),J(Pl)!=="svelte-1aub7yi"&&(Pl.textContent=Ha),ws=n(l),U(Kl.$$.fragment,l),rs=n(l),U(le.$$.fragment,l),us=n(l),ee=M(l,"P",{"data-svelte-h":!0}),J(ee)!=="svelte-1ug6prq"&&(ee.innerHTML=qa),fs=n(l),U(te.$$.fragment,l),hs=n(l),se=M(l,"P",{"data-svelte-h":!0}),J(se)!=="svelte-n9sw30"&&(se.textContent=Sa),ds=n(l),U(ae.$$.fragment,l),os=n(l),U(ne.$$.fragment,l),Cs=n(l),pe=M(l,"P",{"data-svelte-h":!0}),J(pe)!=="svelte-kpt5ph"&&(pe.textContent=Da),bs=n(l),U(Me.$$.fragment,l),$s=n(l),Je=M(l,"P",{"data-svelte-h":!0}),J(Je)!=="svelte-7avbs0"&&(Je.innerHTML=Oa),Is=n(l),U(Te.$$.fragment,l),ks=n(l),Ue=M(l,"P",{"data-svelte-h":!0}),J(Ue)!=="svelte-169ijvl"&&(Ue.textContent=La),gs=n(l),U(ie.$$.fragment,l),Zs=n(l),ye=M(l,"P",{"data-svelte-h":!0}),J(ye)!=="svelte-hto4ro"&&(ye.innerHTML=Pa),Qs=n(l),U(je.$$.fragment,l),xs=n(l),me=M(l,"P",{"data-svelte-h":!0}),J(me)!=="svelte-4sfz1e"&&(me.innerHTML=Ka),Rs=n(l),U(ce.$$.fragment,l),As=n(l),we=M(l,"P",{"data-svelte-h":!0}),J(we)!=="svelte-w4esym"&&(we.textContent=ln),Vs=n(l),U(re.$$.fragment,l),Bs=n(l),U(ue.$$.fragment,l),_s=n(l),fe=M(l,"P",{"data-svelte-h":!0}),J(fe)!=="svelte-ou25m7"&&(fe.textContent=en),Ws=n(l),U(he.$$.fragment,l),vs=n(l),de=M(l,"P",{"data-svelte-h":!0}),J(de)!=="svelte-xms5tj"&&(de.textContent=tn),Ys=n(l),U(oe.$$.fragment,l),Gs=n(l),Ce=M(l,"P",{"data-svelte-h":!0}),J(Ce)!=="svelte-4e57y3"&&(Ce.textContent=sn),Es=n(l),U(be.$$.fragment,l),Xs=n(l),$e=M(l,"P",{"data-svelte-h":!0}),J($e)!=="svelte-b1ybtn"&&($e.textContent=an),Ns=n(l),U(Ie.$$.fragment,l),Fs=n(l),ke=M(l,"P",{"data-svelte-h":!0}),J(ke)!=="svelte-m4c265"&&(ke.textContent=nn),zs=n(l),U(ge.$$.fragment,l),Hs=n(l),Ze=M(l,"P",{"data-svelte-h":!0}),J(Ze)!=="svelte-v08fsb"&&(Ze.textContent=pn),qs=n(l),U(Qe.$$.fragment,l),Ss=n(l),xe=M(l,"P",{"data-svelte-h":!0}),J(xe)!=="svelte-8y01aj"&&(xe.textContent=Mn),Ds=n(l),Re=M(l,"P",{"data-svelte-h":!0}),J(Re)!=="svelte-185eq6j"&&(Re.innerHTML=Jn),Os=n(l),Ae=M(l,"P",{"data-svelte-h":!0}),J(Ae)!=="svelte-g4ct72"&&(Ae.textContent=Tn),Ls=n(l),U(Ve.$$.fragment,l),Ps=n(l),_e=M(l,"P",{}),yn(_e).forEach(t),this.h()},h(){la(w,"name","hf:doc:metadata"),la(w,"content",$n),la(h,"class","flex justify-center"),la(d,"class","flex justify-center")},m(l,e){fn(document.head,w),s(l,o,e),s(l,r,e),s(l,Be,e),i(C,l,e),s(l,ve,e),i(b,l,e),s(l,Ye,e),s(l,$,e),s(l,Ge,e),i(I,l,e),s(l,Ee,e),s(l,k,e),s(l,Xe,e),i(g,l,e),s(l,Ne,e),i(f,l,e),s(l,Fe,e),s(l,Z,e),s(l,ze,e),i(Q,l,e),s(l,He,e),s(l,x,e),s(l,qe,e),i(R,l,e),s(l,Se,e),i(A,l,e),s(l,De,e),s(l,V,e),s(l,Oe,e),s(l,B,e),s(l,Le,e),s(l,_,e),s(l,Pe,e),i(W,l,e),s(l,Ke,e),s(l,v,e),s(l,lt,e),i(Y,l,e),s(l,et,e),s(l,G,e),s(l,tt,e),i(E,l,e),s(l,st,e),i(X,l,e),s(l,at,e),s(l,N,e),s(l,nt,e),i(F,l,e),s(l,pt,e),i(z,l,e),s(l,Mt,e),s(l,H,e),s(l,Jt,e),i(q,l,e),s(l,Tt,e),s(l,S,e),s(l,Ut,e),i(D,l,e),s(l,it,e),s(l,O,e),s(l,yt,e),i(L,l,e),s(l,jt,e),s(l,P,e),s(l,mt,e),s(l,K,e),s(l,ct,e),s(l,ll,e),s(l,wt,e),i(el,l,e),s(l,rt,e),s(l,tl,e),s(l,ut,e),i(sl,l,e),s(l,ft,e),s(l,al,e),s(l,ht,e),i(nl,l,e),s(l,dt,e),s(l,pl,e),s(l,ot,e),i(Ml,l,e),s(l,Ct,e),s(l,Jl,e),s(l,bt,e),i(Tl,l,e),s(l,$t,e),s(l,Ul,e),s(l,It,e),i(il,l,e),s(l,kt,e),s(l,yl,e),s(l,gt,e),i(jl,l,e),s(l,Zt,e),s(l,h,e),s(l,Qt,e),s(l,ml,e),s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i(ce,l,e),s(l,As,e),s(l,we,e),s(l,Vs,e),i(re,l,e),s(l,Bs,e),i(ue,l,e),s(l,_s,e),s(l,fe,e),s(l,Ws,e),i(he,l,e),s(l,vs,e),s(l,de,e),s(l,Ys,e),i(oe,l,e),s(l,Gs,e),s(l,Ce,e),s(l,Es,e),i(be,l,e),s(l,Xs,e),s(l,$e,e),s(l,Ns,e),i(Ie,l,e),s(l,Fs,e),s(l,ke,e),s(l,zs,e),i(ge,l,e),s(l,Hs,e),s(l,Ze,e),s(l,qs,e),i(Qe,l,e),s(l,Ss,e),s(l,xe,e),s(l,Ds,e),s(l,Re,e),s(l,Os,e),s(l,Ae,e),s(l,Ls,e),i(Ve,l,e),s(l,Ps,e),s(l,_e,e),Ks=!0},p(l,[e]){const Un={};e&2&&(Un.$$scope={dirty:e,ctx:l}),f.$set(Un)},i(l){Ks||(y(C.$$.fragment,l),y(b.$$.fragment,l),y(I.$$.fragment,l),y(g.$$.fragment,l),y(f.$$.fragment,l),y(Q.$$.fragment,l),y(R.$$.fragment,l),y(A.$$.fragment,l),y(W.$$.fragment,l),y(Y.$$.fragment,l),y(E.$$.fragment,l),y(X.$$.fragment,l),y(F.$$.fragment,l),y(z.$$.fragment,l),y(q.$$.fragment,l),y(D.$$.fragment,l),y(L.$$.fragment,l),y(el.$$.fragment,l),y(sl.$$.fragment,l),y(nl.$$.fragment,l),y(Ml.$$.fragment,l),y(Tl.$$.fragment,l),y(il.$$.fragment,l),y(jl.$$.fragment,l),y(cl.$$.fragment,l),y(rl.$$.fragment,l),y(fl.$$.fragment,l),y(dl.$$.fragment,l),y(Cl.$$.fragment,l),y(Il.$$.fragment,l),y(Zl.$$.fragment,l),y(Rl.$$.fragment,l),y(Vl.$$.fragment,l),y(_l.$$.fragment,l),y(vl.$$.fragment,l),y(Gl.$$.fragment,l),y(Xl.$$.fragment,l),y(Fl.$$.fragment,l),y(ql.$$.fragment,l),y(Dl.$$.fragment,l),y(Ll.$$.fragment,l),y(Kl.$$.fragment,l),y(le.$$.fragment,l),y(te.$$.fragment,l),y(ae.$$.fragment,l),y(ne.$$.fragment,l),y(Me.$$.fragment,l),y(Te.$$.fragment,l),y(ie.$$.fragment,l),y(je.$$.fragment,l),y(ce.$$.fragment,l),y(re.$$.fragment,l),y(ue.$$.fragment,l),y(he.$$.fragment,l),y(oe.$$.fragment,l),y(be.$$.fragment,l),y(Ie.$$.fragment,l),y(ge.$$.fragment,l),y(Qe.$$.fragment,l),y(Ve.$$.fragment,l),Ks=!0)},o(l){j(C.$$.fragment,l),j(b.$$.fragment,l),j(I.$$.fragment,l),j(g.$$.fragment,l),j(f.$$.fragment,l),j(Q.$$.fragment,l),j(R.$$.fragment,l),j(A.$$.fragment,l),j(W.$$.fragment,l),j(Y.$$.fragment,l),j(E.$$.fragment,l),j(X.$$.fragment,l),j(F.$$.fragment,l),j(z.$$.fragment,l),j(q.$$.fragment,l),j(D.$$.fragment,l),j(L.$$.fragment,l),j(el.$$.fragment,l),j(sl.$$.fragment,l),j(nl.$$.fragment,l),j(Ml.$$.fragment,l),j(Tl.$$.fragment,l),j(il.$$.fragment,l),j(jl.$$.fragment,l),j(cl.$$.fragment,l),j(rl.$$.fragment,l),j(fl.$$.fragment,l),j(dl.$$.fragment,l),j(Cl.$$.fragment,l),j(Il.$$.fragment,l),j(Zl.$$.fragment,l),j(Rl.$$.fragment,l),j(Vl.$$.fragment,l),j(_l.$$.fragment,l),j(vl.$$.fragment,l),j(Gl.$$.fragment,l),j(Xl.$$.fragment,l),j(Fl.$$.fragment,l),j(ql.$$.fragment,l),j(Dl.$$.fragment,l),j(Ll.$$.fragment,l),j(Kl.$$.fragment,l),j(le.$$.fragment,l),j(te.$$.fragment,l),j(ae.$$.fragment,l),j(ne.$$.fragment,l),j(Me.$$.fragment,l),j(Te.$$.fragment,l),j(ie.$$.fragment,l),j(je.$$.fragment,l),j(ce.$$.fragment,l),j(re.$$.fragment,l),j(ue.$$.fragment,l),j(he.$$.fragment,l),j(oe.$$.fragment,l),j(be.$$.fragment,l),j(Ie.$$.fragment,l),j(ge.$$.fragment,l),j(Qe.$$.fragment,l),j(Ve.$$.fragment,l),Ks=!1},d(l){l&&(t(o),t(r),t(Be),t(ve),t(Ye),t($),t(Ge),t(Ee),t(k),t(Xe),t(Ne),t(Fe),t(Z),t(ze),t(He),t(x),t(qe),t(Se),t(De),t(V),t(Oe),t(B),t(Le),t(_),t(Pe),t(Ke),t(v),t(lt),t(et),t(G),t(tt),t(st),t(at),t(N),t(nt),t(pt),t(Mt),t(H),t(Jt),t(Tt),t(S),t(Ut),t(it),t(O),t(yt),t(jt),t(P),t(mt),t(K),t(ct),t(ll),t(wt),t(rt),t(tl),t(ut),t(ft),t(al),t(ht),t(dt),t(pl),t(ot),t(Ct),t(Jl),t(bt),t($t),t(Ul),t(It),t(kt),t(yl),t(gt),t(Zt),t(h),t(Qt),t(ml),t(xt),t(Rt),t(wl),t(At),t(Vt),t(ul),t(Bt),t(_t),t(hl),t(Wt),t(vt),t(ol),t(Yt),t(Gt),t(bl),t(Et),t($l),t(Xt),t(Nt),t(kl),t(Ft),t(gl),t(zt),t(Ht),t(Ql),t(qt),t(xl),t(St),t(Dt),t(Al),t(Ot),t(Lt),t(Bl),t(Pt),t(Kt),t(Wl),t(ls),t(es),t(Yl),t(ts),t(ss),t(El),t(as),t(ns),t(Nl),t(ps),t(Ms),t(d),t(Js),t(zl),t(Ts),t(Hl),t(Us),t(is),t(Sl),t(ys),t(js),t(Ol),t(ms),t(cs),t(Pl),t(ws),t(rs),t(us),t(ee),t(fs),t(hs),t(se),t(ds),t(os),t(Cs),t(pe),t(bs),t($s),t(Je),t(Is),t(ks),t(Ue),t(gs),t(Zs),t(ye),t(Qs),t(xs),t(me),t(Rs),t(As),t(we),t(Vs),t(Bs),t(_s),t(fe),t(Ws),t(vs),t(de),t(Ys),t(Gs),t(Ce),t(Es),t(Xs),t($e),t(Ns),t(Fs),t(ke),t(zs),t(Hs),t(Ze),t(qs),t(Ss),t(xe),t(Ds),t(Re),t(Os),t(Ae),t(Ls),t(Ps),t(_e)),t(w),m(C,l),m(b,l),m(I,l),m(g,l),m(f,l),m(Q,l),m(R,l),m(A,l),m(W,l),m(Y,l),m(E,l),m(X,l),m(F,l),m(z,l),m(q,l),m(D,l),m(L,l),m(el,l),m(sl,l),m(nl,l),m(Ml,l),m(Tl,l),m(il,l),m(jl,l),m(cl,l),m(rl,l),m(fl,l),m(dl,l),m(Cl,l),m(Il,l),m(Zl,l),m(Rl,l),m(Vl,l),m(_l,l),m(vl,l),m(Gl,l),m(Xl,l),m(Fl,l),m(ql,l),m(Dl,l),m(Ll,l),m(Kl,l),m(le,l),m(te,l),m(ae,l),m(ne,l),m(Me,l),m(Te,l),m(ie,l),m(je,l),m(ce,l),m(re,l),m(ue,l),m(he,l),m(oe,l),m(be,l),m(Ie,l),m(ge,l),m(Qe,l),m(Ve,l)}}}const $n='{"title":"微调 SpeechT5","local":"微调-speecht5","sections":[{"title":"基础准备","local":"基础准备","sections":[],"depth":2},{"title":"数据集","local":"数据集","sections":[],"depth":2},{"title":"数据预处理","local":"数据预处理","sections":[{"title":"为 SpeechT5 分词进行文本清理","local":"为-speecht5-分词进行文本清理","sections":[],"depth":3},{"title":"说话人","local":"说话人","sections":[],"depth":3},{"title":"说话人嵌入","local":"说话人嵌入","sections":[],"depth":3},{"title":"处理数据集","local":"处理数据集","sections":[],"depth":3},{"title":"数据整理器","local":"数据整理器","sections":[],"depth":3}],"depth":2},{"title":"训练模型","local":"训练模型","sections":[],"depth":2},{"title":"推理","local":"推理","sections":[],"depth":2}],"depth":1}';function In(We){return mn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Rn extends wn{constructor(w){super(),rn(this,w,In,bn,jn,{})}}export{Rn as component};
