import{s as ep,a as Sn,o as sp,n as Yl}from"../chunks/scheduler.cc52f4b9.js";import{S as tp,i as np,e as J,s as n,c as o,h as ap,a as m,d as e,b as a,f as vn,g as T,j,k as sl,l as pp,m as s,n as U,o as y,u as zs,t as c,p as u,v as As}from"../chunks/index.9480bb2b.js";import{T as le}from"../chunks/Tip.f7b80743.js";import{C as Mp,H as kl,E as rp}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.52103c90.js";import{Y as Qn}from"../chunks/Youtube.7b12d9e8.js";import{C as h}from"../chunks/CodeBlock.c5404643.js";import{D as lp}from"../chunks/DocNotebookDropdown.ea74f0e0.js";import{F as ip}from"../chunks/FrameworkSwitchCourse.42d12053.js";function cp(_){let p,b;return p=new lp({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(){o(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,d){U(p,r,d),b=!0},i(r){b||(c(p.$$.fragment,r),b=!0)},o(r){y(p.$$.fragment,r),b=!1},d(r){u(p,r)}}}function yp(_){let p,b;return p=new lp({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(){o(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,d){U(p,r,d),b=!0},i(r){b||(c(p.$$.fragment,r),b=!0)},o(r){y(p.$$.fragment,r),b=!1},d(r){u(p,r)}}}function Jp(_){let p,b="✏️ <strong>輪到你了！</strong> 另一個在法語中經常使用的英語單詞是“email”。在訓練數據集中找到使用這個詞的第一個樣本。它是如何翻譯的？預訓練模型如何翻譯同一個英文句子？";return{c(){p=J("p"),p.innerHTML=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-g5tv86"&&(p.innerHTML=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function mp(_){let p,b="💡 如果正在使用mart、mBART-50或M2 M100等多語言標記器，則需要在tokenizer中設置tokenizer.src_lang和tokenizer.tgt_lang為正確的輸入和目標的語言代碼。";return{c(){p=J("p"),p.textContent=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-c7m1hm"&&(p.textContent=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function op(_){let p,b="💡如果你使用的是T5模型(更具體地說，是T5 -xxx檢查點之一)，模型將需要文本輸入有一個前綴來表示正在進行的任務，例如從英語到法語的翻譯";return{c(){p=J("p"),p.textContent=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1c965r1"&&(p.textContent=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function Tp(_){let p,b="⚠️ 我們不關注目標的注意力掩碼，因為模型不會需要它。相反，對應於填充標記的標籤應設置為-100，以便在loss計算中忽略它們。這將在稍後由我們的數據整理器完成，因為我們正在應用動態填充，但是如果您在此處使用填充，您應該調整預處理函數以將與填充標記對應的所有標籤設置為 -100。";return{c(){p=J("p"),p.textContent=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1b09f80"&&(p.textContent=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function Up(_){let p,b,r,d="首先，我們需要一個實際的模型來進行微調。 我們將使用通常的 <code>AutoModel</code> API：",g,w,G,x,W;return p=new kl({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}}),x=new le({props:{warning:!1,$$slots:{default:[jp]},$$scope:{ctx:_}}}),{c(){o(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,g=n(),o(w.$$.fragment),G=n(),o(x.$$.fragment)},l(Z){T(p.$$.fragment,Z),b=a(Z),r=m(Z,"P",{"data-svelte-h":!0}),j(r)!=="svelte-7cd7gl"&&(r.innerHTML=d),g=a(Z),T(w.$$.fragment,Z),G=a(Z),T(x.$$.fragment,Z)},m(Z,C){U(p,Z,C),s(Z,b,C),s(Z,r,C),s(Z,g,C),U(w,Z,C),s(Z,G,C),U(x,Z,C),W=!0},i(Z){W||(c(p.$$.fragment,Z),c(w.$$.fragment,Z),c(x.$$.fragment,Z),W=!0)},o(Z){y(p.$$.fragment,Z),y(w.$$.fragment,Z),y(x.$$.fragment,Z),W=!1},d(Z){Z&&(e(b),e(r),e(g),e(G)),u(p,Z),u(w,Z),u(x,Z)}}}function up(_){let p,b,r,d='使用 <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> 方法來預測輸入的輸出。 當我們討論評估指標時，我們將更詳細地探討這一點。',g,w,G="首先，我們需要一個實際的模型來進行微調。 我們將使用通常的 <code>AutoModel</code> API：",x,W,Z;return p=new kl({props:{title:"使用 Trainer API 微調模型",local:"使用-trainer-api-微調模型",headingTag:"h2"}}),W=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(){o(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,g=n(),w=J("p"),w.innerHTML=G,x=n(),o(W.$$.fragment)},l(C){T(p.$$.fragment,C),b=a(C),r=m(C,"P",{"data-svelte-h":!0}),j(r)!=="svelte-1b0v66z"&&(r.innerHTML=d),g=a(C),w=m(C,"P",{"data-svelte-h":!0}),j(w)!=="svelte-7cd7gl"&&(w.innerHTML=G),x=a(C),T(W.$$.fragment,C)},m(C,B){U(p,C,B),s(C,b,B),s(C,r,B),s(C,g,B),s(C,w,B),s(C,x,B),U(W,C,B),Z=!0},i(C){Z||(c(p.$$.fragment,C),c(W.$$.fragment,C),Z=!0)},o(C){y(p.$$.fragment,C),y(W.$$.fragment,C),Z=!1},d(C){C&&(e(b),e(r),e(g),e(w),e(x)),u(p,C),u(W,C)}}}function jp(_){let p,b="💡 <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=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-wbomyv"&&(p.innerHTML=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function wp(_){let p,b;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(){o(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,d){U(p,r,d),b=!0},i(r){b||(c(p.$$.fragment,r),b=!0)},o(r){y(p.$$.fragment,r),b=!1},d(r){u(p,r)}}}function fp(_){let p,b;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(){o(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,d){U(p,r,d),b=!0},i(r){b||(c(p.$$.fragment,r),b=!0)},o(r){y(p.$$.fragment,r),b=!1},d(r){u(p,r)}}}function dp(_){let p,b="我們現在可以使用 <code>data_collator</code> 將我們的每個數據集轉換為 <code>tf.data.Dataset</code>，準備好進行訓練：",r,d,g;return d=new h({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QzMiUyQyUwQSklMEF0Zl9ldmFsX2RhdGFzZXQlMjAlM0QlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEEp",highlighted:`tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].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">True</span>,
    batch_size=<span class="hljs-number">32</span>,
)
tf_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].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">16</span>,
)`,wrap:!1}}),{c(){p=J("p"),p.innerHTML=b,r=n(),o(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-ymdrgq"&&(p.innerHTML=b),r=a(w),T(d.$$.fragment,w)},m(w,G){s(w,p,G),s(w,r,G),U(d,w,G),g=!0},i(w){g||(c(d.$$.fragment,w),g=!0)},o(w){y(d.$$.fragment,w),g=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function bp(_){let p,b="我們將把這個 <code>data_collator</code> 傳遞給 <code>Seq2SeqTrainer</code>。 接下來，讓我們看一下評估指標。";return{c(){p=J("p"),p.innerHTML=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-tnr95g"&&(p.innerHTML=b)},m(r,d){s(r,p,d)},i:Yl,o:Yl,d(r){r&&e(p)}}}function Ka(_){let p,b="<code>Seq2SeqTrainer</code> 添加到其超類 <code>Trainer</code> 的功能是在評估或預測期間使用 <code>generate()</code> 方法的能力。 在訓練期間，模型將使用帶有注意掩碼的“decoder_input_ids”，以確保它不使用預測的標記之後的標記，以加快訓練速度。 在推理過程中，我們將無法使用預測的標記之後的標記，因為我們沒有標籤，因此使用相同的設置使用帶有注意掩碼的“decoder_input_ids”，評估我們的模型是個好主意。",r,d,g='正如我們在<a href="/course/chapter1/6">第一章</a>看到的，解碼器通過一個一個地預測標記來執行推理——這是🤗 Transformers 在幕後通過 <strong>generate()</strong> 方法實現的。如果我們設置 predict_with_generate=True，Seq2 Seq Trainer 將允許我們使用該方法進行評估。';return{c(){p=J("p"),p.innerHTML=b,r=n(),d=J("p"),d.innerHTML=g},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-fftw5d"&&(p.innerHTML=b),r=a(w),d=m(w,"P",{"data-svelte-h":!0}),j(d)!=="svelte-es2xe9"&&(d.innerHTML=g)},m(w,G){s(w,p,G),s(w,r,G),s(w,d,G)},d(w){w&&(e(p),e(r),e(d))}}}function hp(_){let p,b="為了從模型輸出到度量可以使用的文本，我們將使用 <code>tokenizer.batch_decode()</code> 方法。 我們只需要清理標籤中的所有 <code>-100</code>（標記器將自動對填充標記執行相同操作）：",r,d,g;return d=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=b,r=n(),o(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-qycu9"&&(p.innerHTML=b),r=a(w),T(d.$$.fragment,w)},m(w,G){s(w,p,G),s(w,r,G),U(d,w,G),g=!0},i(w){g||(c(d.$$.fragment,w),g=!0)},o(w){y(d.$$.fragment,w),g=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function Cp(_){let p,b="為了從模型輸出可以被評估基準可以使用的文本，我們將使用 <strong>tokenizer.batch_decode()</strong> 方法。我們只需要清理標籤中所有 <strong>-100</strong> （標記器會自動為填充標記做同樣的事情）：",r,d,g;return d=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKCklM0ElMEElMjAlMjAlMjAlMjBhbGxfcHJlZHMlMjAlM0QlMjAlNUIlNUQlMEElMjAlMjAlMjAlMjBhbGxfbGFiZWxzJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwc2FtcGxlZF9kYXRhc2V0JTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RC5zaHVmZmxlKCkuc2VsZWN0KHJhbmdlKDIwMCkpJTBBJTIwJTIwJTIwJTIwdGZfZ2VuZXJhdGVfZGF0YXNldCUyMCUzRCUyMHNhbXBsZWRfZGF0YXNldC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUyMCUyMmxhYmVscyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDQlMkMlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZm9yJTIwYmF0Y2glMjBpbiUyMHRmX2dlbmVyYXRlX2RhdGFzZXQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlucHV0X2lkcyUzRGJhdGNoJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTJDJTIwYXR0ZW50aW9uX21hc2slM0RiYXRjaCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKHByZWRpY3Rpb25zJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwYmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQubnVtcHkoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUobGFiZWxzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMCU1QnByZWQuc3RyaXAoKSUyMGZvciUyMHByZWQlMjBpbiUyMGRlY29kZWRfcHJlZHMlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMCU1QiU1QmxhYmVsLnN0cmlwKCklNUQlMjBmb3IlMjBsYWJlbCUyMGluJTIwZGVjb2RlZF9sYWJlbHMlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfcHJlZHMuZXh0ZW5kKGRlY29kZWRfcHJlZHMpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWxsX2xhYmVscy5leHRlbmQoZGVjb2RlZF9sYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RhbGxfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEYWxsX2xhYmVscyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMjJibGV1JTIyJTNBJTIwcmVzdWx0JTVCJTIyc2NvcmUlMjIlNUQlN0Q=",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>():
    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 <span class="hljs-keyword">in</span> tf_generate_dataset:
        predictions = 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>]
        )
        decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
        labels = batch[<span class="hljs-string">&quot;labels&quot;</span>].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=b,r=n(),o(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-199mhtm"&&(p.innerHTML=b),r=a(w),T(d.$$.fragment,w)},m(w,G){s(w,p,G),s(w,r,G),U(d,w,G),g=!0},i(w){g||(c(d.$$.fragment,w),g=!0)},o(w){y(d.$$.fragment,w),g=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function Ip(_){let p,b="一旦完成，我們就可以定義我們的 <code>Seq2SeqTrainingArguments</code>。 與 <code>Trainer</code> 一樣，我們使用 <code>TrainingArguments</code> 的子類，其中包含更多可以設置的字段：",r,d,g,w,G="除了通常的超參數（如學習率、訓練輪數、批次大小和一些權重衰減）之外，與我們在前幾節中看到的相比，這裡有一些變化：",x,W,Z="<li>我們沒有設置任何定期評估，因為評估需要耗費一定的時間；我們只會在訓練開始之前和結束之後評估我們的模型一次。</li> <li>我們設置fp16=True，這可以加快支持fp16的 GPU 上的訓練速度。</li> <li>和上面我們討論的那樣，我們設置predict_with_generate=True</li> <li>我們用push_to_hub=True在每個 epoch 結束時將模型上傳到 Hub。</li>",C,B,V='請注意，您可以使用 <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>。',Ml,tl,N,v,ll="最後，我們需要將所有內容傳遞給 <strong>Seq2SeqTrainer</strong> ：",Ul,Q,z,A,el="在訓練之前，我們將首先查看我們的模型獲得的分數，以仔細檢查我們的微調沒有讓事情變得更糟。此命令需要一些時間，因此您可以在執行時喝杯咖啡：",ul,E,H,K,X,rl,nl="BLEU的分數還不錯，這反映了我們的模型已經擅長將英語句子翻譯成法語句子。",R,al,f="接下來是訓練，這也需要一些時間：",k,jl,Jl,O,_l="請注意，當訓練發生時，每次保存模型時（這裡是每個時期），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",dl,F,Fl="訓練完成後，我們再次評估我們的模型——希望我們會看到 BLEU 分數有所改善！",bl,S,hl,q,zl,ml,il="這是近 14 點的改進，這很棒。",Cl,D,Sl="最後，我們使用 <strong>push_to_hub()</strong> 方法來確保我們上傳模型的最新版本。這 <strong>Trainer</strong> 還創建了一張包含所有評估結果的模型卡並上傳。此模型卡包含可幫助模型中心為推理演示選擇小部件的元數據。通常不需要做額外的更改，因為它可以從模型類中推斷出正確的小部件，但在這種情況下，相同的模型類可以用於所有類型的序列到序列問題，所以我們指定它是一個翻譯模型：",Il,L,$l,P,ql="如果您想檢查命令執行的結果，此命令將返回它剛剛執行的提交的 URL，可以打開url進行檢查：",gl,Y,Al,ol,cl="在此階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。您已成功微調翻譯任務的模型 - 恭喜！",El,Tl,yl="如果您想更深入地瞭解訓練循環，我們現在將向您展示如何使用 🤗 Accelerate 做同樣的事情。",Zl;return d=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}}),tl=new le({props:{$$slots:{default:[gp]},$$scope:{ctx:_}}}),Q=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}}),E=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X3RhcmdldF9sZW5ndGgp",highlighted:"trainer.evaluate(max_length=max_target_length)",wrap:!1}}),K=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}}),jl=new h({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),S=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X3RhcmdldF9sZW5ndGgp",highlighted:"trainer.evaluate(max_length=max_target_length)",wrap:!1}}),q=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}}),L=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}}),Y=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=b,r=n(),o(d.$$.fragment),g=n(),w=J("p"),w.textContent=G,x=n(),W=J("ul"),W.innerHTML=Z,C=n(),B=J("p"),B.innerHTML=V,Ml=n(),o(tl.$$.fragment),N=n(),v=J("p"),v.innerHTML=ll,Ul=n(),o(Q.$$.fragment),z=n(),A=J("p"),A.textContent=el,ul=n(),o(E.$$.fragment),H=n(),o(K.$$.fragment),X=n(),rl=J("p"),rl.textContent=nl,R=n(),al=J("p"),al.textContent=f,k=n(),o(jl.$$.fragment),Jl=n(),O=J("p"),O.textContent=_l,dl=n(),F=J("p"),F.textContent=Fl,bl=n(),o(S.$$.fragment),hl=n(),o(q.$$.fragment),zl=n(),ml=J("p"),ml.textContent=il,Cl=n(),D=J("p"),D.innerHTML=Sl,Il=n(),o(L.$$.fragment),$l=n(),P=J("p"),P.textContent=ql,gl=n(),o(Y.$$.fragment),Al=n(),ol=J("p"),ol.textContent=cl,El=n(),Tl=J("p"),Tl.textContent=yl},l(i){p=m(i,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1omuxw1"&&(p.innerHTML=b),r=a(i),T(d.$$.fragment,i),g=a(i),w=m(i,"P",{"data-svelte-h":!0}),j(w)!=="svelte-ote8hl"&&(w.textContent=G),x=a(i),W=m(i,"UL",{"data-svelte-h":!0}),j(W)!=="svelte-636x0w"&&(W.innerHTML=Z),C=a(i),B=m(i,"P",{"data-svelte-h":!0}),j(B)!=="svelte-j1rmx5"&&(B.innerHTML=V),Ml=a(i),T(tl.$$.fragment,i),N=a(i),v=m(i,"P",{"data-svelte-h":!0}),j(v)!=="svelte-1lrs60s"&&(v.innerHTML=ll),Ul=a(i),T(Q.$$.fragment,i),z=a(i),A=m(i,"P",{"data-svelte-h":!0}),j(A)!=="svelte-16xy9m0"&&(A.textContent=el),ul=a(i),T(E.$$.fragment,i),H=a(i),T(K.$$.fragment,i),X=a(i),rl=m(i,"P",{"data-svelte-h":!0}),j(rl)!=="svelte-e5x4k4"&&(rl.textContent=nl),R=a(i),al=m(i,"P",{"data-svelte-h":!0}),j(al)!=="svelte-1gqyllf"&&(al.textContent=f),k=a(i),T(jl.$$.fragment,i),Jl=a(i),O=m(i,"P",{"data-svelte-h":!0}),j(O)!=="svelte-1jqup3e"&&(O.textContent=_l),dl=a(i),F=m(i,"P",{"data-svelte-h":!0}),j(F)!=="svelte-9aj88c"&&(F.textContent=Fl),bl=a(i),T(S.$$.fragment,i),hl=a(i),T(q.$$.fragment,i),zl=a(i),ml=m(i,"P",{"data-svelte-h":!0}),j(ml)!=="svelte-e9lkmq"&&(ml.textContent=il),Cl=a(i),D=m(i,"P",{"data-svelte-h":!0}),j(D)!=="svelte-1n6mjia"&&(D.innerHTML=Sl),Il=a(i),T(L.$$.fragment,i),$l=a(i),P=m(i,"P",{"data-svelte-h":!0}),j(P)!=="svelte-1i1ov13"&&(P.textContent=ql),gl=a(i),T(Y.$$.fragment,i),Al=a(i),ol=m(i,"P",{"data-svelte-h":!0}),j(ol)!=="svelte-ldmk0i"&&(ol.textContent=cl),El=a(i),Tl=m(i,"P",{"data-svelte-h":!0}),j(Tl)!=="svelte-1a0w12w"&&(Tl.textContent=yl)},m(i,$){s(i,p,$),s(i,r,$),U(d,i,$),s(i,g,$),s(i,w,$),s(i,x,$),s(i,W,$),s(i,C,$),s(i,B,$),s(i,Ml,$),U(tl,i,$),s(i,N,$),s(i,v,$),s(i,Ul,$),U(Q,i,$),s(i,z,$),s(i,A,$),s(i,ul,$),U(E,i,$),s(i,H,$),U(K,i,$),s(i,X,$),s(i,rl,$),s(i,R,$),s(i,al,$),s(i,k,$),U(jl,i,$),s(i,Jl,$),s(i,O,$),s(i,dl,$),s(i,F,$),s(i,bl,$),U(S,i,$),s(i,hl,$),U(q,i,$),s(i,zl,$),s(i,ml,$),s(i,Cl,$),s(i,D,$),s(i,Il,$),U(L,i,$),s(i,$l,$),s(i,P,$),s(i,gl,$),U(Y,i,$),s(i,Al,$),s(i,ol,$),s(i,El,$),s(i,Tl,$),Zl=!0},i(i){Zl||(c(d.$$.fragment,i),c(tl.$$.fragment,i),c(Q.$$.fragment,i),c(E.$$.fragment,i),c(K.$$.fragment,i),c(jl.$$.fragment,i),c(S.$$.fragment,i),c(q.$$.fragment,i),c(L.$$.fragment,i),c(Y.$$.fragment,i),Zl=!0)},o(i){y(d.$$.fragment,i),y(tl.$$.fragment,i),y(Q.$$.fragment,i),y(E.$$.fragment,i),y(K.$$.fragment,i),y(jl.$$.fragment,i),y(S.$$.fragment,i),y(q.$$.fragment,i),y(L.$$.fragment,i),y(Y.$$.fragment,i),Zl=!1},d(i){i&&(e(p),e(r),e(g),e(w),e(x),e(W),e(C),e(B),e(Ml),e(N),e(v),e(Ul),e(z),e(A),e(ul),e(H),e(X),e(rl),e(R),e(al),e(k),e(Jl),e(O),e(dl),e(F),e(bl),e(hl),e(zl),e(ml),e(Cl),e(D),e(Il),e($l),e(P),e(gl),e(Al),e(ol),e(El),e(Tl)),u(d,i),u(tl,i),u(Q,i),u(E,i),u(K,i),u(jl,i),u(S,i),u(q,i),u(L,i),u(Y,i)}}}function $p(_){let p,b="在我們開始之前，讓我們看看我們在沒有任何訓練的情況下從我們的模型中得到了什麼樣的結果：",r,d,g,w,G,x,W="一旦完成，我們就可以準備編譯和訓練模型所需的一切。 注意當使用 <code>tf.keras.mixed_precision.set_global_policy(&quot;mixed_float16&quot;)</code>時——這將告訴 Keras 使用 float16 進行訓練，這可以顯著提高支持它的 GPU（Nvidia 20xx/V100 或更高版本）的速度。",Z,C,B,V,Ml='接下來，我們定義一個 <code>PushToHubCallback</code> 以便在訓練期間將我們的模型上傳到 Hub，正如我們在 <a href="(/course/chapter7/2)">第 2 節</a> 中看到的，然後我們只需擬合模型時添加該回調函數：',tl,N,v,ll,Ul='請注意，您可以使用 <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>。',Q,z,A,el,ul="最後，讓我們看看訓練結束後我們的指標是什麼樣的：",E,H,K,X,rl,nl,R="在這個階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。 您已經成功地微調了翻譯任務中的模型——恭喜！",al;return d=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}}),N=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}}),z=new le({props:{$$slots:{default:[Zp]},$$scope:{ctx:_}}}),H=new h({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),X=new h({props:{code:"JTdCJ2JsZXUnJTNBJTIwNTcuMzM0MDY2MjcxNTQ1ODY1JTdE",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">57.334066271545865</span>}',wrap:!1}}),{c(){p=J("p"),p.textContent=b,r=n(),o(d.$$.fragment),g=n(),o(w.$$.fragment),G=n(),x=J("p"),x.innerHTML=W,Z=n(),o(C.$$.fragment),B=n(),V=J("p"),V.innerHTML=Ml,tl=n(),o(N.$$.fragment),v=n(),ll=J("p"),ll.innerHTML=Ul,Q=n(),o(z.$$.fragment),A=n(),el=J("p"),el.textContent=ul,E=n(),o(H.$$.fragment),K=n(),o(X.$$.fragment),rl=n(),nl=J("p"),nl.textContent=R},l(f){p=m(f,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1azi1sh"&&(p.textContent=b),r=a(f),T(d.$$.fragment,f),g=a(f),T(w.$$.fragment,f),G=a(f),x=m(f,"P",{"data-svelte-h":!0}),j(x)!=="svelte-1ovc25p"&&(x.innerHTML=W),Z=a(f),T(C.$$.fragment,f),B=a(f),V=m(f,"P",{"data-svelte-h":!0}),j(V)!=="svelte-1sdejyy"&&(V.innerHTML=Ml),tl=a(f),T(N.$$.fragment,f),v=a(f),ll=m(f,"P",{"data-svelte-h":!0}),j(ll)!=="svelte-j1rmx5"&&(ll.innerHTML=Ul),Q=a(f),T(z.$$.fragment,f),A=a(f),el=m(f,"P",{"data-svelte-h":!0}),j(el)!=="svelte-14po97"&&(el.textContent=ul),E=a(f),T(H.$$.fragment,f),K=a(f),T(X.$$.fragment,f),rl=a(f),nl=m(f,"P",{"data-svelte-h":!0}),j(nl)!=="svelte-1uqim6t"&&(nl.textContent=R)},m(f,k){s(f,p,k),s(f,r,k),U(d,f,k),s(f,g,k),U(w,f,k),s(f,G,k),s(f,x,k),s(f,Z,k),U(C,f,k),s(f,B,k),s(f,V,k),s(f,tl,k),U(N,f,k),s(f,v,k),s(f,ll,k),s(f,Q,k),U(z,f,k),s(f,A,k),s(f,el,k),s(f,E,k),U(H,f,k),s(f,K,k),U(X,f,k),s(f,rl,k),s(f,nl,k),al=!0},i(f){al||(c(d.$$.fragment,f),c(w.$$.fragment,f),c(C.$$.fragment,f),c(N.$$.fragment,f),c(z.$$.fragment,f),c(H.$$.fragment,f),c(X.$$.fragment,f),al=!0)},o(f){y(d.$$.fragment,f),y(w.$$.fragment,f),y(C.$$.fragment,f),y(N.$$.fragment,f),y(z.$$.fragment,f),y(H.$$.fragment,f),y(X.$$.fragment,f),al=!1},d(f){f&&(e(p),e(r),e(g),e(G),e(x),e(Z),e(B),e(V),e(tl),e(v),e(ll),e(Q),e(A),e(el),e(E),e(K),e(rl),e(nl)),u(d,f),u(w,f),u(C,f),u(N,f),u(z,f),u(H,f),u(X,f)}}}function gp(_){let p,b="💡如果您使用的輸出目錄已經存在，則它需要是您要推送到的存儲庫的本地克隆。如果不是，您將在定義您的名稱時會遇到錯誤，並且需要設置一個新名稱。";return{c(){p=J("p"),p.textContent=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-q5tehq"&&(p.textContent=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function Zp(_){let p,b="💡如果您使用的輸出目錄已經存在，則它需要是您要推送到的存儲庫的本地克隆。如果不是，您將在定義您的名稱時會遇到錯誤，並且需要設置一個新名稱。";return{c(){p=J("p"),p.textContent=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-q5tehq"&&(p.textContent=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function Oa(_){let p,b,r,d='現在讓我們看一下完整的訓練循環，以便您可以輕鬆自定義所需的部分。它看起來很像我們在<a href="/course/chapter7/2">本章第二節</a>和<a href="/course/chapter3/4">第三章第四小節</a>所做的。',g,w,G,x,W="您已經多次看到所有這些，因此這一塊會簡略進行。首先我們將構建我們的數據集的<strong>DataLoader</strong> ，在將數據集設置為 <strong>torch</strong> 格式，我們就得到了 PyTorch 張量：",Z,C,B,V,Ml="接下來我們重新實例化我們的模型，以確保我們不會繼續上一節的微調，而是再次從預訓練模型開始重新訓練：",tl,N,v,ll,Ul="然後我們需要一個優化器：",Q,z,A,el,ul="一旦我們擁有所有這些對象，我們就可以將它們發送到 <code>accelerator.prepare()</code> 方法。 請記住，如果您想在 Colab 筆記本訓練中使用TPU，則需要將所有這些代碼移動到訓練函數中，並且不應執行任何實例化“加速器”的對象。",E,H,K,X,rl="現在我們已經發送了我們的 <strong>train_dataloader</strong> 到 <strong>accelerator.prepare()</strong> ，我們可以使用它的長度來計算訓練步驟的數量。請記住，我們應該始終在準備好數據加載器後執行此操作，因為該方法會更改 <strong>DataLoader</strong> .我們使用從學習率衰減到 0 的經典線性學習率調度：",nl,R,al,f,k="最後，要將我們的模型推送到 Hub，我們需要創建一個 <strong>Repository</strong> 工作文件夾中的對象。如果您尚未登錄，請先登錄 Hugging Face。我們將從我們想要為模型提供的模型 ID 中確定存儲庫名稱（您可以自由地用自己的選擇替換 <strong>repo_name</strong> ；它需要包含您的用戶名，可以使用<strong>get_full_repo_name()</strong>函數的查看目前的repo_name）：",jl,Jl,O,_l,dl,F,Fl="然後我們可以在本地文件夾中克隆該存儲庫。如果它已經存在，這個本地文件夾應該是我們正在使用的存儲庫的克隆：",bl,S,hl,q,zl="我們現在可以通過調用 <strong>repo.push_to_hub()</strong> 方法上傳我們保存的任何內容 <strong>output_dir</strong> 。這將幫助我們在每個 epoch 結束時上傳過程中的模型。",ml,il,Cl,D,Sl="我們現在準備編寫完整的訓練循環。為了簡化它的評估部分，我們定義了這個 <strong>postprocess()</strong> 函數接收預測結果和正確標籤並將它們轉換為我們 <strong>metric</strong> 對象所需要的字符串列表：",Il,L,$l,P,ql='訓練循環看起來和<a href="/course/chapter7/2">本章第二節</a>與<a href="/course/chapter3">第三章</a>很像，在評估部分有一些不同 - 所以讓我們專注於這一點！',gl,Y,Al="首先要注意的是我們使用 <code>generate()</code> 方法來計算預測，但這是我們基礎模型上的一個方法，而不是包裝模型🤗 Accelerate 在 <code>prepare()</code> 方法中創建。 這就是為什麼我們先解包模型，然後調用這個方法。",ol,cl,El='第二件事是，就像<a href="/course/chapter7/2">token 分類</a>，兩個進程可能將輸入和標籤填充為不同的形狀，因此我們在調用 <strong>gather()</strong> 方法之前使用 <strong>accelerator.pad_across_processes()</strong> 使預測和標籤具有相同的形狀。如果我們不這樣做，評估要麼出錯，要麼永遠在阻塞。',Tl,yl,Zl,i,$,wl,Ls='完成此操作後，您應該有一個模型，其結果與使用 <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%A8%93%E7%B7%B4%E5%AE%8C%E7%9A%84%E7%B5%90%E6%9E%9C%E3%80%82" rel="nofollow">https://huggingface.co/huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate）查看訓練完的結果。</a> 如果您想測試對訓練循環的任何調整，您可以通過編輯上面顯示的代碼直接實現它們！',Hl;return p=new kl({props:{title:"自定義訓練循環",local:"自定義訓練循環",headingTag:"h2"}}),w=new kl({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}}),N=new h({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),z=new h({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDJlLTUp",highlighted:`<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),H=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}}),R=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}}),Jl=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}}),_l=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 kl({props:{title:"訓練循環",local:"訓練循環",headingTag:"h3"}}),L=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}}),yl=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(){o(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,g=n(),o(w.$$.fragment),G=n(),x=J("p"),x.innerHTML=W,Z=n(),o(C.$$.fragment),B=n(),V=J("p"),V.textContent=Ml,tl=n(),o(N.$$.fragment),v=n(),ll=J("p"),ll.textContent=Ul,Q=n(),o(z.$$.fragment),A=n(),el=J("p"),el.innerHTML=ul,E=n(),o(H.$$.fragment),K=n(),X=J("p"),X.innerHTML=rl,nl=n(),o(R.$$.fragment),al=n(),f=J("p"),f.innerHTML=k,jl=n(),o(Jl.$$.fragment),O=n(),o(_l.$$.fragment),dl=n(),F=J("p"),F.textContent=Fl,bl=n(),o(S.$$.fragment),hl=n(),q=J("p"),q.innerHTML=zl,ml=n(),o(il.$$.fragment),Cl=n(),D=J("p"),D.innerHTML=Sl,Il=n(),o(L.$$.fragment),$l=n(),P=J("p"),P.innerHTML=ql,gl=n(),Y=J("p"),Y.innerHTML=Al,ol=n(),cl=J("p"),cl.innerHTML=El,Tl=n(),o(yl.$$.fragment),Zl=n(),o(i.$$.fragment),$=n(),wl=J("p"),wl.innerHTML=Ls},l(M){T(p.$$.fragment,M),b=a(M),r=m(M,"P",{"data-svelte-h":!0}),j(r)!=="svelte-1s6cy6j"&&(r.innerHTML=d),g=a(M),T(w.$$.fragment,M),G=a(M),x=m(M,"P",{"data-svelte-h":!0}),j(x)!=="svelte-1sphalx"&&(x.innerHTML=W),Z=a(M),T(C.$$.fragment,M),B=a(M),V=m(M,"P",{"data-svelte-h":!0}),j(V)!=="svelte-a97q0r"&&(V.textContent=Ml),tl=a(M),T(N.$$.fragment,M),v=a(M),ll=m(M,"P",{"data-svelte-h":!0}),j(ll)!=="svelte-prg2lg"&&(ll.textContent=Ul),Q=a(M),T(z.$$.fragment,M),A=a(M),el=m(M,"P",{"data-svelte-h":!0}),j(el)!=="svelte-15fi82o"&&(el.innerHTML=ul),E=a(M),T(H.$$.fragment,M),K=a(M),X=m(M,"P",{"data-svelte-h":!0}),j(X)!=="svelte-1a7ga15"&&(X.innerHTML=rl),nl=a(M),T(R.$$.fragment,M),al=a(M),f=m(M,"P",{"data-svelte-h":!0}),j(f)!=="svelte-14dqs1o"&&(f.innerHTML=k),jl=a(M),T(Jl.$$.fragment,M),O=a(M),T(_l.$$.fragment,M),dl=a(M),F=m(M,"P",{"data-svelte-h":!0}),j(F)!=="svelte-1fj9jwz"&&(F.textContent=Fl),bl=a(M),T(S.$$.fragment,M),hl=a(M),q=m(M,"P",{"data-svelte-h":!0}),j(q)!=="svelte-1k5u26e"&&(q.innerHTML=zl),ml=a(M),T(il.$$.fragment,M),Cl=a(M),D=m(M,"P",{"data-svelte-h":!0}),j(D)!=="svelte-eap1bh"&&(D.innerHTML=Sl),Il=a(M),T(L.$$.fragment,M),$l=a(M),P=m(M,"P",{"data-svelte-h":!0}),j(P)!=="svelte-pmr4ay"&&(P.innerHTML=ql),gl=a(M),Y=m(M,"P",{"data-svelte-h":!0}),j(Y)!=="svelte-2yiako"&&(Y.innerHTML=Al),ol=a(M),cl=m(M,"P",{"data-svelte-h":!0}),j(cl)!=="svelte-1lt2ki6"&&(cl.innerHTML=El),Tl=a(M),T(yl.$$.fragment,M),Zl=a(M),T(i.$$.fragment,M),$=a(M),wl=m(M,"P",{"data-svelte-h":!0}),j(wl)!=="svelte-1kjr4a"&&(wl.innerHTML=Ls)},m(M,I){U(p,M,I),s(M,b,I),s(M,r,I),s(M,g,I),U(w,M,I),s(M,G,I),s(M,x,I),s(M,Z,I),U(C,M,I),s(M,B,I),s(M,V,I),s(M,tl,I),U(N,M,I),s(M,v,I),s(M,ll,I),s(M,Q,I),U(z,M,I),s(M,A,I),s(M,el,I),s(M,E,I),U(H,M,I),s(M,K,I),s(M,X,I),s(M,nl,I),U(R,M,I),s(M,al,I),s(M,f,I),s(M,jl,I),U(Jl,M,I),s(M,O,I),U(_l,M,I),s(M,dl,I),s(M,F,I),s(M,bl,I),U(S,M,I),s(M,hl,I),s(M,q,I),s(M,ml,I),U(il,M,I),s(M,Cl,I),s(M,D,I),s(M,Il,I),U(L,M,I),s(M,$l,I),s(M,P,I),s(M,gl,I),s(M,Y,I),s(M,ol,I),s(M,cl,I),s(M,Tl,I),U(yl,M,I),s(M,Zl,I),U(i,M,I),s(M,$,I),s(M,wl,I),Hl=!0},i(M){Hl||(c(p.$$.fragment,M),c(w.$$.fragment,M),c(C.$$.fragment,M),c(N.$$.fragment,M),c(z.$$.fragment,M),c(H.$$.fragment,M),c(R.$$.fragment,M),c(Jl.$$.fragment,M),c(_l.$$.fragment,M),c(S.$$.fragment,M),c(il.$$.fragment,M),c(L.$$.fragment,M),c(yl.$$.fragment,M),c(i.$$.fragment,M),Hl=!0)},o(M){y(p.$$.fragment,M),y(w.$$.fragment,M),y(C.$$.fragment,M),y(N.$$.fragment,M),y(z.$$.fragment,M),y(H.$$.fragment,M),y(R.$$.fragment,M),y(Jl.$$.fragment,M),y(_l.$$.fragment,M),y(S.$$.fragment,M),y(il.$$.fragment,M),y(L.$$.fragment,M),y(yl.$$.fragment,M),y(i.$$.fragment,M),Hl=!1},d(M){M&&(e(b),e(r),e(g),e(G),e(x),e(Z),e(B),e(V),e(tl),e(v),e(ll),e(Q),e(A),e(el),e(E),e(K),e(X),e(nl),e(al),e(f),e(jl),e(O),e(dl),e(F),e(bl),e(hl),e(q),e(ml),e(Cl),e(D),e(Il),e($l),e(P),e(gl),e(Y),e(ol),e(cl),e(Tl),e(Zl),e($),e(wl)),u(p,M),u(w,M),u(C,M),u(N,M),u(z,M),u(H,M),u(R,M),u(Jl,M),u(_l,M),u(S,M),u(il,M),u(L,M),u(yl,M),u(i,M)}}}function _p(_){let p,b="✏️ <strong>輪到你了！</strong> “電子郵件”這個詞在模型返回了什麼？";return{c(){p=J("p"),p.innerHTML=b},l(r){p=m(r,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1x2ttjs"&&(p.innerHTML=b)},m(r,d){s(r,p,d)},p:Yl,d(r){r&&e(p)}}}function kp(_){let p,b,r,d,g,w,G,x,W,Z,C,B,V,Ml,tl='現在讓我們深入研究翻譯。這是另一個<a href="/course/chapter1/7">sequence-to-sequence 任務</a>，這意味著這是一個可以表述為從一個序列到另一個序列的問題。從這個意義上說，這個問題非常類似<a href="/course/chapter7/6">文本摘要</a>，並且您可以將我們將在此處學習到的一些內容遷移到其他的序列到序列問題，例如：',N,v,ll="<li><strong>風格遷移</strong> : 創建一個模型將某種風格遷移到一段文本（例如，正式的風格遷移到休閒的風格或莎士比亞英語到現代英語）</li> <li><strong>生成問題的回答</strong> ：創建一個模型，在給定上下文的情況下生成問題的答案</li>",Ul,Q,z,A,el='如果您有足夠大的兩種（或更多）語言的文本語料庫，您可以從頭開始訓練一個新的翻譯模型，就像我們在<a href="/course/chapter7/6">因果語言建模</a>部分中所做的那樣。然而，微調現有的翻譯模型會更快，無論是從像 mT5 或 mBART 這樣的多語言模型微調到特定的語言對，或者是專門用於從一種語言翻譯成另一種語言的模型。',ul,E,H='在本節中，我們將對<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,rl="完成後，我們將擁有一個模型，可以進行這樣的翻譯：",nl,R,al,f,k,jl,Jl,O,_l='<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."/>',dl,F,Fl='與前面的部分一樣，您可以使用以下代碼找到我們將訓練並上傳到 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>查看模型輸出的結果',bl,S,hl,q,zl='為了從頭開始微調或訓練翻譯模型，我們需要一個適合該任務的數據集。如前所述，我們將使用<a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 數據集</a>在本節中，但您可以很容易地調整代碼以使用您自己的數據，只要您有要互譯的兩種語言的句子對。如果您需要複習如何將自定義數據加載到 <strong>Dataset</strong> 可以複習一下<a href="/course/chapter5">第五章</a>.',ml,il,Cl,D,Sl="像往常一樣，我們使用 <strong>load_dataset()</strong> 函數：",Il,L,$l,P,ql='如果您想使用不同的語言對，您可以使用它們的代碼來指定它們。該數據集共有 92 種語言可用；您可以通過<a href="https://huggingface.co/datasets/kde4" rel="nofollow">數據集卡片</a>展開其上的語言標籤來查看它們.',gl,Y,Al,ol,cl,El="我們來看看數據集：",Tl,yl,Zl,i,$,wl,Ls='我們有 210,173 對句子，但在一次訓練過程中，我們需要創建自己的驗證集。正如我們在<a href="/course/chapter5">第五章</a>學的的那樣, <strong>Dataset</strong> 有一個 <strong>train_test_split()</strong> 方法,可以幫我們拆分數據集。我們將設定固定的隨機數種子：',Hl,M,I,ee,Ks,se,qn="我們可以將 <strong>test</strong> 的鍵重命名為 <strong>validation</strong> 像這樣：",Os,te,lt,ne,Dn="現在讓我們看一下數據集的一個元素：",et,ae,st,pe,tt,Me,Ln="我們得到一個字典，其中包含我們請求的兩種語言的兩個句子。這個充滿技術計算機科學術語的數據集的一個特殊之處在於它們都完全用法語翻譯。然而，法國工程師通常很懶惰，在交談時，大多數計算機科學專用詞彙都用英語表述。例如，“threads”這個詞很可能出現在法語句子中，尤其是在技術對話中；但在這個數據集中，它被翻譯成更正確的“fils de Discussion”。我們使用的預訓練模型已經在一個更大的法語和英語句子語料庫上進行了預訓練，採用了更簡單的選擇，即保留單詞的原樣:",nt,re,at,ie,pt,ce,Pn=`這種情況的另一個例子是“plugin”這個詞，它不是正式的法語詞，但大多數母語人士都能理解，也不會費心去翻譯。
在 KDE4 數據集中，這個詞在法語中被翻譯成更正式的“module d’extension”：`,Mt,ye,rt,Je,it,me,Kn="然而，我們的預訓練模型堅持使用簡練而熟悉的英文單詞：",ct,oe,yt,Te,Jt,Ue,On="看看我們的微調模型是否能識別數據集的這些特殊性。（劇透警告：它會）。",mt,ue,ot,Dl,Tt,je,Ut,we,ut,fe,la='您現在應該知道我們的下一步該做些什麼了：所有文本都需要轉換為token ID，以便模型能夠理解它們。對於這個任務，我們需要同時標記輸入和目標。我們的首要任務是創建我們的 <strong>tokenizer</strong> 對象。如前所述，我們將使用 Marian 英語到法語的預訓練模型。如果您使用另一對語言嘗試此代碼，請確保調整模型Checkpoint。<a href="https://huggingface.co/Helsinki-NLP" rel="nofollow">Helsinki-NLP</a>組織提供了多種語言的一千多種模型。',jt,de,wt,be,ea='您可以將 <strong>model_checkpoint</strong> 更換為<a href="https://huggingface.co/models" rel="nofollow">Hub</a>上你喜歡的任何其他型號，或本地保存的預訓練模型和標記器。',ft,Ll,dt,he,sa="我們的數據準備非常簡單。 只需要記住一件事：您照常處理輸入，但對於這次的輸出目標，您需要將標記器包裝在上下文管理器“as_target_tokenizer()”中。",bt,Ce,ta="Python 中的上下文管理器引入了 <strong>with</strong> 語句，當您有兩個相關的操作要成對執行時很有用。最常見的例子是當您寫入或讀取文件時，下面是一個例子：",ht,Ie,Ct,$e,na="這裡成對執行的兩個相關操作是打開和關閉文件的操作。打開的文件f對應的對象只在with下的縮進塊內有效；在該塊之前打開，在該塊的末尾關閉。",It,ge,aa="在本例中，上下文管理器 as_target_tokenizer() 將在執行縮進塊之前將標記器設置為輸出語言（此處為法語），然後將其設置回輸入語言（此處為英語）。",$t,Ze,pa="因此，預處理一個樣本如下所示：",gt,_e,Zt,ke,Ma="如果我們忘記在上下文管理器中標記目標，它們將被輸入標記器標記，在Marian模型的情況下，會導致輸出的異常：",_t,Ge,kt,xe,Gt,Be,ra="正如我們所看到的，使用英語標記器來預處理法語句子會產生更多的標記，因為標記器不知道任何法語單詞(除了那些也出現在英語語言中的單詞，比如“discussion”)。",xt,We,ia="<code>inputs</code> 和 <code>targets</code> 都是帶有我們常用鍵（輸入 ID、注意掩碼等）的字典，所以最後一步是在輸入中設置一個 <code>&quot;labels&quot;</code> 鍵。 我們在數據集的預處理函數中執行此操作：",Bt,Re,Wt,Xe,ca="請注意，我們為輸入和輸出設置了相同的最大長度。由於我們處理的文本看起來很短，我們使用 128。",Rt,Pl,Xt,Kl,Vt,Ve,ya="我們現在可以對數據集的所有數據一次性應用該預處理：",Nt,Ne,vt,ve,Ja="現在數據已經過預處理，我們準備好微調我們的預訓練模型！",Qt,Gl,xl,Es,Qe,ma="請注意，這次我們使用的是在翻譯任務上訓練過的模型，並且實際上已經可以使用，因此沒有關於丟失權重或新初始化權重的警告。",zt,ze,At,Ae,oa='我們需要一個數據整理器來處理動態批處理的填充。在本例中，我們不能像<a href="/course/chapter3">第3章</a>那樣使用帶填充的<strong>DataCollatorWithPadding</strong>，因為它只填充輸入（輸入ID、注意掩碼和令牌類型ID）。我們的標籤也應該填充到標籤中遇到的最大長度。而且，如前所述，用於填充標籤的填充值應為-100，而不是標記器的填充標記，以確保在損失計算中忽略這些填充值。',Et,Ee,Ta='這一切都可以由 <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”需要知道“模型”對象：',Yt,Bl,Wl,Ys,Ye,Ua="為了在幾個樣本上進行測試，我們只需在我們標記化訓練集中的部分數據上調用它：",Ht,He,Ft,Fe,St,Se,ua="我們可以檢查我們的標籤是否已使用 <strong>-100</strong> 填充到批次的最大長度：",qt,qe,Dt,De,Lt,Le,ja="我們還可以查看解碼器輸入 ID，看看它們是標籤的偏移形成的版本：",Pt,Pe,Kt,Ke,Ot,Oe,wa="以下是我們數據集中第一個和第二個元素的標籤：",ln,ls,en,es,sn,Rl,Xl,Hs,ss,tn,ts,nn,Fs,ns,fa='用於翻譯的傳統指標是<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> 這樣的句子）。',an,as,da='BLEU 的一個缺點是它需要文本已經被分詞，這使得比較使用不同標記器的模型之間的分數變得困難。因此，當今用於基準翻譯模型的最常用指標是<a href="https://github.com/mjpost/sacrebleu" rel="nofollow">SacreBLEU</a>，它通過標準化標記化步驟解決了這個缺點（和其他的一些缺點）。要使用此指標，我們首先需要安裝 SacreBLEU 庫：',pn,ps,Mn,Ms,ba='然後我們可以就像我們在<a href="/course/chapter3">第三章</a>那樣通過 <strong>load_metric()</strong> 加載它 ：',rn,rs,cn,is,ha="該指標將文本作為輸入和目標結果。它旨在接受多個可接受的目標，因為同一個句子通常有多個可接受的翻譯——我們使用的數據集只提供一個，但在 NLP 中找到將多個句子作為標籤的數據集不是一個難題。因此，預測結果應該是一個句子列表，而參考應該是一個句子列表的列表。",yn,cs,Ca="讓我們嘗試一個例子：",Jn,ys,mn,Js,on,ms,Ia='這得到了 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 分數：',Tn,os,Un,Ts,un,Us,jn,us,wn,js,$a="分數可以從 0 到 100，越高越好。",fn,Vl,Nl,Ss,ws,ga="現在這已經完成了，我們已經準備好微調我們的模型了！",dn,fs,bn,ds,Za="第一步是登錄 Hugging Face，這樣您就可以將結果上傳到模型中心。有一個方便的功能可以幫助您在notebook中完成此操作：",hn,bs,Cn,hs,_a="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 登錄憑據。",In,Cs,ka="如果您不是在notebook上運行代碼，只需在終端中輸入以下行：",$n,Is,gn,vl,Ql,qs,Ds,$s,Zn,gs,Ga="我們已經向您展示瞭如何將我們在模型中心微調的模型與推理小部件一起使用。 要在“管道”中本地使用它，我們只需要指定正確的模型標識符：",_n,Zs,kn,_s,Gn,ks,xa="正如預期的那樣，我們的預訓練模型將其知識適應了我們對其進行微調的語料庫，而不是單獨留下英文單詞“threads”，而是將其翻譯成法語官方版本。 “”的翻譯也是一樣的：",xn,Gs,Bn,xs,Wn,Bs,Ba="風格適應的另一個很好的例子！",Rn,Ol,Xn,Ws,Vn,Ps,Nn;g=new ip({props:{fw:_[0]}}),G=new Mp({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),W=new kl({props:{title:"翻譯",local:"翻譯",headingTag:"h1"}});const Wa=[yp,cp],Rs=[];function Ra(l,t){return l[0]==="pt"?0:1}C=Ra(_),B=Rs[C]=Wa[C](_),Q=new Qn({props:{id:"1JvfrvZgi6c"}}),S=new kl({props:{title:"準備數據",local:"準備數據",headingTag:"h2"}}),il=new kl({props:{title:"KDE4 數據集",local:"kde4-數據集",headingTag:"h3"}}),L=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTJDJTIwbG9hZF9tZXRyaWMlMEElMEFyYXdfZGF0YXNldHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIya2RlNCUyMiUyQyUyMGxhbmcxJTNEJTIyZW4lMjIlMkMlMjBsYW5nMiUzRCUyMmZyJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, load_metric

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}}),yl=new h({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),i=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}}),M=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}}),ee=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}}),te=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}}),ae=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}}),pe=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}}),re=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}}),ie=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}}),ye=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}}),Je=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}}),oe=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}}),Te=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}}),ue=new Qn({props:{id:"0Oxphw4Q9fo"}}),Dl=new le({props:{$$slots:{default:[Jp]},$$scope:{ctx:_}}}),je=new kl({props:{title:"處理數據",local:"處理數據",headingTag:"h3"}}),we=new Qn({props:{id:"XAR8jnZZuUs"}}),de=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIySGVsc2lua2ktTkxQJTJGb3B1cy1tdC1lbi1mciUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",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;tf&quot;</span>)`,wrap:!1}}),Ll=new le({props:{$$slots:{default:[mp]},$$scope:{ctx:_}}}),Ie=new h({props:{code:"d2l0aCUyMG9wZW4oZmlsZV9wYXRoKSUyMGFzJTIwZiUzQSUwQSUyMCUyMCUyMCUyMGNvbnRlbnQlMjAlM0QlMjBmLnJlYWQoKQ==",highlighted:`<span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(file_path) <span class="hljs-keyword">as</span> f:
    content = f.<span class="hljs-built_in">read</span>()`,wrap:!1}}),_e=new h({props:{code:"ZW5fc2VudGVuY2UlMjAlM0QlMjBzcGxpdF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMSU1RCU1QiUyMnRyYW5zbGF0aW9uJTIyJTVEJTVCJTIyZW4lMjIlNUQlMEFmcl9zZW50ZW5jZSUyMCUzRCUyMHNwbGl0X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIxJTVEJTVCJTIydHJhbnNsYXRpb24lMjIlNUQlNUIlMjJmciUyMiU1RCUwQSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihlbl9zZW50ZW5jZSklMEF3aXRoJTIwdG9rZW5pemVyLmFzX3RhcmdldF90b2tlbml6ZXIoKSUzQSUwQSUyMCUyMCUyMCUyMHRhcmdldHMlMjAlM0QlMjB0b2tlbml6ZXIoZnJfc2VudGVuY2Up",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)
<span class="hljs-keyword">with</span> tokenizer.as_target_tokenizer():
    targets = tokenizer(fr_sentence)`,wrap:!1}}),Ge=new h({props:{code:"d3JvbmdfdGFyZ2V0cyUyMCUzRCUyMHRva2VuaXplcihmcl9zZW50ZW5jZSklMEFwcmludCh0b2tlbml6ZXIuY29udmVydF9pZHNfdG9fdG9rZW5zKHdyb25nX3RhcmdldHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKSUwQXByaW50KHRva2VuaXplci5jb252ZXJ0X2lkc190b190b2tlbnModGFyZ2V0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCkp",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(targets[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),xe=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}}),Re=new h({props:{code:"bWF4X2lucHV0X2xlbmd0aCUyMCUzRCUyMDEyOCUwQW1heF90YXJnZXRfbGVuZ3RoJTIwJTNEJTIwMTI4JTBBJTBBJTBBZGVmJTIwcHJlcHJvY2Vzc19mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBpbnB1dHMlMjAlM0QlMjAlNUJleCU1QiUyMmVuJTIyJTVEJTIwZm9yJTIwZXglMjBpbiUyMGV4YW1wbGVzJTVCJTIydHJhbnNsYXRpb24lMjIlNUQlNUQlMEElMjAlMjAlMjAlMjB0YXJnZXRzJTIwJTNEJTIwJTVCZXglNUIlMjJmciUyMiU1RCUyMGZvciUyMGV4JTIwaW4lMjBleGFtcGxlcyU1QiUyMnRyYW5zbGF0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGlucHV0cyUyQyUyMG1heF9sZW5ndGglM0RtYXhfaW5wdXRfbGVuZ3RoJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwU2V0JTIwdXAlMjB0aGUlMjB0b2tlbml6ZXIlMjBmb3IlMjB0YXJnZXRzJTBBJTIwJTIwJTIwJTIwd2l0aCUyMHRva2VuaXplci5hc190YXJnZXRfdG9rZW5pemVyKCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjB0b2tlbml6ZXIodGFyZ2V0cyUyQyUyMG1heF9sZW5ndGglM0RtYXhfdGFyZ2V0X2xlbmd0aCUyQyUyMHRydW5jYXRpb24lM0RUcnVlKSUwQSUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyU1QiUyMmxhYmVscyUyMiU1RCUyMCUzRCUyMGxhYmVscyU1QiUyMmlucHV0X2lkcyUyMiU1RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX2lucHV0cw==",highlighted:`max_input_length = <span class="hljs-number">128</span>
max_target_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, max_length=max_input_length, truncation=<span class="hljs-literal">True</span>)

    <span class="hljs-comment"># Set up the tokenizer for targets</span>
    <span class="hljs-keyword">with</span> tokenizer.as_target_tokenizer():
        labels = tokenizer(targets, max_length=max_target_length, truncation=<span class="hljs-literal">True</span>)

    model_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = labels[<span class="hljs-string">&quot;input_ids&quot;</span>]
    <span class="hljs-keyword">return</span> model_inputs`,wrap:!1}}),Pl=new le({props:{$$slots:{default:[op]},$$scope:{ctx:_}}}),Kl=new le({props:{warning:!0,$$slots:{default:[Tp]},$$scope:{ctx:_}}}),Ne=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 Xa=[up,Up],Xs=[];function Va(l,t){return l[0]==="pt"?0:1}Gl=Va(_),xl=Xs[Gl]=Xa[Gl](_),ze=new kl({props:{title:"數據整理",local:"數據整理",headingTag:"h3"}});const Na=[fp,wp],Vs=[];function va(l,t){return l[0]==="pt"?0:1}Bl=va(_),Wl=Vs[Bl]=Na[Bl](_),He=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}}),Fe=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}}),qe=new h({props:{code:"YmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQ=",highlighted:'batch[<span class="hljs-string">&quot;labels&quot;</span>]',wrap:!1}}),De=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}}),Pe=new h({props:{code:"YmF0Y2glNUIlMjJkZWNvZGVyX2lucHV0X2lkcyUyMiU1RA==",highlighted:'batch[<span class="hljs-string">&quot;decoder_input_ids&quot;</span>]',wrap:!1}}),Ke=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}}),es=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 Qa=[bp,dp],Ns=[];function za(l,t){return l[0]==="pt"?0:1}Rl=za(_),Xl=Ns[Rl]=Qa[Rl](_),ss=new kl({props:{title:"評估指標",local:"評估指標",headingTag:"h3"}}),ts=new Qn({props:{id:"M05L1DhFqcw"}});let fl=_[0]==="pt"&&Ka();ps=new h({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzYWNyZWJsZXU=",highlighted:"!pip install sacrebleu",wrap:!1}}),rs=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9tZXRyaWMlMEElMEFtZXRyaWMlMjAlM0QlMjBsb2FkX21ldHJpYyglMjJzYWNyZWJsZXUlMjIp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

metric = load_metric(<span class="hljs-string">&quot;sacrebleu&quot;</span>)`,wrap:!1}}),ys=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}}),Js=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}}),os=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}}),Ts=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}}),Us=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}}),us=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 Aa=[Cp,hp],vs=[];function Ea(l,t){return l[0]==="tf"?0:1}Vl=Ea(_),Nl=vs[Vl]=Aa[Vl](_),fs=new kl({props:{title:"微調模型",local:"微調模型",headingTag:"h3"}}),bs=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}}),Is=new h({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}});const Ya=[$p,Ip],Qs=[];function Ha(l,t){return l[0]==="tf"?0:1}vl=Ha(_),Ql=Qs[vl]=Ya[vl](_);let pl=_[0]==="pt"&&Oa();return $s=new kl({props:{title:"使用微調後的模型",local:"使用微調後的模型",headingTag:"h2"}}),Zs=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}}),_s=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}}),Gs=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}}),xs=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 le({props:{$$slots:{default:[_p]},$$scope:{ctx:_}}}),Ws=new rp({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter7/4.mdx"}}),{c(){p=J("meta"),b=n(),r=J("p"),d=n(),o(g.$$.fragment),w=n(),o(G.$$.fragment),x=n(),o(W.$$.fragment),Z=n(),B.c(),V=n(),Ml=J("p"),Ml.innerHTML=tl,N=n(),v=J("ul"),v.innerHTML=ll,Ul=n(),o(Q.$$.fragment),z=n(),A=J("p"),A.innerHTML=el,ul=n(),E=J("p"),E.innerHTML=H,K=n(),X=J("p"),X.textContent=rl,nl=n(),R=J("iframe"),f=n(),k=J("iframe"),Jl=n(),O=J("a"),O.innerHTML=_l,dl=n(),F=J("p"),F.innerHTML=Fl,bl=n(),o(S.$$.fragment),hl=n(),q=J("p"),q.innerHTML=zl,ml=n(),o(il.$$.fragment),Cl=n(),D=J("p"),D.innerHTML=Sl,Il=n(),o(L.$$.fragment),$l=n(),P=J("p"),P.innerHTML=ql,gl=n(),Y=J("img"),ol=n(),cl=J("p"),cl.textContent=El,Tl=n(),o(yl.$$.fragment),Zl=n(),o(i.$$.fragment),$=n(),wl=J("p"),wl.innerHTML=Ls,Hl=n(),o(M.$$.fragment),I=n(),o(ee.$$.fragment),Ks=n(),se=J("p"),se.innerHTML=qn,Os=n(),o(te.$$.fragment),lt=n(),ne=J("p"),ne.textContent=Dn,et=n(),o(ae.$$.fragment),st=n(),o(pe.$$.fragment),tt=n(),Me=J("p"),Me.textContent=Ln,nt=n(),o(re.$$.fragment),at=n(),o(ie.$$.fragment),pt=n(),ce=J("p"),ce.textContent=Pn,Mt=n(),o(ye.$$.fragment),rt=n(),o(Je.$$.fragment),it=n(),me=J("p"),me.textContent=Kn,ct=n(),o(oe.$$.fragment),yt=n(),o(Te.$$.fragment),Jt=n(),Ue=J("p"),Ue.textContent=On,mt=n(),o(ue.$$.fragment),ot=n(),o(Dl.$$.fragment),Tt=n(),o(je.$$.fragment),Ut=n(),o(we.$$.fragment),ut=n(),fe=J("p"),fe.innerHTML=la,jt=n(),o(de.$$.fragment),wt=n(),be=J("p"),be.innerHTML=ea,ft=n(),o(Ll.$$.fragment),dt=n(),he=J("p"),he.textContent=sa,bt=n(),Ce=J("p"),Ce.innerHTML=ta,ht=n(),o(Ie.$$.fragment),Ct=n(),$e=J("p"),$e.textContent=na,It=n(),ge=J("p"),ge.textContent=aa,$t=n(),Ze=J("p"),Ze.textContent=pa,gt=n(),o(_e.$$.fragment),Zt=n(),ke=J("p"),ke.textContent=Ma,_t=n(),o(Ge.$$.fragment),kt=n(),o(xe.$$.fragment),Gt=n(),Be=J("p"),Be.textContent=ra,xt=n(),We=J("p"),We.innerHTML=ia,Bt=n(),o(Re.$$.fragment),Wt=n(),Xe=J("p"),Xe.textContent=ca,Rt=n(),o(Pl.$$.fragment),Xt=n(),o(Kl.$$.fragment),Vt=n(),Ve=J("p"),Ve.textContent=ya,Nt=n(),o(Ne.$$.fragment),vt=n(),ve=J("p"),ve.textContent=Ja,Qt=n(),xl.c(),Es=n(),Qe=J("p"),Qe.textContent=ma,zt=n(),o(ze.$$.fragment),At=n(),Ae=J("p"),Ae.innerHTML=oa,Et=n(),Ee=J("p"),Ee.innerHTML=Ta,Yt=n(),Wl.c(),Ys=n(),Ye=J("p"),Ye.textContent=Ua,Ht=n(),o(He.$$.fragment),Ft=n(),o(Fe.$$.fragment),St=n(),Se=J("p"),Se.innerHTML=ua,qt=n(),o(qe.$$.fragment),Dt=n(),o(De.$$.fragment),Lt=n(),Le=J("p"),Le.textContent=ja,Pt=n(),o(Pe.$$.fragment),Kt=n(),o(Ke.$$.fragment),Ot=n(),Oe=J("p"),Oe.textContent=wa,ln=n(),o(ls.$$.fragment),en=n(),o(es.$$.fragment),sn=n(),Xl.c(),Hs=n(),o(ss.$$.fragment),tn=n(),o(ts.$$.fragment),nn=n(),fl&&fl.c(),Fs=n(),ns=J("p"),ns.innerHTML=fa,an=n(),as=J("p"),as.innerHTML=da,pn=n(),o(ps.$$.fragment),Mn=n(),Ms=J("p"),Ms.innerHTML=ba,rn=n(),o(rs.$$.fragment),cn=n(),is=J("p"),is.textContent=ha,yn=n(),cs=J("p"),cs.textContent=Ca,Jn=n(),o(ys.$$.fragment),mn=n(),o(Js.$$.fragment),on=n(),ms=J("p"),ms.innerHTML=Ia,Tn=n(),o(os.$$.fragment),Un=n(),o(Ts.$$.fragment),un=n(),o(Us.$$.fragment),jn=n(),o(us.$$.fragment),wn=n(),js=J("p"),js.textContent=$a,fn=n(),Nl.c(),Ss=n(),ws=J("p"),ws.textContent=ga,dn=n(),o(fs.$$.fragment),bn=n(),ds=J("p"),ds.textContent=Za,hn=n(),o(bs.$$.fragment),Cn=n(),hs=J("p"),hs.textContent=_a,In=n(),Cs=J("p"),Cs.textContent=ka,$n=n(),o(Is.$$.fragment),gn=n(),Ql.c(),qs=n(),pl&&pl.c(),Ds=n(),o($s.$$.fragment),Zn=n(),gs=J("p"),gs.textContent=Ga,_n=n(),o(Zs.$$.fragment),kn=n(),o(_s.$$.fragment),Gn=n(),ks=J("p"),ks.textContent=xa,xn=n(),o(Gs.$$.fragment),Bn=n(),o(xs.$$.fragment),Wn=n(),Bs=J("p"),Bs.textContent=Ba,Rn=n(),o(Ol.$$.fragment),Xn=n(),o(Ws.$$.fragment),Vn=n(),Ps=J("p"),this.h()},l(l){const t=ap("svelte-u9bgzb",document.head);p=m(t,"META",{name:!0,content:!0}),t.forEach(e),b=a(l),r=m(l,"P",{}),vn(r).forEach(e),d=a(l),T(g.$$.fragment,l),w=a(l),T(G.$$.fragment,l),x=a(l),T(W.$$.fragment,l),Z=a(l),B.l(l),V=a(l),Ml=m(l,"P",{"data-svelte-h":!0}),j(Ml)!=="svelte-g1zz7f"&&(Ml.innerHTML=tl),N=a(l),v=m(l,"UL",{"data-svelte-h":!0}),j(v)!=="svelte-mppk8z"&&(v.innerHTML=ll),Ul=a(l),T(Q.$$.fragment,l),z=a(l),A=m(l,"P",{"data-svelte-h":!0}),j(A)!=="svelte-12vvng4"&&(A.innerHTML=el),ul=a(l),E=m(l,"P",{"data-svelte-h":!0}),j(E)!=="svelte-zwczhs"&&(E.innerHTML=H),K=a(l),X=m(l,"P",{"data-svelte-h":!0}),j(X)!=="svelte-1dwvaw6"&&(X.textContent=rl),nl=a(l),R=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),vn(R).forEach(e),f=a(l),k=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),vn(k).forEach(e),Jl=a(l),O=m(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),j(O)!=="svelte-1ifl6xg"&&(O.innerHTML=_l),dl=a(l),F=m(l,"P",{"data-svelte-h":!0}),j(F)!=="svelte-ltxews"&&(F.innerHTML=Fl),bl=a(l),T(S.$$.fragment,l),hl=a(l),q=m(l,"P",{"data-svelte-h":!0}),j(q)!=="svelte-nnh33g"&&(q.innerHTML=zl),ml=a(l),T(il.$$.fragment,l),Cl=a(l),D=m(l,"P",{"data-svelte-h":!0}),j(D)!=="svelte-wyvyxf"&&(D.innerHTML=Sl),Il=a(l),T(L.$$.fragment,l),$l=a(l),P=m(l,"P",{"data-svelte-h":!0}),j(P)!=="svelte-a99dl6"&&(P.innerHTML=ql),gl=a(l),Y=m(l,"IMG",{src:!0,alt:!0,width:!0}),ol=a(l),cl=m(l,"P",{"data-svelte-h":!0}),j(cl)!=="svelte-y9mrlk"&&(cl.textContent=El),Tl=a(l),T(yl.$$.fragment,l),Zl=a(l),T(i.$$.fragment,l),$=a(l),wl=m(l,"P",{"data-svelte-h":!0}),j(wl)!=="svelte-afc7ia"&&(wl.innerHTML=Ls),Hl=a(l),T(M.$$.fragment,l),I=a(l),T(ee.$$.fragment,l),Ks=a(l),se=m(l,"P",{"data-svelte-h":!0}),j(se)!=="svelte-1sundz5"&&(se.innerHTML=qn),Os=a(l),T(te.$$.fragment,l),lt=a(l),ne=m(l,"P",{"data-svelte-h":!0}),j(ne)!=="svelte-1np1nb1"&&(ne.textContent=Dn),et=a(l),T(ae.$$.fragment,l),st=a(l),T(pe.$$.fragment,l),tt=a(l),Me=m(l,"P",{"data-svelte-h":!0}),j(Me)!=="svelte-1b9ekeu"&&(Me.textContent=Ln),nt=a(l),T(re.$$.fragment,l),at=a(l),T(ie.$$.fragment,l),pt=a(l),ce=m(l,"P",{"data-svelte-h":!0}),j(ce)!=="svelte-dum56n"&&(ce.textContent=Pn),Mt=a(l),T(ye.$$.fragment,l),rt=a(l),T(Je.$$.fragment,l),it=a(l),me=m(l,"P",{"data-svelte-h":!0}),j(me)!=="svelte-j3n155"&&(me.textContent=Kn),ct=a(l),T(oe.$$.fragment,l),yt=a(l),T(Te.$$.fragment,l),Jt=a(l),Ue=m(l,"P",{"data-svelte-h":!0}),j(Ue)!=="svelte-u92b5v"&&(Ue.textContent=On),mt=a(l),T(ue.$$.fragment,l),ot=a(l),T(Dl.$$.fragment,l),Tt=a(l),T(je.$$.fragment,l),Ut=a(l),T(we.$$.fragment,l),ut=a(l),fe=m(l,"P",{"data-svelte-h":!0}),j(fe)!=="svelte-vdluck"&&(fe.innerHTML=la),jt=a(l),T(de.$$.fragment,l),wt=a(l),be=m(l,"P",{"data-svelte-h":!0}),j(be)!=="svelte-19tlzon"&&(be.innerHTML=ea),ft=a(l),T(Ll.$$.fragment,l),dt=a(l),he=m(l,"P",{"data-svelte-h":!0}),j(he)!=="svelte-ya6djn"&&(he.textContent=sa),bt=a(l),Ce=m(l,"P",{"data-svelte-h":!0}),j(Ce)!=="svelte-y7z8zo"&&(Ce.innerHTML=ta),ht=a(l),T(Ie.$$.fragment,l),Ct=a(l),$e=m(l,"P",{"data-svelte-h":!0}),j($e)!=="svelte-fq9j9o"&&($e.textContent=na),It=a(l),ge=m(l,"P",{"data-svelte-h":!0}),j(ge)!=="svelte-1k2jt6s"&&(ge.textContent=aa),$t=a(l),Ze=m(l,"P",{"data-svelte-h":!0}),j(Ze)!=="svelte-j6n7bq"&&(Ze.textContent=pa),gt=a(l),T(_e.$$.fragment,l),Zt=a(l),ke=m(l,"P",{"data-svelte-h":!0}),j(ke)!=="svelte-1hklxb"&&(ke.textContent=Ma),_t=a(l),T(Ge.$$.fragment,l),kt=a(l),T(xe.$$.fragment,l),Gt=a(l),Be=m(l,"P",{"data-svelte-h":!0}),j(Be)!=="svelte-1ezr9a5"&&(Be.textContent=ra),xt=a(l),We=m(l,"P",{"data-svelte-h":!0}),j(We)!=="svelte-2ftd0c"&&(We.innerHTML=ia),Bt=a(l),T(Re.$$.fragment,l),Wt=a(l),Xe=m(l,"P",{"data-svelte-h":!0}),j(Xe)!=="svelte-1t7t0ps"&&(Xe.textContent=ca),Rt=a(l),T(Pl.$$.fragment,l),Xt=a(l),T(Kl.$$.fragment,l),Vt=a(l),Ve=m(l,"P",{"data-svelte-h":!0}),j(Ve)!=="svelte-41g0oo"&&(Ve.textContent=ya),Nt=a(l),T(Ne.$$.fragment,l),vt=a(l),ve=m(l,"P",{"data-svelte-h":!0}),j(ve)!=="svelte-kuri4t"&&(ve.textContent=Ja),Qt=a(l),xl.l(l),Es=a(l),Qe=m(l,"P",{"data-svelte-h":!0}),j(Qe)!=="svelte-1fvhpt7"&&(Qe.textContent=ma),zt=a(l),T(ze.$$.fragment,l),At=a(l),Ae=m(l,"P",{"data-svelte-h":!0}),j(Ae)!=="svelte-gauilj"&&(Ae.innerHTML=oa),Et=a(l),Ee=m(l,"P",{"data-svelte-h":!0}),j(Ee)!=="svelte-1vu6b9l"&&(Ee.innerHTML=Ta),Yt=a(l),Wl.l(l),Ys=a(l),Ye=m(l,"P",{"data-svelte-h":!0}),j(Ye)!=="svelte-1irh16z"&&(Ye.textContent=Ua),Ht=a(l),T(He.$$.fragment,l),Ft=a(l),T(Fe.$$.fragment,l),St=a(l),Se=m(l,"P",{"data-svelte-h":!0}),j(Se)!=="svelte-ixg3i9"&&(Se.innerHTML=ua),qt=a(l),T(qe.$$.fragment,l),Dt=a(l),T(De.$$.fragment,l),Lt=a(l),Le=m(l,"P",{"data-svelte-h":!0}),j(Le)!=="svelte-1txmlsd"&&(Le.textContent=ja),Pt=a(l),T(Pe.$$.fragment,l),Kt=a(l),T(Ke.$$.fragment,l),Ot=a(l),Oe=m(l,"P",{"data-svelte-h":!0}),j(Oe)!=="svelte-13jva7e"&&(Oe.textContent=wa),ln=a(l),T(ls.$$.fragment,l),en=a(l),T(es.$$.fragment,l),sn=a(l),Xl.l(l),Hs=a(l),T(ss.$$.fragment,l),tn=a(l),T(ts.$$.fragment,l),nn=a(l),fl&&fl.l(l),Fs=a(l),ns=m(l,"P",{"data-svelte-h":!0}),j(ns)!=="svelte-10ejz60"&&(ns.innerHTML=fa),an=a(l),as=m(l,"P",{"data-svelte-h":!0}),j(as)!=="svelte-ko64w4"&&(as.innerHTML=da),pn=a(l),T(ps.$$.fragment,l),Mn=a(l),Ms=m(l,"P",{"data-svelte-h":!0}),j(Ms)!=="svelte-1sf91fy"&&(Ms.innerHTML=ba),rn=a(l),T(rs.$$.fragment,l),cn=a(l),is=m(l,"P",{"data-svelte-h":!0}),j(is)!=="svelte-d95f1m"&&(is.textContent=ha),yn=a(l),cs=m(l,"P",{"data-svelte-h":!0}),j(cs)!=="svelte-8blnhe"&&(cs.textContent=Ca),Jn=a(l),T(ys.$$.fragment,l),mn=a(l),T(Js.$$.fragment,l),on=a(l),ms=m(l,"P",{"data-svelte-h":!0}),j(ms)!=="svelte-1rz427r"&&(ms.innerHTML=Ia),Tn=a(l),T(os.$$.fragment,l),Un=a(l),T(Ts.$$.fragment,l),un=a(l),T(Us.$$.fragment,l),jn=a(l),T(us.$$.fragment,l),wn=a(l),js=m(l,"P",{"data-svelte-h":!0}),j(js)!=="svelte-1nxf5yg"&&(js.textContent=$a),fn=a(l),Nl.l(l),Ss=a(l),ws=m(l,"P",{"data-svelte-h":!0}),j(ws)!=="svelte-askdwj"&&(ws.textContent=ga),dn=a(l),T(fs.$$.fragment,l),bn=a(l),ds=m(l,"P",{"data-svelte-h":!0}),j(ds)!=="svelte-lbhkb9"&&(ds.textContent=Za),hn=a(l),T(bs.$$.fragment,l),Cn=a(l),hs=m(l,"P",{"data-svelte-h":!0}),j(hs)!=="svelte-1oxqs03"&&(hs.textContent=_a),In=a(l),Cs=m(l,"P",{"data-svelte-h":!0}),j(Cs)!=="svelte-13113ho"&&(Cs.textContent=ka),$n=a(l),T(Is.$$.fragment,l),gn=a(l),Ql.l(l),qs=a(l),pl&&pl.l(l),Ds=a(l),T($s.$$.fragment,l),Zn=a(l),gs=m(l,"P",{"data-svelte-h":!0}),j(gs)!=="svelte-1jx14be"&&(gs.textContent=Ga),_n=a(l),T(Zs.$$.fragment,l),kn=a(l),T(_s.$$.fragment,l),Gn=a(l),ks=m(l,"P",{"data-svelte-h":!0}),j(ks)!=="svelte-a3uifz"&&(ks.textContent=xa),xn=a(l),T(Gs.$$.fragment,l),Bn=a(l),T(xs.$$.fragment,l),Wn=a(l),Bs=m(l,"P",{"data-svelte-h":!0}),j(Bs)!=="svelte-1txgxe8"&&(Bs.textContent=Ba),Rn=a(l),T(Ol.$$.fragment,l),Xn=a(l),T(Ws.$$.fragment,l),Vn=a(l),Ps=m(l,"P",{}),vn(Ps).forEach(e),this.h()},h(){sl(p,"name","hf:doc:metadata"),sl(p,"content",Gp),Sn(R.src,al="https://course-demos-marian-finetuned-kde4-en-to-fr.hf.space")||sl(R,"src",al),sl(R,"frameborder","0"),sl(R,"height","350"),sl(R,"title","Gradio app"),sl(R,"class","block dark:hidden container p-0 flex-grow space-iframe"),sl(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"),sl(R,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Sn(k.src,jl="https://course-demos-marian-finetuned-kde4-en-to-fr-darkmode.hf.space")||sl(k,"src",jl),sl(k,"frameborder","0"),sl(k,"height","350"),sl(k,"title","Gradio app"),sl(k,"class","hidden dark:block container p-0 flex-grow space-iframe"),sl(k,"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"),sl(k,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),sl(O,"class","flex justify-center"),sl(O,"href","/huggingface-course/marian-finetuned-kde4-en-to-fr"),Sn(Y.src,Al="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/language_tags.png")||sl(Y,"src",Al),sl(Y,"alt","Language available for the KDE4 dataset."),sl(Y,"width","100%")},m(l,t){pp(document.head,p),s(l,b,t),s(l,r,t),s(l,d,t),U(g,l,t),s(l,w,t),U(G,l,t),s(l,x,t),U(W,l,t),s(l,Z,t),Rs[C].m(l,t),s(l,V,t),s(l,Ml,t),s(l,N,t),s(l,v,t),s(l,Ul,t),U(Q,l,t),s(l,z,t),s(l,A,t),s(l,ul,t),s(l,E,t),s(l,K,t),s(l,X,t),s(l,nl,t),s(l,R,t),s(l,f,t),s(l,k,t),s(l,Jl,t),s(l,O,t),s(l,dl,t),s(l,F,t),s(l,bl,t),U(S,l,t),s(l,hl,t),s(l,q,t),s(l,ml,t),U(il,l,t),s(l,Cl,t),s(l,D,t),s(l,Il,t),U(L,l,t),s(l,$l,t),s(l,P,t),s(l,gl,t),s(l,Y,t),s(l,ol,t),s(l,cl,t),s(l,Tl,t),U(yl,l,t),s(l,Zl,t),U(i,l,t),s(l,$,t),s(l,wl,t),s(l,Hl,t),U(M,l,t),s(l,I,t),U(ee,l,t),s(l,Ks,t),s(l,se,t),s(l,Os,t),U(te,l,t),s(l,lt,t),s(l,ne,t),s(l,et,t),U(ae,l,t),s(l,st,t),U(pe,l,t),s(l,tt,t),s(l,Me,t),s(l,nt,t),U(re,l,t),s(l,at,t),U(ie,l,t),s(l,pt,t),s(l,ce,t),s(l,Mt,t),U(ye,l,t),s(l,rt,t),U(Je,l,t),s(l,it,t),s(l,me,t),s(l,ct,t),U(oe,l,t),s(l,yt,t),U(Te,l,t),s(l,Jt,t),s(l,Ue,t),s(l,mt,t),U(ue,l,t),s(l,ot,t),U(Dl,l,t),s(l,Tt,t),U(je,l,t),s(l,Ut,t),U(we,l,t),s(l,ut,t),s(l,fe,t),s(l,jt,t),U(de,l,t),s(l,wt,t),s(l,be,t),s(l,ft,t),U(Ll,l,t),s(l,dt,t),s(l,he,t),s(l,bt,t),s(l,Ce,t),s(l,ht,t),U(Ie,l,t),s(l,Ct,t),s(l,$e,t),s(l,It,t),s(l,ge,t),s(l,$t,t),s(l,Ze,t),s(l,gt,t),U(_e,l,t),s(l,Zt,t),s(l,ke,t),s(l,_t,t),U(Ge,l,t),s(l,kt,t),U(xe,l,t),s(l,Gt,t),s(l,Be,t),s(l,xt,t),s(l,We,t),s(l,Bt,t),U(Re,l,t),s(l,Wt,t),s(l,Xe,t),s(l,Rt,t),U(Pl,l,t),s(l,Xt,t),U(Kl,l,t),s(l,Vt,t),s(l,Ve,t),s(l,Nt,t),U(Ne,l,t),s(l,vt,t),s(l,ve,t),s(l,Qt,t),Xs[Gl].m(l,t),s(l,Es,t),s(l,Qe,t),s(l,zt,t),U(ze,l,t),s(l,At,t),s(l,Ae,t),s(l,Et,t),s(l,Ee,t),s(l,Yt,t),Vs[Bl].m(l,t),s(l,Ys,t),s(l,Ye,t),s(l,Ht,t),U(He,l,t),s(l,Ft,t),U(Fe,l,t),s(l,St,t),s(l,Se,t),s(l,qt,t),U(qe,l,t),s(l,Dt,t),U(De,l,t),s(l,Lt,t),s(l,Le,t),s(l,Pt,t),U(Pe,l,t),s(l,Kt,t),U(Ke,l,t),s(l,Ot,t),s(l,Oe,t),s(l,ln,t),U(ls,l,t),s(l,en,t),U(es,l,t),s(l,sn,t),Ns[Rl].m(l,t),s(l,Hs,t),U(ss,l,t),s(l,tn,t),U(ts,l,t),s(l,nn,t),fl&&fl.m(l,t),s(l,Fs,t),s(l,ns,t),s(l,an,t),s(l,as,t),s(l,pn,t),U(ps,l,t),s(l,Mn,t),s(l,Ms,t),s(l,rn,t),U(rs,l,t),s(l,cn,t),s(l,is,t),s(l,yn,t),s(l,cs,t),s(l,Jn,t),U(ys,l,t),s(l,mn,t),U(Js,l,t),s(l,on,t),s(l,ms,t),s(l,Tn,t),U(os,l,t),s(l,Un,t),U(Ts,l,t),s(l,un,t),U(Us,l,t),s(l,jn,t),U(us,l,t),s(l,wn,t),s(l,js,t),s(l,fn,t),vs[Vl].m(l,t),s(l,Ss,t),s(l,ws,t),s(l,dn,t),U(fs,l,t),s(l,bn,t),s(l,ds,t),s(l,hn,t),U(bs,l,t),s(l,Cn,t),s(l,hs,t),s(l,In,t),s(l,Cs,t),s(l,$n,t),U(Is,l,t),s(l,gn,t),Qs[vl].m(l,t),s(l,qs,t),pl&&pl.m(l,t),s(l,Ds,t),U($s,l,t),s(l,Zn,t),s(l,gs,t),s(l,_n,t),U(Zs,l,t),s(l,kn,t),U(_s,l,t),s(l,Gn,t),s(l,ks,t),s(l,xn,t),U(Gs,l,t),s(l,Bn,t),U(xs,l,t),s(l,Wn,t),s(l,Bs,t),s(l,Rn,t),U(Ol,l,t),s(l,Xn,t),U(Ws,l,t),s(l,Vn,t),s(l,Ps,t),Nn=!0},p(l,[t]){const Fa={};t&1&&(Fa.fw=l[0]),g.$set(Fa);let zn=C;C=Ra(l),C!==zn&&(As(),y(Rs[zn],1,1,()=>{Rs[zn]=null}),zs(),B=Rs[C],B||(B=Rs[C]=Wa[C](l),B.c()),c(B,1),B.m(V.parentNode,V));const Sa={};t&2&&(Sa.$$scope={dirty:t,ctx:l}),Dl.$set(Sa);const qa={};t&2&&(qa.$$scope={dirty:t,ctx:l}),Ll.$set(qa);const Da={};t&2&&(Da.$$scope={dirty:t,ctx:l}),Pl.$set(Da);const La={};t&2&&(La.$$scope={dirty:t,ctx:l}),Kl.$set(La);let An=Gl;Gl=Va(l),Gl!==An&&(As(),y(Xs[An],1,1,()=>{Xs[An]=null}),zs(),xl=Xs[Gl],xl||(xl=Xs[Gl]=Xa[Gl](l),xl.c()),c(xl,1),xl.m(Es.parentNode,Es));let En=Bl;Bl=va(l),Bl!==En&&(As(),y(Vs[En],1,1,()=>{Vs[En]=null}),zs(),Wl=Vs[Bl],Wl||(Wl=Vs[Bl]=Na[Bl](l),Wl.c()),c(Wl,1),Wl.m(Ys.parentNode,Ys));let Yn=Rl;Rl=za(l),Rl!==Yn&&(As(),y(Ns[Yn],1,1,()=>{Ns[Yn]=null}),zs(),Xl=Ns[Rl],Xl||(Xl=Ns[Rl]=Qa[Rl](l),Xl.c()),c(Xl,1),Xl.m(Hs.parentNode,Hs)),l[0]==="pt"?fl||(fl=Ka(),fl.c(),fl.m(Fs.parentNode,Fs)):fl&&(fl.d(1),fl=null);let Hn=Vl;Vl=Ea(l),Vl!==Hn&&(As(),y(vs[Hn],1,1,()=>{vs[Hn]=null}),zs(),Nl=vs[Vl],Nl||(Nl=vs[Vl]=Aa[Vl](l),Nl.c()),c(Nl,1),Nl.m(Ss.parentNode,Ss));let Fn=vl;vl=Ha(l),vl!==Fn&&(As(),y(Qs[Fn],1,1,()=>{Qs[Fn]=null}),zs(),Ql=Qs[vl],Ql||(Ql=Qs[vl]=Ya[vl](l),Ql.c()),c(Ql,1),Ql.m(qs.parentNode,qs)),l[0]==="pt"?pl?t&1&&c(pl,1):(pl=Oa(),pl.c(),c(pl,1),pl.m(Ds.parentNode,Ds)):pl&&(As(),y(pl,1,1,()=>{pl=null}),zs());const Pa={};t&2&&(Pa.$$scope={dirty:t,ctx:l}),Ol.$set(Pa)},i(l){Nn||(c(g.$$.fragment,l),c(G.$$.fragment,l),c(W.$$.fragment,l),c(B),c(Q.$$.fragment,l),c(S.$$.fragment,l),c(il.$$.fragment,l),c(L.$$.fragment,l),c(yl.$$.fragment,l),c(i.$$.fragment,l),c(M.$$.fragment,l),c(ee.$$.fragment,l),c(te.$$.fragment,l),c(ae.$$.fragment,l),c(pe.$$.fragment,l),c(re.$$.fragment,l),c(ie.$$.fragment,l),c(ye.$$.fragment,l),c(Je.$$.fragment,l),c(oe.$$.fragment,l),c(Te.$$.fragment,l),c(ue.$$.fragment,l),c(Dl.$$.fragment,l),c(je.$$.fragment,l),c(we.$$.fragment,l),c(de.$$.fragment,l),c(Ll.$$.fragment,l),c(Ie.$$.fragment,l),c(_e.$$.fragment,l),c(Ge.$$.fragment,l),c(xe.$$.fragment,l),c(Re.$$.fragment,l),c(Pl.$$.fragment,l),c(Kl.$$.fragment,l),c(Ne.$$.fragment,l),c(xl),c(ze.$$.fragment,l),c(Wl),c(He.$$.fragment,l),c(Fe.$$.fragment,l),c(qe.$$.fragment,l),c(De.$$.fragment,l),c(Pe.$$.fragment,l),c(Ke.$$.fragment,l),c(ls.$$.fragment,l),c(es.$$.fragment,l),c(Xl),c(ss.$$.fragment,l),c(ts.$$.fragment,l),c(ps.$$.fragment,l),c(rs.$$.fragment,l),c(ys.$$.fragment,l),c(Js.$$.fragment,l),c(os.$$.fragment,l),c(Ts.$$.fragment,l),c(Us.$$.fragment,l),c(us.$$.fragment,l),c(Nl),c(fs.$$.fragment,l),c(bs.$$.fragment,l),c(Is.$$.fragment,l),c(Ql),c(pl),c($s.$$.fragment,l),c(Zs.$$.fragment,l),c(_s.$$.fragment,l),c(Gs.$$.fragment,l),c(xs.$$.fragment,l),c(Ol.$$.fragment,l),c(Ws.$$.fragment,l),Nn=!0)},o(l){y(g.$$.fragment,l),y(G.$$.fragment,l),y(W.$$.fragment,l),y(B),y(Q.$$.fragment,l),y(S.$$.fragment,l),y(il.$$.fragment,l),y(L.$$.fragment,l),y(yl.$$.fragment,l),y(i.$$.fragment,l),y(M.$$.fragment,l),y(ee.$$.fragment,l),y(te.$$.fragment,l),y(ae.$$.fragment,l),y(pe.$$.fragment,l),y(re.$$.fragment,l),y(ie.$$.fragment,l),y(ye.$$.fragment,l),y(Je.$$.fragment,l),y(oe.$$.fragment,l),y(Te.$$.fragment,l),y(ue.$$.fragment,l),y(Dl.$$.fragment,l),y(je.$$.fragment,l),y(we.$$.fragment,l),y(de.$$.fragment,l),y(Ll.$$.fragment,l),y(Ie.$$.fragment,l),y(_e.$$.fragment,l),y(Ge.$$.fragment,l),y(xe.$$.fragment,l),y(Re.$$.fragment,l),y(Pl.$$.fragment,l),y(Kl.$$.fragment,l),y(Ne.$$.fragment,l),y(xl),y(ze.$$.fragment,l),y(Wl),y(He.$$.fragment,l),y(Fe.$$.fragment,l),y(qe.$$.fragment,l),y(De.$$.fragment,l),y(Pe.$$.fragment,l),y(Ke.$$.fragment,l),y(ls.$$.fragment,l),y(es.$$.fragment,l),y(Xl),y(ss.$$.fragment,l),y(ts.$$.fragment,l),y(ps.$$.fragment,l),y(rs.$$.fragment,l),y(ys.$$.fragment,l),y(Js.$$.fragment,l),y(os.$$.fragment,l),y(Ts.$$.fragment,l),y(Us.$$.fragment,l),y(us.$$.fragment,l),y(Nl),y(fs.$$.fragment,l),y(bs.$$.fragment,l),y(Is.$$.fragment,l),y(Ql),y(pl),y($s.$$.fragment,l),y(Zs.$$.fragment,l),y(_s.$$.fragment,l),y(Gs.$$.fragment,l),y(xs.$$.fragment,l),y(Ol.$$.fragment,l),y(Ws.$$.fragment,l),Nn=!1},d(l){l&&(e(b),e(r),e(d),e(w),e(x),e(Z),e(V),e(Ml),e(N),e(v),e(Ul),e(z),e(A),e(ul),e(E),e(K),e(X),e(nl),e(R),e(f),e(k),e(Jl),e(O),e(dl),e(F),e(bl),e(hl),e(q),e(ml),e(Cl),e(D),e(Il),e($l),e(P),e(gl),e(Y),e(ol),e(cl),e(Tl),e(Zl),e($),e(wl),e(Hl),e(I),e(Ks),e(se),e(Os),e(lt),e(ne),e(et),e(st),e(tt),e(Me),e(nt),e(at),e(pt),e(ce),e(Mt),e(rt),e(it),e(me),e(ct),e(yt),e(Jt),e(Ue),e(mt),e(ot),e(Tt),e(Ut),e(ut),e(fe),e(jt),e(wt),e(be),e(ft),e(dt),e(he),e(bt),e(Ce),e(ht),e(Ct),e($e),e(It),e(ge),e($t),e(Ze),e(gt),e(Zt),e(ke),e(_t),e(kt),e(Gt),e(Be),e(xt),e(We),e(Bt),e(Wt),e(Xe),e(Rt),e(Xt),e(Vt),e(Ve),e(Nt),e(vt),e(ve),e(Qt),e(Es),e(Qe),e(zt),e(At),e(Ae),e(Et),e(Ee),e(Yt),e(Ys),e(Ye),e(Ht),e(Ft),e(St),e(Se),e(qt),e(Dt),e(Lt),e(Le),e(Pt),e(Kt),e(Ot),e(Oe),e(ln),e(en),e(sn),e(Hs),e(tn),e(nn),e(Fs),e(ns),e(an),e(as),e(pn),e(Mn),e(Ms),e(rn),e(cn),e(is),e(yn),e(cs),e(Jn),e(mn),e(on),e(ms),e(Tn),e(Un),e(un),e(jn),e(wn),e(js),e(fn),e(Ss),e(ws),e(dn),e(bn),e(ds),e(hn),e(Cn),e(hs),e(In),e(Cs),e($n),e(gn),e(qs),e(Ds),e(Zn),e(gs),e(_n),e(kn),e(Gn),e(ks),e(xn),e(Bn),e(Wn),e(Bs),e(Rn),e(Xn),e(Vn),e(Ps)),e(p),u(g,l),u(G,l),u(W,l),Rs[C].d(l),u(Q,l),u(S,l),u(il,l),u(L,l),u(yl,l),u(i,l),u(M,l),u(ee,l),u(te,l),u(ae,l),u(pe,l),u(re,l),u(ie,l),u(ye,l),u(Je,l),u(oe,l),u(Te,l),u(ue,l),u(Dl,l),u(je,l),u(we,l),u(de,l),u(Ll,l),u(Ie,l),u(_e,l),u(Ge,l),u(xe,l),u(Re,l),u(Pl,l),u(Kl,l),u(Ne,l),Xs[Gl].d(l),u(ze,l),Vs[Bl].d(l),u(He,l),u(Fe,l),u(qe,l),u(De,l),u(Pe,l),u(Ke,l),u(ls,l),u(es,l),Ns[Rl].d(l),u(ss,l),u(ts,l),fl&&fl.d(l),u(ps,l),u(rs,l),u(ys,l),u(Js,l),u(os,l),u(Ts,l),u(Us,l),u(us,l),vs[Vl].d(l),u(fs,l),u(bs,l),u(Is,l),Qs[vl].d(l),pl&&pl.d(l),u($s,l),u(Zs,l),u(_s,l),u(Gs,l),u(xs,l),u(Ol,l),u(Ws,l)}}}const Gp='{"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 xp(_,p,b){let r="pt";return sp(()=>{const d=new URLSearchParams(window.location.search);b(0,r=d.get("fw")||"pt")}),[r]}class zp extends tp{constructor(p){super(),np(this,p,xp,kp,ep,{})}}export{zp as component};
