Buckets:

rtrm's picture
download
raw
180 kB
import{s as XM,a as RM,o as vM}from"../chunks/scheduler.893fe8c9.js";import{S as $M,i as NM,e as c,s as a,c as J,q as Vs,H as QM,h as FM,a as d,d as l,b as n,f as Sn,g as u,j as w,r as Xs,u as EM,k as K,l as Ke,m as s,n as m,o as y,E as $e,t as r,p as U,F as Ne}from"../chunks/index.b1df2166.js";import{C as YM,H as le,E as zM}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.181aea60.js";import{Y as qn}from"../chunks/Youtube.ec5d7916.js";import{C as j}from"../chunks/CodeBlock.6097a3d8.js";import{C as AM}from"../chunks/CourseFloatingBanner.c1c08878.js";import{F as HM}from"../chunks/FrameworkSwitchCourse.4480e339.js";function SM(k){let i,T;return i=new AM({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/section7_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section7_tf.ipynb"}]}}),{c(){J(i.$$.fragment)},l(p){u(i.$$.fragment,p)},m(p,h){m(i,p,h),T=!0},i(p){T||(r(i.$$.fragment,p),T=!0)},o(p){y(i.$$.fragment,p),T=!1},d(p){U(i,p)}}}function qM(k){let i,T;return i=new AM({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/section7_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section7_pt.ipynb"}]}}),{c(){J(i.$$.fragment)},l(p){u(i.$$.fragment,p)},m(p,h){m(i,p,h),T=!0},i(p){T||(r(i.$$.fragment,p),T=!0)},o(p){y(i.$$.fragment,p),T=!1},d(p){U(i,p)}}}function LM(k){let i,T,p,h="The training code for this example will look a lot like the code in the previous sections, but computing the metrics will be uniquely challenging. Since we padded all the samples to the maximum length we set, there is no data collator to define, so this metric computation is really the only thing we have to worry about. The hard part will be to post-process the model predictions into spans of text in the original examples; once we have done that, the metric from the 🤗 Datasets library will do most of the work for us.",b;return i=new le({props:{title:"Fine-tuning the model with Keras",local:"fine-tuning-the-model-with-keras",headingTag:"h2"}}),{c(){J(i.$$.fragment),T=a(),p=c("p"),p.textContent=h},l(o){u(i.$$.fragment,o),T=n(o),p=d(o,"P",{"data-svelte-h":!0}),w(p)!=="svelte-gueww0"&&(p.textContent=h)},m(o,I){m(i,o,I),s(o,T,I),s(o,p,I),b=!0},i(o){b||(r(i.$$.fragment,o),b=!0)},o(o){y(i.$$.fragment,o),b=!1},d(o){o&&(l(T),l(p)),U(i,o)}}}function DM(k){let i,T,p,h="The training code for this example will look a lot like the code in the previous sections — the hardest thing will be to write the <code>compute_metrics()</code> function. Since we padded all the samples to the maximum length we set, there is no data collator to define, so this metric computation is really the only thing we have to worry about. The difficult part will be to post-process the model predictions into spans of text in the original examples; once we have done that, the metric from the 🤗 Datasets library will do most of the work for us.",b;return i=new le({props:{title:"Fine-tuning the model with the Trainer API",local:"fine-tuning-the-model-with-the-trainer-api",headingTag:"h2"}}),{c(){J(i.$$.fragment),T=a(),p=c("p"),p.innerHTML=h},l(o){u(i.$$.fragment,o),T=n(o),p=d(o,"P",{"data-svelte-h":!0}),w(p)!=="svelte-1rpla2e"&&(p.innerHTML=h)},m(o,I){m(i,o,I),s(o,T,I),s(o,p,I),b=!0},i(o){b||(r(i.$$.fragment,o),b=!0)},o(o){y(i.$$.fragment,o),b=!1},d(o){o&&(l(T),l(p)),U(i,o)}}}function KM(k){let i,T;return i=new qn({props:{id:"VN67ZpN33Ss"}}),{c(){J(i.$$.fragment)},l(p){u(i.$$.fragment,p)},m(p,h){m(i,p,h),T=!0},i(p){T||(r(i.$$.fragment,p),T=!0)},o(p){y(i.$$.fragment,p),T=!1},d(p){U(i,p)}}}function PM(k){let i,T;return i=new qn({props:{id:"BNy08iIWVJM"}}),{c(){J(i.$$.fragment)},l(p){u(i.$$.fragment,p)},m(p,h){m(i,p,h),T=!0},i(p){T||(r(i.$$.fragment,p),T=!0)},o(p){y(i.$$.fragment,p),T=!1},d(p){U(i,p)}}}function OM(k){let i,T,p,h="For ease of experimentation, let’s convert these outputs to NumPy arrays:",b,o,I;return i=new j({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwVEZBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZyUwQSUwQWV2YWxfc2V0X2Zvcl9tb2RlbCUyMCUzRCUyMGV2YWxfc2V0LnJlbW92ZV9jb2x1bW5zKCU1QiUyMmV4YW1wbGVfaWQlMjIlMkMlMjAlMjJvZmZzZXRfbWFwcGluZyUyMiU1RCklMEFldmFsX3NldF9mb3JfbW9kZWwuc2V0X2Zvcm1hdCglMjJudW1weSUyMiklMEElMEFiYXRjaCUyMCUzRCUyMCU3QmslM0ElMjBldmFsX3NldF9mb3JfbW9kZWwlNUJrJTVEJTIwZm9yJTIwayUyMGluJTIwZXZhbF9zZXRfZm9yX21vZGVsLmNvbHVtbl9uYW1lcyU3RCUwQXRyYWluZWRfbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nLmZyb21fcHJldHJhaW5lZCh0cmFpbmVkX2NoZWNrcG9pbnQpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMHRyYWluZWRfbW9kZWwoKipiYXRjaCk=",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForQuestionAnswering
eval_set_for_model = eval_set.remove_columns([<span class="hljs-string">&quot;example_id&quot;</span>, <span class="hljs-string">&quot;offset_mapping&quot;</span>])
eval_set_for_model.set_format(<span class="hljs-string">&quot;numpy&quot;</span>)
batch = {k: eval_set_for_model[k] <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> eval_set_for_model.column_names}
trained_model = TFAutoModelForQuestionAnswering.from_pretrained(trained_checkpoint)
outputs = trained_model(**batch)`,wrap:!1}}),o=new j({props:{code:"c3RhcnRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMubnVtcHkoKSUwQWVuZF9sb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmVuZF9sb2dpdHMubnVtcHkoKQ==",highlighted:`start_logits = outputs.start_logits.numpy()
end_logits = outputs.end_logits.numpy()`,wrap:!1}}),{c(){J(i.$$.fragment),T=a(),p=c("p"),p.textContent=h,b=a(),J(o.$$.fragment)},l(f){u(i.$$.fragment,f),T=n(f),p=d(f,"P",{"data-svelte-h":!0}),w(p)!=="svelte-178m4az"&&(p.textContent=h),b=n(f),u(o.$$.fragment,f)},m(f,C){m(i,f,C),s(f,T,C),s(f,p,C),s(f,b,C),m(o,f,C),I=!0},i(f){I||(r(i.$$.fragment,f),r(o.$$.fragment,f),I=!0)},o(f){y(i.$$.fragment,f),y(o.$$.fragment,f),I=!1},d(f){f&&(l(T),l(p),l(b)),U(i,f),U(o,f)}}}function eo(k){let i,T,p,h="Since the <code>Trainer</code> will give us predictions as NumPy arrays, we grab the start and end logits and convert them to that format:",b,o,I;return i=new j({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmclMEElMEFldmFsX3NldF9mb3JfbW9kZWwlMjAlM0QlMjBldmFsX3NldC5yZW1vdmVfY29sdW1ucyglNUIlMjJleGFtcGxlX2lkJTIyJTJDJTIwJTIyb2Zmc2V0X21hcHBpbmclMjIlNUQpJTBBZXZhbF9zZXRfZm9yX21vZGVsLnNldF9mb3JtYXQoJTIydG9yY2glMjIpJTBBJTBBZGV2aWNlJTIwJTNEJTIwdG9yY2guZGV2aWNlKCUyMmN1ZGElMjIpJTIwaWYlMjB0b3JjaC5jdWRhLmlzX2F2YWlsYWJsZSgpJTIwZWxzZSUyMHRvcmNoLmRldmljZSglMjJjcHUlMjIpJTBBYmF0Y2glMjAlM0QlMjAlN0JrJTNBJTIwZXZhbF9zZXRfZm9yX21vZGVsJTVCayU1RC50byhkZXZpY2UpJTIwZm9yJTIwayUyMGluJTIwZXZhbF9zZXRfZm9yX21vZGVsLmNvbHVtbl9uYW1lcyU3RCUwQXRyYWluZWRfbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQodHJhaW5lZF9jaGVja3BvaW50KS50byglMEElMjAlMjAlMjAlMjBkZXZpY2UlMEEpJTBBJTBBd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjB0cmFpbmVkX21vZGVsKCoqYmF0Y2gp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForQuestionAnswering
eval_set_for_model = eval_set.remove_columns([<span class="hljs-string">&quot;example_id&quot;</span>, <span class="hljs-string">&quot;offset_mapping&quot;</span>])
eval_set_for_model.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
batch = {k: eval_set_for_model[k].to(device) <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> eval_set_for_model.column_names}
trained_model = AutoModelForQuestionAnswering.from_pretrained(trained_checkpoint).to(
device
)
<span class="hljs-keyword">with</span> torch.no_grad():
outputs = trained_model(**batch)`,wrap:!1}}),o=new j({props:{code:"c3RhcnRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMuY3B1KCkubnVtcHkoKSUwQWVuZF9sb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmVuZF9sb2dpdHMuY3B1KCkubnVtcHkoKQ==",highlighted:`start_logits = outputs.start_logits.cpu().numpy()
end_logits = outputs.end_logits.cpu().numpy()`,wrap:!1}}),{c(){J(i.$$.fragment),T=a(),p=c("p"),p.innerHTML=h,b=a(),J(o.$$.fragment)},l(f){u(i.$$.fragment,f),T=n(f),p=d(f,"P",{"data-svelte-h":!0}),w(p)!=="svelte-1lo12mn"&&(p.innerHTML=h),b=n(f),u(o.$$.fragment,f)},m(f,C){m(i,f,C),s(f,T,C),s(f,p,C),s(f,b,C),m(o,f,C),I=!0},i(f){I||(r(i.$$.fragment,f),r(o.$$.fragment,f),I=!0)},o(f){y(i.$$.fragment,f),y(o.$$.fragment,f),I=!1},d(f){f&&(l(T),l(p),l(b)),U(i,f),U(o,f)}}}function lo(k){let i,T="Now let’s put everything we just did in a <code>compute_metrics()</code> function that we will use after training our model. We will need to pass a bit more than just the output logits, as we have to look in the dataset of features for the offset and in the dataset of examples for the original contexts:";return{c(){i=c("p"),i.innerHTML=T},l(p){i=d(p,"P",{"data-svelte-h":!0}),w(i)!=="svelte-bg7g1n"&&(i.innerHTML=T)},m(p,h){s(p,i,h)},d(p){p&&l(i)}}}function to(k){let i,T="Now let’s put everything we just did in a <code>compute_metrics()</code> function that we will use in the <code>Trainer</code>. Normally, that <code>compute_metrics()</code> function only receives a tuple <code>eval_preds</code> with logits and labels. Here we will need a bit more, as we have to look in the dataset of features for the offset and in the dataset of examples for the original contexts, so we won’t be able to use this function to get regular evaluation results during training. We will only use it at the end of training to check the results.",p,h,b="The <code>compute_metrics()</code> function groups the same steps as before; we just add a small check in case we don’t come up with any valid answers (in which case we predict an empty string).";return{c(){i=c("p"),i.innerHTML=T,p=a(),h=c("p"),h.innerHTML=b},l(o){i=d(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-zb7cy8"&&(i.innerHTML=T),p=n(o),h=d(o,"P",{"data-svelte-h":!0}),w(h)!=="svelte-neutnz"&&(h.innerHTML=b)},m(o,I){s(o,i,I),s(o,p,I),s(o,h,I)},d(o){o&&(l(i),l(p),l(h))}}}function so(k){let i,T="We are now ready to train our model. Let’s create it first, using the <code>TFAutoModelForQuestionAnswering</code> class like before:",p,h,b;return h=new j({props:{code:"bW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:"model = TFAutoModelForQuestionAnswering.from_pretrained(model_checkpoint)",wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),J(h.$$.fragment)},l(o){i=d(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-ps4v2s"&&(i.innerHTML=T),p=n(o),u(h.$$.fragment,o)},m(o,I){s(o,i,I),s(o,p,I),m(h,o,I),b=!0},i(o){b||(r(h.$$.fragment,o),b=!0)},o(o){y(h.$$.fragment,o),b=!1},d(o){o&&(l(i),l(p)),U(h,o)}}}function ao(k){let i,T="We are now ready to train our model. Let’s create it first, using the <code>AutoModelForQuestionAnswering</code> class like before:",p,h,b;return h=new j({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:"model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)",wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),J(h.$$.fragment)},l(o){i=d(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-10p5xx2"&&(i.innerHTML=T),p=n(o),u(h.$$.fragment,o)},m(o,I){s(o,i,I),s(o,p,I),m(h,o,I),b=!0},i(o){b||(r(h.$$.fragment,o),b=!0)},o(o){y(h.$$.fragment,o),b=!1},d(o){o&&(l(i),l(p)),U(h,o)}}}function no(k){let i,T="Now that’s done, we can create our TF Datasets. We can use the simple default data collator this time:",p,h,b,o,I="And now we create the datasets as usual.",f,C,_,x,A="Next, we set up our training hyperparameters and compile our model:",V,Z,B,W,P="Finally, we’re ready to train with <code>model.fit()</code>. We use a <code>PushToHubCallback</code> to upload the model to the Hub after each epoch.",L;return h=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcihyZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator
data_collator = DefaultDataCollator(return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`,wrap:!1}}),C=new j({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxNiUyQyUwQSklMEF0Zl9ldmFsX2RhdGFzZXQlMjAlM0QlMjBtb2RlbC5wcmVwYXJlX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwdmFsaWRhdGlvbl9kYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEEp",highlighted:`tf_train_dataset = model.prepare_tf_dataset(
train_dataset,
collate_fn=data_collator,
shuffle=<span class="hljs-literal">True</span>,
batch_size=<span class="hljs-number">16</span>,
)
tf_eval_dataset = model.prepare_tf_dataset(
validation_dataset,
collate_fn=data_collator,
shuffle=<span class="hljs-literal">False</span>,
batch_size=<span class="hljs-number">16</span>,
)`,wrap:!1}}),Z=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmtlcmFzX2NhbGxiYWNrcyUyMGltcG9ydCUyMFB1c2hUb0h1YkNhbGxiYWNrJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEElMjMlMjBUaGUlMjBudW1iZXIlMjBvZiUyMHRyYWluaW5nJTIwc3RlcHMlMjBpcyUyMHRoZSUyMG51bWJlciUyMG9mJTIwc2FtcGxlcyUyMGluJTIwdGhlJTIwZGF0YXNldCUyQyUyMGRpdmlkZWQlMjBieSUyMHRoZSUyMGJhdGNoJTIwc2l6ZSUyMHRoZW4lMjBtdWx0aXBsaWVkJTBBJTIzJTIwYnklMjB0aGUlMjB0b3RhbCUyMG51bWJlciUyMG9mJTIwZXBvY2hzLiUyME5vdGUlMjB0aGF0JTIwdGhlJTIwdGZfdHJhaW5fZGF0YXNldCUyMGhlcmUlMjBpcyUyMGElMjBiYXRjaGVkJTIwdGYuZGF0YS5EYXRhc2V0JTJDJTBBJTIzJTIwbm90JTIwdGhlJTIwb3JpZ2luYWwlMjBIdWdnaW5nJTIwRmFjZSUyMERhdGFzZXQlMkMlMjBzbyUyMGl0cyUyMGxlbigpJTIwaXMlMjBhbHJlYWR5JTIwbnVtX3NhbXBsZXMlMjAlMkYlMkYlMjBiYXRjaF9zaXplLiUwQW51bV90cmFpbl9lcG9jaHMlMjAlM0QlMjAzJTBBbnVtX3RyYWluX3N0ZXBzJTIwJTNEJTIwbGVuKHRmX3RyYWluX2RhdGFzZXQpJTIwKiUyMG51bV90cmFpbl9lcG9jaHMlMEFvcHRpbWl6ZXIlMkMlMjBzY2hlZHVsZSUyMCUzRCUyMGNyZWF0ZV9vcHRpbWl6ZXIoJTBBJTIwJTIwJTIwJTIwaW5pdF9sciUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fd2FybXVwX3N0ZXBzJTNEMCUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9zdGVwcyUzRG51bV90cmFpbl9zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheV9yYXRlJTNEMC4wMSUyQyUwQSklMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplciklMEElMEElMjMlMjBUcmFpbiUyMGluJTIwbWl4ZWQtcHJlY2lzaW9uJTIwZmxvYXQxNiUwQXRmLmtlcmFzLm1peGVkX3ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKQ==",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_train_epochs = <span class="hljs-number">3</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_train_epochs
optimizer, schedule = create_optimizer(
init_lr=<span class="hljs-number">2e-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}}),{c(){i=c("p"),i.textContent=T,p=a(),J(h.$$.fragment),b=a(),o=c("p"),o.textContent=I,f=a(),J(C.$$.fragment),_=a(),x=c("p"),x.textContent=A,V=a(),J(Z.$$.fragment),B=a(),W=c("p"),W.innerHTML=P},l(G){i=d(G,"P",{"data-svelte-h":!0}),w(i)!=="svelte-7ck7e8"&&(i.textContent=T),p=n(G),u(h.$$.fragment,G),b=n(G),o=d(G,"P",{"data-svelte-h":!0}),w(o)!=="svelte-1itb8ap"&&(o.textContent=I),f=n(G),u(C.$$.fragment,G),_=n(G),x=d(G,"P",{"data-svelte-h":!0}),w(x)!=="svelte-zibbtf"&&(x.textContent=A),V=n(G),u(Z.$$.fragment,G),B=n(G),W=d(G,"P",{"data-svelte-h":!0}),w(W)!=="svelte-10m358g"&&(W.innerHTML=P)},m(G,X){s(G,i,X),s(G,p,X),m(h,G,X),s(G,b,X),s(G,o,X),s(G,f,X),m(C,G,X),s(G,_,X),s(G,x,X),s(G,V,X),m(Z,G,X),s(G,B,X),s(G,W,X),L=!0},i(G){L||(r(h.$$.fragment,G),r(C.$$.fragment,G),r(Z.$$.fragment,G),L=!0)},o(G){y(h.$$.fragment,G),y(C.$$.fragment,G),y(Z.$$.fragment,G),L=!1},d(G){G&&(l(i),l(p),l(b),l(o),l(f),l(_),l(x),l(V),l(B),l(W)),U(h,G),U(C,G),U(Z,G)}}}function io(k){let i,T='Once this is done, we can define our <code>TrainingArguments</code>. As we said when we defined our function to compute the metric, we won’t be able to have a regular evaluation loop because of the signature of the <code>compute_metrics()</code> function. We could write our own subclass of <code>Trainer</code> to do this (an approach you can find in the <a href="https://github.com/huggingface/transformers/blob/master/examples/pytorch/question-answering/trainer_qa.py" rel="nofollow">question answering example script</a>), but that’s a bit too long for this section. Instead, we will only evaluate the model at the end of training here and show you how to do a regular evaluation in “A custom training loop” below.',p,h,b="This is really where the <code>Trainer</code> API shows its limits and the 🤗 Accelerate library shines: customizing the class to a specific use case can be painful, but tweaking a fully exposed training loop is easy.",o,I,f="Let’s take a look at our <code>TrainingArguments</code>:",C,_,x,A,V="We’ve seen most of these before: we set some hyperparameters (like the learning rate, the number of epochs we train for, and some weight decay) and indicate that we want to save the model at the end of every epoch, skip evaluation, and upload our results to the Model Hub. We also enable mixed-precision training with <code>fp16=True</code>, as it can speed up the training nicely on a recent GPU.",Z;return _=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMCUyMmJlcnQtZmluZXR1bmVkLXNxdWFkJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMm5vJTIyJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEMyUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments
args = TrainingArguments(
<span class="hljs-string">&quot;bert-finetuned-squad&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>,
num_train_epochs=<span class="hljs-number">3</span>,
weight_decay=<span class="hljs-number">0.01</span>,
fp16=<span class="hljs-literal">True</span>,
push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),h=c("p"),h.innerHTML=b,o=a(),I=c("p"),I.innerHTML=f,C=a(),J(_.$$.fragment),x=a(),A=c("p"),A.innerHTML=V},l(B){i=d(B,"P",{"data-svelte-h":!0}),w(i)!=="svelte-mwaaj2"&&(i.innerHTML=T),p=n(B),h=d(B,"P",{"data-svelte-h":!0}),w(h)!=="svelte-e7i2j4"&&(h.innerHTML=b),o=n(B),I=d(B,"P",{"data-svelte-h":!0}),w(I)!=="svelte-4gcf2c"&&(I.innerHTML=f),C=n(B),u(_.$$.fragment,B),x=n(B),A=d(B,"P",{"data-svelte-h":!0}),w(A)!=="svelte-1tqo63r"&&(A.innerHTML=V)},m(B,W){s(B,i,W),s(B,p,W),s(B,h,W),s(B,o,W),s(B,I,W),s(B,C,W),m(_,B,W),s(B,x,W),s(B,A,W),Z=!0},i(B){Z||(r(_.$$.fragment,B),Z=!0)},o(B){y(_.$$.fragment,B),Z=!1},d(B){B&&(l(i),l(p),l(h),l(o),l(I),l(C),l(x),l(A)),U(_,B)}}}function Mo(k){let i,T;return i=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2sob3V0cHV0X2RpciUzRCUyMmJlcnQtZmluZXR1bmVkLXNxdWFkJTIyJTJDJTIwdG9rZW5pemVyJTNEdG9rZW5pemVyKSUwQSUwQSUyMyUyMFdlJ3JlJTIwZ29pbmclMjB0byUyMGRvJTIwdmFsaWRhdGlvbiUyMGFmdGVyd2FyZHMlMkMlMjBzbyUyMG5vJTIwdmFsaWRhdGlvbiUyMG1pZC10cmFpbmluZyUwQW1vZGVsLmZpdCh0Zl90cmFpbl9kYXRhc2V0JTJDJTIwY2FsbGJhY2tzJTNEJTVCY2FsbGJhY2slNUQlMkMlMjBlcG9jaHMlM0RudW1fdHJhaW5fZXBvY2hzKQ==",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;bert-finetuned-squad&quot;</span>, tokenizer=tokenizer)
<span class="hljs-comment"># We&#x27;re going to do validation afterwards, so no validation mid-training</span>
model.fit(tf_train_dataset, callbacks=[callback], epochs=num_train_epochs)`,wrap:!1}}),{c(){J(i.$$.fragment)},l(p){u(i.$$.fragment,p)},m(p,h){m(i,p,h),T=!0},i(p){T||(r(i.$$.fragment,p),T=!0)},o(p){y(i.$$.fragment,p),T=!1},d(p){U(i,p)}}}function oo(k){let i,T="<p>💡 If the output directory you are using exists, it needs to be a local clone of the repository you want to push to (so set a new name if you get an error when defining your <code>Trainer</code>).</p>",p,h,b="Finally, we just pass everything to the <code>Trainer</code> class and launch the training:",o,I,f;return I=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHZhbGlkYXRpb25fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSklMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer
trainer = Trainer(
model=model,
args=args,
train_dataset=train_dataset,
eval_dataset=validation_dataset,
tokenizer=tokenizer,
)
trainer.train()`,wrap:!1}}),{c(){i=c("blockquote"),i.innerHTML=T,p=a(),h=c("p"),h.innerHTML=b,o=a(),J(I.$$.fragment),this.h()},l(C){i=d(C,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(i)!=="svelte-19pfhm5"&&(i.innerHTML=T),p=n(C),h=d(C,"P",{"data-svelte-h":!0}),w(h)!=="svelte-1khq6u6"&&(h.innerHTML=b),o=n(C),u(I.$$.fragment,C),this.h()},h(){K(i,"class","tip")},m(C,_){s(C,i,_),s(C,p,_),s(C,h,_),s(C,o,_),m(I,C,_),f=!0},i(C){f||(r(I.$$.fragment,C),f=!0)},o(C){y(I.$$.fragment,C),f=!1},d(C){C&&(l(i),l(p),l(h),l(o)),U(I,C)}}}function po(k){let i,T="Once the training is complete, we can finally evaluate our model (and pray we didn’t spend all that compute time on nothing). The <code>predict()</code> method of our <code>model</code> will take care of getting predictions, and since we did all the hard work of defining a <code>compute_metrics()</code> function earlier, we can get our results in a single line:",p,h,b;return h=new j({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjBtb2RlbC5wcmVkaWN0KHRmX2V2YWxfZGF0YXNldCklMEFjb21wdXRlX21ldHJpY3MoJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlNUIlMjJzdGFydF9sb2dpdHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyU1QiUyMmVuZF9sb2dpdHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjByYXdfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTBBKQ==",highlighted:`predictions = model.predict(tf_eval_dataset)
compute_metrics(
predictions[<span class="hljs-string">&quot;start_logits&quot;</span>],
predictions[<span class="hljs-string">&quot;end_logits&quot;</span>],
validation_dataset,
raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
)`,wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),J(h.$$.fragment)},l(o){i=d(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-1f0u5cw"&&(i.innerHTML=T),p=n(o),u(h.$$.fragment,o)},m(o,I){s(o,i,I),s(o,p,I),m(h,o,I),b=!0},i(o){b||(r(h.$$.fragment,o),b=!0)},o(o){y(h.$$.fragment,o),b=!1},d(o){o&&(l(i),l(p)),U(h,o)}}}function ro(k){let i,T="Once the training is complete, we can finally evaluate our model (and pray we didn’t spend all that compute time on nothing). The <code>predict()</code> method of the <code>Trainer</code> will return a tuple where the first elements will be the predictions of the model (here a pair with the start and end logits). We send this to our <code>compute_metrics()</code> function:",p,h,b;return h=new j({props:{code:"cHJlZGljdGlvbnMlMkMlMjBfJTJDJTIwXyUyMCUzRCUyMHRyYWluZXIucHJlZGljdCh2YWxpZGF0aW9uX2RhdGFzZXQpJTBBc3RhcnRfbG9naXRzJTJDJTIwZW5kX2xvZ2l0cyUyMCUzRCUyMHByZWRpY3Rpb25zJTBBY29tcHV0ZV9tZXRyaWNzKHN0YXJ0X2xvZ2l0cyUyQyUyMGVuZF9sb2dpdHMlMkMlMjB2YWxpZGF0aW9uX2RhdGFzZXQlMkMlMjByYXdfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEKQ==",highlighted:`predictions, _, _ = trainer.predict(validation_dataset)
start_logits, end_logits = predictions
compute_metrics(start_logits, end_logits, validation_dataset, raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>])`,wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),J(h.$$.fragment)},l(o){i=d(o,"P",{"data-svelte-h":!0}),w(i)!=="svelte-x87std"&&(i.innerHTML=T),p=n(o),u(h.$$.fragment,o)},m(o,I){s(o,i,I),s(o,p,I),m(h,o,I),b=!0},i(o){b||(r(h.$$.fragment,o),b=!0)},o(o){y(h.$$.fragment,o),b=!1},d(o){o&&(l(i),l(p)),U(h,o)}}}function _M(k){let i,T="Finally, we use the <code>push_to_hub()</code> method to make sure we upload the latest version of the model:",p,h,b,o,I="This returns the URL of the commit it just did, if you want to inspect it:",f,C,_,x,A="The <code>Trainer</code> also drafts a model card with all the evaluation results and uploads it.",V;return h=new j({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),C=new j({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtc3F1YWQlMkZjb21taXQlMkY5ZGNlZTFmYmMyNTk0NmE2ZWQ0YmIzMmVmYjFiZDcxZDVmYTkwYjY4Jw==",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-squad/commit/9dcee1fbc25946a6ed4bb32efb1bd71d5fa90b68&#x27;</span>',wrap:!1}}),{c(){i=c("p"),i.innerHTML=T,p=a(),J(h.$$.fragment),b=a(),o=c("p"),o.textContent=I,f=a(),J(C.$$.fragment),_=a(),x=c("p"),x.innerHTML=A},l(Z){i=d(Z,"P",{"data-svelte-h":!0}),w(i)!=="svelte-1gzri3s"&&(i.innerHTML=T),p=n(Z),u(h.$$.fragment,Z),b=n(Z),o=d(Z,"P",{"data-svelte-h":!0}),w(o)!=="svelte-c2usbc"&&(o.textContent=I),f=n(Z),u(C.$$.fragment,Z),_=n(Z),x=d(Z,"P",{"data-svelte-h":!0}),w(x)!=="svelte-m4z0gi"&&(x.innerHTML=A)},m(Z,B){s(Z,i,B),s(Z,p,B),m(h,Z,B),s(Z,b,B),s(Z,o,B),s(Z,f,B),m(C,Z,B),s(Z,_,B),s(Z,x,B),V=!0},i(Z){V||(r(h.$$.fragment,Z),r(C.$$.fragment,Z),V=!0)},o(Z){y(h.$$.fragment,Z),y(C.$$.fragment,Z),V=!1},d(Z){Z&&(l(i),l(p),l(b),l(o),l(f),l(_),l(x)),U(h,Z),U(C,Z)}}}function WM(k){let i,T="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.",p,h,b,o,I='Let’s now have a look at the full training loop, so you can easily customize the parts you need. It will look a lot like the training loop in <a href="/course/chapter3/4">Chapter 3</a>, with the exception of the evaluation loop. We will be able to evaluate the model regularly since we’re not constrained by the <code>Trainer</code> class anymore.',f,C,_,x,A="First we need to build the <code>DataLoader</code>s from our datasets. We set the format of those datasets to <code>&quot;torch&quot;</code>, and remove the columns in the validation set that are not used by the model. Then, we can use the <code>default_data_collator</code> provided by Transformers as a <code>collate_fn</code> and shuffle the training set, but not the validation set:",V,Z,B,W,P="Next we reinstantiate our model, to make sure we’re not continuing the fine-tuning from before but starting from the BERT pretrained model again:",L,G,X,te,$="Then we will need an optimizer. As usual we use the classic <code>AdamW</code>, which is like Adam, but with a fix in the way weight decay is applied:",ll,se,ae,ke,tl="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>. We can force mixed-precision training by passing <code>fp16=True</code> to the <code>Accelerator</code> (or, if you are executing the code as a script, just make sure to fill in the 🤗 Accelerate <code>config</code> appropriately).",O,xe,Qe,N,sl="As you should know from the previous sections, we can only use the <code>train_dataloader</code> length to compute the number of training steps after it has gone through the <code>accelerator.prepare()</code> method. We use the same linear schedule as in the previous sections:",ne,_e,Fe,Q,al="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):",ie,We,Ee,F,Ye,E,Ws="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:",ze,Y,He,z,nl="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.",Me,Ae,Se,H,il="We are now ready to write the full training loop. After defining a progress bar to follow how training goes, the loop has three parts:",oe,pe,Ve="<li>The training in itself, which is the classic iteration over the <code>train_dataloader</code>, forward pass through the model, then backward pass and optimizer step.</li> <li>The evaluation, in which we gather all the values for <code>start_logits</code> and <code>end_logits</code> before converting them to NumPy arrays. Once the evaluation loop is finished, we concatenate all the results. Note that we need to truncate because the <code>Accelerator</code> may have added a few samples at the end to ensure we have the same number of examples in each process.</li> <li>Saving and uploading, where we first save the model and the tokenizer, then call <code>repo.push_to_hub()</code>. As we did before, we use the argument <code>blocking=False</code> to tell the 🤗 Hub library to push in an asynchronous process. This way, training continues normally and this (long) instruction is executed in the background.</li>",Ml,re,Xe="Here’s the complete code for the training loop:",ol,ye,ce,de,Re="In case this is the first time you’re seeing a model saved with 🤗 Accelerate, let’s take a moment to inspect the three lines of code that go with it:",qe,S,pl,we,ve="The first line is self-explanatory: it tells all the processes to wait until everyone is at that stage before continuing. This is to make sure we have the same model in every process before saving. Then we grab the <code>unwrapped_model</code>, which is the base model we defined. The <code>accelerator.prepare()</code> method changes the model to work in distributed training, so it won’t have the <code>save_pretrained()</code> method anymore; the <code>accelerator.unwrap_model()</code> method undoes that step. Lastly, we call <code>save_pretrained()</code> but tell that method to use <code>accelerator.save()</code> instead of <code>torch.save()</code>.",Le,q,rl='Once this is done, you should have a model that produces results pretty similar to the one trained with the <code>Trainer</code>. You can check the model we trained using this code at <a href="https://huggingface.co/huggingface-course/bert-finetuned-squad-accelerate" rel="nofollow"><em>huggingface-course/bert-finetuned-squad-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!',he;return h=new le({props:{title:"A custom training loop",local:"a-custom-training-loop",headingTag:"h2"}}),C=new le({props:{title:"Preparing everything for training",local:"preparing-everything-for-training",headingTag:"h3"}}),Z=new j({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGRlZmF1bHRfZGF0YV9jb2xsYXRvciUwQSUwQXRyYWluX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJ0b3JjaCUyMiklMEF2YWxpZGF0aW9uX3NldCUyMCUzRCUyMHZhbGlkYXRpb25fZGF0YXNldC5yZW1vdmVfY29sdW1ucyglNUIlMjJleGFtcGxlX2lkJTIyJTJDJTIwJTIyb2Zmc2V0X21hcHBpbmclMjIlNUQpJTBBdmFsaWRhdGlvbl9zZXQuc2V0X2Zvcm1hdCglMjJ0b3JjaCUyMiklMEElMEF0cmFpbl9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGVmYXVsdF9kYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uX3NldCUyQyUyMGNvbGxhdGVfZm4lM0RkZWZhdWx0X2RhdGFfY29sbGF0b3IlMkMlMjBiYXRjaF9zaXplJTNEOCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> default_data_collator
train_dataset.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
validation_set = validation_dataset.remove_columns([<span class="hljs-string">&quot;example_id&quot;</span>, <span class="hljs-string">&quot;offset_mapping&quot;</span>])
validation_set.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
train_dataloader = DataLoader(
train_dataset,
shuffle=<span class="hljs-literal">True</span>,
collate_fn=default_data_collator,
batch_size=<span class="hljs-number">8</span>,
)
eval_dataloader = DataLoader(
validation_set, collate_fn=default_data_collator, batch_size=<span class="hljs-number">8</span>
)`,wrap:!1}}),G=new j({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:"model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)",wrap:!1}}),se=new j({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDJlLTUp",highlighted:`<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),xe=new j({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQSUwQWFjY2VsZXJhdG9yJTIwJTNEJTIwQWNjZWxlcmF0b3IoZnAxNiUzRFRydWUpJTBBbW9kZWwlMkMlMjBvcHRpbWl6ZXIlMkMlMjB0cmFpbl9kYXRhbG9hZGVyJTJDJTIwZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwYWNjZWxlcmF0b3IucHJlcGFyZSglMEElMjAlMjAlMjAlMjBtb2RlbCUyQyUyMG9wdGltaXplciUyQyUyMHRyYWluX2RhdGFsb2FkZXIlMkMlMjBldmFsX2RhdGFsb2FkZXIlMEEp",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
accelerator = Accelerator(fp16=<span class="hljs-literal">True</span>)
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
model, optimizer, train_dataloader, eval_dataloader
)`,wrap:!1}}),_e=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}}),We=new j({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMFJlcG9zaXRvcnklMkMlMjBnZXRfZnVsbF9yZXBvX25hbWUlMEElMEFtb2RlbF9uYW1lJTIwJTNEJTIwJTIyYmVydC1maW5ldHVuZWQtc3F1YWQtYWNjZWxlcmF0ZSUyMiUwQXJlcG9fbmFtZSUyMCUzRCUyMGdldF9mdWxsX3JlcG9fbmFtZShtb2RlbF9uYW1lKSUwQXJlcG9fbmFtZQ==",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;bert-finetuned-squad-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),F=new j({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1zcXVhZC1hY2NlbGVyYXRlJw==",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-squad-accelerate&#x27;</span>',wrap:!1}}),Y=new j({props:{code:"b3V0cHV0X2RpciUyMCUzRCUyMCUyMmJlcnQtZmluZXR1bmVkLXNxdWFkLWFjY2VsZXJhdGUlMjIlMEFyZXBvJTIwJTNEJTIwUmVwb3NpdG9yeShvdXRwdXRfZGlyJTJDJTIwY2xvbmVfZnJvbSUzRHJlcG9fbmFtZSk=",highlighted:`output_dir = <span class="hljs-string">&quot;bert-finetuned-squad-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`,wrap:!1}}),Ae=new le({props:{title:"Training loop",local:"training-loop",headingTag:"h2"}}),ye=new j({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBzdGVwJTJDJTIwYmF0Y2glMjBpbiUyMGVudW1lcmF0ZSh0cmFpbl9kYXRhbG9hZGVyKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJh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AlMjAlMjAlMjB1bndyYXBwZWRfbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKG91dHB1dF9kaXIlMkMlMjBzYXZlX2Z1bmN0aW9uJTNEYWNjZWxlcmF0b3Iuc2F2ZSklMEElMjAlMjAlMjAlMjBpZiUyMGFjY2VsZXJhdG9yLmlzX21haW5fcHJvY2VzcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRva2VuaXplci5zYXZlX3ByZXRyYWluZWQob3V0cHV0X2RpciklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXBvLnB1c2hfdG9faHViKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbW1pdF9tZXNzYWdlJTNEZiUyMlRyYWluaW5nJTIwaW4lMjBwcm9ncmVzcyUyMGVwb2NoJTIwJTdCZXBvY2glN0QlMjIlMkMlMjBibG9ja2luZyUzREZhbHNlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKQ==",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> step, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</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>()
start_logits = []
end_logits = []
accelerator.<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Evaluation!&quot;</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():
outputs = model(**batch)
start_logits.append(accelerator.gather(outputs.start_logits).cpu().numpy())
end_logits.append(accelerator.gather(outputs.end_logits).cpu().numpy())
start_logits = np.concatenate(start_logits)
end_logits = np.concatenate(end_logits)
start_logits = start_logits[: <span class="hljs-built_in">len</span>(validation_dataset)]
end_logits = end_logits[: <span class="hljs-built_in">len</span>(validation_dataset)]
metrics = compute_metrics(
start_logits, end_logits, validation_dataset, raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>]
)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;epoch <span class="hljs-subst">{epoch}</span>:&quot;</span>, metrics)
<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}}),S=new j({props:{code:"YWNjZWxlcmF0b3Iud2FpdF9mb3JfZXZlcnlvbmUoKSUwQXVud3JhcHBlZF9tb2RlbCUyMCUzRCUyMGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbChtb2RlbCklMEF1bndyYXBwZWRfbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKG91dHB1dF9kaXIlMkMlMjBzYXZlX2Z1bmN0aW9uJTNEYWNjZWxlcmF0b3Iuc2F2ZSk=",highlighted:`accelerator.wait_for_everyone()
unwrapped_model = accelerator.unwrap_model(model)
unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)`,wrap:!1}}),{c(){i=c("p"),i.textContent=T,p=a(),J(h.$$.fragment),b=a(),o=c("p"),o.innerHTML=I,f=a(),J(C.$$.fragment),_=a(),x=c("p"),x.innerHTML=A,V=a(),J(Z.$$.fragment),B=a(),W=c("p"),W.textContent=P,L=a(),J(G.$$.fragment),X=a(),te=c("p"),te.innerHTML=$,ll=a(),J(se.$$.fragment),ae=a(),ke=c("p"),ke.innerHTML=tl,O=a(),J(xe.$$.fragment),Qe=a(),N=c("p"),N.innerHTML=sl,ne=a(),J(_e.$$.fragment),Fe=a(),Q=c("p"),Q.innerHTML=al,ie=a(),J(We.$$.fragment),Ee=a(),J(F.$$.fragment),Ye=a(),E=c("p"),E.textContent=Ws,ze=a(),J(Y.$$.fragment),He=a(),z=c("p"),z.innerHTML=nl,Me=a(),J(Ae.$$.fragment),Se=a(),H=c("p"),H.textContent=il,oe=a(),pe=c("ul"),pe.innerHTML=Ve,Ml=a(),re=c("p"),re.textContent=Xe,ol=a(),J(ye.$$.fragment),ce=a(),de=c("p"),de.textContent=Re,qe=a(),J(S.$$.fragment),pl=a(),we=c("p"),we.innerHTML=ve,Le=a(),q=c("p"),q.innerHTML=rl},l(M){i=d(M,"P",{"data-svelte-h":!0}),w(i)!=="svelte-1d13qvr"&&(i.textContent=T),p=n(M),u(h.$$.fragment,M),b=n(M),o=d(M,"P",{"data-svelte-h":!0}),w(o)!=="svelte-qp9mb5"&&(o.innerHTML=I),f=n(M),u(C.$$.fragment,M),_=n(M),x=d(M,"P",{"data-svelte-h":!0}),w(x)!=="svelte-1ybe7da"&&(x.innerHTML=A),V=n(M),u(Z.$$.fragment,M),B=n(M),W=d(M,"P",{"data-svelte-h":!0}),w(W)!=="svelte-fdz4rk"&&(W.textContent=P),L=n(M),u(G.$$.fragment,M),X=n(M),te=d(M,"P",{"data-svelte-h":!0}),w(te)!=="svelte-1knlk02"&&(te.innerHTML=$),ll=n(M),u(se.$$.fragment,M),ae=n(M),ke=d(M,"P",{"data-svelte-h":!0}),w(ke)!=="svelte-1z0bkjl"&&(ke.innerHTML=tl),O=n(M),u(xe.$$.fragment,M),Qe=n(M),N=d(M,"P",{"data-svelte-h":!0}),w(N)!=="svelte-28uouy"&&(N.innerHTML=sl),ne=n(M),u(_e.$$.fragment,M),Fe=n(M),Q=d(M,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-117ky3j"&&(Q.innerHTML=al),ie=n(M),u(We.$$.fragment,M),Ee=n(M),u(F.$$.fragment,M),Ye=n(M),E=d(M,"P",{"data-svelte-h":!0}),w(E)!=="svelte-e9w2am"&&(E.textContent=Ws),ze=n(M),u(Y.$$.fragment,M),He=n(M),z=d(M,"P",{"data-svelte-h":!0}),w(z)!=="svelte-1mcbsiy"&&(z.innerHTML=nl),Me=n(M),u(Ae.$$.fragment,M),Se=n(M),H=d(M,"P",{"data-svelte-h":!0}),w(H)!=="svelte-xmeq7h"&&(H.textContent=il),oe=n(M),pe=d(M,"UL",{"data-svelte-h":!0}),w(pe)!=="svelte-hjn6v3"&&(pe.innerHTML=Ve),Ml=n(M),re=d(M,"P",{"data-svelte-h":!0}),w(re)!=="svelte-1yi720t"&&(re.textContent=Xe),ol=n(M),u(ye.$$.fragment,M),ce=n(M),de=d(M,"P",{"data-svelte-h":!0}),w(de)!=="svelte-10bu99i"&&(de.textContent=Re),qe=n(M),u(S.$$.fragment,M),pl=n(M),we=d(M,"P",{"data-svelte-h":!0}),w(we)!=="svelte-est4dk"&&(we.innerHTML=ve),Le=n(M),q=d(M,"P",{"data-svelte-h":!0}),w(q)!=="svelte-xmmh4v"&&(q.innerHTML=rl)},m(M,g){s(M,i,g),s(M,p,g),m(h,M,g),s(M,b,g),s(M,o,g),s(M,f,g),m(C,M,g),s(M,_,g),s(M,x,g),s(M,V,g),m(Z,M,g),s(M,B,g),s(M,W,g),s(M,L,g),m(G,M,g),s(M,X,g),s(M,te,g),s(M,ll,g),m(se,M,g),s(M,ae,g),s(M,ke,g),s(M,O,g),m(xe,M,g),s(M,Qe,g),s(M,N,g),s(M,ne,g),m(_e,M,g),s(M,Fe,g),s(M,Q,g),s(M,ie,g),m(We,M,g),s(M,Ee,g),m(F,M,g),s(M,Ye,g),s(M,E,g),s(M,ze,g),m(Y,M,g),s(M,He,g),s(M,z,g),s(M,Me,g),m(Ae,M,g),s(M,Se,g),s(M,H,g),s(M,oe,g),s(M,pe,g),s(M,Ml,g),s(M,re,g),s(M,ol,g),m(ye,M,g),s(M,ce,g),s(M,de,g),s(M,qe,g),m(S,M,g),s(M,pl,g),s(M,we,g),s(M,Le,g),s(M,q,g),he=!0},i(M){he||(r(h.$$.fragment,M),r(C.$$.fragment,M),r(Z.$$.fragment,M),r(G.$$.fragment,M),r(se.$$.fragment,M),r(xe.$$.fragment,M),r(_e.$$.fragment,M),r(We.$$.fragment,M),r(F.$$.fragment,M),r(Y.$$.fragment,M),r(Ae.$$.fragment,M),r(ye.$$.fragment,M),r(S.$$.fragment,M),he=!0)},o(M){y(h.$$.fragment,M),y(C.$$.fragment,M),y(Z.$$.fragment,M),y(G.$$.fragment,M),y(se.$$.fragment,M),y(xe.$$.fragment,M),y(_e.$$.fragment,M),y(We.$$.fragment,M),y(F.$$.fragment,M),y(Y.$$.fragment,M),y(Ae.$$.fragment,M),y(ye.$$.fragment,M),y(S.$$.fragment,M),he=!1},d(M){M&&(l(i),l(p),l(b),l(o),l(f),l(_),l(x),l(V),l(B),l(W),l(L),l(X),l(te),l(ll),l(ae),l(ke),l(O),l(Qe),l(N),l(ne),l(Fe),l(Q),l(ie),l(Ee),l(Ye),l(E),l(ze),l(He),l(z),l(Me),l(Se),l(H),l(oe),l(pe),l(Ml),l(re),l(ol),l(ce),l(de),l(qe),l(pl),l(we),l(Le),l(q)),U(h,M),U(C,M),U(Z,M),U(G,M),U(se,M),U(xe,M),U(_e,M),U(We,M),U(F,M),U(Y,M),U(Ae,M),U(ye,M),U(S,M)}}}function yo(k){let i,T,p,h,b,o,I,f,C,_,x,A,V,Z,B="Time to look at question answering! This task comes in many flavors, but the one we’ll focus on in this section is called <em>extractive</em> question answering. This involves posing questions about a document and identifying the answers as <em>spans of text</em> in the document itself.",W,P,L,G,X='We will fine-tune a BERT model on the <a href="https://rajpurkar.github.io/SQuAD-explorer/" rel="nofollow">SQuAD dataset</a>, which consists of questions posed by crowdworkers on a set of Wikipedia articles. This will give us a model able to compute predictions like this one:',te,$,ll,se,ae,ke='This is actually showcasing the model that was trained and uploaded to the Hub using the code shown in this section. You can find it and double-check the predictions <a href="https://huggingface.co/huggingface-course/bert-finetuned-squad?context=%F0%9F%A4%97+Transformers+is+backed+by+the+three+most+popular+deep+learning+libraries+%E2%80%94+Jax%2C+PyTorch+and+TensorFlow+%E2%80%94+with+a+seamless+integration+between+them.+It%27s+straightforward+to+train+your+models+with+one+before+loading+them+for+inference+with+the+other.&amp;question=Which+deep+learning+libraries+back+%F0%9F%A4%97+Transformers%3F" rel="nofollow">here</a>.',tl,O,xe='<p>💡 Encoder-only models like BERT tend to be great at extracting answers to factoid questions like “Who invented the Transformer architecture?” but fare poorly when given open-ended questions like “Why is the sky blue?” In these more challenging cases, encoder-decoder models like T5 and BART are typically used to synthesize the information in a way that’s quite similar to <a href="/course/chapter7/5">text summarization</a>. If you’re interested in this type of <em>generative</em> question answering, we recommend checking out our <a href="https://yjernite.github.io/lfqa.html" rel="nofollow">demo</a> based on the <a href="https://huggingface.co/datasets/eli5" rel="nofollow">ELI5 dataset</a>.</p>',Qe,N,sl,ne,_e='The dataset that is used the most as an academic benchmark for extractive question answering is <a href="https://rajpurkar.github.io/SQuAD-explorer/" rel="nofollow">SQuAD</a>, so that’s the one we’ll use here. There is also a harder <a href="https://huggingface.co/datasets/squad_v2" rel="nofollow">SQuAD v2</a> benchmark, which includes questions that don’t have an answer. As long as your own dataset contains a column for contexts, a column for questions, and a column for answers, you should be able to adapt the steps below.',Fe,Q,al,ie,We="As usual, we can download and cache the dataset in just one step thanks to <code>load_dataset()</code>:",Ee,F,Ye,E,Ws="We can then have a look at this object to learn more about the SQuAD dataset:",ze,Y,He,z,nl,Me,Ae="It looks like we have everything we need with the <code>context</code>, <code>question</code>, and <code>answers</code> fields, so let’s print those for the first element of our training set:",Se,H,il,oe,pe,Ve,Ml="The <code>context</code> and <code>question</code> fields are very straightforward to use. The <code>answers</code> field is a bit trickier as it comports a dictionary with two fields that are both lists. This is the format that will be expected by the <code>squad</code> metric during evaluation; if you are using your own data, you don’t necessarily need to worry about putting the answers in the same format. The <code>text</code> field is rather obvious, and the <code>answer_start</code> field contains the starting character index of each answer in the context.",re,Xe,ol="During training, there is only one possible answer. We can double-check this by using the <code>Dataset.filter()</code> method:",ye,ce,de,Re,qe,S,pl="For evaluation, however, there are several possible answers for each sample, which may be the same or different:",we,ve,Le,q,rl,he,M="We won’t dive into the evaluation script as it will all be wrapped up by a 🤗 Datasets metric for us, but the short version is that some of the questions have several possible answers, and this script will compare a predicted answer to all the acceptable answers and take the best score. If we take a look at the sample at index 2, for instance:",g,yl,Rs,cl,vs,dl,Mi="we can see that the answer can indeed be one of the three possibilities we saw before.",$s,wl,Ns,hl,Qs,Jl,oi="Let’s start with preprocessing the training data. The hard part will be to generate labels for the question’s answer, which will be the start and end positions of the tokens corresponding to the answer inside the context.",Fs,ul,pi="But let’s not get ahead of ourselves. First, we need to convert the text in the input into IDs the model can make sense of, using a tokenizer:",Es,ml,Ys,Ul,ri='As mentioned previously, we’ll be fine-tuning a BERT model, but you can use any other model type as long as it has a fast tokenizer implemented. You can see all the architectures that come with a fast version in <a href="https://huggingface.co/transformers/#supported-frameworks" rel="nofollow">this big table</a>, and to check that the <code>tokenizer</code> object you’re using is indeed backed by 🤗 Tokenizers you can look at its <code>is_fast</code> attribute:',zs,Tl,Hs,jl,Ss,bl,yi="We can pass to our tokenizer the question and the context together, and it will properly insert the special tokens to form a sentence like this:",qs,fl,Ls,Il,ci="Let’s double-check:",Ds,Cl,Ks,gl,Ps,Zl,di="The labels will then be the index of the tokens starting and ending the answer, and the model will be tasked to predicted one start and end logit per token in the input, with the theoretical labels being as follow:",Os,Pe,wi='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/qa_labels.svg" alt="One-hot encoded labels for question answering."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/qa_labels-dark.svg" alt="One-hot encoded labels for question answering."/>',ea,Gl,hi='In this case the context is not too long, but some of the examples in the dataset have very long contexts that will exceed the maximum length we set (which is 384 in this case). As we saw in <a href="/course/chapter6/4">Chapter 6</a> when we explored the internals of the <code>question-answering</code> pipeline, we will deal with long contexts by creating several training features from one sample of our dataset, with a sliding window between them.',la,Bl,Ji="To see how this works using the current example, we can limit the length to 100 and use a sliding window of 50 tokens. As a reminder, we use:",ta,kl,ui="<li><code>max_length</code> to set the maximum length (here 100)</li> <li><code>truncation=&quot;only_second&quot;</code> to truncate the context (which is in the second position) when the question with its context is too long</li> <li><code>stride</code> to set the number of overlapping tokens between two successive chunks (here 50)</li> <li><code>return_overflowing_tokens=True</code> to let the tokenizer know we want the overflowing tokens</li>",sa,xl,aa,_l,na,Wl,mi="As we can see, our example has been in split into four inputs, each of them containing the question and some part of the context. Note that the answer to the question (“Bernadette Soubirous”) only appears in the third and last inputs, so by dealing with long contexts in this way we will create some training examples where the answer is not included in the context. For those examples, the labels will be <code>start_position = end_position = 0</code> (so we predict the <code>[CLS]</code> token). We will also set those labels in the unfortunate case where the answer has been truncated so that we only have the start (or end) of it. For the examples where the answer is fully in the context, the labels will be the index of the token where the answer starts and the index of the token where the answer ends.",ia,Al,Ui='The dataset provides us with the start character of the answer in the context, and by adding the length of the answer, we can find the end character in the context. To map those to token indices, we will need to use the offset mappings we studied in <a href="/course/chapter6/4">Chapter 6</a>. We can have our tokenizer return these by passing along <code>return_offsets_mapping=True</code>:',Ma,Vl,oa,Xl,pa,Rl,Ti="As we can see, we get back the usual input IDs, token type IDs, and attention mask, as well as the offset mapping we required and an extra key, <code>overflow_to_sample_mapping</code>. The corresponding value will be of use to us when we tokenize several texts at the same time (which we should do to benefit from the fact that our tokenizer is backed by Rust). Since one sample can give several features, it maps each feature to the example it originated from. Because here we only tokenized one example, we get a list of <code>0</code>s:",ra,vl,ya,$l,ca,Nl,ji="But if we tokenize more examples, this will become more useful:",da,Ql,wa,Fl,ha,El,bi="As we can see, the first three examples (at indices 2, 3, and 4 in the training set) each gave four features and the last example (at index 5 in the training set) gave 7 features.",Ja,Yl,fi="This information will be useful to map each feature we get to its corresponding label. As mentioned earlier, those labels are:",ua,zl,Ii="<li><code>(0, 0)</code> if the answer is not in the corresponding span of the context</li> <li><code>(start_position, end_position)</code> if the answer is in the corresponding span of the context, with <code>start_position</code> being the index of the token (in the input IDs) at the start of the answer and <code>end_position</code> being the index of the token (in the input IDs) where the answer ends</li>",ma,Hl,Ci="To determine which of these is the case and, if relevant, the positions of the tokens, we first find the indices that start and end the context in the input IDs. We could use the token type IDs to do this, but since those do not necessarily exist for all models (DistilBERT does not require them, for instance), we’ll instead use the <code>sequence_ids()</code> method of the <code>BatchEncoding</code> our tokenizer returns.",Ua,Sl,gi="Once we have those token indices, we look at the corresponding offsets, which are tuples of two integers representing the span of characters inside the original context. We can thus detect if the chunk of the context in this feature starts after the answer or ends before the answer begins (in which case the label is <code>(0, 0)</code>). If that’s not the case, we loop to find the first and last token of the answer:",Ta,ql,ja,Ll,ba,Dl,Zi="Let’s take a look at a few results to verify that our approach is correct. For the first feature we find <code>(83, 85)</code> as labels, so let’s compare the theoretical answer with the decoded span of tokens from 83 to 85 (inclusive):",fa,Kl,Ia,Pl,Ca,Ol,Gi="So that’s a match! Now let’s check index 4, where we set the labels to <code>(0, 0)</code>, which means the answer is not in the context chunk of that feature:",ga,et,Za,lt,Ga,tt,Bi="Indeed, we don’t see the answer inside the context.",Ba,Oe,ki="<p>✏️ <strong>Your turn!</strong> When using the XLNet architecture, padding is applied on the left and the question and context are switched. Adapt all the code we just saw to the XLNet architecture (and add <code>padding=True</code>). Be aware that the <code>[CLS]</code> token may not be at the 0 position with padding applied.</p>",ka,st,xi="Now that we have seen step by step how to preprocess our training data, we can group it in a function we will apply on the whole training dataset. We’ll pad every feature to the maximum length we set, as most of the contexts will be long (and the corresponding samples will be split into several features), so there is no real benefit to applying dynamic padding here:",xa,at,_a,nt,_i="Note that we defined two constants to determine the maximum length used as well as the length of the sliding window, and that we added a tiny bit of cleanup before tokenizing: some of the questions in the SQuAD dataset have extra spaces at the beginning and the end that don’t add anything (and take up space when being tokenized if you use a model like RoBERTa), so we removed those extra spaces.",Wa,it,Wi="To apply this function to the whole training set, we use the <code>Dataset.map()</code> method with the <code>batched=True</code> flag. It’s necessary here as we are changing the length of the dataset (since one example can give several training features):",Aa,Mt,Va,ot,Xa,pt,Ai="As we can see, the preprocessing added roughly 1,000 features. Our training set is now ready to be used — let’s dig into the preprocessing of the validation set!",Ra,rt,va,yt,Vi="Preprocessing the validation data will be slightly easier as we don’t need to generate labels (unless we want to compute a validation loss, but that number won’t really help us understand how good the model is). The real joy will be to interpret the predictions of the model into spans of the original context. For this, we will just need to store both the offset mappings and some way to match each created feature to the original example it comes from. Since there is an ID column in the original dataset, we’ll use that ID.",$a,ct,Xi="The only thing we’ll add here is a tiny bit of cleanup of the offset mappings. They will contain offsets for the question and the context, but once we’re in the post-processing stage we won’t have any way to know which part of the input IDs corresponded to the context and which part was the question (the <code>sequence_ids()</code> method we used is available for the output of the tokenizer only). So, we’ll set the offsets corresponding to the question to <code>None</code>:",Na,dt,Qa,wt,Ri="We can apply this function on the whole validation dataset like before:",Fa,ht,Ea,Jt,Ya,ut,vi="In this case we’ve only added a couple of hundred samples, so it appears the contexts in the validation dataset are a bit shorter.",za,mt,$i="Now that we have preprocessed all the data, we can get to the training.",Ha,Je,ue,Ts,Ut,Sa,me,Ue,js,Tt,Ni='The model will output logits for the start and end positions of the answer in the input IDs, as we saw during our exploration of the <a href="/course/chapter6/3b"><code>question-answering</code> pipeline</a>. The post-processing step will be similar to what we did there, so here’s a quick reminder of the actions we took:',qa,jt,Qi="<li>We masked the start and end logits corresponding to tokens outside of the context.</li> <li>We then converted the start and end logits into probabilities using a softmax.</li> <li>We attributed a score to each <code>(start_token, end_token)</code> pair by taking the product of the corresponding two probabilities.</li> <li>We looked for the pair with the maximum score that yielded a valid answer (e.g., a <code>start_token</code> lower than <code>end_token</code>).</li>",La,D,Ln,bs,Fi="(start_token, end_token)",Dn,fs,Ei="n_best",Kn,Is,Yi="n_best=20",Pn,Da,VM='<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>a</mi><mi>b</mi><mo stretchy="false">)</mo><mo>=</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\\log(ab) = \\log(a) + \\log(b)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">lo<span style="margin-right:0.01389em;">g</span></span><span class="mopen">(</span><span class="mord mathnormal">ab</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">lo<span style="margin-right:0.01389em;">g</span></span><span class="mopen">(</span><span class="mord mathnormal">a</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">lo<span style="margin-right:0.01389em;">g</span></span><span class="mopen">(</span><span class="mord mathnormal">b</span><span class="mclose">)</span></span></span></span>',Ka,Pa,bt,zi="To demonstrate all of this, we will need some kind of predictions. Since we have not trained our model yet, we are going to use the default model for the QA pipeline to generate some predictions on a small part of the validation set. We can use the same processing function as before; because it relies on the global constant <code>tokenizer</code>, we just have to change that object to the tokenizer of the model we want to use temporarily:",Oa,ft,en,It,Hi="Now that the preprocessing is done, we change the tokenizer back to the one we originally picked:",ln,Ct,tn,gt,Si="We then remove the columns of our <code>eval_set</code> that are not expected by the model, build a batch with all of that small validation set, and pass it through the model. If a GPU is available, we use it to go faster:",sn,Te,je,Cs,Zt,qi="Now, we need to find the predicted answer for each example in our <code>small_eval_set</code>. One example may have been split into several features in <code>eval_set</code>, so the first step is to map each example in <code>small_eval_set</code> to the corresponding features in <code>eval_set</code>:",an,Gt,nn,Bt,Li="With this in hand, we can really get to work by looping through all the examples and, for each example, through all the associated features. As we said before, we’ll look at the logit scores for the <code>n_best</code> start logits and end logits, excluding positions that give:",Mn,kt,Di="<li>An answer that wouldn’t be inside the context</li> <li>An answer with negative length</li> <li>An answer that is too long (we limit the possibilities at <code>max_answer_length=30</code>)</li>",on,xt,Ki="Once we have all the scored possible answers for one example, we just pick the one with the best logit score:",pn,_t,rn,Wt,Pi="The final format of the predicted answers is the one that will be expected by the metric we will use. As usual, we can load it with the help of the 🤗 Evaluate library:",yn,At,cn,Vt,Oi="This metric expects the predicted answers in the format we saw above (a list of dictionaries with one key for the ID of the example and one key for the predicted text) and the theoretical answers in the format below (a list of dictionaries with one key for the ID of the example and one key for the possible answers):",dn,Xt,wn,Rt,eM="We can now check that we get sensible results by looking at the first element of both lists:",hn,vt,Jn,$t,un,Nt,lM="Not too bad! Now let’s have a look at the score the metric gives us:",mn,Qt,Un,Ft,Tn,Et,tM='Again, that’s rather good considering that according to <a href="https://arxiv.org/abs/1910.01108v2" rel="nofollow">its paper</a> DistilBERT fine-tuned on SQuAD obtains 79.1 and 86.9 for those scores on the whole dataset.',jn,gs,Yt,bn,zt,sM="We can check it works on our predictions:",fn,Ht,In,St,Cn,qt,aM="Looking good! Now let’s use this to fine-tune our model.",gn,Lt,Zn,be,fe,Zs,Dt,nM="As usual, we get a warning that some weights are not used (the ones from the pretraining head) and some others are initialized randomly (the ones for the question answering head). You should be used to this by now, but that means this model is not ready to be used just yet and needs fine-tuning — good thing we’re about to do that!",Gn,Kt,iM="To be able to push our model to the Hub, we’ll need to log in to Hugging Face. If you’re running this code in a notebook, you can do so with the following utility function, which displays a widget where you can enter your login credentials:",Bn,Pt,kn,Ot,MM="If you aren’t working in a notebook, just type the following line in your terminal:",xn,es,_n,Ie,Ce,Gs,ls,oM="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 in <code>&quot;sgugger/bert-finetuned-squad&quot;</code>. We can override this by passing a <code>hub_model_id</code>; for instance, to push the model to the <code>huggingface_course</code> organization we used <code>hub_model_id=&quot;huggingface_course/bert-finetuned-squad&quot;</code> (which is the model we linked to at the beginning of this section).",Wn,ge,Ze,Bs,ts,pM="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. The whole training takes a while (a little over an hour on a Titan RTX), so you can grab a coffee or reread some of the parts of the course that you’ve found more challenging while it proceeds. Also note that as soon as the first epoch is finished, you will see some weights uploaded to the Hub and you can start playing with your model on its page.",An,Ge,Be,ks,ss,Vn,as,rM="Great! As a comparison, the baseline scores reported in the BERT article for this model are 80.8 and 88.5, so we’re right where we should be.",Xn,xs,ns,yM="At this stage, you can use the inference widget on the Model Hub to test the model and share it with your friends, family, and favorite pets. You have successfully fine-tuned a model on a question answering task — congratulations!",Rn,el,cM="<p>✏️ <strong>Your turn!</strong> Try another model architecture to see if it performs better on this task!</p>",vn,_s,is,$n,Ms,dM="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>, you just have to specify the model identifier:",Nn,os,Qn,ps,Fn,rs,wM="Great! Our model is working as well as the default one for this pipeline!",En,ys,Yn,As,zn;b=new HM({props:{fw:k[0]}}),I=new YM({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),C=new le({props:{title:"Question answering",local:"question-answering",headingTag:"h1"}});const hM=[qM,SM],cs=[];function JM(e,t){return e[0]==="pt"?0:1}x=JM(k),A=cs[x]=hM[x](k),P=new qn({props:{id:"ajPx5LwJD-I"}}),N=new le({props:{title:"Preparing the data",local:"preparing-the-data",headingTag:"h2"}}),Q=new le({props:{title:"The SQuAD dataset",local:"the-squad-dataset",headingTag:"h3"}}),F=new j({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBcmF3X2RhdGFzZXRzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMnNxdWFkJTIyKQ==",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;squad&quot;</span>)`,wrap:!1}}),Y=new j({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),z=new j({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2lkJyUyQyUyMCd0aXRsZSclMkMlMjAnY29udGV4dCclMkMlMjAncXVlc3Rpb24nJTJDJTIwJ2Fuc3dlcnMnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjA4NzU5OSUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uJTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidpZCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbnRleHQnJTJDJTIwJ3F1ZXN0aW9uJyUyQyUyMCdhbnN3ZXJzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMTA1NzAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
train: Dataset({
features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;context&#x27;</span>, <span class="hljs-string">&#x27;question&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>],
num_rows: <span class="hljs-number">87599</span>
})
validation: Dataset({
features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;context&#x27;</span>, <span class="hljs-string">&#x27;question&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>],
num_rows: <span class="hljs-number">10570</span>
})
})`,wrap:!1}}),H=new j({props:{code:"cHJpbnQoJTIyQ29udGV4dCUzQSUyMCUyMiUyQyUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RCU1QiUyMmNvbnRleHQlMjIlNUQpJTBBcHJpbnQoJTIyUXVlc3Rpb24lM0ElMjAlMjIlMkMlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQlNUIlMjJxdWVzdGlvbiUyMiU1RCklMEFwcmludCglMjJBbnN3ZXIlM0ElMjAlMjIlMkMlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQlNUIlMjJhbnN3ZXJzJTIyJTVEKQ==",highlighted:`<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Context: &quot;</span>, raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;context&quot;</span>])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Question: &quot;</span>, raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;question&quot;</span>])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Answer: &quot;</span>, raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;answers&quot;</span>])`,wrap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dCUyMHRoZSUyMGVuZCUyMG9mJTIwdGhlJTIwbWFpbiUyMGRyaXZlJTIwKGFuZCUyMGluJTIwYSUyMGRpcmVjdCUyMGxpbmUlMjB0aGF0JTIwY29ubmVjdHMlMjB0aHJvdWdoJTIwMyUyMHN0YXR1ZXMlMjBhbmQlMjB0aGUlMjBHb2xkJTIwRG9tZSklMkMlMjBpcyUyMGElMjBzaW1wbGUlMkMlMjBtb2Rlcm4lMjBzdG9uZSUyMHN0YXR1ZSUyMG9mJTIwTWFyeS4nJTBBUXVlc3Rpb24lM0ElMjAnVG8lMjB3aG9tJTIwZGlkJTIwdGhlJTIwVmlyZ2luJTIwTWFyeSUyMGFsbGVnZWRseSUyMGFwcGVhciUyMGluJTIwMTg1OCUyMGluJTIwTG91cmRlcyUyMEZyYW5jZSUzRiclMEFBbnN3ZXIlM0ElMjAlN0IndGV4dCclM0ElMjAlNUInU2FpbnQlMjBCZXJuYWRldHRlJTIwU291Ymlyb3VzJyU1RCUyQyUyMCdhbnN3ZXJfc3RhcnQnJTNBJTIwJTVCNTE1JTVEJTdE",highlighted:`Context: <span class="hljs-string">&#x27;Architecturally, the school has a Catholic character. Atop the Main Building\\&#x27;s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend &quot;Venite Ad Me Omnes&quot;. Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.&#x27;</span>
Question: <span class="hljs-string">&#x27;To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?&#x27;</span>
Answer: {<span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Saint Bernadette Soubirous&#x27;</span>], <span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">515</span>]}`,wrap:!1}}),ce=new j({props:{code:"cmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQuZmlsdGVyKGxhbWJkYSUyMHglM0ElMjBsZW4oeCU1QiUyMmFuc3dlcnMlMjIlNUQlNUIlMjJ0ZXh0JTIyJTVEKSUyMCElM0QlMjAxKQ==",highlighted:'raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;answers&quot;</span>][<span class="hljs-string">&quot;text&quot;</span>]) != <span class="hljs-number">1</span>)',wrap:!1}}),Re=new j({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidpZCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbnRleHQnJTJDJTIwJ3F1ZXN0aW9uJyUyQyUyMCdhbnN3ZXJzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMCUwQSU3RCk=",highlighted:`Dataset({
features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;context&#x27;</span>, <span class="hljs-string">&#x27;question&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>],
num_rows: <span class="hljs-number">0</span>
})`,wrap:!1}}),ve=new j({props:{code:"cHJpbnQocmF3X2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCU1QjAlNUQlNUIlMjJhbnN3ZXJzJTIyJTVEKSUwQXByaW50KHJhd19kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlNUIyJTVEJTVCJTIyYW5zd2VycyUyMiU1RCk=",highlighted:`<span class="hljs-built_in">print</span>(raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;answers&quot;</span>])
<span class="hljs-built_in">print</span>(raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-number">2</span>][<span class="hljs-string">&quot;answers&quot;</span>])`,wrap:!1}}),q=new j({props:{code:"JTdCJ3RleHQnJTNBJTIwJTVCJ0RlbnZlciUyMEJyb25jb3MnJTJDJTIwJ0RlbnZlciUyMEJyb25jb3MnJTJDJTIwJ0RlbnZlciUyMEJyb25jb3MnJTVEJTJDJTIwJ2Fuc3dlcl9zdGFydCclM0ElMjAlNUIxNzclMkMlMjAxNzclMkMlMjAxNzclNUQlN0QlMEElN0IndGV4dCclM0ElMjAlNUInU2FudGElMjBDbGFyYSUyQyUyMENhbGlmb3JuaWEnJTJDJTIwJTIyTGV2aSdzJTIwU3RhZGl1bSUyMiUyQyUyMCUyMkxldmkncyUyMFN0YWRpdW0lMjBpbiUyMHRoZSUyMFNhbiUyMEZyYW5jaXNjbyUyMEJheSUyMEFyZWElMjBhdCUyMFNhbnRhJTIwQ2xhcmElMkMlMjBDYWxpZm9ybmlhLiUyMiU1RCUyQyUyMCdhbnN3ZXJfc3RhcnQnJTNBJTIwJTVCNDAzJTJDJTIwMzU1JTJDJTIwMzU1JTVEJTdE",highlighted:`{<span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Denver Broncos&#x27;</span>, <span class="hljs-string">&#x27;Denver Broncos&#x27;</span>, <span class="hljs-string">&#x27;Denver Broncos&#x27;</span>], <span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">177</span>, <span class="hljs-number">177</span>, <span class="hljs-number">177</span>]}
{<span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Santa Clara, California&#x27;</span>, <span class="hljs-string">&quot;Levi&#x27;s Stadium&quot;</span>, <span class="hljs-string">&quot;Levi&#x27;s Stadium in the San Francisco Bay Area at Santa Clara, California.&quot;</span>], <span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">403</span>, <span class="hljs-number">355</span>, <span class="hljs-number">355</span>]}`,wrap:!1}}),yl=new j({props:{code:"cHJpbnQocmF3X2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCU1QjIlNUQlNUIlMjJjb250ZXh0JTIyJTVEKSUwQXByaW50KHJhd19kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlNUIyJTVEJTVCJTIycXVlc3Rpb24lMjIlNUQp",highlighted:`<span class="hljs-built_in">print</span>(raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-number">2</span>][<span class="hljs-string">&quot;context&quot;</span>])
<span class="hljs-built_in">print</span>(raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-number">2</span>][<span class="hljs-string">&quot;question&quot;</span>])`,wrap:!1}}),cl=new j({props:{code:"J1N1cGVyJTIwQm93bCUyMDUwJTIwd2FzJTIwYW4lMjBBbWVyaWNhbiUyMGZvb3RiYWxsJTIwZ2FtZSUyMHRvJTIwZGV0ZXJtaW5lJTIwdGhlJTIwY2hhbXBpb24lMjBvZiUyMHRoZSUyME5hdGlvbmFsJTIwRm9vdGJhbGwlMjBMZWFndWUlMjAoTkZMKSUyMGZvciUyMHRoZSUyMDIwMTUlMjBzZWFzb24uJTIwVGhlJTIwQW1lcmljYW4lMjBGb290YmFsbCUyMENvbmZlcmVuY2UlMjAoQUZDKSUyMGNoYW1waW9uJTIwRGVudmVyJTIwQnJvbmNvcyUyMGRlZmVhdGVkJTIwdGhlJTIwTmF0aW9uYWwlMjBGb290YmFsbCUyMENvbmZlcmVuY2UlMjAoTkZDKSUyMGNoYW1waW9uJTIwQ2Fyb2xpbmElMjBQYW50aGVycyUyMDI0JUUyJTgwJTkzMTAlMjB0byUyMGVhcm4lMjB0aGVpciUyMHRoaXJkJTIwU3VwZXIlMjBCb3dsJTIwdGl0bGUuJTIwVGhlJTIwZ2FtZSUyMHdhcyUyMHBsYXllZCUyMG9uJTIwRmVicnVhcnklMjA3JTJDJTIwMjAxNiUyQyUyMGF0JTIwTGV2aSU1QydzJTIwU3RhZGl1bSUyMGluJTIwdGhlJTIwU2FuJTIwRnJhbmNpc2NvJTIwQmF5JTIwQXJlYSUyMGF0JTIwU2FudGElMjBDbGFyYSUyQyUyMENhbGlmb3JuaWEuJTIwQXMlMjB0aGlzJTIwd2FzJTIwdGhlJTIwNTB0aCUyMFN1cGVyJTIwQm93bCUyQyUyMHRoZSUyMGxlYWd1ZSUyMGVtcGhhc2l6ZWQlMjB0aGUlMjAlMjJnb2xkZW4lMjBhbm5pdmVyc2FyeSUyMiUyMHdpdGglMjB2YXJpb3VzJTIwZ29sZC10aGVtZWQlMjBpbml0aWF0aXZlcyUyQyUyMGFzJTIwd2VsbCUyMGFzJTIwdGVtcG9yYXJpbHklMjBzdXNwZW5kaW5nJTIwdGhlJTIwdHJhZGl0aW9uJTIwb2YlMjBuYW1pbmclMjBlYWNoJTIwU3VwZXIlMjBCb3dsJTIwZ2FtZSUyMHdpdGglMjBSb21hbiUyMG51bWVyYWxzJTIwKHVuZGVyJTIwd2hpY2glMjB0aGUlMjBnYW1lJTIwd291bGQlMjBoYXZlJTIwYmVlbiUyMGtub3duJTIwYXMlMjAlMjJTdXBlciUyMEJvd2wlMjBMJTIyKSUyQyUyMHNvJTIwdGhhdCUyMHRoZSUyMGxvZ28lMjBjb3VsZCUyMHByb21pbmVudGx5JTIwZmVhdHVyZSUyMHRoZSUyMEFyYWJpYyUyMG51bWVyYWxzJTIwNTAuJyUwQSdXaGVyZSUyMGRpZCUyMFN1cGVyJTIwQm93bCUyMDUwJTIwdGFrZSUyMHBsYWNlJTNGJw==",highlighted:`<span class="hljs-string">&#x27;Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi\\&#x27;s Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the &quot;golden anniversary&quot; with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as &quot;Super Bowl L&quot;), so that the logo could prominently feature the Arabic numerals 50.&#x27;</span>
<span class="hljs-string">&#x27;Where did Super Bowl 50 take place?&#x27;</span>`,wrap:!1}}),wl=new le({props:{title:"Processing the training data",local:"processing-the-training-data",headingTag:"h3"}}),hl=new qn({props:{id:"qgaM0weJHpA"}}),ml=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyYmVydC1iYXNlLWNhc2VkJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer
model_checkpoint = <span class="hljs-string">&quot;bert-base-cased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`,wrap:!1}}),Tl=new j({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),jl=new j({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),fl=new j({props:{code:"JTVCQ0xTJTVEJTIwcXVlc3Rpb24lMjAlNUJTRVAlNUQlMjBjb250ZXh0JTIwJTVCU0VQJTVE",highlighted:'<span class="hljs-selector-attr">[CLS]</span> question <span class="hljs-selector-attr">[SEP]</span> context <span class="hljs-selector-attr">[SEP]</span>',wrap:!1}}),Cl=new j({props:{code:"Y29udGV4dCUyMCUzRCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RCU1QiUyMmNvbnRleHQlMjIlNUQlMEFxdWVzdGlvbiUyMCUzRCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RCU1QiUyMnF1ZXN0aW9uJTIyJTVEJTBBJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwY29udGV4dCklMEF0b2tlbml6ZXIuZGVjb2RlKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:`context = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;context&quot;</span>]
question = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;question&quot;</span>]
inputs = tokenizer(question, context)
tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`,wrap:!1}}),gl=new j({props:{code:"JyU1QkNMUyU1RCUyMFRvJTIwd2hvbSUyMGRpZCUyMHRoZSUyMFZpcmdpbiUyME1hcnklMjBhbGxlZ2VkbHklMjBhcHBlYXIlMjBpbiUyMDE4NTglMjBpbiUyMExvdXJkZXMlMjBGcmFuY2UlM0YlMjAlNUJTRVAlNUQlMjBBcmNoaXRlY3R1cmFsbHklMkMlMjAnJTBBJ3RoZSUyMHNjaG9vbCUyMGhhcyUyMGElMjBDYXRob2xpYyUyMGNoYXJhY3Rlci4lMjBBdG9wJTIwdGhlJTIwTWFpbiUyMEJ1aWxkaW5nJTVDJ3MlMjBnb2xkJTIwZG9tZSUyMGlzJTIwYSUyMGdvbGRlbiUyMHN0YXR1ZSUyMG9mJTIwdGhlJTIwVmlyZ2luJTIwJyUwQSdNYXJ5LiUyMEltbWVkaWF0ZWx5JTIwaW4lMjBmcm9udCUyMG9mJTIwdGhlJTIwTWFpbiUyMEJ1aWxkaW5nJTIwYW5kJTIwZmFjaW5nJTIwaXQlMkMlMjBpcyUyMGElMjBjb3BwZXIlMjBzdGF0dWUlMjBvZiUyMENocmlzdCUyMHdpdGglMjBhcm1zJTIwJyUwQSd1cHJhaXNlZCUyMHdpdGglMjB0aGUlMjBsZWdlbmQlMjAlMjIlMjBWZW5pdGUlMjBBZCUyME1lJTIwT21uZXMlMjAlMjIuJTIwTmV4dCUyMHRvJTIwdGhlJTIwTWFpbiUyMEJ1aWxkaW5nJTIwaXMlMjB0aGUlMjBCYXNpbGljYSUyMG9mJTIwdGhlJTIwU2FjcmVkJTIwJyUwQSdIZWFydC4lMjBJbW1lZGlhdGVseSUyMGJlaGluZCUyMHRoZSUyMGJhc2lsaWNhJTIwaXMlMjB0aGUlMjBHcm90dG8lMkMlMjBhJTIwTWFyaWFuJTIwcGxhY2UlMjBvZiUyMHByYXllciUyMGFuZCUyMHJlZmxlY3Rpb24uJTIwSXQlMjBpcyUyMGElMjAnJTBBJ3JlcGxpY2ElMjBvZiUyMHRoZSUyMGdyb3R0byUyMGF0JTIwTG91cmRlcyUyQyUyMEZyYW5jZSUyMHdoZXJlJTIwdGhlJTIwVmlyZ2luJTIwTWFyeSUyMHJlcHV0ZWRseSUyMGFwcGVhcmVkJTIwdG8lMjBTYWludCUyMEJlcm5hZGV0dGUlMjAnJTBBJ1NvdWJpcm91cyUyMGluJTIwMTg1OC4lMjBBdCUyMHRoZSUyMGVuZCUyMG9mJTIwdGhlJTIwbWFpbiUyMGRyaXZlJTIwKCUyMGFuZCUyMGluJTIwYSUyMGRpcmVjdCUyMGxpbmUlMjB0aGF0JTIwY29ubmVjdHMlMjB0aHJvdWdoJTIwMyUyMHN0YXR1ZXMlMjAnJTBBJ2FuZCUyMHRoZSUyMEdvbGQlMjBEb21lJTIwKSUyQyUyMGlzJTIwYSUyMHNpbXBsZSUyQyUyMG1vZGVybiUyMHN0b25lJTIwc3RhdHVlJTIwb2YlMjBNYXJ5LiUyMCU1QlNFUCU1RCc=",highlighted:`<span class="hljs-string">&#x27;[CLS] To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France? [SEP] Architecturally, &#x27;</span>
<span class="hljs-string">&#x27;the school has a Catholic character. Atop the Main Building\\&#x27;s gold dome is a golden statue of the Virgin &#x27;</span>
<span class="hljs-string">&#x27;Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms &#x27;</span>
<span class="hljs-string">&#x27;upraised with the legend &quot; Venite Ad Me Omnes &quot;. Next to the Main Building is the Basilica of the Sacred &#x27;</span>
<span class="hljs-string">&#x27;Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a &#x27;</span>
<span class="hljs-string">&#x27;replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette &#x27;</span>
<span class="hljs-string">&#x27;Soubirous in 1858. At the end of the main drive ( and in a direct line that connects through 3 statues &#x27;</span>
<span class="hljs-string">&#x27;and the Gold Dome ), is a simple, modern stone statue of Mary. [SEP]&#x27;</span>`,wrap:!1}}),xl=new j({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHF1ZXN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwY29udGV4dCUyQyUwQSUyMCUyMCUyMCUyMG1heF9sZW5ndGglM0QxMDAlMkMlMEElMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEJTIyb25seV9zZWNvbmQlMjIlMkMlMEElMjAlMjAlMjAlMjBzdHJpZGUlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHJldHVybl9vdmVyZmxvd2luZ190b2tlbnMlM0RUcnVlJTJDJTBBKSUwQSUwQWZvciUyMGlkcyUyMGluJTIwaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQodG9rZW5pemVyLmRlY29kZShpZHMpKQ==",highlighted:`inputs = tokenizer(
question,
context,
max_length=<span class="hljs-number">100</span>,
truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
stride=<span class="hljs-number">50</span>,
return_overflowing_tokens=<span class="hljs-literal">True</span>,
)
<span class="hljs-keyword">for</span> ids <span class="hljs-keyword">in</span> inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]:
<span class="hljs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29sZCUyMERvbWUlMjApJTJDJTIwaXMlMjBhJTIwc2ltcGxlJTJDJTIwbW9kZXJuJTIwc3RvbmUlMjBzdGF0dWUlMjBvZiUyME1hcnkuJTIwJTVCU0VQJTVEJw==",highlighted:`<span class="hljs-string">&#x27;[CLS] To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France? [SEP] Architecturally, the school has a Catholic character. Atop the Main Building\\&#x27;s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend &quot; Venite Ad Me Omnes &quot;. Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basi [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France? [SEP] the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend &quot; Venite Ad Me Omnes &quot;. Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France? [SEP] Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive ( and in a direct line that connects through 3 [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France? [SEP]. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive ( and in a direct line that connects through 3 statues and the Gold Dome ), is a simple, modern stone statue of Mary. [SEP]&#x27;</span>`,wrap:!1}}),Vl=new j({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHF1ZXN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwY29udGV4dCUyQyUwQSUyMCUyMCUyMCUyMG1heF9sZW5ndGglM0QxMDAlMkMlMEElMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEJTIyb25seV9zZWNvbmQlMjIlMkMlMEElMjAlMjAlMjAlMjBzdHJpZGUlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHJldHVybl9vdmVyZmxvd2luZ190b2tlbnMlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX29mZnNldHNfbWFwcGluZyUzRFRydWUlMkMlMEEpJTBBaW5wdXRzLmtleXMoKQ==",highlighted:`inputs = tokenizer(
question,
context,
max_length=<span class="hljs-number">100</span>,
truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
stride=<span class="hljs-number">50</span>,
return_overflowing_tokens=<span class="hljs-literal">True</span>,
return_offsets_mapping=<span class="hljs-literal">True</span>,
)
inputs.keys()`,wrap:!1}}),Xl=new j({props:{code:"ZGljdF9rZXlzKCU1QidpbnB1dF9pZHMnJTJDJTIwJ3Rva2VuX3R5cGVfaWRzJyUyQyUyMCdhdHRlbnRpb25fbWFzayclMkMlMjAnb2Zmc2V0X21hcHBpbmcnJTJDJTIwJ292ZXJmbG93X3RvX3NhbXBsZV9tYXBwaW5nJyU1RCk=",highlighted:'dict_keys([<span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;token_type_ids&#x27;</span>, <span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;offset_mapping&#x27;</span>, <span class="hljs-string">&#x27;overflow_to_sample_mapping&#x27;</span>])',wrap:!1}}),vl=new j({props:{code:"aW5wdXRzJTVCJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIlNUQ=",highlighted:'inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>]',wrap:!1}}),$l=new j({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RA==",highlighted:'[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]',wrap:!1}}),Ql=new j({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMiUzQTYlNUQlNUIlMjJxdWVzdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMiUzQTYlNUQlNUIlMjJjb250ZXh0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDEwMCUyQyUwQSUyMCUyMCUyMCUyMHRydW5jYXRpb24lM0QlMjJvbmx5X3NlY29uZCUyMiUyQyUwQSUyMCUyMCUyMCUyMHN0cmlkZSUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSklMEElMEFwcmludChmJTIyVGhlJTIwNCUyMGV4YW1wbGVzJTIwZ2F2ZSUyMCU3QmxlbihpbnB1dHMlNUInaW5wdXRfaWRzJyU1RCklN0QlMjBmZWF0dXJlcy4lMjIpJTBBcHJpbnQoZiUyMkhlcmUlMjBpcyUyMHdoZXJlJTIwZWFjaCUyMGNvbWVzJTIwZnJvbSUzQSUyMCU3QmlucHV0cyU1QidvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyclNUQlN0QuJTIyKQ==",highlighted:`inputs = tokenizer(
raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">2</span>:<span class="hljs-number">6</span>][<span class="hljs-string">&quot;question&quot;</span>],
raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">2</span>:<span class="hljs-number">6</span>][<span class="hljs-string">&quot;context&quot;</span>],
max_length=<span class="hljs-number">100</span>,
truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
stride=<span class="hljs-number">50</span>,
return_overflowing_tokens=<span class="hljs-literal">True</span>,
return_offsets_mapping=<span class="hljs-literal">True</span>,
)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;The 4 examples gave <span class="hljs-subst">{<span class="hljs-built_in">len</span>(inputs[<span class="hljs-string">&#x27;input_ids&#x27;</span>])}</span> features.&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Here is where each comes from: <span class="hljs-subst">{inputs[<span class="hljs-string">&#x27;overflow_to_sample_mapping&#x27;</span>]}</span>.&quot;</span>)`,wrap:!1}}),Fl=new j({props:{code:"J1RoZSUyMDQlMjBleGFtcGxlcyUyMGdhdmUlMjAxOSUyMGZlYXR1cmVzLiclMEEnSGVyZSUyMGlzJTIwd2hlcmUlMjBlYWNoJTIwY29tZXMlMjBmcm9tJTNBJTIwJTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAyJTJDJTIwMiUyQyUyMDIlMkMlMjAyJTJDJTIwMyUyQyUyMDMlMkMlMjAzJTJDJTIwMyUyQyUyMDMlMkMlMjAzJTJDJTIwMyU1RC4n",highlighted:`<span class="hljs-string">&#x27;The 4 examples gave 19 features.&#x27;</span>
<span class="hljs-string">&#x27;Here is where each comes from: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3].&#x27;</span>`,wrap:!1}}),ql=new j({props:{code:"YW5zd2VycyUyMCUzRCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMiUzQTYlNUQlNUIlMjJhbnN3ZXJzJTIyJTVEJTBBc3RhcnRfcG9zaXRpb25zJTIwJTNEJTIwJTVCJTVEJTBBZW5kX3Bvc2l0aW9ucyUyMCUzRCUyMCU1QiU1RCUwQSUw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wb3NpdGlvbnMuYXBwZW5kKGlkeCUyMC0lMjAxKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlkeCUyMCUzRCUyMGNvbnRleHRfZW5kJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2hpbGUlMjBpZHglMjAlM0UlM0QlMjBjb250ZXh0X3N0YXJ0JTIwYW5kJTIwb2Zmc2V0JTVCaWR4JTVEJTVCMSU1RCUyMCUzRSUzRCUyMGVuZF9jaGFyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWR4JTIwLSUzRCUyMDElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbmRfcG9zaXRpb25zLmFwcGVuZChpZHglMjAlMkIlMjAxKSUwQSUwQXN0YXJ0X3Bvc2l0aW9ucyUyQyUyMGVuZF9wb3NpdGlvbnM=",highlighted:`answers = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">2</span>:<span class="hljs-number">6</span>][<span class="hljs-string">&quot;answers&quot;</span>]
start_positions = []
end_positions = []
<span class="hljs-keyword">for</span> i, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(inputs[<span class="hljs-string">&quot;offset_mapping&quot;</span>]):
sample_idx = inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>][i]
answer = answers[sample_idx]
start_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>]
end_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>] + <span class="hljs-built_in">len</span>(answer[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
sequence_ids = inputs.sequence_ids(i)
<span class="hljs-comment"># Find the start and end of the context</span>
idx = <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> sequence_ids[idx] != <span class="hljs-number">1</span>:
idx += <span class="hljs-number">1</span>
context_start = idx
<span class="hljs-keyword">while</span> sequence_ids[idx] == <span class="hljs-number">1</span>:
idx += <span class="hljs-number">1</span>
context_end = idx - <span class="hljs-number">1</span>
<span class="hljs-comment"># If the answer is not fully inside the context, label is (0, 0)</span>
<span class="hljs-keyword">if</span> offset[context_start][<span class="hljs-number">0</span>] &gt; start_char <span class="hljs-keyword">or</span> offset[context_end][<span class="hljs-number">1</span>] &lt; end_char:
start_positions.append(<span class="hljs-number">0</span>)
end_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-keyword">else</span>:
<span class="hljs-comment"># Otherwise it&#x27;s the start and end token positions</span>
idx = context_start
<span class="hljs-keyword">while</span> idx &lt;= context_end <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">0</span>] &lt;= start_char:
idx += <span class="hljs-number">1</span>
start_positions.append(idx - <span class="hljs-number">1</span>)
idx = context_end
<span class="hljs-keyword">while</span> idx &gt;= context_start <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">1</span>] &gt;= end_char:
idx -= <span class="hljs-number">1</span>
end_positions.append(idx + <span class="hljs-number">1</span>)
start_positions, end_positions`,wrap:!1}}),Ll=new j({props:{code:"KCU1QjgzJTJDJTIwNTElMkMlMjAxOSUyQyUyMDAlMkMlMjAwJTJDJTIwNjQlMkMlMjAyNyUyQyUyMDAlMkMlMjAzNCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDY3JTJDJTIwMzQlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RCUyQyUwQSUyMCU1Qjg1JTJDJTIwNTMlMkMlMjAyMSUyQyUyMDAlMkMlMjAwJTJDJTIwNzAlMkMlMjAzMyUyQyUyMDAlMkMlMjA0MCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDY4JTJDJTIwMzUlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RCk=",highlighted:`([<span class="hljs-number">83</span>, <span class="hljs-number">51</span>, <span class="hljs-number">19</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">64</span>, <span class="hljs-number">27</span>, <span class="hljs-number">0</span>, <span class="hljs-number">34</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">67</span>, <span class="hljs-number">34</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
[<span class="hljs-number">85</span>, <span class="hljs-number">53</span>, <span class="hljs-number">21</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">70</span>, <span class="hljs-number">33</span>, <span class="hljs-number">0</span>, <span class="hljs-number">40</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">68</span>, <span class="hljs-number">35</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>])`,wrap:!1}}),Kl=new j({props:{code:"aWR4JTIwJTNEJTIwMCUwQXNhbXBsZV9pZHglMjAlM0QlMjBpbnB1dHMlNUIlMjJvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyUyMiU1RCU1QmlkeCU1RCUwQWFuc3dlciUyMCUzRCUyMGFuc3dlcnMlNUJzYW1wbGVfaWR4JTVEJTVCJTIydGV4dCUyMiU1RCU1QjAlNUQlMEElMEFzdGFydCUyMCUzRCUyMHN0YXJ0X3Bvc2l0aW9ucyU1QmlkeCU1RCUwQWVuZCUyMCUzRCUyMGVuZF9wb3NpdGlvbnMlNUJpZHglNUQlMEFsYWJlbGVkX2Fuc3dlciUyMCUzRCUyMHRva2VuaXplci5kZWNvZGUoaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTVCaWR4JTVEJTVCc3RhcnQlMjAlM0ElMjBlbmQlMjAlMkIlMjAxJTVEKSUwQSUwQXByaW50KGYlMjJUaGVvcmV0aWNhbCUyMGFuc3dlciUzQSUyMCU3QmFuc3dlciU3RCUyQyUyMGxhYmVscyUyMGdpdmUlM0ElMjAlN0JsYWJlbGVkX2Fuc3dlciU3RCUyMik=",highlighted:`idx = <span class="hljs-number">0</span>
sample_idx = inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>][idx]
answer = answers[sample_idx][<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>]
start = start_positions[idx]
end = end_positions[idx]
labeled_answer = tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>][idx][start : end + <span class="hljs-number">1</span>])
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Theoretical answer: <span class="hljs-subst">{answer}</span>, labels give: <span class="hljs-subst">{labeled_answer}</span>&quot;</span>)`,wrap:!1}}),Pl=new j({props:{code:"J1RoZW9yZXRpY2FsJTIwYW5zd2VyJTNBJTIwdGhlJTIwTWFpbiUyMEJ1aWxkaW5nJTJDJTIwbGFiZWxzJTIwZ2l2ZSUzQSUyMHRoZSUyME1haW4lMjBCdWlsZGluZyc=",highlighted:'<span class="hljs-string">&#x27;Theoretical answer: the Main Building, labels give: the Main Building&#x27;</span>',wrap:!1}}),et=new j({props:{code:"aWR4JTIwJTNEJTIwNCUwQXNhbXBsZV9pZHglMjAlM0QlMjBpbnB1dHMlNUIlMjJvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyUyMiU1RCU1QmlkeCU1RCUwQWFuc3dlciUyMCUzRCUyMGFuc3dlcnMlNUJzYW1wbGVfaWR4JTVEJTVCJTIydGV4dCUyMiU1RCU1QjAlNUQlMEElMEFkZWNvZGVkX2V4YW1wbGUlMjAlM0QlMjB0b2tlbml6ZXIuZGVjb2RlKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCU1QmlkeCU1RCklMEFwcmludChmJTIyVGhlb3JldGljYWwlMjBhbnN3ZXIlM0ElMjAlN0JhbnN3ZXIlN0QlMkMlMjBkZWNvZGVkJTIwZXhhbXBsZSUzQSUyMCU3QmRlY29kZWRfZXhhbXBsZSU3RCUyMik=",highlighted:`idx = <span class="hljs-number">4</span>
sample_idx = inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>][idx]
answer = answers[sample_idx][<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>]
decoded_example = tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>][idx])
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Theoretical answer: <span class="hljs-subst">{answer}</span>, decoded example: <span class="hljs-subst">{decoded_example}</span>&quot;</span>)`,wrap:!1}}),lt=new j({props:{code:"J1RoZW9yZXRpY2FsJTIwYW5zd2VyJTNBJTIwYSUyME1hcmlhbiUyMHBsYWNlJTIwb2YlMjBwcmF5ZXIlMjBhbmQlMjByZWZsZWN0aW9uJTJDJTIwZGVjb2RlZCUyMGV4YW1wbGUlM0ElMjAlNUJDTFMlNUQlMjBXaGF0JTIwaXMlMjB0aGUlMjBHcm90dG8lMjBhdCUyME5vdHJlJTIwRGFtZSUzRiUyMCU1QlNFUCU1RCUyMEFyY2hpdGVjdHVyYWxseSUyQyUyMHRoZSUyMHNjaG9vbCUyMGhhcyUyMGElMjBDYXRob2xpYyUyMGNoYXJhY3Rlci4lMjBBdG9wJTIwdGhlJTIwTWFpbiUyMEJ1aWxkaW5nJTVDJ3MlMjBnb2xkJTIwZG9tZSUyMGlzJTIwYSUyMGdvbGRlbiUyMHN0YXR1ZSUyMG9mJTIwdGhlJTIwVmlyZ2luJTIwTWFyeS4lMjBJbW1lZGlhdGVseSUyMGluJTIwZnJvbnQlMjBvZiUyMHRoZSUyME1haW4lMjBCdWlsZGluZyUyMGFuZCUyMGZhY2luZyUyMGl0JTJDJTIwaXMlMjBhJTIwY29wcGVyJTIwc3RhdHVlJTIwb2YlMjBDaHJpc3QlMjB3aXRoJTIwYXJtcyUyMHVwcmFpc2VkJTIwd2l0aCUyMHRoZSUyMGxlZ2VuZCUyMCUyMiUyMFZlbml0ZSUyMEFkJTIwTWUlMjBPbW5lcyUyMCUyMi4lMjBOZXh0JTIwdG8lMjB0aGUlMjBNYWluJTIwQnVpbGRpbmclMjBpcyUyMHRoZSUyMEJhc2lsaWNhJTIwb2YlMjB0aGUlMjBTYWNyZWQlMjBIZWFydC4lMjBJbW1lZGlhdGVseSUyMGJlaGluZCUyMHRoZSUyMGJhc2lsaWNhJTIwaXMlMjB0aGUlMjBHcm90JTIwJTVCU0VQJTVEJw==",highlighted:'<span class="hljs-string">&#x27;Theoretical answer: a Marian place of prayer and reflection, decoded example: [CLS] What is the Grotto at Notre Dame? [SEP] Architecturally, the school has a Catholic character. Atop the Main Building\\&#x27;s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend &quot; Venite Ad Me Omnes &quot;. Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grot [SEP]&#x27;</span>',wrap:!1}}),at=new j({props:{code:"bWF4X2xlbmd0aCUyMCUzRCUyMDM4NCUwQXN0cmlkZSUyMCUzRCUyMDEyOCUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfdHJhaW5pbmdfZXhhbXBsZXMoZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwcXVlc3Rpb25zJTIwJTNEJTIwJTVCcS5zdHJpcCgpJTIwZm9yJTIwcSUyMGluJTIwZXhhbXBsZXMlNUIlMjJxdWVzdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBxdWVzdGlvbnMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMmNvbnRleHQlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtYXhfbGVuZ3RoJTNEbWF4X2xlbm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yMGlkeCUyMCUyQiUzRCUyMDElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzdGFydF9wb3NpdGlvbnMuYXBwZW5kKGlkeCUyMC0lMjAxKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlkeCUyMCUzRCUyMGNvbnRleHRfZW5kJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2hpbGUlMjBpZHglMjAlM0UlM0QlMjBjb250ZXh0X3N0YXJ0JTIwYW5kJTIwb2Zmc2V0JTVCaWR4JTVEJTVCMSU1RCUyMCUzRSUzRCUyMGVuZF9jaGFyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWR4JTIwLSUzRCUyMDElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbmRfcG9zaXRpb25zLmFwcGVuZChpZHglMjAlMkIlMjAxKSUwQSUwQSUyMCUyMCUyMCUyMGlucHV0cyU1QiUyMnN0YXJ0X3Bvc2l0aW9ucyUyMiU1RCUyMCUzRCUyMHN0YXJ0X3Bvc2l0aW9ucyUwQSUyMCUyMCUyMCUyMGlucHV0cyU1QiUyMmVuZF9wb3NpdGlvbnMlMjIlNUQlMjAlM0QlMjBlbmRfcG9zaXRpb25zJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW5wdXRz",highlighted:`max_length = <span class="hljs-number">384</span>
stride = <span class="hljs-number">128</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_training_examples</span>(<span class="hljs-params">examples</span>):
questions = [q.strip() <span class="hljs-keyword">for</span> q <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;question&quot;</span>]]
inputs = tokenizer(
questions,
examples[<span class="hljs-string">&quot;context&quot;</span>],
max_length=max_length,
truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
stride=stride,
return_overflowing_tokens=<span class="hljs-literal">True</span>,
return_offsets_mapping=<span class="hljs-literal">True</span>,
padding=<span class="hljs-string">&quot;max_length&quot;</span>,
)
offset_mapping = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)
sample_map = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
answers = examples[<span class="hljs-string">&quot;answers&quot;</span>]
start_positions = []
end_positions = []
<span class="hljs-keyword">for</span> i, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(offset_mapping):
sample_idx = sample_map[i]
answer = answers[sample_idx]
start_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>]
end_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>] + <span class="hljs-built_in">len</span>(answer[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
sequence_ids = inputs.sequence_ids(i)
<span class="hljs-comment"># Find the start and end of the context</span>
idx = <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> sequence_ids[idx] != <span class="hljs-number">1</span>:
idx += <span class="hljs-number">1</span>
context_start = idx
<span class="hljs-keyword">while</span> sequence_ids[idx] == <span class="hljs-number">1</span>:
idx += <span class="hljs-number">1</span>
context_end = idx - <span class="hljs-number">1</span>
<span class="hljs-comment"># If the answer is not fully inside the context, label is (0, 0)</span>
<span class="hljs-keyword">if</span> offset[context_start][<span class="hljs-number">0</span>] &gt; start_char <span class="hljs-keyword">or</span> offset[context_end][<span class="hljs-number">1</span>] &lt; end_char:
start_positions.append(<span class="hljs-number">0</span>)
end_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-keyword">else</span>:
<span class="hljs-comment"># Otherwise it&#x27;s the start and end token positions</span>
idx = context_start
<span class="hljs-keyword">while</span> idx &lt;= context_end <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">0</span>] &lt;= start_char:
idx += <span class="hljs-number">1</span>
start_positions.append(idx - <span class="hljs-number">1</span>)
idx = context_end
<span class="hljs-keyword">while</span> idx &gt;= context_start <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">1</span>] &gt;= end_char:
idx -= <span class="hljs-number">1</span>
end_positions.append(idx + <span class="hljs-number">1</span>)
inputs[<span class="hljs-string">&quot;start_positions&quot;</span>] = start_positions
inputs[<span class="hljs-string">&quot;end_positions&quot;</span>] = end_positions
<span class="hljs-keyword">return</span> inputs`,wrap:!1}}),Mt=new j({props:{code:"dHJhaW5fZGF0YXNldCUyMCUzRCUyMHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELm1hcCglMEElMjAlMjAlMjAlMjBwcmVwcm9jZXNzX3RyYWluaW5nX2V4YW1wbGVzJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hlZCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfY29sdW1ucyUzRHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELmNvbHVtbl9uYW1lcyUyQyUwQSklMEFsZW4ocmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQpJTJDJTIwbGVuKHRyYWluX2RhdGFzZXQp",highlighted:`train_dataset = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].<span class="hljs-built_in">map</span>(
preprocess_training_examples,
batched=<span class="hljs-literal">True</span>,
remove_columns=raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names,
)
<span class="hljs-built_in">len</span>(raw_datasets[<span class="hljs-string">&quot;train&quot;</span>]), <span class="hljs-built_in">len</span>(train_dataset)`,wrap:!1}}),ot=new j({props:{code:"KDg3NTk5JTJDJTIwODg3Mjkp",highlighted:'(<span class="hljs-number">87599</span>, <span class="hljs-number">88729</span>)',wrap:!1}}),rt=new le({props:{title:"Processing the validation data",local:"processing-the-validation-data",headingTag:"h3"}}),dt=new j({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc192YWxpZGF0aW9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aWRzJTIyJTVEKSklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzYW1wbGVfaWR4JTIwJTNEJTIwc2FtcGxlX21hcCU1QmklNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBleGFtcGxlX2lkcy5hcHBlbmQoZXhhbXBsZXMlNUIlMjJpZCUyMiU1RCU1QnNhbXBsZV9pZHglNUQpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcyhpKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9mZnNldCUyMCUzRCUyMGlucHV0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTVCaSU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlucHV0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTVCaSU1RCUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG8lMjBpZiUyMHNlcXVlbmNlX2lkcyU1QmslNUQlMjAlM0QlM0QlMjAxJTIwZWxzZSUyME5vbmUlMjBmb3IlMjBrJTJDJTIwbyUyMGluJTIwZW51bWVyYXRlKG9mZnNldCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUQlMEElMEElMjAlMjAlMjAlMjBpbnB1dHMlNUIlMjJleGFtcGxlX2lkJTIyJTVEJTIwJTNEJTIwZXhhbXBsZV9pZHMlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHM=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_validation_examples</span>(<span class="hljs-params">examples</span>):
questions = [q.strip() <span class="hljs-keyword">for</span> q <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;question&quot;</span>]]
inputs = tokenizer(
questions,
examples[<span class="hljs-string">&quot;context&quot;</span>],
max_length=max_length,
truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
stride=stride,
return_overflowing_tokens=<span class="hljs-literal">True</span>,
return_offsets_mapping=<span class="hljs-literal">True</span>,
padding=<span class="hljs-string">&quot;max_length&quot;</span>,
)
sample_map = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
example_ids = []
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])):
sample_idx = sample_map[i]
example_ids.append(examples[<span class="hljs-string">&quot;id&quot;</span>][sample_idx])
sequence_ids = inputs.sequence_ids(i)
offset = inputs[<span class="hljs-string">&quot;offset_mapping&quot;</span>][i]
inputs[<span class="hljs-string">&quot;offset_mapping&quot;</span>][i] = [
o <span class="hljs-keyword">if</span> sequence_ids[k] == <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">for</span> k, o <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(offset)
]
inputs[<span class="hljs-string">&quot;example_id&quot;</span>] = example_ids
<span class="hljs-keyword">return</span> inputs`,wrap:!1}}),ht=new j({props:{code:"dmFsaWRhdGlvbl9kYXRhc2V0JTIwJTNEJTIwcmF3X2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RC5tYXAoJTBBJTIwJTIwJTIwJTIwcHJlcHJvY2Vzc192YWxpZGF0aW9uX2V4YW1wbGVzJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hlZCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfY29sdW1ucyUzRHJhd19kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQuY29sdW1uX25hbWVzJTJDJTBBKSUwQWxlbihyYXdfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEKSUyQyUyMGxlbih2YWxpZGF0aW9uX2RhdGFzZXQp",highlighted:`validation_dataset = raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>].<span class="hljs-built_in">map</span>(
preprocess_validation_examples,
batched=<span class="hljs-literal">True</span>,
remove_columns=raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>].column_names,
)
<span class="hljs-built_in">len</span>(raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>]), <span class="hljs-built_in">len</span>(validation_dataset)`,wrap:!1}}),Jt=new j({props:{code:"KDEwNTcwJTJDJTIwMTA4MjIp",highlighted:'(<span class="hljs-number">10570</span>, <span class="hljs-number">10822</span>)',wrap:!1}});const uM=[DM,LM],ds=[];function mM(e,t){return e[0]==="pt"?0:1}Je=mM(k),ue=ds[Je]=uM[Je](k),Ut=new le({props:{title:"Post-processing",local:"post-processing",headingTag:"h3"}});const UM=[PM,KM],ws=[];function TM(e,t){return e[0]==="pt"?0:1}me=TM(k),Ue=ws[me]=UM[me](k),ft=new j({props:{code:"c21hbGxfZXZhbF9zZXQlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVELnNlbGVjdChyYW5nZSgxMDApKSUwQXRyYWluZWRfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS1jYXNlZC1kaXN0aWxsZWQtc3F1YWQlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCh0cmFpbmVkX2NoZWNrcG9pbnQpJTBBZXZhbF9zZXQlMjAlM0QlMjBzbWFsbF9ldmFsX3NldC5tYXAoJTBBJTIwJTIwJTIwJTIwcHJlcHJvY2Vzc192YWxpZGF0aW9uX2V4YW1wbGVzJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hlZCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfY29sdW1ucyUzRHJhd19kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQuY29sdW1uX25hbWVzJTJDJTBBKQ==",highlighted:`small_eval_set = raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>].select(<span class="hljs-built_in">range</span>(<span class="hljs-number">100</span>))
trained_checkpoint = <span class="hljs-string">&quot;distilbert-base-cased-distilled-squad&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(trained_checkpoint)
eval_set = small_eval_set.<span class="hljs-built_in">map</span>(
preprocess_validation_examples,
batched=<span class="hljs-literal">True</span>,
remove_columns=raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>].column_names,
)`,wrap:!1}}),Ct=new j({props:{code:"dG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:"tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)",wrap:!1}});const jM=[eo,OM],hs=[];function bM(e,t){return e[0]==="pt"?0:1}Te=bM(k),je=hs[Te]=jM[Te](k),Gt=new j({props:{code:"aW1wb3J0JTIwY29sbGVjdGlvbnMlMEElMEFleGFtcGxlX3RvX2ZlYXR1cmVzJTIwJTNEJTIwY29sbGVjdGlvbnMuZGVmYXVsdGRpY3QobGlzdCklMEFmb3IlMjBpZHglMkMlMjBmZWF0dXJlJTIwaW4lMjBlbnVtZXJhdGUoZXZhbF9zZXQpJTNBJTBBJTIwJTIwJTIwJTIwZXhhbXBsZV90b19mZWF0dXJlcyU1QmZlYXR1cmUlNUIlMjJleGFtcGxlX2lkJTIyJTVEJTVELmFwcGVuZChpZHgp",highlighted:`<span class="hljs-keyword">import</span> collections
example_to_features = collections.defaultdict(<span class="hljs-built_in">list</span>)
<span class="hljs-keyword">for</span> idx, feature <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(eval_set):
example_to_features[feature[<span class="hljs-string">&quot;example_id&quot;</span>]].append(idx)`,wrap:!1}}),_t=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJ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X2luZGV4JTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMGJlc3RfYW5zd2VyJTIwJTNEJTIwbWF4KGFuc3dlcnMlMkMlMjBrZXklM0RsYW1iZGElMjB4JTNBJTIweCU1QiUyMmxvZ2l0X3Njb3JlJTIyJTVEKSUwQSUyMCUyMCUyMCUyMHByZWRpY3RlZF9hbnN3ZXJzLmFwcGVuZCglN0IlMjJpZCUyMiUzQSUyMGV4YW1wbGVfaWQlMkMlMjAlMjJwcmVkaWN0aW9uX3RleHQlMjIlM0ElMjBiZXN0X2Fuc3dlciU1QiUyMnRleHQlMjIlNUQlN0Qp",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
n_best = <span class="hljs-number">20</span>
max_answer_length = <span class="hljs-number">30</span>
predicted_answers = []
<span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> small_eval_set:
example_id = example[<span class="hljs-string">&quot;id&quot;</span>]
context = example[<span class="hljs-string">&quot;context&quot;</span>]
answers = []
<span class="hljs-keyword">for</span> feature_index <span class="hljs-keyword">in</span> example_to_features[example_id]:
start_logit = start_logits[feature_index]
end_logit = end_logits[feature_index]
offsets = eval_set[<span class="hljs-string">&quot;offset_mapping&quot;</span>][feature_index]
start_indexes = np.argsort(start_logit)[-<span class="hljs-number">1</span> : -n_best - <span class="hljs-number">1</span> : -<span class="hljs-number">1</span>].tolist()
end_indexes = np.argsort(end_logit)[-<span class="hljs-number">1</span> : -n_best - <span class="hljs-number">1</span> : -<span class="hljs-number">1</span>].tolist()
<span class="hljs-keyword">for</span> start_index <span class="hljs-keyword">in</span> start_indexes:
<span class="hljs-keyword">for</span> end_index <span class="hljs-keyword">in</span> end_indexes:
<span class="hljs-comment"># Skip answers that are not fully in the context</span>
<span class="hljs-keyword">if</span> offsets[start_index] <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">or</span> offsets[end_index] <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-keyword">continue</span>
<span class="hljs-comment"># Skip answers with a length that is either &lt; 0 or &gt; max_answer_length.</span>
<span class="hljs-keyword">if</span> (
end_index &lt; start_index
<span class="hljs-keyword">or</span> end_index - start_index + <span class="hljs-number">1</span> &gt; max_answer_length
):
<span class="hljs-keyword">continue</span>
answers.append(
{
<span class="hljs-string">&quot;text&quot;</span>: context[offsets[start_index][<span class="hljs-number">0</span>] : offsets[end_index][<span class="hljs-number">1</span>]],
<span class="hljs-string">&quot;logit_score&quot;</span>: start_logit[start_index] + end_logit[end_index],
}
)
best_answer = <span class="hljs-built_in">max</span>(answers, key=<span class="hljs-keyword">lambda</span> x: x[<span class="hljs-string">&quot;logit_score&quot;</span>])
predicted_answers.append({<span class="hljs-string">&quot;id&quot;</span>: example_id, <span class="hljs-string">&quot;prediction_text&quot;</span>: best_answer[<span class="hljs-string">&quot;text&quot;</span>]})`,wrap:!1}}),At=new j({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNxdWFkJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> evaluate
metric = evaluate.load(<span class="hljs-string">&quot;squad&quot;</span>)`,wrap:!1}}),Xt=new j({props:{code:"dGhlb3JldGljYWxfYW5zd2VycyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUyMmlkJTIyJTNBJTIwZXglNUIlMjJpZCUyMiU1RCUyQyUyMCUyMmFuc3dlcnMlMjIlM0ElMjBleCU1QiUyMmFuc3dlcnMlMjIlNUQlN0QlMjBmb3IlMjBleCUyMGluJTIwc21hbGxfZXZhbF9zZXQlMEElNUQ=",highlighted:`theoretical_answers = [
{<span class="hljs-string">&quot;id&quot;</span>: ex[<span class="hljs-string">&quot;id&quot;</span>], <span class="hljs-string">&quot;answers&quot;</span>: ex[<span class="hljs-string">&quot;answers&quot;</span>]} <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> small_eval_set
]`,wrap:!1}}),vt=new j({props:{code:"cHJpbnQocHJlZGljdGVkX2Fuc3dlcnMlNUIwJTVEKSUwQXByaW50KHRoZW9yZXRpY2FsX2Fuc3dlcnMlNUIwJTVEKQ==",highlighted:`<span class="hljs-built_in">print</span>(predicted_answers[<span class="hljs-number">0</span>])
<span class="hljs-built_in">print</span>(theoretical_answers[<span class="hljs-number">0</span>])`,wrap:!1}}),$t=new j({props:{code:"JTdCJ2lkJyUzQSUyMCc1NmJlNGRiMGFjYjgwMDE0MDBhNTAyZWMnJTJDJTIwJ3ByZWRpY3Rpb25fdGV4dCclM0ElMjAnRGVudmVyJTIwQnJvbmNvcyclN0QlMEElN0InaWQnJTNBJTIwJzU2YmU0ZGIwYWNiODAwMTQwMGE1MDJlYyclMkMlMjAnYW5zd2VycyclM0ElMjAlN0IndGV4dCclM0ElMjAlNUInRGVudmVyJTIwQnJvbmNvcyclMkMlMjAnRGVudmVyJTIwQnJvbmNvcyclMkMlMjAnRGVudmVyJTIwQnJvbmNvcyclNUQlMkMlMjAnYW5zd2VyX3N0YXJ0JyUzQSUyMCU1QjE3NyUyQyUyMDE3NyUyQyUyMDE3NyU1RCU3RCU3RA==",highlighted:`{<span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;56be4db0acb8001400a502ec&#x27;</span>, <span class="hljs-string">&#x27;prediction_text&#x27;</span>: <span class="hljs-string">&#x27;Denver Broncos&#x27;</span>}
{<span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;56be4db0acb8001400a502ec&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>: {<span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Denver Broncos&#x27;</span>, <span class="hljs-string">&#x27;Denver Broncos&#x27;</span>, <span class="hljs-string">&#x27;Denver Broncos&#x27;</span>], <span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">177</span>, <span class="hljs-number">177</span>, <span class="hljs-number">177</span>]}}`,wrap:!1}}),Qt=new j({props:{code:"bWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RwcmVkaWN0ZWRfYW5zd2VycyUyQyUyMHJlZmVyZW5jZXMlM0R0aGVvcmV0aWNhbF9hbnN3ZXJzKQ==",highlighted:"metric.compute(predictions=predicted_answers, references=theoretical_answers)",wrap:!1}}),Ft=new j({props:{code:"JTdCJ2V4YWN0X21hdGNoJyUzQSUyMDgzLjAlMkMlMjAnZjEnJTNBJTIwODguMjUlN0Q=",highlighted:'{<span class="hljs-string">&#x27;exact_match&#x27;</span>: <span class="hljs-number">83.0</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">88.25</span>}',wrap:!1}});function fM(e,t){return e[0]==="pt"?to:lo}let Hn=fM(k),De=Hn(k);Yt=new j({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEElMEElMEFkZWYlMjBjb21wdXRlX21ldHJpY3Moc3RhcnRfbG9naXRzJTJDJTIwZW5kX2xvZ2l0cyUyQyUyMGZlYXR1cmVzJTJDJTIwZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwZXhhbXBsZV90b19mZWF0dXJlcyUyMCUzRCUyMGNvbGxlY3Rpb25zLmRlZmF1bHRkaWN0KGxpc3QpJTBBJTIwJTIwJTIwJTIwZm9yJTIwaWR4JTJDJTIwZmVhdHVyZSUyMGluJTIwZW51bWVyYXRlKGZlYXR1cmVzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGV4YW1wbGVfdG9fZmVhdHVyZXMlNUJmZWF0dXJlJTVCJTIyZXhhbXBsZV9pZCUy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glMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0IlMjJpZCUyMiUzQSUyMGV4YW1wbGVfaWQlMkMlMjAlMjJwcmVkaWN0aW9uX3RleHQlMjIlM0ElMjBiZXN0X2Fuc3dlciU1QiUyMnRleHQlMjIlNUQlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZWxzZSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByZWRpY3RlZF9hbnN3ZXJzLmFwcGVuZCglN0IlMjJpZCUyMiUzQSUyMGV4YW1wbGVfaWQlMkMlMjAlMjJwcmVkaWN0aW9uX3RleHQlMjIlM0ElMjAlMjIlMjIlN0QpJTBBJTBBJTIwJTIwJTIwJTIwdGhlb3JldGljYWxfYW5zd2VycyUyMCUzRCUyMCU1QiU3QiUyMmlkJTIyJTNBJTIwZXglNUIlMjJpZCUyMiU1RCUyQyUyMCUyMmFuc3dlcnMlMjIlM0ElMjBleCU1QiUyMmFuc3dlcnMlMjIlNUQlN0QlMjBmb3IlMjBleCUyMGluJTIwZXhhbXBsZXMlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBtZXRyaWMuY29tcHV0ZShwcmVkaWN0aW9ucyUzRHByZWRpY3RlZF9hbnN3ZXJzJTJDJTIwcmVmZXJlbmNlcyUzRHRoZW9yZXRpY2FsX2Fuc3dlcnMp",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">start_logits, end_logits, features, examples</span>):
example_to_features = collections.defaultdict(<span class="hljs-built_in">list</span>)
<span class="hljs-keyword">for</span> idx, feature <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(features):
example_to_features[feature[<span class="hljs-string">&quot;example_id&quot;</span>]].append(idx)
predicted_answers = []
<span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> tqdm(examples):
example_id = example[<span class="hljs-string">&quot;id&quot;</span>]
context = example[<span class="hljs-string">&quot;context&quot;</span>]
answers = []
<span class="hljs-comment"># Loop through all features associated with that example</span>
<span class="hljs-keyword">for</span> feature_index <span class="hljs-keyword">in</span> example_to_features[example_id]:
start_logit = start_logits[feature_index]
end_logit = end_logits[feature_index]
offsets = features[feature_index][<span class="hljs-string">&quot;offset_mapping&quot;</span>]
start_indexes = np.argsort(start_logit)[-<span class="hljs-number">1</span> : -n_best - <span class="hljs-number">1</span> : -<span class="hljs-number">1</span>].tolist()
end_indexes = np.argsort(end_logit)[-<span class="hljs-number">1</span> : -n_best - <span class="hljs-number">1</span> : -<span class="hljs-number">1</span>].tolist()
<span class="hljs-keyword">for</span> start_index <span class="hljs-keyword">in</span> start_indexes:
<span class="hljs-keyword">for</span> end_index <span class="hljs-keyword">in</span> end_indexes:
<span class="hljs-comment"># Skip answers that are not fully in the context</span>
<span class="hljs-keyword">if</span> offsets[start_index] <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">or</span> offsets[end_index] <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-keyword">continue</span>
<span class="hljs-comment"># Skip answers with a length that is either &lt; 0 or &gt; max_answer_length</span>
<span class="hljs-keyword">if</span> (
end_index &lt; start_index
<span class="hljs-keyword">or</span> end_index - start_index + <span class="hljs-number">1</span> &gt; max_answer_length
):
<span class="hljs-keyword">continue</span>
answer = {
<span class="hljs-string">&quot;text&quot;</span>: context[offsets[start_index][<span class="hljs-number">0</span>] : offsets[end_index][<span class="hljs-number">1</span>]],
<span class="hljs-string">&quot;logit_score&quot;</span>: start_logit[start_index] + end_logit[end_index],
}
answers.append(answer)
<span class="hljs-comment"># Select the answer with the best score</span>
<span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(answers) &gt; <span class="hljs-number">0</span>:
best_answer = <span class="hljs-built_in">max</span>(answers, key=<span class="hljs-keyword">lambda</span> x: x[<span class="hljs-string">&quot;logit_score&quot;</span>])
predicted_answers.append(
{<span class="hljs-string">&quot;id&quot;</span>: example_id, <span class="hljs-string">&quot;prediction_text&quot;</span>: best_answer[<span class="hljs-string">&quot;text&quot;</span>]}
)
<span class="hljs-keyword">else</span>:
predicted_answers.append({<span class="hljs-string">&quot;id&quot;</span>: example_id, <span class="hljs-string">&quot;prediction_text&quot;</span>: <span class="hljs-string">&quot;&quot;</span>})
theoretical_answers = [{<span class="hljs-string">&quot;id&quot;</span>: ex[<span class="hljs-string">&quot;id&quot;</span>], <span class="hljs-string">&quot;answers&quot;</span>: ex[<span class="hljs-string">&quot;answers&quot;</span>]} <span class="hljs-keyword">for</span> ex <span class="hljs-keyword">in</span> examples]
<span class="hljs-keyword">return</span> metric.compute(predictions=predicted_answers, references=theoretical_answers)`,wrap:!1}}),Ht=new j({props:{code:"Y29tcHV0ZV9tZXRyaWNzKHN0YXJ0X2xvZ2l0cyUyQyUyMGVuZF9sb2dpdHMlMkMlMjBldmFsX3NldCUyQyUyMHNtYWxsX2V2YWxfc2V0KQ==",highlighted:"compute_metrics(start_logits, end_logits, eval_set, small_eval_set)",wrap:!1}}),St=new j({props:{code:"JTdCJ2V4YWN0X21hdGNoJyUzQSUyMDgzLjAlMkMlMjAnZjEnJTNBJTIwODguMjUlN0Q=",highlighted:'{<span class="hljs-string">&#x27;exact_match&#x27;</span>: <span class="hljs-number">83.0</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">88.25</span>}',wrap:!1}}),Lt=new le({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}});const IM=[ao,so],Js=[];function CM(e,t){return e[0]==="pt"?0:1}be=CM(k),fe=Js[be]=IM[be](k),Pt=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}}),es=new j({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}});const gM=[io,no],us=[];function ZM(e,t){return e[0]==="pt"?0:1}Ie=ZM(k),Ce=us[Ie]=gM[Ie](k);const GM=[oo,Mo],ms=[];function BM(e,t){return e[0]==="pt"?0:1}ge=BM(k),Ze=ms[ge]=GM[ge](k);const kM=[ro,po],Us=[];function xM(e,t){return e[0]==="pt"?0:1}Ge=xM(k),Be=Us[Ge]=kM[Ge](k),ss=new j({props:{code:"JTdCJ2V4YWN0X21hdGNoJyUzQSUyMDgxLjE4MjU5MjI0MjE5NDg5JTJDJTIwJ2YxJyUzQSUyMDg4LjY3MzgxMzIxOTA1NTE2JTdE",highlighted:'{<span class="hljs-string">&#x27;exact_match&#x27;</span>: <span class="hljs-number">81.18259224219489</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">88.67381321905516</span>}',wrap:!1}});let R=k[0]==="pt"&&_M(),v=k[0]==="pt"&&WM();return is=new le({props:{title:"Using the fine-tuned model",local:"using-the-fine-tuned-model",headingTag:"h2"}}),os=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTIzJTIwUmVwbGFjZSUyMHRoaXMlMjB3aXRoJTIweW91ciUyMG93biUyMGNoZWNrcG9pbnQlMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGYmVydC1maW5ldHVuZWQtc3F1YWQlMjIlMEFxdWVzdGlvbl9hbnN3ZXJlciUyMCUzRCUyMHBpcGVsaW5lKCUyMnF1ZXN0aW9uLWFuc3dlcmluZyUyMiUyQyUyMG1vZGVsJTNEbW9kZWxfY2hlY2twb2ludCklMEElMEFjb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTIwaXMlMjBiYWNrZWQlMjBieSUyMHRoZSUyMHRocmVlJTIwbW9zdCUyMHBvcHVsYXIlMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjAlRTIlODAlOTQlMjBKYXglMkMlMjBQeVRvcmNoJTIwYW5kJTIwVGVuc29yRmxvdyUyMCVFMiU4MCU5NCUyMHdpdGglMjBhJTIwc2VhbWxlc3MlMjBpbnRlZ3JhdGlvbiUwQWJldHdlZW4lMjB0aGVtLiUyMEl0J3MlMjBzdHJhaWdodGZvcndhcmQlMjB0byUyMHRyYWluJTIweW91ciUyMG1vZGVscyUyMHdpdGglMjBvbmUlMjBiZWZvcmUlMjBsb2FkaW5nJTIwdGhlbSUyMGZvciUyMGluZmVyZW5jZSUyMHdpdGglMjB0aGUlMjBvdGhlci4lMEElMjIlMjIlMjIlMEFxdWVzdGlvbiUyMCUzRCUyMCUyMldoaWNoJTIwZGVlcCUyMGxlYXJuaW5nJTIwbGlicmFyaWVzJTIwYmFjayUyMCVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUzRiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEY29udGV4dCk=",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/bert-finetuned-squad&quot;</span>
question_answerer = pipeline(<span class="hljs-string">&quot;question-answering&quot;</span>, model=model_checkpoint)
context = <span class="hljs-string">&quot;&quot;&quot;
🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch and TensorFlow — with a seamless integration
between them. It&#x27;s straightforward to train your models with one before loading them for inference with the other.
&quot;&quot;&quot;</span>
question = <span class="hljs-string">&quot;Which deep learning libraries back 🤗 Transformers?&quot;</span>
question_answerer(question=question, context=context)`,wrap:!1}}),ps=new j({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTk3OTAwMzA3MTc4NDk3MyUyQyUwQSUyMCdzdGFydCclM0ElMjA3OCUyQyUwQSUyMCdlbmQnJTNBJTIwMTA1JTJDJTBBJTIwJ2Fuc3dlciclM0ElMjAnSmF4JTJDJTIwUHlUb3JjaCUyMGFuZCUyMFRlbnNvckZsb3cnJTdE",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9979003071784973</span>,
<span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
<span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),ys=new zM({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter7/7.mdx"}}),{c(){i=c("meta"),T=a(),p=c("p"),h=a(),J(b.$$.fragment),o=a(),J(I.$$.fragment),f=a(),J(C.$$.fragment),_=a(),A.c(),V=a(),Z=c("p"),Z.innerHTML=B,W=a(),J(P.$$.fragment),L=a(),G=c("p"),G.innerHTML=X,te=a(),$=c("iframe"),se=a(),ae=c("p"),ae.innerHTML=ke,tl=a(),O=c("blockquote"),O.innerHTML=xe,Qe=a(),J(N.$$.fragment),sl=a(),ne=c("p"),ne.innerHTML=_e,Fe=a(),J(Q.$$.fragment),al=a(),ie=c("p"),ie.innerHTML=We,Ee=a(),J(F.$$.fragment),Ye=a(),E=c("p"),E.textContent=Ws,ze=a(),J(Y.$$.fragment),He=a(),J(z.$$.fragment),nl=a(),Me=c("p"),Me.innerHTML=Ae,Se=a(),J(H.$$.fragment),il=a(),J(oe.$$.fragment),pe=a(),Ve=c("p"),Ve.innerHTML=Ml,re=a(),Xe=c("p"),Xe.innerHTML=ol,ye=a(),J(ce.$$.fragment),de=a(),J(Re.$$.fragment),qe=a(),S=c("p"),S.textContent=pl,we=a(),J(ve.$$.fragment),Le=a(),J(q.$$.fragment),rl=a(),he=c("p"),he.textContent=M,g=a(),J(yl.$$.fragment),Rs=a(),J(cl.$$.fragment),vs=a(),dl=c("p"),dl.textContent=Mi,$s=a(),J(wl.$$.fragment),Ns=a(),J(hl.$$.fragment),Qs=a(),Jl=c("p"),Jl.textContent=oi,Fs=a(),ul=c("p"),ul.textContent=pi,Es=a(),J(ml.$$.fragment),Ys=a(),Ul=c("p"),Ul.innerHTML=ri,zs=a(),J(Tl.$$.fragment),Hs=a(),J(jl.$$.fragment),Ss=a(),bl=c("p"),bl.textContent=yi,qs=a(),J(fl.$$.fragment),Ls=a(),Il=c("p"),Il.textContent=ci,Ds=a(),J(Cl.$$.fragment),Ks=a(),J(gl.$$.fragment),Ps=a(),Zl=c("p"),Zl.textContent=di,Os=a(),Pe=c("div"),Pe.innerHTML=wi,ea=a(),Gl=c("p"),Gl.innerHTML=hi,la=a(),Bl=c("p"),Bl.textContent=Ji,ta=a(),kl=c("ul"),kl.innerHTML=ui,sa=a(),J(xl.$$.fragment),aa=a(),J(_l.$$.fragment),na=a(),Wl=c("p"),Wl.innerHTML=mi,ia=a(),Al=c("p"),Al.innerHTML=Ui,Ma=a(),J(Vl.$$.fragment),oa=a(),J(Xl.$$.fragment),pa=a(),Rl=c("p"),Rl.innerHTML=Ti,ra=a(),J(vl.$$.fragment),ya=a(),J($l.$$.fragment),ca=a(),Nl=c("p"),Nl.textContent=ji,da=a(),J(Ql.$$.fragment),wa=a(),J(Fl.$$.fragment),ha=a(),El=c("p"),El.textContent=bi,Ja=a(),Yl=c("p"),Yl.textContent=fi,ua=a(),zl=c("ul"),zl.innerHTML=Ii,ma=a(),Hl=c("p"),Hl.innerHTML=Ci,Ua=a(),Sl=c("p"),Sl.innerHTML=gi,Ta=a(),J(ql.$$.fragment),ja=a(),J(Ll.$$.fragment),ba=a(),Dl=c("p"),Dl.innerHTML=Zi,fa=a(),J(Kl.$$.fragment),Ia=a(),J(Pl.$$.fragment),Ca=a(),Ol=c("p"),Ol.innerHTML=Gi,ga=a(),J(et.$$.fragment),Za=a(),J(lt.$$.fragment),Ga=a(),tt=c("p"),tt.textContent=Bi,Ba=a(),Oe=c("blockquote"),Oe.innerHTML=ki,ka=a(),st=c("p"),st.textContent=xi,xa=a(),J(at.$$.fragment),_a=a(),nt=c("p"),nt.textContent=_i,Wa=a(),it=c("p"),it.innerHTML=Wi,Aa=a(),J(Mt.$$.fragment),Va=a(),J(ot.$$.fragment),Xa=a(),pt=c("p"),pt.textContent=Ai,Ra=a(),J(rt.$$.fragment),va=a(),yt=c("p"),yt.textContent=Vi,$a=a(),ct=c("p"),ct.innerHTML=Xi,Na=a(),J(dt.$$.fragment),Qa=a(),wt=c("p"),wt.textContent=Ri,Fa=a(),J(ht.$$.fragment),Ea=a(),J(Jt.$$.fragment),Ya=a(),ut=c("p"),ut.textContent=vi,za=a(),mt=c("p"),mt.textContent=$i,Ha=a(),ue.c(),Ts=a(),J(Ut.$$.fragment),Sa=a(),Ue.c(),js=a(),Tt=c("p"),Tt.innerHTML=Ni,qa=a(),jt=c("ul"),jt.innerHTML=Qi,La=a(),D=c("p"),Ln=Vs("Here we will change this process slightly because we don’t need to compute actual scores (just the predicted answer). This means we can skip the softmax step. To go faster, we also won’t score all the possible "),bs=c("code"),bs.textContent=Fi,Dn=Vs(" pairs, but only the ones corresponding to the highest "),fs=c("code"),fs.textContent=Ei,Kn=Vs(" logits (with "),Is=c("code"),Is.textContent=Yi,Pn=Vs("). Since we will skip the softmax, those scores will be logit scores, and will be obtained by taking the sum of the start and end logits (instead of the product, because of the rule"),Da=new QM(!1),Ka=Vs(")."),Pa=a(),bt=c("p"),bt.innerHTML=zi,Oa=a(),J(ft.$$.fragment),en=a(),It=c("p"),It.textContent=Hi,ln=a(),J(Ct.$$.fragment),tn=a(),gt=c("p"),gt.innerHTML=Si,sn=a(),je.c(),Cs=a(),Zt=c("p"),Zt.innerHTML=qi,an=a(),J(Gt.$$.fragment),nn=a(),Bt=c("p"),Bt.innerHTML=Li,Mn=a(),kt=c("ul"),kt.innerHTML=Di,on=a(),xt=c("p"),xt.textContent=Ki,pn=a(),J(_t.$$.fragment),rn=a(),Wt=c("p"),Wt.textContent=Pi,yn=a(),J(At.$$.fragment),cn=a(),Vt=c("p"),Vt.textContent=Oi,dn=a(),J(Xt.$$.fragment),wn=a(),Rt=c("p"),Rt.textContent=eM,hn=a(),J(vt.$$.fragment),Jn=a(),J($t.$$.fragment),un=a(),Nt=c("p"),Nt.textContent=lM,mn=a(),J(Qt.$$.fragment),Un=a(),J(Ft.$$.fragment),Tn=a(),Et=c("p"),Et.innerHTML=tM,jn=a(),De.c(),gs=a(),J(Yt.$$.fragment),bn=a(),zt=c("p"),zt.textContent=sM,fn=a(),J(Ht.$$.fragment),In=a(),J(St.$$.fragment),Cn=a(),qt=c("p"),qt.textContent=aM,gn=a(),J(Lt.$$.fragment),Zn=a(),fe.c(),Zs=a(),Dt=c("p"),Dt.textContent=nM,Gn=a(),Kt=c("p"),Kt.textContent=iM,Bn=a(),J(Pt.$$.fragment),kn=a(),Ot=c("p"),Ot.textContent=MM,xn=a(),J(es.$$.fragment),_n=a(),Ce.c(),Gs=a(),ls=c("p"),ls.innerHTML=oM,Wn=a(),Ze.c(),Bs=a(),ts=c("p"),ts.textContent=pM,An=a(),Be.c(),ks=a(),J(ss.$$.fragment),Vn=a(),as=c("p"),as.textContent=rM,Xn=a(),R&&R.c(),xs=a(),ns=c("p"),ns.textContent=yM,Rn=a(),el=c("blockquote"),el.innerHTML=cM,vn=a(),v&&v.c(),_s=a(),J(is.$$.fragment),$n=a(),Ms=c("p"),Ms.innerHTML=dM,Nn=a(),J(os.$$.fragment),Qn=a(),J(ps.$$.fragment),Fn=a(),rs=c("p"),rs.textContent=wM,En=a(),J(ys.$$.fragment),Yn=a(),As=c("p"),this.h()},l(e){const t=FM("svelte-u9bgzb",document.head);i=d(t,"META",{name:!0,content:!0}),t.forEach(l),T=n(e),p=d(e,"P",{}),Sn(p).forEach(l),h=n(e),u(b.$$.fragment,e),o=n(e),u(I.$$.fragment,e),f=n(e),u(C.$$.fragment,e),_=n(e),A.l(e),V=n(e),Z=d(e,"P",{"data-svelte-h":!0}),w(Z)!=="svelte-myriyg"&&(Z.innerHTML=B),W=n(e),u(P.$$.fragment,e),L=n(e),G=d(e,"P",{"data-svelte-h":!0}),w(G)!=="svelte-t0si27"&&(G.innerHTML=X),te=n(e),$=d(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Sn($).forEach(l),se=n(e),ae=d(e,"P",{"data-svelte-h":!0}),w(ae)!=="svelte-m6tvk5"&&(ae.innerHTML=ke),tl=n(e),O=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(O)!=="svelte-cy1faf"&&(O.innerHTML=xe),Qe=n(e),u(N.$$.fragment,e),sl=n(e),ne=d(e,"P",{"data-svelte-h":!0}),w(ne)!=="svelte-1p5n70d"&&(ne.innerHTML=_e),Fe=n(e),u(Q.$$.fragment,e),al=n(e),ie=d(e,"P",{"data-svelte-h":!0}),w(ie)!=="svelte-7ye89e"&&(ie.innerHTML=We),Ee=n(e),u(F.$$.fragment,e),Ye=n(e),E=d(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-1knbtwl"&&(E.textContent=Ws),ze=n(e),u(Y.$$.fragment,e),He=n(e),u(z.$$.fragment,e),nl=n(e),Me=d(e,"P",{"data-svelte-h":!0}),w(Me)!=="svelte-ktjy4x"&&(Me.innerHTML=Ae),Se=n(e),u(H.$$.fragment,e),il=n(e),u(oe.$$.fragment,e),pe=n(e),Ve=d(e,"P",{"data-svelte-h":!0}),w(Ve)!=="svelte-tb5lsq"&&(Ve.innerHTML=Ml),re=n(e),Xe=d(e,"P",{"data-svelte-h":!0}),w(Xe)!=="svelte-vaxn0j"&&(Xe.innerHTML=ol),ye=n(e),u(ce.$$.fragment,e),de=n(e),u(Re.$$.fragment,e),qe=n(e),S=d(e,"P",{"data-svelte-h":!0}),w(S)!=="svelte-1h7jomn"&&(S.textContent=pl),we=n(e),u(ve.$$.fragment,e),Le=n(e),u(q.$$.fragment,e),rl=n(e),he=d(e,"P",{"data-svelte-h":!0}),w(he)!=="svelte-hecde5"&&(he.textContent=M),g=n(e),u(yl.$$.fragment,e),Rs=n(e),u(cl.$$.fragment,e),vs=n(e),dl=d(e,"P",{"data-svelte-h":!0}),w(dl)!=="svelte-cdi2lk"&&(dl.textContent=Mi),$s=n(e),u(wl.$$.fragment,e),Ns=n(e),u(hl.$$.fragment,e),Qs=n(e),Jl=d(e,"P",{"data-svelte-h":!0}),w(Jl)!=="svelte-7xl3sb"&&(Jl.textContent=oi),Fs=n(e),ul=d(e,"P",{"data-svelte-h":!0}),w(ul)!=="svelte-1pwg6fm"&&(ul.textContent=pi),Es=n(e),u(ml.$$.fragment,e),Ys=n(e),Ul=d(e,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-1dej8u9"&&(Ul.innerHTML=ri),zs=n(e),u(Tl.$$.fragment,e),Hs=n(e),u(jl.$$.fragment,e),Ss=n(e),bl=d(e,"P",{"data-svelte-h":!0}),w(bl)!=="svelte-14vvvpt"&&(bl.textContent=yi),qs=n(e),u(fl.$$.fragment,e),Ls=n(e),Il=d(e,"P",{"data-svelte-h":!0}),w(Il)!=="svelte-1kjwjcz"&&(Il.textContent=ci),Ds=n(e),u(Cl.$$.fragment,e),Ks=n(e),u(gl.$$.fragment,e),Ps=n(e),Zl=d(e,"P",{"data-svelte-h":!0}),w(Zl)!=="svelte-1hh9t0e"&&(Zl.textContent=di),Os=n(e),Pe=d(e,"DIV",{class:!0,"data-svelte-h":!0}),w(Pe)!=="svelte-cxbodn"&&(Pe.innerHTML=wi),ea=n(e),Gl=d(e,"P",{"data-svelte-h":!0}),w(Gl)!=="svelte-1kjufr6"&&(Gl.innerHTML=hi),la=n(e),Bl=d(e,"P",{"data-svelte-h":!0}),w(Bl)!=="svelte-58v7q5"&&(Bl.textContent=Ji),ta=n(e),kl=d(e,"UL",{"data-svelte-h":!0}),w(kl)!=="svelte-6x2io6"&&(kl.innerHTML=ui),sa=n(e),u(xl.$$.fragment,e),aa=n(e),u(_l.$$.fragment,e),na=n(e),Wl=d(e,"P",{"data-svelte-h":!0}),w(Wl)!=="svelte-1tsnw8"&&(Wl.innerHTML=mi),ia=n(e),Al=d(e,"P",{"data-svelte-h":!0}),w(Al)!=="svelte-sde0e0"&&(Al.innerHTML=Ui),Ma=n(e),u(Vl.$$.fragment,e),oa=n(e),u(Xl.$$.fragment,e),pa=n(e),Rl=d(e,"P",{"data-svelte-h":!0}),w(Rl)!=="svelte-14worlm"&&(Rl.innerHTML=Ti),ra=n(e),u(vl.$$.fragment,e),ya=n(e),u($l.$$.fragment,e),ca=n(e),Nl=d(e,"P",{"data-svelte-h":!0}),w(Nl)!=="svelte-35wqxf"&&(Nl.textContent=ji),da=n(e),u(Ql.$$.fragment,e),wa=n(e),u(Fl.$$.fragment,e),ha=n(e),El=d(e,"P",{"data-svelte-h":!0}),w(El)!=="svelte-1ia87mf"&&(El.textContent=bi),Ja=n(e),Yl=d(e,"P",{"data-svelte-h":!0}),w(Yl)!=="svelte-1npwtyu"&&(Yl.textContent=fi),ua=n(e),zl=d(e,"UL",{"data-svelte-h":!0}),w(zl)!=="svelte-prlp5i"&&(zl.innerHTML=Ii),ma=n(e),Hl=d(e,"P",{"data-svelte-h":!0}),w(Hl)!=="svelte-17fh4wp"&&(Hl.innerHTML=Ci),Ua=n(e),Sl=d(e,"P",{"data-svelte-h":!0}),w(Sl)!=="svelte-16vvku3"&&(Sl.innerHTML=gi),Ta=n(e),u(ql.$$.fragment,e),ja=n(e),u(Ll.$$.fragment,e),ba=n(e),Dl=d(e,"P",{"data-svelte-h":!0}),w(Dl)!=="svelte-1hgj446"&&(Dl.innerHTML=Zi),fa=n(e),u(Kl.$$.fragment,e),Ia=n(e),u(Pl.$$.fragment,e),Ca=n(e),Ol=d(e,"P",{"data-svelte-h":!0}),w(Ol)!=="svelte-fazefa"&&(Ol.innerHTML=Gi),ga=n(e),u(et.$$.fragment,e),Za=n(e),u(lt.$$.fragment,e),Ga=n(e),tt=d(e,"P",{"data-svelte-h":!0}),w(tt)!=="svelte-1fhoy6z"&&(tt.textContent=Bi),Ba=n(e),Oe=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(Oe)!=="svelte-10rl3uf"&&(Oe.innerHTML=ki),ka=n(e),st=d(e,"P",{"data-svelte-h":!0}),w(st)!=="svelte-pljeaa"&&(st.textContent=xi),xa=n(e),u(at.$$.fragment,e),_a=n(e),nt=d(e,"P",{"data-svelte-h":!0}),w(nt)!=="svelte-1xwitc5"&&(nt.textContent=_i),Wa=n(e),it=d(e,"P",{"data-svelte-h":!0}),w(it)!=="svelte-sdejg"&&(it.innerHTML=Wi),Aa=n(e),u(Mt.$$.fragment,e),Va=n(e),u(ot.$$.fragment,e),Xa=n(e),pt=d(e,"P",{"data-svelte-h":!0}),w(pt)!=="svelte-7dpaps"&&(pt.textContent=Ai),Ra=n(e),u(rt.$$.fragment,e),va=n(e),yt=d(e,"P",{"data-svelte-h":!0}),w(yt)!=="svelte-19rsl9d"&&(yt.textContent=Vi),$a=n(e),ct=d(e,"P",{"data-svelte-h":!0}),w(ct)!=="svelte-1lo0yv3"&&(ct.innerHTML=Xi),Na=n(e),u(dt.$$.fragment,e),Qa=n(e),wt=d(e,"P",{"data-svelte-h":!0}),w(wt)!=="svelte-1dpgya2"&&(wt.textContent=Ri),Fa=n(e),u(ht.$$.fragment,e),Ea=n(e),u(Jt.$$.fragment,e),Ya=n(e),ut=d(e,"P",{"data-svelte-h":!0}),w(ut)!=="svelte-9xk5eq"&&(ut.textContent=vi),za=n(e),mt=d(e,"P",{"data-svelte-h":!0}),w(mt)!=="svelte-tuy2yy"&&(mt.textContent=$i),Ha=n(e),ue.l(e),Ts=n(e),u(Ut.$$.fragment,e),Sa=n(e),Ue.l(e),js=n(e),Tt=d(e,"P",{"data-svelte-h":!0}),w(Tt)!=="svelte-jznsd0"&&(Tt.innerHTML=Ni),qa=n(e),jt=d(e,"UL",{"data-svelte-h":!0}),w(jt)!=="svelte-m8u7qd"&&(jt.innerHTML=Qi),La=n(e),D=d(e,"P",{});var ee=Sn(D);Ln=Xs(ee,"Here we will change this process slightly because we don’t need to compute actual scores (just the predicted answer). This means we can skip the softmax step. To go faster, we also won’t score all the possible "),bs=d(ee,"CODE",{"data-svelte-h":!0}),w(bs)!=="svelte-h5rtds"&&(bs.textContent=Fi),Dn=Xs(ee," pairs, but only the ones corresponding to the highest "),fs=d(ee,"CODE",{"data-svelte-h":!0}),w(fs)!=="svelte-4nlbo1"&&(fs.textContent=Ei),Kn=Xs(ee," logits (with "),Is=d(ee,"CODE",{"data-svelte-h":!0}),w(Is)!=="svelte-jugzo8"&&(Is.textContent=Yi),Pn=Xs(ee,"). Since we will skip the softmax, those scores will be logit scores, and will be obtained by taking the sum of the start and end logits (instead of the product, because of the rule"),Da=EM(ee,!1),Ka=Xs(ee,")."),ee.forEach(l),Pa=n(e),bt=d(e,"P",{"data-svelte-h":!0}),w(bt)!=="svelte-llzo73"&&(bt.innerHTML=zi),Oa=n(e),u(ft.$$.fragment,e),en=n(e),It=d(e,"P",{"data-svelte-h":!0}),w(It)!=="svelte-fruu7j"&&(It.textContent=Hi),ln=n(e),u(Ct.$$.fragment,e),tn=n(e),gt=d(e,"P",{"data-svelte-h":!0}),w(gt)!=="svelte-6pa3pk"&&(gt.innerHTML=Si),sn=n(e),je.l(e),Cs=n(e),Zt=d(e,"P",{"data-svelte-h":!0}),w(Zt)!=="svelte-tk5afo"&&(Zt.innerHTML=qi),an=n(e),u(Gt.$$.fragment,e),nn=n(e),Bt=d(e,"P",{"data-svelte-h":!0}),w(Bt)!=="svelte-ql5gpc"&&(Bt.innerHTML=Li),Mn=n(e),kt=d(e,"UL",{"data-svelte-h":!0}),w(kt)!=="svelte-1ithwwo"&&(kt.innerHTML=Di),on=n(e),xt=d(e,"P",{"data-svelte-h":!0}),w(xt)!=="svelte-ys0ywc"&&(xt.textContent=Ki),pn=n(e),u(_t.$$.fragment,e),rn=n(e),Wt=d(e,"P",{"data-svelte-h":!0}),w(Wt)!=="svelte-1f0vmkj"&&(Wt.textContent=Pi),yn=n(e),u(At.$$.fragment,e),cn=n(e),Vt=d(e,"P",{"data-svelte-h":!0}),w(Vt)!=="svelte-g7bi3x"&&(Vt.textContent=Oi),dn=n(e),u(Xt.$$.fragment,e),wn=n(e),Rt=d(e,"P",{"data-svelte-h":!0}),w(Rt)!=="svelte-1r94o8l"&&(Rt.textContent=eM),hn=n(e),u(vt.$$.fragment,e),Jn=n(e),u($t.$$.fragment,e),un=n(e),Nt=d(e,"P",{"data-svelte-h":!0}),w(Nt)!=="svelte-fcu3w1"&&(Nt.textContent=lM),mn=n(e),u(Qt.$$.fragment,e),Un=n(e),u(Ft.$$.fragment,e),Tn=n(e),Et=d(e,"P",{"data-svelte-h":!0}),w(Et)!=="svelte-1mits6t"&&(Et.innerHTML=tM),jn=n(e),De.l(e),gs=n(e),u(Yt.$$.fragment,e),bn=n(e),zt=d(e,"P",{"data-svelte-h":!0}),w(zt)!=="svelte-xvtmh8"&&(zt.textContent=sM),fn=n(e),u(Ht.$$.fragment,e),In=n(e),u(St.$$.fragment,e),Cn=n(e),qt=d(e,"P",{"data-svelte-h":!0}),w(qt)!=="svelte-1u746y"&&(qt.textContent=aM),gn=n(e),u(Lt.$$.fragment,e),Zn=n(e),fe.l(e),Zs=n(e),Dt=d(e,"P",{"data-svelte-h":!0}),w(Dt)!=="svelte-q4u5lv"&&(Dt.textContent=nM),Gn=n(e),Kt=d(e,"P",{"data-svelte-h":!0}),w(Kt)!=="svelte-p6654n"&&(Kt.textContent=iM),Bn=n(e),u(Pt.$$.fragment,e),kn=n(e),Ot=d(e,"P",{"data-svelte-h":!0}),w(Ot)!=="svelte-648vlf"&&(Ot.textContent=MM),xn=n(e),u(es.$$.fragment,e),_n=n(e),Ce.l(e),Gs=n(e),ls=d(e,"P",{"data-svelte-h":!0}),w(ls)!=="svelte-1bhn9dh"&&(ls.innerHTML=oM),Wn=n(e),Ze.l(e),Bs=n(e),ts=d(e,"P",{"data-svelte-h":!0}),w(ts)!=="svelte-8kltkn"&&(ts.textContent=pM),An=n(e),Be.l(e),ks=n(e),u(ss.$$.fragment,e),Vn=n(e),as=d(e,"P",{"data-svelte-h":!0}),w(as)!=="svelte-1n0mqlm"&&(as.textContent=rM),Xn=n(e),R&&R.l(e),xs=n(e),ns=d(e,"P",{"data-svelte-h":!0}),w(ns)!=="svelte-4jl15q"&&(ns.textContent=yM),Rn=n(e),el=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),w(el)!=="svelte-1blbx5y"&&(el.innerHTML=cM),vn=n(e),v&&v.l(e),_s=n(e),u(is.$$.fragment,e),$n=n(e),Ms=d(e,"P",{"data-svelte-h":!0}),w(Ms)!=="svelte-1mnag4f"&&(Ms.innerHTML=dM),Nn=n(e),u(os.$$.fragment,e),Qn=n(e),u(ps.$$.fragment,e),Fn=n(e),rs=d(e,"P",{"data-svelte-h":!0}),w(rs)!=="svelte-19li140"&&(rs.textContent=wM),En=n(e),u(ys.$$.fragment,e),Yn=n(e),As=d(e,"P",{}),Sn(As).forEach(l),this.h()},h(){K(i,"name","hf:doc:metadata"),K(i,"content",co),RM($.src,ll="https://course-demos-bert-finetuned-squad.hf.space")||K($,"src",ll),K($,"frameborder","0"),K($,"height","450"),K($,"title","Gradio app"),K($,"class","block dark:hidden container p-0 flex-grow space-iframe"),K($,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),K($,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),K(O,"class","tip"),K(Pe,"class","flex justify-center"),K(Oe,"class","tip"),Da.a=Ka,K(el,"class","tip")},m(e,t){Ke(document.head,i),s(e,T,t),s(e,p,t),s(e,h,t),m(b,e,t),s(e,o,t),m(I,e,t),s(e,f,t),m(C,e,t),s(e,_,t),cs[x].m(e,t),s(e,V,t),s(e,Z,t),s(e,W,t),m(P,e,t),s(e,L,t),s(e,G,t),s(e,te,t),s(e,$,t),s(e,se,t),s(e,ae,t),s(e,tl,t),s(e,O,t),s(e,Qe,t),m(N,e,t),s(e,sl,t),s(e,ne,t),s(e,Fe,t),m(Q,e,t),s(e,al,t),s(e,ie,t),s(e,Ee,t),m(F,e,t),s(e,Ye,t),s(e,E,t),s(e,ze,t),m(Y,e,t),s(e,He,t),m(z,e,t),s(e,nl,t),s(e,Me,t),s(e,Se,t),m(H,e,t),s(e,il,t),m(oe,e,t),s(e,pe,t),s(e,Ve,t),s(e,re,t),s(e,Xe,t),s(e,ye,t),m(ce,e,t),s(e,de,t),m(Re,e,t),s(e,qe,t),s(e,S,t),s(e,we,t),m(ve,e,t),s(e,Le,t),m(q,e,t),s(e,rl,t),s(e,he,t),s(e,g,t),m(yl,e,t),s(e,Rs,t),m(cl,e,t),s(e,vs,t),s(e,dl,t),s(e,$s,t),m(wl,e,t),s(e,Ns,t),m(hl,e,t),s(e,Qs,t),s(e,Jl,t),s(e,Fs,t),s(e,ul,t),s(e,Es,t),m(ml,e,t),s(e,Ys,t),s(e,Ul,t),s(e,zs,t),m(Tl,e,t),s(e,Hs,t),m(jl,e,t),s(e,Ss,t),s(e,bl,t),s(e,qs,t),m(fl,e,t),s(e,Ls,t),s(e,Il,t),s(e,Ds,t),m(Cl,e,t),s(e,Ks,t),m(gl,e,t),s(e,Ps,t),s(e,Zl,t),s(e,Os,t),s(e,Pe,t),s(e,ea,t),s(e,Gl,t),s(e,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!0},p(e,[t]){const ee={};t&1&&(ee.fw=e[0]),b.$set(ee);let On=x;x=JM(e),x!==On&&(Ne(),y(cs[On],1,1,()=>{cs[On]=null}),$e(),A=cs[x],A||(A=cs[x]=hM[x](e),A.c()),r(A,1),A.m(V.parentNode,V));let ei=Je;Je=mM(e),Je!==ei&&(Ne(),y(ds[ei],1,1,()=>{ds[ei]=null}),$e(),ue=ds[Je],ue||(ue=ds[Je]=uM[Je](e),ue.c()),r(ue,1),ue.m(Ts.parentNode,Ts));let li=me;me=TM(e),me!==li&&(Ne(),y(ws[li],1,1,()=>{ws[li]=null}),$e(),Ue=ws[me],Ue||(Ue=ws[me]=UM[me](e),Ue.c()),r(Ue,1),Ue.m(js.parentNode,js));let ti=Te;Te=bM(e),Te!==ti&&(Ne(),y(hs[ti],1,1,()=>{hs[ti]=null}),$e(),je=hs[Te],je||(je=hs[Te]=jM[Te](e),je.c()),r(je,1),je.m(Cs.parentNode,Cs)),Hn!==(Hn=fM(e))&&(De.d(1),De=Hn(e),De&&(De.c(),De.m(gs.parentNode,gs)));let si=be;be=CM(e),be!==si&&(Ne(),y(Js[si],1,1,()=>{Js[si]=null}),$e(),fe=Js[be],fe||(fe=Js[be]=IM[be](e),fe.c()),r(fe,1),fe.m(Zs.parentNode,Zs));let ai=Ie;Ie=ZM(e),Ie!==ai&&(Ne(),y(us[ai],1,1,()=>{us[ai]=null}),$e(),Ce=us[Ie],Ce||(Ce=us[Ie]=gM[Ie](e),Ce.c()),r(Ce,1),Ce.m(Gs.parentNode,Gs));let ni=ge;ge=BM(e),ge!==ni&&(Ne(),y(ms[ni],1,1,()=>{ms[ni]=null}),$e(),Ze=ms[ge],Ze||(Ze=ms[ge]=GM[ge](e),Ze.c()),r(Ze,1),Ze.m(Bs.parentNode,Bs));let ii=Ge;Ge=xM(e),Ge!==ii&&(Ne(),y(Us[ii],1,1,()=>{Us[ii]=null}),$e(),Be=Us[Ge],Be||(Be=Us[Ge]=kM[Ge](e),Be.c()),r(Be,1),Be.m(ks.parentNode,ks)),e[0]==="pt"?R?t&1&&r(R,1):(R=_M(),R.c(),r(R,1),R.m(xs.parentNode,xs)):R&&(Ne(),y(R,1,1,()=>{R=null}),$e()),e[0]==="pt"?v?t&1&&r(v,1):(v=WM(),v.c(),r(v,1),v.m(_s.parentNode,_s)):v&&(Ne(),y(v,1,1,()=>{v=null}),$e())},i(e){zn||(r(b.$$.fragment,e),r(I.$$.fragment,e),r(C.$$.fragment,e),r(A),r(P.$$.fragment,e),r(N.$$.fragment,e),r(Q.$$.fragment,e),r(F.$$.fragment,e),r(Y.$$.fragment,e),r(z.$$.fragment,e),r(H.$$.fragment,e),r(oe.$$.fragment,e),r(ce.$$.fragment,e),r(Re.$$.fragment,e),r(ve.$$.fragment,e),r(q.$$.fragment,e),r(yl.$$.fragment,e),r(cl.$$.fragment,e),r(wl.$$.fragment,e),r(hl.$$.fragment,e),r(ml.$$.fragment,e),r(Tl.$$.fragment,e),r(jl.$$.fragment,e),r(fl.$$.fragment,e),r(Cl.$$.fragment,e),r(gl.$$.fragment,e),r(xl.$$.fragment,e),r(_l.$$.fragment,e),r(Vl.$$.fragment,e),r(Xl.$$.fragment,e),r(vl.$$.fragment,e),r($l.$$.fragment,e),r(Ql.$$.fragment,e),r(Fl.$$.fragment,e),r(ql.$$.fragment,e),r(Ll.$$.fragment,e),r(Kl.$$.fragment,e),r(Pl.$$.fragment,e),r(et.$$.fragment,e),r(lt.$$.fragment,e),r(at.$$.fragment,e),r(Mt.$$.fragment,e),r(ot.$$.fragment,e),r(rt.$$.fragment,e),r(dt.$$.fragment,e),r(ht.$$.fragment,e),r(Jt.$$.fragment,e),r(ue),r(Ut.$$.fragment,e),r(Ue),r(ft.$$.fragment,e),r(Ct.$$.fragment,e),r(je),r(Gt.$$.fragment,e),r(_t.$$.fragment,e),r(At.$$.fragment,e),r(Xt.$$.fragment,e),r(vt.$$.fragment,e),r($t.$$.fragment,e),r(Qt.$$.fragment,e),r(Ft.$$.fragment,e),r(Yt.$$.fragment,e),r(Ht.$$.fragment,e),r(St.$$.fragment,e),r(Lt.$$.fragment,e),r(fe),r(Pt.$$.fragment,e),r(es.$$.fragment,e),r(Ce),r(Ze),r(Be),r(ss.$$.fragment,e),r(R),r(v),r(is.$$.fragment,e),r(os.$$.fragment,e),r(ps.$$.fragment,e),r(ys.$$.fragment,e),zn=!0)},o(e){y(b.$$.fragment,e),y(I.$$.fragment,e),y(C.$$.fragment,e),y(A),y(P.$$.fragment,e),y(N.$$.fragment,e),y(Q.$$.fragment,e),y(F.$$.fragment,e),y(Y.$$.fragment,e),y(z.$$.fragment,e),y(H.$$.fragment,e),y(oe.$$.fragment,e),y(ce.$$.fragment,e),y(Re.$$.fragment,e),y(ve.$$.fragment,e),y(q.$$.fragment,e),y(yl.$$.fragment,e),y(cl.$$.fragment,e),y(wl.$$.fragment,e),y(hl.$$.fragment,e),y(ml.$$.fragment,e),y(Tl.$$.fragment,e),y(jl.$$.fragment,e),y(fl.$$.fragment,e),y(Cl.$$.fragment,e),y(gl.$$.fragment,e),y(xl.$$.fragment,e),y(_l.$$.fragment,e),y(Vl.$$.fragment,e),y(Xl.$$.fragment,e),y(vl.$$.fragment,e),y($l.$$.fragment,e),y(Ql.$$.fragment,e),y(Fl.$$.fragment,e),y(ql.$$.fragment,e),y(Ll.$$.fragment,e),y(Kl.$$.fragment,e),y(Pl.$$.fragment,e),y(et.$$.fragment,e),y(lt.$$.fragment,e),y(at.$$.fragment,e),y(Mt.$$.fragment,e),y(ot.$$.fragment,e),y(rt.$$.fragment,e),y(dt.$$.fragment,e),y(ht.$$.fragment,e),y(Jt.$$.fragment,e),y(ue),y(Ut.$$.fragment,e),y(Ue),y(ft.$$.fragment,e),y(Ct.$$.fragment,e),y(je),y(Gt.$$.fragment,e),y(_t.$$.fragment,e),y(At.$$.fragment,e),y(Xt.$$.fragment,e),y(vt.$$.fragment,e),y($t.$$.fragment,e),y(Qt.$$.fragment,e),y(Ft.$$.fragment,e),y(Yt.$$.fragment,e),y(Ht.$$.fragment,e),y(St.$$.fragment,e),y(Lt.$$.fragment,e),y(fe),y(Pt.$$.fragment,e),y(es.$$.fragment,e),y(Ce),y(Ze),y(Be),y(ss.$$.fragment,e),y(R),y(v),y(is.$$.fragment,e),y(os.$$.fragment,e),y(ps.$$.fragment,e),y(ys.$$.fragment,e),zn=!1},d(e){e&&(l(T),l(p),l(h),l(o),l(f),l(_),l(V),l(Z),l(W),l(L),l(G),l(te),l($),l(se),l(ae),l(tl),l(O),l(Qe),l(sl),l(ne),l(Fe),l(al),l(ie),l(Ee),l(Ye),l(E),l(ze),l(He),l(nl),l(Me),l(Se),l(il),l(pe),l(Ve),l(re),l(Xe),l(ye),l(de),l(qe),l(S),l(we),l(Le),l(rl),l(he),l(g),l(Rs),l(vs),l(dl),l($s),l(Ns),l(Qs),l(Jl),l(Fs),l(ul),l(Es),l(Ys),l(Ul),l(zs),l(Hs),l(Ss),l(bl),l(qs),l(Ls),l(Il),l(Ds),l(Ks),l(Ps),l(Zl),l(Os),l(Pe),l(ea),l(Gl),l(la),l(Bl),l(ta),l(kl),l(sa),l(aa),l(na),l(Wl),l(ia),l(Al),l(Ma),l(oa),l(pa),l(Rl),l(ra),l(ya),l(ca),l(Nl),l(da),l(wa),l(ha),l(El),l(Ja),l(Yl),l(ua),l(zl),l(ma),l(Hl),l(Ua),l(Sl),l(Ta),l(ja),l(ba),l(Dl),l(fa),l(Ia),l(Ca),l(Ol),l(ga),l(Za),l(Ga),l(tt),l(Ba),l(Oe),l(ka),l(st),l(xa),l(_a),l(nt),l(Wa),l(it),l(Aa),l(Va),l(Xa),l(pt),l(Ra),l(va),l(yt),l($a),l(ct),l(Na),l(Qa),l(wt),l(Fa),l(Ea),l(Ya),l(ut),l(za),l(mt),l(Ha),l(Ts),l(Sa),l(js),l(Tt),l(qa),l(jt),l(La),l(D),l(Pa),l(bt),l(Oa),l(en),l(It),l(ln),l(tn),l(gt),l(sn),l(Cs),l(Zt),l(an),l(nn),l(Bt),l(Mn),l(kt),l(on),l(xt),l(pn),l(rn),l(Wt),l(yn),l(cn),l(Vt),l(dn),l(wn),l(Rt),l(hn),l(Jn),l(un),l(Nt),l(mn),l(Un),l(Tn),l(Et),l(jn),l(gs),l(bn),l(zt),l(fn),l(In),l(Cn),l(qt),l(gn),l(Zn),l(Zs),l(Dt),l(Gn),l(Kt),l(Bn),l(kn),l(Ot),l(xn),l(_n),l(Gs),l(ls),l(Wn),l(Bs),l(ts),l(An),l(ks),l(Vn),l(as),l(Xn),l(xs),l(ns),l(Rn),l(el),l(vn),l(_s),l($n),l(Ms),l(Nn),l(Qn),l(Fn),l(rs),l(En),l(Yn),l(As)),l(i),U(b,e),U(I,e),U(C,e),cs[x].d(e),U(P,e),U(N,e),U(Q,e),U(F,e),U(Y,e),U(z,e),U(H,e),U(oe,e),U(ce,e),U(Re,e),U(ve,e),U(q,e),U(yl,e),U(cl,e),U(wl,e),U(hl,e),U(ml,e),U(Tl,e),U(jl,e),U(fl,e),U(Cl,e),U(gl,e),U(xl,e),U(_l,e),U(Vl,e),U(Xl,e),U(vl,e),U($l,e),U(Ql,e),U(Fl,e),U(ql,e),U(Ll,e),U(Kl,e),U(Pl,e),U(et,e),U(lt,e),U(at,e),U(Mt,e),U(ot,e),U(rt,e),U(dt,e),U(ht,e),U(Jt,e),ds[Je].d(e),U(Ut,e),ws[me].d(e),U(ft,e),U(Ct,e),hs[Te].d(e),U(Gt,e),U(_t,e),U(At,e),U(Xt,e),U(vt,e),U($t,e),U(Qt,e),U(Ft,e),De.d(e),U(Yt,e),U(Ht,e),U(St,e),U(Lt,e),Js[be].d(e),U(Pt,e),U(es,e),us[Ie].d(e),ms[ge].d(e),Us[Ge].d(e),U(ss,e),R&&R.d(e),v&&v.d(e),U(is,e),U(os,e),U(ps,e),U(ys,e)}}}const co='{"title":"Question answering","local":"question-answering","sections":[{"title":"Preparing the data","local":"preparing-the-data","sections":[{"title":"The SQuAD dataset","local":"the-squad-dataset","sections":[],"depth":3},{"title":"Processing the training data","local":"processing-the-training-data","sections":[],"depth":3},{"title":"Processing the validation data","local":"processing-the-validation-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":"Post-processing","local":"post-processing","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}],"depth":2},{"title":"Training loop","local":"training-loop","sections":[],"depth":2},{"title":"Using the fine-tuned model","local":"using-the-fine-tuned-model","sections":[],"depth":2}],"depth":1}';function wo(k,i,T){let p="pt";return vM(()=>{const h=new URLSearchParams(window.location.search);T(0,p=h.get("fw")||"pt")}),[p]}class bo extends $M{constructor(i){super(),NM(this,i,wo,yo,XM,{})}}export{bo as component};

Xet Storage Details

Size:
180 kB
·
Xet hash:
d9759d382758ac97cac0d1b3293a48658fec7cf4461815b12e57e2c49caf8726

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.