import{s as zn,a as Vn,o as Yn,n as Se}from"../chunks/scheduler.cc52f4b9.js";import{S as Hn,i as Fn,e as y,s as a,c as h,h as Sn,a as w,d as t,b as n,f as Ra,g as d,j as f,k as Ie,l as qn,m as l,n as u,o as c,E as Xl,t as M,p as m,F as Nl}from"../chunks/index.5b747fde.js";import{T as et}from"../chunks/Tip.f0925d57.js";import{C as Dn,H as _e,E as Ln}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d38ac5a9.js";import{Y as Za}from"../chunks/Youtube.8bb4154e.js";import{C as j}from"../chunks/CodeBlock.665bfc37.js";import{C as En}from"../chunks/CourseFloatingBanner.b33fcd79.js";import{F as Pn}from"../chunks/FrameworkSwitchCourse.b3b657b3.js";function Kn(Z){let i,U;return i=new En({props:{chapter:7,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter7/section4_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section4_tf.ipynb"}]}}),{c(){h(i.$$.fragment)},l(p){d(i.$$.fragment,p)},m(p,b){u(i,p,b),U=!0},i(p){U||(M(i.$$.fragment,p),U=!0)},o(p){c(i.$$.fragment,p),U=!1},d(p){m(i,p)}}}function On(Z){let i,U;return i=new En({props:{chapter:7,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter7/section4_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section4_pt.ipynb"}]}}),{c(){h(i.$$.fragment)},l(p){d(i.$$.fragment,p)},m(p,b){u(i,p,b),U=!0},i(p){U||(M(i.$$.fragment,p),U=!0)},o(p){c(i.$$.fragment,p),U=!1},d(p){m(i,p)}}}function ei(Z){let i,U="✏️ <strong>Your turn!</strong> Another English word that is often used in French is “email.” Find the first sample in the training dataset that uses this word. How is it translated? How does the pretrained model translate the same English sentence?";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-uwcde8"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function ti(Z){let i,U="💡 If you are using a multilingual tokenizer such as mBART, mBART-50, or M2M100, you will need to set the language codes of your inputs and targets in the tokenizer by setting <code>tokenizer.src_lang</code> and <code>tokenizer.tgt_lang</code> to the right values.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-w81hxj"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function li(Z){let i,U="💡 If you are using a T5 model (more specifically, one of the <code>t5-xxx</code> checkpoints), the model will expect the text inputs to have a prefix indicating the task at hand, such as <code>translate: English to French:</code>.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-9rujvy"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function si(Z){let i,U="⚠️ We don’t pay attention to the attention mask of the targets, as the model won’t expect it. Instead, the labels corresponding to a padding token should be set to <code>-100</code> so they are ignored in the loss computation. This will be done by our data collator later on since we are applying dynamic padding, but if you use padding here, you should adapt the preprocessing function to set all labels that correspond to the padding token to <code>-100</code>.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-1i4t0xl"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function ai(Z){let i,U,p,b="First things first, we need an actual model to fine-tune. We’ll use the usual <code>AutoModel</code> API:",I,J,_,G,v;return i=new _e({props:{title:"Fine-tuning the model with Keras",local:"fine-tuning-the-model-with-keras",headingTag:"h2"}}),J=new j({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 et({props:{warning:!1,$$slots:{default:[ii]},$$scope:{ctx:Z}}}),{c(){h(i.$$.fragment),U=a(),p=y("p"),p.innerHTML=b,I=a(),h(J.$$.fragment),_=a(),h(G.$$.fragment)},l(k){d(i.$$.fragment,k),U=n(k),p=w(k,"P",{"data-svelte-h":!0}),f(p)!=="svelte-c4jxu5"&&(p.innerHTML=b),I=n(k),d(J.$$.fragment,k),_=n(k),d(G.$$.fragment,k)},m(k,g){u(i,k,g),l(k,U,g),l(k,p,g),l(k,I,g),u(J,k,g),l(k,_,g),u(G,k,g),v=!0},i(k){v||(M(i.$$.fragment,k),M(J.$$.fragment,k),M(G.$$.fragment,k),v=!0)},o(k){c(i.$$.fragment,k),c(J.$$.fragment,k),c(G.$$.fragment,k),v=!1},d(k){k&&(t(U),t(p),t(I),t(_)),m(i,k),m(J,k),m(G,k)}}}function ni(Z){let i,U,p,b='The actual code using the <code>Trainer</code> will be the same as before, with just one little change: we use a <a href="https://huggingface.co/transformers/main_classes/trainer.html#seq2seqtrainer" rel="nofollow"><code>Seq2SeqTrainer</code></a> here, which is a subclass of <code>Trainer</code> that will allow us to properly deal with the evaluation, using the <code>generate()</code> method to predict outputs from the inputs. We’ll dive into that in more detail when we talk about the metric computation.',I,J,_="First things first, we need an actual model to fine-tune. We’ll use the usual <code>AutoModel</code> API:",G,v,k;return i=new _e({props:{title:"Fine-tuning the model with the Trainer API",local:"fine-tuning-the-model-with-the-trainer-api",headingTag:"h2"}}),v=new j({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(){h(i.$$.fragment),U=a(),p=y("p"),p.innerHTML=b,I=a(),J=y("p"),J.innerHTML=_,G=a(),h(v.$$.fragment)},l(g){d(i.$$.fragment,g),U=n(g),p=w(g,"P",{"data-svelte-h":!0}),f(p)!=="svelte-1u27cnc"&&(p.innerHTML=b),I=n(g),J=w(g,"P",{"data-svelte-h":!0}),f(J)!=="svelte-c4jxu5"&&(J.innerHTML=_),G=n(g),d(v.$$.fragment,g)},m(g,B){u(i,g,B),l(g,U,B),l(g,p,B),l(g,I,B),l(g,J,B),l(g,G,B),u(v,g,B),k=!0},i(g){k||(M(i.$$.fragment,g),M(v.$$.fragment,g),k=!0)},o(g){c(i.$$.fragment,g),c(v.$$.fragment,g),k=!1},d(g){g&&(t(U),t(p),t(I),t(J),t(G)),m(i,g),m(v,g)}}}function ii(Z){let i,U=`💡 The <code>Helsinki-NLP/opus-mt-en-fr</code> checkpoint only has PyTorch weights, so
you’ll get an error if you try to load the model without using the
<code>from_pt=True</code> argument in the <code>from_pretrained()</code> method. When you specify
<code>from_pt=True</code>, the library will automatically download and convert the
PyTorch weights for you. As you can see, it is very simple to switch between
frameworks in 🤗 Transformers!`;return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-1swjwma"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function ri(Z){let i,U;return i=new j({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(){h(i.$$.fragment)},l(p){d(i.$$.fragment,p)},m(p,b){u(i,p,b),U=!0},i(p){U||(M(i.$$.fragment,p),U=!0)},o(p){c(i.$$.fragment,p),U=!1},d(p){m(i,p)}}}function pi(Z){let i,U;return i=new j({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(){h(i.$$.fragment)},l(p){d(i.$$.fragment,p)},m(p,b){u(i,p,b),U=!0},i(p){U||(M(i.$$.fragment,p),U=!0)},o(p){c(i.$$.fragment,p),U=!1},d(p){m(i,p)}}}function oi(Z){let i,U="We can now use this <code>data_collator</code> to convert each of our datasets to a <code>tf.data.Dataset</code>, ready for training:",p,b,I;return b=new j({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMzIlMkMlMEEpJTBBdGZfZXZhbF9kYXRhc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxNiUyQyUwQSk=",highlighted:`tf_train_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">32</span>,
)
tf_eval_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">16</span>,
)`,wrap:!1}}),{c(){i=y("p"),i.innerHTML=U,p=a(),h(b.$$.fragment)},l(J){i=w(J,"P",{"data-svelte-h":!0}),f(i)!=="svelte-1hevmzh"&&(i.innerHTML=U),p=n(J),d(b.$$.fragment,J)},m(J,_){l(J,i,_),l(J,p,_),u(b,J,_),I=!0},i(J){I||(M(b.$$.fragment,J),I=!0)},o(J){c(b.$$.fragment,J),I=!1},d(J){J&&(t(i),t(p)),m(b,J)}}}function Mi(Z){let i,U="We will pass this <code>data_collator</code> along to the <code>Seq2SeqTrainer</code>. Next, let’s have a look at the metric.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-gyo8yo"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},i:Se,o:Se,d(p){p&&t(i)}}}function An(Z){let i,U="The feature that <code>Seq2SeqTrainer</code> adds to its superclass <code>Trainer</code> is the ability to use the <code>generate()</code> method during evaluation or prediction. During training, the model will use the <code>decoder_input_ids</code> with an attention mask ensuring it does not use the tokens after the token it’s trying to predict, to speed up training. During inference we won’t be able to use those since we won’t have labels, so it’s a good idea to evaluate our model with the same setup.",p,b,I='As we saw in <a href="/course/chapter1/6">Chapter 1</a>, the decoder performs inference by predicting tokens one by one — something that’s implemented behind the scenes in 🤗 Transformers by the <code>generate()</code> method. The <code>Seq2SeqTrainer</code> will let us use that method for evaluation if we set <code>predict_with_generate=True</code>.';return{c(){i=y("p"),i.innerHTML=U,p=a(),b=y("p"),b.innerHTML=I},l(J){i=w(J,"P",{"data-svelte-h":!0}),f(i)!=="svelte-1dssf7l"&&(i.innerHTML=U),p=n(J),b=w(J,"P",{"data-svelte-h":!0}),f(b)!=="svelte-thx2aq"&&(b.innerHTML=I)},m(J,_){l(J,i,_),l(J,p,_),l(J,b,_)},d(J){J&&(t(i),t(p),t(b))}}}function ci(Z){let i,U="To get from the model outputs to texts the metric can use, we will use the <code>tokenizer.batch_decode()</code> method. We just have to clean up all the <code>-100</code>s in the labels (the tokenizer will automatically do the same for the padding token):",p,b,I;return b=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZHMpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWRzJTBBJTIwJTIwJTIwJTIwJTIzJTIwSW4lMjBjYXNlJTIwdGhlJTIwbW9kZWwlMjByZXR1cm5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TIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RkZWNvZGVkX3ByZWRzJTJDJTIwcmVmZXJlbmNlcyUzRGRlY29kZWRfbGFiZWxzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMmJsZXUlMjIlM0ElMjByZXN1bHQlNUIlMjJzY29yZSUyMiU1RCU3RA==",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(){i=y("p"),i.innerHTML=U,p=a(),h(b.$$.fragment)},l(J){i=w(J,"P",{"data-svelte-h":!0}),f(i)!=="svelte-12prd39"&&(i.innerHTML=U),p=n(J),d(b.$$.fragment,J)},m(J,_){l(J,i,_),l(J,p,_),u(b,J,_),I=!0},i(J){I||(M(b.$$.fragment,J),I=!0)},o(J){c(b.$$.fragment,J),I=!1},d(J){J&&(t(i),t(p)),m(b,J)}}}function hi(Z){let i,U='To get from the model outputs to texts the metric can use, we will use the <code>tokenizer.batch_decode()</code> method. We just have to clean up all the <code>-100</code>s in the labels; the tokenizer will automatically do the same for the padding token. Let’s define a function that takes our model and a dataset and computes metrics on it. We’re also going to use a trick that dramatically increases performance - compiling our generation code with <a href="https://www.tensorflow.org/xla" rel="nofollow">XLA</a>, TensorFlow’s accelerated linear algebra compiler. XLA applies various optimizations to the model’s computation graph, and results in significant improvements to speed and memory usage. As described in the Hugging Face <a href="https://huggingface.co/blog/tf-xla-generate" rel="nofollow">blog</a>, XLA works best when our input shapes don’t vary too much. To handle this, we’ll pad our inputs to multiples of 128, and make a new dataset with the padding collator, and then we’ll apply the <code>@tf.function(jit_compile=True)</code> decorator to our generation function, which marks the whole function for compilation with XLA.',p,b,I;return b=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHFkbSUyMGltcG9ydCUyMHRxZG0lMEElMEFnZW5lcmF0aW9uX2RhdGFfY29sbGF0b3IlMjAlM0QlMjBEYXRhQ29sbGF0b3JGb3JTZXEyU2VxKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUyQyUyMG1vZGVsJTNEbW9kZWwlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyJTJDJTIwcGFkX3RvX211bHRpcGxlX29mJTNEMTI4JTBBKSUwQSUwQXRmX2dlbmVyYXRlX2RhdGFzZXQlMjAlM0QlMjBtb2RlbC5wcmVwYXJlX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RnZW5l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ted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> tqdm <span class="hljs-keyword">import</span> tqdm

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

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


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


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>():
    all_preds = []
    all_labels = []

    <span class="hljs-keyword">for</span> batch, labels <span class="hljs-keyword">in</span> tqdm(tf_generate_dataset):
        predictions = generate_with_xla(batch)
        decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
        labels = labels.numpy()
        labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
        decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
        decoded_preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
        decoded_labels = [[label.strip()] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]
        all_preds.extend(decoded_preds)
        all_labels.extend(decoded_labels)

    result = metric.compute(predictions=all_preds, references=all_labels)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;bleu&quot;</span>: result[<span class="hljs-string">&quot;score&quot;</span>]}`,wrap:!1}}),{c(){i=y("p"),i.innerHTML=U,p=a(),h(b.$$.fragment)},l(J){i=w(J,"P",{"data-svelte-h":!0}),f(i)!=="svelte-de3ij7"&&(i.innerHTML=U),p=n(J),d(b.$$.fragment,J)},m(J,_){l(J,i,_),l(J,p,_),u(b,J,_),I=!0},i(J){I||(M(b.$$.fragment,J),I=!0)},o(J){c(b.$$.fragment,J),I=!1},d(J){J&&(t(i),t(p)),m(b,J)}}}function di(Z){let i,U="Once this is done, we can define our <code>Seq2SeqTrainingArguments</code>. Like for the <code>Trainer</code>, we use a subclass of <code>TrainingArguments</code> that contains a few more fields:",p,b,I,J,_="Apart from the usual hyperparameters (like learning rate, number of epochs, batch size, and some weight decay), here are a few changes compared to what we saw in the previous sections:",G,v,k="<li>We don’t set any regular evaluation, as evaluation takes a while; we will just evaluate our model once before training and after.</li> <li>We set <code>fp16=True</code>, which speeds up training on modern GPUs.</li> <li>We set <code>predict_with_generate=True</code>, as discussed above.</li> <li>We use <code>push_to_hub=True</code> to upload the model to the Hub at the end of each epoch.</li>",g,B,X='Note that you can specify the full name of the repository you want to push to with the <code>hub_model_id</code> argument (in particular, you will have to use this argument to push to an organization). For instance, when we pushed the model to the <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, we added <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en-to-fr&quot;</code> to <code>Seq2SeqTrainingArguments</code>. By default, the repository used will be in your namespace and named after the output directory you set, so in our case it will be <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code> (which is the model we linked to at the beginning of this section).',ie,O,N,V,P="Finally, we just pass everything to the <code>Seq2SeqTrainer</code>:",ye,A,Q,E,K="Before training, we’ll first look at the score our model gets, to double-check that we’re not making things worse with our fine-tuning. This command will take a bit of time, so you can grab a coffee while it executes:",we,z,H,L,R,re,ee="A BLEU score of 39 is not too bad, which reflects the fact that our model is already good at translating English sentences to French ones.",W,te,T="Next is the training, which will also take a bit of time:",x,fe,ce,le,ke="Note that while the training happens, each time the model is saved (here, every epoch) it is uploaded to the Hub in the background. This way, you will be able to to resume your training on another machine if necessary.",Ue,F,Ye="Once training is done, we evaluate our model again — hopefully we will see some amelioration in the BLEU score!",he,pe,je,S,xe,se,Ze="That’s a nearly 14-point improvement, which is great.",ge,q,He="Finally, we use the <code>push_to_hub()</code> method to make sure we upload the latest version of the model. The <code>Trainer</code> also drafts a model card with all the evaluation results and uploads it. This model card contains metadata that helps the Model Hub pick the widget for the inference demo. Usually, there is no need to say anything as it can infer the right widget from the model class, but in this case, the same model class can be used for all kinds of sequence-to-sequence problems, so we specify it’s a translation model:",de,oe,Ce,Y,qe="This command returns the URL of the commit it just did, if you want to inspect it:",$e,D,Fe,ue,Me="At this stage, you can use the inference widget on the Model Hub to test your model and share it with your friends. You have successfully fine-tuned a model on a translation task — congratulations!",Ge,ae,Je="If you want to dive a bit more deeply into the training loop, we will now show you how to do the same thing using 🤗 Accelerate.",me;return b=new j({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}}),O=new et({props:{$$slots:{default:[mi]},$$scope:{ctx:Z}}}),A=new j({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}}),z=new j({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),L=new j({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}}),fe=new j({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),pe=new j({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),S=new j({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}}),oe=new j({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}}),D=new j({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(){i=y("p"),i.innerHTML=U,p=a(),h(b.$$.fragment),I=a(),J=y("p"),J.textContent=_,G=a(),v=y("ul"),v.innerHTML=k,g=a(),B=y("p"),B.innerHTML=X,ie=a(),h(O.$$.fragment),N=a(),V=y("p"),V.innerHTML=P,ye=a(),h(A.$$.fragment),Q=a(),E=y("p"),E.textContent=K,we=a(),h(z.$$.fragment),H=a(),h(L.$$.fragment),R=a(),re=y("p"),re.textContent=ee,W=a(),te=y("p"),te.textContent=T,x=a(),h(fe.$$.fragment),ce=a(),le=y("p"),le.textContent=ke,Ue=a(),F=y("p"),F.textContent=Ye,he=a(),h(pe.$$.fragment),je=a(),h(S.$$.fragment),xe=a(),se=y("p"),se.textContent=Ze,ge=a(),q=y("p"),q.innerHTML=He,de=a(),h(oe.$$.fragment),Ce=a(),Y=y("p"),Y.textContent=qe,$e=a(),h(D.$$.fragment),Fe=a(),ue=y("p"),ue.textContent=Me,Ge=a(),ae=y("p"),ae.textContent=Je},l(o){i=w(o,"P",{"data-svelte-h":!0}),f(i)!=="svelte-1hue7r3"&&(i.innerHTML=U),p=n(o),d(b.$$.fragment,o),I=n(o),J=w(o,"P",{"data-svelte-h":!0}),f(J)!=="svelte-vr7kv5"&&(J.textContent=_),G=n(o),v=w(o,"UL",{"data-svelte-h":!0}),f(v)!=="svelte-ckg3z2"&&(v.innerHTML=k),g=n(o),B=w(o,"P",{"data-svelte-h":!0}),f(B)!=="svelte-14ymb4g"&&(B.innerHTML=X),ie=n(o),d(O.$$.fragment,o),N=n(o),V=w(o,"P",{"data-svelte-h":!0}),f(V)!=="svelte-vnqwl3"&&(V.innerHTML=P),ye=n(o),d(A.$$.fragment,o),Q=n(o),E=w(o,"P",{"data-svelte-h":!0}),f(E)!=="svelte-ixolzg"&&(E.textContent=K),we=n(o),d(z.$$.fragment,o),H=n(o),d(L.$$.fragment,o),R=n(o),re=w(o,"P",{"data-svelte-h":!0}),f(re)!=="svelte-16qcd8b"&&(re.textContent=ee),W=n(o),te=w(o,"P",{"data-svelte-h":!0}),f(te)!=="svelte-1shq479"&&(te.textContent=T),x=n(o),d(fe.$$.fragment,o),ce=n(o),le=w(o,"P",{"data-svelte-h":!0}),f(le)!=="svelte-2l4fow"&&(le.textContent=ke),Ue=n(o),F=w(o,"P",{"data-svelte-h":!0}),f(F)!=="svelte-1tyayn3"&&(F.textContent=Ye),he=n(o),d(pe.$$.fragment,o),je=n(o),d(S.$$.fragment,o),xe=n(o),se=w(o,"P",{"data-svelte-h":!0}),f(se)!=="svelte-2wjeu9"&&(se.textContent=Ze),ge=n(o),q=w(o,"P",{"data-svelte-h":!0}),f(q)!=="svelte-emcbnj"&&(q.innerHTML=He),de=n(o),d(oe.$$.fragment,o),Ce=n(o),Y=w(o,"P",{"data-svelte-h":!0}),f(Y)!=="svelte-mme7gz"&&(Y.textContent=qe),$e=n(o),d(D.$$.fragment,o),Fe=n(o),ue=w(o,"P",{"data-svelte-h":!0}),f(ue)!=="svelte-1is5qce"&&(ue.textContent=Me),Ge=n(o),ae=w(o,"P",{"data-svelte-h":!0}),f(ae)!=="svelte-1q5ysr9"&&(ae.textContent=Je)},m(o,$){l(o,i,$),l(o,p,$),u(b,o,$),l(o,I,$),l(o,J,$),l(o,G,$),l(o,v,$),l(o,g,$),l(o,B,$),l(o,ie,$),u(O,o,$),l(o,N,$),l(o,V,$),l(o,ye,$),u(A,o,$),l(o,Q,$),l(o,E,$),l(o,we,$),u(z,o,$),l(o,H,$),u(L,o,$),l(o,R,$),l(o,re,$),l(o,W,$),l(o,te,$),l(o,x,$),u(fe,o,$),l(o,ce,$),l(o,le,$),l(o,Ue,$),l(o,F,$),l(o,he,$),u(pe,o,$),l(o,je,$),u(S,o,$),l(o,xe,$),l(o,se,$),l(o,ge,$),l(o,q,$),l(o,de,$),u(oe,o,$),l(o,Ce,$),l(o,Y,$),l(o,$e,$),u(D,o,$),l(o,Fe,$),l(o,ue,$),l(o,Ge,$),l(o,ae,$),me=!0},i(o){me||(M(b.$$.fragment,o),M(O.$$.fragment,o),M(A.$$.fragment,o),M(z.$$.fragment,o),M(L.$$.fragment,o),M(fe.$$.fragment,o),M(pe.$$.fragment,o),M(S.$$.fragment,o),M(oe.$$.fragment,o),M(D.$$.fragment,o),me=!0)},o(o){c(b.$$.fragment,o),c(O.$$.fragment,o),c(A.$$.fragment,o),c(z.$$.fragment,o),c(L.$$.fragment,o),c(fe.$$.fragment,o),c(pe.$$.fragment,o),c(S.$$.fragment,o),c(oe.$$.fragment,o),c(D.$$.fragment,o),me=!1},d(o){o&&(t(i),t(p),t(I),t(J),t(G),t(v),t(g),t(B),t(ie),t(N),t(V),t(ye),t(Q),t(E),t(we),t(H),t(R),t(re),t(W),t(te),t(x),t(ce),t(le),t(Ue),t(F),t(he),t(je),t(xe),t(se),t(ge),t(q),t(de),t(Ce),t(Y),t($e),t(Fe),t(ue),t(Ge),t(ae)),m(b,o),m(O,o),m(A,o),m(z,o),m(L,o),m(fe,o),m(pe,o),m(S,o),m(oe,o),m(D,o)}}}function ui(Z){let i,U="Before we start, let’s see what kind of results we get from our model without any training:",p,b,I,J,_,G,v="Once this is done, we can prepare everything we need to compile and train our model. Note the use of <code>tf.keras.mixed_precision.set_global_policy(&quot;mixed_float16&quot;)</code> — this will tell Keras to train using float16, which can give a significant speedup on GPUs that support it (Nvidia 20xx/V100 or newer).",k,g,B,X,ie='Next, we define a <code>PushToHubCallback</code> to upload our model to the Hub during training, as we saw in <a href="(/course/chapter7/2)">section 2</a>, and then we simply fit the model with that callback:',O,N,V,P,ye='Note that you can specify the name of the repository you want to push to with the <code>hub_model_id</code> argument (in particular, you will have to use this argument to push to an organization). For instance, when we pushed the model to the <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, we added <code>hub_model_id=&quot;huggingface-course/marian-finetuned-kde4-en-to-fr&quot;</code> to <code>Seq2SeqTrainingArguments</code>. By default, the repository used will be in your namespace and named after the output directory you set, so here it will be <code>&quot;sgugger/marian-finetuned-kde4-en-to-fr&quot;</code> (which is the model we linked to at the beginning of this section).',A,Q,E,K,we="Finally, let’s see what our metrics look like now that training has finished:",z,H,L,R,re,ee,W="At this stage, you can use the inference widget on the Model Hub to test your model and share it with your friends. You have successfully fine-tuned a model on a translation task — congratulations!",te;return b=new j({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),J=new j({props:{code:"JTdCJ2JsZXUnJTNBJTIwMzMuMjY5ODM3MDE0NTQ3MzMlN0Q=",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">33.26983701454733</span>}',wrap:!1}}),g=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmtlcmFzX2NhbGxiYWNrcyUyMGltcG9ydCUyMFB1c2hUb0h1YkNhbGxiYWNrJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEElMjMlMjBUaGUlMjBudW1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JTIwZmxvYXQxNiUwQXRmLmtlcmFzLm1peGVkX3ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

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

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

<span class="hljs-comment"># Train in mixed-precision float16</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)`,wrap:!1}}),N=new j({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}}),Q=new et({props:{$$slots:{default:[yi]},$$scope:{ctx:Z}}}),H=new j({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),R=new j({props:{code:"JTdCJ2JsZXUnJTNBJTIwNTcuMzM0MDY2MjcxNTQ1ODY1JTdE",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">57.334066271545865</span>}',wrap:!1}}),{c(){i=y("p"),i.textContent=U,p=a(),h(b.$$.fragment),I=a(),h(J.$$.fragment),_=a(),G=y("p"),G.innerHTML=v,k=a(),h(g.$$.fragment),B=a(),X=y("p"),X.innerHTML=ie,O=a(),h(N.$$.fragment),V=a(),P=y("p"),P.innerHTML=ye,A=a(),h(Q.$$.fragment),E=a(),K=y("p"),K.textContent=we,z=a(),h(H.$$.fragment),L=a(),h(R.$$.fragment),re=a(),ee=y("p"),ee.textContent=W},l(T){i=w(T,"P",{"data-svelte-h":!0}),f(i)!=="svelte-15un45t"&&(i.textContent=U),p=n(T),d(b.$$.fragment,T),I=n(T),d(J.$$.fragment,T),_=n(T),G=w(T,"P",{"data-svelte-h":!0}),f(G)!=="svelte-6yez9a"&&(G.innerHTML=v),k=n(T),d(g.$$.fragment,T),B=n(T),X=w(T,"P",{"data-svelte-h":!0}),f(X)!=="svelte-xippoq"&&(X.innerHTML=ie),O=n(T),d(N.$$.fragment,T),V=n(T),P=w(T,"P",{"data-svelte-h":!0}),f(P)!=="svelte-1r4up0e"&&(P.innerHTML=ye),A=n(T),d(Q.$$.fragment,T),E=n(T),K=w(T,"P",{"data-svelte-h":!0}),f(K)!=="svelte-qf3ykr"&&(K.textContent=we),z=n(T),d(H.$$.fragment,T),L=n(T),d(R.$$.fragment,T),re=n(T),ee=w(T,"P",{"data-svelte-h":!0}),f(ee)!=="svelte-1is5qce"&&(ee.textContent=W)},m(T,x){l(T,i,x),l(T,p,x),u(b,T,x),l(T,I,x),u(J,T,x),l(T,_,x),l(T,G,x),l(T,k,x),u(g,T,x),l(T,B,x),l(T,X,x),l(T,O,x),u(N,T,x),l(T,V,x),l(T,P,x),l(T,A,x),u(Q,T,x),l(T,E,x),l(T,K,x),l(T,z,x),u(H,T,x),l(T,L,x),u(R,T,x),l(T,re,x),l(T,ee,x),te=!0},i(T){te||(M(b.$$.fragment,T),M(J.$$.fragment,T),M(g.$$.fragment,T),M(N.$$.fragment,T),M(Q.$$.fragment,T),M(H.$$.fragment,T),M(R.$$.fragment,T),te=!0)},o(T){c(b.$$.fragment,T),c(J.$$.fragment,T),c(g.$$.fragment,T),c(N.$$.fragment,T),c(Q.$$.fragment,T),c(H.$$.fragment,T),c(R.$$.fragment,T),te=!1},d(T){T&&(t(i),t(p),t(I),t(_),t(G),t(k),t(B),t(X),t(O),t(V),t(P),t(A),t(E),t(K),t(z),t(L),t(re),t(ee)),m(b,T),m(J,T),m(g,T),m(N,T),m(Q,T),m(H,T),m(R,T)}}}function mi(Z){let i,U="💡 If the output directory you are using already exists, it needs to be a local clone of the repository you want to push to. If it isn’t, you’ll get an error when defining your <code>Seq2SeqTrainer</code> and will need to set a new name.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-449gha"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function yi(Z){let i,U="💡 If the output directory you are using already exists, it needs to be a local clone of the repository you want to push to. If it isn’t, you’ll get an error when calling <code>model.fit()</code> and will need to set a new name.";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-fiahcl"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function Qn(Z){let i,U,p,b='Let’s now take a look at the full training loop, so you can easily customize the parts you need. It will look a lot like what we did in <a href="/course/chapter7/2">section 2</a> and <a href="/course/chapter3/4">Chapter 3</a>.',I,J,_,G,v="You’ve seen all of this a few times now, so we’ll go through the code quite quickly. First we’ll build the <code>DataLoader</code>s from our datasets, after setting the datasets to the <code>&quot;torch&quot;</code> format so we get PyTorch tensors:",k,g,B,X,ie="Next we reinstantiate our model, to make sure we’re not continuing the fine-tuning from before but starting from the pretrained model again:",O,N,V,P,ye="Then we will need an optimizer:",A,Q,E,K,we="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method. Remember that if you want to train on TPUs in a Colab notebook, you will need to move all of this code into a training function, and that shouldn’t execute any cell that instantiates an <code>Accelerator</code>.",z,H,L,R,re="Now that we have sent our <code>train_dataloader</code> to <code>accelerator.prepare()</code>, we can use its length to compute the number of training steps. Remember we should always do this after preparing the dataloader, as that method will change the length of the <code>DataLoader</code>. We use a classic linear schedule from the learning rate to 0:",ee,W,te,T,x="Lastly, to push our model to the Hub, we will need to create a <code>Repository</code> object in a working folder. First log in to the Hugging Face Hub, if you’re not logged in already. We’ll determine the repository name from the model ID we want to give our model (feel free to replace the <code>repo_name</code> with your own choice; it just needs to contain your username, which is what the function <code>get_full_repo_name()</code> does):",fe,ce,le,ke,Ue,F,Ye="Then we can clone that repository in a local folder. If it already exists, this local folder should be a clone of the repository we are working with:",he,pe,je,S,xe="We can now upload anything we save in <code>output_dir</code> by calling the <code>repo.push_to_hub()</code> method. This will help us upload the intermediate models at the end of each epoch.",se,Ze,ge,q,He="We are now ready to write the full training loop. To simplify its evaluation part, we define this <code>postprocess()</code> function that takes predictions and labels and converts them to the lists of strings our <code>metric</code> object will expect:",de,oe,Ce,Y,qe='The training loop looks a lot like the ones in <a href="/course/chapter7/2">section 2</a> and <a href="/course/chapter3">Chapter 3</a>, with a few differences in the evaluation part — so let’s focus on that!',$e,D,Fe="The first thing to note is that we use the <code>generate()</code> method to compute predictions, but this is a method on our base model, not the wrapped model 🤗 Accelerate created in the <code>prepare()</code> method. That’s why we unwrap the model first, then call this method.",ue,Me,Ge='The second thing is that, like with <a href="/course/chapter7/2">token classification</a>, two processes may have padded the inputs and labels to different shapes, so we use <code>accelerator.pad_across_processes()</code> to make the predictions and labels the same shape before calling the <code>gather()</code> method. If we don’t do this, the evaluation will either error out or hang forever.',ae,Je,me,o,$,Te,tt='Once this is done, you should have a model that has results pretty similar to the one trained with the <code>Seq2SeqTrainer</code>. You can check the one we trained using this code at <a href="https://huggingface.co/huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate" rel="nofollow"><em>huggingface-course/marian-finetuned-kde4-en-to-fr-accelerate</em></a>. And if you want to test out any tweaks to the training loop, you can directly implement them by editing the code shown above!',Be;return i=new _e({props:{title:"A custom training loop",local:"a-custom-training-loop",headingTag:"h2"}}),J=new _e({props:{title:"Preparing everything for training",local:"preparing-everything-for-training",headingTag:"h3"}}),g=new j({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBdG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIpJTBBdHJhaW5fZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMjBiYXRjaF9zaXplJTNEOCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

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

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),H=new j({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}}),W=new j({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}}),ce=new j({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}}),ke=new j({props:{code:"J3NndWdnZXIlMkZtYXJpYW4tZmluZXR1bmVkLWtkZTQtZW4tdG8tZnItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/marian-finetuned-kde4-en-to-fr-accelerate&#x27;</span>',wrap:!1}}),pe=new j({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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IlNUJsYWJlbC5zdHJpcCgpJTVEJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxz",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}}),Je=new j({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHJhaW5fZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjB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IoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29tbWl0X21lc3NhZ2UlM0RmJTIyVHJhaW5pbmclMjBpbiUyMHByb2dyZXNzJTIwZXBvY2glMjAlN0JlcG9jaCU3RCUyMiUyQyUyMGJsb2NraW5nJTNERmFsc2UlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAp",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}}),o=new j({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(){h(i.$$.fragment),U=a(),p=y("p"),p.innerHTML=b,I=a(),h(J.$$.fragment),_=a(),G=y("p"),G.innerHTML=v,k=a(),h(g.$$.fragment),B=a(),X=y("p"),X.textContent=ie,O=a(),h(N.$$.fragment),V=a(),P=y("p"),P.textContent=ye,A=a(),h(Q.$$.fragment),E=a(),K=y("p"),K.innerHTML=we,z=a(),h(H.$$.fragment),L=a(),R=y("p"),R.innerHTML=re,ee=a(),h(W.$$.fragment),te=a(),T=y("p"),T.innerHTML=x,fe=a(),h(ce.$$.fragment),le=a(),h(ke.$$.fragment),Ue=a(),F=y("p"),F.textContent=Ye,he=a(),h(pe.$$.fragment),je=a(),S=y("p"),S.innerHTML=xe,se=a(),h(Ze.$$.fragment),ge=a(),q=y("p"),q.innerHTML=He,de=a(),h(oe.$$.fragment),Ce=a(),Y=y("p"),Y.innerHTML=qe,$e=a(),D=y("p"),D.innerHTML=Fe,ue=a(),Me=y("p"),Me.innerHTML=Ge,ae=a(),h(Je.$$.fragment),me=a(),h(o.$$.fragment),$=a(),Te=y("p"),Te.innerHTML=tt},l(r){d(i.$$.fragment,r),U=n(r),p=w(r,"P",{"data-svelte-h":!0}),f(p)!=="svelte-qavg11"&&(p.innerHTML=b),I=n(r),d(J.$$.fragment,r),_=n(r),G=w(r,"P",{"data-svelte-h":!0}),f(G)!=="svelte-1xyz8xy"&&(G.innerHTML=v),k=n(r),d(g.$$.fragment,r),B=n(r),X=w(r,"P",{"data-svelte-h":!0}),f(X)!=="svelte-e8509p"&&(X.textContent=ie),O=n(r),d(N.$$.fragment,r),V=n(r),P=w(r,"P",{"data-svelte-h":!0}),f(P)!=="svelte-47lq6z"&&(P.textContent=ye),A=n(r),d(Q.$$.fragment,r),E=n(r),K=w(r,"P",{"data-svelte-h":!0}),f(K)!=="svelte-18hq2jn"&&(K.innerHTML=we),z=n(r),d(H.$$.fragment,r),L=n(r),R=w(r,"P",{"data-svelte-h":!0}),f(R)!=="svelte-udl66p"&&(R.innerHTML=re),ee=n(r),d(W.$$.fragment,r),te=n(r),T=w(r,"P",{"data-svelte-h":!0}),f(T)!=="svelte-v6q3yq"&&(T.innerHTML=x),fe=n(r),d(ce.$$.fragment,r),le=n(r),d(ke.$$.fragment,r),Ue=n(r),F=w(r,"P",{"data-svelte-h":!0}),f(F)!=="svelte-e9w2am"&&(F.textContent=Ye),he=n(r),d(pe.$$.fragment,r),je=n(r),S=w(r,"P",{"data-svelte-h":!0}),f(S)!=="svelte-1mcbsiy"&&(S.innerHTML=xe),se=n(r),d(Ze.$$.fragment,r),ge=n(r),q=w(r,"P",{"data-svelte-h":!0}),f(q)!=="svelte-1x90r0t"&&(q.innerHTML=He),de=n(r),d(oe.$$.fragment,r),Ce=n(r),Y=w(r,"P",{"data-svelte-h":!0}),f(Y)!=="svelte-11l1dbc"&&(Y.innerHTML=qe),$e=n(r),D=w(r,"P",{"data-svelte-h":!0}),f(D)!=="svelte-1sfscsd"&&(D.innerHTML=Fe),ue=n(r),Me=w(r,"P",{"data-svelte-h":!0}),f(Me)!=="svelte-1cf30vw"&&(Me.innerHTML=Ge),ae=n(r),d(Je.$$.fragment,r),me=n(r),d(o.$$.fragment,r),$=n(r),Te=w(r,"P",{"data-svelte-h":!0}),f(Te)!=="svelte-ezkapr"&&(Te.innerHTML=tt)},m(r,C){u(i,r,C),l(r,U,C),l(r,p,C),l(r,I,C),u(J,r,C),l(r,_,C),l(r,G,C),l(r,k,C),u(g,r,C),l(r,B,C),l(r,X,C),l(r,O,C),u(N,r,C),l(r,V,C),l(r,P,C),l(r,A,C),u(Q,r,C),l(r,E,C),l(r,K,C),l(r,z,C),u(H,r,C),l(r,L,C),l(r,R,C),l(r,ee,C),u(W,r,C),l(r,te,C),l(r,T,C),l(r,fe,C),u(ce,r,C),l(r,le,C),u(ke,r,C),l(r,Ue,C),l(r,F,C),l(r,he,C),u(pe,r,C),l(r,je,C),l(r,S,C),l(r,se,C),u(Ze,r,C),l(r,ge,C),l(r,q,C),l(r,de,C),u(oe,r,C),l(r,Ce,C),l(r,Y,C),l(r,$e,C),l(r,D,C),l(r,ue,C),l(r,Me,C),l(r,ae,C),u(Je,r,C),l(r,me,C),u(o,r,C),l(r,$,C),l(r,Te,C),Be=!0},i(r){Be||(M(i.$$.fragment,r),M(J.$$.fragment,r),M(g.$$.fragment,r),M(N.$$.fragment,r),M(Q.$$.fragment,r),M(H.$$.fragment,r),M(W.$$.fragment,r),M(ce.$$.fragment,r),M(ke.$$.fragment,r),M(pe.$$.fragment,r),M(Ze.$$.fragment,r),M(oe.$$.fragment,r),M(Je.$$.fragment,r),M(o.$$.fragment,r),Be=!0)},o(r){c(i.$$.fragment,r),c(J.$$.fragment,r),c(g.$$.fragment,r),c(N.$$.fragment,r),c(Q.$$.fragment,r),c(H.$$.fragment,r),c(W.$$.fragment,r),c(ce.$$.fragment,r),c(ke.$$.fragment,r),c(pe.$$.fragment,r),c(Ze.$$.fragment,r),c(oe.$$.fragment,r),c(Je.$$.fragment,r),c(o.$$.fragment,r),Be=!1},d(r){r&&(t(U),t(p),t(I),t(_),t(G),t(k),t(B),t(X),t(O),t(V),t(P),t(A),t(E),t(K),t(z),t(L),t(R),t(ee),t(te),t(T),t(fe),t(le),t(Ue),t(F),t(he),t(je),t(S),t(se),t(ge),t(q),t(de),t(Ce),t(Y),t($e),t(D),t(ue),t(Me),t(ae),t(me),t($),t(Te)),m(i,r),m(J,r),m(g,r),m(N,r),m(Q,r),m(H,r),m(W,r),m(ce,r),m(ke,r),m(pe,r),m(Ze,r),m(oe,r),m(Je,r),m(o,r)}}}function wi(Z){let i,U="✏️ <strong>Your turn!</strong> What does the model return on the sample with the word “email” you identified earlier?";return{c(){i=y("p"),i.innerHTML=U},l(p){i=w(p,"P",{"data-svelte-h":!0}),f(i)!=="svelte-9o8gsu"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Se,d(p){p&&t(i)}}}function fi(Z){let i,U,p,b,I,J,_,G,v,k,g,B,X,ie,O='Let’s now dive into translation. This is another <a href="/course/chapter1/7">sequence-to-sequence task</a>, which means it’s a problem that can be formulated as going from one sequence to another. In that sense the problem is pretty close to <a href="/course/chapter7/6">summarization</a>, and you could adapt what we will see here to other sequence-to-sequence problems such as:',N,V,P="<li><strong>Style transfer</strong>: Creating a model that <em>translates</em> texts written in a certain style to another (e.g., formal to casual or Shakespearean English to modern English)</li> <li><strong>Generative question answering</strong>: Creating a model that generates answers to questions, given a context</li>",ye,A,Q,E,K='If you have a big enough corpus of texts in two (or more) languages, you can train a new translation model from scratch like we will in the section on <a href="/course/chapter7/6">causal language modeling</a>. It will be faster, however, to fine-tune an existing translation model, be it a multilingual one like mT5 or mBART that you want to fine-tune to a specific language pair, or even a model specialized for translation from one language to another that you want to fine-tune to your specific corpus.',we,z,H='In this section, we will fine-tune a Marian model pretrained to translate from English to French (since a lot of Hugging Face employees speak both those languages) on the <a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 dataset</a>, which is a dataset of localized files for the <a href="https://apps.kde.org/" rel="nofollow">KDE apps</a>. The model we will use has been pretrained on a large corpus of French and English texts taken from the <a href="https://opus.nlpl.eu/" rel="nofollow">Opus dataset</a>, which actually contains the KDE4 dataset. But even if the pretrained model we use has seen that data during its pretraining, we will see that we can get a better version of it after fine-tuning.',L,R,re="Once we’re finished, we will have a model able to make predictions like this one:",ee,W,te,T,x,fe='<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."/>',ce,le,ke='As in the previous sections, you can find the actual model that we’ll train and upload to the Hub using the code below and double-check its predictions <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">here</a>.',Ue,F,Ye,he,pe='To fine-tune or train a translation model from scratch, we will need a dataset suitable for the task. As mentioned previously, we’ll use the <a href="https://huggingface.co/datasets/kde4" rel="nofollow">KDE4 dataset</a> in this section, but you can adapt the code to use your own data quite easily, as long as you have pairs of sentences in the two languages you want to translate from and into. Refer back to <a href="/course/chapter5">Chapter 5</a> if you need a reminder of how to load your custom data in a <code>Dataset</code>.',je,S,xe,se,Ze="As usual, we download our dataset using the <code>load_dataset()</code> function:",ge,q,He,de,oe='If you want to work with a different pair of languages, you can specify them by their codes. A total of 92 languages are available for this dataset; you can see them all by expanding the language tags on its <a href="https://huggingface.co/datasets/kde4" rel="nofollow">dataset card</a>.',Ce,Y,qe,$e,D,Fe="Let’s have a look at the dataset:",ue,Me,Ge,ae,Je,me,o='We have 210,173 pairs of sentences, but in one single split, so we will need to create our own validation set. As we saw in <a href="/course/chapter5">Chapter 5</a>, a <code>Dataset</code> has a <code>train_test_split()</code> method that can help us. We’ll provide a seed for reproducibility:',$,Te,tt,Be,r,C,Xa="We can rename the <code>&quot;test&quot;</code> key to <code>&quot;validation&quot;</code> like this:",Sl,lt,ql,st,Na="Now let’s take a look at one element of the dataset:",Dl,at,Ll,nt,Pl,it,Va="We get a dictionary with two sentences in the pair of languages we requested. One particularity of this dataset full of technical computer science terms is that they are all fully translated in French. However, French engineers leave most computer science-specific words in English when they talk. Here, for instance, the word “threads” might well appear in a French sentence, especially in a technical conversation; but in this dataset it has been translated into the more correct “fils de discussion.” The pretrained model we use, which has been pretrained on a larger corpus of French and English sentences, takes the easier option of leaving the word as is:",Kl,rt,Ol,pt,es,ot,Aa=`Another example of this behavior can be seen with the word “plugin,” which isn’t officially a French word but which most native speakers will understand and not bother to translate.
In the KDE4 dataset this word has been translated in French into the more official “module d’extension”:`,ts,Mt,ls,ct,ss,ht,Qa="Our pretrained model, however, sticks with the compact and familiar English word:",as,dt,ns,ut,is,mt,Ea="It will be interesting to see if our fine-tuned model picks up on those particularities of the dataset (spoiler alert: it will).",rs,yt,ps,De,os,wt,Ms,ft,cs,Jt,za='You should know the drill by now: the texts all need to be converted into sets of token IDs so the model can make sense of them. For this task, we’ll need to tokenize both the inputs and the targets. Our first task is to create our <code>tokenizer</code> object. As noted earlier, we’ll be using a Marian English to French pretrained model. If you are trying this code with another pair of languages, make sure to adapt the model checkpoint. The <a href="https://huggingface.co/Helsinki-NLP" rel="nofollow">Helsinki-NLP</a> organization provides more than a thousand models in multiple languages.',hs,Tt,ds,bt,Ya='You can also replace the <code>model_checkpoint</code> with any other model you prefer from the <a href="https://huggingface.co/models" rel="nofollow">Hub</a>, or a local folder where you’ve saved a pretrained model and a tokenizer.',us,Le,ms,Ut,Ha="The preparation of our data is pretty straightforward. There’s just one thing to remember; you need to ensure that the tokenizer processes the targets in the output language (here, French). You can do this by passing the targets to the <code>text_targets</code> argument of the tokenizer’s <code>__call__</code> method.",ys,jt,Fa="To see how this works, let’s process one sample of each language in the training set:",ws,gt,fs,Ct,Js,$t,Sa="As we can see, the output contains the input IDs associated with the English sentence, while the IDs associated with the French one are stored in the <code>labels</code> field. If you forget to indicate that you are tokenizing labels, they will be tokenized by the input tokenizer, which in the case of a Marian model is not going to go well at all:",Ts,It,bs,kt,Us,Zt,qa="As we can see, using the English tokenizer to preprocess a French sentence results in a lot more tokens, since the tokenizer doesn’t know any French words (except those that also appear in the English language, like “discussion”).",js,_t,Da="Since <code>inputs</code> is a dictionary with our usual keys (input IDs, attention mask, etc.), the last step is to define the preprocessing function we will apply on the datasets:",gs,xt,Cs,Gt,La="Note that we set the same maximum length for our inputs and outputs. Since the texts we’re dealing with seem pretty short, we use 128.",$s,Pe,Is,Ke,ks,Bt,Pa="We can now apply that preprocessing in one go on all the splits of our dataset:",Zs,vt,_s,Wt,Ka="Now that the data has been preprocessed, we are ready to fine-tune our pretrained model!",xs,ve,We,Vl,Rt,Oa="Note that this time we are using a model that was trained on a translation task and can actually be used already, so there is no warning about missing weights or newly initialized ones.",Gs,Xt,Bs,Nt,en='We’ll need a data collator to deal with the padding for dynamic batching. We can’t just use a <code>DataCollatorWithPadding</code> like in <a href="/course/chapter3">Chapter 3</a> in this case, because that only pads the inputs (input IDs, attention mask, and token type IDs). Our labels should also be padded to the maximum length encountered in the labels. And, as mentioned previously, the padding value used to pad the labels should be <code>-100</code> and not the padding token of the tokenizer, to make sure those padded values are ignored in the loss computation.',vs,Vt,tn='This is all done by a <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorforseq2seq" rel="nofollow"><code>DataCollatorForSeq2Seq</code></a>. Like the <code>DataCollatorWithPadding</code>, it takes the <code>tokenizer</code> used to preprocess the inputs, but it also takes the <code>model</code>. This is because this data collator will also be responsible for preparing the decoder input IDs, which are shifted versions of the labels with a special token at the beginning. Since this shift is done slightly differently for different architectures, the <code>DataCollatorForSeq2Seq</code> needs to know the <code>model</code> object:',Ws,Re,Xe,Al,At,ln="To test this on a few samples, we just call it on a list of examples from our tokenized training set:",Rs,Qt,Xs,Et,Ns,zt,sn="We can check our labels have been padded to the maximum length of the batch, using <code>-100</code>:",Vs,Yt,As,Ht,Qs,Ft,an="And we can also have a look at the decoder input IDs, to see that they are shifted versions of the labels:",Es,St,zs,qt,Ys,Dt,nn="Here are the labels for the first and second elements in our dataset:",Hs,Lt,Fs,Pt,Ss,Ne,Ve,Ql,Kt,qs,Ot,Ds,El,el,rn='The traditional metric used for translation is the <a href="https://en.wikipedia.org/wiki/BLEU" rel="nofollow">BLEU score</a>, introduced in <a href="https://aclanthology.org/P02-1040.pdf" rel="nofollow">a 2002 article</a> by Kishore Papineni et al. The BLEU score evaluates how close the translations are to their labels. It does not measure the intelligibility or grammatical correctness of the model’s generated outputs, but uses statistical rules to ensure that all the words in the generated outputs also appear in the targets. In addition, there are rules that penalize repetitions of the same words if they are not also repeated in the targets (to avoid the model outputting sentences like <code>&quot;the the the the the&quot;</code>) and output sentences that are shorter than those in the targets (to avoid the model outputting sentences like <code>&quot;the&quot;</code>).',Ls,tl,pn='One weakness with BLEU is that it expects the text to already be tokenized, which makes it difficult to compare scores between models that use different tokenizers. So instead, the most commonly used metric for benchmarking translation models today is <a href="https://github.com/mjpost/sacrebleu" rel="nofollow">SacreBLEU</a>, which addresses this weakness (and others) by standardizing the tokenization step. To use this metric, we first need to install the SacreBLEU library:',Ps,ll,Ks,sl,on='We can then load it via <code>evaluate.load()</code> like we did in <a href="/course/chapter3">Chapter 3</a>:',Os,al,ea,nl,Mn="This metric will take texts as inputs and targets. It is designed to accept several acceptable targets, as there are often multiple acceptable translations of the same sentence — the dataset we’re using only provides one, but it’s not uncommon in NLP to find datasets that give several sentences as labels. So, the predictions should be a list of sentences, but the references should be a list of lists of sentences.",ta,il,cn="Let’s try an example:",la,rl,sa,pl,aa,ol,hn='This gets a BLEU score of 46.75, which is rather good — for reference, the original Transformer model in the <a href="https://arxiv.org/pdf/1706.03762.pdf" rel="nofollow">“Attention Is All You Need” paper</a> achieved a BLEU score of 41.8 on a similar translation task between English and French! (For more information about the individual metrics, like <code>counts</code> and <code>bp</code>, see the <a href="https://github.com/mjpost/sacrebleu/blob/078c440168c6adc89ba75fe6d63f0d922d42bcfe/sacrebleu/metrics/bleu.py#L74" rel="nofollow">SacreBLEU repository</a>.) On the other hand, if we try with the two bad types of predictions (lots of repetitions or too short) that often come out of translation models, we will get rather bad BLEU scores:',na,Ml,ia,cl,ra,hl,pa,dl,oa,ul,dn="The score can go from 0 to 100, and higher is better.",Ma,Ae,Qe,zl,ml,un="Now that this is done, we are ready to fine-tune our model!",ca,yl,ha,wl,mn="The first step is to log in to Hugging Face, so you’re able to upload your results to the Model Hub. There’s a convenience function to help you with this in a notebook:",da,fl,ua,Jl,yn="This will display a widget where you can enter your Hugging Face login credentials.",ma,Tl,wn="If you aren’t working in a notebook, just type the following line in your terminal:",ya,bl,wa,Ee,ze,Yl,Hl,Ul,fa,jl,fn="We’ve already shown you how you can use the model we fine-tuned on the Model Hub with the inference widget. To use it locally in a <code>pipeline</code>, we just have to specify the proper model identifier:",Ja,gl,Ta,Cl,ba,$l,Jn="As expected, our pretrained model adapted its knowledge to the corpus we fine-tuned it on, and instead of leaving the English word “threads” alone, it now translates it to the French official version. It’s the same for “plugin”:",Ua,Il,ja,kl,ga,Zl,Tn="Another great example of domain adaptation!",Ca,Oe,$a,_l,Ia,Fl,ka;I=new Pn({props:{fw:Z[0]}}),_=new Dn({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),v=new _e({props:{title:"Translation",local:"translation",headingTag:"h1"}});const bn=[On,Kn],xl=[];function Un(e,s){return e[0]==="pt"?0:1}g=Un(Z),B=xl[g]=bn[g](Z),A=new Za({props:{id:"1JvfrvZgi6c"}}),F=new _e({props:{title:"Preparing the data",local:"preparing-the-data",headingTag:"h2"}}),S=new _e({props:{title:"The KDE4 dataset",local:"the-kde4-dataset",headingTag:"h3"}}),q=new j({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBcmF3X2RhdGFzZXRzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmtkZTQlMjIlMkMlMjBsYW5nMSUzRCUyMmVuJTIyJTJDJTIwbGFuZzIlM0QlMjJmciUyMik=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

raw_datasets = load_dataset(<span class="hljs-string">&quot;kde4&quot;</span>, lang1=<span class="hljs-string">&quot;en&quot;</span>, lang2=<span class="hljs-string">&quot;fr&quot;</span>)`,wrap:!1}}),Me=new j({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),ae=new j({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}}),Te=new j({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}}),Be=new j({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}}),lt=new j({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}}),at=new j({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}}),nt=new j({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}}),rt=new j({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}}),pt=new j({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}}),Mt=new j({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}}),ct=new j({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}}),dt=new j({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}}),ut=new j({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}}),yt=new Za({props:{id:"0Oxphw4Q9fo"}}),De=new et({props:{$$slots:{default:[ei]},$$scope:{ctx:Z}}}),wt=new _e({props:{title:"Processing the data",local:"processing-the-data",headingTag:"h3"}}),ft=new Za({props:{id:"XAR8jnZZuUs"}}),Tt=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIySGVsc2lua2ktTkxQJTJGb3B1cy1tdC1lbi1mciUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

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

inputs = tokenizer(en_sentence, text_target=fr_sentence)
inputs`,wrap:!1}}),Ct=new j({props:{code:"JTdCJ2lucHV0X2lkcyclM0ElMjAlNUI0NzU5MSUyQyUyMDEyJTJDJTIwOTg0MiUyQyUyMDE5NjM0JTJDJTIwOSUyQyUyMDAlNUQlMkMlMjAnYXR0ZW50aW9uX21hc2snJTNBJTIwJTVCMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTVEJTJDJTIwJ2xhYmVscyclM0ElMjAlNUI1NzclMkMlMjA1ODkxJTJDJTIwMiUyQyUyMDMxODQlMkMlMjAxNiUyQyUyMDI1NDIlMkMlMjA1JTJDJTIwMTcxMCUyQyUyMDAlNUQlN0Q=",highlighted:'{<span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">47591</span>, <span class="hljs-number">12</span>, <span class="hljs-number">9842</span>, <span class="hljs-number">19634</span>, <span class="hljs-number">9</span>, <span class="hljs-number">0</span>], <span class="hljs-string">&#x27;attention_mask&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>], <span class="hljs-string">&#x27;labels&#x27;</span>: [<span class="hljs-number">577</span>, <span class="hljs-number">5891</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3184</span>, <span class="hljs-number">16</span>, <span class="hljs-number">2542</span>, <span class="hljs-number">5</span>, <span class="hljs-number">1710</span>, <span class="hljs-number">0</span>]}',wrap:!1}}),It=new j({props:{code:"d3JvbmdfdGFyZ2V0cyUyMCUzRCUyMHRva2VuaXplcihmcl9zZW50ZW5jZSklMEFwcmludCh0b2tlbml6ZXIuY29udmVydF9pZHNfdG9fdG9rZW5zKHdyb25nX3RhcmdldHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKSUwQXByaW50KHRva2VuaXplci5jb252ZXJ0X2lkc190b190b2tlbnMoaW5wdXRzJTVCJTIybGFiZWxzJTIyJTVEKSk=",highlighted:`wrong_targets = tokenizer(fr_sentence)
<span class="hljs-built_in">print</span>(tokenizer.convert_ids_to_tokens(wrong_targets[<span class="hljs-string">&quot;input_ids&quot;</span>]))
<span class="hljs-built_in">print</span>(tokenizer.convert_ids_to_tokens(inputs[<span class="hljs-string">&quot;labels&quot;</span>]))`,wrap:!1}}),kt=new j({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}}),xt=new j({props:{code:"bWF4X2xlbmd0aCUyMCUzRCUyMDEyOCUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfZnVuY3Rpb24oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwJTVCZXglNUIlMjJlbiUyMiU1RCUyMGZvciUyMGV4JTIwaW4lMjBleGFtcGxlcyU1QiUyMnRyYW5zbGF0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwdGFyZ2V0cyUyMCUzRCUyMCU1QmV4JTVCJTIyZnIlMjIlNUQlMjBmb3IlMjBleCUyMGluJTIwZXhhbXBsZXMlNUIlMjJ0cmFuc2xhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbnB1dHMlMkMlMjB0ZXh0X3RhcmdldCUzRHRhcmdldHMlMkMlMjBtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX2lucHV0cw==",highlighted:`max_length = <span class="hljs-number">128</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
    inputs = [ex[<span class="hljs-string">&quot;en&quot;</span>] <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
    targets = [ex[<span class="hljs-string">&quot;fr&quot;</span>] <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
    model_inputs = tokenizer(
        inputs, text_target=targets, max_length=max_length, truncation=<span class="hljs-literal">True</span>
    )
    <span class="hljs-keyword">return</span> model_inputs`,wrap:!1}}),Pe=new et({props:{$$slots:{default:[li]},$$scope:{ctx:Z}}}),Ke=new et({props:{warning:!0,$$slots:{default:[si]},$$scope:{ctx:Z}}}),vt=new j({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 jn=[ni,ai],Gl=[];function gn(e,s){return e[0]==="pt"?0:1}ve=gn(Z),We=Gl[ve]=jn[ve](Z),Xt=new _e({props:{title:"Data collation",local:"data-collation",headingTag:"h3"}});const Cn=[pi,ri],Bl=[];function $n(e,s){return e[0]==="pt"?0:1}Re=$n(Z),Xe=Bl[Re]=Cn[Re](Z),Qt=new j({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}}),Et=new j({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}}),Yt=new j({props:{code:"YmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQ=",highlighted:'batch[<span class="hljs-string">&quot;labels&quot;</span>]',wrap:!1}}),Ht=new j({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}}),St=new j({props:{code:"YmF0Y2glNUIlMjJkZWNvZGVyX2lucHV0X2lkcyUyMiU1RA==",highlighted:'batch[<span class="hljs-string">&quot;decoder_input_ids&quot;</span>]',wrap:!1}}),qt=new j({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}}),Lt=new j({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}}),Pt=new j({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 In=[Mi,oi],vl=[];function kn(e,s){return e[0]==="pt"?0:1}Ne=kn(Z),Ve=vl[Ne]=In[Ne](Z),Kt=new _e({props:{title:"Metrics",local:"metrics",headingTag:"h3"}}),Ot=new Za({props:{id:"M05L1DhFqcw"}});let be=Z[0]==="pt"&&An();ll=new j({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzYWNyZWJsZXU=",highlighted:"!pip install sacrebleu",wrap:!1}}),al=new j({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNhY3JlYmxldSUyMik=",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;sacrebleu&quot;</span>)`,wrap:!1}}),rl=new j({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}}),pl=new j({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}}),Ml=new j({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}}),cl=new j({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}}),hl=new j({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}}),dl=new j({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 Zn=[hi,ci],Wl=[];function _n(e,s){return e[0]==="tf"?0:1}Ae=_n(Z),Qe=Wl[Ae]=Zn[Ae](Z),yl=new _e({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),fl=new j({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),bl=new j({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}});const xn=[ui,di],Rl=[];function Gn(e,s){return e[0]==="tf"?0:1}Ee=Gn(Z),ze=Rl[Ee]=xn[Ee](Z);let ne=Z[0]==="pt"&&Qn();return Ul=new _e({props:{title:"Using the fine-tuned model",local:"using-the-fine-tuned-model",headingTag:"h2"}}),gl=new j({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}}),Cl=new j({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}}),Il=new j({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}}),kl=new j({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}}),Oe=new et({props:{$$slots:{default:[wi]},$$scope:{ctx:Z}}}),_l=new Ln({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter7/4.mdx"}}),{c(){i=y("meta"),U=a(),p=y("p"),b=a(),h(I.$$.fragment),J=a(),h(_.$$.fragment),G=a(),h(v.$$.fragment),k=a(),B.c(),X=a(),ie=y("p"),ie.innerHTML=O,N=a(),V=y("ul"),V.innerHTML=P,ye=a(),h(A.$$.fragment),Q=a(),E=y("p"),E.innerHTML=K,we=a(),z=y("p"),z.innerHTML=H,L=a(),R=y("p"),R.textContent=re,ee=a(),W=y("iframe"),T=a(),x=y("a"),x.innerHTML=fe,ce=a(),le=y("p"),le.innerHTML=ke,Ue=a(),h(F.$$.fragment),Ye=a(),he=y("p"),he.innerHTML=pe,je=a(),h(S.$$.fragment),xe=a(),se=y("p"),se.innerHTML=Ze,ge=a(),h(q.$$.fragment),He=a(),de=y("p"),de.innerHTML=oe,Ce=a(),Y=y("img"),$e=a(),D=y("p"),D.textContent=Fe,ue=a(),h(Me.$$.fragment),Ge=a(),h(ae.$$.fragment),Je=a(),me=y("p"),me.innerHTML=o,$=a(),h(Te.$$.fragment),tt=a(),h(Be.$$.fragment),r=a(),C=y("p"),C.innerHTML=Xa,Sl=a(),h(lt.$$.fragment),ql=a(),st=y("p"),st.textContent=Na,Dl=a(),h(at.$$.fragment),Ll=a(),h(nt.$$.fragment),Pl=a(),it=y("p"),it.textContent=Va,Kl=a(),h(rt.$$.fragment),Ol=a(),h(pt.$$.fragment),es=a(),ot=y("p"),ot.textContent=Aa,ts=a(),h(Mt.$$.fragment),ls=a(),h(ct.$$.fragment),ss=a(),ht=y("p"),ht.textContent=Qa,as=a(),h(dt.$$.fragment),ns=a(),h(ut.$$.fragment),is=a(),mt=y("p"),mt.textContent=Ea,rs=a(),h(yt.$$.fragment),ps=a(),h(De.$$.fragment),os=a(),h(wt.$$.fragment),Ms=a(),h(ft.$$.fragment),cs=a(),Jt=y("p"),Jt.innerHTML=za,hs=a(),h(Tt.$$.fragment),ds=a(),bt=y("p"),bt.innerHTML=Ya,us=a(),h(Le.$$.fragment),ms=a(),Ut=y("p"),Ut.innerHTML=Ha,ys=a(),jt=y("p"),jt.textContent=Fa,ws=a(),h(gt.$$.fragment),fs=a(),h(Ct.$$.fragment),Js=a(),$t=y("p"),$t.innerHTML=Sa,Ts=a(),h(It.$$.fragment),bs=a(),h(kt.$$.fragment),Us=a(),Zt=y("p"),Zt.textContent=qa,js=a(),_t=y("p"),_t.innerHTML=Da,gs=a(),h(xt.$$.fragment),Cs=a(),Gt=y("p"),Gt.textContent=La,$s=a(),h(Pe.$$.fragment),Is=a(),h(Ke.$$.fragment),ks=a(),Bt=y("p"),Bt.textContent=Pa,Zs=a(),h(vt.$$.fragment),_s=a(),Wt=y("p"),Wt.textContent=Ka,xs=a(),We.c(),Vl=a(),Rt=y("p"),Rt.textContent=Oa,Gs=a(),h(Xt.$$.fragment),Bs=a(),Nt=y("p"),Nt.innerHTML=en,vs=a(),Vt=y("p"),Vt.innerHTML=tn,Ws=a(),Xe.c(),Al=a(),At=y("p"),At.textContent=ln,Rs=a(),h(Qt.$$.fragment),Xs=a(),h(Et.$$.fragment),Ns=a(),zt=y("p"),zt.innerHTML=sn,Vs=a(),h(Yt.$$.fragment),As=a(),h(Ht.$$.fragment),Qs=a(),Ft=y("p"),Ft.textContent=an,Es=a(),h(St.$$.fragment),zs=a(),h(qt.$$.fragment),Ys=a(),Dt=y("p"),Dt.textContent=nn,Hs=a(),h(Lt.$$.fragment),Fs=a(),h(Pt.$$.fragment),Ss=a(),Ve.c(),Ql=a(),h(Kt.$$.fragment),qs=a(),h(Ot.$$.fragment),Ds=a(),be&&be.c(),El=a(),el=y("p"),el.innerHTML=rn,Ls=a(),tl=y("p"),tl.innerHTML=pn,Ps=a(),h(ll.$$.fragment),Ks=a(),sl=y("p"),sl.innerHTML=on,Os=a(),h(al.$$.fragment),ea=a(),nl=y("p"),nl.textContent=Mn,ta=a(),il=y("p"),il.textContent=cn,la=a(),h(rl.$$.fragment),sa=a(),h(pl.$$.fragment),aa=a(),ol=y("p"),ol.innerHTML=hn,na=a(),h(Ml.$$.fragment),ia=a(),h(cl.$$.fragment),ra=a(),h(hl.$$.fragment),pa=a(),h(dl.$$.fragment),oa=a(),ul=y("p"),ul.textContent=dn,Ma=a(),Qe.c(),zl=a(),ml=y("p"),ml.textContent=un,ca=a(),h(yl.$$.fragment),ha=a(),wl=y("p"),wl.textContent=mn,da=a(),h(fl.$$.fragment),ua=a(),Jl=y("p"),Jl.textContent=yn,ma=a(),Tl=y("p"),Tl.textContent=wn,ya=a(),h(bl.$$.fragment),wa=a(),ze.c(),Yl=a(),ne&&ne.c(),Hl=a(),h(Ul.$$.fragment),fa=a(),jl=y("p"),jl.innerHTML=fn,Ja=a(),h(gl.$$.fragment),Ta=a(),h(Cl.$$.fragment),ba=a(),$l=y("p"),$l.textContent=Jn,Ua=a(),h(Il.$$.fragment),ja=a(),h(kl.$$.fragment),ga=a(),Zl=y("p"),Zl.textContent=Tn,Ca=a(),h(Oe.$$.fragment),$a=a(),h(_l.$$.fragment),Ia=a(),Fl=y("p"),this.h()},l(e){const s=Sn("svelte-u9bgzb",document.head);i=w(s,"META",{name:!0,content:!0}),s.forEach(t),U=n(e),p=w(e,"P",{}),Ra(p).forEach(t),b=n(e),d(I.$$.fragment,e),J=n(e),d(_.$$.fragment,e),G=n(e),d(v.$$.fragment,e),k=n(e),B.l(e),X=n(e),ie=w(e,"P",{"data-svelte-h":!0}),f(ie)!=="svelte-eyotq9"&&(ie.innerHTML=O),N=n(e),V=w(e,"UL",{"data-svelte-h":!0}),f(V)!=="svelte-mdl7i"&&(V.innerHTML=P),ye=n(e),d(A.$$.fragment,e),Q=n(e),E=w(e,"P",{"data-svelte-h":!0}),f(E)!=="svelte-qi4xhg"&&(E.innerHTML=K),we=n(e),z=w(e,"P",{"data-svelte-h":!0}),f(z)!=="svelte-19rlunj"&&(z.innerHTML=H),L=n(e),R=w(e,"P",{"data-svelte-h":!0}),f(R)!=="svelte-104mbqb"&&(R.textContent=re),ee=n(e),W=w(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Ra(W).forEach(t),T=n(e),x=w(e,"A",{class:!0,href:!0,"data-svelte-h":!0}),f(x)!=="svelte-1ifl6xg"&&(x.innerHTML=fe),ce=n(e),le=w(e,"P",{"data-svelte-h":!0}),f(le)!=="svelte-8feqj6"&&(le.innerHTML=ke),Ue=n(e),d(F.$$.fragment,e),Ye=n(e),he=w(e,"P",{"data-svelte-h":!0}),f(he)!=="svelte-1w48ec5"&&(he.innerHTML=pe),je=n(e),d(S.$$.fragment,e),xe=n(e),se=w(e,"P",{"data-svelte-h":!0}),f(se)!=="svelte-psemqo"&&(se.innerHTML=Ze),ge=n(e),d(q.$$.fragment,e),He=n(e),de=w(e,"P",{"data-svelte-h":!0}),f(de)!=="svelte-waadns"&&(de.innerHTML=oe),Ce=n(e),Y=w(e,"IMG",{src:!0,alt:!0,width:!0}),$e=n(e),D=w(e,"P",{"data-svelte-h":!0}),f(D)!=="svelte-11kki55"&&(D.textContent=Fe),ue=n(e),d(Me.$$.fragment,e),Ge=n(e),d(ae.$$.fragment,e),Je=n(e),me=w(e,"P",{"data-svelte-h":!0}),f(me)!=="svelte-am89ab"&&(me.innerHTML=o),$=n(e),d(Te.$$.fragment,e),tt=n(e),d(Be.$$.fragment,e),r=n(e),C=w(e,"P",{"data-svelte-h":!0}),f(C)!=="svelte-1b0nmgl"&&(C.innerHTML=Xa),Sl=n(e),d(lt.$$.fragment,e),ql=n(e),st=w(e,"P",{"data-svelte-h":!0}),f(st)!=="svelte-yn8zd9"&&(st.textContent=Na),Dl=n(e),d(at.$$.fragment,e),Ll=n(e),d(nt.$$.fragment,e),Pl=n(e),it=w(e,"P",{"data-svelte-h":!0}),f(it)!=="svelte-1neulry"&&(it.textContent=Va),Kl=n(e),d(rt.$$.fragment,e),Ol=n(e),d(pt.$$.fragment,e),es=n(e),ot=w(e,"P",{"data-svelte-h":!0}),f(ot)!=="svelte-1x2u8k0"&&(ot.textContent=Aa),ts=n(e),d(Mt.$$.fragment,e),ls=n(e),d(ct.$$.fragment,e),ss=n(e),ht=w(e,"P",{"data-svelte-h":!0}),f(ht)!=="svelte-1pzq3b6"&&(ht.textContent=Qa),as=n(e),d(dt.$$.fragment,e),ns=n(e),d(ut.$$.fragment,e),is=n(e),mt=w(e,"P",{"data-svelte-h":!0}),f(mt)!=="svelte-1xxhzkh"&&(mt.textContent=Ea),rs=n(e),d(yt.$$.fragment,e),ps=n(e),d(De.$$.fragment,e),os=n(e),d(wt.$$.fragment,e),Ms=n(e),d(ft.$$.fragment,e),cs=n(e),Jt=w(e,"P",{"data-svelte-h":!0}),f(Jt)!=="svelte-7kxu8d"&&(Jt.innerHTML=za),hs=n(e),d(Tt.$$.fragment,e),ds=n(e),bt=w(e,"P",{"data-svelte-h":!0}),f(bt)!=="svelte-1akd2n2"&&(bt.innerHTML=Ya),us=n(e),d(Le.$$.fragment,e),ms=n(e),Ut=w(e,"P",{"data-svelte-h":!0}),f(Ut)!=="svelte-1pc1kc0"&&(Ut.innerHTML=Ha),ys=n(e),jt=w(e,"P",{"data-svelte-h":!0}),f(jt)!=="svelte-16j9n8c"&&(jt.textContent=Fa),ws=n(e),d(gt.$$.fragment,e),fs=n(e),d(Ct.$$.fragment,e),Js=n(e),$t=w(e,"P",{"data-svelte-h":!0}),f($t)!=="svelte-o6ed2q"&&($t.innerHTML=Sa),Ts=n(e),d(It.$$.fragment,e),bs=n(e),d(kt.$$.fragment,e),Us=n(e),Zt=w(e,"P",{"data-svelte-h":!0}),f(Zt)!=="svelte-10w8fo4"&&(Zt.textContent=qa),js=n(e),_t=w(e,"P",{"data-svelte-h":!0}),f(_t)!=="svelte-q0ybzj"&&(_t.innerHTML=Da),gs=n(e),d(xt.$$.fragment,e),Cs=n(e),Gt=w(e,"P",{"data-svelte-h":!0}),f(Gt)!=="svelte-wqps0w"&&(Gt.textContent=La),$s=n(e),d(Pe.$$.fragment,e),Is=n(e),d(Ke.$$.fragment,e),ks=n(e),Bt=w(e,"P",{"data-svelte-h":!0}),f(Bt)!=="svelte-u9dyhf"&&(Bt.textContent=Pa),Zs=n(e),d(vt.$$.fragment,e),_s=n(e),Wt=w(e,"P",{"data-svelte-h":!0}),f(Wt)!=="svelte-1a79fos"&&(Wt.textContent=Ka),xs=n(e),We.l(e),Vl=n(e),Rt=w(e,"P",{"data-svelte-h":!0}),f(Rt)!=="svelte-1merkap"&&(Rt.textContent=Oa),Gs=n(e),d(Xt.$$.fragment,e),Bs=n(e),Nt=w(e,"P",{"data-svelte-h":!0}),f(Nt)!=="svelte-1uzskyq"&&(Nt.innerHTML=en),vs=n(e),Vt=w(e,"P",{"data-svelte-h":!0}),f(Vt)!=="svelte-18ubg06"&&(Vt.innerHTML=tn),Ws=n(e),Xe.l(e),Al=n(e),At=w(e,"P",{"data-svelte-h":!0}),f(At)!=="svelte-bijhma"&&(At.textContent=ln),Rs=n(e),d(Qt.$$.fragment,e),Xs=n(e),d(Et.$$.fragment,e),Ns=n(e),zt=w(e,"P",{"data-svelte-h":!0}),f(zt)!=="svelte-990iko"&&(zt.innerHTML=sn),Vs=n(e),d(Yt.$$.fragment,e),As=n(e),d(Ht.$$.fragment,e),Qs=n(e),Ft=w(e,"P",{"data-svelte-h":!0}),f(Ft)!=="svelte-1hivgoi"&&(Ft.textContent=an),Es=n(e),d(St.$$.fragment,e),zs=n(e),d(qt.$$.fragment,e),Ys=n(e),Dt=w(e,"P",{"data-svelte-h":!0}),f(Dt)!=="svelte-unhint"&&(Dt.textContent=nn),Hs=n(e),d(Lt.$$.fragment,e),Fs=n(e),d(Pt.$$.fragment,e),Ss=n(e),Ve.l(e),Ql=n(e),d(Kt.$$.fragment,e),qs=n(e),d(Ot.$$.fragment,e),Ds=n(e),be&&be.l(e),El=n(e),el=w(e,"P",{"data-svelte-h":!0}),f(el)!=="svelte-1kiw7od"&&(el.innerHTML=rn),Ls=n(e),tl=w(e,"P",{"data-svelte-h":!0}),f(tl)!=="svelte-1bnfkqb"&&(tl.innerHTML=pn),Ps=n(e),d(ll.$$.fragment,e),Ks=n(e),sl=w(e,"P",{"data-svelte-h":!0}),f(sl)!=="svelte-jh6rtm"&&(sl.innerHTML=on),Os=n(e),d(al.$$.fragment,e),ea=n(e),nl=w(e,"P",{"data-svelte-h":!0}),f(nl)!=="svelte-1oah3bx"&&(nl.textContent=Mn),ta=n(e),il=w(e,"P",{"data-svelte-h":!0}),f(il)!=="svelte-1h2fqkp"&&(il.textContent=cn),la=n(e),d(rl.$$.fragment,e),sa=n(e),d(pl.$$.fragment,e),aa=n(e),ol=w(e,"P",{"data-svelte-h":!0}),f(ol)!=="svelte-1iu1ast"&&(ol.innerHTML=hn),na=n(e),d(Ml.$$.fragment,e),ia=n(e),d(cl.$$.fragment,e),ra=n(e),d(hl.$$.fragment,e),pa=n(e),d(dl.$$.fragment,e),oa=n(e),ul=w(e,"P",{"data-svelte-h":!0}),f(ul)!=="svelte-tsitwn"&&(ul.textContent=dn),Ma=n(e),Qe.l(e),zl=n(e),ml=w(e,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-1gk0eqs"&&(ml.textContent=un),ca=n(e),d(yl.$$.fragment,e),ha=n(e),wl=w(e,"P",{"data-svelte-h":!0}),f(wl)!=="svelte-gd91fw"&&(wl.textContent=mn),da=n(e),d(fl.$$.fragment,e),ua=n(e),Jl=w(e,"P",{"data-svelte-h":!0}),f(Jl)!=="svelte-1ied0vh"&&(Jl.textContent=yn),ma=n(e),Tl=w(e,"P",{"data-svelte-h":!0}),f(Tl)!=="svelte-648vlf"&&(Tl.textContent=wn),ya=n(e),d(bl.$$.fragment,e),wa=n(e),ze.l(e),Yl=n(e),ne&&ne.l(e),Hl=n(e),d(Ul.$$.fragment,e),fa=n(e),jl=w(e,"P",{"data-svelte-h":!0}),f(jl)!=="svelte-d11l7w"&&(jl.innerHTML=fn),Ja=n(e),d(gl.$$.fragment,e),Ta=n(e),d(Cl.$$.fragment,e),ba=n(e),$l=w(e,"P",{"data-svelte-h":!0}),f($l)!=="svelte-1gj0rwy"&&($l.textContent=Jn),Ua=n(e),d(Il.$$.fragment,e),ja=n(e),d(kl.$$.fragment,e),ga=n(e),Zl=w(e,"P",{"data-svelte-h":!0}),f(Zl)!=="svelte-1o5slqz"&&(Zl.textContent=Tn),Ca=n(e),d(Oe.$$.fragment,e),$a=n(e),d(_l.$$.fragment,e),Ia=n(e),Fl=w(e,"P",{}),Ra(Fl).forEach(t),this.h()},h(){Ie(i,"name","hf:doc:metadata"),Ie(i,"content",Ji),Vn(W.src,te="https://course-demos-marian-finetuned-kde4-en-to-fr.hf.space")||Ie(W,"src",te),Ie(W,"frameborder","0"),Ie(W,"height","350"),Ie(W,"title","Gradio app"),Ie(W,"class","block dark:hidden container p-0 flex-grow space-iframe"),Ie(W,"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"),Ie(W,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Ie(x,"class","flex justify-center"),Ie(x,"href","/huggingface-course/marian-finetuned-kde4-en-to-fr"),Vn(Y.src,qe="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/language_tags.png")||Ie(Y,"src",qe),Ie(Y,"alt","Language available for the KDE4 dataset."),Ie(Y,"width","100%")},m(e,s){qn(document.head,i),l(e,U,s),l(e,p,s),l(e,b,s),u(I,e,s),l(e,J,s),u(_,e,s),l(e,G,s),u(v,e,s),l(e,k,s),xl[g].m(e,s),l(e,X,s),l(e,ie,s),l(e,N,s),l(e,V,s),l(e,ye,s),u(A,e,s),l(e,Q,s),l(e,E,s),l(e,we,s),l(e,z,s),l(e,L,s),l(e,R,s),l(e,ee,s),l(e,W,s),l(e,T,s),l(e,x,s),l(e,ce,s),l(e,le,s),l(e,Ue,s),u(F,e,s),l(e,Ye,s),l(e,he,s),l(e,je,s),u(S,e,s),l(e,xe,s),l(e,se,s),l(e,ge,s),u(q,e,s),l(e,He,s),l(e,de,s),l(e,Ce,s),l(e,Y,s),l(e,$e,s),l(e,D,s),l(e,ue,s),u(Me,e,s),l(e,Ge,s),u(ae,e,s),l(e,Je,s),l(e,me,s),l(e,$,s),u(Te,e,s),l(e,tt,s),u(Be,e,s),l(e,r,s),l(e,C,s),l(e,Sl,s),u(lt,e,s),l(e,ql,s),l(e,st,s),l(e,Dl,s),u(at,e,s),l(e,Ll,s),u(nt,e,s),l(e,Pl,s),l(e,it,s),l(e,Kl,s),u(rt,e,s),l(e,Ol,s),u(pt,e,s),l(e,es,s),l(e,ot,s),l(e,ts,s),u(Mt,e,s),l(e,ls,s),u(ct,e,s),l(e,ss,s),l(e,ht,s),l(e,as,s),u(dt,e,s),l(e,ns,s),u(ut,e,s),l(e,is,s),l(e,mt,s),l(e,rs,s),u(yt,e,s),l(e,ps,s),u(De,e,s),l(e,os,s),u(wt,e,s),l(e,Ms,s),u(ft,e,s),l(e,cs,s),l(e,Jt,s),l(e,hs,s),u(Tt,e,s),l(e,ds,s),l(e,bt,s),l(e,us,s),u(Le,e,s),l(e,ms,s),l(e,Ut,s),l(e,ys,s),l(e,jt,s),l(e,ws,s),u(gt,e,s),l(e,fs,s),u(Ct,e,s),l(e,Js,s),l(e,$t,s),l(e,Ts,s),u(It,e,s),l(e,bs,s),u(kt,e,s),l(e,Us,s),l(e,Zt,s),l(e,js,s),l(e,_t,s),l(e,gs,s),u(xt,e,s),l(e,Cs,s),l(e,Gt,s),l(e,$s,s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),l(e,Ja,s),u(gl,e,s),l(e,Ta,s),u(Cl,e,s),l(e,ba,s),l(e,$l,s),l(e,Ua,s),u(Il,e,s),l(e,ja,s),u(kl,e,s),l(e,ga,s),l(e,Zl,s),l(e,Ca,s),u(Oe,e,s),l(e,$a,s),u(_l,e,s),l(e,Ia,s),l(e,Fl,s),ka=!0},p(e,[s]){const Bn={};s&1&&(Bn.fw=e[0]),I.$set(Bn);let _a=g;g=Un(e),g!==_a&&(Nl(),c(xl[_a],1,1,()=>{xl[_a]=null}),Xl(),B=xl[g],B||(B=xl[g]=bn[g](e),B.c()),M(B,1),B.m(X.parentNode,X));const vn={};s&2&&(vn.$$scope={dirty:s,ctx:e}),De.$set(vn);const Wn={};s&2&&(Wn.$$scope={dirty:s,ctx:e}),Le.$set(Wn);const Rn={};s&2&&(Rn.$$scope={dirty:s,ctx:e}),Pe.$set(Rn);const Xn={};s&2&&(Xn.$$scope={dirty:s,ctx:e}),Ke.$set(Xn);let xa=ve;ve=gn(e),ve!==xa&&(Nl(),c(Gl[xa],1,1,()=>{Gl[xa]=null}),Xl(),We=Gl[ve],We||(We=Gl[ve]=jn[ve](e),We.c()),M(We,1),We.m(Vl.parentNode,Vl));let Ga=Re;Re=$n(e),Re!==Ga&&(Nl(),c(Bl[Ga],1,1,()=>{Bl[Ga]=null}),Xl(),Xe=Bl[Re],Xe||(Xe=Bl[Re]=Cn[Re](e),Xe.c()),M(Xe,1),Xe.m(Al.parentNode,Al));let Ba=Ne;Ne=kn(e),Ne!==Ba&&(Nl(),c(vl[Ba],1,1,()=>{vl[Ba]=null}),Xl(),Ve=vl[Ne],Ve||(Ve=vl[Ne]=In[Ne](e),Ve.c()),M(Ve,1),Ve.m(Ql.parentNode,Ql)),e[0]==="pt"?be||(be=An(),be.c(),be.m(El.parentNode,El)):be&&(be.d(1),be=null);let va=Ae;Ae=_n(e),Ae!==va&&(Nl(),c(Wl[va],1,1,()=>{Wl[va]=null}),Xl(),Qe=Wl[Ae],Qe||(Qe=Wl[Ae]=Zn[Ae](e),Qe.c()),M(Qe,1),Qe.m(zl.parentNode,zl));let Wa=Ee;Ee=Gn(e),Ee!==Wa&&(Nl(),c(Rl[Wa],1,1,()=>{Rl[Wa]=null}),Xl(),ze=Rl[Ee],ze||(ze=Rl[Ee]=xn[Ee](e),ze.c()),M(ze,1),ze.m(Yl.parentNode,Yl)),e[0]==="pt"?ne?s&1&&M(ne,1):(ne=Qn(),ne.c(),M(ne,1),ne.m(Hl.parentNode,Hl)):ne&&(Nl(),c(ne,1,1,()=>{ne=null}),Xl());const Nn={};s&2&&(Nn.$$scope={dirty:s,ctx:e}),Oe.$set(Nn)},i(e){ka||(M(I.$$.fragment,e),M(_.$$.fragment,e),M(v.$$.fragment,e),M(B),M(A.$$.fragment,e),M(F.$$.fragment,e),M(S.$$.fragment,e),M(q.$$.fragment,e),M(Me.$$.fragment,e),M(ae.$$.fragment,e),M(Te.$$.fragment,e),M(Be.$$.fragment,e),M(lt.$$.fragment,e),M(at.$$.fragment,e),M(nt.$$.fragment,e),M(rt.$$.fragment,e),M(pt.$$.fragment,e),M(Mt.$$.fragment,e),M(ct.$$.fragment,e),M(dt.$$.fragment,e),M(ut.$$.fragment,e),M(yt.$$.fragment,e),M(De.$$.fragment,e),M(wt.$$.fragment,e),M(ft.$$.fragment,e),M(Tt.$$.fragment,e),M(Le.$$.fragment,e),M(gt.$$.fragment,e),M(Ct.$$.fragment,e),M(It.$$.fragment,e),M(kt.$$.fragment,e),M(xt.$$.fragment,e),M(Pe.$$.fragment,e),M(Ke.$$.fragment,e),M(vt.$$.fragment,e),M(We),M(Xt.$$.fragment,e),M(Xe),M(Qt.$$.fragment,e),M(Et.$$.fragment,e),M(Yt.$$.fragment,e),M(Ht.$$.fragment,e),M(St.$$.fragment,e),M(qt.$$.fragment,e),M(Lt.$$.fragment,e),M(Pt.$$.fragment,e),M(Ve),M(Kt.$$.fragment,e),M(Ot.$$.fragment,e),M(ll.$$.fragment,e),M(al.$$.fragment,e),M(rl.$$.fragment,e),M(pl.$$.fragment,e),M(Ml.$$.fragment,e),M(cl.$$.fragment,e),M(hl.$$.fragment,e),M(dl.$$.fragment,e),M(Qe),M(yl.$$.fragment,e),M(fl.$$.fragment,e),M(bl.$$.fragment,e),M(ze),M(ne),M(Ul.$$.fragment,e),M(gl.$$.fragment,e),M(Cl.$$.fragment,e),M(Il.$$.fragment,e),M(kl.$$.fragment,e),M(Oe.$$.fragment,e),M(_l.$$.fragment,e),ka=!0)},o(e){c(I.$$.fragment,e),c(_.$$.fragment,e),c(v.$$.fragment,e),c(B),c(A.$$.fragment,e),c(F.$$.fragment,e),c(S.$$.fragment,e),c(q.$$.fragment,e),c(Me.$$.fragment,e),c(ae.$$.fragment,e),c(Te.$$.fragment,e),c(Be.$$.fragment,e),c(lt.$$.fragment,e),c(at.$$.fragment,e),c(nt.$$.fragment,e),c(rt.$$.fragment,e),c(pt.$$.fragment,e),c(Mt.$$.fragment,e),c(ct.$$.fragment,e),c(dt.$$.fragment,e),c(ut.$$.fragment,e),c(yt.$$.fragment,e),c(De.$$.fragment,e),c(wt.$$.fragment,e),c(ft.$$.fragment,e),c(Tt.$$.fragment,e),c(Le.$$.fragment,e),c(gt.$$.fragment,e),c(Ct.$$.fragment,e),c(It.$$.fragment,e),c(kt.$$.fragment,e),c(xt.$$.fragment,e),c(Pe.$$.fragment,e),c(Ke.$$.fragment,e),c(vt.$$.fragment,e),c(We),c(Xt.$$.fragment,e),c(Xe),c(Qt.$$.fragment,e),c(Et.$$.fragment,e),c(Yt.$$.fragment,e),c(Ht.$$.fragment,e),c(St.$$.fragment,e),c(qt.$$.fragment,e),c(Lt.$$.fragment,e),c(Pt.$$.fragment,e),c(Ve),c(Kt.$$.fragment,e),c(Ot.$$.fragment,e),c(ll.$$.fragment,e),c(al.$$.fragment,e),c(rl.$$.fragment,e),c(pl.$$.fragment,e),c(Ml.$$.fragment,e),c(cl.$$.fragment,e),c(hl.$$.fragment,e),c(dl.$$.fragment,e),c(Qe),c(yl.$$.fragment,e),c(fl.$$.fragment,e),c(bl.$$.fragment,e),c(ze),c(ne),c(Ul.$$.fragment,e),c(gl.$$.fragment,e),c(Cl.$$.fragment,e),c(Il.$$.fragment,e),c(kl.$$.fragment,e),c(Oe.$$.fragment,e),c(_l.$$.fragment,e),ka=!1},d(e){e&&(t(U),t(p),t(b),t(J),t(G),t(k),t(X),t(ie),t(N),t(V),t(ye),t(Q),t(E),t(we),t(z),t(L),t(R),t(ee),t(W),t(T),t(x),t(ce),t(le),t(Ue),t(Ye),t(he),t(je),t(xe),t(se),t(ge),t(He),t(de),t(Ce),t(Y),t($e),t(D),t(ue),t(Ge),t(Je),t(me),t($),t(tt),t(r),t(C),t(Sl),t(ql),t(st),t(Dl),t(Ll),t(Pl),t(it),t(Kl),t(Ol),t(es),t(ot),t(ts),t(ls),t(ss),t(ht),t(as),t(ns),t(is),t(mt),t(rs),t(ps),t(os),t(Ms),t(cs),t(Jt),t(hs),t(ds),t(bt),t(us),t(ms),t(Ut),t(ys),t(jt),t(ws),t(fs),t(Js),t($t),t(Ts),t(bs),t(Us),t(Zt),t(js),t(_t),t(gs),t(Cs),t(Gt),t($s),t(Is),t(ks),t(Bt),t(Zs),t(_s),t(Wt),t(xs),t(Vl),t(Rt),t(Gs),t(Bs),t(Nt),t(vs),t(Vt),t(Ws),t(Al),t(At),t(Rs),t(Xs),t(Ns),t(zt),t(Vs),t(As),t(Qs),t(Ft),t(Es),t(zs),t(Ys),t(Dt),t(Hs),t(Fs),t(Ss),t(Ql),t(qs),t(Ds),t(El),t(el),t(Ls),t(tl),t(Ps),t(Ks),t(sl),t(Os),t(ea),t(nl),t(ta),t(il),t(la),t(sa),t(aa),t(ol),t(na),t(ia),t(ra),t(pa),t(oa),t(ul),t(Ma),t(zl),t(ml),t(ca),t(ha),t(wl),t(da),t(ua),t(Jl),t(ma),t(Tl),t(ya),t(wa),t(Yl),t(Hl),t(fa),t(jl),t(Ja),t(Ta),t(ba),t($l),t(Ua),t(ja),t(ga),t(Zl),t(Ca),t($a),t(Ia),t(Fl)),t(i),m(I,e),m(_,e),m(v,e),xl[g].d(e),m(A,e),m(F,e),m(S,e),m(q,e),m(Me,e),m(ae,e),m(Te,e),m(Be,e),m(lt,e),m(at,e),m(nt,e),m(rt,e),m(pt,e),m(Mt,e),m(ct,e),m(dt,e),m(ut,e),m(yt,e),m(De,e),m(wt,e),m(ft,e),m(Tt,e),m(Le,e),m(gt,e),m(Ct,e),m(It,e),m(kt,e),m(xt,e),m(Pe,e),m(Ke,e),m(vt,e),Gl[ve].d(e),m(Xt,e),Bl[Re].d(e),m(Qt,e),m(Et,e),m(Yt,e),m(Ht,e),m(St,e),m(qt,e),m(Lt,e),m(Pt,e),vl[Ne].d(e),m(Kt,e),m(Ot,e),be&&be.d(e),m(ll,e),m(al,e),m(rl,e),m(pl,e),m(Ml,e),m(cl,e),m(hl,e),m(dl,e),Wl[Ae].d(e),m(yl,e),m(fl,e),m(bl,e),Rl[Ee].d(e),ne&&ne.d(e),m(Ul,e),m(gl,e),m(Cl,e),m(Il,e),m(kl,e),m(Oe,e),m(_l,e)}}}const Ji='{"title":"Translation","local":"translation","sections":[{"title":"Preparing the data","local":"preparing-the-data","sections":[{"title":"The KDE4 dataset","local":"the-kde4-dataset","sections":[],"depth":3},{"title":"Processing the data","local":"processing-the-data","sections":[],"depth":3}],"depth":2},{"title":"Fine-tuning the model with the Trainer API","local":"fine-tuning-the-model-with-the-trainer-api","sections":[],"depth":2},{"title":"Fine-tuning the model with Keras","local":"fine-tuning-the-model-with-keras","sections":[{"title":"Data collation","local":"data-collation","sections":[],"depth":3},{"title":"Metrics","local":"metrics","sections":[],"depth":3},{"title":"Fine-tuning the model","local":"fine-tuning-the-model","sections":[],"depth":3}],"depth":2},{"title":"A custom training loop","local":"a-custom-training-loop","sections":[{"title":"Preparing everything for training","local":"preparing-everything-for-training","sections":[],"depth":3},{"title":"Training loop","local":"training-loop","sections":[],"depth":3}],"depth":2},{"title":"Using the fine-tuned model","local":"using-the-fine-tuned-model","sections":[],"depth":2}],"depth":1}';function Ti(Z,i,U){let p="pt";return Yn(()=>{const b=new URLSearchParams(window.location.search);U(0,p=b.get("fw")||"pt")}),[p]}class Zi extends Hn{constructor(i){super(),Fn(this,i,Ti,fi,zn,{})}}export{Zi as component};
