import{s as jt,o as Ut,n as et}from"../chunks/scheduler.37c15a92.js";import{S as Gt,i as Zt,g as u,s as l,r,A as vt,h as f,f as s,c as n,j as Jt,u as p,x as w,k as gt,y as kt,a,v as m,d as h,t as c,w as d}from"../chunks/index.2bf4358c.js";import{T as Ke}from"../chunks/Tip.363c041f.js";import{Y as De}from"../chunks/Youtube.1e50a667.js";import{C as $}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as _t}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Ct}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Oe}from"../chunks/Heading.8ada512a.js";function It(b){let i,y="Note that 🤗 Transformers models have a special ability that most Keras models don’t - they can automatically use an appropriate loss which they compute internally. They will use this loss by default if you don’t set a loss argument in <code>compile()</code>. Note that to use the internal loss you’ll need to pass your labels as part of the input, not as a separate label, which is the normal way to use labels with Keras models. You’ll see examples of this in Part 2 of the course, where defining the correct loss function can be tricky. For sequence classification, however, a standard Keras loss function works fine, so that’s what we’ll use here.";return{c(){i=u("p"),i.innerHTML=y},l(o){i=f(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-gq31cq"&&(i.innerHTML=y)},m(o,M){a(o,i,M)},p:et,d(o){o&&s(i)}}}function Wt(b){let i,y="Note a very common pitfall here — you <em>can</em> just pass the name of the loss as a string to Keras, but by default Keras will assume that you have already applied a softmax to your outputs. Many models, however, output the values right before the softmax is applied, which are also known as the <em>logits</em>. We need to tell the loss function that that’s what our model does, and the only way to do that is to call it directly, rather than by name with a string.";return{c(){i=u("p"),i.innerHTML=y},l(o){i=f(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-8ry0o4"&&(i.innerHTML=y)},m(o,M){a(o,i,M)},p:et,d(o){o&&s(i)}}}function Rt(b){let i,y="The 🤗 Transformers library also has a <code>create_optimizer()</code> function that will create an <code>AdamW</code> optimizer with learning rate decay. This is a convenient shortcut that you’ll see in detail in future sections of the course.";return{c(){i=u("p"),i.innerHTML=y},l(o){i=f(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-1pwe2ym"&&(i.innerHTML=y)},m(o,M){a(o,i,M)},p:et,d(o){o&&s(i)}}}function Xt(b){let i,y='💡 If you want to automatically upload your model to the Hub during training, you can pass along a <code>PushToHubCallback</code> in the <code>model.fit()</code> method. We will learn more about this in <a href="/course/chapter4/3">Chapter 4</a>';return{c(){i=u("p"),i.innerHTML=y},l(o){i=f(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-1n54c61"&&(i.innerHTML=y)},m(o,M){a(o,i,M)},p:et,d(o){o&&s(i)}}}function zt(b){let i,y,o,M,T,pe,G,me,Z,he,v,tt='Once you’ve done all the data preprocessing work in the last section, you have just a few steps left to train the model. Note, however, that the <code>model.fit()</code> command will run very slowly on a CPU. If you don’t have a GPU set up, you can get access to free GPUs or TPUs on <a href="https://colab.research.google.com/" rel="nofollow">Google Colab</a>.',ce,k,st="The code examples below assume you have already executed the examples in the previous section. Here is a short summary recapping what you need:",de,_,ue,C,fe,I,at="TensorFlow models imported from 🤗 Transformers are already Keras models. Here is a short introduction to Keras.",we,W,ye,R,lt="That means that once we have our data, very little work is required to begin training on it.",Me,X,be,z,nt='As in the <a href="/course/chapter2">previous chapter</a>, we will use the <code>TFAutoModelForSequenceClassification</code> class, with two labels:',$e,F,Te,V,it='You will notice that unlike in <a href="/course/chapter2">Chapter 2</a>, you get a warning after instantiating this pretrained model. This is because BERT has not been pretrained on classifying pairs of sentences, so the head of the pretrained model has been discarded and a new head suitable for sequence classification has been inserted instead. The warnings indicate that some weights were not used (the ones corresponding to the dropped pretraining head) and that some others were randomly initialized (the ones for the new head). It concludes by encouraging you to train the model, which is exactly what we are going to do now.',Je,H,ot="To fine-tune the model on our dataset, we just have to <code>compile()</code> our model and then pass our data to the <code>fit()</code> method. This will start the fine-tuning process (which should take a couple of minutes on a GPU) and report training loss as it goes, plus the validation loss at the end of each epoch.",ge,J,je,Y,Ue,g,Ge,Q,Ze,B,ve,x,rt=`If you try the above code, it certainly runs, but you’ll find that the loss declines only slowly or sporadically. The primary cause
is the <em>learning rate</em>. As with the loss, when we pass Keras the name of an optimizer as a string, Keras initializes
that optimizer with default values for all parameters, including learning rate. From long experience, though, we know
that transformer models benefit from a much lower learning rate than the default for Adam, which is 1e-3, also written
as 10 to the power of -3, or 0.001. 5e-5 (0.00005), which is some twenty times lower, is a much better starting point.`,ke,N,pt=`In addition to lowering the learning rate, we have a second trick up our sleeve: We can slowly reduce the learning rate
over the course of training. In the literature, you will sometimes see this referred to as <em>decaying</em> or <em>annealing</em>
the learning rate. In Keras, the best way to do this is to use a <em>learning rate scheduler</em>. A good one to use is
<code>PolynomialDecay</code> — despite the name, with default settings it simply linearly decays the learning rate from the initial
value to the final value over the course of training, which is exactly what we want. In order to use a scheduler correctly,
though, we need to tell it how long training is going to be. We compute that as <code>num_train_steps</code> below.`,_e,E,Ce,j,Ie,S,mt="Now we have our all-new optimizer, and we can try training with it. First, let’s reload the model, to reset the changes to the weights from the training run we just did, and then we can compile it with the new optimizer:",We,q,Re,A,ht="Now, we fit again:",Xe,L,ze,U,Fe,P,Ve,K,He,D,ct="Training and watching the loss go down is all very nice, but what if we want to actually get outputs from the trained model, either to compute some metrics, or to use the model in production? To do that, we can just use the <code>predict()</code> method. This will return the <em>logits</em> from the output head of the model, one per class.",Ye,O,Qe,ee,dt="We can convert these logits into the model’s class predictions by using <code>argmax</code> to find the highest logit, which corresponds to the most likely class:",Be,te,xe,se,Ne,ae,ut="Now, let’s use those <code>preds</code> to compute some metrics! We can load the metrics associated with the MRPC dataset as easily as we loaded the dataset, this time with the <code>evaluate.load()</code> function. The object returned has a <code>compute()</code> method we can use to do the metric calculation:",Ee,le,Se,ne,qe,ie,ft='The exact results you get may vary, as the random initialization of the model head might change the metrics it achieved. Here, we can see our model has an accuracy of 85.78% on the validation set and an F1 score of 89.97. Those are the two metrics used to evaluate results on the MRPC dataset for the GLUE benchmark. The table in the <a href="https://arxiv.org/pdf/1810.04805.pdf" rel="nofollow">BERT paper</a> reported an F1 score of 88.9 for the base model. That was the <code>uncased</code> model while we are currently using the <code>cased</code> model, which explains the better result.',Ae,oe,wt='This concludes the introduction to fine-tuning using the Keras API. An example of doing this for most common NLP tasks will be given in <a href="/course/chapter7">Chapter 7</a>. If you would like to hone your skills on the Keras API, try to fine-tune a model on the GLUE SST-2 dataset, using the data processing you did in section 2.',Le,re,Pe;return T=new Ct({props:{fw:b[0]}}),G=new Oe({props:{title:"Fine-tuning a model with Keras",local:"fine-tuning-a-model-with-keras",headingTag:"h1"}}),Z=new _t({props:{chapter:3,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/chapter3/section3_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter3/section3_tf.ipynb"}]}}),_=new $({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBEYXRhQ29sbGF0b3JXaXRoUGFkZGluZyUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQXJhd19kYXRhc2V0cyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwJTIybXJwYyUyMiklMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyYmVydC1iYXNlLXVuY2FzZWQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQSUwQWRlZiUyMHRva2VuaXplX2Z1bmN0aW9uKGV4YW1wbGUpJTNBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdG9rZW5pemVyKGV4YW1wbGUlNUIlMjJzZW50ZW5jZTElMjIlNUQlMkMlMjBleGFtcGxlJTVCJTIyc2VudGVuY2UyJTIyJTVEJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUpJTBBJTBBJTBBdG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwcmF3X2RhdGFzZXRzLm1hcCh0b2tlbml6ZV9mdW5jdGlvbiUyQyUyMGJhdGNoZWQlM0RUcnVlKSUwQSUwQWRhdGFfY29sbGF0b3IlMjAlM0QlMjBEYXRhQ29sbGF0b3JXaXRoUGFkZGluZyh0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKSUwQSUwQXRmX3RyYWluX2RhdGFzZXQlMjAlM0QlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUyMCUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMnRva2VuX3R5cGVfaWRzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWxfY29scyUzRCU1QiUyMmxhYmVscyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSklMEElMEF0Zl92YWxpZGF0aW9uX2RhdGFzZXQlMjAlM0QlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsYWJlbF9jb2xzJTNEJTVCJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, DataCollatorWithPadding
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

raw_datasets = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">example</span>):
    <span class="hljs-keyword">return</span> tokenizer(example[<span class="hljs-string">&quot;sentence1&quot;</span>], example[<span class="hljs-string">&quot;sentence2&quot;</span>], truncation=<span class="hljs-literal">True</span>)


tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)

data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)

tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)

tf_validation_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">False</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)`,wrap:!1}}),C=new Oe({props:{title:"Training",local:"training",headingTag:"h3"}}),W=new De({props:{id:"rnTGBy2ax1c"}}),X=new De({props:{id:"AUozVp78dhk"}}),F=new $({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50JTJDJTIwbnVtX2xhYmVscyUzRDIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)`,wrap:!1}}),J=new Ke({props:{$$slots:{default:[It]},$$scope:{ctx:b}}}),Y=new $({props:{code:"ZnJvbSUyMHRlbnNvcmZsb3cua2VyYXMubG9zc2VzJTIwaW1wb3J0JTIwU3BhcnNlQ2F0ZWdvcmljYWxDcm9zc2VudHJvcHklMEElMEFtb2RlbC5jb21waWxlKCUwQSUyMCUyMCUyMCUyMG9wdGltaXplciUzRCUyMmFkYW0lMjIlMkMlMEElMjAlMjAlMjAlMjBsb3NzJTNEU3BhcnNlQ2F0ZWdvcmljYWxDcm9zc2VudHJvcHkoZnJvbV9sb2dpdHMlM0RUcnVlKSUyQyUwQSUyMCUyMCUyMCUyMG1ldHJpY3MlM0QlNUIlMjJhY2N1cmFjeSUyMiU1RCUyQyUwQSklMEFtb2RlbC5maXQoJTBBJTIwJTIwJTIwJTIwdGZfdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHZhbGlkYXRpb25fZGF0YSUzRHRmX3ZhbGlkYXRpb25fZGF0YXNldCUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> tensorflow.keras.losses <span class="hljs-keyword">import</span> SparseCategoricalCrossentropy

model.<span class="hljs-built_in">compile</span>(
    optimizer=<span class="hljs-string">&quot;adam&quot;</span>,
    loss=SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>),
    metrics=[<span class="hljs-string">&quot;accuracy&quot;</span>],
)
model.fit(
    tf_train_dataset,
    validation_data=tf_validation_dataset,
)`,wrap:!1}}),g=new Ke({props:{warning:!0,$$slots:{default:[Wt]},$$scope:{ctx:b}}}),Q=new Oe({props:{title:"Improving training performance",local:"improving-training-performance",headingTag:"h3"}}),B=new De({props:{id:"cpzq6ESSM5c"}}),E=new $({props:{code:"ZnJvbSUyMHRlbnNvcmZsb3cua2VyYXMub3B0aW1pemVycy5zY2hlZHVsZXMlMjBpbXBvcnQlMjBQb2x5bm9taWFsRGVjYXklMEElMEFiYXRjaF9zaXplJTIwJTNEJTIwOCUwQW51bV9lcG9jaHMlMjAlM0QlMjAzJTBBJTIzJTIwVGhlJTIwbnVtYmVyJTIwb2YlMjB0cmFpbmluZyUyMHN0ZXBzJTIwaXMlMjB0aGUlMjBudW1iZXIlMjBvZiUyMHNhbXBsZXMlMjBpbiUyMHRoZSUyMGRhdGFzZXQlMkMlMjBkaXZpZGVkJTIwYnklMjB0aGUlMjBiYXRjaCUyMHNpemUlMjB0aGVuJTIwbXVsdGlwbGllZCUwQSUyMyUyMGJ5JTIwdGhlJTIwdG90YWwlMjBudW1iZXIlMjBvZiUyMGVwb2Nocy4lMjBOb3RlJTIwdGhhdCUyMHRoZSUyMHRmX3RyYWluX2RhdGFzZXQlMjBoZXJlJTIwaXMlMjBhJTIwYmF0Y2hlZCUyMHRmLmRhdGEuRGF0YXNldCUyQyUwQSUyMyUyMG5vdCUyMHRoZSUyMG9yaWdpbmFsJTIwSHVnZ2luZyUyMEZhY2UlMjBEYXRhc2V0JTJDJTIwc28lMjBpdHMlMjBsZW4oKSUyMGlzJTIwYWxyZWFkeSUyMG51bV9zYW1wbGVzJTIwJTJGJTJGJTIwYmF0Y2hfc2l6ZS4lMEFudW1fdHJhaW5fc3RlcHMlMjAlM0QlMjBsZW4odGZfdHJhaW5fZGF0YXNldCklMjAqJTIwbnVtX2Vwb2NocyUwQWxyX3NjaGVkdWxlciUyMCUzRCUyMFBvbHlub21pYWxEZWNheSglMEElMjAlMjAlMjAlMjBpbml0aWFsX2xlYXJuaW5nX3JhdGUlM0Q1ZS01JTJDJTIwZW5kX2xlYXJuaW5nX3JhdGUlM0QwLjAlMkMlMjBkZWNheV9zdGVwcyUzRG51bV90cmFpbl9zdGVwcyUwQSklMEFmcm9tJTIwdGVuc29yZmxvdy5rZXJhcy5vcHRpbWl6ZXJzJTIwaW1wb3J0JTIwQWRhbSUwQSUwQW9wdCUyMCUzRCUyMEFkYW0obGVhcm5pbmdfcmF0ZSUzRGxyX3NjaGVkdWxlcik=",highlighted:`<span class="hljs-keyword">from</span> tensorflow.keras.optimizers.schedules <span class="hljs-keyword">import</span> PolynomialDecay

batch_size = <span class="hljs-number">8</span>
num_epochs = <span class="hljs-number">3</span>
<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_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_epochs
lr_scheduler = PolynomialDecay(
    initial_learning_rate=<span class="hljs-number">5e-5</span>, end_learning_rate=<span class="hljs-number">0.0</span>, decay_steps=num_train_steps
)
<span class="hljs-keyword">from</span> tensorflow.keras.optimizers <span class="hljs-keyword">import</span> Adam

opt = Adam(learning_rate=lr_scheduler)`,wrap:!1}}),j=new Ke({props:{$$slots:{default:[Rt]},$$scope:{ctx:b}}}),q=new $({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCUyQyUyMG51bV9sYWJlbHMlM0QyKSUwQWxvc3MlMjAlM0QlMjB0Zi5rZXJhcy5sb3NzZXMuU3BhcnNlQ2F0ZWdvcmljYWxDcm9zc2VudHJvcHkoZnJvbV9sb2dpdHMlM0RUcnVlKSUwQW1vZGVsLmNvbXBpbGUob3B0aW1pemVyJTNEb3B0JTJDJTIwbG9zcyUzRGxvc3MlMkMlMjBtZXRyaWNzJTNEJTVCJTIyYWNjdXJhY3klMjIlNUQp",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>)
model.<span class="hljs-built_in">compile</span>(optimizer=opt, loss=loss, metrics=[<span class="hljs-string">&quot;accuracy&quot;</span>])`,wrap:!1}}),L=new $({props:{code:"bW9kZWwuZml0KHRmX3RyYWluX2RhdGFzZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl92YWxpZGF0aW9uX2RhdGFzZXQlMkMlMjBlcG9jaHMlM0QzKQ==",highlighted:'model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=<span class="hljs-number">3</span>)',wrap:!1}}),U=new Ke({props:{$$slots:{default:[Xt]},$$scope:{ctx:b}}}),P=new Oe({props:{title:"Model predictions",local:"model-predictions",headingTag:"h3"}}),K=new De({props:{id:"nx10eh4CoOs"}}),O=new $({props:{code:"cHJlZHMlMjAlM0QlMjBtb2RlbC5wcmVkaWN0KHRmX3ZhbGlkYXRpb25fZGF0YXNldCklNUIlMjJsb2dpdHMlMjIlNUQ=",highlighted:'preds = model.predict(tf_validation_dataset)[<span class="hljs-string">&quot;logits&quot;</span>]',wrap:!1}}),te=new $({props:{code:"Y2xhc3NfcHJlZHMlMjAlM0QlMjBucC5hcmdtYXgocHJlZHMlMkMlMjBheGlzJTNEMSklMEFwcmludChwcmVkcy5zaGFwZSUyQyUyMGNsYXNzX3ByZWRzLnNoYXBlKQ==",highlighted:`class_preds = np.argmax(preds, axis=<span class="hljs-number">1</span>)
<span class="hljs-built_in">print</span>(preds.shape, class_preds.shape)`,wrap:!1}}),se=new $({props:{code:"KDQwOCUyQyUyMDIpJTIwKDQwOCUyQyk=",highlighted:'(<span class="hljs-number">408</span>, <span class="hljs-number">2</span>) (<span class="hljs-number">408</span>,)',wrap:!1}}),le=new $({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmdsdWUlMjIlMkMlMjAlMjJtcnBjJTIyKSUwQW1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEY2xhc3NfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEcmF3X2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCU1QiUyMmxhYmVsJTIyJTVEKQ==",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
metric.compute(predictions=class_preds, references=raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-string">&quot;label&quot;</span>])`,wrap:!1}}),ne=new $({props:{code:"JTdCJ2FjY3VyYWN5JyUzQSUyMDAuODU3ODQzMTM3MjU0OTAxOSUyQyUyMCdmMSclM0ElMjAwLjg5OTY1Mzk3OTIzODc1NDIlN0Q=",highlighted:'{<span class="hljs-string">&#x27;accuracy&#x27;</span>: <span class="hljs-number">0.8578431372549019</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.8996539792387542</span>}',wrap:!1}}),{c(){i=u("meta"),y=l(),o=u("p"),M=l(),r(T.$$.fragment),pe=l(),r(G.$$.fragment),me=l(),r(Z.$$.fragment),he=l(),v=u("p"),v.innerHTML=tt,ce=l(),k=u("p"),k.textContent=st,de=l(),r(_.$$.fragment),ue=l(),r(C.$$.fragment),fe=l(),I=u("p"),I.textContent=at,we=l(),r(W.$$.fragment),ye=l(),R=u("p"),R.textContent=lt,Me=l(),r(X.$$.fragment),be=l(),z=u("p"),z.innerHTML=nt,$e=l(),r(F.$$.fragment),Te=l(),V=u("p"),V.innerHTML=it,Je=l(),H=u("p"),H.innerHTML=ot,ge=l(),r(J.$$.fragment),je=l(),r(Y.$$.fragment),Ue=l(),r(g.$$.fragment),Ge=l(),r(Q.$$.fragment),Ze=l(),r(B.$$.fragment),ve=l(),x=u("p"),x.innerHTML=rt,ke=l(),N=u("p"),N.innerHTML=pt,_e=l(),r(E.$$.fragment),Ce=l(),r(j.$$.fragment),Ie=l(),S=u("p"),S.textContent=mt,We=l(),r(q.$$.fragment),Re=l(),A=u("p"),A.textContent=ht,Xe=l(),r(L.$$.fragment),ze=l(),r(U.$$.fragment),Fe=l(),r(P.$$.fragment),Ve=l(),r(K.$$.fragment),He=l(),D=u("p"),D.innerHTML=ct,Ye=l(),r(O.$$.fragment),Qe=l(),ee=u("p"),ee.innerHTML=dt,Be=l(),r(te.$$.fragment),xe=l(),r(se.$$.fragment),Ne=l(),ae=u("p"),ae.innerHTML=ut,Ee=l(),r(le.$$.fragment),Se=l(),r(ne.$$.fragment),qe=l(),ie=u("p"),ie.innerHTML=ft,Ae=l(),oe=u("p"),oe.innerHTML=wt,Le=l(),re=u("p"),this.h()},l(e){const t=vt("svelte-u9bgzb",document.head);i=f(t,"META",{name:!0,content:!0}),t.forEach(s),y=n(e),o=f(e,"P",{}),Jt(o).forEach(s),M=n(e),p(T.$$.fragment,e),pe=n(e),p(G.$$.fragment,e),me=n(e),p(Z.$$.fragment,e),he=n(e),v=f(e,"P",{"data-svelte-h":!0}),w(v)!=="svelte-1r7nza7"&&(v.innerHTML=tt),ce=n(e),k=f(e,"P",{"data-svelte-h":!0}),w(k)!=="svelte-1r8y7hl"&&(k.textContent=st),de=n(e),p(_.$$.fragment,e),ue=n(e),p(C.$$.fragment,e),fe=n(e),I=f(e,"P",{"data-svelte-h":!0}),w(I)!=="svelte-1q5w70i"&&(I.textContent=at),we=n(e),p(W.$$.fragment,e),ye=n(e),R=f(e,"P",{"data-svelte-h":!0}),w(R)!=="svelte-8f7zap"&&(R.textContent=lt),Me=n(e),p(X.$$.fragment,e),be=n(e),z=f(e,"P",{"data-svelte-h":!0}),w(z)!=="svelte-5yuavp"&&(z.innerHTML=nt),$e=n(e),p(F.$$.fragment,e),Te=n(e),V=f(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-zny54p"&&(V.innerHTML=it),Je=n(e),H=f(e,"P",{"data-svelte-h":!0}),w(H)!=="svelte-yed56q"&&(H.innerHTML=ot),ge=n(e),p(J.$$.fragment,e),je=n(e),p(Y.$$.fragment,e),Ue=n(e),p(g.$$.fragment,e),Ge=n(e),p(Q.$$.fragment,e),Ze=n(e),p(B.$$.fragment,e),ve=n(e),x=f(e,"P",{"data-svelte-h":!0}),w(x)!=="svelte-kzgk6r"&&(x.innerHTML=rt),ke=n(e),N=f(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-116hdi5"&&(N.innerHTML=pt),_e=n(e),p(E.$$.fragment,e),Ce=n(e),p(j.$$.fragment,e),Ie=n(e),S=f(e,"P",{"data-svelte-h":!0}),w(S)!=="svelte-1ama0ws"&&(S.textContent=mt),We=n(e),p(q.$$.fragment,e),Re=n(e),A=f(e,"P",{"data-svelte-h":!0}),w(A)!=="svelte-1kj61ul"&&(A.textContent=ht),Xe=n(e),p(L.$$.fragment,e),ze=n(e),p(U.$$.fragment,e),Fe=n(e),p(P.$$.fragment,e),Ve=n(e),p(K.$$.fragment,e),He=n(e),D=f(e,"P",{"data-svelte-h":!0}),w(D)!=="svelte-blmlfo"&&(D.innerHTML=ct),Ye=n(e),p(O.$$.fragment,e),Qe=n(e),ee=f(e,"P",{"data-svelte-h":!0}),w(ee)!=="svelte-jglcdu"&&(ee.innerHTML=dt),Be=n(e),p(te.$$.fragment,e),xe=n(e),p(se.$$.fragment,e),Ne=n(e),ae=f(e,"P",{"data-svelte-h":!0}),w(ae)!=="svelte-1kf4jti"&&(ae.innerHTML=ut),Ee=n(e),p(le.$$.fragment,e),Se=n(e),p(ne.$$.fragment,e),qe=n(e),ie=f(e,"P",{"data-svelte-h":!0}),w(ie)!=="svelte-59ywn7"&&(ie.innerHTML=ft),Ae=n(e),oe=f(e,"P",{"data-svelte-h":!0}),w(oe)!=="svelte-vkvhid"&&(oe.innerHTML=wt),Le=n(e),re=f(e,"P",{}),Jt(re).forEach(s),this.h()},h(){gt(i,"name","hf:doc:metadata"),gt(i,"content",Ft)},m(e,t){kt(document.head,i),a(e,y,t),a(e,o,t),a(e,M,t),m(T,e,t),a(e,pe,t),m(G,e,t),a(e,me,t),m(Z,e,t),a(e,he,t),a(e,v,t),a(e,ce,t),a(e,k,t),a(e,de,t),m(_,e,t),a(e,ue,t),m(C,e,t),a(e,fe,t),a(e,I,t),a(e,we,t),m(W,e,t),a(e,ye,t),a(e,R,t),a(e,Me,t),m(X,e,t),a(e,be,t),a(e,z,t),a(e,$e,t),m(F,e,t),a(e,Te,t),a(e,V,t),a(e,Je,t),a(e,H,t),a(e,ge,t),m(J,e,t),a(e,je,t),m(Y,e,t),a(e,Ue,t),m(g,e,t),a(e,Ge,t),m(Q,e,t),a(e,Ze,t),m(B,e,t),a(e,ve,t),a(e,x,t),a(e,ke,t),a(e,N,t),a(e,_e,t),m(E,e,t),a(e,Ce,t),m(j,e,t),a(e,Ie,t),a(e,S,t),a(e,We,t),m(q,e,t),a(e,Re,t),a(e,A,t),a(e,Xe,t),m(L,e,t),a(e,ze,t),m(U,e,t),a(e,Fe,t),m(P,e,t),a(e,Ve,t),m(K,e,t),a(e,He,t),a(e,D,t),a(e,Ye,t),m(O,e,t),a(e,Qe,t),a(e,ee,t),a(e,Be,t),m(te,e,t),a(e,xe,t),m(se,e,t),a(e,Ne,t),a(e,ae,t),a(e,Ee,t),m(le,e,t),a(e,Se,t),m(ne,e,t),a(e,qe,t),a(e,ie,t),a(e,Ae,t),a(e,oe,t),a(e,Le,t),a(e,re,t),Pe=!0},p(e,[t]){const yt={};t&1&&(yt.fw=e[0]),T.$set(yt);const Mt={};t&2&&(Mt.$$scope={dirty:t,ctx:e}),J.$set(Mt);const bt={};t&2&&(bt.$$scope={dirty:t,ctx:e}),g.$set(bt);const $t={};t&2&&($t.$$scope={dirty:t,ctx:e}),j.$set($t);const Tt={};t&2&&(Tt.$$scope={dirty:t,ctx:e}),U.$set(Tt)},i(e){Pe||(h(T.$$.fragment,e),h(G.$$.fragment,e),h(Z.$$.fragment,e),h(_.$$.fragment,e),h(C.$$.fragment,e),h(W.$$.fragment,e),h(X.$$.fragment,e),h(F.$$.fragment,e),h(J.$$.fragment,e),h(Y.$$.fragment,e),h(g.$$.fragment,e),h(Q.$$.fragment,e),h(B.$$.fragment,e),h(E.$$.fragment,e),h(j.$$.fragment,e),h(q.$$.fragment,e),h(L.$$.fragment,e),h(U.$$.fragment,e),h(P.$$.fragment,e),h(K.$$.fragment,e),h(O.$$.fragment,e),h(te.$$.fragment,e),h(se.$$.fragment,e),h(le.$$.fragment,e),h(ne.$$.fragment,e),Pe=!0)},o(e){c(T.$$.fragment,e),c(G.$$.fragment,e),c(Z.$$.fragment,e),c(_.$$.fragment,e),c(C.$$.fragment,e),c(W.$$.fragment,e),c(X.$$.fragment,e),c(F.$$.fragment,e),c(J.$$.fragment,e),c(Y.$$.fragment,e),c(g.$$.fragment,e),c(Q.$$.fragment,e),c(B.$$.fragment,e),c(E.$$.fragment,e),c(j.$$.fragment,e),c(q.$$.fragment,e),c(L.$$.fragment,e),c(U.$$.fragment,e),c(P.$$.fragment,e),c(K.$$.fragment,e),c(O.$$.fragment,e),c(te.$$.fragment,e),c(se.$$.fragment,e),c(le.$$.fragment,e),c(ne.$$.fragment,e),Pe=!1},d(e){e&&(s(y),s(o),s(M),s(pe),s(me),s(he),s(v),s(ce),s(k),s(de),s(ue),s(fe),s(I),s(we),s(ye),s(R),s(Me),s(be),s(z),s($e),s(Te),s(V),s(Je),s(H),s(ge),s(je),s(Ue),s(Ge),s(Ze),s(ve),s(x),s(ke),s(N),s(_e),s(Ce),s(Ie),s(S),s(We),s(Re),s(A),s(Xe),s(ze),s(Fe),s(Ve),s(He),s(D),s(Ye),s(Qe),s(ee),s(Be),s(xe),s(Ne),s(ae),s(Ee),s(Se),s(qe),s(ie),s(Ae),s(oe),s(Le),s(re)),s(i),d(T,e),d(G,e),d(Z,e),d(_,e),d(C,e),d(W,e),d(X,e),d(F,e),d(J,e),d(Y,e),d(g,e),d(Q,e),d(B,e),d(E,e),d(j,e),d(q,e),d(L,e),d(U,e),d(P,e),d(K,e),d(O,e),d(te,e),d(se,e),d(le,e),d(ne,e)}}}const Ft='{"title":"Fine-tuning a model with Keras","local":"fine-tuning-a-model-with-keras","sections":[{"title":"Training","local":"training","sections":[],"depth":3},{"title":"Improving training performance","local":"improving-training-performance","sections":[],"depth":3},{"title":"Model predictions","local":"model-predictions","sections":[],"depth":3}],"depth":1}';function Vt(b,i,y){let o="pt";return Ut(()=>{const M=new URLSearchParams(window.location.search);y(0,o=M.get("fw")||"pt")}),[o]}class qt extends Gt{constructor(i){super(),Zt(this,i,Vt,zt,jt,{})}}export{qt as component};
