import{s as Pa,f as Yn,o as Ka,n as ql}from"../chunks/scheduler.37c15a92.js";import{S as Oa,i as lp,g as J,s as n,r as T,A as ep,h as m,f as e,c as a,j as Rn,u as o,x as j,k as K,y as sp,a as s,v as U,t as y,b as Qs,d as c,w as u,p as As}from"../chunks/index.2bf4358c.js";import{T as ee}from"../chunks/Tip.363c041f.js";import{Y as Vn}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as La}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{F as tp}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as kl}from"../chunks/Heading.8ada512a.js";function np(_){let p,b;return p=new La({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section4_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section4_tf.ipynb"}]}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,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 ap(_){let p,b;return p=new La({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section4_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section4_pt.ipynb"}]}}),{c(){T(p.$$.fragment)},l(r){o(p.$$.fragment,r)},m(r,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 pp(_){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:ql,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:ql,d(r){r&&e(p)}}}function rp(_){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:ql,d(r){r&&e(p)}}}function ip(_){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:ql,d(r){r&&e(p)}}}function cp(_){let p,b,r,d="首先，我們需要一個實際的模型來進行微調。 我們將使用通常的 <code>AutoModel</code> API：",Z,w,k,G,x;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}}),G=new ee({props:{warning:!1,$$slots:{default:[Jp]},$$scope:{ctx:_}}}),{c(){T(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,Z=n(),T(w.$$.fragment),k=n(),T(G.$$.fragment)},l($){o(p.$$.fragment,$),b=a($),r=m($,"P",{"data-svelte-h":!0}),j(r)!=="svelte-7cd7gl"&&(r.innerHTML=d),Z=a($),o(w.$$.fragment,$),k=a($),o(G.$$.fragment,$)},m($,C){U(p,$,C),s($,b,C),s($,r,C),s($,Z,C),U(w,$,C),s($,k,C),U(G,$,C),x=!0},i($){x||(c(p.$$.fragment,$),c(w.$$.fragment,$),c(G.$$.fragment,$),x=!0)},o($){y(p.$$.fragment,$),y(w.$$.fragment,$),y(G.$$.fragment,$),x=!1},d($){$&&(e(b),e(r),e(Z),e(k)),u(p,$),u(w,$),u(G,$)}}}function yp(_){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> 方法來預測輸入的輸出。 當我們討論評估指標時，我們將更詳細地探討這一點。',Z,w,k="首先，我們需要一個實際的模型來進行微調。 我們將使用通常的 <code>AutoModel</code> API：",G,x,$;return p=new kl({props:{title:"使用 Trainer API 微調模型",local:"使用-trainer-api-微調模型",headingTag:"h2"}}),x=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)`,wrap:!1}}),{c(){T(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,Z=n(),w=J("p"),w.innerHTML=k,G=n(),T(x.$$.fragment)},l(C){o(p.$$.fragment,C),b=a(C),r=m(C,"P",{"data-svelte-h":!0}),j(r)!=="svelte-1b0v66z"&&(r.innerHTML=d),Z=a(C),w=m(C,"P",{"data-svelte-h":!0}),j(w)!=="svelte-7cd7gl"&&(w.innerHTML=k),G=a(C),o(x.$$.fragment,C)},m(C,W){U(p,C,W),s(C,b,W),s(C,r,W),s(C,Z,W),s(C,w,W),s(C,G,W),U(x,C,W),$=!0},i(C){$||(c(p.$$.fragment,C),c(x.$$.fragment,C),$=!0)},o(C){y(p.$$.fragment,C),y(x.$$.fragment,C),$=!1},d(C){C&&(e(b),e(r),e(Z),e(w),e(G)),u(p,C),u(x,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:ql,d(r){r&&e(p)}}}function mp(_){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(){T(p.$$.fragment)},l(r){o(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 Tp(_){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(){T(p.$$.fragment)},l(r){o(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 op(_){let p,b="我們現在可以使用 <code>data_collator</code> 將我們的每個數據集轉換為 <code>tf.data.Dataset</code>，準備好進行訓練：",r,d,Z;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(),T(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-ymdrgq"&&(p.innerHTML=b),r=a(w),o(d.$$.fragment,w)},m(w,k){s(w,p,k),s(w,r,k),U(d,w,k),Z=!0},i(w){Z||(c(d.$$.fragment,w),Z=!0)},o(w){y(d.$$.fragment,w),Z=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function Up(_){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:ql,o:ql,d(r){r&&e(p)}}}function qa(_){let p,b="<code>Seq2SeqTrainer</code> 添加到其超類 <code>Trainer</code> 的功能是在評估或預測期間使用 <code>generate()</code> 方法的能力。 在訓練期間，模型將使用帶有注意掩碼的“decoder_input_ids”，以確保它不使用預測的標記之後的標記，以加快訓練速度。 在推理過程中，我們將無法使用預測的標記之後的標記，因為我們沒有標籤，因此使用相同的設置使用帶有注意掩碼的“decoder_input_ids”，評估我們的模型是個好主意。",r,d,Z='正如我們在<a href="/course/chapter1/6">第一章</a>看到的，解碼器通過一個一個地預測標記來執行推理——這是🤗 Transformers 在幕後通過 <strong>generate()</strong> 方法實現的。如果我們設置 predict_with_generate=True，Seq2 Seq Trainer 將允許我們使用該方法進行評估。';return{c(){p=J("p"),p.innerHTML=b,r=n(),d=J("p"),d.innerHTML=Z},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=Z)},m(w,k){s(w,p,k),s(w,r,k),s(w,d,k)},d(w){w&&(e(p),e(r),e(d))}}}function up(_){let p,b="為了從模型輸出到度量可以使用的文本，我們將使用 <code>tokenizer.batch_decode()</code> 方法。 我們只需要清理標籤中的所有 <code>-100</code>（標記器將自動對填充標記執行相同操作）：",r,d,Z;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(),T(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-qycu9"&&(p.innerHTML=b),r=a(w),o(d.$$.fragment,w)},m(w,k){s(w,p,k),s(w,r,k),U(d,w,k),Z=!0},i(w){Z||(c(d.$$.fragment,w),Z=!0)},o(w){y(d.$$.fragment,w),Z=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function jp(_){let p,b="為了從模型輸出可以被評估基準可以使用的文本，我們將使用 <strong>tokenizer.batch_decode()</strong> 方法。我們只需要清理標籤中所有 <strong>-100</strong> （標記器會自動為填充標記做同樣的事情）：",r,d,Z;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(),T(d.$$.fragment)},l(w){p=m(w,"P",{"data-svelte-h":!0}),j(p)!=="svelte-199mhtm"&&(p.innerHTML=b),r=a(w),o(d.$$.fragment,w)},m(w,k){s(w,p,k),s(w,r,k),U(d,w,k),Z=!0},i(w){Z||(c(d.$$.fragment,w),Z=!0)},o(w){y(d.$$.fragment,w),Z=!1},d(w){w&&(e(p),e(r)),u(d,w)}}}function wp(_){let p,b="一旦完成，我們就可以定義我們的 <code>Seq2SeqTrainingArguments</code>。 與 <code>Trainer</code> 一樣，我們使用 <code>TrainingArguments</code> 的子類，其中包含更多可以設置的字段：",r,d,Z,w,k="除了通常的超參數（如學習率、訓練輪數、批次大小和一些權重衰減）之外，與我們在前幾節中看到的相比，這裡有一些變化：",G,x,$="<li>我們沒有設置任何定期評估，因為評估需要耗費一定的時間；我們只會在訓練開始之前和結束之後評估我們的模型一次。</li> <li>我們設置fp16=True，這可以加快支持fp16的 GPU 上的訓練速度。</li> <li>和上面我們討論的那樣，我們設置predict_with_generate=True</li> <li>我們用push_to_hub=True在每個 epoch 結束時將模型上傳到 Hub。</li>",C,W,P='請注意，您可以使用 <code>hub_model_id</code> 參數指定要推送到的存儲庫的名稱（當您想把模型推送到指定的組織的時候，您也必須使用此參數）。 例如，當我們將模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> 組織</a> 時，我們添加了 <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en- to-fr&quot;</code> 到 <code>Seq2SeqTrainingArguments</code>。 默認情況下，使用的存儲庫將在您的命名空間中，並以您設置的輸出目錄命名，因此這裡將是 <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code>。',Tl,Q,Y,S,N="最後，我們需要將所有內容傳遞給 <strong>Seq2SeqTrainer</strong> ：",ol,A,E,q,v="在訓練之前，我們將首先查看我們的模型獲得的分數，以仔細檢查我們的微調沒有讓事情變得更糟。此命令需要一些時間，因此您可以在執行時喝杯咖啡：",gl,D,X,O,z,V,Ml="BLEU的分數還不錯，這反映了我們的模型已經擅長將英語句子翻譯成法語句子。",ll,R,f="接下來是訓練，這也需要一些時間：",B,L,Ul,yl,rl="請注意，當訓練發生時，每次保存模型時（這裡是每個時期），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",Gl,el,Zl="訓練完成後，我們再次評估我們的模型——希望我們會看到 BLEU 分數有所改善！",hl,H,xl,sl,ul,Jl,il="這是近 14 點的改進，這很棒。",Bl,tl,_l="最後，我們使用 <strong>push_to_hub()</strong> 方法來確保我們上傳模型的最新版本。這 <strong>Trainer</strong> 還創建了一張包含所有評估結果的模型卡並上傳。此模型卡包含可幫助模型中心為推理演示選擇小部件的元數據。通常不需要做額外的更改，因為它可以從模型類中推斷出正確的小部件，但在這種情況下，相同的模型類可以用於所有類型的序列到序列問題，所以我們指定它是一個翻譯模型：",Cl,F,Wl,nl,Il="如果您想檢查命令執行的結果，此命令將返回它剛剛執行的提交的 URL，可以打開url進行檢查：",Rl,al,jl,wl,fl="在此階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。您已成功微調翻譯任務的模型 - 恭喜！",dl,ml,cl="如果您想更深入地瞭解訓練循環，我們現在將向您展示如何使用 🤗 Accelerate 做同樣的事情。",$l;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}}),Q=new ee({props:{$$slots:{default:[dp]},$$scope:{ctx:_}}}),A=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBdHJhaW5lciUyMCUzRCUyMFNlcTJTZXFUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    model,
    args,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    data_collator=data_collator,
    tokenizer=tokenizer,
    compute_metrics=compute_metrics,
)`,wrap:!1}}),D=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X3RhcmdldF9sZW5ndGgp",highlighted:"trainer.evaluate(max_length=max_target_length)",wrap:!1}}),O=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}}),L=new h({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),H=new h({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X3RhcmdldF9sZW5ndGgp",highlighted:"trainer.evaluate(max_length=max_target_length)",wrap:!1}}),sl=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}}),F=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}}),al=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(),T(d.$$.fragment),Z=n(),w=J("p"),w.textContent=k,G=n(),x=J("ul"),x.innerHTML=$,C=n(),W=J("p"),W.innerHTML=P,Tl=n(),T(Q.$$.fragment),Y=n(),S=J("p"),S.innerHTML=N,ol=n(),T(A.$$.fragment),E=n(),q=J("p"),q.textContent=v,gl=n(),T(D.$$.fragment),X=n(),T(O.$$.fragment),z=n(),V=J("p"),V.textContent=Ml,ll=n(),R=J("p"),R.textContent=f,B=n(),T(L.$$.fragment),Ul=n(),yl=J("p"),yl.textContent=rl,Gl=n(),el=J("p"),el.textContent=Zl,hl=n(),T(H.$$.fragment),xl=n(),T(sl.$$.fragment),ul=n(),Jl=J("p"),Jl.textContent=il,Bl=n(),tl=J("p"),tl.innerHTML=_l,Cl=n(),T(F.$$.fragment),Wl=n(),nl=J("p"),nl.textContent=Il,Rl=n(),T(al.$$.fragment),jl=n(),wl=J("p"),wl.textContent=fl,dl=n(),ml=J("p"),ml.textContent=cl},l(i){p=m(i,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1omuxw1"&&(p.innerHTML=b),r=a(i),o(d.$$.fragment,i),Z=a(i),w=m(i,"P",{"data-svelte-h":!0}),j(w)!=="svelte-ote8hl"&&(w.textContent=k),G=a(i),x=m(i,"UL",{"data-svelte-h":!0}),j(x)!=="svelte-636x0w"&&(x.innerHTML=$),C=a(i),W=m(i,"P",{"data-svelte-h":!0}),j(W)!=="svelte-j1rmx5"&&(W.innerHTML=P),Tl=a(i),o(Q.$$.fragment,i),Y=a(i),S=m(i,"P",{"data-svelte-h":!0}),j(S)!=="svelte-1lrs60s"&&(S.innerHTML=N),ol=a(i),o(A.$$.fragment,i),E=a(i),q=m(i,"P",{"data-svelte-h":!0}),j(q)!=="svelte-16xy9m0"&&(q.textContent=v),gl=a(i),o(D.$$.fragment,i),X=a(i),o(O.$$.fragment,i),z=a(i),V=m(i,"P",{"data-svelte-h":!0}),j(V)!=="svelte-e5x4k4"&&(V.textContent=Ml),ll=a(i),R=m(i,"P",{"data-svelte-h":!0}),j(R)!=="svelte-1gqyllf"&&(R.textContent=f),B=a(i),o(L.$$.fragment,i),Ul=a(i),yl=m(i,"P",{"data-svelte-h":!0}),j(yl)!=="svelte-1jqup3e"&&(yl.textContent=rl),Gl=a(i),el=m(i,"P",{"data-svelte-h":!0}),j(el)!=="svelte-9aj88c"&&(el.textContent=Zl),hl=a(i),o(H.$$.fragment,i),xl=a(i),o(sl.$$.fragment,i),ul=a(i),Jl=m(i,"P",{"data-svelte-h":!0}),j(Jl)!=="svelte-e9lkmq"&&(Jl.textContent=il),Bl=a(i),tl=m(i,"P",{"data-svelte-h":!0}),j(tl)!=="svelte-1n6mjia"&&(tl.innerHTML=_l),Cl=a(i),o(F.$$.fragment,i),Wl=a(i),nl=m(i,"P",{"data-svelte-h":!0}),j(nl)!=="svelte-1i1ov13"&&(nl.textContent=Il),Rl=a(i),o(al.$$.fragment,i),jl=a(i),wl=m(i,"P",{"data-svelte-h":!0}),j(wl)!=="svelte-ldmk0i"&&(wl.textContent=fl),dl=a(i),ml=m(i,"P",{"data-svelte-h":!0}),j(ml)!=="svelte-1a0w12w"&&(ml.textContent=cl)},m(i,g){s(i,p,g),s(i,r,g),U(d,i,g),s(i,Z,g),s(i,w,g),s(i,G,g),s(i,x,g),s(i,C,g),s(i,W,g),s(i,Tl,g),U(Q,i,g),s(i,Y,g),s(i,S,g),s(i,ol,g),U(A,i,g),s(i,E,g),s(i,q,g),s(i,gl,g),U(D,i,g),s(i,X,g),U(O,i,g),s(i,z,g),s(i,V,g),s(i,ll,g),s(i,R,g),s(i,B,g),U(L,i,g),s(i,Ul,g),s(i,yl,g),s(i,Gl,g),s(i,el,g),s(i,hl,g),U(H,i,g),s(i,xl,g),U(sl,i,g),s(i,ul,g),s(i,Jl,g),s(i,Bl,g),s(i,tl,g),s(i,Cl,g),U(F,i,g),s(i,Wl,g),s(i,nl,g),s(i,Rl,g),U(al,i,g),s(i,jl,g),s(i,wl,g),s(i,dl,g),s(i,ml,g),$l=!0},i(i){$l||(c(d.$$.fragment,i),c(Q.$$.fragment,i),c(A.$$.fragment,i),c(D.$$.fragment,i),c(O.$$.fragment,i),c(L.$$.fragment,i),c(H.$$.fragment,i),c(sl.$$.fragment,i),c(F.$$.fragment,i),c(al.$$.fragment,i),$l=!0)},o(i){y(d.$$.fragment,i),y(Q.$$.fragment,i),y(A.$$.fragment,i),y(D.$$.fragment,i),y(O.$$.fragment,i),y(L.$$.fragment,i),y(H.$$.fragment,i),y(sl.$$.fragment,i),y(F.$$.fragment,i),y(al.$$.fragment,i),$l=!1},d(i){i&&(e(p),e(r),e(Z),e(w),e(G),e(x),e(C),e(W),e(Tl),e(Y),e(S),e(ol),e(E),e(q),e(gl),e(X),e(z),e(V),e(ll),e(R),e(B),e(Ul),e(yl),e(Gl),e(el),e(hl),e(xl),e(ul),e(Jl),e(Bl),e(tl),e(Cl),e(Wl),e(nl),e(Rl),e(jl),e(wl),e(dl),e(ml)),u(d,i),u(Q,i),u(A,i),u(D,i),u(O,i),u(L,i),u(H,i),u(sl,i),u(F,i),u(al,i)}}}function fp(_){let p,b="在我們開始之前，讓我們看看我們在沒有任何訓練的情況下從我們的模型中得到了什麼樣的結果：",r,d,Z,w,k,G,x="一旦完成，我們就可以準備編譯和訓練模型所需的一切。 注意當使用 <code>tf.keras.mixed_precision.set_global_policy(&quot;mixed_float16&quot;)</code>時——這將告訴 Keras 使用 float16 進行訓練，這可以顯著提高支持它的 GPU（Nvidia 20xx/V100 或更高版本）的速度。",$,C,W,P,Tl='接下來，我們定義一個 <code>PushToHubCallback</code> 以便在訓練期間將我們的模型上傳到 Hub，正如我們在 <a href="(/course/chapter7/2)">第 2 節</a> 中看到的，然後我們只需擬合模型時添加該回調函數：',Q,Y,S,N,ol='請注意，您可以使用 <code>hub_model_id</code> 參數指定要推送到的存儲庫的名稱（當您想把模型推送到指定的組織的時候，您也必須使用此參數）。 例如，當我們將模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> 組織</a> 時，我們添加了 <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en- to-fr&quot;</code> 到 <code>Seq2SeqTrainingArguments</code>。 默認情況下，使用的存儲庫將在您的命名空間中，並以您設置的輸出目錄命名，因此這裡將是 <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code>。',A,E,q,v,gl="最後，讓我們看看訓練結束後我們的指標是什麼樣的：",D,X,O,z,V,Ml,ll="在這個階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。 您已經成功地微調了翻譯任務中的模型——恭喜！",R;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}}),Y=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMm1hcmlhbi1maW5ldHVuZWQta2RlNC1lbi10by1mciUyMiUyQyUyMHRva2VuaXplciUzRHRva2VuaXplciUwQSklMEElMEFtb2RlbC5maXQoJTBBJTIwJTIwJTIwJTIwdGZfdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHZhbGlkYXRpb25fZGF0YSUzRHRmX2V2YWxfZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGNhbGxiYWNrcyUzRCU1QmNhbGxiYWNrJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXBvY2hzJTNEbnVtX2Vwb2NocyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

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

model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=[callback],
    epochs=num_epochs,
)`,wrap:!1}}),E=new ee({props:{$$slots:{default:[bp]},$$scope:{ctx:_}}}),X=new h({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),z=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(),T(d.$$.fragment),Z=n(),T(w.$$.fragment),k=n(),G=J("p"),G.innerHTML=x,$=n(),T(C.$$.fragment),W=n(),P=J("p"),P.innerHTML=Tl,Q=n(),T(Y.$$.fragment),S=n(),N=J("p"),N.innerHTML=ol,A=n(),T(E.$$.fragment),q=n(),v=J("p"),v.textContent=gl,D=n(),T(X.$$.fragment),O=n(),T(z.$$.fragment),V=n(),Ml=J("p"),Ml.textContent=ll},l(f){p=m(f,"P",{"data-svelte-h":!0}),j(p)!=="svelte-1azi1sh"&&(p.textContent=b),r=a(f),o(d.$$.fragment,f),Z=a(f),o(w.$$.fragment,f),k=a(f),G=m(f,"P",{"data-svelte-h":!0}),j(G)!=="svelte-1ovc25p"&&(G.innerHTML=x),$=a(f),o(C.$$.fragment,f),W=a(f),P=m(f,"P",{"data-svelte-h":!0}),j(P)!=="svelte-1sdejyy"&&(P.innerHTML=Tl),Q=a(f),o(Y.$$.fragment,f),S=a(f),N=m(f,"P",{"data-svelte-h":!0}),j(N)!=="svelte-j1rmx5"&&(N.innerHTML=ol),A=a(f),o(E.$$.fragment,f),q=a(f),v=m(f,"P",{"data-svelte-h":!0}),j(v)!=="svelte-14po97"&&(v.textContent=gl),D=a(f),o(X.$$.fragment,f),O=a(f),o(z.$$.fragment,f),V=a(f),Ml=m(f,"P",{"data-svelte-h":!0}),j(Ml)!=="svelte-1uqim6t"&&(Ml.textContent=ll)},m(f,B){s(f,p,B),s(f,r,B),U(d,f,B),s(f,Z,B),U(w,f,B),s(f,k,B),s(f,G,B),s(f,$,B),U(C,f,B),s(f,W,B),s(f,P,B),s(f,Q,B),U(Y,f,B),s(f,S,B),s(f,N,B),s(f,A,B),U(E,f,B),s(f,q,B),s(f,v,B),s(f,D,B),U(X,f,B),s(f,O,B),U(z,f,B),s(f,V,B),s(f,Ml,B),R=!0},i(f){R||(c(d.$$.fragment,f),c(w.$$.fragment,f),c(C.$$.fragment,f),c(Y.$$.fragment,f),c(E.$$.fragment,f),c(X.$$.fragment,f),c(z.$$.fragment,f),R=!0)},o(f){y(d.$$.fragment,f),y(w.$$.fragment,f),y(C.$$.fragment,f),y(Y.$$.fragment,f),y(E.$$.fragment,f),y(X.$$.fragment,f),y(z.$$.fragment,f),R=!1},d(f){f&&(e(p),e(r),e(Z),e(k),e(G),e($),e(W),e(P),e(Q),e(S),e(N),e(A),e(q),e(v),e(D),e(O),e(V),e(Ml)),u(d,f),u(w,f),u(C,f),u(Y,f),u(E,f),u(X,f),u(z,f)}}}function dp(_){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:ql,d(r){r&&e(p)}}}function bp(_){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:ql,d(r){r&&e(p)}}}function Da(_){let p,b,r,d='現在讓我們看一下完整的訓練循環，以便您可以輕鬆自定義所需的部分。它看起來很像我們在<a href="/course/chapter7/2">本章第二節</a>和<a href="/course/chapter3/4">第三章第四小節</a>所做的。',Z,w,k,G,x="您已經多次看到所有這些，因此這一塊會簡略進行。首先我們將構建我們的數據集的<strong>DataLoader</strong> ，在將數據集設置為 <strong>torch</strong> 格式，我們就得到了 PyTorch 張量：",$,C,W,P,Tl="接下來我們重新實例化我們的模型，以確保我們不會繼續上一節的微調，而是再次從預訓練模型開始重新訓練：",Q,Y,S,N,ol="然後我們需要一個優化器：",A,E,q,v,gl="一旦我們擁有所有這些對象，我們就可以將它們發送到 <code>accelerator.prepare()</code> 方法。 請記住，如果您想在 Colab 筆記本訓練中使用TPU，則需要將所有這些代碼移動到訓練函數中，並且不應執行任何實例化“加速器”的對象。",D,X,O,z,V="現在我們已經發送了我們的 <strong>train_dataloader</strong> 到 <strong>accelerator.prepare()</strong> ，我們可以使用它的長度來計算訓練步驟的數量。請記住，我們應該始終在準備好數據加載器後執行此操作，因為該方法會更改 <strong>DataLoader</strong> .我們使用從學習率衰減到 0 的經典線性學習率調度：",Ml,ll,R,f,B="最後，要將我們的模型推送到 Hub，我們需要創建一個 <strong>Repository</strong> 工作文件夾中的對象。如果您尚未登錄，請先登錄 Hugging Face。我們將從我們想要為模型提供的模型 ID 中確定存儲庫名稱（您可以自由地用自己的選擇替換 <strong>repo_name</strong> ；它需要包含您的用戶名，可以使用<strong>get_full_repo_name()</strong>函數的查看目前的repo_name）：",L,Ul,yl,rl,Gl,el,Zl="然後我們可以在本地文件夾中克隆該存儲庫。如果它已經存在，這個本地文件夾應該是我們正在使用的存儲庫的克隆：",hl,H,xl,sl,ul="我們現在可以通過調用 <strong>repo.push_to_hub()</strong> 方法上傳我們保存的任何內容 <strong>output_dir</strong> 。這將幫助我們在每個 epoch 結束時上傳過程中的模型。",Jl,il,Bl,tl,_l="我們現在準備編寫完整的訓練循環。為了簡化它的評估部分，我們定義了這個 <strong>postprocess()</strong> 函數接收預測結果和正確標籤並將它們轉換為我們 <strong>metric</strong> 對象所需要的字符串列表：",Cl,F,Wl,nl,Il='訓練循環看起來和<a href="/course/chapter7/2">本章第二節</a>與<a href="/course/chapter3">第三章</a>很像，在評估部分有一些不同 - 所以讓我們專注於這一點！',Rl,al,jl="首先要注意的是我們使用 <code>generate()</code> 方法來計算預測，但這是我們基礎模型上的一個方法，而不是包裝模型🤗 Accelerate 在 <code>prepare()</code> 方法中創建。 這就是為什麼我們先解包模型，然後調用這個方法。",wl,fl,dl='第二件事是，就像<a href="/course/chapter7/2">token 分類</a>，兩個進程可能將輸入和標籤填充為不同的形狀，因此我們在調用 <strong>gather()</strong> 方法之前使用 <strong>accelerator.pad_across_processes()</strong> 使預測和標籤具有相同的形狀。如果我們不這樣做，評估要麼出錯，要麼永遠在阻塞。',ml,cl,$l,i,g,Vl,Sl='完成此操作後，您應該有一個模型，其結果與使用 <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> 如果您想測試對訓練循環的任何調整，您可以通過編輯上面顯示的代碼直接實現它們！',Dl;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}}),Y=new h({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),E=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEFkYW1XJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhbVcobW9kZWwucGFyYW1ldGVycygpJTJDJTIwbHIlM0QyZS01KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW

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

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

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

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

model_name = <span class="hljs-string">&quot;marian-finetuned-kde4-en-to-fr-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),rl=new h({props:{code:"J3NndWdnZXIlMkZtYXJpYW4tZmluZXR1bmVkLWtkZTQtZW4tdG8tZnItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/marian-finetuned-kde4-en-to-fr-accelerate&#x27;</span>',wrap:!1}}),H=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"}}),F=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}}),cl=new h({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHJhaW5fZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvc3MlMjAlM0QlMjBvdXRwdXRzLmxvc3MlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhY2NlbGVyYXRvci5iYWNrd2FyZChsb3NzKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9wdGltaXplci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBscl9zY2hlZHVsZXIuc3RlcCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnplcm9fZ3JhZCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvZ3Jlc3NfYmFyLnVwZGF0ZSgxKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEV2YWx1YXRpb24lMEElMjAlMjAlMjAlMjBtb2RlbC5ldmFsKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHFkbShldmFsX2RhdGFsb2FkZXIpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdlbmVyYXRlZF90b2tlbnMlMjAlM0QlMjBhY2NlbGVyYXRvci51bndyYXBfbW9kZWwobW9kZWwpLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGJhdGNoJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXR0ZW50aW9uX21hc2slM0RiYXRjaCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDEyOCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBiYXRjaCU1QiUyMmxhYmVscyUyMiU1RCUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyME5lY2Vzc2FyeSUyMHRvJTIwcGFkJTIwcHJlZGljdGlvbnMlMjBhbmQlMjBsYWJlbHMlMjBmb3IlMjBiZWluZyUyMGdhdGhlcmVkJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ2VuZXJhdGVkX3Rva2VucyUyMCUzRCUyMGFjY2VsZXJhdG9yLnBhZF9hY3Jvc3NfcHJvY2Vzc2VzKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdlbmVyYXRlZF90b2tlbnMlMkMlMjBkaW0lM0QxJTJDJTIwcGFkX2luZGV4JTNEdG9rZW5pemVyLnBhZF90b2tlbl9pZCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBhY2NlbGVyYXRvci5wYWRfYWNyb3NzX3Byb2Nlc3NlcyhsYWJlbHMlMkMlMjBkaW0lM0QxJTJDJTIwcGFkX2luZGV4JTNELTEwMCklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9uc19nYXRoZXJlZCUyMCUzRCUyMGFjY2VsZXJhdG9yLmdhdGhlcihnZW5lcmF0ZWRfdG9rZW5zKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVsc19nYXRoZXJlZCUyMCUzRCUyMGFjY2VsZXJhdG9yLmdhdGhlcihsYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwcG9zdHByb2Nlc3MocHJlZGljdGlvbnNfZ2F0aGVyZWQlMkMlMjBsYWJlbHNfZ2F0aGVyZWQpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWV0cmljLmFkZF9iYXRjaChwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMpJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0cyUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKCklMEElMjAlMjAlMjAlMjBwcmludChmJTIyZXBvY2glMjAlN0JlcG9jaCU3RCUyQyUyMEJMRVUlMjBzY29yZSUzQSUyMCU3QnJlc3VsdHMlNUInc2NvcmUnJTVEJTNBLjJmJTdEJTIyKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFNhdmUlMjBhbmQlMjB1cGxvYWQlMEElMjAlMjAlMjAlMjBhY2NlbGVyYXRvci53YWl0X2Zvcl9ldmVyeW9uZSgpJTBBJTIwJTIwJTIwJTIwdW53cmFwcGVkX21vZGVsJTIwJTNEJTIwYWNjZWxlcmF0b3IudW53cmFwX21vZGVsKG1vZGVsKSUwQSUyMCUyMCUyMCUyMHVud3JhcHBlZF9tb2RlbC5zYXZlX3ByZXRyYWluZWQob3V0cHV0X2RpciUyQyUyMHNhdmVfZnVuY3Rpb24lM0RhY2NlbGVyYXRvci5zYXZlKSUwQSUyMCUyMCUyMCUyMGlmJTIwYWNjZWxlcmF0b3IuaXNfbWFpbl9wcm9jZXNzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdG9rZW5pemVyLnNhdmVfcHJldHJhaW5lZChvdXRwdXRfZGlyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJlcG8ucHVzaF90b19odWIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29tbWl0X21lc3NhZ2UlM0RmJTIyVHJhaW5pbmclMjBpbiUyMHByb2dyZXNzJTIwZXBvY2glMjAlN0JlcG9jaCU3RCUyMiUyQyUyMGJsb2NraW5nJTNERmFsc2UlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAp",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch

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

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

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

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

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

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

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

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

    <span class="hljs-comment"># Save and upload</span>
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    <span class="hljs-keyword">if</span> accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=<span class="hljs-string">f&quot;Training in progress epoch <span class="hljs-subst">{epoch}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
        )`,wrap:!1}}),i=new h({props:{code:"ZXBvY2glMjAwJTJDJTIwQkxFVSUyMHNjb3JlJTNBJTIwNTMuNDclMEFlcG9jaCUyMDElMkMlMjBCTEVVJTIwc2NvcmUlM0ElMjA1NC4yNCUwQWVwb2NoJTIwMiUyQyUyMEJMRVUlMjBzY29yZSUzQSUyMDU0LjQ0",highlighted:`epoch <span class="hljs-number">0</span>, BLEU score: <span class="hljs-number">53.47</span>
epoch <span class="hljs-number">1</span>, BLEU score: <span class="hljs-number">54.24</span>
epoch <span class="hljs-number">2</span>, BLEU score: <span class="hljs-number">54.44</span>`,wrap:!1}}),{c(){T(p.$$.fragment),b=n(),r=J("p"),r.innerHTML=d,Z=n(),T(w.$$.fragment),k=n(),G=J("p"),G.innerHTML=x,$=n(),T(C.$$.fragment),W=n(),P=J("p"),P.textContent=Tl,Q=n(),T(Y.$$.fragment),S=n(),N=J("p"),N.textContent=ol,A=n(),T(E.$$.fragment),q=n(),v=J("p"),v.innerHTML=gl,D=n(),T(X.$$.fragment),O=n(),z=J("p"),z.innerHTML=V,Ml=n(),T(ll.$$.fragment),R=n(),f=J("p"),f.innerHTML=B,L=n(),T(Ul.$$.fragment),yl=n(),T(rl.$$.fragment),Gl=n(),el=J("p"),el.textContent=Zl,hl=n(),T(H.$$.fragment),xl=n(),sl=J("p"),sl.innerHTML=ul,Jl=n(),T(il.$$.fragment),Bl=n(),tl=J("p"),tl.innerHTML=_l,Cl=n(),T(F.$$.fragment),Wl=n(),nl=J("p"),nl.innerHTML=Il,Rl=n(),al=J("p"),al.innerHTML=jl,wl=n(),fl=J("p"),fl.innerHTML=dl,ml=n(),T(cl.$$.fragment),$l=n(),T(i.$$.fragment),g=n(),Vl=J("p"),Vl.innerHTML=Sl},l(M){o(p.$$.fragment,M),b=a(M),r=m(M,"P",{"data-svelte-h":!0}),j(r)!=="svelte-1s6cy6j"&&(r.innerHTML=d),Z=a(M),o(w.$$.fragment,M),k=a(M),G=m(M,"P",{"data-svelte-h":!0}),j(G)!=="svelte-1sphalx"&&(G.innerHTML=x),$=a(M),o(C.$$.fragment,M),W=a(M),P=m(M,"P",{"data-svelte-h":!0}),j(P)!=="svelte-a97q0r"&&(P.textContent=Tl),Q=a(M),o(Y.$$.fragment,M),S=a(M),N=m(M,"P",{"data-svelte-h":!0}),j(N)!=="svelte-prg2lg"&&(N.textContent=ol),A=a(M),o(E.$$.fragment,M),q=a(M),v=m(M,"P",{"data-svelte-h":!0}),j(v)!=="svelte-15fi82o"&&(v.innerHTML=gl),D=a(M),o(X.$$.fragment,M),O=a(M),z=m(M,"P",{"data-svelte-h":!0}),j(z)!=="svelte-1a7ga15"&&(z.innerHTML=V),Ml=a(M),o(ll.$$.fragment,M),R=a(M),f=m(M,"P",{"data-svelte-h":!0}),j(f)!=="svelte-14dqs1o"&&(f.innerHTML=B),L=a(M),o(Ul.$$.fragment,M),yl=a(M),o(rl.$$.fragment,M),Gl=a(M),el=m(M,"P",{"data-svelte-h":!0}),j(el)!=="svelte-1fj9jwz"&&(el.textContent=Zl),hl=a(M),o(H.$$.fragment,M),xl=a(M),sl=m(M,"P",{"data-svelte-h":!0}),j(sl)!=="svelte-1k5u26e"&&(sl.innerHTML=ul),Jl=a(M),o(il.$$.fragment,M),Bl=a(M),tl=m(M,"P",{"data-svelte-h":!0}),j(tl)!=="svelte-eap1bh"&&(tl.innerHTML=_l),Cl=a(M),o(F.$$.fragment,M),Wl=a(M),nl=m(M,"P",{"data-svelte-h":!0}),j(nl)!=="svelte-pmr4ay"&&(nl.innerHTML=Il),Rl=a(M),al=m(M,"P",{"data-svelte-h":!0}),j(al)!=="svelte-2yiako"&&(al.innerHTML=jl),wl=a(M),fl=m(M,"P",{"data-svelte-h":!0}),j(fl)!=="svelte-1lt2ki6"&&(fl.innerHTML=dl),ml=a(M),o(cl.$$.fragment,M),$l=a(M),o(i.$$.fragment,M),g=a(M),Vl=m(M,"P",{"data-svelte-h":!0}),j(Vl)!=="svelte-1kjr4a"&&(Vl.innerHTML=Sl)},m(M,I){U(p,M,I),s(M,b,I),s(M,r,I),s(M,Z,I),U(w,M,I),s(M,k,I),s(M,G,I),s(M,$,I),U(C,M,I),s(M,W,I),s(M,P,I),s(M,Q,I),U(Y,M,I),s(M,S,I),s(M,N,I),s(M,A,I),U(E,M,I),s(M,q,I),s(M,v,I),s(M,D,I),U(X,M,I),s(M,O,I),s(M,z,I),s(M,Ml,I),U(ll,M,I),s(M,R,I),s(M,f,I),s(M,L,I),U(Ul,M,I),s(M,yl,I),U(rl,M,I),s(M,Gl,I),s(M,el,I),s(M,hl,I),U(H,M,I),s(M,xl,I),s(M,sl,I),s(M,Jl,I),U(il,M,I),s(M,Bl,I),s(M,tl,I),s(M,Cl,I),U(F,M,I),s(M,Wl,I),s(M,nl,I),s(M,Rl,I),s(M,al,I),s(M,wl,I),s(M,fl,I),s(M,ml,I),U(cl,M,I),s(M,$l,I),U(i,M,I),s(M,g,I),s(M,Vl,I),Dl=!0},i(M){Dl||(c(p.$$.fragment,M),c(w.$$.fragment,M),c(C.$$.fragment,M),c(Y.$$.fragment,M),c(E.$$.fragment,M),c(X.$$.fragment,M),c(ll.$$.fragment,M),c(Ul.$$.fragment,M),c(rl.$$.fragment,M),c(H.$$.fragment,M),c(il.$$.fragment,M),c(F.$$.fragment,M),c(cl.$$.fragment,M),c(i.$$.fragment,M),Dl=!0)},o(M){y(p.$$.fragment,M),y(w.$$.fragment,M),y(C.$$.fragment,M),y(Y.$$.fragment,M),y(E.$$.fragment,M),y(X.$$.fragment,M),y(ll.$$.fragment,M),y(Ul.$$.fragment,M),y(rl.$$.fragment,M),y(H.$$.fragment,M),y(il.$$.fragment,M),y(F.$$.fragment,M),y(cl.$$.fragment,M),y(i.$$.fragment,M),Dl=!1},d(M){M&&(e(b),e(r),e(Z),e(k),e(G),e($),e(W),e(P),e(Q),e(S),e(N),e(A),e(q),e(v),e(D),e(O),e(z),e(Ml),e(R),e(f),e(L),e(yl),e(Gl),e(el),e(hl),e(xl),e(sl),e(Jl),e(Bl),e(tl),e(Cl),e(Wl),e(nl),e(Rl),e(al),e(wl),e(fl),e(ml),e($l),e(g),e(Vl)),u(p,M),u(w,M),u(C,M),u(Y,M),u(E,M),u(X,M),u(ll,M),u(Ul,M),u(rl,M),u(H,M),u(il,M),u(F,M),u(cl,M),u(i,M)}}}function hp(_){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:ql,d(r){r&&e(p)}}}function Cp(_){let p,b,r,d,Z,w,k,G,x,$,C,W,P='現在讓我們深入研究翻譯。這是另一個<a href="/course/chapter1/7">sequence-to-sequence 任務</a>，這意味著這是一個可以表述為從一個序列到另一個序列的問題。從這個意義上說，這個問題非常類似<a href="/course/chapter7/6">文本摘要</a>，並且您可以將我們將在此處學習到的一些內容遷移到其他的序列到序列問題，例如：',Tl,Q,Y="<li><strong>風格遷移</strong> : 創建一個模型將某種風格遷移到一段文本（例如，正式的風格遷移到休閒的風格或莎士比亞英語到現代英語）</li> <li><strong>生成問題的回答</strong> ：創建一個模型，在給定上下文的情況下生成問題的答案</li>",S,N,ol,A,E='如果您有足夠大的兩種（或更多）語言的文本語料庫，您可以從頭開始訓練一個新的翻譯模型，就像我們在<a href="/course/chapter7/6">因果語言建模</a>部分中所做的那樣。然而，微調現有的翻譯模型會更快，無論是從像 mT5 或 mBART 這樣的多語言模型微調到特定的語言對，或者是專門用於從一種語言翻譯成另一種語言的模型。',q,v,gl='在本節中，我們將對<a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 數據集</a>上的Marian模型進行微調，該模型經過了從英語到法語的翻譯預訓練(因為很多“ Hugging Face”的員工會說這兩種語言)，它是<a href="https://apps.kde.org/" rel="nofollow">KDE應用程序</a>本地化文件的數據集。我們將使用的模型已經在從<a href="https://opus.nlpl.eu/" rel="nofollow">Opus 數據集</a>(實際上包含KDE4數據集)中提取的法語和英語文本的大型語料庫上進行了預先訓練。但是，即使我們使用的預訓練模型在其預訓練期間使用了這部分數據集，我們也會看到，經過微調後，我們可以得到一個更好的版本。',D,X,O="完成後，我們將擁有一個模型，可以進行這樣的翻譯：",z,V,Ml,ll,R,f,B,L,Ul='<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."/>',yl,rl,Gl='與前面的部分一樣，您可以使用以下代碼找到我們將訓練並上傳到 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>查看模型輸出的結果',el,Zl,hl,H,xl='為了從頭開始微調或訓練翻譯模型，我們需要一個適合該任務的數據集。如前所述，我們將使用<a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 數據集</a>在本節中，但您可以很容易地調整代碼以使用您自己的數據，只要您有要互譯的兩種語言的句子對。如果您需要複習如何將自定義數據加載到 <strong>Dataset</strong> 可以複習一下<a href="/course/chapter5">第五章</a>.',sl,ul,Jl,il,Bl="像往常一樣，我們使用 <strong>load_dataset()</strong> 函數：",tl,_l,Cl,F,Wl='如果您想使用不同的語言對，您可以使用它們的代碼來指定它們。該數據集共有 92 種語言可用；您可以通過<a href="https://huggingface.co/datasets/kde4" rel="nofollow">數據集卡片</a>展開其上的語言標籤來查看它們.',nl,Il,Rl,al,jl,wl="我們來看看數據集：",fl,dl,ml,cl,$l,i,g='我們有 210,173 對句子，但在一次訓練過程中，我們需要創建自己的驗證集。正如我們在<a href="/course/chapter5">第五章</a>學的的那樣, <strong>Dataset</strong> 有一個 <strong>train_test_split()</strong> 方法,可以幫我們拆分數據集。我們將設定固定的隨機數種子：',Vl,Sl,Dl,M,I,se,En="我們可以將 <strong>test</strong> 的鍵重命名為 <strong>validation</strong> 像這樣：",Ls,te,Ps,ne,Hn="現在讓我們看一下數據集的一個元素：",Ks,ae,Os,pe,lt,Me,Fn="我們得到一個字典，其中包含我們請求的兩種語言的兩個句子。這個充滿技術計算機科學術語的數據集的一個特殊之處在於它們都完全用法語翻譯。然而，法國工程師通常很懶惰，在交談時，大多數計算機科學專用詞彙都用英語表述。例如，“threads”這個詞很可能出現在法語句子中，尤其是在技術對話中；但在這個數據集中，它被翻譯成更正確的“fils de Discussion”。我們使用的預訓練模型已經在一個更大的法語和英語句子語料庫上進行了預訓練，採用了更簡單的選擇，即保留單詞的原樣:",et,re,st,ie,tt,ce,Sn=`這種情況的另一個例子是“plugin”這個詞，它不是正式的法語詞，但大多數母語人士都能理解，也不會費心去翻譯。
在 KDE4 數據集中，這個詞在法語中被翻譯成更正式的“module d’extension”：`,nt,ye,at,Je,pt,me,qn="然而，我們的預訓練模型堅持使用簡練而熟悉的英文單詞：",Mt,Te,rt,oe,it,Ue,Dn="看看我們的微調模型是否能識別數據集的這些特殊性。（劇透警告：它會）。",ct,ue,yt,Ll,Jt,je,mt,we,Tt,fe,Ln='您現在應該知道我們的下一步該做些什麼了：所有文本都需要轉換為token ID，以便模型能夠理解它們。對於這個任務，我們需要同時標記輸入和目標。我們的首要任務是創建我們的 <strong>tokenizer</strong> 對象。如前所述，我們將使用 Marian 英語到法語的預訓練模型。如果您使用另一對語言嘗試此代碼，請確保調整模型Checkpoint。<a href="https://huggingface.co/Helsinki-NLP" rel="nofollow">Helsinki-NLP</a>組織提供了多種語言的一千多種模型。',ot,de,Ut,be,Pn='您可以將 <strong>model_checkpoint</strong> 更換為<a href="https://huggingface.co/models" rel="nofollow">Hub</a>上你喜歡的任何其他型號，或本地保存的預訓練模型和標記器。',ut,Pl,jt,he,Kn="我們的數據準備非常簡單。 只需要記住一件事：您照常處理輸入，但對於這次的輸出目標，您需要將標記器包裝在上下文管理器“as_target_tokenizer()”中。",wt,Ce,On="Python 中的上下文管理器引入了 <strong>with</strong> 語句，當您有兩個相關的操作要成對執行時很有用。最常見的例子是當您寫入或讀取文件時，下面是一個例子：",ft,Ie,dt,$e,la="這裡成對執行的兩個相關操作是打開和關閉文件的操作。打開的文件f對應的對象只在with下的縮進塊內有效；在該塊之前打開，在該塊的末尾關閉。",bt,ge,ea="在本例中，上下文管理器 as_target_tokenizer() 將在執行縮進塊之前將標記器設置為輸出語言（此處為法語），然後將其設置回輸入語言（此處為英語）。",ht,Ze,sa="因此，預處理一個樣本如下所示：",Ct,_e,It,ke,ta="如果我們忘記在上下文管理器中標記目標，它們將被輸入標記器標記，在Marian模型的情況下，會導致輸出的異常：",$t,Ge,gt,xe,Zt,Be,na="正如我們所看到的，使用英語標記器來預處理法語句子會產生更多的標記，因為標記器不知道任何法語單詞(除了那些也出現在英語語言中的單詞，比如“discussion”)。",_t,We,aa="<code>inputs</code> 和 <code>targets</code> 都是帶有我們常用鍵（輸入 ID、注意掩碼等）的字典，所以最後一步是在輸入中設置一個 <code>&quot;labels&quot;</code> 鍵。 我們在數據集的預處理函數中執行此操作：",kt,Re,Gt,Ve,pa="請注意，我們為輸入和輸出設置了相同的最大長度。由於我們處理的文本看起來很短，我們使用 128。",xt,Kl,Bt,Ol,Wt,Xe,Ma="我們現在可以對數據集的所有數據一次性應用該預處理：",Rt,Ne,Vt,ve,ra="現在數據已經過預處理，我們準備好微調我們的預訓練模型！",Xt,Xl,Nl,zs,Qe,ia="請注意，這次我們使用的是在翻譯任務上訓練過的模型，並且實際上已經可以使用，因此沒有關於丟失權重或新初始化權重的警告。",Nt,Ae,vt,ze,ca='我們需要一個數據整理器來處理動態批處理的填充。在本例中，我們不能像<a href="/course/chapter3">第3章</a>那樣使用帶填充的<strong>DataCollatorWithPadding</strong>，因為它只填充輸入（輸入ID、注意掩碼和令牌類型ID）。我們的標籤也應該填充到標籤中遇到的最大長度。而且，如前所述，用於填充標籤的填充值應為-100，而不是標記器的填充標記，以確保在損失計算中忽略這些填充值。',Qt,Ye,ya='這一切都可以由 <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”需要知道“模型”對象：',At,vl,Ql,Ys,Ee,Ja="為了在幾個樣本上進行測試，我們只需在我們標記化訓練集中的部分數據上調用它：",zt,He,Yt,Fe,Et,Se,ma="我們可以檢查我們的標籤是否已使用 <strong>-100</strong> 填充到批次的最大長度：",Ht,qe,Ft,De,St,Le,Ta="我們還可以查看解碼器輸入 ID，看看它們是標籤的偏移形成的版本：",qt,Pe,Dt,Ke,Lt,Oe,oa="以下是我們數據集中第一個和第二個元素的標籤：",Pt,ls,Kt,es,Ot,Al,zl,Es,ss,ln,ts,en,Hs,ns,Ua='用於翻譯的傳統指標是<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> 這樣的句子）。',sn,as,ua='BLEU 的一個缺點是它需要文本已經被分詞，這使得比較使用不同標記器的模型之間的分數變得困難。因此，當今用於基準翻譯模型的最常用指標是<a href="https://github.com/mjpost/sacrebleu" rel="nofollow">SacreBLEU</a>，它通過標準化標記化步驟解決了這個缺點（和其他的一些缺點）。要使用此指標，我們首先需要安裝 SacreBLEU 庫：',tn,ps,nn,Ms,ja='然後我們可以就像我們在<a href="/course/chapter3">第三章</a>那樣通過 <strong>load_metric()</strong> 加載它 ：',an,rs,pn,is,wa="該指標將文本作為輸入和目標結果。它旨在接受多個可接受的目標，因為同一個句子通常有多個可接受的翻譯——我們使用的數據集只提供一個，但在 NLP 中找到將多個句子作為標籤的數據集不是一個難題。因此，預測結果應該是一個句子列表，而參考應該是一個句子列表的列表。",Mn,cs,fa="讓我們嘗試一個例子：",rn,ys,cn,Js,yn,ms,da='這得到了 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 分數：',Jn,Ts,mn,os,Tn,Us,on,us,Un,js,ba="分數可以從 0 到 100，越高越好。",un,Yl,El,Fs,ws,ha="現在這已經完成了，我們已經準備好微調我們的模型了！",jn,fs,wn,ds,Ca="第一步是登錄 Hugging Face，這樣您就可以將結果上傳到模型中心。有一個方便的功能可以幫助您在notebook中完成此操作：",fn,bs,dn,hs,Ia="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 登錄憑據。",bn,Cs,$a="如果您不是在notebook上運行代碼，只需在終端中輸入以下行：",hn,Is,Cn,Hl,Fl,Ss,qs,$s,In,gs,ga="我們已經向您展示瞭如何將我們在模型中心微調的模型與推理小部件一起使用。 要在“管道”中本地使用它，我們只需要指定正確的模型標識符：",$n,Zs,gn,_s,Zn,ks,Za="正如預期的那樣，我們的預訓練模型將其知識適應了我們對其進行微調的語料庫，而不是單獨留下英文單詞“threads”，而是將其翻譯成法語官方版本。 “”的翻譯也是一樣的：",_n,Gs,kn,xs,Gn,Bs,_a="風格適應的另一個很好的例子！",xn,le,Bn,Ds,Wn;Z=new tp({props:{fw:_[0]}}),k=new kl({props:{title:"翻譯",local:"翻譯",headingTag:"h1"}});const ka=[ap,np],Ws=[];function Ga(l,t){return l[0]==="pt"?0:1}x=Ga(_),$=Ws[x]=ka[x](_),N=new Vn({props:{id:"1JvfrvZgi6c"}}),Zl=new kl({props:{title:"準備數據",local:"準備數據",headingTag:"h2"}}),ul=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}}),dl=new h({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),cl=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2lkJyUyQyUyMCd0cmFuc2xhdGlvbiclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIxMDE3MyUwQSUyMCUyMCUyMCUyMCU3RCklMEElN0Qp",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;translation&#x27;</span>],
        num_rows: <span class="hljs-number">210173</span>
    })
})`,wrap:!1}}),Sl=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}}),M=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}}),Te=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}}),oe=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 Vn({props:{id:"0Oxphw4Q9fo"}}),Ll=new ee({props:{$$slots:{default:[pp]},$$scope:{ctx:_}}}),je=new kl({props:{title:"處理數據",local:"處理數據",headingTag:"h3"}}),we=new Vn({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}}),Pl=new ee({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}}),Kl=new ee({props:{$$slots:{default:[rp]},$$scope:{ctx:_}}}),Ol=new ee({props:{warning:!0,$$slots:{default:[ip]},$$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=[yp,cp],Rs=[];function Ba(l,t){return l[0]==="pt"?0:1}Xl=Ba(_),Nl=Rs[Xl]=xa[Xl](_),Ae=new kl({props:{title:"數據整理",local:"數據整理",headingTag:"h3"}});const Wa=[Tp,mp],Vs=[];function Ra(l,t){return l[0]==="pt"?0:1}vl=Ra(_),Ql=Vs[vl]=Wa[vl](_),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 Va=[Up,op],Xs=[];function Xa(l,t){return l[0]==="pt"?0:1}Al=Xa(_),zl=Xs[Al]=Va[Al](_),ss=new kl({props:{title:"評估指標",local:"評估指標",headingTag:"h3"}}),ts=new Vn({props:{id:"M05L1DhFqcw"}});let bl=_[0]==="pt"&&qa();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}}),Ts=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}}),os=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 Na=[jp,up],Ns=[];function va(l,t){return l[0]==="tf"?0:1}Yl=va(_),El=Ns[Yl]=Na[Yl](_),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 Qa=[fp,wp],vs=[];function Aa(l,t){return l[0]==="tf"?0:1}Hl=Aa(_),Fl=vs[Hl]=Qa[Hl](_);let pl=_[0]==="pt"&&Da();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}}),le=new ee({props:{$$slots:{default:[hp]},$$scope:{ctx:_}}}),{c(){p=J("meta"),b=n(),r=J("p"),d=n(),T(Z.$$.fragment),w=n(),T(k.$$.fragment),G=n(),$.c(),C=n(),W=J("p"),W.innerHTML=P,Tl=n(),Q=J("ul"),Q.innerHTML=Y,S=n(),T(N.$$.fragment),ol=n(),A=J("p"),A.innerHTML=E,q=n(),v=J("p"),v.innerHTML=gl,D=n(),X=J("p"),X.textContent=O,z=n(),V=J("iframe"),ll=n(),R=J("iframe"),B=n(),L=J("a"),L.innerHTML=Ul,yl=n(),rl=J("p"),rl.innerHTML=Gl,el=n(),T(Zl.$$.fragment),hl=n(),H=J("p"),H.innerHTML=xl,sl=n(),T(ul.$$.fragment),Jl=n(),il=J("p"),il.innerHTML=Bl,tl=n(),T(_l.$$.fragment),Cl=n(),F=J("p"),F.innerHTML=Wl,nl=n(),Il=J("img"),al=n(),jl=J("p"),jl.textContent=wl,fl=n(),T(dl.$$.fragment),ml=n(),T(cl.$$.fragment),$l=n(),i=J("p"),i.innerHTML=g,Vl=n(),T(Sl.$$.fragment),Dl=n(),T(M.$$.fragment),I=n(),se=J("p"),se.innerHTML=En,Ls=n(),T(te.$$.fragment),Ps=n(),ne=J("p"),ne.textContent=Hn,Ks=n(),T(ae.$$.fragment),Os=n(),T(pe.$$.fragment),lt=n(),Me=J("p"),Me.textContent=Fn,et=n(),T(re.$$.fragment),st=n(),T(ie.$$.fragment),tt=n(),ce=J("p"),ce.textContent=Sn,nt=n(),T(ye.$$.fragment),at=n(),T(Je.$$.fragment),pt=n(),me=J("p"),me.textContent=qn,Mt=n(),T(Te.$$.fragment),rt=n(),T(oe.$$.fragment),it=n(),Ue=J("p"),Ue.textContent=Dn,ct=n(),T(ue.$$.fragment),yt=n(),T(Ll.$$.fragment),Jt=n(),T(je.$$.fragment),mt=n(),T(we.$$.fragment),Tt=n(),fe=J("p"),fe.innerHTML=Ln,ot=n(),T(de.$$.fragment),Ut=n(),be=J("p"),be.innerHTML=Pn,ut=n(),T(Pl.$$.fragment),jt=n(),he=J("p"),he.textContent=Kn,wt=n(),Ce=J("p"),Ce.innerHTML=On,ft=n(),T(Ie.$$.fragment),dt=n(),$e=J("p"),$e.textContent=la,bt=n(),ge=J("p"),ge.textContent=ea,ht=n(),Ze=J("p"),Ze.textContent=sa,Ct=n(),T(_e.$$.fragment),It=n(),ke=J("p"),ke.textContent=ta,$t=n(),T(Ge.$$.fragment),gt=n(),T(xe.$$.fragment),Zt=n(),Be=J("p"),Be.textContent=na,_t=n(),We=J("p"),We.innerHTML=aa,kt=n(),T(Re.$$.fragment),Gt=n(),Ve=J("p"),Ve.textContent=pa,xt=n(),T(Kl.$$.fragment),Bt=n(),T(Ol.$$.fragment),Wt=n(),Xe=J("p"),Xe.textContent=Ma,Rt=n(),T(Ne.$$.fragment),Vt=n(),ve=J("p"),ve.textContent=ra,Xt=n(),Nl.c(),zs=n(),Qe=J("p"),Qe.textContent=ia,Nt=n(),T(Ae.$$.fragment),vt=n(),ze=J("p"),ze.innerHTML=ca,Qt=n(),Ye=J("p"),Ye.innerHTML=ya,At=n(),Ql.c(),Ys=n(),Ee=J("p"),Ee.textContent=Ja,zt=n(),T(He.$$.fragment),Yt=n(),T(Fe.$$.fragment),Et=n(),Se=J("p"),Se.innerHTML=ma,Ht=n(),T(qe.$$.fragment),Ft=n(),T(De.$$.fragment),St=n(),Le=J("p"),Le.textContent=Ta,qt=n(),T(Pe.$$.fragment),Dt=n(),T(Ke.$$.fragment),Lt=n(),Oe=J("p"),Oe.textContent=oa,Pt=n(),T(ls.$$.fragment),Kt=n(),T(es.$$.fragment),Ot=n(),zl.c(),Es=n(),T(ss.$$.fragment),ln=n(),T(ts.$$.fragment),en=n(),bl&&bl.c(),Hs=n(),ns=J("p"),ns.innerHTML=Ua,sn=n(),as=J("p"),as.innerHTML=ua,tn=n(),T(ps.$$.fragment),nn=n(),Ms=J("p"),Ms.innerHTML=ja,an=n(),T(rs.$$.fragment),pn=n(),is=J("p"),is.textContent=wa,Mn=n(),cs=J("p"),cs.textContent=fa,rn=n(),T(ys.$$.fragment),cn=n(),T(Js.$$.fragment),yn=n(),ms=J("p"),ms.innerHTML=da,Jn=n(),T(Ts.$$.fragment),mn=n(),T(os.$$.fragment),Tn=n(),T(Us.$$.fragment),on=n(),T(us.$$.fragment),Un=n(),js=J("p"),js.textContent=ba,un=n(),El.c(),Fs=n(),ws=J("p"),ws.textContent=ha,jn=n(),T(fs.$$.fragment),wn=n(),ds=J("p"),ds.textContent=Ca,fn=n(),T(bs.$$.fragment),dn=n(),hs=J("p"),hs.textContent=Ia,bn=n(),Cs=J("p"),Cs.textContent=$a,hn=n(),T(Is.$$.fragment),Cn=n(),Fl.c(),Ss=n(),pl&&pl.c(),qs=n(),T($s.$$.fragment),In=n(),gs=J("p"),gs.textContent=ga,$n=n(),T(Zs.$$.fragment),gn=n(),T(_s.$$.fragment),Zn=n(),ks=J("p"),ks.textContent=Za,_n=n(),T(Gs.$$.fragment),kn=n(),T(xs.$$.fragment),Gn=n(),Bs=J("p"),Bs.textContent=_a,xn=n(),T(le.$$.fragment),Bn=n(),Ds=J("p"),this.h()},l(l){const t=ep("svelte-u9bgzb",document.head);p=m(t,"META",{name:!0,content:!0}),t.forEach(e),b=a(l),r=m(l,"P",{}),Rn(r).forEach(e),d=a(l),o(Z.$$.fragment,l),w=a(l),o(k.$$.fragment,l),G=a(l),$.l(l),C=a(l),W=m(l,"P",{"data-svelte-h":!0}),j(W)!=="svelte-g1zz7f"&&(W.innerHTML=P),Tl=a(l),Q=m(l,"UL",{"data-svelte-h":!0}),j(Q)!=="svelte-mppk8z"&&(Q.innerHTML=Y),S=a(l),o(N.$$.fragment,l),ol=a(l),A=m(l,"P",{"data-svelte-h":!0}),j(A)!=="svelte-12vvng4"&&(A.innerHTML=E),q=a(l),v=m(l,"P",{"data-svelte-h":!0}),j(v)!=="svelte-zwczhs"&&(v.innerHTML=gl),D=a(l),X=m(l,"P",{"data-svelte-h":!0}),j(X)!=="svelte-1dwvaw6"&&(X.textContent=O),z=a(l),V=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Rn(V).forEach(e),ll=a(l),R=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Rn(R).forEach(e),B=a(l),L=m(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),j(L)!=="svelte-1ifl6xg"&&(L.innerHTML=Ul),yl=a(l),rl=m(l,"P",{"data-svelte-h":!0}),j(rl)!=="svelte-ltxews"&&(rl.innerHTML=Gl),el=a(l),o(Zl.$$.fragment,l),hl=a(l),H=m(l,"P",{"data-svelte-h":!0}),j(H)!=="svelte-nnh33g"&&(H.innerHTML=xl),sl=a(l),o(ul.$$.fragment,l),Jl=a(l),il=m(l,"P",{"data-svelte-h":!0}),j(il)!=="svelte-wyvyxf"&&(il.innerHTML=Bl),tl=a(l),o(_l.$$.fragment,l),Cl=a(l),F=m(l,"P",{"data-svelte-h":!0}),j(F)!=="svelte-a99dl6"&&(F.innerHTML=Wl),nl=a(l),Il=m(l,"IMG",{src:!0,alt:!0,width:!0}),al=a(l),jl=m(l,"P",{"data-svelte-h":!0}),j(jl)!=="svelte-y9mrlk"&&(jl.textContent=wl),fl=a(l),o(dl.$$.fragment,l),ml=a(l),o(cl.$$.fragment,l),$l=a(l),i=m(l,"P",{"data-svelte-h":!0}),j(i)!=="svelte-afc7ia"&&(i.innerHTML=g),Vl=a(l),o(Sl.$$.fragment,l),Dl=a(l),o(M.$$.fragment,l),I=a(l),se=m(l,"P",{"data-svelte-h":!0}),j(se)!=="svelte-1sundz5"&&(se.innerHTML=En),Ls=a(l),o(te.$$.fragment,l),Ps=a(l),ne=m(l,"P",{"data-svelte-h":!0}),j(ne)!=="svelte-1np1nb1"&&(ne.textContent=Hn),Ks=a(l),o(ae.$$.fragment,l),Os=a(l),o(pe.$$.fragment,l),lt=a(l),Me=m(l,"P",{"data-svelte-h":!0}),j(Me)!=="svelte-1b9ekeu"&&(Me.textContent=Fn),et=a(l),o(re.$$.fragment,l),st=a(l),o(ie.$$.fragment,l),tt=a(l),ce=m(l,"P",{"data-svelte-h":!0}),j(ce)!=="svelte-dum56n"&&(ce.textContent=Sn),nt=a(l),o(ye.$$.fragment,l),at=a(l),o(Je.$$.fragment,l),pt=a(l),me=m(l,"P",{"data-svelte-h":!0}),j(me)!=="svelte-j3n155"&&(me.textContent=qn),Mt=a(l),o(Te.$$.fragment,l),rt=a(l),o(oe.$$.fragment,l),it=a(l),Ue=m(l,"P",{"data-svelte-h":!0}),j(Ue)!=="svelte-u92b5v"&&(Ue.textContent=Dn),ct=a(l),o(ue.$$.fragment,l),yt=a(l),o(Ll.$$.fragment,l),Jt=a(l),o(je.$$.fragment,l),mt=a(l),o(we.$$.fragment,l),Tt=a(l),fe=m(l,"P",{"data-svelte-h":!0}),j(fe)!=="svelte-vdluck"&&(fe.innerHTML=Ln),ot=a(l),o(de.$$.fragment,l),Ut=a(l),be=m(l,"P",{"data-svelte-h":!0}),j(be)!=="svelte-19tlzon"&&(be.innerHTML=Pn),ut=a(l),o(Pl.$$.fragment,l),jt=a(l),he=m(l,"P",{"data-svelte-h":!0}),j(he)!=="svelte-ya6djn"&&(he.textContent=Kn),wt=a(l),Ce=m(l,"P",{"data-svelte-h":!0}),j(Ce)!=="svelte-y7z8zo"&&(Ce.innerHTML=On),ft=a(l),o(Ie.$$.fragment,l),dt=a(l),$e=m(l,"P",{"data-svelte-h":!0}),j($e)!=="svelte-fq9j9o"&&($e.textContent=la),bt=a(l),ge=m(l,"P",{"data-svelte-h":!0}),j(ge)!=="svelte-1k2jt6s"&&(ge.textContent=ea),ht=a(l),Ze=m(l,"P",{"data-svelte-h":!0}),j(Ze)!=="svelte-j6n7bq"&&(Ze.textContent=sa),Ct=a(l),o(_e.$$.fragment,l),It=a(l),ke=m(l,"P",{"data-svelte-h":!0}),j(ke)!=="svelte-1hklxb"&&(ke.textContent=ta),$t=a(l),o(Ge.$$.fragment,l),gt=a(l),o(xe.$$.fragment,l),Zt=a(l),Be=m(l,"P",{"data-svelte-h":!0}),j(Be)!=="svelte-1ezr9a5"&&(Be.textContent=na),_t=a(l),We=m(l,"P",{"data-svelte-h":!0}),j(We)!=="svelte-2ftd0c"&&(We.innerHTML=aa),kt=a(l),o(Re.$$.fragment,l),Gt=a(l),Ve=m(l,"P",{"data-svelte-h":!0}),j(Ve)!=="svelte-1t7t0ps"&&(Ve.textContent=pa),xt=a(l),o(Kl.$$.fragment,l),Bt=a(l),o(Ol.$$.fragment,l),Wt=a(l),Xe=m(l,"P",{"data-svelte-h":!0}),j(Xe)!=="svelte-41g0oo"&&(Xe.textContent=Ma),Rt=a(l),o(Ne.$$.fragment,l),Vt=a(l),ve=m(l,"P",{"data-svelte-h":!0}),j(ve)!=="svelte-kuri4t"&&(ve.textContent=ra),Xt=a(l),Nl.l(l),zs=a(l),Qe=m(l,"P",{"data-svelte-h":!0}),j(Qe)!=="svelte-1fvhpt7"&&(Qe.textContent=ia),Nt=a(l),o(Ae.$$.fragment,l),vt=a(l),ze=m(l,"P",{"data-svelte-h":!0}),j(ze)!=="svelte-gauilj"&&(ze.innerHTML=ca),Qt=a(l),Ye=m(l,"P",{"data-svelte-h":!0}),j(Ye)!=="svelte-1vu6b9l"&&(Ye.innerHTML=ya),At=a(l),Ql.l(l),Ys=a(l),Ee=m(l,"P",{"data-svelte-h":!0}),j(Ee)!=="svelte-1irh16z"&&(Ee.textContent=Ja),zt=a(l),o(He.$$.fragment,l),Yt=a(l),o(Fe.$$.fragment,l),Et=a(l),Se=m(l,"P",{"data-svelte-h":!0}),j(Se)!=="svelte-ixg3i9"&&(Se.innerHTML=ma),Ht=a(l),o(qe.$$.fragment,l),Ft=a(l),o(De.$$.fragment,l),St=a(l),Le=m(l,"P",{"data-svelte-h":!0}),j(Le)!=="svelte-1txmlsd"&&(Le.textContent=Ta),qt=a(l),o(Pe.$$.fragment,l),Dt=a(l),o(Ke.$$.fragment,l),Lt=a(l),Oe=m(l,"P",{"data-svelte-h":!0}),j(Oe)!=="svelte-13jva7e"&&(Oe.textContent=oa),Pt=a(l),o(ls.$$.fragment,l),Kt=a(l),o(es.$$.fragment,l),Ot=a(l),zl.l(l),Es=a(l),o(ss.$$.fragment,l),ln=a(l),o(ts.$$.fragment,l),en=a(l),bl&&bl.l(l),Hs=a(l),ns=m(l,"P",{"data-svelte-h":!0}),j(ns)!=="svelte-10ejz60"&&(ns.innerHTML=Ua),sn=a(l),as=m(l,"P",{"data-svelte-h":!0}),j(as)!=="svelte-ko64w4"&&(as.innerHTML=ua),tn=a(l),o(ps.$$.fragment,l),nn=a(l),Ms=m(l,"P",{"data-svelte-h":!0}),j(Ms)!=="svelte-1sf91fy"&&(Ms.innerHTML=ja),an=a(l),o(rs.$$.fragment,l),pn=a(l),is=m(l,"P",{"data-svelte-h":!0}),j(is)!=="svelte-d95f1m"&&(is.textContent=wa),Mn=a(l),cs=m(l,"P",{"data-svelte-h":!0}),j(cs)!=="svelte-8blnhe"&&(cs.textContent=fa),rn=a(l),o(ys.$$.fragment,l),cn=a(l),o(Js.$$.fragment,l),yn=a(l),ms=m(l,"P",{"data-svelte-h":!0}),j(ms)!=="svelte-1rz427r"&&(ms.innerHTML=da),Jn=a(l),o(Ts.$$.fragment,l),mn=a(l),o(os.$$.fragment,l),Tn=a(l),o(Us.$$.fragment,l),on=a(l),o(us.$$.fragment,l),Un=a(l),js=m(l,"P",{"data-svelte-h":!0}),j(js)!=="svelte-1nxf5yg"&&(js.textContent=ba),un=a(l),El.l(l),Fs=a(l),ws=m(l,"P",{"data-svelte-h":!0}),j(ws)!=="svelte-askdwj"&&(ws.textContent=ha),jn=a(l),o(fs.$$.fragment,l),wn=a(l),ds=m(l,"P",{"data-svelte-h":!0}),j(ds)!=="svelte-lbhkb9"&&(ds.textContent=Ca),fn=a(l),o(bs.$$.fragment,l),dn=a(l),hs=m(l,"P",{"data-svelte-h":!0}),j(hs)!=="svelte-1oxqs03"&&(hs.textContent=Ia),bn=a(l),Cs=m(l,"P",{"data-svelte-h":!0}),j(Cs)!=="svelte-13113ho"&&(Cs.textContent=$a),hn=a(l),o(Is.$$.fragment,l),Cn=a(l),Fl.l(l),Ss=a(l),pl&&pl.l(l),qs=a(l),o($s.$$.fragment,l),In=a(l),gs=m(l,"P",{"data-svelte-h":!0}),j(gs)!=="svelte-1jx14be"&&(gs.textContent=ga),$n=a(l),o(Zs.$$.fragment,l),gn=a(l),o(_s.$$.fragment,l),Zn=a(l),ks=m(l,"P",{"data-svelte-h":!0}),j(ks)!=="svelte-a3uifz"&&(ks.textContent=Za),_n=a(l),o(Gs.$$.fragment,l),kn=a(l),o(xs.$$.fragment,l),Gn=a(l),Bs=m(l,"P",{"data-svelte-h":!0}),j(Bs)!=="svelte-1txgxe8"&&(Bs.textContent=_a),xn=a(l),o(le.$$.fragment,l),Bn=a(l),Ds=m(l,"P",{}),Rn(Ds).forEach(e),this.h()},h(){K(p,"name","hf:doc:metadata"),K(p,"content",Ip),Yn(V.src,Ml="https://course-demos-marian-finetuned-kde4-en-to-fr.hf.space")||K(V,"src",Ml),K(V,"frameborder","0"),K(V,"height","350"),K(V,"title","Gradio app"),K(V,"class","block dark:hidden container p-0 flex-grow space-iframe"),K(V,"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"),K(V,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Yn(R.src,f="https://course-demos-marian-finetuned-kde4-en-to-fr-darkmode.hf.space")||K(R,"src",f),K(R,"frameborder","0"),K(R,"height","350"),K(R,"title","Gradio app"),K(R,"class","hidden dark:block container p-0 flex-grow space-iframe"),K(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"),K(R,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),K(L,"class","flex justify-center"),K(L,"href","/huggingface-course/marian-finetuned-kde4-en-to-fr"),Yn(Il.src,Rl="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/language_tags.png")||K(Il,"src",Rl),K(Il,"alt","Language available for the KDE4 dataset."),K(Il,"width","100%")},m(l,t){sp(document.head,p),s(l,b,t),s(l,r,t),s(l,d,t),U(Z,l,t),s(l,w,t),U(k,l,t),s(l,G,t),Ws[x].m(l,t),s(l,C,t),s(l,W,t),s(l,Tl,t),s(l,Q,t),s(l,S,t),U(N,l,t),s(l,ol,t),s(l,A,t),s(l,q,t),s(l,v,t),s(l,D,t),s(l,X,t),s(l,z,t),s(l,V,t),s(l,ll,t),s(l,R,t),s(l,B,t),s(l,L,t),s(l,yl,t),s(l,rl,t),s(l,el,t),U(Zl,l,t),s(l,hl,t),s(l,H,t),s(l,sl,t),U(ul,l,t),s(l,Jl,t),s(l,il,t),s(l,tl,t),U(_l,l,t),s(l,Cl,t),s(l,F,t),s(l,nl,t),s(l,Il,t),s(l,al,t),s(l,jl,t),s(l,fl,t),U(dl,l,t),s(l,ml,t),U(cl,l,t),s(l,$l,t),s(l,i,t),s(l,Vl,t),U(Sl,l,t),s(l,Dl,t),U(M,l,t),s(l,I,t),s(l,se,t),s(l,Ls,t),U(te,l,t),s(l,Ps,t),s(l,ne,t),s(l,Ks,t),U(ae,l,t),s(l,Os,t),U(pe,l,t),s(l,lt,t),s(l,Me,t),s(l,et,t),U(re,l,t),s(l,st,t),U(ie,l,t),s(l,tt,t),s(l,ce,t),s(l,nt,t),U(ye,l,t),s(l,at,t),U(Je,l,t),s(l,pt,t),s(l,me,t),s(l,Mt,t),U(Te,l,t),s(l,rt,t),U(oe,l,t),s(l,it,t),s(l,Ue,t),s(l,ct,t),U(ue,l,t),s(l,yt,t),U(Ll,l,t),s(l,Jt,t),U(je,l,t),s(l,mt,t),U(we,l,t),s(l,Tt,t),s(l,fe,t),s(l,ot,t),U(de,l,t),s(l,Ut,t),s(l,be,t),s(l,ut,t),U(Pl,l,t),s(l,jt,t),s(l,he,t),s(l,wt,t),s(l,Ce,t),s(l,ft,t),U(Ie,l,t),s(l,dt,t),s(l,$e,t),s(l,bt,t),s(l,ge,t),s(l,ht,t),s(l,Ze,t),s(l,Ct,t),U(_e,l,t),s(l,It,t),s(l,ke,t),s(l,$t,t),U(Ge,l,t),s(l,gt,t),U(xe,l,t),s(l,Zt,t),s(l,Be,t),s(l,_t,t),s(l,We,t),s(l,kt,t),U(Re,l,t),s(l,Gt,t),s(l,Ve,t),s(l,xt,t),U(Kl,l,t),s(l,Bt,t),U(Ol,l,t),s(l,Wt,t),s(l,Xe,t),s(l,Rt,t),U(Ne,l,t),s(l,Vt,t),s(l,ve,t),s(l,Xt,t),Rs[Xl].m(l,t),s(l,zs,t),s(l,Qe,t),s(l,Nt,t),U(Ae,l,t),s(l,vt,t),s(l,ze,t),s(l,Qt,t),s(l,Ye,t),s(l,At,t),Vs[vl].m(l,t),s(l,Ys,t),s(l,Ee,t),s(l,zt,t),U(He,l,t),s(l,Yt,t),U(Fe,l,t),s(l,Et,t),s(l,Se,t),s(l,Ht,t),U(qe,l,t),s(l,Ft,t),U(De,l,t),s(l,St,t),s(l,Le,t),s(l,qt,t),U(Pe,l,t),s(l,Dt,t),U(Ke,l,t),s(l,Lt,t),s(l,Oe,t),s(l,Pt,t),U(ls,l,t),s(l,Kt,t),U(es,l,t),s(l,Ot,t),Xs[Al].m(l,t),s(l,Es,t),U(ss,l,t),s(l,ln,t),U(ts,l,t),s(l,en,t),bl&&bl.m(l,t),s(l,Hs,t),s(l,ns,t),s(l,sn,t),s(l,as,t),s(l,tn,t),U(ps,l,t),s(l,nn,t),s(l,Ms,t),s(l,an,t),U(rs,l,t),s(l,pn,t),s(l,is,t),s(l,Mn,t),s(l,cs,t),s(l,rn,t),U(ys,l,t),s(l,cn,t),U(Js,l,t),s(l,yn,t),s(l,ms,t),s(l,Jn,t),U(Ts,l,t),s(l,mn,t),U(os,l,t),s(l,Tn,t),U(Us,l,t),s(l,on,t),U(us,l,t),s(l,Un,t),s(l,js,t),s(l,un,t),Ns[Yl].m(l,t),s(l,Fs,t),s(l,ws,t),s(l,jn,t),U(fs,l,t),s(l,wn,t),s(l,ds,t),s(l,fn,t),U(bs,l,t),s(l,dn,t),s(l,hs,t),s(l,bn,t),s(l,Cs,t),s(l,hn,t),U(Is,l,t),s(l,Cn,t),vs[Hl].m(l,t),s(l,Ss,t),pl&&pl.m(l,t),s(l,qs,t),U($s,l,t),s(l,In,t),s(l,gs,t),s(l,$n,t),U(Zs,l,t),s(l,gn,t),U(_s,l,t),s(l,Zn,t),s(l,ks,t),s(l,_n,t),U(Gs,l,t),s(l,kn,t),U(xs,l,t),s(l,Gn,t),s(l,Bs,t),s(l,xn,t),U(le,l,t),s(l,Bn,t),s(l,Ds,t),Wn=!0},p(l,[t]){const za={};t&1&&(za.fw=l[0]),Z.$set(za);let Xn=x;x=Ga(l),x!==Xn&&(As(),y(Ws[Xn],1,1,()=>{Ws[Xn]=null}),Qs(),$=Ws[x],$||($=Ws[x]=ka[x](l),$.c()),c($,1),$.m(C.parentNode,C));const Ya={};t&2&&(Ya.$$scope={dirty:t,ctx:l}),Ll.$set(Ya);const Ea={};t&2&&(Ea.$$scope={dirty:t,ctx:l}),Pl.$set(Ea);const Ha={};t&2&&(Ha.$$scope={dirty:t,ctx:l}),Kl.$set(Ha);const Fa={};t&2&&(Fa.$$scope={dirty:t,ctx:l}),Ol.$set(Fa);let Nn=Xl;Xl=Ba(l),Xl!==Nn&&(As(),y(Rs[Nn],1,1,()=>{Rs[Nn]=null}),Qs(),Nl=Rs[Xl],Nl||(Nl=Rs[Xl]=xa[Xl](l),Nl.c()),c(Nl,1),Nl.m(zs.parentNode,zs));let vn=vl;vl=Ra(l),vl!==vn&&(As(),y(Vs[vn],1,1,()=>{Vs[vn]=null}),Qs(),Ql=Vs[vl],Ql||(Ql=Vs[vl]=Wa[vl](l),Ql.c()),c(Ql,1),Ql.m(Ys.parentNode,Ys));let Qn=Al;Al=Xa(l),Al!==Qn&&(As(),y(Xs[Qn],1,1,()=>{Xs[Qn]=null}),Qs(),zl=Xs[Al],zl||(zl=Xs[Al]=Va[Al](l),zl.c()),c(zl,1),zl.m(Es.parentNode,Es)),l[0]==="pt"?bl||(bl=qa(),bl.c(),bl.m(Hs.parentNode,Hs)):bl&&(bl.d(1),bl=null);let An=Yl;Yl=va(l),Yl!==An&&(As(),y(Ns[An],1,1,()=>{Ns[An]=null}),Qs(),El=Ns[Yl],El||(El=Ns[Yl]=Na[Yl](l),El.c()),c(El,1),El.m(Fs.parentNode,Fs));let zn=Hl;Hl=Aa(l),Hl!==zn&&(As(),y(vs[zn],1,1,()=>{vs[zn]=null}),Qs(),Fl=vs[Hl],Fl||(Fl=vs[Hl]=Qa[Hl](l),Fl.c()),c(Fl,1),Fl.m(Ss.parentNode,Ss)),l[0]==="pt"?pl?t&1&&c(pl,1):(pl=Da(),pl.c(),c(pl,1),pl.m(qs.parentNode,qs)):pl&&(As(),y(pl,1,1,()=>{pl=null}),Qs());const Sa={};t&2&&(Sa.$$scope={dirty:t,ctx:l}),le.$set(Sa)},i(l){Wn||(c(Z.$$.fragment,l),c(k.$$.fragment,l),c($),c(N.$$.fragment,l),c(Zl.$$.fragment,l),c(ul.$$.fragment,l),c(_l.$$.fragment,l),c(dl.$$.fragment,l),c(cl.$$.fragment,l),c(Sl.$$.fragment,l),c(M.$$.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(Te.$$.fragment,l),c(oe.$$.fragment,l),c(ue.$$.fragment,l),c(Ll.$$.fragment,l),c(je.$$.fragment,l),c(we.$$.fragment,l),c(de.$$.fragment,l),c(Pl.$$.fragment,l),c(Ie.$$.fragment,l),c(_e.$$.fragment,l),c(Ge.$$.fragment,l),c(xe.$$.fragment,l),c(Re.$$.fragment,l),c(Kl.$$.fragment,l),c(Ol.$$.fragment,l),c(Ne.$$.fragment,l),c(Nl),c(Ae.$$.fragment,l),c(Ql),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(zl),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(Ts.$$.fragment,l),c(os.$$.fragment,l),c(Us.$$.fragment,l),c(us.$$.fragment,l),c(El),c(fs.$$.fragment,l),c(bs.$$.fragment,l),c(Is.$$.fragment,l),c(Fl),c(pl),c($s.$$.fragment,l),c(Zs.$$.fragment,l),c(_s.$$.fragment,l),c(Gs.$$.fragment,l),c(xs.$$.fragment,l),c(le.$$.fragment,l),Wn=!0)},o(l){y(Z.$$.fragment,l),y(k.$$.fragment,l),y($),y(N.$$.fragment,l),y(Zl.$$.fragment,l),y(ul.$$.fragment,l),y(_l.$$.fragment,l),y(dl.$$.fragment,l),y(cl.$$.fragment,l),y(Sl.$$.fragment,l),y(M.$$.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(Te.$$.fragment,l),y(oe.$$.fragment,l),y(ue.$$.fragment,l),y(Ll.$$.fragment,l),y(je.$$.fragment,l),y(we.$$.fragment,l),y(de.$$.fragment,l),y(Pl.$$.fragment,l),y(Ie.$$.fragment,l),y(_e.$$.fragment,l),y(Ge.$$.fragment,l),y(xe.$$.fragment,l),y(Re.$$.fragment,l),y(Kl.$$.fragment,l),y(Ol.$$.fragment,l),y(Ne.$$.fragment,l),y(Nl),y(Ae.$$.fragment,l),y(Ql),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(zl),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(Ts.$$.fragment,l),y(os.$$.fragment,l),y(Us.$$.fragment,l),y(us.$$.fragment,l),y(El),y(fs.$$.fragment,l),y(bs.$$.fragment,l),y(Is.$$.fragment,l),y(Fl),y(pl),y($s.$$.fragment,l),y(Zs.$$.fragment,l),y(_s.$$.fragment,l),y(Gs.$$.fragment,l),y(xs.$$.fragment,l),y(le.$$.fragment,l),Wn=!1},d(l){l&&(e(b),e(r),e(d),e(w),e(G),e(C),e(W),e(Tl),e(Q),e(S),e(ol),e(A),e(q),e(v),e(D),e(X),e(z),e(V),e(ll),e(R),e(B),e(L),e(yl),e(rl),e(el),e(hl),e(H),e(sl),e(Jl),e(il),e(tl),e(Cl),e(F),e(nl),e(Il),e(al),e(jl),e(fl),e(ml),e($l),e(i),e(Vl),e(Dl),e(I),e(se),e(Ls),e(Ps),e(ne),e(Ks),e(Os),e(lt),e(Me),e(et),e(st),e(tt),e(ce),e(nt),e(at),e(pt),e(me),e(Mt),e(rt),e(it),e(Ue),e(ct),e(yt),e(Jt),e(mt),e(Tt),e(fe),e(ot),e(Ut),e(be),e(ut),e(jt),e(he),e(wt),e(Ce),e(ft),e(dt),e($e),e(bt),e(ge),e(ht),e(Ze),e(Ct),e(It),e(ke),e($t),e(gt),e(Zt),e(Be),e(_t),e(We),e(kt),e(Gt),e(Ve),e(xt),e(Bt),e(Wt),e(Xe),e(Rt),e(Vt),e(ve),e(Xt),e(zs),e(Qe),e(Nt),e(vt),e(ze),e(Qt),e(Ye),e(At),e(Ys),e(Ee),e(zt),e(Yt),e(Et),e(Se),e(Ht),e(Ft),e(St),e(Le),e(qt),e(Dt),e(Lt),e(Oe),e(Pt),e(Kt),e(Ot),e(Es),e(ln),e(en),e(Hs),e(ns),e(sn),e(as),e(tn),e(nn),e(Ms),e(an),e(pn),e(is),e(Mn),e(cs),e(rn),e(cn),e(yn),e(ms),e(Jn),e(mn),e(Tn),e(on),e(Un),e(js),e(un),e(Fs),e(ws),e(jn),e(wn),e(ds),e(fn),e(dn),e(hs),e(bn),e(Cs),e(hn),e(Cn),e(Ss),e(qs),e(In),e(gs),e($n),e(gn),e(Zn),e(ks),e(_n),e(kn),e(Gn),e(Bs),e(xn),e(Bn),e(Ds)),e(p),u(Z,l),u(k,l),Ws[x].d(l),u(N,l),u(Zl,l),u(ul,l),u(_l,l),u(dl,l),u(cl,l),u(Sl,l),u(M,l),u(te,l),u(ae,l),u(pe,l),u(re,l),u(ie,l),u(ye,l),u(Je,l),u(Te,l),u(oe,l),u(ue,l),u(Ll,l),u(je,l),u(we,l),u(de,l),u(Pl,l),u(Ie,l),u(_e,l),u(Ge,l),u(xe,l),u(Re,l),u(Kl,l),u(Ol,l),u(Ne,l),Rs[Xl].d(l),u(Ae,l),Vs[vl].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),Xs[Al].d(l),u(ss,l),u(ts,l),bl&&bl.d(l),u(ps,l),u(rs,l),u(ys,l),u(Js,l),u(Ts,l),u(os,l),u(Us,l),u(us,l),Ns[Yl].d(l),u(fs,l),u(bs,l),u(Is,l),vs[Hl].d(l),pl&&pl.d(l),u($s,l),u(Zs,l),u(_s,l),u(Gs,l),u(xs,l),u(le,l)}}}const Ip='{"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 $p(_,p,b){let r="pt";return Ka(()=>{const d=new URLSearchParams(window.location.search);b(0,r=d.get("fw")||"pt")}),[r]}class Rp extends Oa{constructor(p){super(),lp(this,p,$p,Cp,Pa,{})}}export{Rp as component};
