import{s as Qn,f as Xn,o as En,n as Fe}from"../chunks/scheduler.37c15a92.js";import{S as zn,i as Yn,g as h,s as a,r as u,A as Hn,h as d,f as t,c as n,j as Wa,u as y,x as J,k as Ie,y as Fn,a as l,v as m,t as M,b as Xl,d as c,w,p as Nl}from"../chunks/index.2bf4358c.js";import{T as et}from"../chunks/Tip.363c041f.js";import{Y as ka}from"../chunks/Youtube.1e50a667.js";import{C as j}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as An}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Sn}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as _e,E as qn}from"../chunks/EditOnGithub.8916dc7c.js";function Dn(Z){let i,U;return i=new An({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(){u(i.$$.fragment)},l(p){y(i.$$.fragment,p)},m(p,b){m(i,p,b),U=!0},i(p){U||(c(i.$$.fragment,p),U=!0)},o(p){M(i.$$.fragment,p),U=!1},d(p){w(i,p)}}}function Ln(Z){let i,U;return i=new An({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(){u(i.$$.fragment)},l(p){y(i.$$.fragment,p)},m(p,b){m(i,p,b),U=!0},i(p){U||(c(i.$$.fragment,p),U=!0)},o(p){M(i.$$.fragment,p),U=!1},d(p){w(i,p)}}}function Pn(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-uwcde8"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function Kn(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-w81hxj"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function On(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-9rujvy"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function ei(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-1i4t0xl"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function ti(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:",k,f,_,x,G;return i=new _e({props:{title:"Fine-tuning the model with Keras",local:"fine-tuning-the-model-with-keras",headingTag:"h2"}}),f=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}}),x=new et({props:{warning:!1,$$slots:{default:[si]},$$scope:{ctx:Z}}}),{c(){u(i.$$.fragment),U=a(),p=h("p"),p.innerHTML=b,k=a(),u(f.$$.fragment),_=a(),u(x.$$.fragment)},l($){y(i.$$.fragment,$),U=n($),p=d($,"P",{"data-svelte-h":!0}),J(p)!=="svelte-c4jxu5"&&(p.innerHTML=b),k=n($),y(f.$$.fragment,$),_=n($),y(x.$$.fragment,$)},m($,g){m(i,$,g),l($,U,g),l($,p,g),l($,k,g),m(f,$,g),l($,_,g),m(x,$,g),G=!0},i($){G||(c(i.$$.fragment,$),c(f.$$.fragment,$),c(x.$$.fragment,$),G=!0)},o($){M(i.$$.fragment,$),M(f.$$.fragment,$),M(x.$$.fragment,$),G=!1},d($){$&&(t(U),t(p),t(k),t(_)),w(i,$),w(f,$),w(x,$)}}}function li(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.',k,f,_="First things first, we need an actual model to fine-tune. We’ll use the usual <code>AutoModel</code> API:",x,G,$;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"}}),G=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(){u(i.$$.fragment),U=a(),p=h("p"),p.innerHTML=b,k=a(),f=h("p"),f.innerHTML=_,x=a(),u(G.$$.fragment)},l(g){y(i.$$.fragment,g),U=n(g),p=d(g,"P",{"data-svelte-h":!0}),J(p)!=="svelte-1u27cnc"&&(p.innerHTML=b),k=n(g),f=d(g,"P",{"data-svelte-h":!0}),J(f)!=="svelte-c4jxu5"&&(f.innerHTML=_),x=n(g),y(G.$$.fragment,g)},m(g,v){m(i,g,v),l(g,U,v),l(g,p,v),l(g,k,v),l(g,f,v),l(g,x,v),m(G,g,v),$=!0},i(g){$||(c(i.$$.fragment,g),c(G.$$.fragment,g),$=!0)},o(g){M(i.$$.fragment,g),M(G.$$.fragment,g),$=!1},d(g){g&&(t(U),t(p),t(k),t(f),t(x)),w(i,g),w(G,g)}}}function si(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-1swjwma"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function ai(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(){u(i.$$.fragment)},l(p){y(i.$$.fragment,p)},m(p,b){m(i,p,b),U=!0},i(p){U||(c(i.$$.fragment,p),U=!0)},o(p){M(i.$$.fragment,p),U=!1},d(p){w(i,p)}}}function ni(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(){u(i.$$.fragment)},l(p){y(i.$$.fragment,p)},m(p,b){m(i,p,b),U=!0},i(p){U||(c(i.$$.fragment,p),U=!0)},o(p){M(i.$$.fragment,p),U=!1},d(p){w(i,p)}}}function ii(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,k;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=h("p"),i.innerHTML=U,p=a(),u(b.$$.fragment)},l(f){i=d(f,"P",{"data-svelte-h":!0}),J(i)!=="svelte-1hevmzh"&&(i.innerHTML=U),p=n(f),y(b.$$.fragment,f)},m(f,_){l(f,i,_),l(f,p,_),m(b,f,_),k=!0},i(f){k||(c(b.$$.fragment,f),k=!0)},o(f){M(b.$$.fragment,f),k=!1},d(f){f&&(t(i),t(p)),w(b,f)}}}function ri(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-gyo8yo"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},i:Fe,o:Fe,d(p){p&&t(i)}}}function Nn(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,k='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=h("p"),i.innerHTML=U,p=a(),b=h("p"),b.innerHTML=k},l(f){i=d(f,"P",{"data-svelte-h":!0}),J(i)!=="svelte-1dssf7l"&&(i.innerHTML=U),p=n(f),b=d(f,"P",{"data-svelte-h":!0}),J(b)!=="svelte-thx2aq"&&(b.innerHTML=k)},m(f,_){l(f,i,_),l(f,p,_),l(f,b,_)},d(f){f&&(t(i),t(p),t(b))}}}function pi(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,k;return b=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZHMpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWRzJTBBJTIwJTIwJTIwJTIwJTIzJTIwSW4lMjBjYXNlJTIwdGhlJTIwbW9kZWwlMjByZXR1cm5zJTIwbW9yZSUyMHRoYW4lMjB0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IwJTNEJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RkZWNvZGVkX3ByZWRzJTJDJTIwcmVmZXJlbmNlcyUzRGRlY29kZWRfbGFiZWxzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMmJsZXUlMjIlM0ElMjByZXN1bHQlNUIlMjJzY29yZSUyMiU1RCU3RA==",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=h("p"),i.innerHTML=U,p=a(),u(b.$$.fragment)},l(f){i=d(f,"P",{"data-svelte-h":!0}),J(i)!=="svelte-12prd39"&&(i.innerHTML=U),p=n(f),y(b.$$.fragment,f)},m(f,_){l(f,i,_),l(f,p,_),m(b,f,_),k=!0},i(f){k||(c(b.$$.fragment,f),k=!0)},o(f){M(b.$$.fragment,f),k=!1},d(f){f&&(t(i),t(p)),w(b,f)}}}function oi(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,k;return b=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHFkbSUyMGltcG9ydCUyMHRxZG0lMEElMEFnZW5lcmF0aW9uX2RhdGFfY29sbGF0b3IlMjAlM0QlMjBEYXRhQ29sbGF0b3JGb3JTZXEyU2VxKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUyQyUyMG1vZGVsJTNEbW9kZWwlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyJTJDJTIwcGFkX3RvX211bHRpcGxlX29mJTNEMTI4JTBBKSUwQSUwQXRmX2dlbmVyYXRlX2RhdGFzZXQlMjAlM0QlMjBtb2RlbC5wcmVwYXJlX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RnZW5lcmF0aW9uX2RhdGFfY29sbGF0b3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="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=h("p"),i.innerHTML=U,p=a(),u(b.$$.fragment)},l(f){i=d(f,"P",{"data-svelte-h":!0}),J(i)!=="svelte-de3ij7"&&(i.innerHTML=U),p=n(f),y(b.$$.fragment,f)},m(f,_){l(f,i,_),l(f,p,_),m(b,f,_),k=!0},i(f){k||(c(b.$$.fragment,f),k=!0)},o(f){M(b.$$.fragment,f),k=!1},d(f){f&&(t(i),t(p)),w(b,f)}}}function ci(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,k,f,_="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:",x,G,$="<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,v,O='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).',ue,A,Y,L,N="Finally, we just pass everything to the <code>Seq2SeqTrainer</code>:",ye,Q,H,P,V="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:",$e,K,R,ee,E,W,re="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.",te,X,T="Next is the training, which will also take a bit of time:",B,le,me,Me,pe="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.",Te,F,Se="Once training is done, we evaluate our model again — hopefully we will see some amelioration in the BLEU score!",be,S,Ue,q,He,he,oe="That’s a nearly 14-point improvement, which is great.",je,D,qe="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:",ge,z,xe,se,ke="This command returns the URL of the commit it just did, if you want to inspect it:",Ge,ae,we,de,ce="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!",Be,ne,Ze="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.",Ce;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}}),A=new et({props:{$$slots:{default:[hi]},$$scope:{ctx:Z}}}),Q=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}}),K=new j({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),ee=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}}),le=new j({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),S=new j({props:{code:"dHJhaW5lci5ldmFsdWF0ZShtYXhfbGVuZ3RoJTNEbWF4X2xlbmd0aCk=",highlighted:"trainer.evaluate(max_length=max_length)",wrap:!1}}),q=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}}),z=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}}),ae=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=h("p"),i.innerHTML=U,p=a(),u(b.$$.fragment),k=a(),f=h("p"),f.textContent=_,x=a(),G=h("ul"),G.innerHTML=$,g=a(),v=h("p"),v.innerHTML=O,ue=a(),u(A.$$.fragment),Y=a(),L=h("p"),L.innerHTML=N,ye=a(),u(Q.$$.fragment),H=a(),P=h("p"),P.textContent=V,$e=a(),u(K.$$.fragment),R=a(),u(ee.$$.fragment),E=a(),W=h("p"),W.textContent=re,te=a(),X=h("p"),X.textContent=T,B=a(),u(le.$$.fragment),me=a(),Me=h("p"),Me.textContent=pe,Te=a(),F=h("p"),F.textContent=Se,be=a(),u(S.$$.fragment),Ue=a(),u(q.$$.fragment),He=a(),he=h("p"),he.textContent=oe,je=a(),D=h("p"),D.innerHTML=qe,ge=a(),u(z.$$.fragment),xe=a(),se=h("p"),se.textContent=ke,Ge=a(),u(ae.$$.fragment),we=a(),de=h("p"),de.textContent=ce,Be=a(),ne=h("p"),ne.textContent=Ze},l(o){i=d(o,"P",{"data-svelte-h":!0}),J(i)!=="svelte-1hue7r3"&&(i.innerHTML=U),p=n(o),y(b.$$.fragment,o),k=n(o),f=d(o,"P",{"data-svelte-h":!0}),J(f)!=="svelte-vr7kv5"&&(f.textContent=_),x=n(o),G=d(o,"UL",{"data-svelte-h":!0}),J(G)!=="svelte-ckg3z2"&&(G.innerHTML=$),g=n(o),v=d(o,"P",{"data-svelte-h":!0}),J(v)!=="svelte-14ymb4g"&&(v.innerHTML=O),ue=n(o),y(A.$$.fragment,o),Y=n(o),L=d(o,"P",{"data-svelte-h":!0}),J(L)!=="svelte-vnqwl3"&&(L.innerHTML=N),ye=n(o),y(Q.$$.fragment,o),H=n(o),P=d(o,"P",{"data-svelte-h":!0}),J(P)!=="svelte-ixolzg"&&(P.textContent=V),$e=n(o),y(K.$$.fragment,o),R=n(o),y(ee.$$.fragment,o),E=n(o),W=d(o,"P",{"data-svelte-h":!0}),J(W)!=="svelte-16qcd8b"&&(W.textContent=re),te=n(o),X=d(o,"P",{"data-svelte-h":!0}),J(X)!=="svelte-1shq479"&&(X.textContent=T),B=n(o),y(le.$$.fragment,o),me=n(o),Me=d(o,"P",{"data-svelte-h":!0}),J(Me)!=="svelte-2l4fow"&&(Me.textContent=pe),Te=n(o),F=d(o,"P",{"data-svelte-h":!0}),J(F)!=="svelte-1tyayn3"&&(F.textContent=Se),be=n(o),y(S.$$.fragment,o),Ue=n(o),y(q.$$.fragment,o),He=n(o),he=d(o,"P",{"data-svelte-h":!0}),J(he)!=="svelte-2wjeu9"&&(he.textContent=oe),je=n(o),D=d(o,"P",{"data-svelte-h":!0}),J(D)!=="svelte-emcbnj"&&(D.innerHTML=qe),ge=n(o),y(z.$$.fragment,o),xe=n(o),se=d(o,"P",{"data-svelte-h":!0}),J(se)!=="svelte-mme7gz"&&(se.textContent=ke),Ge=n(o),y(ae.$$.fragment,o),we=n(o),de=d(o,"P",{"data-svelte-h":!0}),J(de)!=="svelte-1is5qce"&&(de.textContent=ce),Be=n(o),ne=d(o,"P",{"data-svelte-h":!0}),J(ne)!=="svelte-1q5ysr9"&&(ne.textContent=Ze)},m(o,I){l(o,i,I),l(o,p,I),m(b,o,I),l(o,k,I),l(o,f,I),l(o,x,I),l(o,G,I),l(o,g,I),l(o,v,I),l(o,ue,I),m(A,o,I),l(o,Y,I),l(o,L,I),l(o,ye,I),m(Q,o,I),l(o,H,I),l(o,P,I),l(o,$e,I),m(K,o,I),l(o,R,I),m(ee,o,I),l(o,E,I),l(o,W,I),l(o,te,I),l(o,X,I),l(o,B,I),m(le,o,I),l(o,me,I),l(o,Me,I),l(o,Te,I),l(o,F,I),l(o,be,I),m(S,o,I),l(o,Ue,I),m(q,o,I),l(o,He,I),l(o,he,I),l(o,je,I),l(o,D,I),l(o,ge,I),m(z,o,I),l(o,xe,I),l(o,se,I),l(o,Ge,I),m(ae,o,I),l(o,we,I),l(o,de,I),l(o,Be,I),l(o,ne,I),Ce=!0},i(o){Ce||(c(b.$$.fragment,o),c(A.$$.fragment,o),c(Q.$$.fragment,o),c(K.$$.fragment,o),c(ee.$$.fragment,o),c(le.$$.fragment,o),c(S.$$.fragment,o),c(q.$$.fragment,o),c(z.$$.fragment,o),c(ae.$$.fragment,o),Ce=!0)},o(o){M(b.$$.fragment,o),M(A.$$.fragment,o),M(Q.$$.fragment,o),M(K.$$.fragment,o),M(ee.$$.fragment,o),M(le.$$.fragment,o),M(S.$$.fragment,o),M(q.$$.fragment,o),M(z.$$.fragment,o),M(ae.$$.fragment,o),Ce=!1},d(o){o&&(t(i),t(p),t(k),t(f),t(x),t(G),t(g),t(v),t(ue),t(Y),t(L),t(ye),t(H),t(P),t($e),t(R),t(E),t(W),t(te),t(X),t(B),t(me),t(Me),t(Te),t(F),t(be),t(Ue),t(He),t(he),t(je),t(D),t(ge),t(xe),t(se),t(Ge),t(we),t(de),t(Be),t(ne)),w(b,o),w(A,o),w(Q,o),w(K,o),w(ee,o),w(le,o),w(S,o),w(q,o),w(z,o),w(ae,o)}}}function Mi(Z){let i,U="Before we start, let’s see what kind of results we get from our model without any training:",p,b,k,f,_,x,G="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).",$,g,v,O,ue='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:',A,Y,L,N,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).',Q,H,P,V,$e="Finally, let’s see what our metrics look like now that training has finished:",K,R,ee,E,W,re,te="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!",X;return b=new j({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),f=new j({props:{code:"JTdCJ2JsZXUnJTNBJTIwMzMuMjY5ODM3MDE0NTQ3MzMlN0Q=",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">33.26983701454733</span>}',wrap:!1}}),g=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmtlcmFzX2NhbGxiYWNrcyUyMGltcG9ydCUyMFB1c2hUb0h1YkNhbGxiYWNrJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEElMjMlMjBUaGUlMjBudW1iZXIlMjBvZiUyMHRyYWluaW5nJTIwc3RlcHMlM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ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

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

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

<span class="hljs-comment"># Train in mixed-precision float16</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)`,wrap:!1}}),Y=new 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}}),H=new et({props:{$$slots:{default:[di]},$$scope:{ctx:Z}}}),R=new j({props:{code:"cHJpbnQoY29tcHV0ZV9tZXRyaWNzKCkp",highlighted:'<span class="hljs-built_in">print</span>(compute_metrics())',wrap:!1}}),E=new j({props:{code:"JTdCJ2JsZXUnJTNBJTIwNTcuMzM0MDY2MjcxNTQ1ODY1JTdE",highlighted:'{&#x27;bleu&#x27;: <span class="hljs-number">57.334066271545865</span>}',wrap:!1}}),{c(){i=h("p"),i.textContent=U,p=a(),u(b.$$.fragment),k=a(),u(f.$$.fragment),_=a(),x=h("p"),x.innerHTML=G,$=a(),u(g.$$.fragment),v=a(),O=h("p"),O.innerHTML=ue,A=a(),u(Y.$$.fragment),L=a(),N=h("p"),N.innerHTML=ye,Q=a(),u(H.$$.fragment),P=a(),V=h("p"),V.textContent=$e,K=a(),u(R.$$.fragment),ee=a(),u(E.$$.fragment),W=a(),re=h("p"),re.textContent=te},l(T){i=d(T,"P",{"data-svelte-h":!0}),J(i)!=="svelte-15un45t"&&(i.textContent=U),p=n(T),y(b.$$.fragment,T),k=n(T),y(f.$$.fragment,T),_=n(T),x=d(T,"P",{"data-svelte-h":!0}),J(x)!=="svelte-6yez9a"&&(x.innerHTML=G),$=n(T),y(g.$$.fragment,T),v=n(T),O=d(T,"P",{"data-svelte-h":!0}),J(O)!=="svelte-xippoq"&&(O.innerHTML=ue),A=n(T),y(Y.$$.fragment,T),L=n(T),N=d(T,"P",{"data-svelte-h":!0}),J(N)!=="svelte-1r4up0e"&&(N.innerHTML=ye),Q=n(T),y(H.$$.fragment,T),P=n(T),V=d(T,"P",{"data-svelte-h":!0}),J(V)!=="svelte-qf3ykr"&&(V.textContent=$e),K=n(T),y(R.$$.fragment,T),ee=n(T),y(E.$$.fragment,T),W=n(T),re=d(T,"P",{"data-svelte-h":!0}),J(re)!=="svelte-1is5qce"&&(re.textContent=te)},m(T,B){l(T,i,B),l(T,p,B),m(b,T,B),l(T,k,B),m(f,T,B),l(T,_,B),l(T,x,B),l(T,$,B),m(g,T,B),l(T,v,B),l(T,O,B),l(T,A,B),m(Y,T,B),l(T,L,B),l(T,N,B),l(T,Q,B),m(H,T,B),l(T,P,B),l(T,V,B),l(T,K,B),m(R,T,B),l(T,ee,B),m(E,T,B),l(T,W,B),l(T,re,B),X=!0},i(T){X||(c(b.$$.fragment,T),c(f.$$.fragment,T),c(g.$$.fragment,T),c(Y.$$.fragment,T),c(H.$$.fragment,T),c(R.$$.fragment,T),c(E.$$.fragment,T),X=!0)},o(T){M(b.$$.fragment,T),M(f.$$.fragment,T),M(g.$$.fragment,T),M(Y.$$.fragment,T),M(H.$$.fragment,T),M(R.$$.fragment,T),M(E.$$.fragment,T),X=!1},d(T){T&&(t(i),t(p),t(k),t(_),t(x),t($),t(v),t(O),t(A),t(L),t(N),t(Q),t(P),t(V),t(K),t(ee),t(W),t(re)),w(b,T),w(f,T),w(g,T),w(Y,T),w(H,T),w(R,T),w(E,T)}}}function hi(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-449gha"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function di(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-fiahcl"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function Vn(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>.',k,f,_,x,G="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:",$,g,v,O,ue="Next we reinstantiate our model, to make sure we’re not continuing the fine-tuning from before but starting from the pretrained model again:",A,Y,L,N,ye="Then we will need an optimizer:",Q,H,P,V,$e="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>.",K,R,ee,E,W="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:",re,te,X,T,B="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):",le,me,Me,pe,Te,F,Se="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:",be,S,Ue,q,He="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.",he,oe,je,D,qe="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:",ge,z,xe,se,ke='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!',Ge,ae,we="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.",de,ce,Be='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.',ne,Ze,Ce,o,I,Je,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!',ve;return i=new _e({props:{title:"A custom training loop",local:"a-custom-training-loop",headingTag:"h2"}}),f=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}}),Y=new j({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),H=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEFkYW1XJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhbVcobW9kZWwucGFyYW1ldGVycygpJTJDJTIwbHIlM0QyZS01KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),R=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}}),te=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}}),me=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}}),pe=new j({props:{code:"J3NndWdnZXIlMkZtYXJpYW4tZmluZXR1bmVkLWtkZTQtZW4tdG8tZnItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/marian-finetuned-kde4-en-to-fr-accelerate&#x27;</span>',wrap:!1}}),S=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=repo_name)`,wrap:!1}}),oe=new _e({props:{title:"Training loop",local:"training-loop",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lMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxz",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}}),Ze=new j({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHJhaW5fZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUyMCUyMCUyMCUyMCUyMCU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IwJTIwJTIwY29tbWl0X21lc3NhZ2UlM0RmJTIyVHJhaW5pbmclMjBpbiUyMHByb2dyZXNzJTIwZXBvY2glMjAlN0JlcG9jaCU3RCUyMiUyQyUyMGJsb2NraW5nJTNERmFsc2UlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAp",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(){u(i.$$.fragment),U=a(),p=h("p"),p.innerHTML=b,k=a(),u(f.$$.fragment),_=a(),x=h("p"),x.innerHTML=G,$=a(),u(g.$$.fragment),v=a(),O=h("p"),O.textContent=ue,A=a(),u(Y.$$.fragment),L=a(),N=h("p"),N.textContent=ye,Q=a(),u(H.$$.fragment),P=a(),V=h("p"),V.innerHTML=$e,K=a(),u(R.$$.fragment),ee=a(),E=h("p"),E.innerHTML=W,re=a(),u(te.$$.fragment),X=a(),T=h("p"),T.innerHTML=B,le=a(),u(me.$$.fragment),Me=a(),u(pe.$$.fragment),Te=a(),F=h("p"),F.textContent=Se,be=a(),u(S.$$.fragment),Ue=a(),q=h("p"),q.innerHTML=He,he=a(),u(oe.$$.fragment),je=a(),D=h("p"),D.innerHTML=qe,ge=a(),u(z.$$.fragment),xe=a(),se=h("p"),se.innerHTML=ke,Ge=a(),ae=h("p"),ae.innerHTML=we,de=a(),ce=h("p"),ce.innerHTML=Be,ne=a(),u(Ze.$$.fragment),Ce=a(),u(o.$$.fragment),I=a(),Je=h("p"),Je.innerHTML=tt},l(r){y(i.$$.fragment,r),U=n(r),p=d(r,"P",{"data-svelte-h":!0}),J(p)!=="svelte-qavg11"&&(p.innerHTML=b),k=n(r),y(f.$$.fragment,r),_=n(r),x=d(r,"P",{"data-svelte-h":!0}),J(x)!=="svelte-1xyz8xy"&&(x.innerHTML=G),$=n(r),y(g.$$.fragment,r),v=n(r),O=d(r,"P",{"data-svelte-h":!0}),J(O)!=="svelte-e8509p"&&(O.textContent=ue),A=n(r),y(Y.$$.fragment,r),L=n(r),N=d(r,"P",{"data-svelte-h":!0}),J(N)!=="svelte-47lq6z"&&(N.textContent=ye),Q=n(r),y(H.$$.fragment,r),P=n(r),V=d(r,"P",{"data-svelte-h":!0}),J(V)!=="svelte-18hq2jn"&&(V.innerHTML=$e),K=n(r),y(R.$$.fragment,r),ee=n(r),E=d(r,"P",{"data-svelte-h":!0}),J(E)!=="svelte-udl66p"&&(E.innerHTML=W),re=n(r),y(te.$$.fragment,r),X=n(r),T=d(r,"P",{"data-svelte-h":!0}),J(T)!=="svelte-v6q3yq"&&(T.innerHTML=B),le=n(r),y(me.$$.fragment,r),Me=n(r),y(pe.$$.fragment,r),Te=n(r),F=d(r,"P",{"data-svelte-h":!0}),J(F)!=="svelte-e9w2am"&&(F.textContent=Se),be=n(r),y(S.$$.fragment,r),Ue=n(r),q=d(r,"P",{"data-svelte-h":!0}),J(q)!=="svelte-1mcbsiy"&&(q.innerHTML=He),he=n(r),y(oe.$$.fragment,r),je=n(r),D=d(r,"P",{"data-svelte-h":!0}),J(D)!=="svelte-1x90r0t"&&(D.innerHTML=qe),ge=n(r),y(z.$$.fragment,r),xe=n(r),se=d(r,"P",{"data-svelte-h":!0}),J(se)!=="svelte-11l1dbc"&&(se.innerHTML=ke),Ge=n(r),ae=d(r,"P",{"data-svelte-h":!0}),J(ae)!=="svelte-1sfscsd"&&(ae.innerHTML=we),de=n(r),ce=d(r,"P",{"data-svelte-h":!0}),J(ce)!=="svelte-1cf30vw"&&(ce.innerHTML=Be),ne=n(r),y(Ze.$$.fragment,r),Ce=n(r),y(o.$$.fragment,r),I=n(r),Je=d(r,"P",{"data-svelte-h":!0}),J(Je)!=="svelte-ezkapr"&&(Je.innerHTML=tt)},m(r,C){m(i,r,C),l(r,U,C),l(r,p,C),l(r,k,C),m(f,r,C),l(r,_,C),l(r,x,C),l(r,$,C),m(g,r,C),l(r,v,C),l(r,O,C),l(r,A,C),m(Y,r,C),l(r,L,C),l(r,N,C),l(r,Q,C),m(H,r,C),l(r,P,C),l(r,V,C),l(r,K,C),m(R,r,C),l(r,ee,C),l(r,E,C),l(r,re,C),m(te,r,C),l(r,X,C),l(r,T,C),l(r,le,C),m(me,r,C),l(r,Me,C),m(pe,r,C),l(r,Te,C),l(r,F,C),l(r,be,C),m(S,r,C),l(r,Ue,C),l(r,q,C),l(r,he,C),m(oe,r,C),l(r,je,C),l(r,D,C),l(r,ge,C),m(z,r,C),l(r,xe,C),l(r,se,C),l(r,Ge,C),l(r,ae,C),l(r,de,C),l(r,ce,C),l(r,ne,C),m(Ze,r,C),l(r,Ce,C),m(o,r,C),l(r,I,C),l(r,Je,C),ve=!0},i(r){ve||(c(i.$$.fragment,r),c(f.$$.fragment,r),c(g.$$.fragment,r),c(Y.$$.fragment,r),c(H.$$.fragment,r),c(R.$$.fragment,r),c(te.$$.fragment,r),c(me.$$.fragment,r),c(pe.$$.fragment,r),c(S.$$.fragment,r),c(oe.$$.fragment,r),c(z.$$.fragment,r),c(Ze.$$.fragment,r),c(o.$$.fragment,r),ve=!0)},o(r){M(i.$$.fragment,r),M(f.$$.fragment,r),M(g.$$.fragment,r),M(Y.$$.fragment,r),M(H.$$.fragment,r),M(R.$$.fragment,r),M(te.$$.fragment,r),M(me.$$.fragment,r),M(pe.$$.fragment,r),M(S.$$.fragment,r),M(oe.$$.fragment,r),M(z.$$.fragment,r),M(Ze.$$.fragment,r),M(o.$$.fragment,r),ve=!1},d(r){r&&(t(U),t(p),t(k),t(_),t(x),t($),t(v),t(O),t(A),t(L),t(N),t(Q),t(P),t(V),t(K),t(ee),t(E),t(re),t(X),t(T),t(le),t(Me),t(Te),t(F),t(be),t(Ue),t(q),t(he),t(je),t(D),t(ge),t(xe),t(se),t(Ge),t(ae),t(de),t(ce),t(ne),t(Ce),t(I),t(Je)),w(i,r),w(f,r),w(g,r),w(Y,r),w(H,r),w(R,r),w(te,r),w(me,r),w(pe,r),w(S,r),w(oe,r),w(z,r),w(Ze,r),w(o,r)}}}function ui(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=h("p"),i.innerHTML=U},l(p){i=d(p,"P",{"data-svelte-h":!0}),J(i)!=="svelte-9o8gsu"&&(i.innerHTML=U)},m(p,b){l(p,i,b)},p:Fe,d(p){p&&t(i)}}}function yi(Z){let i,U,p,b,k,f,_,x,G,$,g,v,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:',ue,A,Y="<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>",L,N,ye,Q,H='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.',P,V,$e='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.',K,R,ee="Once we’re finished, we will have a model able to make predictions like this one:",E,W,re,te,X,T='<img class="block dark:hidden lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/modeleval-marian-finetuned-kde4-en-to-fr.png" alt="One-hot encoded labels for question answering."/> <img class="hidden dark:block lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/modeleval-marian-finetuned-kde4-en-to-fr-dark.png" alt="One-hot encoded labels for question answering."/>',B,le,me='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>.',Me,pe,Te,F,Se='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>.',be,S,Ue,q,He="As usual, we download our dataset using the <code>load_dataset()</code> function:",he,oe,je,D,qe='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>.',ge,z,xe,se,ke,Ge="Let’s have a look at the dataset:",ae,we,de,ce,Be,ne,Ze='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:',Ce,o,I,Je,tt,ve,r="We can rename the <code>&quot;test&quot;</code> key to <code>&quot;validation&quot;</code> like this:",C,lt,Sl,st,Ra="Now let’s take a look at one element of the dataset:",ql,at,Dl,nt,Ll,it,Xa="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:",Pl,rt,Kl,pt,Ol,ot,Na=`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”:`,es,ct,ts,Mt,ls,ht,Va="Our pretrained model, however, sticks with the compact and familiar English word:",ss,dt,as,ut,ns,yt,Aa="It will be interesting to see if our fine-tuned model picks up on those particularities of the dataset (spoiler alert: it will).",is,mt,rs,De,ps,wt,os,Jt,cs,ft,Qa='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.',Ms,Tt,hs,bt,Ea='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.',ds,Le,us,Ut,za="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,Ya="To see how this works, let’s process one sample of each language in the training set:",ms,gt,ws,Ct,Js,It,Ha="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:",fs,$t,Ts,kt,bs,Zt,Fa="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”).",Us,_t,Sa="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:",js,xt,gs,Gt,qa="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.",Cs,Pe,Is,Ke,$s,Bt,Da="We can now apply that preprocessing in one go on all the splits of our dataset:",ks,vt,Zs,Wt,La="Now that the data has been preprocessed, we are ready to fine-tune our pretrained model!",_s,We,Re,Vl,Rt,Pa="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.",xs,Xt,Gs,Nt,Ka='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.',Bs,Vt,Oa='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:',vs,Xe,Ne,Al,At,en="To test this on a few samples, we just call it on a list of examples from our tokenized training set:",Ws,Qt,Rs,Et,Xs,zt,tn="We can check our labels have been padded to the maximum length of the batch, using <code>-100</code>:",Ns,Yt,Vs,Ht,As,Ft,ln="And we can also have a look at the decoder input IDs, to see that they are shifted versions of the labels:",Qs,St,Es,qt,zs,Dt,sn="Here are the labels for the first and second elements in our dataset:",Ys,Lt,Hs,Pt,Fs,Ve,Ae,Ql,Kt,Ss,Ot,qs,El,el,an='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>).',Ds,tl,nn='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:',Ls,ll,Ps,sl,rn='We can then load it via <code>evaluate.load()</code> like we did in <a href="/course/chapter3">Chapter 3</a>:',Ks,al,Os,nl,pn="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.",ea,il,on="Let’s try an example:",ta,rl,la,pl,sa,ol,cn='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:',aa,cl,na,Ml,ia,hl,ra,dl,pa,ul,Mn="The score can go from 0 to 100, and higher is better.",oa,Qe,Ee,zl,yl,hn="Now that this is done, we are ready to fine-tune our model!",ca,ml,Ma,wl,dn="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:",ha,Jl,da,fl,un="This will display a widget where you can enter your Hugging Face login credentials.",ua,Tl,yn="If you aren’t working in a notebook, just type the following line in your terminal:",ya,bl,ma,ze,Ye,Yl,Hl,Ul,wa,jl,mn="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,fa,Cl,Ta,Il,wn="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”:",ba,$l,Ua,kl,ja,Zl,Jn="Another great example of domain adaptation!",ga,Oe,Ca,_l,Ia,Fl,$a;k=new Sn({props:{fw:Z[0]}}),_=new _e({props:{title:"Translation",local:"translation",headingTag:"h1"}});const fn=[Ln,Dn],xl=[];function Tn(e,s){return e[0]==="pt"?0:1}G=Tn(Z),$=xl[G]=fn[G](Z),N=new ka({props:{id:"1JvfrvZgi6c"}}),pe=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"}}),oe=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}}),we=new j({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),ce=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}}),o=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}}),Je=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}}),ct=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}}),Mt=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}}),mt=new ka({props:{id:"0Oxphw4Q9fo"}}),De=new et({props:{$$slots:{default:[Pn]},$$scope:{ctx:Z}}}),wt=new _e({props:{title:"Processing the data",local:"processing-the-data",headingTag:"h3"}}),Jt=new ka({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:[Kn]},$$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}}),$t=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:[On]},$$scope:{ctx:Z}}}),Ke=new et({props:{warning:!0,$$slots:{default:[ei]},$$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 bn=[li,ti],Gl=[];function Un(e,s){return e[0]==="pt"?0:1}We=Un(Z),Re=Gl[We]=bn[We](Z),Xt=new _e({props:{title:"Data collation",local:"data-collation",headingTag:"h3"}});const jn=[ni,ai],Bl=[];function gn(e,s){return e[0]==="pt"?0:1}Xe=gn(Z),Ne=Bl[Xe]=jn[Xe](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 Cn=[ri,ii],vl=[];function In(e,s){return e[0]==="pt"?0:1}Ve=In(Z),Ae=vl[Ve]=Cn[Ve](Z),Kt=new _e({props:{title:"Metrics",local:"metrics",headingTag:"h3"}}),Ot=new ka({props:{id:"M05L1DhFqcw"}});let fe=Z[0]==="pt"&&Nn();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}}),cl=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}}),Ml=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 $n=[oi,pi],Wl=[];function kn(e,s){return e[0]==="tf"?0:1}Qe=kn(Z),Ee=Wl[Qe]=$n[Qe](Z),ml=new _e({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),Jl=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 Zn=[Mi,ci],Rl=[];function _n(e,s){return e[0]==="tf"?0:1}ze=_n(Z),Ye=Rl[ze]=Zn[ze](Z);let ie=Z[0]==="pt"&&Vn();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}}),$l=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:[ui]},$$scope:{ctx:Z}}}),_l=new qn({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter7/4.mdx"}}),{c(){i=h("meta"),U=a(),p=h("p"),b=a(),u(k.$$.fragment),f=a(),u(_.$$.fragment),x=a(),$.c(),g=a(),v=h("p"),v.innerHTML=O,ue=a(),A=h("ul"),A.innerHTML=Y,L=a(),u(N.$$.fragment),ye=a(),Q=h("p"),Q.innerHTML=H,P=a(),V=h("p"),V.innerHTML=$e,K=a(),R=h("p"),R.textContent=ee,E=a(),W=h("iframe"),te=a(),X=h("a"),X.innerHTML=T,B=a(),le=h("p"),le.innerHTML=me,Me=a(),u(pe.$$.fragment),Te=a(),F=h("p"),F.innerHTML=Se,be=a(),u(S.$$.fragment),Ue=a(),q=h("p"),q.innerHTML=He,he=a(),u(oe.$$.fragment),je=a(),D=h("p"),D.innerHTML=qe,ge=a(),z=h("img"),se=a(),ke=h("p"),ke.textContent=Ge,ae=a(),u(we.$$.fragment),de=a(),u(ce.$$.fragment),Be=a(),ne=h("p"),ne.innerHTML=Ze,Ce=a(),u(o.$$.fragment),I=a(),u(Je.$$.fragment),tt=a(),ve=h("p"),ve.innerHTML=r,C=a(),u(lt.$$.fragment),Sl=a(),st=h("p"),st.textContent=Ra,ql=a(),u(at.$$.fragment),Dl=a(),u(nt.$$.fragment),Ll=a(),it=h("p"),it.textContent=Xa,Pl=a(),u(rt.$$.fragment),Kl=a(),u(pt.$$.fragment),Ol=a(),ot=h("p"),ot.textContent=Na,es=a(),u(ct.$$.fragment),ts=a(),u(Mt.$$.fragment),ls=a(),ht=h("p"),ht.textContent=Va,ss=a(),u(dt.$$.fragment),as=a(),u(ut.$$.fragment),ns=a(),yt=h("p"),yt.textContent=Aa,is=a(),u(mt.$$.fragment),rs=a(),u(De.$$.fragment),ps=a(),u(wt.$$.fragment),os=a(),u(Jt.$$.fragment),cs=a(),ft=h("p"),ft.innerHTML=Qa,Ms=a(),u(Tt.$$.fragment),hs=a(),bt=h("p"),bt.innerHTML=Ea,ds=a(),u(Le.$$.fragment),us=a(),Ut=h("p"),Ut.innerHTML=za,ys=a(),jt=h("p"),jt.textContent=Ya,ms=a(),u(gt.$$.fragment),ws=a(),u(Ct.$$.fragment),Js=a(),It=h("p"),It.innerHTML=Ha,fs=a(),u($t.$$.fragment),Ts=a(),u(kt.$$.fragment),bs=a(),Zt=h("p"),Zt.textContent=Fa,Us=a(),_t=h("p"),_t.innerHTML=Sa,js=a(),u(xt.$$.fragment),gs=a(),Gt=h("p"),Gt.textContent=qa,Cs=a(),u(Pe.$$.fragment),Is=a(),u(Ke.$$.fragment),$s=a(),Bt=h("p"),Bt.textContent=Da,ks=a(),u(vt.$$.fragment),Zs=a(),Wt=h("p"),Wt.textContent=La,_s=a(),Re.c(),Vl=a(),Rt=h("p"),Rt.textContent=Pa,xs=a(),u(Xt.$$.fragment),Gs=a(),Nt=h("p"),Nt.innerHTML=Ka,Bs=a(),Vt=h("p"),Vt.innerHTML=Oa,vs=a(),Ne.c(),Al=a(),At=h("p"),At.textContent=en,Ws=a(),u(Qt.$$.fragment),Rs=a(),u(Et.$$.fragment),Xs=a(),zt=h("p"),zt.innerHTML=tn,Ns=a(),u(Yt.$$.fragment),Vs=a(),u(Ht.$$.fragment),As=a(),Ft=h("p"),Ft.textContent=ln,Qs=a(),u(St.$$.fragment),Es=a(),u(qt.$$.fragment),zs=a(),Dt=h("p"),Dt.textContent=sn,Ys=a(),u(Lt.$$.fragment),Hs=a(),u(Pt.$$.fragment),Fs=a(),Ae.c(),Ql=a(),u(Kt.$$.fragment),Ss=a(),u(Ot.$$.fragment),qs=a(),fe&&fe.c(),El=a(),el=h("p"),el.innerHTML=an,Ds=a(),tl=h("p"),tl.innerHTML=nn,Ls=a(),u(ll.$$.fragment),Ps=a(),sl=h("p"),sl.innerHTML=rn,Ks=a(),u(al.$$.fragment),Os=a(),nl=h("p"),nl.textContent=pn,ea=a(),il=h("p"),il.textContent=on,ta=a(),u(rl.$$.fragment),la=a(),u(pl.$$.fragment),sa=a(),ol=h("p"),ol.innerHTML=cn,aa=a(),u(cl.$$.fragment),na=a(),u(Ml.$$.fragment),ia=a(),u(hl.$$.fragment),ra=a(),u(dl.$$.fragment),pa=a(),ul=h("p"),ul.textContent=Mn,oa=a(),Ee.c(),zl=a(),yl=h("p"),yl.textContent=hn,ca=a(),u(ml.$$.fragment),Ma=a(),wl=h("p"),wl.textContent=dn,ha=a(),u(Jl.$$.fragment),da=a(),fl=h("p"),fl.textContent=un,ua=a(),Tl=h("p"),Tl.textContent=yn,ya=a(),u(bl.$$.fragment),ma=a(),Ye.c(),Yl=a(),ie&&ie.c(),Hl=a(),u(Ul.$$.fragment),wa=a(),jl=h("p"),jl.innerHTML=mn,Ja=a(),u(gl.$$.fragment),fa=a(),u(Cl.$$.fragment),Ta=a(),Il=h("p"),Il.textContent=wn,ba=a(),u($l.$$.fragment),Ua=a(),u(kl.$$.fragment),ja=a(),Zl=h("p"),Zl.textContent=Jn,ga=a(),u(Oe.$$.fragment),Ca=a(),u(_l.$$.fragment),Ia=a(),Fl=h("p"),this.h()},l(e){const s=Hn("svelte-u9bgzb",document.head);i=d(s,"META",{name:!0,content:!0}),s.forEach(t),U=n(e),p=d(e,"P",{}),Wa(p).forEach(t),b=n(e),y(k.$$.fragment,e),f=n(e),y(_.$$.fragment,e),x=n(e),$.l(e),g=n(e),v=d(e,"P",{"data-svelte-h":!0}),J(v)!=="svelte-eyotq9"&&(v.innerHTML=O),ue=n(e),A=d(e,"UL",{"data-svelte-h":!0}),J(A)!=="svelte-mdl7i"&&(A.innerHTML=Y),L=n(e),y(N.$$.fragment,e),ye=n(e),Q=d(e,"P",{"data-svelte-h":!0}),J(Q)!=="svelte-qi4xhg"&&(Q.innerHTML=H),P=n(e),V=d(e,"P",{"data-svelte-h":!0}),J(V)!=="svelte-19rlunj"&&(V.innerHTML=$e),K=n(e),R=d(e,"P",{"data-svelte-h":!0}),J(R)!=="svelte-104mbqb"&&(R.textContent=ee),E=n(e),W=d(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Wa(W).forEach(t),te=n(e),X=d(e,"A",{class:!0,href:!0,"data-svelte-h":!0}),J(X)!=="svelte-1ifl6xg"&&(X.innerHTML=T),B=n(e),le=d(e,"P",{"data-svelte-h":!0}),J(le)!=="svelte-8feqj6"&&(le.innerHTML=me),Me=n(e),y(pe.$$.fragment,e),Te=n(e),F=d(e,"P",{"data-svelte-h":!0}),J(F)!=="svelte-1w48ec5"&&(F.innerHTML=Se),be=n(e),y(S.$$.fragment,e),Ue=n(e),q=d(e,"P",{"data-svelte-h":!0}),J(q)!=="svelte-psemqo"&&(q.innerHTML=He),he=n(e),y(oe.$$.fragment,e),je=n(e),D=d(e,"P",{"data-svelte-h":!0}),J(D)!=="svelte-waadns"&&(D.innerHTML=qe),ge=n(e),z=d(e,"IMG",{src:!0,alt:!0,width:!0}),se=n(e),ke=d(e,"P",{"data-svelte-h":!0}),J(ke)!=="svelte-11kki55"&&(ke.textContent=Ge),ae=n(e),y(we.$$.fragment,e),de=n(e),y(ce.$$.fragment,e),Be=n(e),ne=d(e,"P",{"data-svelte-h":!0}),J(ne)!=="svelte-am89ab"&&(ne.innerHTML=Ze),Ce=n(e),y(o.$$.fragment,e),I=n(e),y(Je.$$.fragment,e),tt=n(e),ve=d(e,"P",{"data-svelte-h":!0}),J(ve)!=="svelte-1b0nmgl"&&(ve.innerHTML=r),C=n(e),y(lt.$$.fragment,e),Sl=n(e),st=d(e,"P",{"data-svelte-h":!0}),J(st)!=="svelte-yn8zd9"&&(st.textContent=Ra),ql=n(e),y(at.$$.fragment,e),Dl=n(e),y(nt.$$.fragment,e),Ll=n(e),it=d(e,"P",{"data-svelte-h":!0}),J(it)!=="svelte-1neulry"&&(it.textContent=Xa),Pl=n(e),y(rt.$$.fragment,e),Kl=n(e),y(pt.$$.fragment,e),Ol=n(e),ot=d(e,"P",{"data-svelte-h":!0}),J(ot)!=="svelte-1x2u8k0"&&(ot.textContent=Na),es=n(e),y(ct.$$.fragment,e),ts=n(e),y(Mt.$$.fragment,e),ls=n(e),ht=d(e,"P",{"data-svelte-h":!0}),J(ht)!=="svelte-1pzq3b6"&&(ht.textContent=Va),ss=n(e),y(dt.$$.fragment,e),as=n(e),y(ut.$$.fragment,e),ns=n(e),yt=d(e,"P",{"data-svelte-h":!0}),J(yt)!=="svelte-1xxhzkh"&&(yt.textContent=Aa),is=n(e),y(mt.$$.fragment,e),rs=n(e),y(De.$$.fragment,e),ps=n(e),y(wt.$$.fragment,e),os=n(e),y(Jt.$$.fragment,e),cs=n(e),ft=d(e,"P",{"data-svelte-h":!0}),J(ft)!=="svelte-7kxu8d"&&(ft.innerHTML=Qa),Ms=n(e),y(Tt.$$.fragment,e),hs=n(e),bt=d(e,"P",{"data-svelte-h":!0}),J(bt)!=="svelte-1akd2n2"&&(bt.innerHTML=Ea),ds=n(e),y(Le.$$.fragment,e),us=n(e),Ut=d(e,"P",{"data-svelte-h":!0}),J(Ut)!=="svelte-1pc1kc0"&&(Ut.innerHTML=za),ys=n(e),jt=d(e,"P",{"data-svelte-h":!0}),J(jt)!=="svelte-16j9n8c"&&(jt.textContent=Ya),ms=n(e),y(gt.$$.fragment,e),ws=n(e),y(Ct.$$.fragment,e),Js=n(e),It=d(e,"P",{"data-svelte-h":!0}),J(It)!=="svelte-o6ed2q"&&(It.innerHTML=Ha),fs=n(e),y($t.$$.fragment,e),Ts=n(e),y(kt.$$.fragment,e),bs=n(e),Zt=d(e,"P",{"data-svelte-h":!0}),J(Zt)!=="svelte-10w8fo4"&&(Zt.textContent=Fa),Us=n(e),_t=d(e,"P",{"data-svelte-h":!0}),J(_t)!=="svelte-q0ybzj"&&(_t.innerHTML=Sa),js=n(e),y(xt.$$.fragment,e),gs=n(e),Gt=d(e,"P",{"data-svelte-h":!0}),J(Gt)!=="svelte-wqps0w"&&(Gt.textContent=qa),Cs=n(e),y(Pe.$$.fragment,e),Is=n(e),y(Ke.$$.fragment,e),$s=n(e),Bt=d(e,"P",{"data-svelte-h":!0}),J(Bt)!=="svelte-u9dyhf"&&(Bt.textContent=Da),ks=n(e),y(vt.$$.fragment,e),Zs=n(e),Wt=d(e,"P",{"data-svelte-h":!0}),J(Wt)!=="svelte-1a79fos"&&(Wt.textContent=La),_s=n(e),Re.l(e),Vl=n(e),Rt=d(e,"P",{"data-svelte-h":!0}),J(Rt)!=="svelte-1merkap"&&(Rt.textContent=Pa),xs=n(e),y(Xt.$$.fragment,e),Gs=n(e),Nt=d(e,"P",{"data-svelte-h":!0}),J(Nt)!=="svelte-1uzskyq"&&(Nt.innerHTML=Ka),Bs=n(e),Vt=d(e,"P",{"data-svelte-h":!0}),J(Vt)!=="svelte-18ubg06"&&(Vt.innerHTML=Oa),vs=n(e),Ne.l(e),Al=n(e),At=d(e,"P",{"data-svelte-h":!0}),J(At)!=="svelte-bijhma"&&(At.textContent=en),Ws=n(e),y(Qt.$$.fragment,e),Rs=n(e),y(Et.$$.fragment,e),Xs=n(e),zt=d(e,"P",{"data-svelte-h":!0}),J(zt)!=="svelte-990iko"&&(zt.innerHTML=tn),Ns=n(e),y(Yt.$$.fragment,e),Vs=n(e),y(Ht.$$.fragment,e),As=n(e),Ft=d(e,"P",{"data-svelte-h":!0}),J(Ft)!=="svelte-1hivgoi"&&(Ft.textContent=ln),Qs=n(e),y(St.$$.fragment,e),Es=n(e),y(qt.$$.fragment,e),zs=n(e),Dt=d(e,"P",{"data-svelte-h":!0}),J(Dt)!=="svelte-unhint"&&(Dt.textContent=sn),Ys=n(e),y(Lt.$$.fragment,e),Hs=n(e),y(Pt.$$.fragment,e),Fs=n(e),Ae.l(e),Ql=n(e),y(Kt.$$.fragment,e),Ss=n(e),y(Ot.$$.fragment,e),qs=n(e),fe&&fe.l(e),El=n(e),el=d(e,"P",{"data-svelte-h":!0}),J(el)!=="svelte-1kiw7od"&&(el.innerHTML=an),Ds=n(e),tl=d(e,"P",{"data-svelte-h":!0}),J(tl)!=="svelte-1bnfkqb"&&(tl.innerHTML=nn),Ls=n(e),y(ll.$$.fragment,e),Ps=n(e),sl=d(e,"P",{"data-svelte-h":!0}),J(sl)!=="svelte-jh6rtm"&&(sl.innerHTML=rn),Ks=n(e),y(al.$$.fragment,e),Os=n(e),nl=d(e,"P",{"data-svelte-h":!0}),J(nl)!=="svelte-1oah3bx"&&(nl.textContent=pn),ea=n(e),il=d(e,"P",{"data-svelte-h":!0}),J(il)!=="svelte-1h2fqkp"&&(il.textContent=on),ta=n(e),y(rl.$$.fragment,e),la=n(e),y(pl.$$.fragment,e),sa=n(e),ol=d(e,"P",{"data-svelte-h":!0}),J(ol)!=="svelte-1iu1ast"&&(ol.innerHTML=cn),aa=n(e),y(cl.$$.fragment,e),na=n(e),y(Ml.$$.fragment,e),ia=n(e),y(hl.$$.fragment,e),ra=n(e),y(dl.$$.fragment,e),pa=n(e),ul=d(e,"P",{"data-svelte-h":!0}),J(ul)!=="svelte-tsitwn"&&(ul.textContent=Mn),oa=n(e),Ee.l(e),zl=n(e),yl=d(e,"P",{"data-svelte-h":!0}),J(yl)!=="svelte-1gk0eqs"&&(yl.textContent=hn),ca=n(e),y(ml.$$.fragment,e),Ma=n(e),wl=d(e,"P",{"data-svelte-h":!0}),J(wl)!=="svelte-gd91fw"&&(wl.textContent=dn),ha=n(e),y(Jl.$$.fragment,e),da=n(e),fl=d(e,"P",{"data-svelte-h":!0}),J(fl)!=="svelte-1ied0vh"&&(fl.textContent=un),ua=n(e),Tl=d(e,"P",{"data-svelte-h":!0}),J(Tl)!=="svelte-648vlf"&&(Tl.textContent=yn),ya=n(e),y(bl.$$.fragment,e),ma=n(e),Ye.l(e),Yl=n(e),ie&&ie.l(e),Hl=n(e),y(Ul.$$.fragment,e),wa=n(e),jl=d(e,"P",{"data-svelte-h":!0}),J(jl)!=="svelte-d11l7w"&&(jl.innerHTML=mn),Ja=n(e),y(gl.$$.fragment,e),fa=n(e),y(Cl.$$.fragment,e),Ta=n(e),Il=d(e,"P",{"data-svelte-h":!0}),J(Il)!=="svelte-1gj0rwy"&&(Il.textContent=wn),ba=n(e),y($l.$$.fragment,e),Ua=n(e),y(kl.$$.fragment,e),ja=n(e),Zl=d(e,"P",{"data-svelte-h":!0}),J(Zl)!=="svelte-1o5slqz"&&(Zl.textContent=Jn),ga=n(e),y(Oe.$$.fragment,e),Ca=n(e),y(_l.$$.fragment,e),Ia=n(e),Fl=d(e,"P",{}),Wa(Fl).forEach(t),this.h()},h(){Ie(i,"name","hf:doc:metadata"),Ie(i,"content",mi),Xn(W.src,re="https://course-demos-marian-finetuned-kde4-en-to-fr.hf.space")||Ie(W,"src",re),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"),Xn(z.src,xe="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/language_tags.png")||Ie(z,"src",xe),Ie(z,"alt","Language available for the KDE4 dataset."),Ie(z,"width","100%")},m(e,s){Fn(document.head,i),l(e,U,s),l(e,p,s),l(e,b,s),m(k,e,s),l(e,f,s),m(_,e,s),l(e,x,s),xl[G].m(e,s),l(e,g,s),l(e,v,s),l(e,ue,s),l(e,A,s),l(e,L,s),m(N,e,s),l(e,ye,s),l(e,Q,s),l(e,P,s),l(e,V,s),l(e,K,s),l(e,R,s),l(e,E,s),l(e,W,s),l(e,te,s),l(e,X,s),l(e,B,s),l(e,le,s),l(e,Me,s),m(pe,e,s),l(e,Te,s),l(e,F,s),l(e,be,s),m(S,e,s),l(e,Ue,s),l(e,q,s),l(e,he,s),m(oe,e,s),l(e,je,s),l(e,D,s),l(e,ge,s),l(e,z,s),l(e,se,s),l(e,ke,s),l(e,ae,s),m(we,e,s),l(e,de,s),m(ce,e,s),l(e,Be,s),l(e,ne,s),l(e,Ce,s),m(o,e,s),l(e,I,s),m(Je,e,s),l(e,tt,s),l(e,ve,s),l(e,C,s),m(lt,e,s),l(e,Sl,s),l(e,st,s),l(e,ql,s),m(at,e,s),l(e,Dl,s),m(nt,e,s),l(e,Ll,s),l(e,it,s),l(e,Pl,s),m(rt,e,s),l(e,Kl,s),m(pt,e,s),l(e,Ol,s),l(e,ot,s),l(e,es,s),m(ct,e,s),l(e,ts,s),m(Mt,e,s),l(e,ls,s),l(e,ht,s),l(e,ss,s),m(dt,e,s),l(e,as,s),m(ut,e,s),l(e,ns,s),l(e,yt,s),l(e,is,s),m(mt,e,s),l(e,rs,s),m(De,e,s),l(e,ps,s),m(wt,e,s),l(e,os,s),m(Jt,e,s),l(e,cs,s),l(e,ft,s),l(e,Ms,s),m(Tt,e,s),l(e,hs,s),l(e,bt,s),l(e,ds,s),m(Le,e,s),l(e,us,s),l(e,Ut,s),l(e,ys,s),l(e,jt,s),l(e,ms,s),m(gt,e,s),l(e,ws,s),m(Ct,e,s),l(e,Js,s),l(e,It,s),l(e,fs,s),m($t,e,s),l(e,Ts,s),m(kt,e,s),l(e,bs,s),l(e,Zt,s),l(e,Us,s),l(e,_t,s),l(e,js,s),m(xt,e,s),l(e,gs,s),l(e,Gt,s),l(e,Cs,s),m(Pe,e,s),l(e,Is,s),m(Ke,e,s),l(e,$s,s),l(e,Bt,s),l(e,ks,s),m(vt,e,s),l(e,Zs,s),l(e,Wt,s),l(e,_s,s),Gl[We].m(e,s),l(e,Vl,s),l(e,Rt,s),l(e,xs,s),m(Xt,e,s),l(e,Gs,s),l(e,Nt,s),l(e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s),$a=!0},p(e,[s]){const xn={};s&1&&(xn.fw=e[0]),k.$set(xn);let Za=G;G=Tn(e),G!==Za&&(Nl(),M(xl[Za],1,1,()=>{xl[Za]=null}),Xl(),$=xl[G],$||($=xl[G]=fn[G](e),$.c()),c($,1),$.m(g.parentNode,g));const Gn={};s&2&&(Gn.$$scope={dirty:s,ctx:e}),De.$set(Gn);const Bn={};s&2&&(Bn.$$scope={dirty:s,ctx:e}),Le.$set(Bn);const vn={};s&2&&(vn.$$scope={dirty:s,ctx:e}),Pe.$set(vn);const Wn={};s&2&&(Wn.$$scope={dirty:s,ctx:e}),Ke.$set(Wn);let _a=We;We=Un(e),We!==_a&&(Nl(),M(Gl[_a],1,1,()=>{Gl[_a]=null}),Xl(),Re=Gl[We],Re||(Re=Gl[We]=bn[We](e),Re.c()),c(Re,1),Re.m(Vl.parentNode,Vl));let xa=Xe;Xe=gn(e),Xe!==xa&&(Nl(),M(Bl[xa],1,1,()=>{Bl[xa]=null}),Xl(),Ne=Bl[Xe],Ne||(Ne=Bl[Xe]=jn[Xe](e),Ne.c()),c(Ne,1),Ne.m(Al.parentNode,Al));let Ga=Ve;Ve=In(e),Ve!==Ga&&(Nl(),M(vl[Ga],1,1,()=>{vl[Ga]=null}),Xl(),Ae=vl[Ve],Ae||(Ae=vl[Ve]=Cn[Ve](e),Ae.c()),c(Ae,1),Ae.m(Ql.parentNode,Ql)),e[0]==="pt"?fe||(fe=Nn(),fe.c(),fe.m(El.parentNode,El)):fe&&(fe.d(1),fe=null);let Ba=Qe;Qe=kn(e),Qe!==Ba&&(Nl(),M(Wl[Ba],1,1,()=>{Wl[Ba]=null}),Xl(),Ee=Wl[Qe],Ee||(Ee=Wl[Qe]=$n[Qe](e),Ee.c()),c(Ee,1),Ee.m(zl.parentNode,zl));let va=ze;ze=_n(e),ze!==va&&(Nl(),M(Rl[va],1,1,()=>{Rl[va]=null}),Xl(),Ye=Rl[ze],Ye||(Ye=Rl[ze]=Zn[ze](e),Ye.c()),c(Ye,1),Ye.m(Yl.parentNode,Yl)),e[0]==="pt"?ie?s&1&&c(ie,1):(ie=Vn(),ie.c(),c(ie,1),ie.m(Hl.parentNode,Hl)):ie&&(Nl(),M(ie,1,1,()=>{ie=null}),Xl());const Rn={};s&2&&(Rn.$$scope={dirty:s,ctx:e}),Oe.$set(Rn)},i(e){$a||(c(k.$$.fragment,e),c(_.$$.fragment,e),c($),c(N.$$.fragment,e),c(pe.$$.fragment,e),c(S.$$.fragment,e),c(oe.$$.fragment,e),c(we.$$.fragment,e),c(ce.$$.fragment,e),c(o.$$.fragment,e),c(Je.$$.fragment,e),c(lt.$$.fragment,e),c(at.$$.fragment,e),c(nt.$$.fragment,e),c(rt.$$.fragment,e),c(pt.$$.fragment,e),c(ct.$$.fragment,e),c(Mt.$$.fragment,e),c(dt.$$.fragment,e),c(ut.$$.fragment,e),c(mt.$$.fragment,e),c(De.$$.fragment,e),c(wt.$$.fragment,e),c(Jt.$$.fragment,e),c(Tt.$$.fragment,e),c(Le.$$.fragment,e),c(gt.$$.fragment,e),c(Ct.$$.fragment,e),c($t.$$.fragment,e),c(kt.$$.fragment,e),c(xt.$$.fragment,e),c(Pe.$$.fragment,e),c(Ke.$$.fragment,e),c(vt.$$.fragment,e),c(Re),c(Xt.$$.fragment,e),c(Ne),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(Ae),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(cl.$$.fragment,e),c(Ml.$$.fragment,e),c(hl.$$.fragment,e),c(dl.$$.fragment,e),c(Ee),c(ml.$$.fragment,e),c(Jl.$$.fragment,e),c(bl.$$.fragment,e),c(Ye),c(ie),c(Ul.$$.fragment,e),c(gl.$$.fragment,e),c(Cl.$$.fragment,e),c($l.$$.fragment,e),c(kl.$$.fragment,e),c(Oe.$$.fragment,e),c(_l.$$.fragment,e),$a=!0)},o(e){M(k.$$.fragment,e),M(_.$$.fragment,e),M($),M(N.$$.fragment,e),M(pe.$$.fragment,e),M(S.$$.fragment,e),M(oe.$$.fragment,e),M(we.$$.fragment,e),M(ce.$$.fragment,e),M(o.$$.fragment,e),M(Je.$$.fragment,e),M(lt.$$.fragment,e),M(at.$$.fragment,e),M(nt.$$.fragment,e),M(rt.$$.fragment,e),M(pt.$$.fragment,e),M(ct.$$.fragment,e),M(Mt.$$.fragment,e),M(dt.$$.fragment,e),M(ut.$$.fragment,e),M(mt.$$.fragment,e),M(De.$$.fragment,e),M(wt.$$.fragment,e),M(Jt.$$.fragment,e),M(Tt.$$.fragment,e),M(Le.$$.fragment,e),M(gt.$$.fragment,e),M(Ct.$$.fragment,e),M($t.$$.fragment,e),M(kt.$$.fragment,e),M(xt.$$.fragment,e),M(Pe.$$.fragment,e),M(Ke.$$.fragment,e),M(vt.$$.fragment,e),M(Re),M(Xt.$$.fragment,e),M(Ne),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(Ae),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(cl.$$.fragment,e),M(Ml.$$.fragment,e),M(hl.$$.fragment,e),M(dl.$$.fragment,e),M(Ee),M(ml.$$.fragment,e),M(Jl.$$.fragment,e),M(bl.$$.fragment,e),M(Ye),M(ie),M(Ul.$$.fragment,e),M(gl.$$.fragment,e),M(Cl.$$.fragment,e),M($l.$$.fragment,e),M(kl.$$.fragment,e),M(Oe.$$.fragment,e),M(_l.$$.fragment,e),$a=!1},d(e){e&&(t(U),t(p),t(b),t(f),t(x),t(g),t(v),t(ue),t(A),t(L),t(ye),t(Q),t(P),t(V),t(K),t(R),t(E),t(W),t(te),t(X),t(B),t(le),t(Me),t(Te),t(F),t(be),t(Ue),t(q),t(he),t(je),t(D),t(ge),t(z),t(se),t(ke),t(ae),t(de),t(Be),t(ne),t(Ce),t(I),t(tt),t(ve),t(C),t(Sl),t(st),t(ql),t(Dl),t(Ll),t(it),t(Pl),t(Kl),t(Ol),t(ot),t(es),t(ts),t(ls),t(ht),t(ss),t(as),t(ns),t(yt),t(is),t(rs),t(ps),t(os),t(cs),t(ft),t(Ms),t(hs),t(bt),t(ds),t(us),t(Ut),t(ys),t(jt),t(ms),t(ws),t(Js),t(It),t(fs),t(Ts),t(bs),t(Zt),t(Us),t(_t),t(js),t(gs),t(Gt),t(Cs),t(Is),t($s),t(Bt),t(ks),t(Zs),t(Wt),t(_s),t(Vl),t(Rt),t(xs),t(Gs),t(Nt),t(Bs),t(Vt),t(vs),t(Al),t(At),t(Ws),t(Rs),t(Xs),t(zt),t(Ns),t(Vs),t(As),t(Ft),t(Qs),t(Es),t(zs),t(Dt),t(Ys),t(Hs),t(Fs),t(Ql),t(Ss),t(qs),t(El),t(el),t(Ds),t(tl),t(Ls),t(Ps),t(sl),t(Ks),t(Os),t(nl),t(ea),t(il),t(ta),t(la),t(sa),t(ol),t(aa),t(na),t(ia),t(ra),t(pa),t(ul),t(oa),t(zl),t(yl),t(ca),t(Ma),t(wl),t(ha),t(da),t(fl),t(ua),t(Tl),t(ya),t(ma),t(Yl),t(Hl),t(wa),t(jl),t(Ja),t(fa),t(Ta),t(Il),t(ba),t(Ua),t(ja),t(Zl),t(ga),t(Ca),t(Ia),t(Fl)),t(i),w(k,e),w(_,e),xl[G].d(e),w(N,e),w(pe,e),w(S,e),w(oe,e),w(we,e),w(ce,e),w(o,e),w(Je,e),w(lt,e),w(at,e),w(nt,e),w(rt,e),w(pt,e),w(ct,e),w(Mt,e),w(dt,e),w(ut,e),w(mt,e),w(De,e),w(wt,e),w(Jt,e),w(Tt,e),w(Le,e),w(gt,e),w(Ct,e),w($t,e),w(kt,e),w(xt,e),w(Pe,e),w(Ke,e),w(vt,e),Gl[We].d(e),w(Xt,e),Bl[Xe].d(e),w(Qt,e),w(Et,e),w(Yt,e),w(Ht,e),w(St,e),w(qt,e),w(Lt,e),w(Pt,e),vl[Ve].d(e),w(Kt,e),w(Ot,e),fe&&fe.d(e),w(ll,e),w(al,e),w(rl,e),w(pl,e),w(cl,e),w(Ml,e),w(hl,e),w(dl,e),Wl[Qe].d(e),w(ml,e),w(Jl,e),w(bl,e),Rl[ze].d(e),ie&&ie.d(e),w(Ul,e),w(gl,e),w(Cl,e),w($l,e),w(kl,e),w(Oe,e),w(_l,e)}}}const mi='{"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 wi(Z,i,U){let p="pt";return En(()=>{const b=new URLSearchParams(window.location.search);U(0,p=b.get("fw")||"pt")}),[p]}class Ii extends zn{constructor(i){super(),Yn(this,i,wi,yi,Qn,{})}}export{Ii as component};
