import{s as Aa,f as Va,o as Ea,n as Hl}from"../chunks/scheduler.37c15a92.js";import{S as za,i as Ya,g as J,s as n,r as T,A as Fa,h as m,f as s,c as a,j as Xn,u as o,x as u,k as $l,y as Ha,a as e,v as U,t as y,b as Ve,d as c,w as j,p as Ne}from"../chunks/index.2bf4358c.js";import{T as ls}from"../chunks/Tip.363c041f.js";import{Y as kn}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as Qa}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{F as Sa}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as _l,E as Da}from"../chunks/EditOnGithub.8916dc7c.js";function qa(k){let p,d;return p=new Qa({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section4_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section4_tf.ipynb"}]}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,f){U(p,r,f),d=!0},i(r){d||(c(p.$$.fragment,r),d=!0)},o(r){y(p.$$.fragment,r),d=!1},d(r){j(p,r)}}}function La(k){let p,d;return p=new Qa({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section4_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section4_pt.ipynb"}]}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,f){U(p,r,f),d=!0},i(r){d||(c(p.$$.fragment,r),d=!0)},o(r){y(p.$$.fragment,r),d=!1},d(r){j(p,r)}}}function Pa(k){let p,d="✏️ <strong>轮到你了！</strong> 另一个在法语中经常使用的英语单词是“email”。在训练数据集中找到使用这个词的第一个样本。它是如何翻译的？预训练模型如何翻译同一个英文句子？";return{c(){p=J("p"),p.innerHTML=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-no44wf"&&(p.innerHTML=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function Ka(k){let p,d="💡 如果正在使用mart、mBART-50或M2 M100等多语言标记器，则需要在tokenizer中设置tokenizer.src_lang和tokenizer.tgt_lang为正确的输入和目标的语言代码。";return{c(){p=J("p"),p.textContent=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-59ya5z"&&(p.textContent=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function Oa(k){let p,d="💡如果你使用的是T5模型(更具体地说，是T5 -xxx检查点之一)，模型将需要文本输入有一个前缀来表示正在进行的任务，例如从英语到法语的翻译";return{c(){p=J("p"),p.textContent=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-1ub3nk2"&&(p.textContent=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function lp(k){let p,d="⚠️ 我们不关注目标的注意力掩码，因为模型不会需要它。相反，对应于填充标记的标签应设置为-100，以便在loss计算中忽略它们。这将在稍后由我们的数据整理器完成，因为我们正在应用动态填充，但是如果您在此处使用填充，您应该调整预处理函数以将与填充标记对应的所有标签设置为 -100。";return{c(){p=J("p"),p.textContent=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-jo20py"&&(p.textContent=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function sp(k){let p,d,r,f="首先，我们需要一个实际的模型来进行微调。 我们将使用通常的 <code>AutoModel</code> API：",Z,w,_,G,x;return p=new _l({props:{title:"使用 Keras 微调模型",local:"使用 Keras 微调模型",headingTag:"h2"}}),w=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxMlNlcUxNJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCUyQyUyMGZyb21fcHQlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSeq2SeqLM

model = TFAutoModelForSeq2SeqLM.from_pretrained(model_checkpoint, from_pt=<span class="hljs-literal">True</span>)`,wrap:!1}}),G=new ls({props:{warning:!1,$$slots:{default:[tp]},$$scope:{ctx:k}}}),{c(){T(p.$$.fragment),d=n(),r=J("p"),r.innerHTML=f,Z=n(),T(w.$$.fragment),_=n(),T(G.$$.fragment)},l(g){o(p.$$.fragment,g),d=a(g),r=m(g,"P",{"data-svelte-h":!0}),u(r)!=="svelte-l874w1"&&(r.innerHTML=f),Z=a(g),o(w.$$.fragment,g),_=a(g),o(G.$$.fragment,g)},m(g,C){U(p,g,C),e(g,d,C),e(g,r,C),e(g,Z,C),U(w,g,C),e(g,_,C),U(G,g,C),x=!0},i(g){x||(c(p.$$.fragment,g),c(w.$$.fragment,g),c(G.$$.fragment,g),x=!0)},o(g){y(p.$$.fragment,g),y(w.$$.fragment,g),y(G.$$.fragment,g),x=!1},d(g){g&&(s(d),s(r),s(Z),s(_)),j(p,g),j(w,g),j(G,g)}}}function ep(k){let p,d,r,f='使用 <code>Trainer</code> 的实际代码将与以前相同，只是稍作改动：我们在这里使用 <a href="https://huggingface.co/transformers/main_classes/trainer.html#seq2seqtrainer" rel="nofollow"><code>Seq2SeqTrainer</code></a>， 它是 <code>Trainer</code> 的子类，它可以正确处理这种序列到序列的评估，并使用 <code>generate()</code> 方法来预测输入的输出。 当我们讨论评估指标时，我们将更详细地探讨这一点。',Z,w,_="首先，我们需要一个实际的模型来进行微调。 我们将使用通常的 <code>AutoModel</code> API：",G,x,g;return p=new _l({props:{title:"使用 Trainer API 微调模型",local:"使用 Trainer API 微调模型",headingTag:"h2"}}),x=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)`,wrap:!1}}),{c(){T(p.$$.fragment),d=n(),r=J("p"),r.innerHTML=f,Z=n(),w=J("p"),w.innerHTML=_,G=n(),T(x.$$.fragment)},l(C){o(p.$$.fragment,C),d=a(C),r=m(C,"P",{"data-svelte-h":!0}),u(r)!=="svelte-102a0ve"&&(r.innerHTML=f),Z=a(C),w=m(C,"P",{"data-svelte-h":!0}),u(w)!=="svelte-l874w1"&&(w.innerHTML=_),G=a(C),o(x.$$.fragment,C)},m(C,W){U(p,C,W),e(C,d,W),e(C,r,W),e(C,Z,W),e(C,w,W),e(C,G,W),U(x,C,W),g=!0},i(C){g||(c(p.$$.fragment,C),c(x.$$.fragment,C),g=!0)},o(C){y(p.$$.fragment,C),y(x.$$.fragment,C),g=!1},d(C){C&&(s(d),s(r),s(Z),s(w),s(G)),j(p,C),j(x,C)}}}function tp(k){let p,d="💡 <code>Helsinki-NLP/opus-mt-en-fr</code> checkpoint只有 PyTorch 的权重，所以在使用<code>from_pretrained()</code>方法加载模型时不会使用 <code>from_pt=True</code> 参数。 当您指定<code>from_pt=True</code>，库会自动下载并转换PyTorch 为您提供权重。 如您所见，使用🤗transormer 在两者之间切换非常简单";return{c(){p=J("p"),p.innerHTML=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-1rl7uof"&&(p.innerHTML=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function np(k){let p,d;return p=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`,wrap:!1}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,f){U(p,r,f),d=!0},i(r){d||(c(p.$$.fragment,r),d=!0)},o(r){y(p.$$.fragment,r),d=!1},d(r){j(p,r)}}}function ap(k){let p,d;return p=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)`,wrap:!1}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,f){U(p,r,f),d=!0},i(r){d||(c(p.$$.fragment,r),d=!0)},o(r){y(p.$$.fragment,r),d=!1},d(r){j(p,r)}}}function pp(k){let p,d="我们现在可以使用 <code>data_collator</code> 将我们的每个数据集转换为 <code>tf.data.Dataset</code>，准备好进行训练：",r,f,Z;return f=new h({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMzIlMkMlMEEpJTBBdGZfZXZhbF9kYXRhc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxNiUyQyUwQSk=",highlighted:`tf_train_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">32</span>,
)
tf_eval_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">16</span>,
)`,wrap:!1}}),{c(){p=J("p"),p.innerHTML=d,r=n(),T(f.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),u(p)!=="svelte-ug4cr2"&&(p.innerHTML=d),r=a(w),o(f.$$.fragment,w)},m(w,_){e(w,p,_),e(w,r,_),U(f,w,_),Z=!0},i(w){Z||(c(f.$$.fragment,w),Z=!0)},o(w){y(f.$$.fragment,w),Z=!1},d(w){w&&(s(p),s(r)),j(f,w)}}}function Mp(k){let p,d="我们将把这个 <code>data_collator</code> 传递给 <code>Seq2SeqTrainer</code>。 接下来，让我们看一下评估指标。";return{c(){p=J("p"),p.innerHTML=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-exil4s"&&(p.innerHTML=d)},m(r,f){e(r,p,f)},i:Hl,o:Hl,d(r){r&&s(p)}}}function Na(k){let p,d="<code>Seq2SeqTrainer</code> 添加到其超类 <code>Trainer</code> 的功能是在评估或预测期间使用 <code>generate()</code> 方法的能力。 在训练期间，模型将使用带有注意掩码的“decoder_input_ids”，以确保它不使用预测的标记之后的标记，以加快训练速度。 在推理过程中，我们将无法使用预测的标记之后的标记，因为我们没有标签，因此使用相同的设置使用带有注意掩码的“decoder_input_ids”，评估我们的模型是个好主意。",r,f,Z='正如我们在<a href="/course/chapter1/6">第一章</a>看到的，解码器通过一个一个地预测标记来执行推理——这是🤗 Transformers 在幕后通过 <strong>generate()</strong> 方法实现的。如果我们设置 predict_with_generate=True，Seq2 Seq Trainer 将允许我们使用该方法进行评估。';return{c(){p=J("p"),p.innerHTML=d,r=n(),f=J("p"),f.innerHTML=Z},l(w){p=m(w,"P",{"data-svelte-h":!0}),u(p)!=="svelte-8mh6bv"&&(p.innerHTML=d),r=a(w),f=m(w,"P",{"data-svelte-h":!0}),u(f)!=="svelte-149jxw9"&&(f.innerHTML=Z)},m(w,_){e(w,p,_),e(w,r,_),e(w,f,_)},d(w){w&&(s(p),s(r),s(f))}}}function rp(k){let p,d="为了从模型输出到度量可以使用的文本，我们将使用 <code>tokenizer.batch_decode()</code> 方法。 我们只需要清理标签中的所有 <code>-100</code>（标记器将自动对填充标记执行相同操作）：",r,f,Z;return f=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZHMpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWRzJTBBJTIwJTIwJTIwJTIwJTIzJTIwSW4lMjBjYXNlJTIwdGhlJTIwbW9kZWwlMjByZXR1cm5zJTIwbW9yZSUyMHRoYW4lMjB0aGUlMjBwcmVkaWN0aW9uJTIwbG9naXRzJTBBJTIwJTIwJTIwJTIwaWYlMjBpc2luc3RhbmNlKHByZWRzJTJDJTIwdHVwbGUpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJlZHMlMjAlM0QlMjBwcmVkcyU1QjAlNUQlMEElMEElMjAlMjAlMjAlMjBkZWNvZGVkX3ByZWRzJTIwJTNEJTIwdG9rZW5pemVyLmJhdGNoX2RlY29kZShwcmVkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFJlcGxhY2UlMjAtMTAwcyUyMGluJTIwdGhlJTIwbGFiZWxzJTIwYXMlMjB3ZSUyMGNhbid0JTIwZGVjb2RlJTIwdGhlbSUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUobGFiZWxzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwU29tZSUyMHNpbXBsZSUyMHBvc3QtcHJvY2Vzc2luZyUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjAlNUJwcmVkLnN0cmlwKCklMjBmb3IlMjBwcmVkJTIwaW4lMjBkZWNvZGVkX3ByZWRzJTVEJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9sYWJlbHMlMjAlM0QlMjAlNUIlNUJsYWJlbC5zdHJpcCgpJTVEJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RkZWNvZGVkX3ByZWRzJTJDJTIwcmVmZXJlbmNlcyUzRGRlY29kZWRfbGFiZWxzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMmJsZXUlMjIlM0ElMjByZXN1bHQlNUIlMjJzY29yZSUyMiU1RCU3RA==",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_preds</span>):
    preds, labels = eval_preds
    <span class="hljs-comment"># In case the model returns more than the prediction logits</span>
    <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(preds, <span class="hljs-built_in">tuple</span>):
        preds = preds[<span class="hljs-number">0</span>]

    decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># Replace -100s in the labels as we can&#x27;t decode them</span>
    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># Some simple post-processing</span>
    decoded_preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
    decoded_labels = [[label.strip()] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]

    result = metric.compute(predictions=decoded_preds, references=decoded_labels)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;bleu&quot;</span>: result[<span class="hljs-string">&quot;score&quot;</span>]}`,wrap:!1}}),{c(){p=J("p"),p.innerHTML=d,r=n(),T(f.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),u(p)!=="svelte-bxrv4x"&&(p.innerHTML=d),r=a(w),o(f.$$.fragment,w)},m(w,_){e(w,p,_),e(w,r,_),U(f,w,_),Z=!0},i(w){Z||(c(f.$$.fragment,w),Z=!0)},o(w){y(f.$$.fragment,w),Z=!1},d(w){w&&(s(p),s(r)),j(f,w)}}}function ip(k){let p,d='为了将模型输出的向量转换为可以使用的文本，我们将使用 <code>tokenizer.batch_decode()</code> 方法。 我们只需要清除标签中的所有“-100”； tokenizer 将自动对填充令牌执行相同的操作。 让我们定义一个函数，它接受我们的模型和数据集并计算其指标。 我们还将使用一个可以显着提高性能的技巧 - 使用 TensorFlow 的加速线性代数编译器 <a href="https://www.tensorflow.org/xla" rel="nofollow">XLA</a> 编译我们的生成代码。 XLA 对模型的计算图应用了各种优化，并显着提高了速度和内存使用率。 正如 Hugging Face <a href="https://huggingface.co/blog/tf-xla-generate" rel="nofollow">博客</a> 中所述，当我们的输入形状变化不大时，XLA 效果最佳。 为了处理这个问题，我们将输入填充为 128 的倍数，并使用填充整理器创建一个新数据集，然后我们将 @tf.function(jit_compile=True) 装饰器应用于我们的生成函数，将整个函数标记为使用 XLA 进行编译。',r,f,Z;return f=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHFkbSUyMGltcG9ydCUyMHRxZG0lMEElMEFnZW5lcmF0aW9uX2RhdGFfY29sbGF0b3IlMjAlM0QlMjBEYXRhQ29sbGF0b3JGb3JTZXEyU2VxKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUyQyUyMG1vZGVsJTNEbW9kZWwlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyJTJDJTIwcGFkX3RvX211bHRpcGxlX29mJTNEMTI4JTBBKSUwQSUwQXRmX2dlbmVyYXRlX2RhdGFzZXQlMjAlM0QlMjBtb2RlbC5wcmVwYXJlX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RnZW5lcmF0aW9uX2RhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSklMEElMEElMEElNDB0Zi5mdW5jdGlvbihqaXRfY29tcGlsZSUzRFRydWUpJTBBZGVmJTIwZ2VuZXJhdGVfd2l0aF94bGEoYmF0Y2gpJTNBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTNEYmF0Y2glNUIlMjJpbnB1dF9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhdHRlbnRpb25fbWFzayUzRGJhdGNoJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtYXhfbmV3X3Rva2VucyUzRDEyOCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMEElMEFkZWYlMjBjb21wdXRlX21ldHJpY3MoKSUzQSUwQSUyMCUyMCUyMCUyMGFsbF9wcmVkcyUyMCUzRCUyMCU1QiU1RCUwQSUyMCUyMCUyMCUyMGFsbF9sYWJlbHMlMjAlM0QlMjAlNUIlNUQlMEElMjAlMjAlMjAlMjBzYW1wbGVkX2RhdGFzZXQlMjAlM0QlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVELnNodWZmbGUoKS5zZWxlY3QocmFuZ2UoMjAwKSklMEElMjAlMjAlMjAlMjB0Zl9nZW5lcmF0ZV9kYXRhc2V0JTIwJTNEJTIwc2FtcGxlZF9kYXRhc2V0LnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzaHVmZmxlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNENCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyQyUyMGxhYmVscyUyMGluJTIwdHFkbSh0Zl9nZW5lcmF0ZV9kYXRhc2V0KSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwZ2VuZXJhdGVfd2l0aF94bGEoYmF0Y2gpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUocHJlZGljdGlvbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBsYWJlbHMubnVtcHkoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUobGFiZWxzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMCU1QnByZWQuc3RyaXAoKSUyMGZvciUyMHByZWQlMjBpbiUyMGRlY29kZWRfcHJlZHMlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMCU1QiU1QmxhYmVsLnN0cmlwKCklNUQlMjBmb3IlMjBsYWJlbCUyMGluJTIwZGVjb2RlZF9sYWJlbHMlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfcHJlZHMuZXh0ZW5kKGRlY29kZWRfcHJlZHMpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWxsX2xhYmVscy5leHRlbmQoZGVjb2RlZF9sYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RhbGxfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEYWxsX2xhYmVscyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMjJibGV1JTIyJTNBJTIwcmVzdWx0JTVCJTIyc2NvcmUlMjIlNUQlN0Q=",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> tqdm <span class="hljs-keyword">import</span> tqdm

generation_data_collator = DataCollatorForSeq2Seq(
    tokenizer, model=model, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>, pad_to_multiple_of=<span class="hljs-number">128</span>
)

tf_generate_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    collate_fn=generation_data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">8</span>,
)


<span class="hljs-meta">@tf.function(<span class="hljs-params">jit_compile=<span class="hljs-literal">True</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_with_xla</span>(<span class="hljs-params">batch</span>):
    <span class="hljs-keyword">return</span> model.generate(
        input_ids=batch[<span class="hljs-string">&quot;input_ids&quot;</span>],
        attention_mask=batch[<span class="hljs-string">&quot;attention_mask&quot;</span>],
        max_new_tokens=<span class="hljs-number">128</span>,
    )


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>():
    all_preds = []
    all_labels = []
    sampled_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].shuffle().select(<span class="hljs-built_in">range</span>(<span class="hljs-number">200</span>))
    tf_generate_dataset = sampled_dataset.to_tf_dataset(
        columns=[<span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>],
        collate_fn=data_collator,
        shuffle=<span class="hljs-literal">False</span>,
        batch_size=<span class="hljs-number">4</span>,
    )
    <span class="hljs-keyword">for</span> batch, labels <span class="hljs-keyword">in</span> tqdm(tf_generate_dataset):
        predictions = generate_with_xla(batch)
        decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
        labels = labels.numpy()
        labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
        decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
        decoded_preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
        decoded_labels = [[label.strip()] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]
        all_preds.extend(decoded_preds)
        all_labels.extend(decoded_labels)

    result = metric.compute(predictions=all_preds, references=all_labels)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;bleu&quot;</span>: result[<span class="hljs-string">&quot;score&quot;</span>]}`,wrap:!1}}),{c(){p=J("p"),p.innerHTML=d,r=n(),T(f.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),u(p)!=="svelte-sznvab"&&(p.innerHTML=d),r=a(w),o(f.$$.fragment,w)},m(w,_){e(w,p,_),e(w,r,_),U(f,w,_),Z=!0},i(w){Z||(c(f.$$.fragment,w),Z=!0)},o(w){y(f.$$.fragment,w),Z=!1},d(w){w&&(s(p),s(r)),j(f,w)}}}function cp(k){let p,d="一旦完成，我们就可以定义我们的 <code>Seq2SeqTrainingArguments</code>。 与 <code>Trainer</code> 一样，我们使用 <code>TrainingArguments</code> 的子类，其中包含更多可以设置的字段：",r,f,Z,w,_="除了通常的超参数（如学习率、训练轮数、批次大小和一些权重衰减）之外，与我们在前几节中看到的相比，这里有一些变化：",G,x,g="<li>我们没有设置任何定期评估，因为评估需要耗费一定的时间；我们只会在训练开始之前和结束之后评估我们的模型一次。</li> <li>我们设置fp16=True，这可以加快支持fp16的 GPU 上的训练速度。</li> <li>和上面我们讨论的那样，我们设置predict_with_generate=True</li> <li>我们用push_to_hub=True在每个 epoch 结束时将模型上传到 Hub。</li>",C,W,O='请注意，您可以使用 <code>hub_model_id</code> 参数指定要推送到的存储库的名称（当您想把模型推送到指定的组织的时候，您也必须使用此参数）。 例如，当我们将模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> 组织</a> 时，我们添加了 <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en- to-fr&quot;</code> 到 <code>Seq2SeqTrainingArguments</code>。 默认情况下，使用的存储库将在您的命名空间中，并以您设置的输出目录命名，因此这里将是 <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code>。',Tl,Q,Y,L,N="最后，我们需要将所有内容传递给 <strong>Seq2SeqTrainer</strong> ：",ol,A,F,P,v="在训练之前，我们将首先查看我们的模型获得的分数，以仔细检查我们的微调没有让事情变得更糟。此命令需要一些时间，因此您可以在执行时喝杯咖啡：",gl,K,X,ll,E,R,Ml="BLEU的分数还不错，这反映了我们的模型已经擅长将英语句子翻译成法语句子。",sl,V,b="接下来是训练，这也需要一些时间：",B,el,Ul,yl,rl="请注意，当训练发生时，每次保存模型时（这里是每个时期），它都会在后台上传到 Hub。这样，如有必要，您将能够在另一台机器上继续您的训练。",bl,H,Sl="训练完成后，我们再次评估我们的模型——希望我们会看到 BLEU 分数有所改善！",fl,S,dl,D,Fl,Jl,il="这是近 14 点的改进，这很棒。",hl,q,Dl="最后，我们使用 <strong>push_to_hub()</strong> 方法来确保我们上传模型的最新版本。这 <strong>Trainer</strong> 还创建了一张包含所有评估结果的模型卡并上传。此模型卡包含可帮助模型中心为推理演示选择小部件的元数据。通常不需要做额外的更改，因为它可以从模型类中推断出正确的小部件，但在这种情况下，相同的模型类可以用于所有类型的序列到序列问题，所以我们指定它是一个翻译模型：",Cl,z,Gl,tl,Zl="如果您想检查命令执行的结果，此命令将返回它刚刚执行的提交的 URL，可以打开url进行检查：",xl,nl,jl,ml,cl="在此阶段，您可以使用模型中心上的推理小部件来测试您的模型并与您的朋友分享。您已成功微调翻译任务的模型 - 恭喜！",Bl,al,kl="如果您想更深入地了解训练循环，我们现在将向您展示如何使用 🤗 Accelerate 做同样的事情。",Il;return f=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQWFyZ3MlMjAlM0QlMjBTZXEyU2VxVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwZiUyMm1hcmlhbi1maW5ldHVuZWQta2RlNC1lbi10by1mciUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJubyUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNEMzIlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRDY0JTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5JTNEMC4wMSUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfdG90YWxfbGltaXQlM0QzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDMlMkMlMEElMjAlMjAlMjAlMjBwcmVkaWN0X3dpdGhfZ2VuZXJhdGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZnAxNiUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBwdXNoX3RvX2h1YiUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainingArguments

args = Seq2SeqTrainingArguments(
    <span class="hljs-string">f&quot;marian-finetuned-kde4-en-to-fr&quot;</span>,
    evaluation_strategy=<span class="hljs-string">&quot;no&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    per_device_train_batch_size=<span class="hljs-number">32</span>,
    per_device_eval_batch_size=<span class="hljs-number">64</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    save_total_limit=<span class="hljs-number">3</span>,
    num_train_epochs=<span class="hljs-number">3</span>,
    predict_with_generate=<span class="hljs-literal">True</span>,
    fp16=<span class="hljs-literal">True</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),Q=new ls({props:{$$slots:{default:[Jp]},$$scope:{ctx:k}}}),A=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBdHJhaW5lciUyMCUzRCUyMFNlcTJTZXFUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    model,
    args,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    data_collator=data_collator,
    tokenizer=tokenizer,
    compute_metrics=compute_metrics,
)`,wrap:!1}}),K=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),ll=new h({props:{code:"JTdCJ2V2YWxfbG9zcyclM0ElMjAxLjY5NjQ0MDgxNTkyNTU5ODElMkMlMEElMjAnZXZhbF9ibGV1JyUzQSUyMDM5LjI2ODY1MDYxMDA3NjE2JTJDJTBBJTIwJ2V2YWxfcnVudGltZSclM0ElMjA5NjUuODg4NCUyQyUwQSUyMCdldmFsX3NhbXBsZXNfcGVyX3NlY29uZCclM0ElMjAyMS43NiUyQyUwQSUyMCdldmFsX3N0ZXBzX3Blcl9zZWNvbmQnJTNBJTIwMC4zNDElN0Q=",highlighted:`{<span class="hljs-string">&#x27;eval_loss&#x27;</span>: <span class="hljs-number">1.6964408159255981</span>,
 <span class="hljs-string">&#x27;eval_bleu&#x27;</span>: <span class="hljs-number">39.26865061007616</span>,
 <span class="hljs-string">&#x27;eval_runtime&#x27;</span>: <span class="hljs-number">965.8884</span>,
 <span class="hljs-string">&#x27;eval_samples_per_second&#x27;</span>: <span class="hljs-number">21.76</span>,
 <span class="hljs-string">&#x27;eval_steps_per_second&#x27;</span>: <span class="hljs-number">0.341</span>}`,wrap:!1}}),el=new h({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),S=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),D=new h({props:{code:"JTdCJ2V2YWxfbG9zcyclM0ElMjAwLjg1NTg1MDU3NzM1NDQzMTIlMkMlMEElMjAnZXZhbF9ibGV1JyUzQSUyMDUyLjk0MTYxMzM3Nzc1NTc2JTJDJTBBJTIwJ2V2YWxfcnVudGltZSclM0ElMjA3MTQuMjU3NiUyQyUwQSUyMCdldmFsX3NhbXBsZXNfcGVyX3NlY29uZCclM0ElMjAyOS40MjYlMkMlMEElMjAnZXZhbF9zdGVwc19wZXJfc2Vjb25kJyUzQSUyMDAuNDYxJTJDJTBBJTIwJ2Vwb2NoJyUzQSUyMDMuMCU3RA==",highlighted:`{<span class="hljs-string">&#x27;eval_loss&#x27;</span>: <span class="hljs-number">0.8558505773544312</span>,
 <span class="hljs-string">&#x27;eval_bleu&#x27;</span>: <span class="hljs-number">52.94161337775576</span>,
 <span class="hljs-string">&#x27;eval_runtime&#x27;</span>: <span class="hljs-number">714.2576</span>,
 <span class="hljs-string">&#x27;eval_samples_per_second&#x27;</span>: <span class="hljs-number">29.426</span>,
 <span class="hljs-string">&#x27;eval_steps_per_second&#x27;</span>: <span class="hljs-number">0.461</span>,
 <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-number">3.0</span>}`,wrap:!1}}),z=new h({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yih0YWdzJTNEJTIydHJhbnNsYXRpb24lMjIlMkMlMjBjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(tags=<span class="hljs-string">&quot;translation&quot;</span>, commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),nl=new h({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGbWFyaWFuLWZpbmV0dW5lZC1rZGU0LWVuLXRvLWZyJTJGY29tbWl0JTJGMzYwMWQ2MjFlM2JhYWUyYmM2M2QzMzExNDUyNTM1ZjhmNThmNmVmMyc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/marian-finetuned-kde4-en-to-fr/commit/3601d621e3baae2bc63d3311452535f8f58f6ef3&#x27;</span>',wrap:!1}}),{c(){p=J("p"),p.innerHTML=d,r=n(),T(f.$$.fragment),Z=n(),w=J("p"),w.textContent=_,G=n(),x=J("ul"),x.innerHTML=g,C=n(),W=J("p"),W.innerHTML=O,Tl=n(),T(Q.$$.fragment),Y=n(),L=J("p"),L.innerHTML=N,ol=n(),T(A.$$.fragment),F=n(),P=J("p"),P.textContent=v,gl=n(),T(K.$$.fragment),X=n(),T(ll.$$.fragment),E=n(),R=J("p"),R.textContent=Ml,sl=n(),V=J("p"),V.textContent=b,B=n(),T(el.$$.fragment),Ul=n(),yl=J("p"),yl.textContent=rl,bl=n(),H=J("p"),H.textContent=Sl,fl=n(),T(S.$$.fragment),dl=n(),T(D.$$.fragment),Fl=n(),Jl=J("p"),Jl.textContent=il,hl=n(),q=J("p"),q.innerHTML=Dl,Cl=n(),T(z.$$.fragment),Gl=n(),tl=J("p"),tl.textContent=Zl,xl=n(),T(nl.$$.fragment),jl=n(),ml=J("p"),ml.textContent=cl,Bl=n(),al=J("p"),al.textContent=kl},l(i){p=m(i,"P",{"data-svelte-h":!0}),u(p)!=="svelte-9t278v"&&(p.innerHTML=d),r=a(i),o(f.$$.fragment,i),Z=a(i),w=m(i,"P",{"data-svelte-h":!0}),u(w)!=="svelte-1inxxv"&&(w.textContent=_),G=a(i),x=m(i,"UL",{"data-svelte-h":!0}),u(x)!=="svelte-vj4u"&&(x.innerHTML=g),C=a(i),W=m(i,"P",{"data-svelte-h":!0}),u(W)!=="svelte-3pcrhk"&&(W.innerHTML=O),Tl=a(i),o(Q.$$.fragment,i),Y=a(i),L=m(i,"P",{"data-svelte-h":!0}),u(L)!=="svelte-lzs5ma"&&(L.innerHTML=N),ol=a(i),o(A.$$.fragment,i),F=a(i),P=m(i,"P",{"data-svelte-h":!0}),u(P)!=="svelte-1nklwna"&&(P.textContent=v),gl=a(i),o(K.$$.fragment,i),X=a(i),o(ll.$$.fragment,i),E=a(i),R=m(i,"P",{"data-svelte-h":!0}),u(R)!=="svelte-1h8h1za"&&(R.textContent=Ml),sl=a(i),V=m(i,"P",{"data-svelte-h":!0}),u(V)!=="svelte-mtrcqq"&&(V.textContent=b),B=a(i),o(el.$$.fragment,i),Ul=a(i),yl=m(i,"P",{"data-svelte-h":!0}),u(yl)!=="svelte-1iltohp"&&(yl.textContent=rl),bl=a(i),H=m(i,"P",{"data-svelte-h":!0}),u(H)!=="svelte-1o1cwga"&&(H.textContent=Sl),fl=a(i),o(S.$$.fragment,i),dl=a(i),o(D.$$.fragment,i),Fl=a(i),Jl=m(i,"P",{"data-svelte-h":!0}),u(Jl)!=="svelte-1h3a7pu"&&(Jl.textContent=il),hl=a(i),q=m(i,"P",{"data-svelte-h":!0}),u(q)!=="svelte-1rx99yb"&&(q.innerHTML=Dl),Cl=a(i),o(z.$$.fragment,i),Gl=a(i),tl=m(i,"P",{"data-svelte-h":!0}),u(tl)!=="svelte-i3og4x"&&(tl.textContent=Zl),xl=a(i),o(nl.$$.fragment,i),jl=a(i),ml=m(i,"P",{"data-svelte-h":!0}),u(ml)!=="svelte-1vjzzgc"&&(ml.textContent=cl),Bl=a(i),al=m(i,"P",{"data-svelte-h":!0}),u(al)!=="svelte-h7k4v7"&&(al.textContent=kl)},m(i,$){e(i,p,$),e(i,r,$),U(f,i,$),e(i,Z,$),e(i,w,$),e(i,G,$),e(i,x,$),e(i,C,$),e(i,W,$),e(i,Tl,$),U(Q,i,$),e(i,Y,$),e(i,L,$),e(i,ol,$),U(A,i,$),e(i,F,$),e(i,P,$),e(i,gl,$),U(K,i,$),e(i,X,$),U(ll,i,$),e(i,E,$),e(i,R,$),e(i,sl,$),e(i,V,$),e(i,B,$),U(el,i,$),e(i,Ul,$),e(i,yl,$),e(i,bl,$),e(i,H,$),e(i,fl,$),U(S,i,$),e(i,dl,$),U(D,i,$),e(i,Fl,$),e(i,Jl,$),e(i,hl,$),e(i,q,$),e(i,Cl,$),U(z,i,$),e(i,Gl,$),e(i,tl,$),e(i,xl,$),U(nl,i,$),e(i,jl,$),e(i,ml,$),e(i,Bl,$),e(i,al,$),Il=!0},i(i){Il||(c(f.$$.fragment,i),c(Q.$$.fragment,i),c(A.$$.fragment,i),c(K.$$.fragment,i),c(ll.$$.fragment,i),c(el.$$.fragment,i),c(S.$$.fragment,i),c(D.$$.fragment,i),c(z.$$.fragment,i),c(nl.$$.fragment,i),Il=!0)},o(i){y(f.$$.fragment,i),y(Q.$$.fragment,i),y(A.$$.fragment,i),y(K.$$.fragment,i),y(ll.$$.fragment,i),y(el.$$.fragment,i),y(S.$$.fragment,i),y(D.$$.fragment,i),y(z.$$.fragment,i),y(nl.$$.fragment,i),Il=!1},d(i){i&&(s(p),s(r),s(Z),s(w),s(G),s(x),s(C),s(W),s(Tl),s(Y),s(L),s(ol),s(F),s(P),s(gl),s(X),s(E),s(R),s(sl),s(V),s(B),s(Ul),s(yl),s(bl),s(H),s(fl),s(dl),s(Fl),s(Jl),s(hl),s(q),s(Cl),s(Gl),s(tl),s(xl),s(jl),s(ml),s(Bl),s(al)),j(f,i),j(Q,i),j(A,i),j(K,i),j(ll,i),j(el,i),j(S,i),j(D,i),j(z,i),j(nl,i)}}}function yp(k){let p,d="在我们开始之前，让我们看看我们在没有任何训练的情况下从我们的模型中得到了什么样的结果：",r,f,Z,w,_,G,x="一旦完成，我们就可以准备编译和训练模型所需的一切。 注意当使用 <code>tf.keras.mixed_precision.set_global_policy(&quot;mixed_float16&quot;)</code>时——这将告诉 Keras 使用 float16 进行训练，这可以显着提高支持它的 GPU（Nvidia 20xx/V100 或更高版本）的速度。",g,C,W,O,Tl='接下来，我们定义一个 <code>PushToHubCallback</code> 以便在训练期间将我们的模型上传到 Hub，正如我们在 <a href="(/course/chapter7/2)">第 2 节</a> 中看到的，然后我们只需拟合模型时添加该回调函数：',Q,Y,L,N,ol='请注意，您可以使用 <code>hub_model_id</code> 参数指定要推送到的存储库的名称（当您想把模型推送到指定的组织的时候，您也必须使用此参数）。 例如，当我们将模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> 组织</a> 时，我们添加了 <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en- to-fr&quot;</code> 到 <code>Seq2SeqTrainingArguments</code>。 默认情况下，使用的存储库将在您的命名空间中，并以您设置的输出目录命名，因此这里将是 <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code>。',A,F,P,v,gl="最后，让我们看看训练结束后我们的指标是什么样的：",K,X,ll,E,R,Ml,sl="在这个阶段，您可以使用模型中心上的推理小部件来测试您的模型并与您的朋友分享。 您已经成功地微调了翻译任务中的模型——恭喜！",V;return f=new h({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),w=new h({props:{code:"JTdCJ2JsZXUnJTNBJTIwMzMuMjY5ODM3MDE0NTQ3MzMlN0Q=",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">33.26983701454733</span>}',wrap:!1}}),C=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmtlcmFzX2NhbGxiYWNrcyUyMGltcG9ydCUyMFB1c2hUb0h1YkNhbGxiYWNrJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEElMjMlMjBUaGUlMjBudW1iZXIlMjBvZiUyMHRyYWluaW5nJTIwc3RlcHMlMjBpcyUyMHRoZSUyMG51bWJlciUyMG9mJTIwc2FtcGxlcyUyMGluJTIwdGhlJTIwZGF0YXNldCUyQyUyMGRpdmlkZWQlMjBieSUyMHRoZSUyMGJhdGNoJTIwc2l6ZSUyMHRoZW4lMjBtdWx0aXBsaWVkJTBBJTIzJTIwYnklMjB0aGUlMjB0b3RhbCUyMG51bWJlciUyMG9mJTIwZXBvY2hzLiUyME5vdGUlMjB0aGF0JTIwdGhlJTIwdGZfdHJhaW5fZGF0YXNldCUyMGhlcmUlMjBpcyUyMGElMjBiYXRjaGVkJTIwdGYuZGF0YS5EYXRhc2V0JTJDJTBBJTIzJTIwbm90JTIwdGhlJTIwb3JpZ2luYWwlMjBIdWdnaW5nJTIwRmFjZSUyMERhdGFzZXQlMkMlMjBzbyUyMGl0cyUyMGxlbigpJTIwaXMlMjBhbHJlYWR5JTIwbnVtX3NhbXBsZXMlMjAlMkYlMkYlMjBiYXRjaF9zaXplLiUwQW51bV9lcG9jaHMlMjAlM0QlMjAzJTBBbnVtX3RyYWluX3N0ZXBzJTIwJTNEJTIwbGVuKHRmX3RyYWluX2RhdGFzZXQpJTIwKiUyMG51bV9lcG9jaHMlMEElMEFvcHRpbWl6ZXIlMkMlMjBzY2hlZHVsZSUyMCUzRCUyMGNyZWF0ZV9vcHRpbWl6ZXIoJTBBJTIwJTIwJTIwJTIwaW5pdF9sciUzRDVlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fd2FybXVwX3N0ZXBzJTNEMCUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9zdGVwcyUzRG51bV90cmFpbl9zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheV9yYXRlJTNEMC4wMSUyQyUwQSklMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplciklMEElMEElMjMlMjBUcmFpbiUyMGluJTIwbWl4ZWQtcHJlY2lzaW9uJTIwZmxvYXQxNiUwQXRmLmtlcmFzLm1peGVkX3ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-comment"># The number of training steps is the number of samples in the dataset, divided by the batch size then multiplied</span>
<span class="hljs-comment"># by the total number of epochs. Note that the tf_train_dataset here is a batched tf.data.Dataset,</span>
<span class="hljs-comment"># not the original Hugging Face Dataset, so its len() is already num_samples // batch_size.</span>
num_epochs = <span class="hljs-number">3</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_epochs

optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">5e-5</span>,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_train_steps=num_train_steps,
    weight_decay_rate=<span class="hljs-number">0.01</span>,
)
model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)

<span class="hljs-comment"># Train in mixed-precision float16</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)`,wrap:!1}}),Y=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMm1hcmlhbi1maW5ldHVuZWQta2RlNC1lbi10by1mciUyMiUyQyUyMHRva2VuaXplciUzRHRva2VuaXplciUwQSklMEElMEFtb2RlbC5maXQoJTBBJTIwJTIwJTIwJTIwdGZfdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHZhbGlkYXRpb25fZGF0YSUzRHRmX2V2YWxfZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGNhbGxiYWNrcyUzRCU1QmNhbGxiYWNrJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXBvY2hzJTNEbnVtX2Vwb2NocyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

callback = PushToHubCallback(
    output_dir=<span class="hljs-string">&quot;marian-finetuned-kde4-en-to-fr&quot;</span>, tokenizer=tokenizer
)

model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=[callback],
    epochs=num_epochs,
)`,wrap:!1}}),F=new ls({props:{$$slots:{default:[mp]},$$scope:{ctx:k}}}),X=new h({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),E=new h({props:{code:"JTdCJ2JsZXUnJTNBJTIwNTcuMzM0MDY2MjcxNTQ1ODY1JTdE",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">57.334066271545865</span>}',wrap:!1}}),{c(){p=J("p"),p.textContent=d,r=n(),T(f.$$.fragment),Z=n(),T(w.$$.fragment),_=n(),G=J("p"),G.innerHTML=x,g=n(),T(C.$$.fragment),W=n(),O=J("p"),O.innerHTML=Tl,Q=n(),T(Y.$$.fragment),L=n(),N=J("p"),N.innerHTML=ol,A=n(),T(F.$$.fragment),P=n(),v=J("p"),v.textContent=gl,K=n(),T(X.$$.fragment),ll=n(),T(E.$$.fragment),R=n(),Ml=J("p"),Ml.textContent=sl},l(b){p=m(b,"P",{"data-svelte-h":!0}),u(p)!=="svelte-d81fnd"&&(p.textContent=d),r=a(b),o(f.$$.fragment,b),Z=a(b),o(w.$$.fragment,b),_=a(b),G=m(b,"P",{"data-svelte-h":!0}),u(G)!=="svelte-95tmq"&&(G.innerHTML=x),g=a(b),o(C.$$.fragment,b),W=a(b),O=m(b,"P",{"data-svelte-h":!0}),u(O)!=="svelte-1mkffqe"&&(O.innerHTML=Tl),Q=a(b),o(Y.$$.fragment,b),L=a(b),N=m(b,"P",{"data-svelte-h":!0}),u(N)!=="svelte-3pcrhk"&&(N.innerHTML=ol),A=a(b),o(F.$$.fragment,b),P=a(b),v=m(b,"P",{"data-svelte-h":!0}),u(v)!=="svelte-rfwpp9"&&(v.textContent=gl),K=a(b),o(X.$$.fragment,b),ll=a(b),o(E.$$.fragment,b),R=a(b),Ml=m(b,"P",{"data-svelte-h":!0}),u(Ml)!=="svelte-m9wtzw"&&(Ml.textContent=sl)},m(b,B){e(b,p,B),e(b,r,B),U(f,b,B),e(b,Z,B),U(w,b,B),e(b,_,B),e(b,G,B),e(b,g,B),U(C,b,B),e(b,W,B),e(b,O,B),e(b,Q,B),U(Y,b,B),e(b,L,B),e(b,N,B),e(b,A,B),U(F,b,B),e(b,P,B),e(b,v,B),e(b,K,B),U(X,b,B),e(b,ll,B),U(E,b,B),e(b,R,B),e(b,Ml,B),V=!0},i(b){V||(c(f.$$.fragment,b),c(w.$$.fragment,b),c(C.$$.fragment,b),c(Y.$$.fragment,b),c(F.$$.fragment,b),c(X.$$.fragment,b),c(E.$$.fragment,b),V=!0)},o(b){y(f.$$.fragment,b),y(w.$$.fragment,b),y(C.$$.fragment,b),y(Y.$$.fragment,b),y(F.$$.fragment,b),y(X.$$.fragment,b),y(E.$$.fragment,b),V=!1},d(b){b&&(s(p),s(r),s(Z),s(_),s(G),s(g),s(W),s(O),s(Q),s(L),s(N),s(A),s(P),s(v),s(K),s(ll),s(R),s(Ml)),j(f,b),j(w,b),j(C,b),j(Y,b),j(F,b),j(X,b),j(E,b)}}}function Jp(k){let p,d="💡如果您使用的输出目录已经存在，则它需要是您要推送到的存储库的本地克隆。如果不是，您将在定义您的名称时会遇到错误，并且需要设置一个新名称。";return{c(){p=J("p"),p.textContent=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-4wkymf"&&(p.textContent=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function mp(k){let p,d="💡如果您使用的输出目录已经存在，则它需要是您要推送到的存储库的本地克隆。如果不是，您将在定义您的名称时会遇到错误，并且需要设置一个新名称。";return{c(){p=J("p"),p.textContent=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-4wkymf"&&(p.textContent=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function va(k){let p,d,r,f='现在让我们看一下完整的训练循环，以便您可以轻松自定义所需的部分。它看起来很像我们在<a href="/course/chapter7/2">本章第二节</a>和<a href="/course/chapter3/4">第三章第四小节</a>所做的。',Z,w,_,G,x="您已经多次看到所有这些，因此这一块会简略进行。首先我们将构建我们的数据集的<strong>DataLoader</strong> ，在将数据集设置为 <strong>torch</strong> 格式，我们就得到了 PyTorch 张量：",g,C,W,O,Tl="接下来我们重新实例化我们的模型，以确保我们不会继续上一节的微调，而是再次从预训练模型开始重新训练：",Q,Y,L,N,ol="然后我们需要一个优化器：",A,F,P,v,gl="一旦我们拥有所有这些对象，我们就可以将它们发送到 <code>accelerator.prepare()</code> 方法。 请记住，如果您想在 Colab 笔记本训练中使用TPU，则需要将所有这些代码移动到训练函数中，并且不应执行任何实例化“加速器”的对象。",K,X,ll,E,R="现在我们已经发送了我们的 <strong>train_dataloader</strong> 到 <strong>accelerator.prepare()</strong> ，我们可以使用它的长度来计算训练步骤的数量。请记住，我们应该始终在准备好数据加载器后执行此操作，因为该方法会更改 <strong>DataLoader</strong> .我们使用从学习率衰减到 0 的经典线性学习率调度：",Ml,sl,V,b,B="最后，要将我们的模型推送到 Hub，我们需要创建一个 <strong>Repository</strong> 工作文件夹中的对象。如果您尚未登录，请先登录 Hugging Face。我们将从我们想要为模型提供的模型 ID 中确定存储库名称（您可以自由地用自己的选择替换 <strong>repo_name</strong> ；它需要包含您的用户名，可以使用<strong>get_full_repo_name()</strong>函数的查看目前的repo_name）：",el,Ul,yl,rl,bl,H,Sl="然后我们可以在本地文件夹中克隆该存储库。如果它已经存在，这个本地文件夹应该是我们正在使用的存储库的克隆：",fl,S,dl,D,Fl="我们现在可以通过调用 <strong>repo.push_to_hub()</strong> 方法上传我们保存的任何内容 <strong>output_dir</strong> 。这将帮助我们在每个 epoch 结束时上传过程中的模型。",Jl,il,hl,q,Dl="我们现在准备编写完整的训练循环。为了简化它的评估部分，我们定义了这个 <strong>postprocess()</strong> 函数接收预测结果和正确标签并将它们转换为我们 <strong>metric</strong> 对象所需要的字符串列表：",Cl,z,Gl,tl,Zl='训练循环看起来和<a href="/course/chapter7/2">本章第二节</a>与<a href="/course/chapter3">第三章</a>很像，在评估部分有一些不同 - 所以让我们专注于这一点！',xl,nl,jl="首先要注意的是我们使用 <code>generate()</code> 方法来计算预测，但这是我们基础模型上的一个方法，而不是包装模型🤗 Accelerate 在 <code>prepare()</code> 方法中创建。 这就是为什么我们先解包模型，然后调用这个方法。",ml,cl,Bl='第二件事是，就像<a href="/course/chapter7/2">token 分类</a>，两个进程可能将输入和标签填充为不同的形状，因此我们在调用 <strong>gather()</strong> 方法之前使用 <strong>accelerator.pad_across_processes()</strong> 使预测和标签具有相同的形状。如果我们不这样做，评估要么出错，要么永远在阻塞。',al,kl,Il,i,$,ul,ss='完成此操作后，您应该有一个模型，其结果与使用 <code>Seq2SeqTrainer</code> 训练的模型非常相似。 您可以在 [<em>huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate</em>](<a href="https://huggingface.co/huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate%EF%BC%89%E6%9F%A5%E7%9C%8B%E8%AE%AD%E7%BB%83%E5%AE%8C%E7%9A%84%E7%BB%93%E6%9E%9C%E3%80%82" rel="nofollow">https://huggingface.co/huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate）查看训练完的结果。</a> 如果您想测试对训练循环的任何调整，您可以通过编辑上面显示的代码直接实现它们！',Wl;return p=new _l({props:{title:"自定义训练循环",local:"自定义训练循环",headingTag:"h2"}}),w=new _l({props:{title:"准备训练所需的一切",local:"准备训练所需的一切",headingTag:"h3"}}),C=new h({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBdG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIpJTBBdHJhaW5fZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMjBiYXRjaF9zaXplJTNEOCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
train_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)
eval_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], collate_fn=data_collator, batch_size=<span class="hljs-number">8</span>
)`,wrap:!1}}),Y=new h({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),F=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEFkYW1XJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhbVcobW9kZWwucGFyYW1ldGVycygpJTJDJTIwbHIlM0QyZS01KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),X=new h({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQSUwQWFjY2VsZXJhdG9yJTIwJTNEJTIwQWNjZWxlcmF0b3IoKSUwQW1vZGVsJTJDJTIwb3B0aW1pemVyJTJDJTIwdHJhaW5fZGF0YWxvYWRlciUyQyUyMGV2YWxfZGF0YWxvYWRlciUyMCUzRCUyMGFjY2VsZXJhdG9yLnByZXBhcmUoJTBBJTIwJTIwJTIwJTIwbW9kZWwlMkMlMjBvcHRpbWl6ZXIlMkMlMjB0cmFpbl9kYXRhbG9hZGVyJTJDJTIwZXZhbF9kYXRhbG9hZGVyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`,wrap:!1}}),sl=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fdHJhaW5fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV91cGRhdGVfc3RlcHNfcGVyX2Vwb2NoJTIwJTNEJTIwbGVuKHRyYWluX2RhdGFsb2FkZXIpJTBBbnVtX3RyYWluaW5nX3N0ZXBzJTIwJTNEJTIwbnVtX3RyYWluX2Vwb2NocyUyMColMjBudW1fdXBkYXRlX3N0ZXBzX3Blcl9lcG9jaCUwQSUwQWxyX3NjaGVkdWxlciUyMCUzRCUyMGdldF9zY2hlZHVsZXIoJTBBJTIwJTIwJTIwJTIwJTIybGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwb3B0aW1pemVyJTNEb3B0aW1pemVyJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5pbmdfc3RlcHMlM0RudW1fdHJhaW5pbmdfc3RlcHMlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

num_train_epochs = <span class="hljs-number">3</span>
num_update_steps_per_epoch = <span class="hljs-built_in">len</span>(train_dataloader)
num_training_steps = num_train_epochs * num_update_steps_per_epoch

lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)`,wrap:!1}}),Ul=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMFJlcG9zaXRvcnklMkMlMjBnZXRfZnVsbF9yZXBvX25hbWUlMEElMEFtb2RlbF9uYW1lJTIwJTNEJTIwJTIybWFyaWFuLWZpbmV0dW5lZC1rZGU0LWVuLXRvLWZyLWFjY2VsZXJhdGUlMjIlMEFyZXBvX25hbWUlMjAlM0QlMjBnZXRfZnVsbF9yZXBvX25hbWUobW9kZWxfbmFtZSklMEFyZXBvX25hbWU=",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository, get_full_repo_name

model_name = <span class="hljs-string">&quot;marian-finetuned-kde4-en-to-fr-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),rl=new h({props:{code:"J3NndWdnZXIlMkZtYXJpYW4tZmluZXR1bmVkLWtkZTQtZW4tdG8tZnItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/marian-finetuned-kde4-en-to-fr-accelerate&#x27;</span>',wrap:!1}}),S=new h({props:{code:"b3V0cHV0X2RpciUyMCUzRCUyMCUyMm1hcmlhbi1maW5ldHVuZWQta2RlNC1lbi10by1mci1hY2NlbGVyYXRlJTIyJTBBcmVwbyUyMCUzRCUyMFJlcG9zaXRvcnkob3V0cHV0X2RpciUyQyUyMGNsb25lX2Zyb20lM0RyZXBvX25hbWUp",highlighted:`output_dir = <span class="hljs-string">&quot;marian-finetuned-kde4-en-to-fr-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`,wrap:!1}}),il=new _l({props:{title:"训练循环",local:"训练循环",headingTag:"h3"}}),z=new h({props:{code:"ZGVmJTIwcG9zdHByb2Nlc3MocHJlZGljdGlvbnMlMkMlMjBsYWJlbHMpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlMjAlM0QlMjBwcmVkaWN0aW9ucy5jcHUoKS5udW1weSgpJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwbGFiZWxzLmNwdSgpLm51bXB5KCklMEElMEElMjAlMjAlMjAlMjBkZWNvZGVkX3ByZWRzJTIwJTNEJTIwdG9rZW5pemVyLmJhdGNoX2RlY29kZShwcmVkaWN0aW9ucyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFJlcGxhY2UlMjAtMTAwJTIwaW4lMjB0aGUlMjBsYWJlbHMlMjBhcyUyMHdlJTIwY2FuJ3QlMjBkZWNvZGUlMjB0aGVtLiUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUobGFiZWxzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwU29tZSUyMHNpbXBsZSUyMHBvc3QtcHJvY2Vzc2luZyUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjAlNUJwcmVkLnN0cmlwKCklMjBmb3IlMjBwcmVkJTIwaW4lMjBkZWNvZGVkX3ByZWRzJTVEJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9sYWJlbHMlMjAlM0QlMjAlNUIlNUJsYWJlbC5zdHJpcCgpJTVEJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxz",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">postprocess</span>(<span class="hljs-params">predictions, labels</span>):
    predictions = predictions.cpu().numpy()
    labels = labels.cpu().numpy()

    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># Replace -100 in the labels as we can&#x27;t decode them.</span>
    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># Some simple post-processing</span>
    decoded_preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
    decoded_labels = [[label.strip()] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]
    <span class="hljs-keyword">return</span> decoded_preds, decoded_labels`,wrap:!1}}),kl=new h({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHJhaW5fZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvc3MlMjAlM0QlMjBvdXRwdXRzLmxvc3MlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhY2NlbGVyYXRvci5iYWNrd2FyZChsb3NzKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9wdGltaXplci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBscl9zY2hlZHVsZXIuc3RlcCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnplcm9fZ3JhZCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvZ3Jlc3NfYmFyLnVwZGF0ZSgxKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEV2YWx1YXRpb24lMEElMjAlMjAlMjAlMjBtb2RlbC5ldmFsKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHFkbShldmFsX2RhdGFsb2FkZXIpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdlbmVyYXRlZF90b2tlbnMlMjAlM0QlMjBhY2NlbGVyYXRvci51bndyYXBfbW9kZWwobW9kZWwpLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGJhdGNoJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXR0ZW50aW9uX21hc2slM0RiYXRjaCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDEyOCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBiYXRjaCU1QiUyMmxhYmVscyUyMiU1RCUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyME5lY2Vzc2FyeSUyMHRvJTIwcGFkJTIwcHJlZGljdGlvbnMlMjBhbmQlMjBsYWJlbHMlMjBmb3IlMjBiZWluZyUyMGdhdGhlcmVkJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ2VuZXJhdGVkX3Rva2VucyUyMCUzRCUyMGFjY2VsZXJhdG9yLnBhZF9hY3Jvc3NfcHJvY2Vzc2VzKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdlbmVyYXRlZF90b2tlbnMlMkMlMjBkaW0lM0QxJTJDJTIwcGFkX2luZGV4JTNEdG9rZW5pemVyLnBhZF90b2tlbl9pZCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBhY2NlbGVyYXRvci5wYWRfYWNyb3NzX3Byb2Nlc3NlcyhsYWJlbHMlMkMlMjBkaW0lM0QxJTJDJTIwcGFkX2luZGV4JTNELTEwMCklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9uc19nYXRoZXJlZCUyMCUzRCUyMGFjY2VsZXJhdG9yLmdhdGhlcihnZW5lcmF0ZWRfdG9rZW5zKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVsc19nYXRoZXJlZCUyMCUzRCUyMGFjY2VsZXJhdG9yLmdhdGhlcihsYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwcG9zdHByb2Nlc3MocHJlZGljdGlvbnNfZ2F0aGVyZWQlMkMlMjBsYWJlbHNfZ2F0aGVyZWQpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWV0cmljLmFkZF9iYXRjaChwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0cyUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKCklMEElMjAlMjAlMjAlMjBwcmludChmJTIyZXBvY2glMjAlN0JlcG9jaCU3RCUyQyUyMEJMRVUlMjBzY29yZSUzQSUyMCU3QnJlc3VsdHMlNUInc2NvcmUnJTVEJTNBLjJmJTdEJTIyKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFNhdmUlMjBhbmQlMjB1cGxvYWQlMEElMjAlMjAlMjAlMjBhY2NlbGVyYXRvci53YWl0X2Zvcl9ldmVyeW9uZSgpJTBBJTIwJTIwJTIwJTIwdW53cmFwcGVkX21vZGVsJTIwJTNEJTIwYWNjZWxlcmF0b3IudW53cmFwX21vZGVsKG1vZGVsKSUwQSUyMCUyMCUyMCUyMHVud3JhcHBlZF9tb2RlbC5zYXZlX3ByZXRyYWluZWQob3V0cHV0X2RpciUyQyUyMHNhdmVfZnVuY3Rpb24lM0RhY2NlbGVyYXRvci5zYXZlKSUwQSUyMCUyMCUyMCUyMGlmJTIwYWNjZWxlcmF0b3IuaXNfbWFpbl9wcm9jZXNzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdG9rZW5pemVyLnNhdmVfcHJldHJhaW5lZChvdXRwdXRfZGlyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJlcG8ucHVzaF90b19odWIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29tbWl0X21lc3NhZ2UlM0RmJTIyVHJhaW5pbmclMjBpbiUyMHByb2dyZXNzJTIwZXBvY2glMjAlN0JlcG9jaCU3RCUyMiUyQyUyMGJsb2NraW5nJTNERmFsc2UlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAp",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_train_epochs):
    <span class="hljs-comment"># Training</span>
    model.train()
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
        outputs = model(**batch)
        loss = outputs.loss
        accelerator.backward(loss)

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)

    <span class="hljs-comment"># Evaluation</span>
    model.<span class="hljs-built_in">eval</span>()
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> tqdm(eval_dataloader):
        <span class="hljs-keyword">with</span> torch.no_grad():
            generated_tokens = accelerator.unwrap_model(model).generate(
                batch[<span class="hljs-string">&quot;input_ids&quot;</span>],
                attention_mask=batch[<span class="hljs-string">&quot;attention_mask&quot;</span>],
                max_length=<span class="hljs-number">128</span>,
            )
        labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]

        <span class="hljs-comment"># Necessary to pad predictions and labels for being gathered</span>
        generated_tokens = accelerator.pad_across_processes(
            generated_tokens, dim=<span class="hljs-number">1</span>, pad_index=tokenizer.pad_token_id
        )
        labels = accelerator.pad_across_processes(labels, dim=<span class="hljs-number">1</span>, pad_index=-<span class="hljs-number">100</span>)

        predictions_gathered = accelerator.gather(generated_tokens)
        labels_gathered = accelerator.gather(labels)

        decoded_preds, decoded_labels = postprocess(predictions_gathered, labels_gathered)
        metric.add_batch(predictions=decoded_preds, references=decoded_labels)

    results = metric.compute()
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;epoch <span class="hljs-subst">{epoch}</span>, BLEU score: <span class="hljs-subst">{results[<span class="hljs-string">&#x27;score&#x27;</span>]:<span class="hljs-number">.2</span>f}</span>&quot;</span>)

    <span class="hljs-comment"># Save and upload</span>
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    <span class="hljs-keyword">if</span> accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=<span class="hljs-string">f&quot;Training in progress epoch <span class="hljs-subst">{epoch}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
        )`,wrap:!1}}),i=new h({props:{code:"ZXBvY2glMjAwJTJDJTIwQkxFVSUyMHNjb3JlJTNBJTIwNTMuNDclMEFlcG9jaCUyMDElMkMlMjBCTEVVJTIwc2NvcmUlM0ElMjA1NC4yNCUwQWVwb2NoJTIwMiUyQyUyMEJMRVUlMjBzY29yZSUzQSUyMDU0LjQ0",highlighted:`epoch <span class="hljs-number">0</span>, BLEU score: <span class="hljs-number">53.47</span>
epoch <span class="hljs-number">1</span>, BLEU score: <span class="hljs-number">54.24</span>
epoch <span class="hljs-number">2</span>, BLEU score: <span class="hljs-number">54.44</span>`,wrap:!1}}),{c(){T(p.$$.fragment),d=n(),r=J("p"),r.innerHTML=f,Z=n(),T(w.$$.fragment),_=n(),G=J("p"),G.innerHTML=x,g=n(),T(C.$$.fragment),W=n(),O=J("p"),O.textContent=Tl,Q=n(),T(Y.$$.fragment),L=n(),N=J("p"),N.textContent=ol,A=n(),T(F.$$.fragment),P=n(),v=J("p"),v.innerHTML=gl,K=n(),T(X.$$.fragment),ll=n(),E=J("p"),E.innerHTML=R,Ml=n(),T(sl.$$.fragment),V=n(),b=J("p"),b.innerHTML=B,el=n(),T(Ul.$$.fragment),yl=n(),T(rl.$$.fragment),bl=n(),H=J("p"),H.textContent=Sl,fl=n(),T(S.$$.fragment),dl=n(),D=J("p"),D.innerHTML=Fl,Jl=n(),T(il.$$.fragment),hl=n(),q=J("p"),q.innerHTML=Dl,Cl=n(),T(z.$$.fragment),Gl=n(),tl=J("p"),tl.innerHTML=Zl,xl=n(),nl=J("p"),nl.innerHTML=jl,ml=n(),cl=J("p"),cl.innerHTML=Bl,al=n(),T(kl.$$.fragment),Il=n(),T(i.$$.fragment),$=n(),ul=J("p"),ul.innerHTML=ss},l(M){o(p.$$.fragment,M),d=a(M),r=m(M,"P",{"data-svelte-h":!0}),u(r)!=="svelte-1tji5xy"&&(r.innerHTML=f),Z=a(M),o(w.$$.fragment,M),_=a(M),G=m(M,"P",{"data-svelte-h":!0}),u(G)!=="svelte-1v78nur"&&(G.innerHTML=x),g=a(M),o(C.$$.fragment,M),W=a(M),O=m(M,"P",{"data-svelte-h":!0}),u(O)!=="svelte-3cw9vf"&&(O.textContent=Tl),Q=a(M),o(Y.$$.fragment,M),L=a(M),N=m(M,"P",{"data-svelte-h":!0}),u(N)!=="svelte-boavug"&&(N.textContent=ol),A=a(M),o(F.$$.fragment,M),P=a(M),v=m(M,"P",{"data-svelte-h":!0}),u(v)!=="svelte-95g1r5"&&(v.innerHTML=gl),K=a(M),o(X.$$.fragment,M),ll=a(M),E=m(M,"P",{"data-svelte-h":!0}),u(E)!=="svelte-11dhpm8"&&(E.innerHTML=R),Ml=a(M),o(sl.$$.fragment,M),V=a(M),b=m(M,"P",{"data-svelte-h":!0}),u(b)!=="svelte-1kqae38"&&(b.innerHTML=B),el=a(M),o(Ul.$$.fragment,M),yl=a(M),o(rl.$$.fragment,M),bl=a(M),H=m(M,"P",{"data-svelte-h":!0}),u(H)!=="svelte-tsfefx"&&(H.textContent=Sl),fl=a(M),o(S.$$.fragment,M),dl=a(M),D=m(M,"P",{"data-svelte-h":!0}),u(D)!=="svelte-19z8tc9"&&(D.innerHTML=Fl),Jl=a(M),o(il.$$.fragment,M),hl=a(M),q=m(M,"P",{"data-svelte-h":!0}),u(q)!=="svelte-2qi9pd"&&(q.innerHTML=Dl),Cl=a(M),o(z.$$.fragment,M),Gl=a(M),tl=m(M,"P",{"data-svelte-h":!0}),u(tl)!=="svelte-v6gn5i"&&(tl.innerHTML=Zl),xl=a(M),nl=m(M,"P",{"data-svelte-h":!0}),u(nl)!=="svelte-66feps"&&(nl.innerHTML=jl),ml=a(M),cl=m(M,"P",{"data-svelte-h":!0}),u(cl)!=="svelte-1gquo9k"&&(cl.innerHTML=Bl),al=a(M),o(kl.$$.fragment,M),Il=a(M),o(i.$$.fragment,M),$=a(M),ul=m(M,"P",{"data-svelte-h":!0}),u(ul)!=="svelte-cj9vya"&&(ul.innerHTML=ss)},m(M,I){U(p,M,I),e(M,d,I),e(M,r,I),e(M,Z,I),U(w,M,I),e(M,_,I),e(M,G,I),e(M,g,I),U(C,M,I),e(M,W,I),e(M,O,I),e(M,Q,I),U(Y,M,I),e(M,L,I),e(M,N,I),e(M,A,I),U(F,M,I),e(M,P,I),e(M,v,I),e(M,K,I),U(X,M,I),e(M,ll,I),e(M,E,I),e(M,Ml,I),U(sl,M,I),e(M,V,I),e(M,b,I),e(M,el,I),U(Ul,M,I),e(M,yl,I),U(rl,M,I),e(M,bl,I),e(M,H,I),e(M,fl,I),U(S,M,I),e(M,dl,I),e(M,D,I),e(M,Jl,I),U(il,M,I),e(M,hl,I),e(M,q,I),e(M,Cl,I),U(z,M,I),e(M,Gl,I),e(M,tl,I),e(M,xl,I),e(M,nl,I),e(M,ml,I),e(M,cl,I),e(M,al,I),U(kl,M,I),e(M,Il,I),U(i,M,I),e(M,$,I),e(M,ul,I),Wl=!0},i(M){Wl||(c(p.$$.fragment,M),c(w.$$.fragment,M),c(C.$$.fragment,M),c(Y.$$.fragment,M),c(F.$$.fragment,M),c(X.$$.fragment,M),c(sl.$$.fragment,M),c(Ul.$$.fragment,M),c(rl.$$.fragment,M),c(S.$$.fragment,M),c(il.$$.fragment,M),c(z.$$.fragment,M),c(kl.$$.fragment,M),c(i.$$.fragment,M),Wl=!0)},o(M){y(p.$$.fragment,M),y(w.$$.fragment,M),y(C.$$.fragment,M),y(Y.$$.fragment,M),y(F.$$.fragment,M),y(X.$$.fragment,M),y(sl.$$.fragment,M),y(Ul.$$.fragment,M),y(rl.$$.fragment,M),y(S.$$.fragment,M),y(il.$$.fragment,M),y(z.$$.fragment,M),y(kl.$$.fragment,M),y(i.$$.fragment,M),Wl=!1},d(M){M&&(s(d),s(r),s(Z),s(_),s(G),s(g),s(W),s(O),s(Q),s(L),s(N),s(A),s(P),s(v),s(K),s(ll),s(E),s(Ml),s(V),s(b),s(el),s(yl),s(bl),s(H),s(fl),s(dl),s(D),s(Jl),s(hl),s(q),s(Cl),s(Gl),s(tl),s(xl),s(nl),s(ml),s(cl),s(al),s(Il),s($),s(ul)),j(p,M),j(w,M),j(C,M),j(Y,M),j(F,M),j(X,M),j(sl,M),j(Ul,M),j(rl,M),j(S,M),j(il,M),j(z,M),j(kl,M),j(i,M)}}}function Tp(k){let p,d="✏️ <strong>轮到你了！</strong> “电子邮件”这个词在模型返回了什么？";return{c(){p=J("p"),p.innerHTML=d},l(r){p=m(r,"P",{"data-svelte-h":!0}),u(p)!=="svelte-1fwmahd"&&(p.innerHTML=d)},m(r,f){e(r,p,f)},p:Hl,d(r){r&&s(p)}}}function op(k){let p,d,r,f,Z,w,_,G,x,g,C,W,O='现在让我们深入研究翻译。这是另一个<a href="/course/chapter1/7">sequence-to-sequence 任务</a>，这意味着这是一个可以表述为从一个序列到另一个序列的问题。从这个意义上说，这个问题非常类似<a href="/course/chapter7/6">文本摘要</a>，并且您可以将我们将在此处学习到的一些内容迁移到其他的序列到序列问题，例如：',Tl,Q,Y="<li><strong>风格迁移</strong> : 创建一个模型将某种风格迁移到一段文本（例如，正式的风格迁移到休闲的风格或莎士比亚英语到现代英语）</li> <li><strong>生成问题的回答</strong> ：创建一个模型，在给定上下文的情况下生成问题的答案</li>",L,N,ol,A,F='如果您有足够大的两种（或更多）语言的文本语料库，您可以从头开始训练一个新的翻译模型，就像我们在<a href="/course/chapter7/6">因果语言建模</a>部分中所做的那样。然而，微调现有的翻译模型会更快，无论是从像 mT5 或 mBART 这样的多语言模型微调到特定的语言对，或者是专门用于从一种语言翻译成另一种语言的模型。',P,v,gl='在本节中，我们将对<a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 数据集</a>上的Marian模型进行微调，该模型经过了从英语到法语的翻译预训练(因为很多“ Hugging Face”的员工会说这两种语言)，它是<a href="https://apps.kde.org/" rel="nofollow">KDE应用程序</a>本地化文件的数据集。我们将使用的模型已经在从<a href="https://opus.nlpl.eu/" rel="nofollow">Opus 数据集</a>(实际上包含KDE4数据集)中提取的法语和英语文本的大型语料库上进行了预先训练。但是，即使我们使用的预训练模型在其预训练期间使用了这部分数据集，我们也会看到，经过微调后，我们可以得到一个更好的版本。',K,X,ll="完成后，我们将拥有一个模型，可以进行这样的翻译：",E,R,Ml,sl,V,b='<img class="block dark:hidden lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/modeleval-marian-finetuned-kde4-en-to-fr.png" alt="One-hot encoded labels for question answering."/> <img class="hidden dark:block lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/modeleval-marian-finetuned-kde4-en-to-fr-dark.png" alt="One-hot encoded labels for question answering."/>',B,el,Ul='与前面的部分一样，您可以使用以下代码找到我们将训练并上传到 Hub 的实际模型，并<a href="https://huggingface.co/huggingface-course/marian-finetuned-kde4-en-to-fr?text=This+plugin+allows+you+to+automatically+translate+web+pages+between+several+languages." rel="nofollow">在这里</a>查看模型输出的结果',yl,rl,bl,H,Sl='为了从头开始微调或训练翻译模型，我们需要一个适合该任务的数据集。如前所述，我们将使用<a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 数据集</a>在本节中，但您可以很容易地调整代码以使用您自己的数据，只要您有要互译的两种语言的句子对。如果您需要复习如何将自定义数据加载到 <strong>Dataset</strong> 可以复习一下<a href="/course/chapter5">第五章</a>.',fl,S,dl,D,Fl="像往常一样，我们使用 <strong>load_dataset()</strong> 函数：",Jl,il,hl,q,Dl='如果您想使用不同的语言对，您可以使用它们的代码来指定它们。该数据集共有 92 种语言可用；您可以通过<a href="https://huggingface.co/datasets/kde4" rel="nofollow">数据集卡片</a>展开其上的语言标签来查看它们.',Cl,z,Gl,tl,Zl,xl="我们来看看数据集：",nl,jl,ml,cl,Bl,al,kl='我们有 210,173 对句子，但在一次训练过程中，我们需要创建自己的验证集。正如我们在<a href="/course/chapter5">第五章</a>学的的那样, <strong>Dataset</strong> 有一个 <strong>train_test_split()</strong> 方法,可以帮我们拆分数据集。我们将设定固定的随机数种子：',Il,i,$,ul,ss,Wl,M="我们可以将 <strong>test</strong> 的键重命名为 <strong>validation</strong> 像这样：",I,es,Se,ts,Vn="现在让我们看一下数据集的一个元素：",De,ns,qe,as,Le,ps,Nn="我们得到一个字典，其中包含我们请求的两种语言的两个句子。这个充满技术计算机科学术语的数据集的一个特殊之处在于它们都完全用法语翻译。然而，法国工程师通常很懒惰，在交谈时，大多数计算机科学专用词汇都用英语表述。例如，“threads”这个词很可能出现在法语句子中，尤其是在技术对话中；但在这个数据集中，它被翻译成更正确的“fils de Discussion”。我们使用的预训练模型已经在一个更大的法语和英语句子语料库上进行了预训练，采用了更简单的选择，即保留单词的原样:",Pe,Ms,Ke,rs,Oe,is,vn=`这种情况的另一个例子是“plugin”这个词，它不是正式的法语词，但大多数母语人士都能理解，也不会费心去翻译。
在 KDE4 数据集中，这个词在法语中被翻译成更正式的“module d’extension”：`,lt,cs,st,ys,et,Js,Qn="然而，我们的预训练模型坚持使用简练而熟悉的英文单词：",tt,ms,nt,Ts,at,os,An="看看我们的微调模型是否能识别数据集的这些特殊性。（剧透警告：它会）。",pt,Us,Mt,ql,rt,js,it,us,ct,ws,En='您现在应该知道我们的下一步该做些什么了：所有文本都需要转换为token ID，以便模型能够理解它们。对于这个任务，我们需要同时标记输入和目标。我们的首要任务是创建我们的 <strong>tokenizer</strong> 对象。如前所述，我们将使用 Marian 英语到法语的预训练模型。如果您使用另一对语言尝试此代码，请确保调整模型Checkpoint。<a href="https://huggingface.co/Helsinki-NLP" rel="nofollow">Helsinki-NLP</a>组织提供了多种语言的一千多种模型。',yt,bs,Jt,fs,zn='您可以将 <strong>model_checkpoint</strong> 更换为<a href="https://huggingface.co/models" rel="nofollow">Hub</a>上你喜欢的任何其他型号，或本地保存的预训练模型和标记器。',mt,Ll,Tt,ds,Yn="我们的数据准备非常简单。 只有一件事要记住； 您需要确保分词器以输出语言（此处为法语）处理目标。 您可以通过将目标传递给分词器的 <strong>call</strong> 方法的 text_targets 参数来完成此操作。",ot,hs,Fn="为了了解这是如何工作的，让我们处理训练集中每种语言的一个样本：",Ut,Cs,jt,Is,ut,$s,Hn="正如我们所见，输出包含与英语句子关联的输入 ID，而与法语句子关联的 ID 存储在“labels”字段中。 如果您忘记表明您正在对标签进行分词，它们将由输入分词器进行分词，这在 Marian 模型的情况下根本不会顺利进行：",wt,gs,bt,Zs,ft,ks,Sn="正如我们所看到的，使用英语标记器来预处理法语句子会产生更多的标记，因为标记器不知道任何法语单词(除了那些也出现在英语语言中的单词，比如“discussion”)。",dt,_s,Dn="由于“inputs”是一个包含我们常用键（输入 ID、注意掩码等）的字典，最后一步是定义我们将应用于数据集的预处理函数：",ht,Gs,Ct,xs,qn="请注意，我们为输入和输出设置了相同的最大长度。由于我们处理的文本看起来很短，我们使用 128。",It,Pl,$t,Kl,gt,Bs,Ln="我们现在可以对数据集的所有数据一次性应用该预处理：",Zt,Ws,kt,Rs,Pn="现在数据已经过预处理，我们准备好微调我们的预训练模型！",_t,Rl,Xl,ve,Xs,Kn="请注意，这次我们使用的是在翻译任务上训练过的模型，并且实际上已经可以使用，因此没有关于丢失权重或新初始化权重的警告。",Gt,Vs,xt,Ns,On='我们需要一个数据整理器来处理动态批处理的填充。在本例中，我们不能像<a href="/course/chapter3">第3章</a>那样使用带填充的<strong>DataCollatorWithPadding</strong>，因为它只填充输入（输入ID、注意掩码和令牌类型ID）。我们的标签也应该填充到标签中遇到的最大长度。而且，如前所述，用于填充标签的填充值应为-100，而不是标记器的填充标记，以确保在损失计算中忽略这些填充值。',Bt,vs,la='这一切都可以由 <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorforseq2seq" rel="nofollow"><code>DataCollatorForSeq2Seq</code></a> 完成。 与 <code>DataCollatorWithPadding</code> 一样，它采用用于预处理输入的<code>tokenizer</code>，但它也采用<code>model</code>。 这是因为数据整理器还将负责准备解码器输入 ID，它们是标签偏移之后形成的，开头带有特殊标记。 由于不同架构的这种转变略有不同，因此“DataCollatorForSeq2Seq”需要知道“模型”对象：',Wt,Vl,Nl,Qe,Qs,sa="为了在几个样本上进行测试，我们只需在我们标记化训练集中的部分数据上调用它：",Rt,As,Xt,Es,Vt,zs,ea="我们可以检查我们的标签是否已使用 <strong>-100</strong> 填充到批次的最大长度：",Nt,Ys,vt,Fs,Qt,Hs,ta="我们还可以查看解码器输入 ID，看看它们是标签的偏移形成的版本：",At,Ss,Et,Ds,zt,qs,na="以下是我们数据集中第一个和第二个元素的标签：",Yt,Ls,Ft,Ps,Ht,vl,Ql,Ae,Ks,St,Os,Dt,Ee,le,aa='用于翻译的传统指标是<a href="https://en.wikipedia.org/wiki/BLEU" rel="nofollow">BLEU 分数</a>, 由Kishore Papineni等人在<a href="https://aclanthology.org/P02-1040.pdf" rel="nofollow">2002年的一篇文章</a>中引入。BLEU 分数评估翻译与其标签的接近程度。它不衡量模型生成输出的可懂度或语法正确性，而是使用统计规则来确保生成输出中的所有单词也出现在目标中。此外，如果相同单词在目标中没有重复，则有规则惩罚相同单词的重复（以避免模型输出类似 <strong>the the the the the</strong>的句子 ) 并输出比目标中短的句子（以避免模型输出像 <strong>the</strong> 这样的句子）。',qt,se,pa='BLEU 的一个缺点是它需要文本已经被分词，这使得比较使用不同标记器的模型之间的分数变得困难。因此，当今用于基准翻译模型的最常用指标是<a href="https://github.com/mjpost/sacrebleu" rel="nofollow">SacreBLEU</a>，它通过标准化标记化步骤解决了这个缺点（和其他的一些缺点）。要使用此指标，我们首先需要安装 SacreBLEU 库：',Lt,ee,Pt,te,Ma='然后我们可以就像我们在<a href="/course/chapter3">第三章</a>那样通过 <strong>evaluate.load()</strong> 加载它 ：',Kt,ne,Ot,ae,ra="该指标将文本作为输入和目标结果。它旨在接受多个可接受的目标，因为同一个句子通常有多个可接受的翻译——我们使用的数据集只提供一个，但在 NLP 中找到将多个句子作为标签的数据集不是一个难题。因此，预测结果应该是一个句子列表，而参考应该是一个句子列表的列表。",ln,pe,ia="让我们尝试一个例子：",sn,Me,en,re,tn,ie,ca='这得到了 46.75 的 BLEU 分数，这是相当不错的——作为参考，原始 Transformer 模型在<a href="https://arxiv.org/pdf/1706.03762.pdf" rel="nofollow">“Attention Is All You Need” 论文</a>类似的英语和法语翻译任务中获得了 41.8 的 BLEU 分数！ （有关各个指标的更多信息，例如 <strong>counts</strong> 和 <strong>bp</strong> ，见<a href="https://github.com/mjpost/sacrebleu/blob/078c440168c6adc89ba75fe6d63f0d922d42bcfe/sacrebleu/metrics/bleu.py#L74" rel="nofollow">SacreBLEU 仓库</a>.) 另一方面，如果我们尝试使用翻译模型中经常出现的两种糟糕的预测类型（大量重复或太短），我们将得到相当糟糕的 BLEU 分数：',nn,ce,an,ye,pn,Je,Mn,me,rn,Te,ya="分数可以从 0 到 100，越高越好。",cn,Al,El,ze,oe,Ja="现在这已经完成了，我们已经准备好微调我们的模型了！",yn,Ue,Jn,je,ma="第一步是登录 Hugging Face，这样您就可以将结果上传到模型中心。有一个方便的功能可以帮助您在notebook中完成此操作：",mn,ue,Tn,we,Ta="这将显示一个小部件，您可以在其中输入您的 Hugging Face 登录凭据。",on,be,oa="如果您不是在notebook上运行代码，只需在终端中输入以下行：",Un,fe,jn,zl,Yl,Ye,Fe,de,un,he,Ua="我们已经向您展示了如何将我们在模型中心微调的模型与推理小部件一起使用。 要在“管道”中本地使用它，我们只需要指定正确的模型标识符：",wn,Ce,bn,Ie,fn,$e,ja="正如预期的那样，我们的预训练模型将其知识适应了我们对其进行微调的语料库，而不是单独留下英文单词“threads”，而是将其翻译成法语官方版本。 “”的翻译也是一样的：",dn,ge,hn,Ze,Cn,ke,ua="风格适应的另一个很好的例子！",In,Ol,$n,_e,gn,He,Zn;Z=new Sa({props:{fw:k[0]}}),_=new _l({props:{title:"翻译",local:"翻译",headingTag:"h1"}});const wa=[La,qa],Ge=[];function ba(l,t){return l[0]==="pt"?0:1}x=ba(k),g=Ge[x]=wa[x](k),N=new kn({props:{id:"1JvfrvZgi6c"}}),rl=new _l({props:{title:"准备数据",local:"准备数据",headingTag:"h2"}}),S=new _l({props:{title:"KDE4 数据集",local:"KDE4 数据集",headingTag:"h3"}}),il=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBcmF3X2RhdGFzZXRzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmtkZTQlMjIlMkMlMjBsYW5nMSUzRCUyMmVuJTIyJTJDJTIwbGFuZzIlM0QlMjJmciUyMik=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

raw_datasets = load_dataset(<span class="hljs-string">&quot;kde4&quot;</span>, lang1=<span class="hljs-string">&quot;en&quot;</span>, lang2=<span class="hljs-string">&quot;fr&quot;</span>)`,wrap:!1}}),jl=new h({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),cl=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2lkJyUyQyUyMCd0cmFuc2xhdGlvbiclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIxMDE3MyUwQSUyMCUyMCUyMCUyMCU3RCklMEElN0Qp",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;translation&#x27;</span>],
        num_rows: <span class="hljs-number">210173</span>
    })
})`,wrap:!1}}),i=new h({props:{code:"c3BsaXRfZGF0YXNldHMlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RC50cmFpbl90ZXN0X3NwbGl0KHRyYWluX3NpemUlM0QwLjklMkMlMjBzZWVkJTNEMjApJTBBc3BsaXRfZGF0YXNldHM=",highlighted:`split_datasets = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(train_size=<span class="hljs-number">0.9</span>, seed=<span class="hljs-number">20</span>)
split_datasets`,wrap:!1}}),ul=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2lkJyUyQyUyMCd0cmFuc2xhdGlvbiclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDE4OTE1NSUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidpZCclMkMlMjAndHJhbnNsYXRpb24nJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjAyMTAxOCUwQSUyMCUyMCUyMCUyMCU3RCklMEElN0Qp",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;translation&#x27;</span>],
        num_rows: <span class="hljs-number">189155</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;translation&#x27;</span>],
        num_rows: <span class="hljs-number">21018</span>
    })
})`,wrap:!1}}),es=new h({props:{code:"c3BsaXRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTIwJTNEJTIwc3BsaXRfZGF0YXNldHMucG9wKCUyMnRlc3QlMjIp",highlighted:'split_datasets[<span class="hljs-string">&quot;validation&quot;</span>] = split_datasets.pop(<span class="hljs-string">&quot;test&quot;</span>)',wrap:!1}}),ns=new h({props:{code:"c3BsaXRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjElNUQlNUIlMjJ0cmFuc2xhdGlvbiUyMiU1RA==",highlighted:'split_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;translation&quot;</span>]',wrap:!1}}),as=new h({props:{code:"JTdCJ2VuJyUzQSUyMCdEZWZhdWx0JTIwdG8lMjBleHBhbmRlZCUyMHRocmVhZHMnJTJDJTBBJTIwJ2ZyJyUzQSUyMCdQYXIlMjBkJUMzJUE5ZmF1dCUyQyUyMGQlQzMlQTl2ZWxvcHBlciUyMGxlcyUyMGZpbHMlMjBkZSUyMGRpc2N1c3Npb24nJTdE",highlighted:`{<span class="hljs-string">&#x27;en&#x27;</span>: <span class="hljs-string">&#x27;Default to expanded threads&#x27;</span>,
 <span class="hljs-string">&#x27;fr&#x27;</span>: <span class="hljs-string">&#x27;Par défaut, développer les fils de discussion&#x27;</span>}`,wrap:!1}}),Ms=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMkhlbHNpbmtpLU5MUCUyRm9wdXMtbXQtZW4tZnIlMjIlMEF0cmFuc2xhdG9yJTIwJTNEJTIwcGlwZWxpbmUoJTIydHJhbnNsYXRpb24lMjIlMkMlMjBtb2RlbCUzRG1vZGVsX2NoZWNrcG9pbnQpJTBBdHJhbnNsYXRvciglMjJEZWZhdWx0JTIwdG8lMjBleHBhbmRlZCUyMHRocmVhZHMlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

model_checkpoint = <span class="hljs-string">&quot;Helsinki-NLP/opus-mt-en-fr&quot;</span>
translator = pipeline(<span class="hljs-string">&quot;translation&quot;</span>, model=model_checkpoint)
translator(<span class="hljs-string">&quot;Default to expanded threads&quot;</span>)`,wrap:!1}}),rs=new h({props:{code:"JTVCJTdCJ3RyYW5zbGF0aW9uX3RleHQnJTNBJTIwJ1BhciUyMGQlQzMlQTlmYXV0JTIwcG91ciUyMGxlcyUyMHRocmVhZHMlMjAlQzMlQTlsYXJnaXMnJTdEJTVE",highlighted:'[{<span class="hljs-string">&#x27;translation_text&#x27;</span>: <span class="hljs-string">&#x27;Par défaut pour les threads élargis&#x27;</span>}]',wrap:!1}}),cs=new h({props:{code:"c3BsaXRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjE3MiU1RCU1QiUyMnRyYW5zbGF0aW9uJTIyJTVE",highlighted:'split_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">172</span>][<span class="hljs-string">&quot;translation&quot;</span>]',wrap:!1}}),ys=new h({props:{code:"JTdCJ2VuJyUzQSUyMCdVbmFibGUlMjB0byUyMGltcG9ydCUyMCUyNTElMjB1c2luZyUyMHRoZSUyME9GWCUyMGltcG9ydGVyJTIwcGx1Z2luLiUyMFRoaXMlMjBmaWxlJTIwaXMlMjBub3QlMjB0aGUlMjBjb3JyZWN0JTIwZm9ybWF0LiclMkMlMEElMjAnZnInJTNBJTIwJTIySW1wb3NzaWJsZSUyMGQnaW1wb3J0ZXIlMjAlMjUxJTIwZW4lMjB1dGlsaXNhbnQlMjBsZSUyMG1vZHVsZSUyMGQnZXh0ZW5zaW9uJTIwZCdpbXBvcnRhdGlvbiUyME9GWC4lMjBDZSUyMGZpY2hpZXIlMjBuJ2ElMjBwYXMlMjB1biUyMGZvcm1hdCUyMGNvcnJlY3QuJTIyJTdE",highlighted:`{<span class="hljs-string">&#x27;en&#x27;</span>: <span class="hljs-string">&#x27;Unable to import %1 using the OFX importer plugin. This file is not the correct format.&#x27;</span>,
 <span class="hljs-string">&#x27;fr&#x27;</span>: <span class="hljs-string">&quot;Impossible d&#x27;importer %1 en utilisant le module d&#x27;extension d&#x27;importation OFX. Ce fichier n&#x27;a pas un format correct.&quot;</span>}`,wrap:!1}}),ms=new h({props:{code:"dHJhbnNsYXRvciglMEElMjAlMjAlMjAlMjAlMjJVbmFibGUlMjB0byUyMGltcG9ydCUyMCUyNTElMjB1c2luZyUyMHRoZSUyME9GWCUyMGltcG9ydGVyJTIwcGx1Z2luLiUyMFRoaXMlMjBmaWxlJTIwaXMlMjBub3QlMjB0aGUlMjBjb3JyZWN0JTIwZm9ybWF0LiUyMiUwQSk=",highlighted:`translator(
    <span class="hljs-string">&quot;Unable to import %1 using the OFX importer plugin. This file is not the correct format.&quot;</span>
)`,wrap:!1}}),Ts=new h({props:{code:"JTVCJTdCJ3RyYW5zbGF0aW9uX3RleHQnJTNBJTIwJTIySW1wb3NzaWJsZSUyMGQnaW1wb3J0ZXIlMjAlMjUxJTIwZW4lMjB1dGlsaXNhbnQlMjBsZSUyMHBsdWdpbiUyMGQnaW1wb3J0YXRldXIlMjBPRlguJTIwQ2UlMjBmaWNoaWVyJTIwbidlc3QlMjBwYXMlMjBsZSUyMGJvbiUyMGZvcm1hdC4lMjIlN0QlNUQ=",highlighted:'[{<span class="hljs-string">&#x27;translation_text&#x27;</span>: <span class="hljs-string">&quot;Impossible d&#x27;importer %1 en utilisant le plugin d&#x27;importateur OFX. Ce fichier n&#x27;est pas le bon format.&quot;</span>}]',wrap:!1}}),Us=new kn({props:{id:"0Oxphw4Q9fo"}}),ql=new ls({props:{$$slots:{default:[Pa]},$$scope:{ctx:k}}}),js=new _l({props:{title:"处理数据",local:"处理数据",headingTag:"h3"}}),us=new kn({props:{id:"XAR8jnZZuUs"}}),bs=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIySGVsc2lua2ktTkxQJTJGb3B1cy1tdC1lbi1mciUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

model_checkpoint = <span class="hljs-string">&quot;Helsinki-NLP/opus-mt-en-fr&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`,wrap:!1}}),Ll=new ls({props:{$$slots:{default:[Ka]},$$scope:{ctx:k}}}),Cs=new h({props:{code:"ZW5fc2VudGVuY2UlMjAlM0QlMjBzcGxpdF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMSU1RCU1QiUyMnRyYW5zbGF0aW9uJTIyJTVEJTVCJTIyZW4lMjIlNUQlMEFmcl9zZW50ZW5jZSUyMCUzRCUyMHNwbGl0X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIxJTVEJTVCJTIydHJhbnNsYXRpb24lMjIlNUQlNUIlMjJmciUyMiU1RCUwQSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihlbl9zZW50ZW5jZSUyQyUyMHRleHRfdGFyZ2V0JTNEZnJfc2VudGVuY2UpJTBBaW5wdXRz",highlighted:`en_sentence = split_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;translation&quot;</span>][<span class="hljs-string">&quot;en&quot;</span>]
fr_sentence = split_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;translation&quot;</span>][<span class="hljs-string">&quot;fr&quot;</span>]

inputs = tokenizer(en_sentence, text_target=fr_sentence)
inputs`,wrap:!1}}),Is=new h({props:{code:"JTdCJ2lucHV0X2lkcyclM0ElMjAlNUI0NzU5MSUyQyUyMDEyJTJDJTIwOTg0MiUyQyUyMDE5NjM0JTJDJTIwOSUyQyUyMDAlNUQlMkMlMjAnYXR0ZW50aW9uX21hc2snJTNBJTIwJTVCMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTVEJTJDJTIwJ2xhYmVscyclM0ElMjAlNUI1NzclMkMlMjA1ODkxJTJDJTIwMiUyQyUyMDMxODQlMkMlMjAxNiUyQyUyMDI1NDIlMkMlMjA1JTJDJTIwMTcxMCUyQyUyMDAlNUQlN0Q=",highlighted:'{<span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">47591</span>, <span class="hljs-number">12</span>, <span class="hljs-number">9842</span>, <span class="hljs-number">19634</span>, <span class="hljs-number">9</span>, <span class="hljs-number">0</span>], <span class="hljs-string">&#x27;attention_mask&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>], <span class="hljs-string">&#x27;labels&#x27;</span>: [<span class="hljs-number">577</span>, <span class="hljs-number">5891</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3184</span>, <span class="hljs-number">16</span>, <span class="hljs-number">2542</span>, <span class="hljs-number">5</span>, <span class="hljs-number">1710</span>, <span class="hljs-number">0</span>]}',wrap:!1}}),gs=new h({props:{code:"d3JvbmdfdGFyZ2V0cyUyMCUzRCUyMHRva2VuaXplcihmcl9zZW50ZW5jZSklMEFwcmludCh0b2tlbml6ZXIuY29udmVydF9pZHNfdG9fdG9rZW5zKHdyb25nX3RhcmdldHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKSUwQXByaW50KHRva2VuaXplci5jb252ZXJ0X2lkc190b190b2tlbnMoaW5wdXRzJTVCJTIybGFiZWxzJTIyJTVEKSk=",highlighted:`wrong_targets = tokenizer(fr_sentence)
<span class="hljs-built_in">print</span>(tokenizer.convert_ids_to_tokens(wrong_targets[<span class="hljs-string">&quot;input_ids&quot;</span>]))
<span class="hljs-built_in">print</span>(tokenizer.convert_ids_to_tokens(inputs[<span class="hljs-string">&quot;labels&quot;</span>]))`,wrap:!1}}),Zs=new h({props:{code:"JTVCJyVFMiU5NiU4MVBhciclMkMlMjAnJUUyJTk2JTgxZCVDMyVBOSclMkMlMjAnZiclMkMlMjAnYXV0JyUyQyUyMCclMkMnJTJDJTIwJyVFMiU5NiU4MWQlQzMlQTknJTJDJTIwJ3ZlJyUyQyUyMCdsb3AnJTJDJTIwJ3BlciclMkMlMjAnJUUyJTk2JTgxbGVzJyUyQyUyMCclRTIlOTYlODFmaWwnJTJDJTIwJ3MnJTJDJTIwJyVFMiU5NiU4MWRlJyUyQyUyMCclRTIlOTYlODFkaXNjdXNzaW9uJyUyQyUyMCclM0MlMkZzJTNFJyU1RCUwQSU1QiclRTIlOTYlODFQYXInJTJDJTIwJyVFMiU5NiU4MWQlQzMlQTlmYXV0JyUyQyUyMCclMkMnJTJDJTIwJyVFMiU5NiU4MWQlQzMlQTl2ZWxvcHBlciclMkMlMjAnJUUyJTk2JTgxbGVzJyUyQyUyMCclRTIlOTYlODFmaWxzJyUyQyUyMCclRTIlOTYlODFkZSclMkMlMjAnJUUyJTk2JTgxZGlzY3Vzc2lvbiclMkMlMjAnJTNDJTJGcyUzRSclNUQ=",highlighted:`[<span class="hljs-string">&#x27;▁Par&#x27;</span>, <span class="hljs-string">&#x27;▁dé&#x27;</span>, <span class="hljs-string">&#x27;f&#x27;</span>, <span class="hljs-string">&#x27;aut&#x27;</span>, <span class="hljs-string">&#x27;,&#x27;</span>, <span class="hljs-string">&#x27;▁dé&#x27;</span>, <span class="hljs-string">&#x27;ve&#x27;</span>, <span class="hljs-string">&#x27;lop&#x27;</span>, <span class="hljs-string">&#x27;per&#x27;</span>, <span class="hljs-string">&#x27;▁les&#x27;</span>, <span class="hljs-string">&#x27;▁fil&#x27;</span>, <span class="hljs-string">&#x27;s&#x27;</span>, <span class="hljs-string">&#x27;▁de&#x27;</span>, <span class="hljs-string">&#x27;▁discussion&#x27;</span>, <span class="hljs-string">&#x27;&lt;/s&gt;&#x27;</span>]
[<span class="hljs-string">&#x27;▁Par&#x27;</span>, <span class="hljs-string">&#x27;▁défaut&#x27;</span>, <span class="hljs-string">&#x27;,&#x27;</span>, <span class="hljs-string">&#x27;▁développer&#x27;</span>, <span class="hljs-string">&#x27;▁les&#x27;</span>, <span class="hljs-string">&#x27;▁fils&#x27;</span>, <span class="hljs-string">&#x27;▁de&#x27;</span>, <span class="hljs-string">&#x27;▁discussion&#x27;</span>, <span class="hljs-string">&#x27;&lt;/s&gt;&#x27;</span>]`,wrap:!1}}),Gs=new h({props:{code:"bWF4X2xlbmd0aCUyMCUzRCUyMDEyOCUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfZnVuY3Rpb24oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwJTVCZXglNUIlMjJlbiUyMiU1RCUyMGZvciUyMGV4JTIwaW4lMjBleGFtcGxlcyU1QiUyMnRyYW5zbGF0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwdGFyZ2V0cyUyMCUzRCUyMCU1QmV4JTVCJTIyZnIlMjIlNUQlMjBmb3IlMjBleCUyMGluJTIwZXhhbXBsZXMlNUIlMjJ0cmFuc2xhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbnB1dHMlMkMlMjB0ZXh0X3RhcmdldCUzRHRhcmdldHMlMkMlMjBtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX2lucHV0cw==",highlighted:`max_length = <span class="hljs-number">128</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
    inputs = [ex[<span class="hljs-string">&quot;en&quot;</span>] <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
    targets = [ex[<span class="hljs-string">&quot;fr&quot;</span>] <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
    model_inputs = tokenizer(
        inputs, text_target=targets, max_length=max_length, truncation=<span class="hljs-literal">True</span>
    )
    <span class="hljs-keyword">return</span> model_inputs`,wrap:!1}}),Pl=new ls({props:{$$slots:{default:[Oa]},$$scope:{ctx:k}}}),Kl=new ls({props:{warning:!0,$$slots:{default:[lp]},$$scope:{ctx:k}}}),Ws=new h({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwc3BsaXRfZGF0YXNldHMubWFwKCUwQSUyMCUyMCUyMCUyMHByZXByb2Nlc3NfZnVuY3Rpb24lMkMlMEElMjAlMjAlMjAlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHJlbW92ZV9jb2x1bW5zJTNEc3BsaXRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMlMkMlMEEp",highlighted:`tokenized_datasets = split_datasets.<span class="hljs-built_in">map</span>(
    preprocess_function,
    batched=<span class="hljs-literal">True</span>,
    remove_columns=split_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names,
)`,wrap:!1}});const fa=[ep,sp],xe=[];function da(l,t){return l[0]==="pt"?0:1}Rl=da(k),Xl=xe[Rl]=fa[Rl](k),Vs=new _l({props:{title:"数据整理",local:"数据整理",headingTag:"h3"}});const ha=[ap,np],Be=[];function Ca(l,t){return l[0]==="pt"?0:1}Vl=Ca(k),Nl=Be[Vl]=ha[Vl](k),As=new h({props:{code:"YmF0Y2glMjAlM0QlMjBkYXRhX2NvbGxhdG9yKCU1QnRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCaSU1RCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDElMkMlMjAzKSU1RCklMEFiYXRjaC5rZXlzKCk=",highlighted:`batch = data_collator([tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>)])
batch.keys()`,wrap:!1}}),Es=new h({props:{code:"ZGljdF9rZXlzKCU1QidhdHRlbnRpb25fbWFzayclMkMlMjAnaW5wdXRfaWRzJyUyQyUyMCdsYWJlbHMnJTJDJTIwJ2RlY29kZXJfaW5wdXRfaWRzJyU1RCk=",highlighted:'dict_keys([<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;decoder_input_ids&#x27;</span>])',wrap:!1}}),Ys=new h({props:{code:"YmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQ=",highlighted:'batch[<span class="hljs-string">&quot;labels&quot;</span>]',wrap:!1}}),Fs=new h({props:{code:"dGVuc29yKCU1QiU1QiUyMCUyMDU3NyUyQyUyMCUyMDU4OTElMkMlMjAlMjAlMjAlMjAlMjAyJTJDJTIwJTIwMzE4NCUyQyUyMCUyMCUyMCUyMDE2JTJDJTIwJTIwMjU0MiUyQyUyMCUyMCUyMCUyMCUyMDUlMkMlMjAlMjAxNzEwJTJDJTIwJTIwJTIwJTIwJTIwMCUyQyUyMCUyMC0xMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtMTAwJTJDJTIwJTIwLTEwMCUyQyUyMCUyMC0xMDAlMkMlMjAlMjAtMTAwJTJDJTIwJTIwLTEwMCUyQyUyMCUyMC0xMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUIlMjAxMjExJTJDJTIwJTIwJTIwJTIwJTIwMyUyQyUyMCUyMCUyMCUyMDQ5JTJDJTIwJTIwOTQwOSUyQyUyMCUyMDEyMTElMkMlMjAlMjAlMjAlMjAlMjAzJTJDJTIwMjkxNDAlMkMlMjAlMjAlMjA4MTclMkMlMjAlMjAzMTI0JTJDJTIwJTIwJTIwODE3JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTUwJTJDJTIwJTIwNzAzMiUyQyUyMCUyMDU4MjElMkMlMjAlMjA3OTA3JTJDJTIwMTI2NDklMkMlMjAlMjAlMjAlMjAlMjAwJTVEJTVEKQ==",highlighted:`tensor([[  <span class="hljs-number">577</span>,  <span class="hljs-number">5891</span>,     <span class="hljs-number">2</span>,  <span class="hljs-number">3184</span>,    <span class="hljs-number">16</span>,  <span class="hljs-number">2542</span>,     <span class="hljs-number">5</span>,  <span class="hljs-number">1710</span>,     <span class="hljs-number">0</span>,  -<span class="hljs-number">100</span>,
          -<span class="hljs-number">100</span>,  -<span class="hljs-number">100</span>,  -<span class="hljs-number">100</span>,  -<span class="hljs-number">100</span>,  -<span class="hljs-number">100</span>,  -<span class="hljs-number">100</span>],
        [ <span class="hljs-number">1211</span>,     <span class="hljs-number">3</span>,    <span class="hljs-number">49</span>,  <span class="hljs-number">9409</span>,  <span class="hljs-number">1211</span>,     <span class="hljs-number">3</span>, <span class="hljs-number">29140</span>,   <span class="hljs-number">817</span>,  <span class="hljs-number">3124</span>,   <span class="hljs-number">817</span>,
           <span class="hljs-number">550</span>,  <span class="hljs-number">7032</span>,  <span class="hljs-number">5821</span>,  <span class="hljs-number">7907</span>, <span class="hljs-number">12649</span>,     <span class="hljs-number">0</span>]])`,wrap:!1}}),Ss=new h({props:{code:"YmF0Y2glNUIlMjJkZWNvZGVyX2lucHV0X2lkcyUyMiU1RA==",highlighted:'batch[<span class="hljs-string">&quot;decoder_input_ids&quot;</span>]',wrap:!1}}),Ds=new h({props:{code:"dGVuc29yKCU1QiU1QjU5NTEzJTJDJTIwJTIwJTIwNTc3JTJDJTIwJTIwNTg5MSUyQyUyMCUyMCUyMCUyMCUyMDIlMkMlMjAlMjAzMTg0JTJDJTIwJTIwJTIwJTIwMTYlMkMlMjAlMjAyNTQyJTJDJTIwJTIwJTIwJTIwJTIwNSUyQyUyMCUyMDE3MTAlMkMlMjAlMjAlMjAlMjAlMjAwJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTk1MTMlMkMlMjA1OTUxMyUyQyUyMDU5NTEzJTJDJTIwNTk1MTMlMkMlMjA1OTUxMyUyQyUyMDU5NTEzJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCNTk1MTMlMkMlMjAlMjAxMjExJTJDJTIwJTIwJTIwJTIwJTIwMyUyQyUyMCUyMCUyMCUyMDQ5JTJDJTIwJTIwOTQwOSUyQyUyMCUyMDEyMTElMkMlMjAlMjAlMjAlMjAlMjAzJTJDJTIwMjkxNDAlMkMlMjAlMjAlMjA4MTclMkMlMjAlMjAzMTI0JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwODE3JTJDJTIwJTIwJTIwNTUwJTJDJTIwJTIwNzAzMiUyQyUyMCUyMDU4MjElMkMlMjAlMjA3OTA3JTJDJTIwMTI2NDklNUQlNUQp",highlighted:`tensor([[<span class="hljs-number">59513</span>,   <span class="hljs-number">577</span>,  <span class="hljs-number">5891</span>,     <span class="hljs-number">2</span>,  <span class="hljs-number">3184</span>,    <span class="hljs-number">16</span>,  <span class="hljs-number">2542</span>,     <span class="hljs-number">5</span>,  <span class="hljs-number">1710</span>,     <span class="hljs-number">0</span>,
         <span class="hljs-number">59513</span>, <span class="hljs-number">59513</span>, <span class="hljs-number">59513</span>, <span class="hljs-number">59513</span>, <span class="hljs-number">59513</span>, <span class="hljs-number">59513</span>],
        [<span class="hljs-number">59513</span>,  <span class="hljs-number">1211</span>,     <span class="hljs-number">3</span>,    <span class="hljs-number">49</span>,  <span class="hljs-number">9409</span>,  <span class="hljs-number">1211</span>,     <span class="hljs-number">3</span>, <span class="hljs-number">29140</span>,   <span class="hljs-number">817</span>,  <span class="hljs-number">3124</span>,
           <span class="hljs-number">817</span>,   <span class="hljs-number">550</span>,  <span class="hljs-number">7032</span>,  <span class="hljs-number">5821</span>,  <span class="hljs-number">7907</span>, <span class="hljs-number">12649</span>]])`,wrap:!1}}),Ls=new h({props:{code:"Zm9yJTIwaSUyMGluJTIwcmFuZ2UoMSUyQyUyMDMpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQodG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUJpJTVEJTVCJTIybGFiZWxzJTIyJTVEKQ==",highlighted:`<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>):
    <span class="hljs-built_in">print</span>(tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i][<span class="hljs-string">&quot;labels&quot;</span>])`,wrap:!1}}),Ps=new h({props:{code:"JTVCNTc3JTJDJTIwNTg5MSUyQyUyMDIlMkMlMjAzMTg0JTJDJTIwMTYlMkMlMjAyNTQyJTJDJTIwNSUyQyUyMDE3MTAlMkMlMjAwJTVEJTBBJTVCMTIxMSUyQyUyMDMlMkMlMjA0OSUyQyUyMDk0MDklMkMlMjAxMjExJTJDJTIwMyUyQyUyMDI5MTQwJTJDJTIwODE3JTJDJTIwMzEyNCUyQyUyMDgxNyUyQyUyMDU1MCUyQyUyMDcwMzIlMkMlMjA1ODIxJTJDJTIwNzkwNyUyQyUyMDEyNjQ5JTJDJTIwMCU1RA==",highlighted:`[<span class="hljs-number">577</span>, <span class="hljs-number">5891</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3184</span>, <span class="hljs-number">16</span>, <span class="hljs-number">2542</span>, <span class="hljs-number">5</span>, <span class="hljs-number">1710</span>, <span class="hljs-number">0</span>]
[<span class="hljs-number">1211</span>, <span class="hljs-number">3</span>, <span class="hljs-number">49</span>, <span class="hljs-number">9409</span>, <span class="hljs-number">1211</span>, <span class="hljs-number">3</span>, <span class="hljs-number">29140</span>, <span class="hljs-number">817</span>, <span class="hljs-number">3124</span>, <span class="hljs-number">817</span>, <span class="hljs-number">550</span>, <span class="hljs-number">7032</span>, <span class="hljs-number">5821</span>, <span class="hljs-number">7907</span>, <span class="hljs-number">12649</span>, <span class="hljs-number">0</span>]`,wrap:!1}});const Ia=[Mp,pp],We=[];function $a(l,t){return l[0]==="pt"?0:1}vl=$a(k),Ql=We[vl]=Ia[vl](k),Ks=new _l({props:{title:"评估指标",local:"评估指标",headingTag:"h3"}}),Os=new kn({props:{id:"M05L1DhFqcw"}});let wl=k[0]==="pt"&&Na();ee=new h({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzYWNyZWJsZXU=",highlighted:"!pip install sacrebleu",wrap:!1}}),ne=new h({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNhY3JlYmxldSUyMik=",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;sacrebleu&quot;</span>)`,wrap:!1}}),Me=new h({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjJUaGlzJTIwcGx1Z2luJTIwbGV0cyUyMHlvdSUyMHRyYW5zbGF0ZSUyMHdlYiUyMHBhZ2VzJTIwYmV0d2VlbiUyMHNldmVyYWwlMjBsYW5ndWFnZXMlMjBhdXRvbWF0aWNhbGx5LiUyMiUwQSU1RCUwQXJlZmVyZW5jZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJUaGlzJTIwcGx1Z2luJTIwYWxsb3dzJTIweW91JTIwdG8lMjBhdXRvbWF0aWNhbGx5JTIwdHJhbnNsYXRlJTIwd2ViJTIwcGFnZXMlMjBiZXR3ZWVuJTIwc2V2ZXJhbCUyMGxhbmd1YWdlcy4lMjIlMEElMjAlMjAlMjAlMjAlNUQlMEElNUQlMEFtZXRyaWMuY29tcHV0ZShwcmVkaWN0aW9ucyUzRHByZWRpY3Rpb25zJTJDJTIwcmVmZXJlbmNlcyUzRHJlZmVyZW5jZXMp",highlighted:`predictions = [
    <span class="hljs-string">&quot;This plugin lets you translate web pages between several languages automatically.&quot;</span>
]
references = [
    [
        <span class="hljs-string">&quot;This plugin allows you to automatically translate web pages between several languages.&quot;</span>
    ]
]
metric.compute(predictions=predictions, references=references)`,wrap:!1}}),re=new h({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDQ2Ljc1MDQ2OTY4Mjk5MDE2NSUyQyUwQSUyMCdjb3VudHMnJTNBJTIwJTVCMTElMkMlMjA2JTJDJTIwNCUyQyUyMDMlNUQlMkMlMEElMjAndG90YWxzJyUzQSUyMCU1QjEyJTJDJTIwMTElMkMlMjAxMCUyQyUyMDklNUQlMkMlMEElMjAncHJlY2lzaW9ucyclM0ElMjAlNUI5MS42NyUyQyUyMDU0LjU0JTJDJTIwNDAuMCUyQyUyMDMzLjMzJTVEJTJDJTBBJTIwJ2JwJyUzQSUyMDAuOTIwMDQ0NDE0NjI5MzIzMyUyQyUwQSUyMCdzeXNfbGVuJyUzQSUyMDEyJTJDJTBBJTIwJ3JlZl9sZW4nJTNBJTIwMTMlN0Q=",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">46.750469682990165</span>,
 <span class="hljs-string">&#x27;counts&#x27;</span>: [<span class="hljs-number">11</span>, <span class="hljs-number">6</span>, <span class="hljs-number">4</span>, <span class="hljs-number">3</span>],
 <span class="hljs-string">&#x27;totals&#x27;</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">11</span>, <span class="hljs-number">10</span>, <span class="hljs-number">9</span>],
 <span class="hljs-string">&#x27;precisions&#x27;</span>: [<span class="hljs-number">91.67</span>, <span class="hljs-number">54.54</span>, <span class="hljs-number">40.0</span>, <span class="hljs-number">33.33</span>],
 <span class="hljs-string">&#x27;bp&#x27;</span>: <span class="hljs-number">0.9200444146293233</span>,
 <span class="hljs-string">&#x27;sys_len&#x27;</span>: <span class="hljs-number">12</span>,
 <span class="hljs-string">&#x27;ref_len&#x27;</span>: <span class="hljs-number">13</span>}`,wrap:!1}}),ce=new h({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjAlNUIlMjJUaGlzJTIwVGhpcyUyMFRoaXMlMjBUaGlzJTIyJTVEJTBBcmVmZXJlbmNlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMlRoaXMlMjBwbHVnaW4lMjBhbGxvd3MlMjB5b3UlMjB0byUyMGF1dG9tYXRpY2FsbHklMjB0cmFuc2xhdGUlMjB3ZWIlMjBwYWdlcyUyMGJldHdlZW4lMjBzZXZlcmFsJTIwbGFuZ3VhZ2VzLiUyMiUwQSUyMCUyMCUyMCUyMCU1RCUwQSU1RCUwQW1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEcmVmZXJlbmNlcyk=",highlighted:`predictions = [<span class="hljs-string">&quot;This This This This&quot;</span>]
references = [
    [
        <span class="hljs-string">&quot;This plugin allows you to automatically translate web pages between several languages.&quot;</span>
    ]
]
metric.compute(predictions=predictions, references=references)`,wrap:!1}}),ye=new h({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDEuNjgzNjAyNjkzMTY3Njg5JTJDJTBBJTIwJ2NvdW50cyclM0ElMjAlNUIxJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTVEJTJDJTBBJTIwJ3RvdGFscyclM0ElMjAlNUI0JTJDJTIwMyUyQyUyMDIlMkMlMjAxJTVEJTJDJTBBJTIwJ3ByZWNpc2lvbnMnJTNBJTIwJTVCMjUuMCUyQyUyMDE2LjY3JTJDJTIwMTIuNSUyQyUyMDEyLjUlNUQlMkMlMEElMjAnYnAnJTNBJTIwMC4xMDUzOTkyMjQ1NjE4NjQzMyUyQyUwQSUyMCdzeXNfbGVuJyUzQSUyMDQlMkMlMEElMjAncmVmX2xlbiclM0ElMjAxMyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">1.683602693167689</span>,
 <span class="hljs-string">&#x27;counts&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
 <span class="hljs-string">&#x27;totals&#x27;</span>: [<span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>],
 <span class="hljs-string">&#x27;precisions&#x27;</span>: [<span class="hljs-number">25.0</span>, <span class="hljs-number">16.67</span>, <span class="hljs-number">12.5</span>, <span class="hljs-number">12.5</span>],
 <span class="hljs-string">&#x27;bp&#x27;</span>: <span class="hljs-number">0.10539922456186433</span>,
 <span class="hljs-string">&#x27;sys_len&#x27;</span>: <span class="hljs-number">4</span>,
 <span class="hljs-string">&#x27;ref_len&#x27;</span>: <span class="hljs-number">13</span>}`,wrap:!1}}),Je=new h({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjAlNUIlMjJUaGlzJTIwcGx1Z2luJTIyJTVEJTBBcmVmZXJlbmNlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMlRoaXMlMjBwbHVnaW4lMjBhbGxvd3MlMjB5b3UlMjB0byUyMGF1dG9tYXRpY2FsbHklMjB0cmFuc2xhdGUlMjB3ZWIlMjBwYWdlcyUyMGJldHdlZW4lMjBzZXZlcmFsJTIwbGFuZ3VhZ2VzLiUyMiUwQSUyMCUyMCUyMCUyMCU1RCUwQSU1RCUwQW1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEcmVmZXJlbmNlcyk=",highlighted:`predictions = [<span class="hljs-string">&quot;This plugin&quot;</span>]
references = [
    [
        <span class="hljs-string">&quot;This plugin allows you to automatically translate web pages between several languages.&quot;</span>
    ]
]
metric.compute(predictions=predictions, references=references)`,wrap:!1}}),me=new h({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuMCUyQyUwQSUyMCdjb3VudHMnJTNBJTIwJTVCMiUyQyUyMDElMkMlMjAwJTJDJTIwMCU1RCUyQyUwQSUyMCd0b3RhbHMnJTNBJTIwJTVCMiUyQyUyMDElMkMlMjAwJTJDJTIwMCU1RCUyQyUwQSUyMCdwcmVjaXNpb25zJyUzQSUyMCU1QjEwMC4wJTJDJTIwMTAwLjAlMkMlMjAwLjAlMkMlMjAwLjAlNUQlMkMlMEElMjAnYnAnJTNBJTIwMC4wMDQwODY3NzE0Mzg0NjQwNjclMkMlMEElMjAnc3lzX2xlbiclM0ElMjAyJTJDJTBBJTIwJ3JlZl9sZW4nJTNBJTIwMTMlN0Q=",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0</span>,
 <span class="hljs-string">&#x27;counts&#x27;</span>: [<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
 <span class="hljs-string">&#x27;totals&#x27;</span>: [<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
 <span class="hljs-string">&#x27;precisions&#x27;</span>: [<span class="hljs-number">100.0</span>, <span class="hljs-number">100.0</span>, <span class="hljs-number">0.0</span>, <span class="hljs-number">0.0</span>],
 <span class="hljs-string">&#x27;bp&#x27;</span>: <span class="hljs-number">0.004086771438464067</span>,
 <span class="hljs-string">&#x27;sys_len&#x27;</span>: <span class="hljs-number">2</span>,
 <span class="hljs-string">&#x27;ref_len&#x27;</span>: <span class="hljs-number">13</span>}`,wrap:!1}});const ga=[ip,rp],Re=[];function Za(l,t){return l[0]==="tf"?0:1}Al=Za(k),El=Re[Al]=ga[Al](k),Ue=new _l({props:{title:"微调模型",local:"微调模型",headingTag:"h3"}}),ue=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),fe=new h({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}});const ka=[yp,cp],Xe=[];function _a(l,t){return l[0]==="tf"?0:1}zl=_a(k),Yl=Xe[zl]=ka[zl](k);let pl=k[0]==="pt"&&va();return de=new _l({props:{title:"使用微调后的模型",local:"使用微调后的模型",headingTag:"h2"}}),Ce=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTIzJTIwUmVwbGFjZSUyMHRoaXMlMjB3aXRoJTIweW91ciUyMG93biUyMGNoZWNrcG9pbnQlMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGbWFyaWFuLWZpbmV0dW5lZC1rZGU0LWVuLXRvLWZyJTIyJTBBdHJhbnNsYXRvciUyMCUzRCUyMHBpcGVsaW5lKCUyMnRyYW5zbGF0aW9uJTIyJTJDJTIwbW9kZWwlM0Rtb2RlbF9jaGVja3BvaW50KSUwQXRyYW5zbGF0b3IoJTIyRGVmYXVsdCUyMHRvJTIwZXhwYW5kZWQlMjB0aHJlYWRzJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-comment"># Replace this with your own checkpoint</span>
model_checkpoint = <span class="hljs-string">&quot;huggingface-course/marian-finetuned-kde4-en-to-fr&quot;</span>
translator = pipeline(<span class="hljs-string">&quot;translation&quot;</span>, model=model_checkpoint)
translator(<span class="hljs-string">&quot;Default to expanded threads&quot;</span>)`,wrap:!1}}),Ie=new h({props:{code:"JTVCJTdCJ3RyYW5zbGF0aW9uX3RleHQnJTNBJTIwJ1BhciUyMGQlQzMlQTlmYXV0JTJDJTIwZCVDMyVBOXZlbG9wcGVyJTIwbGVzJTIwZmlscyUyMGRlJTIwZGlzY3Vzc2lvbiclN0QlNUQ=",highlighted:'[{<span class="hljs-string">&#x27;translation_text&#x27;</span>: <span class="hljs-string">&#x27;Par défaut, développer les fils de discussion&#x27;</span>}]',wrap:!1}}),ge=new h({props:{code:"dHJhbnNsYXRvciglMEElMjAlMjAlMjAlMjAlMjJVbmFibGUlMjB0byUyMGltcG9ydCUyMCUyNTElMjB1c2luZyUyMHRoZSUyME9GWCUyMGltcG9ydGVyJTIwcGx1Z2luLiUyMFRoaXMlMjBmaWxlJTIwaXMlMjBub3QlMjB0aGUlMjBjb3JyZWN0JTIwZm9ybWF0LiUyMiUwQSk=",highlighted:`translator(
    <span class="hljs-string">&quot;Unable to import %1 using the OFX importer plugin. This file is not the correct format.&quot;</span>
)`,wrap:!1}}),Ze=new h({props:{code:"JTVCJTdCJ3RyYW5zbGF0aW9uX3RleHQnJTNBJTIwJTIySW1wb3NzaWJsZSUyMGQnaW1wb3J0ZXIlMjAlMjUxJTIwZW4lMjB1dGlsaXNhbnQlMjBsZSUyMG1vZHVsZSUyMGV4dGVybmUlMjBkJ2ltcG9ydGF0aW9uJTIwT0ZYLiUyMENlJTIwZmljaGllciUyMG4nZXN0JTIwcGFzJTIwbGUlMjBib24lMjBmb3JtYXQuJTIyJTdEJTVE",highlighted:'[{<span class="hljs-string">&#x27;translation_text&#x27;</span>: <span class="hljs-string">&quot;Impossible d&#x27;importer %1 en utilisant le module externe d&#x27;importation OFX. Ce fichier n&#x27;est pas le bon format.&quot;</span>}]',wrap:!1}}),Ol=new ls({props:{$$slots:{default:[Tp]},$$scope:{ctx:k}}}),_e=new Da({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter7/4.mdx"}}),{c(){p=J("meta"),d=n(),r=J("p"),f=n(),T(Z.$$.fragment),w=n(),T(_.$$.fragment),G=n(),g.c(),C=n(),W=J("p"),W.innerHTML=O,Tl=n(),Q=J("ul"),Q.innerHTML=Y,L=n(),T(N.$$.fragment),ol=n(),A=J("p"),A.innerHTML=F,P=n(),v=J("p"),v.innerHTML=gl,K=n(),X=J("p"),X.textContent=ll,E=n(),R=J("iframe"),sl=n(),V=J("a"),V.innerHTML=b,B=n(),el=J("p"),el.innerHTML=Ul,yl=n(),T(rl.$$.fragment),bl=n(),H=J("p"),H.innerHTML=Sl,fl=n(),T(S.$$.fragment),dl=n(),D=J("p"),D.innerHTML=Fl,Jl=n(),T(il.$$.fragment),hl=n(),q=J("p"),q.innerHTML=Dl,Cl=n(),z=J("img"),tl=n(),Zl=J("p"),Zl.textContent=xl,nl=n(),T(jl.$$.fragment),ml=n(),T(cl.$$.fragment),Bl=n(),al=J("p"),al.innerHTML=kl,Il=n(),T(i.$$.fragment),$=n(),T(ul.$$.fragment),ss=n(),Wl=J("p"),Wl.innerHTML=M,I=n(),T(es.$$.fragment),Se=n(),ts=J("p"),ts.textContent=Vn,De=n(),T(ns.$$.fragment),qe=n(),T(as.$$.fragment),Le=n(),ps=J("p"),ps.textContent=Nn,Pe=n(),T(Ms.$$.fragment),Ke=n(),T(rs.$$.fragment),Oe=n(),is=J("p"),is.textContent=vn,lt=n(),T(cs.$$.fragment),st=n(),T(ys.$$.fragment),et=n(),Js=J("p"),Js.textContent=Qn,tt=n(),T(ms.$$.fragment),nt=n(),T(Ts.$$.fragment),at=n(),os=J("p"),os.textContent=An,pt=n(),T(Us.$$.fragment),Mt=n(),T(ql.$$.fragment),rt=n(),T(js.$$.fragment),it=n(),T(us.$$.fragment),ct=n(),ws=J("p"),ws.innerHTML=En,yt=n(),T(bs.$$.fragment),Jt=n(),fs=J("p"),fs.innerHTML=zn,mt=n(),T(Ll.$$.fragment),Tt=n(),ds=J("p"),ds.innerHTML=Yn,ot=n(),hs=J("p"),hs.textContent=Fn,Ut=n(),T(Cs.$$.fragment),jt=n(),T(Is.$$.fragment),ut=n(),$s=J("p"),$s.textContent=Hn,wt=n(),T(gs.$$.fragment),bt=n(),T(Zs.$$.fragment),ft=n(),ks=J("p"),ks.textContent=Sn,dt=n(),_s=J("p"),_s.textContent=Dn,ht=n(),T(Gs.$$.fragment),Ct=n(),xs=J("p"),xs.textContent=qn,It=n(),T(Pl.$$.fragment),$t=n(),T(Kl.$$.fragment),gt=n(),Bs=J("p"),Bs.textContent=Ln,Zt=n(),T(Ws.$$.fragment),kt=n(),Rs=J("p"),Rs.textContent=Pn,_t=n(),Xl.c(),ve=n(),Xs=J("p"),Xs.textContent=Kn,Gt=n(),T(Vs.$$.fragment),xt=n(),Ns=J("p"),Ns.innerHTML=On,Bt=n(),vs=J("p"),vs.innerHTML=la,Wt=n(),Nl.c(),Qe=n(),Qs=J("p"),Qs.textContent=sa,Rt=n(),T(As.$$.fragment),Xt=n(),T(Es.$$.fragment),Vt=n(),zs=J("p"),zs.innerHTML=ea,Nt=n(),T(Ys.$$.fragment),vt=n(),T(Fs.$$.fragment),Qt=n(),Hs=J("p"),Hs.textContent=ta,At=n(),T(Ss.$$.fragment),Et=n(),T(Ds.$$.fragment),zt=n(),qs=J("p"),qs.textContent=na,Yt=n(),T(Ls.$$.fragment),Ft=n(),T(Ps.$$.fragment),Ht=n(),Ql.c(),Ae=n(),T(Ks.$$.fragment),St=n(),T(Os.$$.fragment),Dt=n(),wl&&wl.c(),Ee=n(),le=J("p"),le.innerHTML=aa,qt=n(),se=J("p"),se.innerHTML=pa,Lt=n(),T(ee.$$.fragment),Pt=n(),te=J("p"),te.innerHTML=Ma,Kt=n(),T(ne.$$.fragment),Ot=n(),ae=J("p"),ae.textContent=ra,ln=n(),pe=J("p"),pe.textContent=ia,sn=n(),T(Me.$$.fragment),en=n(),T(re.$$.fragment),tn=n(),ie=J("p"),ie.innerHTML=ca,nn=n(),T(ce.$$.fragment),an=n(),T(ye.$$.fragment),pn=n(),T(Je.$$.fragment),Mn=n(),T(me.$$.fragment),rn=n(),Te=J("p"),Te.textContent=ya,cn=n(),El.c(),ze=n(),oe=J("p"),oe.textContent=Ja,yn=n(),T(Ue.$$.fragment),Jn=n(),je=J("p"),je.textContent=ma,mn=n(),T(ue.$$.fragment),Tn=n(),we=J("p"),we.textContent=Ta,on=n(),be=J("p"),be.textContent=oa,Un=n(),T(fe.$$.fragment),jn=n(),Yl.c(),Ye=n(),pl&&pl.c(),Fe=n(),T(de.$$.fragment),un=n(),he=J("p"),he.textContent=Ua,wn=n(),T(Ce.$$.fragment),bn=n(),T(Ie.$$.fragment),fn=n(),$e=J("p"),$e.textContent=ja,dn=n(),T(ge.$$.fragment),hn=n(),T(Ze.$$.fragment),Cn=n(),ke=J("p"),ke.textContent=ua,In=n(),T(Ol.$$.fragment),$n=n(),T(_e.$$.fragment),gn=n(),He=J("p"),this.h()},l(l){const t=Fa("svelte-u9bgzb",document.head);p=m(t,"META",{name:!0,content:!0}),t.forEach(s),d=a(l),r=m(l,"P",{}),Xn(r).forEach(s),f=a(l),o(Z.$$.fragment,l),w=a(l),o(_.$$.fragment,l),G=a(l),g.l(l),C=a(l),W=m(l,"P",{"data-svelte-h":!0}),u(W)!=="svelte-1ng04m1"&&(W.innerHTML=O),Tl=a(l),Q=m(l,"UL",{"data-svelte-h":!0}),u(Q)!=="svelte-148sqa4"&&(Q.innerHTML=Y),L=a(l),o(N.$$.fragment,l),ol=a(l),A=m(l,"P",{"data-svelte-h":!0}),u(A)!=="svelte-1lz8dv2"&&(A.innerHTML=F),P=a(l),v=m(l,"P",{"data-svelte-h":!0}),u(v)!=="svelte-mleyv0"&&(v.innerHTML=gl),K=a(l),X=m(l,"P",{"data-svelte-h":!0}),u(X)!=="svelte-1unz1qk"&&(X.textContent=ll),E=a(l),R=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Xn(R).forEach(s),sl=a(l),V=m(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),u(V)!=="svelte-1ifl6xg"&&(V.innerHTML=b),B=a(l),el=m(l,"P",{"data-svelte-h":!0}),u(el)!=="svelte-1ojgeub"&&(el.innerHTML=Ul),yl=a(l),o(rl.$$.fragment,l),bl=a(l),H=m(l,"P",{"data-svelte-h":!0}),u(H)!=="svelte-1134q08"&&(H.innerHTML=Sl),fl=a(l),o(S.$$.fragment,l),dl=a(l),D=m(l,"P",{"data-svelte-h":!0}),u(D)!=="svelte-hlqu7i"&&(D.innerHTML=Fl),Jl=a(l),o(il.$$.fragment,l),hl=a(l),q=m(l,"P",{"data-svelte-h":!0}),u(q)!=="svelte-41sqzz"&&(q.innerHTML=Dl),Cl=a(l),z=m(l,"IMG",{src:!0,alt:!0,width:!0}),tl=a(l),Zl=m(l,"P",{"data-svelte-h":!0}),u(Zl)!=="svelte-vvikr8"&&(Zl.textContent=xl),nl=a(l),o(jl.$$.fragment,l),ml=a(l),o(cl.$$.fragment,l),Bl=a(l),al=m(l,"P",{"data-svelte-h":!0}),u(al)!=="svelte-15udkwx"&&(al.innerHTML=kl),Il=a(l),o(i.$$.fragment,l),$=a(l),o(ul.$$.fragment,l),ss=a(l),Wl=m(l,"P",{"data-svelte-h":!0}),u(Wl)!=="svelte-1adp8uk"&&(Wl.innerHTML=M),I=a(l),o(es.$$.fragment,l),Se=a(l),ts=m(l,"P",{"data-svelte-h":!0}),u(ts)!=="svelte-17klq8b"&&(ts.textContent=Vn),De=a(l),o(ns.$$.fragment,l),qe=a(l),o(as.$$.fragment,l),Le=a(l),ps=m(l,"P",{"data-svelte-h":!0}),u(ps)!=="svelte-17cyno8"&&(ps.textContent=Nn),Pe=a(l),o(Ms.$$.fragment,l),Ke=a(l),o(rs.$$.fragment,l),Oe=a(l),is=m(l,"P",{"data-svelte-h":!0}),u(is)!=="svelte-i1zna0"&&(is.textContent=vn),lt=a(l),o(cs.$$.fragment,l),st=a(l),o(ys.$$.fragment,l),et=a(l),Js=m(l,"P",{"data-svelte-h":!0}),u(Js)!=="svelte-ipwn4g"&&(Js.textContent=Qn),tt=a(l),o(ms.$$.fragment,l),nt=a(l),o(Ts.$$.fragment,l),at=a(l),os=m(l,"P",{"data-svelte-h":!0}),u(os)!=="svelte-117w5tn"&&(os.textContent=An),pt=a(l),o(Us.$$.fragment,l),Mt=a(l),o(ql.$$.fragment,l),rt=a(l),o(js.$$.fragment,l),it=a(l),o(us.$$.fragment,l),ct=a(l),ws=m(l,"P",{"data-svelte-h":!0}),u(ws)!=="svelte-1gb39mt"&&(ws.innerHTML=En),yt=a(l),o(bs.$$.fragment,l),Jt=a(l),fs=m(l,"P",{"data-svelte-h":!0}),u(fs)!=="svelte-1rmw8z"&&(fs.innerHTML=zn),mt=a(l),o(Ll.$$.fragment,l),Tt=a(l),ds=m(l,"P",{"data-svelte-h":!0}),u(ds)!=="svelte-18xmek7"&&(ds.innerHTML=Yn),ot=a(l),hs=m(l,"P",{"data-svelte-h":!0}),u(hs)!=="svelte-oi1mjw"&&(hs.textContent=Fn),Ut=a(l),o(Cs.$$.fragment,l),jt=a(l),o(Is.$$.fragment,l),ut=a(l),$s=m(l,"P",{"data-svelte-h":!0}),u($s)!=="svelte-1vtl0ih"&&($s.textContent=Hn),wt=a(l),o(gs.$$.fragment,l),bt=a(l),o(Zs.$$.fragment,l),ft=a(l),ks=m(l,"P",{"data-svelte-h":!0}),u(ks)!=="svelte-ywudht"&&(ks.textContent=Sn),dt=a(l),_s=m(l,"P",{"data-svelte-h":!0}),u(_s)!=="svelte-1wccoha"&&(_s.textContent=Dn),ht=a(l),o(Gs.$$.fragment,l),Ct=a(l),xs=m(l,"P",{"data-svelte-h":!0}),u(xs)!=="svelte-187oeom"&&(xs.textContent=qn),It=a(l),o(Pl.$$.fragment,l),$t=a(l),o(Kl.$$.fragment,l),gt=a(l),Bs=m(l,"P",{"data-svelte-h":!0}),u(Bs)!=="svelte-i6kcj6"&&(Bs.textContent=Ln),Zt=a(l),o(Ws.$$.fragment,l),kt=a(l),Rs=m(l,"P",{"data-svelte-h":!0}),u(Rs)!=="svelte-wwpome"&&(Rs.textContent=Pn),_t=a(l),Xl.l(l),ve=a(l),Xs=m(l,"P",{"data-svelte-h":!0}),u(Xs)!=="svelte-fwam2l"&&(Xs.textContent=Kn),Gt=a(l),o(Vs.$$.fragment,l),xt=a(l),Ns=m(l,"P",{"data-svelte-h":!0}),u(Ns)!=="svelte-1ql90lx"&&(Ns.innerHTML=On),Bt=a(l),vs=m(l,"P",{"data-svelte-h":!0}),u(vs)!=="svelte-1od79f1"&&(vs.innerHTML=la),Wt=a(l),Nl.l(l),Qe=a(l),Qs=m(l,"P",{"data-svelte-h":!0}),u(Qs)!=="svelte-12bvzts"&&(Qs.textContent=sa),Rt=a(l),o(As.$$.fragment,l),Xt=a(l),o(Es.$$.fragment,l),Vt=a(l),zs=m(l,"P",{"data-svelte-h":!0}),u(zs)!=="svelte-89onln"&&(zs.innerHTML=ea),Nt=a(l),o(Ys.$$.fragment,l),vt=a(l),o(Fs.$$.fragment,l),Qt=a(l),Hs=m(l,"P",{"data-svelte-h":!0}),u(Hs)!=="svelte-15gu66n"&&(Hs.textContent=ta),At=a(l),o(Ss.$$.fragment,l),Et=a(l),o(Ds.$$.fragment,l),zt=a(l),qs=m(l,"P",{"data-svelte-h":!0}),u(qs)!=="svelte-j27xgx"&&(qs.textContent=na),Yt=a(l),o(Ls.$$.fragment,l),Ft=a(l),o(Ps.$$.fragment,l),Ht=a(l),Ql.l(l),Ae=a(l),o(Ks.$$.fragment,l),St=a(l),o(Os.$$.fragment,l),Dt=a(l),wl&&wl.l(l),Ee=a(l),le=m(l,"P",{"data-svelte-h":!0}),u(le)!=="svelte-58jiik"&&(le.innerHTML=aa),qt=a(l),se=m(l,"P",{"data-svelte-h":!0}),u(se)!=="svelte-17dypn9"&&(se.innerHTML=pa),Lt=a(l),o(ee.$$.fragment,l),Pt=a(l),te=m(l,"P",{"data-svelte-h":!0}),u(te)!=="svelte-1skeqz1"&&(te.innerHTML=Ma),Kt=a(l),o(ne.$$.fragment,l),Ot=a(l),ae=m(l,"P",{"data-svelte-h":!0}),u(ae)!=="svelte-7p5wpa"&&(ae.textContent=ra),ln=a(l),pe=m(l,"P",{"data-svelte-h":!0}),u(pe)!=="svelte-jokngj"&&(pe.textContent=ia),sn=a(l),o(Me.$$.fragment,l),en=a(l),o(re.$$.fragment,l),tn=a(l),ie=m(l,"P",{"data-svelte-h":!0}),u(ie)!=="svelte-1rxt198"&&(ie.innerHTML=ca),nn=a(l),o(ce.$$.fragment,l),an=a(l),o(ye.$$.fragment,l),pn=a(l),o(Je.$$.fragment,l),Mn=a(l),o(me.$$.fragment,l),rn=a(l),Te=m(l,"P",{"data-svelte-h":!0}),u(Te)!=="svelte-bq8n0g"&&(Te.textContent=ya),cn=a(l),El.l(l),ze=a(l),oe=m(l,"P",{"data-svelte-h":!0}),u(oe)!=="svelte-1b8shi1"&&(oe.textContent=Ja),yn=a(l),o(Ue.$$.fragment,l),Jn=a(l),je=m(l,"P",{"data-svelte-h":!0}),u(je)!=="svelte-hbhqu5"&&(je.textContent=ma),mn=a(l),o(ue.$$.fragment,l),Tn=a(l),we=m(l,"P",{"data-svelte-h":!0}),u(we)!=="svelte-kumw5c"&&(we.textContent=Ta),on=a(l),be=m(l,"P",{"data-svelte-h":!0}),u(be)!=="svelte-1v2mulv"&&(be.textContent=oa),Un=a(l),o(fe.$$.fragment,l),jn=a(l),Yl.l(l),Ye=a(l),pl&&pl.l(l),Fe=a(l),o(de.$$.fragment,l),un=a(l),he=m(l,"P",{"data-svelte-h":!0}),u(he)!=="svelte-1b6wyxe"&&(he.textContent=Ua),wn=a(l),o(Ce.$$.fragment,l),bn=a(l),o(Ie.$$.fragment,l),fn=a(l),$e=m(l,"P",{"data-svelte-h":!0}),u($e)!=="svelte-r76vze"&&($e.textContent=ja),dn=a(l),o(ge.$$.fragment,l),hn=a(l),o(Ze.$$.fragment,l),Cn=a(l),ke=m(l,"P",{"data-svelte-h":!0}),u(ke)!=="svelte-mqc9or"&&(ke.textContent=ua),In=a(l),o(Ol.$$.fragment,l),$n=a(l),o(_e.$$.fragment,l),gn=a(l),He=m(l,"P",{}),Xn(He).forEach(s),this.h()},h(){$l(p,"name","hf:doc:metadata"),$l(p,"content",Up),Va(R.src,Ml="https://course-demos-marian-finetuned-kde4-en-to-fr.hf.space")||$l(R,"src",Ml),$l(R,"frameborder","0"),$l(R,"height","350"),$l(R,"title","Gradio app"),$l(R,"class","block dark:hidden container p-0 flex-grow space-iframe"),$l(R,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),$l(R,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),$l(V,"class","flex justify-center"),$l(V,"href","/huggingface-course/marian-finetuned-kde4-en-to-fr"),Va(z.src,Gl="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/language_tags.png")||$l(z,"src",Gl),$l(z,"alt","Language available for the KDE4 dataset."),$l(z,"width","100%")},m(l,t){Ha(document.head,p),e(l,d,t),e(l,r,t),e(l,f,t),U(Z,l,t),e(l,w,t),U(_,l,t),e(l,G,t),Ge[x].m(l,t),e(l,C,t),e(l,W,t),e(l,Tl,t),e(l,Q,t),e(l,L,t),U(N,l,t),e(l,ol,t),e(l,A,t),e(l,P,t),e(l,v,t),e(l,K,t),e(l,X,t),e(l,E,t),e(l,R,t),e(l,sl,t),e(l,V,t),e(l,B,t),e(l,el,t),e(l,yl,t),U(rl,l,t),e(l,bl,t),e(l,H,t),e(l,fl,t),U(S,l,t),e(l,dl,t),e(l,D,t),e(l,Jl,t),U(il,l,t),e(l,hl,t),e(l,q,t),e(l,Cl,t),e(l,z,t),e(l,tl,t),e(l,Zl,t),e(l,nl,t),U(jl,l,t),e(l,ml,t),U(cl,l,t),e(l,Bl,t),e(l,al,t),e(l,Il,t),U(i,l,t),e(l,$,t),U(ul,l,t),e(l,ss,t),e(l,Wl,t),e(l,I,t),U(es,l,t),e(l,Se,t),e(l,ts,t),e(l,De,t),U(ns,l,t),e(l,qe,t),U(as,l,t),e(l,Le,t),e(l,ps,t),e(l,Pe,t),U(Ms,l,t),e(l,Ke,t),U(rs,l,t),e(l,Oe,t),e(l,is,t),e(l,lt,t),U(cs,l,t),e(l,st,t),U(ys,l,t),e(l,et,t),e(l,Js,t),e(l,tt,t),U(ms,l,t),e(l,nt,t),U(Ts,l,t),e(l,at,t),e(l,os,t),e(l,pt,t),U(Us,l,t),e(l,Mt,t),U(ql,l,t),e(l,rt,t),U(js,l,t),e(l,it,t),U(us,l,t),e(l,ct,t),e(l,ws,t),e(l,yt,t),U(bs,l,t),e(l,Jt,t),e(l,fs,t),e(l,mt,t),U(Ll,l,t),e(l,Tt,t),e(l,ds,t),e(l,ot,t),e(l,hs,t),e(l,Ut,t),U(Cs,l,t),e(l,jt,t),U(Is,l,t),e(l,ut,t),e(l,$s,t),e(l,wt,t),U(gs,l,t),e(l,bt,t),U(Zs,l,t),e(l,ft,t),e(l,ks,t),e(l,dt,t),e(l,_s,t),e(l,ht,t),U(Gs,l,t),e(l,Ct,t),e(l,xs,t),e(l,It,t),U(Pl,l,t),e(l,$t,t),U(Kl,l,t),e(l,gt,t),e(l,Bs,t),e(l,Zt,t),U(Ws,l,t),e(l,kt,t),e(l,Rs,t),e(l,_t,t),xe[Rl].m(l,t),e(l,ve,t),e(l,Xs,t),e(l,Gt,t),U(Vs,l,t),e(l,xt,t),e(l,Ns,t),e(l,Bt,t),e(l,vs,t),e(l,Wt,t),Be[Vl].m(l,t),e(l,Qe,t),e(l,Qs,t),e(l,Rt,t),U(As,l,t),e(l,Xt,t),U(Es,l,t),e(l,Vt,t),e(l,zs,t),e(l,Nt,t),U(Ys,l,t),e(l,vt,t),U(Fs,l,t),e(l,Qt,t),e(l,Hs,t),e(l,At,t),U(Ss,l,t),e(l,Et,t),U(Ds,l,t),e(l,zt,t),e(l,qs,t),e(l,Yt,t),U(Ls,l,t),e(l,Ft,t),U(Ps,l,t),e(l,Ht,t),We[vl].m(l,t),e(l,Ae,t),U(Ks,l,t),e(l,St,t),U(Os,l,t),e(l,Dt,t),wl&&wl.m(l,t),e(l,Ee,t),e(l,le,t),e(l,qt,t),e(l,se,t),e(l,Lt,t),U(ee,l,t),e(l,Pt,t),e(l,te,t),e(l,Kt,t),U(ne,l,t),e(l,Ot,t),e(l,ae,t),e(l,ln,t),e(l,pe,t),e(l,sn,t),U(Me,l,t),e(l,en,t),U(re,l,t),e(l,tn,t),e(l,ie,t),e(l,nn,t),U(ce,l,t),e(l,an,t),U(ye,l,t),e(l,pn,t),U(Je,l,t),e(l,Mn,t),U(me,l,t),e(l,rn,t),e(l,Te,t),e(l,cn,t),Re[Al].m(l,t),e(l,ze,t),e(l,oe,t),e(l,yn,t),U(Ue,l,t),e(l,Jn,t),e(l,je,t),e(l,mn,t),U(ue,l,t),e(l,Tn,t),e(l,we,t),e(l,on,t),e(l,be,t),e(l,Un,t),U(fe,l,t),e(l,jn,t),Xe[zl].m(l,t),e(l,Ye,t),pl&&pl.m(l,t),e(l,Fe,t),U(de,l,t),e(l,un,t),e(l,he,t),e(l,wn,t),U(Ce,l,t),e(l,bn,t),U(Ie,l,t),e(l,fn,t),e(l,$e,t),e(l,dn,t),U(ge,l,t),e(l,hn,t),U(Ze,l,t),e(l,Cn,t),e(l,ke,t),e(l,In,t),U(Ol,l,t),e(l,$n,t),U(_e,l,t),e(l,gn,t),e(l,He,t),Zn=!0},p(l,[t]){const Ga={};t&1&&(Ga.fw=l[0]),Z.$set(Ga);let _n=x;x=ba(l),x!==_n&&(Ne(),y(Ge[_n],1,1,()=>{Ge[_n]=null}),Ve(),g=Ge[x],g||(g=Ge[x]=wa[x](l),g.c()),c(g,1),g.m(C.parentNode,C));const xa={};t&2&&(xa.$$scope={dirty:t,ctx:l}),ql.$set(xa);const Ba={};t&2&&(Ba.$$scope={dirty:t,ctx:l}),Ll.$set(Ba);const Wa={};t&2&&(Wa.$$scope={dirty:t,ctx:l}),Pl.$set(Wa);const Ra={};t&2&&(Ra.$$scope={dirty:t,ctx:l}),Kl.$set(Ra);let Gn=Rl;Rl=da(l),Rl!==Gn&&(Ne(),y(xe[Gn],1,1,()=>{xe[Gn]=null}),Ve(),Xl=xe[Rl],Xl||(Xl=xe[Rl]=fa[Rl](l),Xl.c()),c(Xl,1),Xl.m(ve.parentNode,ve));let xn=Vl;Vl=Ca(l),Vl!==xn&&(Ne(),y(Be[xn],1,1,()=>{Be[xn]=null}),Ve(),Nl=Be[Vl],Nl||(Nl=Be[Vl]=ha[Vl](l),Nl.c()),c(Nl,1),Nl.m(Qe.parentNode,Qe));let Bn=vl;vl=$a(l),vl!==Bn&&(Ne(),y(We[Bn],1,1,()=>{We[Bn]=null}),Ve(),Ql=We[vl],Ql||(Ql=We[vl]=Ia[vl](l),Ql.c()),c(Ql,1),Ql.m(Ae.parentNode,Ae)),l[0]==="pt"?wl||(wl=Na(),wl.c(),wl.m(Ee.parentNode,Ee)):wl&&(wl.d(1),wl=null);let Wn=Al;Al=Za(l),Al!==Wn&&(Ne(),y(Re[Wn],1,1,()=>{Re[Wn]=null}),Ve(),El=Re[Al],El||(El=Re[Al]=ga[Al](l),El.c()),c(El,1),El.m(ze.parentNode,ze));let Rn=zl;zl=_a(l),zl!==Rn&&(Ne(),y(Xe[Rn],1,1,()=>{Xe[Rn]=null}),Ve(),Yl=Xe[zl],Yl||(Yl=Xe[zl]=ka[zl](l),Yl.c()),c(Yl,1),Yl.m(Ye.parentNode,Ye)),l[0]==="pt"?pl?t&1&&c(pl,1):(pl=va(),pl.c(),c(pl,1),pl.m(Fe.parentNode,Fe)):pl&&(Ne(),y(pl,1,1,()=>{pl=null}),Ve());const Xa={};t&2&&(Xa.$$scope={dirty:t,ctx:l}),Ol.$set(Xa)},i(l){Zn||(c(Z.$$.fragment,l),c(_.$$.fragment,l),c(g),c(N.$$.fragment,l),c(rl.$$.fragment,l),c(S.$$.fragment,l),c(il.$$.fragment,l),c(jl.$$.fragment,l),c(cl.$$.fragment,l),c(i.$$.fragment,l),c(ul.$$.fragment,l),c(es.$$.fragment,l),c(ns.$$.fragment,l),c(as.$$.fragment,l),c(Ms.$$.fragment,l),c(rs.$$.fragment,l),c(cs.$$.fragment,l),c(ys.$$.fragment,l),c(ms.$$.fragment,l),c(Ts.$$.fragment,l),c(Us.$$.fragment,l),c(ql.$$.fragment,l),c(js.$$.fragment,l),c(us.$$.fragment,l),c(bs.$$.fragment,l),c(Ll.$$.fragment,l),c(Cs.$$.fragment,l),c(Is.$$.fragment,l),c(gs.$$.fragment,l),c(Zs.$$.fragment,l),c(Gs.$$.fragment,l),c(Pl.$$.fragment,l),c(Kl.$$.fragment,l),c(Ws.$$.fragment,l),c(Xl),c(Vs.$$.fragment,l),c(Nl),c(As.$$.fragment,l),c(Es.$$.fragment,l),c(Ys.$$.fragment,l),c(Fs.$$.fragment,l),c(Ss.$$.fragment,l),c(Ds.$$.fragment,l),c(Ls.$$.fragment,l),c(Ps.$$.fragment,l),c(Ql),c(Ks.$$.fragment,l),c(Os.$$.fragment,l),c(ee.$$.fragment,l),c(ne.$$.fragment,l),c(Me.$$.fragment,l),c(re.$$.fragment,l),c(ce.$$.fragment,l),c(ye.$$.fragment,l),c(Je.$$.fragment,l),c(me.$$.fragment,l),c(El),c(Ue.$$.fragment,l),c(ue.$$.fragment,l),c(fe.$$.fragment,l),c(Yl),c(pl),c(de.$$.fragment,l),c(Ce.$$.fragment,l),c(Ie.$$.fragment,l),c(ge.$$.fragment,l),c(Ze.$$.fragment,l),c(Ol.$$.fragment,l),c(_e.$$.fragment,l),Zn=!0)},o(l){y(Z.$$.fragment,l),y(_.$$.fragment,l),y(g),y(N.$$.fragment,l),y(rl.$$.fragment,l),y(S.$$.fragment,l),y(il.$$.fragment,l),y(jl.$$.fragment,l),y(cl.$$.fragment,l),y(i.$$.fragment,l),y(ul.$$.fragment,l),y(es.$$.fragment,l),y(ns.$$.fragment,l),y(as.$$.fragment,l),y(Ms.$$.fragment,l),y(rs.$$.fragment,l),y(cs.$$.fragment,l),y(ys.$$.fragment,l),y(ms.$$.fragment,l),y(Ts.$$.fragment,l),y(Us.$$.fragment,l),y(ql.$$.fragment,l),y(js.$$.fragment,l),y(us.$$.fragment,l),y(bs.$$.fragment,l),y(Ll.$$.fragment,l),y(Cs.$$.fragment,l),y(Is.$$.fragment,l),y(gs.$$.fragment,l),y(Zs.$$.fragment,l),y(Gs.$$.fragment,l),y(Pl.$$.fragment,l),y(Kl.$$.fragment,l),y(Ws.$$.fragment,l),y(Xl),y(Vs.$$.fragment,l),y(Nl),y(As.$$.fragment,l),y(Es.$$.fragment,l),y(Ys.$$.fragment,l),y(Fs.$$.fragment,l),y(Ss.$$.fragment,l),y(Ds.$$.fragment,l),y(Ls.$$.fragment,l),y(Ps.$$.fragment,l),y(Ql),y(Ks.$$.fragment,l),y(Os.$$.fragment,l),y(ee.$$.fragment,l),y(ne.$$.fragment,l),y(Me.$$.fragment,l),y(re.$$.fragment,l),y(ce.$$.fragment,l),y(ye.$$.fragment,l),y(Je.$$.fragment,l),y(me.$$.fragment,l),y(El),y(Ue.$$.fragment,l),y(ue.$$.fragment,l),y(fe.$$.fragment,l),y(Yl),y(pl),y(de.$$.fragment,l),y(Ce.$$.fragment,l),y(Ie.$$.fragment,l),y(ge.$$.fragment,l),y(Ze.$$.fragment,l),y(Ol.$$.fragment,l),y(_e.$$.fragment,l),Zn=!1},d(l){l&&(s(d),s(r),s(f),s(w),s(G),s(C),s(W),s(Tl),s(Q),s(L),s(ol),s(A),s(P),s(v),s(K),s(X),s(E),s(R),s(sl),s(V),s(B),s(el),s(yl),s(bl),s(H),s(fl),s(dl),s(D),s(Jl),s(hl),s(q),s(Cl),s(z),s(tl),s(Zl),s(nl),s(ml),s(Bl),s(al),s(Il),s($),s(ss),s(Wl),s(I),s(Se),s(ts),s(De),s(qe),s(Le),s(ps),s(Pe),s(Ke),s(Oe),s(is),s(lt),s(st),s(et),s(Js),s(tt),s(nt),s(at),s(os),s(pt),s(Mt),s(rt),s(it),s(ct),s(ws),s(yt),s(Jt),s(fs),s(mt),s(Tt),s(ds),s(ot),s(hs),s(Ut),s(jt),s(ut),s($s),s(wt),s(bt),s(ft),s(ks),s(dt),s(_s),s(ht),s(Ct),s(xs),s(It),s($t),s(gt),s(Bs),s(Zt),s(kt),s(Rs),s(_t),s(ve),s(Xs),s(Gt),s(xt),s(Ns),s(Bt),s(vs),s(Wt),s(Qe),s(Qs),s(Rt),s(Xt),s(Vt),s(zs),s(Nt),s(vt),s(Qt),s(Hs),s(At),s(Et),s(zt),s(qs),s(Yt),s(Ft),s(Ht),s(Ae),s(St),s(Dt),s(Ee),s(le),s(qt),s(se),s(Lt),s(Pt),s(te),s(Kt),s(Ot),s(ae),s(ln),s(pe),s(sn),s(en),s(tn),s(ie),s(nn),s(an),s(pn),s(Mn),s(rn),s(Te),s(cn),s(ze),s(oe),s(yn),s(Jn),s(je),s(mn),s(Tn),s(we),s(on),s(be),s(Un),s(jn),s(Ye),s(Fe),s(un),s(he),s(wn),s(bn),s(fn),s($e),s(dn),s(hn),s(Cn),s(ke),s(In),s($n),s(gn),s(He)),s(p),j(Z,l),j(_,l),Ge[x].d(l),j(N,l),j(rl,l),j(S,l),j(il,l),j(jl,l),j(cl,l),j(i,l),j(ul,l),j(es,l),j(ns,l),j(as,l),j(Ms,l),j(rs,l),j(cs,l),j(ys,l),j(ms,l),j(Ts,l),j(Us,l),j(ql,l),j(js,l),j(us,l),j(bs,l),j(Ll,l),j(Cs,l),j(Is,l),j(gs,l),j(Zs,l),j(Gs,l),j(Pl,l),j(Kl,l),j(Ws,l),xe[Rl].d(l),j(Vs,l),Be[Vl].d(l),j(As,l),j(Es,l),j(Ys,l),j(Fs,l),j(Ss,l),j(Ds,l),j(Ls,l),j(Ps,l),We[vl].d(l),j(Ks,l),j(Os,l),wl&&wl.d(l),j(ee,l),j(ne,l),j(Me,l),j(re,l),j(ce,l),j(ye,l),j(Je,l),j(me,l),Re[Al].d(l),j(Ue,l),j(ue,l),j(fe,l),Xe[zl].d(l),pl&&pl.d(l),j(de,l),j(Ce,l),j(Ie,l),j(ge,l),j(Ze,l),j(Ol,l),j(_e,l)}}}const Up='{"title":"翻译","local":"翻译","sections":[{"title":"准备数据","local":"准备数据","sections":[{"title":"KDE4 数据集","local":"KDE4 数据集","sections":[],"depth":3},{"title":"处理数据","local":"处理数据","sections":[],"depth":3}],"depth":2},{"title":"使用 Trainer API 微调模型","local":"使用 Trainer API 微调模型","sections":[],"depth":2},{"title":"使用 Keras 微调模型","local":"使用 Keras 微调模型","sections":[{"title":"数据整理","local":"数据整理","sections":[],"depth":3},{"title":"评估指标","local":"评估指标","sections":[],"depth":3},{"title":"微调模型","local":"微调模型","sections":[],"depth":3}],"depth":2},{"title":"自定义训练循环","local":"自定义训练循环","sections":[{"title":"准备训练所需的一切","local":"准备训练所需的一切","sections":[],"depth":3},{"title":"训练循环","local":"训练循环","sections":[],"depth":3}],"depth":2},{"title":"使用微调后的模型","local":"使用微调后的模型","sections":[],"depth":2}],"depth":1}';function jp(k,p,d){let r="pt";return Ea(()=>{const f=new URLSearchParams(window.location.search);d(0,r=f.get("fw")||"pt")}),[r]}class $p extends za{constructor(p){super(),Ya(this,p,jp,op,Aa,{})}}export{$p as component};
