import{s as zs,o as Hs,n as ce}from"../chunks/scheduler.9bc65507.js";import{S as Qs,i as qs,g as h,s as o,u as w,A as Ys,h as d,f as t,c as p,j as F,v as y,y as f,k as G,o as W,a as n,w as g,d as j,t as T,x as J,m as Vs,n as Fs}from"../chunks/index.78c82d43.js";import{T as ts}from"../chunks/Tip.87d55b76.js";import{Y as Ns}from"../chunks/Youtube.b19762b6.js";import{I as st}from"../chunks/IconCopyLink.bedaa44d.js";import{C as B}from"../chunks/CodeBlock.48618ec2.js";import{D as Ss}from"../chunks/DocNotebookDropdown.40f7599b.js";import{F as os,M as at}from"../chunks/Markdown.993b48ef.js";function Ls(I){let l,m,a='<a href="../model_doc/albert">ALBERT</a>, <a href="../model_doc/bart">BART</a>, <a href="../model_doc/bert">BERT</a>, <a href="../model_doc/big_bird">BigBird</a>, <a href="../model_doc/bigbird_pegasus">BigBird-Pegasus</a>, <a href="../model_doc/bloom">BLOOM</a>, <a href="../model_doc/camembert">CamemBERT</a>, <a href="../model_doc/canine">CANINE</a>, <a href="../model_doc/convbert">ConvBERT</a>, <a href="../model_doc/data2vec-text">Data2VecText</a>, <a href="../model_doc/deberta">DeBERTa</a>, <a href="../model_doc/deberta-v2">DeBERTa-v2</a>, <a href="../model_doc/distilbert">DistilBERT</a>, <a href="../model_doc/electra">ELECTRA</a>, <a href="../model_doc/ernie">ERNIE</a>, <a href="../model_doc/ernie_m">ErnieM</a>, <a href="../model_doc/falcon">Falcon</a>, <a href="../model_doc/flaubert">FlauBERT</a>, <a href="../model_doc/fnet">FNet</a>, <a href="../model_doc/funnel">Funnel Transformer</a>, <a href="../model_doc/gpt2">OpenAI GPT-2</a>, <a href="../model_doc/gpt_neo">GPT Neo</a>, <a href="../model_doc/gpt_neox">GPT NeoX</a>, <a href="../model_doc/gptj">GPT-J</a>, <a href="../model_doc/ibert">I-BERT</a>, <a href="../model_doc/layoutlmv2">LayoutLMv2</a>, <a href="../model_doc/layoutlmv3">LayoutLMv3</a>, <a href="../model_doc/led">LED</a>, <a href="../model_doc/lilt">LiLT</a>, <a href="../model_doc/longformer">Longformer</a>, <a href="../model_doc/luke">LUKE</a>, <a href="../model_doc/lxmert">LXMERT</a>, <a href="../model_doc/markuplm">MarkupLM</a>, <a href="../model_doc/mbart">mBART</a>, <a href="../model_doc/mega">MEGA</a>, <a href="../model_doc/megatron-bert">Megatron-BERT</a>, <a href="../model_doc/mobilebert">MobileBERT</a>, <a href="../model_doc/mpnet">MPNet</a>, <a href="../model_doc/mpt">MPT</a>, <a href="../model_doc/mra">MRA</a>, <a href="../model_doc/mt5">MT5</a>, <a href="../model_doc/mvp">MVP</a>, <a href="../model_doc/nezha">Nezha</a>, <a href="../model_doc/nystromformer">Nyströmformer</a>, <a href="../model_doc/opt">OPT</a>, <a href="../model_doc/qdqbert">QDQBert</a>, <a href="../model_doc/reformer">Reformer</a>, <a href="../model_doc/rembert">RemBERT</a>, <a href="../model_doc/roberta">RoBERTa</a>, <a href="../model_doc/roberta-prelayernorm">RoBERTa-PreLayerNorm</a>, <a href="../model_doc/roc_bert">RoCBert</a>, <a href="../model_doc/roformer">RoFormer</a>, <a href="../model_doc/splinter">Splinter</a>, <a href="../model_doc/squeezebert">SqueezeBERT</a>, <a href="../model_doc/t5">T5</a>, <a href="../model_doc/umt5">UMT5</a>, <a href="../model_doc/xlm">XLM</a>, <a href="../model_doc/xlm-roberta">XLM-RoBERTa</a>, <a href="../model_doc/xlm-roberta-xl">XLM-RoBERTa-XL</a>, <a href="../model_doc/xlnet">XLNet</a>, <a href="../model_doc/xmod">X-MOD</a>, <a href="../model_doc/yoso">YOSO</a>';return{c(){l=Vs(`The task illustrated in this tutorial is supported by the following model architectures:

`),m=h("p"),m.innerHTML=a},l(c){l=Fs(c,`The task illustrated in this tutorial is supported by the following model architectures:

`),m=d(c,"P",{"data-svelte-h":!0}),f(m)!=="svelte-1grwhx8"&&(m.innerHTML=a)},m(c,M){n(c,l,M),n(c,m,M)},p:ce,d(c){c&&(t(l),t(m))}}}function Ps(I){let l,m;return l=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DefaultDataCollator()`}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p:ce,i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function Ds(I){let l,m;return l=new at({props:{$$slots:{default:[Ps]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function Ks(I){let l,m;return l=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcihyZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DefaultDataCollator(return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p:ce,i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function Os(I){let l,m;return l=new at({props:{$$slots:{default:[Ks]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function ea(I){let l,m='If you aren’t familiar with finetuning a model with the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a>, take a look at the basic tutorial <a href="../training#train-with-pytorch-trainer">here</a>!';return{c(){l=h("p"),l.innerHTML=m},l(a){l=d(a,"P",{"data-svelte-h":!0}),f(l)!=="svelte-1kww4sq"&&(l.innerHTML=m)},m(a,c){n(a,l,c)},p:ce,d(a){a&&t(l)}}}function ta(I){let l,m,a,c='You’re ready to start training your model now! Load DistilBERT with <a href="/docs/transformers/v4.33.3/en/model_doc/auto#transformers.AutoModelForQuestionAnswering">AutoModelForQuestionAnswering</a>:',M,$,N,_,A="At this point, only three steps remain:",R,X,z='<li>Define your training hyperparameters in <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>. The only required parameter is <code>output_dir</code> which specifies where to save your model. You’ll push this model to the Hub by setting <code>push_to_hub=True</code> (you need to be signed in to Hugging Face to upload your model).</li> <li>Pass the training arguments to <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with the model, dataset, tokenizer, and data collator.</li> <li>Call <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.train">train()</a> to finetune your model.</li>',k,U,Z,v,V='Once training is completed, share your model to the Hub with the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> method so everyone can use your model:',E,C,x;return l=new ts({props:{$$slots:{default:[ea]},$$scope:{ctx:I}}}),$=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nJTJDJTIwVHJhaW5pbmdBcmd1bWVudHMlMkMlMjBUcmFpbmVyJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQoJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForQuestionAnswering, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),U=new B({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJteV9hd2Vzb21lX3FhX21vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfZXZhbF9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEMyUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBwdXNoX3RvX2h1YiUzRFRydWUlMkMlMEEpJTBBJTBBdHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRva2VuaXplZF9zcXVhZCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdG9rZW5pemVkX3NxdWFkJTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGRhdGFfY29sbGF0b3IlM0RkYXRhX2NvbGxhdG9yJTJDJTBBKSUwQSUwQXRyYWluZXIudHJhaW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_squad[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),C=new B({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){w(l.$$.fragment),m=o(),a=h("p"),a.innerHTML=c,M=o(),w($.$$.fragment),N=o(),_=h("p"),_.textContent=A,R=o(),X=h("ol"),X.innerHTML=z,k=o(),w(U.$$.fragment),Z=o(),v=h("p"),v.innerHTML=V,E=o(),w(C.$$.fragment)},l(s){y(l.$$.fragment,s),m=p(s),a=d(s,"P",{"data-svelte-h":!0}),f(a)!=="svelte-1rztydk"&&(a.innerHTML=c),M=p(s),y($.$$.fragment,s),N=p(s),_=d(s,"P",{"data-svelte-h":!0}),f(_)!=="svelte-l42k0i"&&(_.textContent=A),R=p(s),X=d(s,"OL",{"data-svelte-h":!0}),f(X)!=="svelte-104vyhw"&&(X.innerHTML=z),k=p(s),y(U.$$.fragment,s),Z=p(s),v=d(s,"P",{"data-svelte-h":!0}),f(v)!=="svelte-158pnaw"&&(v.innerHTML=V),E=p(s),y(C.$$.fragment,s)},m(s,u){g(l,s,u),n(s,m,u),n(s,a,u),n(s,M,u),g($,s,u),n(s,N,u),n(s,_,u),n(s,R,u),n(s,X,u),n(s,k,u),g(U,s,u),n(s,Z,u),n(s,v,u),n(s,E,u),g(C,s,u),x=!0},p(s,u){const H={};u&2&&(H.$$scope={dirty:u,ctx:s}),l.$set(H)},i(s){x||(j(l.$$.fragment,s),j($.$$.fragment,s),j(U.$$.fragment,s),j(C.$$.fragment,s),x=!0)},o(s){T(l.$$.fragment,s),T($.$$.fragment,s),T(U.$$.fragment,s),T(C.$$.fragment,s),x=!1},d(s){s&&(t(m),t(a),t(M),t(N),t(_),t(R),t(X),t(k),t(Z),t(v),t(E)),J(l,s),J($,s),J(U,s),J(C,s)}}}function sa(I){let l,m;return l=new at({props:{$$slots:{default:[ta]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function aa(I){let l,m='If you aren’t familiar with finetuning a model with Keras, take a look at the basic tutorial <a href="../training#train-a-tensorflow-model-with-keras">here</a>!';return{c(){l=h("p"),l.innerHTML=m},l(a){l=d(a,"P",{"data-svelte-h":!0}),f(l)!=="svelte-1rd4nl8"&&(l.innerHTML=m)},m(a,c){n(a,l,c)},p:ce,d(a){a&&t(l)}}}function la(I){let l,m,a,c,M,$='Then you can load DistilBERT with <a href="/docs/transformers/v4.33.3/en/model_doc/auto#transformers.TFAutoModelForQuestionAnswering">TFAutoModelForQuestionAnswering</a>:',N,_,A,R,X='Convert your datasets to the <code>tf.data.Dataset</code> format with <a href="/docs/transformers/v4.33.3/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset">prepare_tf_dataset()</a>:',z,k,U,Z,v='Configure the model for training with <a href="https://keras.io/api/models/model_training_apis/#compile-method" rel="nofollow"><code>compile</code></a>:',V,E,C,x,s='The last thing to setup before you start training is to provide a way to push your model to the Hub. This can be done by specifying where to push your model and tokenizer in the <a href="/docs/transformers/v4.33.3/en/main_classes/keras_callbacks#transformers.PushToHubCallback">PushToHubCallback</a>:',u,H,he,q,L='Finally, you’re ready to start training your model! Call <a href="https://keras.io/api/models/model_training_apis/#fit-method" rel="nofollow"><code>fit</code></a> with your training and validation datasets, the number of epochs, and your callback to finetune the model:',de,Y,Q,S,P="Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!",ue;return l=new ts({props:{$$slots:{default:[aa]},$$scope:{ctx:I}}}),a=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEElMEFiYXRjaF9zaXplJTIwJTNEJTIwMTYlMEFudW1fZXBvY2hzJTIwJTNEJTIwMiUwQXRvdGFsX3RyYWluX3N0ZXBzJTIwJTNEJTIwKGxlbih0b2tlbml6ZWRfc3F1YWQlNUIlMjJ0cmFpbiUyMiU1RCklMjAlMkYlMkYlMjBiYXRjaF9zaXplKSUyMColMjBudW1fZXBvY2hzJTBBb3B0aW1pemVyJTJDJTIwc2NoZWR1bGUlMjAlM0QlMjBjcmVhdGVfb3B0aW1pemVyKCUwQSUyMCUyMCUyMCUyMGluaXRfbHIlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fc3RlcHMlM0R0b3RhbF90cmFpbl9zdGVwcyUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer

<span class="hljs-meta">&gt;&gt;&gt; </span>batch_size = <span class="hljs-number">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>total_train_steps = (<span class="hljs-built_in">len</span>(tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size) * num_epochs
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, schedule = create_optimizer(
<span class="hljs-meta">... </span>    init_lr=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    num_warmup_steps=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>    num_train_steps=total_train_steps,
<span class="hljs-meta">... </span>)`}}),_=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmclMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmcoJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForQuestionAnswering(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),k=new B({props:{code:"dGZfdHJhaW5fc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9zcXVhZCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0Zl92YWxpZGF0aW9uX3NldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfc3F1YWQlNUIlMjJ0ZXN0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_validation_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_squad[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)`}}),E=new B({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplcik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`}}),H=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMm15X2F3ZXNvbWVfcWFfbW9kZWwlMjIlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

<span class="hljs-meta">&gt;&gt;&gt; </span>callback = PushToHubCallback(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>)`}}),Y=new B({props:{code:"bW9kZWwuZml0KHglM0R0Zl90cmFpbl9zZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl92YWxpZGF0aW9uX3NldCUyQyUyMGVwb2NocyUzRDMlMkMlMjBjYWxsYmFja3MlM0QlNUJjYWxsYmFjayU1RCk=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(x=tf_train_set, validation_data=tf_validation_set, epochs=<span class="hljs-number">3</span>, callbacks=[callback])'}}),{c(){w(l.$$.fragment),m=Vs(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),w(a.$$.fragment),c=o(),M=h("p"),M.innerHTML=$,N=o(),w(_.$$.fragment),A=o(),R=h("p"),R.innerHTML=X,z=o(),w(k.$$.fragment),U=o(),Z=h("p"),Z.innerHTML=v,V=o(),w(E.$$.fragment),C=o(),x=h("p"),x.innerHTML=s,u=o(),w(H.$$.fragment),he=o(),q=h("p"),q.innerHTML=L,de=o(),w(Y.$$.fragment),Q=o(),S=h("p"),S.textContent=P},l(i){y(l.$$.fragment,i),m=Fs(i,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),y(a.$$.fragment,i),c=p(i),M=d(i,"P",{"data-svelte-h":!0}),f(M)!=="svelte-p21jsu"&&(M.innerHTML=$),N=p(i),y(_.$$.fragment,i),A=p(i),R=d(i,"P",{"data-svelte-h":!0}),f(R)!=="svelte-1hx2ar1"&&(R.innerHTML=X),z=p(i),y(k.$$.fragment,i),U=p(i),Z=d(i,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-rt1r5v"&&(Z.innerHTML=v),V=p(i),y(E.$$.fragment,i),C=p(i),x=d(i,"P",{"data-svelte-h":!0}),f(x)!=="svelte-1xislmm"&&(x.innerHTML=s),u=p(i),y(H.$$.fragment,i),he=p(i),q=d(i,"P",{"data-svelte-h":!0}),f(q)!=="svelte-1pfsro2"&&(q.innerHTML=L),de=p(i),y(Y.$$.fragment,i),Q=p(i),S=d(i,"P",{"data-svelte-h":!0}),f(S)!=="svelte-2s71om"&&(S.textContent=P)},m(i,b){g(l,i,b),n(i,m,b),g(a,i,b),n(i,c,b),n(i,M,b),n(i,N,b),g(_,i,b),n(i,A,b),n(i,R,b),n(i,z,b),g(k,i,b),n(i,U,b),n(i,Z,b),n(i,V,b),g(E,i,b),n(i,C,b),n(i,x,b),n(i,u,b),g(H,i,b),n(i,he,b),n(i,q,b),n(i,de,b),g(Y,i,b),n(i,Q,b),n(i,S,b),ue=!0},p(i,b){const Me={};b&2&&(Me.$$scope={dirty:b,ctx:i}),l.$set(Me)},i(i){ue||(j(l.$$.fragment,i),j(a.$$.fragment,i),j(_.$$.fragment,i),j(k.$$.fragment,i),j(E.$$.fragment,i),j(H.$$.fragment,i),j(Y.$$.fragment,i),ue=!0)},o(i){T(l.$$.fragment,i),T(a.$$.fragment,i),T(_.$$.fragment,i),T(k.$$.fragment,i),T(E.$$.fragment,i),T(H.$$.fragment,i),T(Y.$$.fragment,i),ue=!1},d(i){i&&(t(m),t(c),t(M),t(N),t(A),t(R),t(z),t(U),t(Z),t(V),t(C),t(x),t(u),t(he),t(q),t(de),t(Q),t(S)),J(l,i),J(a,i),J(_,i),J(k,i),J(E,i),J(H,i),J(Y,i)}}}function na(I){let l,m;return l=new at({props:{$$slots:{default:[la]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function ra(I){let l,m=`For a more in-depth example of how to finetune a model for question answering, take a look at the corresponding
<a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering.ipynb" rel="nofollow">PyTorch notebook</a>
or <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering-tf.ipynb" rel="nofollow">TensorFlow notebook</a>.`;return{c(){l=h("p"),l.innerHTML=m},l(a){l=d(a,"P",{"data-svelte-h":!0}),f(l)!=="svelte-14amlb3"&&(l.innerHTML=m)},m(a,c){n(a,l,c)},p:ce,d(a){a&&t(l)}}}function oa(I){let l,m="Tokenize the text and return PyTorch tensors:",a,c,M,$,N="Pass your inputs to the model and return the <code>logits</code>:",_,A,R,X,z="Get the highest probability from the model output for the start and end positions:",k,U,Z,v,V="Decode the predicted tokens to get the answer:",E,C,x;return c=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX3FhX21vZGVsJTIyKSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(question, context, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),A=new B({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmclMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX3FhX21vZGVsJTIyKSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(**inputs)`}}),U=new B({props:{code:"YW5zd2VyX3N0YXJ0X2luZGV4JTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMuYXJnbWF4KCklMEFhbnN3ZXJfZW5kX2luZGV4JTIwJTNEJTIwb3V0cHV0cy5lbmRfbG9naXRzLmFyZ21heCgp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>answer_start_index = outputs.start_logits.argmax()
<span class="hljs-meta">&gt;&gt;&gt; </span>answer_end_index = outputs.end_logits.argmax()`}}),C=new B({props:{code:"cHJlZGljdF9hbnN3ZXJfdG9rZW5zJTIwJTNEJTIwaW5wdXRzLmlucHV0X2lkcyU1QjAlMkMlMjBhbnN3ZXJfc3RhcnRfaW5kZXglMjAlM0ElMjBhbnN3ZXJfZW5kX2luZGV4JTIwJTJCJTIwMSU1RCUwQXRva2VuaXplci5kZWNvZGUocHJlZGljdF9hbnN3ZXJfdG9rZW5zKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predict_answer_tokens = inputs.input_ids[<span class="hljs-number">0</span>, answer_start_index : answer_end_index + <span class="hljs-number">1</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(predict_answer_tokens)
<span class="hljs-string">&#x27;176 billion parameters and can generate text in 46 languages natural languages and 13&#x27;</span>`}}),{c(){l=h("p"),l.textContent=m,a=o(),w(c.$$.fragment),M=o(),$=h("p"),$.innerHTML=N,_=o(),w(A.$$.fragment),R=o(),X=h("p"),X.textContent=z,k=o(),w(U.$$.fragment),Z=o(),v=h("p"),v.textContent=V,E=o(),w(C.$$.fragment)},l(s){l=d(s,"P",{"data-svelte-h":!0}),f(l)!=="svelte-1qcz1wr"&&(l.textContent=m),a=p(s),y(c.$$.fragment,s),M=p(s),$=d(s,"P",{"data-svelte-h":!0}),f($)!=="svelte-f3g043"&&($.innerHTML=N),_=p(s),y(A.$$.fragment,s),R=p(s),X=d(s,"P",{"data-svelte-h":!0}),f(X)!=="svelte-v8itmt"&&(X.textContent=z),k=p(s),y(U.$$.fragment,s),Z=p(s),v=d(s,"P",{"data-svelte-h":!0}),f(v)!=="svelte-66bsyj"&&(v.textContent=V),E=p(s),y(C.$$.fragment,s)},m(s,u){n(s,l,u),n(s,a,u),g(c,s,u),n(s,M,u),n(s,$,u),n(s,_,u),g(A,s,u),n(s,R,u),n(s,X,u),n(s,k,u),g(U,s,u),n(s,Z,u),n(s,v,u),n(s,E,u),g(C,s,u),x=!0},p:ce,i(s){x||(j(c.$$.fragment,s),j(A.$$.fragment,s),j(U.$$.fragment,s),j(C.$$.fragment,s),x=!0)},o(s){T(c.$$.fragment,s),T(A.$$.fragment,s),T(U.$$.fragment,s),T(C.$$.fragment,s),x=!1},d(s){s&&(t(l),t(a),t(M),t($),t(_),t(R),t(X),t(k),t(Z),t(v),t(E)),J(c,s),J(A,s),J(U,s),J(C,s)}}}function pa(I){let l,m;return l=new at({props:{$$slots:{default:[oa]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function ia(I){let l,m="Tokenize the text and return TensorFlow tensors:",a,c,M,$,N="Pass your inputs to the model and return the <code>logits</code>:",_,A,R,X,z="Get the highest probability from the model output for the start and end positions:",k,U,Z,v,V="Decode the predicted tokens to get the answer:",E,C,x;return c=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX3FhX21vZGVsJTIyKSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMHRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(question, text, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),A=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmclMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmcuZnJvbV9wcmV0cmFpbmVkKCUyMm15X2F3ZXNvbWVfcWFfbW9kZWwlMjIpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)`}}),U=new B({props:{code:"YW5zd2VyX3N0YXJ0X2luZGV4JTIwJTNEJTIwaW50KHRmLm1hdGguYXJnbWF4KG91dHB1dHMuc3RhcnRfbG9naXRzJTJDJTIwYXhpcyUzRC0xKSU1QjAlNUQpJTBBYW5zd2VyX2VuZF9pbmRleCUyMCUzRCUyMGludCh0Zi5tYXRoLmFyZ21heChvdXRwdXRzLmVuZF9sb2dpdHMlMkMlMjBheGlzJTNELTEpJTVCMCU1RCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>answer_start_index = <span class="hljs-built_in">int</span>(tf.math.argmax(outputs.start_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>answer_end_index = <span class="hljs-built_in">int</span>(tf.math.argmax(outputs.end_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>])`}}),C=new B({props:{code:"cHJlZGljdF9hbnN3ZXJfdG9rZW5zJTIwJTNEJTIwaW5wdXRzLmlucHV0X2lkcyU1QjAlMkMlMjBhbnN3ZXJfc3RhcnRfaW5kZXglMjAlM0ElMjBhbnN3ZXJfZW5kX2luZGV4JTIwJTJCJTIwMSU1RCUwQXRva2VuaXplci5kZWNvZGUocHJlZGljdF9hbnN3ZXJfdG9rZW5zKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predict_answer_tokens = inputs.input_ids[<span class="hljs-number">0</span>, answer_start_index : answer_end_index + <span class="hljs-number">1</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(predict_answer_tokens)
<span class="hljs-string">&#x27;176 billion parameters and can generate text in 46 languages natural languages and 13&#x27;</span>`}}),{c(){l=h("p"),l.textContent=m,a=o(),w(c.$$.fragment),M=o(),$=h("p"),$.innerHTML=N,_=o(),w(A.$$.fragment),R=o(),X=h("p"),X.textContent=z,k=o(),w(U.$$.fragment),Z=o(),v=h("p"),v.textContent=V,E=o(),w(C.$$.fragment)},l(s){l=d(s,"P",{"data-svelte-h":!0}),f(l)!=="svelte-s1qr7b"&&(l.textContent=m),a=p(s),y(c.$$.fragment,s),M=p(s),$=d(s,"P",{"data-svelte-h":!0}),f($)!=="svelte-f3g043"&&($.innerHTML=N),_=p(s),y(A.$$.fragment,s),R=p(s),X=d(s,"P",{"data-svelte-h":!0}),f(X)!=="svelte-v8itmt"&&(X.textContent=z),k=p(s),y(U.$$.fragment,s),Z=p(s),v=d(s,"P",{"data-svelte-h":!0}),f(v)!=="svelte-66bsyj"&&(v.textContent=V),E=p(s),y(C.$$.fragment,s)},m(s,u){n(s,l,u),n(s,a,u),g(c,s,u),n(s,M,u),n(s,$,u),n(s,_,u),g(A,s,u),n(s,R,u),n(s,X,u),n(s,k,u),g(U,s,u),n(s,Z,u),n(s,v,u),n(s,E,u),g(C,s,u),x=!0},p:ce,i(s){x||(j(c.$$.fragment,s),j(A.$$.fragment,s),j(U.$$.fragment,s),j(C.$$.fragment,s),x=!0)},o(s){T(c.$$.fragment,s),T(A.$$.fragment,s),T(U.$$.fragment,s),T(C.$$.fragment,s),x=!1},d(s){s&&(t(l),t(a),t(M),t($),t(_),t(R),t(X),t(k),t(Z),t(v),t(E)),J(c,s),J(A,s),J(U,s),J(C,s)}}}function ma(I){let l,m;return l=new at({props:{$$slots:{default:[ia]},$$scope:{ctx:I}}}),{c(){w(l.$$.fragment)},l(a){y(l.$$.fragment,a)},m(a,c){g(l,a,c),m=!0},p(a,c){const M={};c&2&&(M.$$scope={dirty:c,ctx:a}),l.$set(M)},i(a){m||(j(l.$$.fragment,a),m=!0)},o(a){T(l.$$.fragment,a),m=!1},d(a){J(l,a)}}}function ca(I){let l,m,a,c,M,$,N,_,A,R,X="Question answering",z,k,U,Z,v,V,E="Question answering tasks return an answer given a question. If you’ve ever asked a virtual assistant like Alexa, Siri or Google what the weather is, then you’ve used a question answering model before. There are two common types of question answering tasks:",C,x,s="<li>Extractive: extract the answer from the given context.</li> <li>Abstractive: generate an answer from the context that correctly answers the question.</li>",u,H,he="This guide will show you how to:",q,L,de='<li>Finetune <a href="https://huggingface.co/distilbert-base-uncased" rel="nofollow">DistilBERT</a> on the <a href="https://huggingface.co/datasets/squad" rel="nofollow">SQuAD</a> dataset for extractive question answering.</li> <li>Use your finetuned model for inference.</li>',Y,Q,S,P,ue="Before you begin, make sure you have all the necessary libraries installed:",i,b,Me,fe,ps="We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:",dt,we,ut,D,se,lt,ye,ss,De,is="Load SQuAD dataset",Mt,ge,ms="Start by loading a smaller subset of the SQuAD dataset from the 🤗 Datasets library. This’ll give you a chance to experiment and make sure everything works before spending more time training on the full dataset.",ft,je,wt,Te,cs='Split the dataset’s <code>train</code> split into a train and test set with the <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.train_test_split" rel="nofollow">train_test_split</a> method:',yt,Je,gt,be,hs="Then take a look at an example:",jt,$e,Tt,_e,ds="There are several important fields here:",Jt,Ue,us="<li><code>answers</code>: the starting location of the answer token and the answer text.</li> <li><code>context</code>: background information from which the model needs to extract the answer.</li> <li><code>question</code>: the question a model should answer.</li>",bt,K,ae,nt,Ce,as,Ke,Ms="Preprocess",$t,Ie,_t,ve,fs="The next step is to load a DistilBERT tokenizer to process the <code>question</code> and <code>context</code> fields:",Ut,ke,Ct,Ze,ws="There are a few preprocessing steps particular to question answering tasks you should be aware of:",It,xe,ys=`<li>Some examples in a dataset may have a very long <code>context</code> that exceeds the maximum input length of the model. To deal with longer sequences, truncate only the <code>context</code> by setting <code>truncation=&quot;only_second&quot;</code>.</li> <li>Next, map the start and end positions of the answer to the original <code>context</code> by setting
<code>return_offset_mapping=True</code>.</li> <li>With the mapping in hand, now you can find the start and end tokens of the answer. Use the <code>sequence_ids</code> method to
find which part of the offset corresponds to the <code>question</code> and which corresponds to the <code>context</code>.</li>`,vt,Re,gs="Here is how you can create a function to truncate and map the start and end tokens of the <code>answer</code> to the <code>context</code>:",kt,Xe,Zt,Be,js='To apply the preprocessing function over the entire dataset, use 🤗 Datasets <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.map" rel="nofollow">map</a> function. You can speed up the <code>map</code> function by setting <code>batched=True</code> to process multiple elements of the dataset at once. Remove any columns you don’t need:',xt,Ae,Rt,Ge,Ts='Now create a batch of examples using <a href="/docs/transformers/v4.33.3/en/main_classes/data_collator#transformers.DefaultDataCollator">DefaultDataCollator</a>. Unlike other data collators in 🤗 Transformers, the <a href="/docs/transformers/v4.33.3/en/main_classes/data_collator#transformers.DefaultDataCollator">DefaultDataCollator</a> does not apply any additional preprocessing such as padding.',Xt,le,Bt,O,ne,rt,Ee,ls,Oe,Js="Train",At,re,Gt,oe,Et,ee,pe,ot,We,ns,et,bs="Evaluate",Wt,Ne,$s='Evaluation for question answering requires a significant amount of postprocessing. To avoid taking up too much of your time, this guide skips the evaluation step. The <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> still calculates the evaluation loss during training so you’re not completely in the dark about your model’s performance.',Nt,Ve,_s='If have more time and you’re interested in how to evaluate your model for question answering, take a look at the <a href="https://huggingface.co/course/chapter7/7?fw=pt#postprocessing" rel="nofollow">Question answering</a> chapter from the 🤗 Hugging Face Course!',Vt,te,ie,pt,Fe,rs,tt,Us="Inference",Ft,ze,Cs="Great, now that you’ve finetuned a model, you can use it for inference!",zt,He,Is="Come up with a question and some context you’d like the model to predict:",Ht,Qe,Qt,qe,vs='The simplest way to try out your finetuned model for inference is to use it in a <a href="/docs/transformers/v4.33.3/en/main_classes/pipelines#transformers.pipeline">pipeline()</a>. Instantiate a <code>pipeline</code> for question answering with your model, and pass your text to it:',qt,Ye,Yt,Se,ks="You can also manually replicate the results of the <code>pipeline</code> if you’d like:",St,me,Lt,it,Pt;return _=new st({}),k=new Ss({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/question_answering.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/question_answering.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/question_answering.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/question_answering.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/question_answering.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/question_answering.ipynb"}]}}),Z=new Ns({props:{id:"ajPx5LwJD-I"}}),Q=new ts({props:{$$slots:{default:[Ls]},$$scope:{ctx:I}}}),b=new B({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGU=",highlighted:"pip install transformers datasets evaluate"}}),we=new B({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),ye=new st({}),je=new B({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBc3F1YWQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyc3F1YWQlMjIlMkMlMjBzcGxpdCUzRCUyMnRyYWluJTVCJTNBNTAwMCU1RCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>squad = load_dataset(<span class="hljs-string">&quot;squad&quot;</span>, split=<span class="hljs-string">&quot;train[:5000]&quot;</span>)`}}),Je=new B({props:{code:"c3F1YWQlMjAlM0QlMjBzcXVhZC50cmFpbl90ZXN0X3NwbGl0KHRlc3Rfc2l6ZSUzRDAuMik=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>squad = squad.train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),$e=new B({props:{code:"c3F1YWQlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>squad[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;answers&#x27;</span>: {<span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">515</span>], <span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Saint Bernadette Soubirous&#x27;</span>]},
 <span class="hljs-string">&#x27;context&#x27;</span>: <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>,
 <span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;5733be284776f41900661182&#x27;</span>,
 <span class="hljs-string">&#x27;question&#x27;</span>: <span class="hljs-string">&#x27;To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?&#x27;</span>,
 <span class="hljs-string">&#x27;title&#x27;</span>: <span class="hljs-string">&#x27;University_of_Notre_Dame&#x27;</span>
}`}}),Ce=new st({}),Ie=new Ns({props:{id:"qgaM0weJHpA"}}),ke=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),Xe=new B({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc19mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBxdWVzdGlvbnMlMjAlM0QlMjAlNUJxLnN0cmlwKCklMjBmb3IlMjBxJTIwaW4lMjBleGFtcGxlcyU1QiUyMnF1ZXN0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHF1ZXN0aW9ucyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIyY29udGV4dCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1heF9sZW5ndGglM0QzODQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEJTIyb25seV9zZWNvbmQlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBhZGRpbmclM0QlMjJtYXhfbGVuZ3RoJTIyJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMG9mZnNldF9tYXBwaW5nJTIwJTNEJTIwaW5wdXRzLnBvcCglMjJvZmZzZXRfbWFwcGluZyUyMiklMEElMjAlMjAlMjAlMjBhbnN3ZXJzJTIwJTNEJTIwZXhhbXBsZXMlNUIlMjJhbnN3ZXJzJTIyJTVEJTBBJTIwJTIwJTIwJTIwc3RhcnRfcG9zaXRpb25zJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwZW5kX3Bvc2l0aW9ucyUyMCUzRCUyMCU1QiU1RCUwQSUwQSUyMCUyMCUyMCUyMGZvciUyMGklMkMlMjBvZmZzZXQlMjBpbiUyMGVudW1lcmF0ZShvZmZzZXRfbWFwcGluZyklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbnN3ZXIlMjAlM0QlMjBhbnN3ZXJzJTVCaSU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHN0YXJ0X2NoYXIlMjAlM0QlMjBhbnN3ZXIlNUIlMjJhbnN3ZXJfc3RhcnQlMjIlNUQlNUIwJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZW5kX2NoYXIlMjAlM0QlMjBhbnN3ZXIlNUIlMjJhbnN3ZXJfc3RhcnQlMjIlNUQlNUIwJTVEJTIwJTJCJTIwbGVuKGFuc3dlciU1QiUyMnRleHQlMjIlNUQlNUIwJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlcXVlbmNlX2lkcyUyMCUzRCUyMGlucHV0cy5zZXF1ZW5jZV9pZHMoaSklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBGaW5kJTIwdGhlJTIwc3RhcnQlMjBhbmQlMjBlbmQlMjBvZiUyMHRoZSUyMGNvbnRleHQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZHglMjAlM0QlMjAwJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2hpbGUlMjBzZXF1ZW5jZV9pZHMlNUJpZHglNUQlMjAhJTNEJTIwMSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlkeCUyMCUyQiUzRCUyMDElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBjb250ZXh0X3N0YXJ0JTIwJTNEJTIwaWR4JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2hpbGUlMjBzZXF1ZW5jZV9pZHMlNUJpZHglNUQlMjAlM0QlM0QlMjAxJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWR4JTIwJTJCJTNEJTIwMSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbnRleHRfZW5kJTIwJTNEJTIwaWR4JTIwLSUyMDElMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBJZiUyMHRoZSUyMGFuc3dlciUyMGlzJTIwbm90JTIwZnVsbHklMjBpbnNpZGUlMjB0aGUlMjBjb250ZXh0JTJDJTIwbGFiZWwlMjBpdCUyMCgwJTJDJTIwMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZiUyMG9mZnNldCU1QmNvbnRleHRfc3RhcnQlNUQlNUIwJTVEJTIwJTNFJTIwZW5kX2NoYXIlMjBvciUyMG9mZnNldCU1QmNvbnRleHRfZW5kJTVEJTVCMSU1RCUyMCUzQyUyMHN0YXJ0X2NoYXIlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzdGFydF9wb3NpdGlvbnMuYXBwZW5kKDApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZW5kX3Bvc2l0aW9ucy5hcHBlbmQoMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwT3RoZXJ3aXNlJTIwaXQncyUyMHRoZSUyMHN0YXJ0JTIwYW5kJTIwZW5kJTIwdG9rZW4lMjBwb3NpdGlvbnMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZHglMjAlM0QlMjBjb250ZXh0X3N0YXJ0JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2hpbGUlMjBpZHglMjAlM0MlM0QlMjBjb250ZXh0X2VuZCUyMGFuZCUyMG9mZnNldCU1QmlkeCU1RCU1QjAlNUQlMjAlM0MlM0QlMjBzdGFydF9jaGFyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWR4JTIwJTJCJTNEJTIwMSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHN0YXJ0X3Bvc2l0aW9ucy5hcHBlbmQoaWR4JTIwLSUyMDEpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwY29udGV4dF9lbmQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3aGlsZSUyMGlkeCUyMCUzRSUzRCUyMGNvbnRleHRfc3RhcnQlMjBhbmQlMjBvZmZzZXQlNUJpZHglNUQlNUIxJTVEJTIwJTNFJTNEJTIwZW5kX2NoYXIlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZHglMjAtJTNEJTIwMSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGVuZF9wb3NpdGlvbnMuYXBwZW5kKGlkeCUyMCUyQiUyMDEpJTBBJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTVCJTIyc3RhcnRfcG9zaXRpb25zJTIyJTVEJTIwJTNEJTIwc3RhcnRfcG9zaXRpb25zJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTVCJTIyZW5kX3Bvc2l0aW9ucyUyMiU1RCUyMCUzRCUyMGVuZF9wb3NpdGlvbnMlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </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>]]
<span class="hljs-meta">... </span>    inputs = tokenizer(
<span class="hljs-meta">... </span>        questions,
<span class="hljs-meta">... </span>        examples[<span class="hljs-string">&quot;context&quot;</span>],
<span class="hljs-meta">... </span>        max_length=<span class="hljs-number">384</span>,
<span class="hljs-meta">... </span>        truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
<span class="hljs-meta">... </span>        return_offsets_mapping=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>        padding=<span class="hljs-string">&quot;max_length&quot;</span>,
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    offset_mapping = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)
<span class="hljs-meta">... </span>    answers = examples[<span class="hljs-string">&quot;answers&quot;</span>]
<span class="hljs-meta">... </span>    start_positions = []
<span class="hljs-meta">... </span>    end_positions = []

<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(offset_mapping):
<span class="hljs-meta">... </span>        answer = answers[i]
<span class="hljs-meta">... </span>        start_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">... </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>])
<span class="hljs-meta">... </span>        sequence_ids = inputs.sequence_ids(i)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># Find the start and end of the context</span>
<span class="hljs-meta">... </span>        idx = <span class="hljs-number">0</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">while</span> sequence_ids[idx] != <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>            idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>        context_start = idx
<span class="hljs-meta">... </span>        <span class="hljs-keyword">while</span> sequence_ids[idx] == <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>            idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>        context_end = idx - <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>        <span class="hljs-comment"># If the answer is not fully inside the context, label it (0, 0)</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">if</span> offset[context_start][<span class="hljs-number">0</span>] &gt; end_char <span class="hljs-keyword">or</span> offset[context_end][<span class="hljs-number">1</span>] &lt; start_char:
<span class="hljs-meta">... </span>            start_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-meta">... </span>            end_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-meta">... </span>        <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>            <span class="hljs-comment"># Otherwise it&#x27;s the start and end token positions</span>
<span class="hljs-meta">... </span>            idx = context_start
<span class="hljs-meta">... </span>            <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:
<span class="hljs-meta">... </span>                idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>            start_positions.append(idx - <span class="hljs-number">1</span>)

<span class="hljs-meta">... </span>            idx = context_end
<span class="hljs-meta">... </span>            <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:
<span class="hljs-meta">... </span>                idx -= <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>            end_positions.append(idx + <span class="hljs-number">1</span>)

<span class="hljs-meta">... </span>    inputs[<span class="hljs-string">&quot;start_positions&quot;</span>] = start_positions
<span class="hljs-meta">... </span>    inputs[<span class="hljs-string">&quot;end_positions&quot;</span>] = end_positions
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs`}}),Ae=new B({props:{code:"dG9rZW5pemVkX3NxdWFkJTIwJTNEJTIwc3F1YWQubWFwKHByZXByb2Nlc3NfZnVuY3Rpb24lMkMlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUyMHJlbW92ZV9jb2x1bW5zJTNEc3F1YWQlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_squad = squad.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>, remove_columns=squad[<span class="hljs-string">&quot;train&quot;</span>].column_names)'}}),le=new os({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Os],pytorch:[Ds]},$$scope:{ctx:I}}}),Ee=new st({}),re=new os({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[na],pytorch:[sa]},$$scope:{ctx:I}}}),oe=new ts({props:{$$slots:{default:[ra]},$$scope:{ctx:I}}}),We=new st({}),Fe=new st({}),Qe=new B({props:{code:"cXVlc3Rpb24lMjAlM0QlMjAlMjJIb3clMjBtYW55JTIwcHJvZ3JhbW1pbmclMjBsYW5ndWFnZXMlMjBkb2VzJTIwQkxPT00lMjBzdXBwb3J0JTNGJTIyJTBBY29udGV4dCUyMCUzRCUyMCUyMkJMT09NJTIwaGFzJTIwMTc2JTIwYmlsbGlvbiUyMHBhcmFtZXRlcnMlMjBhbmQlMjBjYW4lMjBnZW5lcmF0ZSUyMHRleHQlMjBpbiUyMDQ2JTIwbGFuZ3VhZ2VzJTIwbmF0dXJhbCUyMGxhbmd1YWdlcyUyMGFuZCUyMDEzJTIwcHJvZ3JhbW1pbmclMjBsYW5ndWFnZXMuJTIy",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>question = <span class="hljs-string">&quot;How many programming languages does BLOOM support?&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>context = <span class="hljs-string">&quot;BLOOM has 176 billion parameters and can generate text in 46 languages natural languages and 13 programming languages.&quot;</span>`}}),Ye=new B({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcXVlc3Rpb25fYW5zd2VyZXIlMjAlM0QlMjBwaXBlbGluZSglMjJxdWVzdGlvbi1hbnN3ZXJpbmclMjIlMkMlMjBtb2RlbCUzRCUyMm15X2F3ZXNvbWVfcWFfbW9kZWwlMjIpJTBBcXVlc3Rpb25fYW5zd2VyZXIocXVlc3Rpb24lM0RxdWVzdGlvbiUyQyUyMGNvbnRleHQlM0Rjb250ZXh0KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>question_answerer = pipeline(<span class="hljs-string">&quot;question-answering&quot;</span>, model=<span class="hljs-string">&quot;my_awesome_qa_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>question_answerer(question=question, context=context)
{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.2058267742395401</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">10</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">95</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;176 billion parameters and can generate text in 46 languages natural languages and 13&#x27;</span>}`}}),me=new os({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ma],pytorch:[pa]},$$scope:{ctx:I}}}),{c(){l=h("meta"),m=o(),a=h("p"),c=o(),M=h("h1"),$=h("a"),N=h("span"),w(_.$$.fragment),A=o(),R=h("span"),R.textContent=X,z=o(),w(k.$$.fragment),U=o(),w(Z.$$.fragment),v=o(),V=h("p"),V.textContent=E,C=o(),x=h("ul"),x.innerHTML=s,u=o(),H=h("p"),H.textContent=he,q=o(),L=h("ol"),L.innerHTML=de,Y=o(),w(Q.$$.fragment),S=o(),P=h("p"),P.textContent=ue,i=o(),w(b.$$.fragment),Me=o(),fe=h("p"),fe.textContent=ps,dt=o(),w(we.$$.fragment),ut=o(),D=h("h2"),se=h("a"),lt=h("span"),w(ye.$$.fragment),ss=o(),De=h("span"),De.textContent=is,Mt=o(),ge=h("p"),ge.textContent=ms,ft=o(),w(je.$$.fragment),wt=o(),Te=h("p"),Te.innerHTML=cs,yt=o(),w(Je.$$.fragment),gt=o(),be=h("p"),be.textContent=hs,jt=o(),w($e.$$.fragment),Tt=o(),_e=h("p"),_e.textContent=ds,Jt=o(),Ue=h("ul"),Ue.innerHTML=us,bt=o(),K=h("h2"),ae=h("a"),nt=h("span"),w(Ce.$$.fragment),as=o(),Ke=h("span"),Ke.textContent=Ms,$t=o(),w(Ie.$$.fragment),_t=o(),ve=h("p"),ve.innerHTML=fs,Ut=o(),w(ke.$$.fragment),Ct=o(),Ze=h("p"),Ze.textContent=ws,It=o(),xe=h("ol"),xe.innerHTML=ys,vt=o(),Re=h("p"),Re.innerHTML=gs,kt=o(),w(Xe.$$.fragment),Zt=o(),Be=h("p"),Be.innerHTML=js,xt=o(),w(Ae.$$.fragment),Rt=o(),Ge=h("p"),Ge.innerHTML=Ts,Xt=o(),w(le.$$.fragment),Bt=o(),O=h("h2"),ne=h("a"),rt=h("span"),w(Ee.$$.fragment),ls=o(),Oe=h("span"),Oe.textContent=Js,At=o(),w(re.$$.fragment),Gt=o(),w(oe.$$.fragment),Et=o(),ee=h("h2"),pe=h("a"),ot=h("span"),w(We.$$.fragment),ns=o(),et=h("span"),et.textContent=bs,Wt=o(),Ne=h("p"),Ne.innerHTML=$s,Nt=o(),Ve=h("p"),Ve.innerHTML=_s,Vt=o(),te=h("h2"),ie=h("a"),pt=h("span"),w(Fe.$$.fragment),rs=o(),tt=h("span"),tt.textContent=Us,Ft=o(),ze=h("p"),ze.textContent=Cs,zt=o(),He=h("p"),He.textContent=Is,Ht=o(),w(Qe.$$.fragment),Qt=o(),qe=h("p"),qe.innerHTML=vs,qt=o(),w(Ye.$$.fragment),Yt=o(),Se=h("p"),Se.innerHTML=ks,St=o(),w(me.$$.fragment),Lt=o(),it=h("p"),this.h()},l(e){const r=Ys("svelte-1phssyn",document.head);l=d(r,"META",{name:!0,content:!0}),r.forEach(t),m=p(e),a=d(e,"P",{}),F(a).forEach(t),c=p(e),M=d(e,"H1",{class:!0});var Le=F(M);$=d(Le,"A",{id:!0,class:!0,href:!0});var mt=F($);N=d(mt,"SPAN",{});var ct=F(N);y(_.$$.fragment,ct),ct.forEach(t),mt.forEach(t),A=p(Le),R=d(Le,"SPAN",{"data-svelte-h":!0}),f(R)!=="svelte-1i2el67"&&(R.textContent=X),Le.forEach(t),z=p(e),y(k.$$.fragment,e),U=p(e),y(Z.$$.fragment,e),v=p(e),V=d(e,"P",{"data-svelte-h":!0}),f(V)!=="svelte-wddg3q"&&(V.textContent=E),C=p(e),x=d(e,"UL",{"data-svelte-h":!0}),f(x)!=="svelte-juxaac"&&(x.innerHTML=s),u=p(e),H=d(e,"P",{"data-svelte-h":!0}),f(H)!=="svelte-1aff4p7"&&(H.textContent=he),q=p(e),L=d(e,"OL",{"data-svelte-h":!0}),f(L)!=="svelte-aty3s5"&&(L.innerHTML=de),Y=p(e),y(Q.$$.fragment,e),S=p(e),P=d(e,"P",{"data-svelte-h":!0}),f(P)!=="svelte-1c9nexd"&&(P.textContent=ue),i=p(e),y(b.$$.fragment,e),Me=p(e),fe=d(e,"P",{"data-svelte-h":!0}),f(fe)!=="svelte-k76o1m"&&(fe.textContent=ps),dt=p(e),y(we.$$.fragment,e),ut=p(e),D=d(e,"H2",{class:!0});var Pe=F(D);se=d(Pe,"A",{id:!0,class:!0,href:!0});var ht=F(se);lt=d(ht,"SPAN",{});var Zs=F(lt);y(ye.$$.fragment,Zs),Zs.forEach(t),ht.forEach(t),ss=p(Pe),De=d(Pe,"SPAN",{"data-svelte-h":!0}),f(De)!=="svelte-mole1n"&&(De.textContent=is),Pe.forEach(t),Mt=p(e),ge=d(e,"P",{"data-svelte-h":!0}),f(ge)!=="svelte-86lsp1"&&(ge.textContent=ms),ft=p(e),y(je.$$.fragment,e),wt=p(e),Te=d(e,"P",{"data-svelte-h":!0}),f(Te)!=="svelte-1izknij"&&(Te.innerHTML=cs),yt=p(e),y(Je.$$.fragment,e),gt=p(e),be=d(e,"P",{"data-svelte-h":!0}),f(be)!=="svelte-1m91ua0"&&(be.textContent=hs),jt=p(e),y($e.$$.fragment,e),Tt=p(e),_e=d(e,"P",{"data-svelte-h":!0}),f(_e)!=="svelte-ixla8d"&&(_e.textContent=ds),Jt=p(e),Ue=d(e,"UL",{"data-svelte-h":!0}),f(Ue)!=="svelte-13sugm7"&&(Ue.innerHTML=us),bt=p(e),K=d(e,"H2",{class:!0});var Dt=F(K);ae=d(Dt,"A",{id:!0,class:!0,href:!0});var xs=F(ae);nt=d(xs,"SPAN",{});var Rs=F(nt);y(Ce.$$.fragment,Rs),Rs.forEach(t),xs.forEach(t),as=p(Dt),Ke=d(Dt,"SPAN",{"data-svelte-h":!0}),f(Ke)!=="svelte-1cg9qj"&&(Ke.textContent=Ms),Dt.forEach(t),$t=p(e),y(Ie.$$.fragment,e),_t=p(e),ve=d(e,"P",{"data-svelte-h":!0}),f(ve)!=="svelte-1l87utj"&&(ve.innerHTML=fs),Ut=p(e),y(ke.$$.fragment,e),Ct=p(e),Ze=d(e,"P",{"data-svelte-h":!0}),f(Ze)!=="svelte-6fi1jw"&&(Ze.textContent=ws),It=p(e),xe=d(e,"OL",{"data-svelte-h":!0}),f(xe)!=="svelte-1pbu9ad"&&(xe.innerHTML=ys),vt=p(e),Re=d(e,"P",{"data-svelte-h":!0}),f(Re)!=="svelte-1l18kqg"&&(Re.innerHTML=gs),kt=p(e),y(Xe.$$.fragment,e),Zt=p(e),Be=d(e,"P",{"data-svelte-h":!0}),f(Be)!=="svelte-1j29ck8"&&(Be.innerHTML=js),xt=p(e),y(Ae.$$.fragment,e),Rt=p(e),Ge=d(e,"P",{"data-svelte-h":!0}),f(Ge)!=="svelte-ko2gw8"&&(Ge.innerHTML=Ts),Xt=p(e),y(le.$$.fragment,e),Bt=p(e),O=d(e,"H2",{class:!0});var Kt=F(O);ne=d(Kt,"A",{id:!0,class:!0,href:!0});var Xs=F(ne);rt=d(Xs,"SPAN",{});var Bs=F(rt);y(Ee.$$.fragment,Bs),Bs.forEach(t),Xs.forEach(t),ls=p(Kt),Oe=d(Kt,"SPAN",{"data-svelte-h":!0}),f(Oe)!=="svelte-5arm0l"&&(Oe.textContent=Js),Kt.forEach(t),At=p(e),y(re.$$.fragment,e),Gt=p(e),y(oe.$$.fragment,e),Et=p(e),ee=d(e,"H2",{class:!0});var Ot=F(ee);pe=d(Ot,"A",{id:!0,class:!0,href:!0});var As=F(pe);ot=d(As,"SPAN",{});var Gs=F(ot);y(We.$$.fragment,Gs),Gs.forEach(t),As.forEach(t),ns=p(Ot),et=d(Ot,"SPAN",{"data-svelte-h":!0}),f(et)!=="svelte-sh8s6s"&&(et.textContent=bs),Ot.forEach(t),Wt=p(e),Ne=d(e,"P",{"data-svelte-h":!0}),f(Ne)!=="svelte-1djcdi9"&&(Ne.innerHTML=$s),Nt=p(e),Ve=d(e,"P",{"data-svelte-h":!0}),f(Ve)!=="svelte-ktob7c"&&(Ve.innerHTML=_s),Vt=p(e),te=d(e,"H2",{class:!0});var es=F(te);ie=d(es,"A",{id:!0,class:!0,href:!0});var Es=F(ie);pt=d(Es,"SPAN",{});var Ws=F(pt);y(Fe.$$.fragment,Ws),Ws.forEach(t),Es.forEach(t),rs=p(es),tt=d(es,"SPAN",{"data-svelte-h":!0}),f(tt)!=="svelte-199uz7g"&&(tt.textContent=Us),es.forEach(t),Ft=p(e),ze=d(e,"P",{"data-svelte-h":!0}),f(ze)!=="svelte-633ppb"&&(ze.textContent=Cs),zt=p(e),He=d(e,"P",{"data-svelte-h":!0}),f(He)!=="svelte-1wy7p4p"&&(He.textContent=Is),Ht=p(e),y(Qe.$$.fragment,e),Qt=p(e),qe=d(e,"P",{"data-svelte-h":!0}),f(qe)!=="svelte-1emol1a"&&(qe.innerHTML=vs),qt=p(e),y(Ye.$$.fragment,e),Yt=p(e),Se=d(e,"P",{"data-svelte-h":!0}),f(Se)!=="svelte-1njl8vm"&&(Se.innerHTML=ks),St=p(e),y(me.$$.fragment,e),Lt=p(e),it=d(e,"P",{}),F(it).forEach(t),this.h()},h(){G(l,"name","hf:doc:metadata"),G(l,"content",JSON.stringify(ha)),G($,"id","question-answering"),G($,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G($,"href","#question-answering"),G(M,"class","relative group"),G(se,"id","load-squad-dataset"),G(se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G(se,"href","#load-squad-dataset"),G(D,"class","relative group"),G(ae,"id","preprocess"),G(ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G(ae,"href","#preprocess"),G(K,"class","relative group"),G(ne,"id","train"),G(ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G(ne,"href","#train"),G(O,"class","relative group"),G(pe,"id","evaluate"),G(pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G(pe,"href","#evaluate"),G(ee,"class","relative group"),G(ie,"id","inference"),G(ie,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),G(ie,"href","#inference"),G(te,"class","relative group")},m(e,r){W(document.head,l),n(e,m,r),n(e,a,r),n(e,c,r),n(e,M,r),W(M,$),W($,N),g(_,N,null),W(M,A),W(M,R),n(e,z,r),g(k,e,r),n(e,U,r),g(Z,e,r),n(e,v,r),n(e,V,r),n(e,C,r),n(e,x,r),n(e,u,r),n(e,H,r),n(e,q,r),n(e,L,r),n(e,Y,r),g(Q,e,r),n(e,S,r),n(e,P,r),n(e,i,r),g(b,e,r),n(e,Me,r),n(e,fe,r),n(e,dt,r),g(we,e,r),n(e,ut,r),n(e,D,r),W(D,se),W(se,lt),g(ye,lt,null),W(D,ss),W(D,De),n(e,Mt,r),n(e,ge,r),n(e,ft,r),g(je,e,r),n(e,wt,r),n(e,Te,r),n(e,yt,r),g(Je,e,r),n(e,gt,r),n(e,be,r),n(e,jt,r),g($e,e,r),n(e,Tt,r),n(e,_e,r),n(e,Jt,r),n(e,Ue,r),n(e,bt,r),n(e,K,r),W(K,ae),W(ae,nt),g(Ce,nt,null),W(K,as),W(K,Ke),n(e,$t,r),g(Ie,e,r),n(e,_t,r),n(e,ve,r),n(e,Ut,r),g(ke,e,r),n(e,Ct,r),n(e,Ze,r),n(e,It,r),n(e,xe,r),n(e,vt,r),n(e,Re,r),n(e,kt,r),g(Xe,e,r),n(e,Zt,r),n(e,Be,r),n(e,xt,r),g(Ae,e,r),n(e,Rt,r),n(e,Ge,r),n(e,Xt,r),g(le,e,r),n(e,Bt,r),n(e,O,r),W(O,ne),W(ne,rt),g(Ee,rt,null),W(O,ls),W(O,Oe),n(e,At,r),g(re,e,r),n(e,Gt,r),g(oe,e,r),n(e,Et,r),n(e,ee,r),W(ee,pe),W(pe,ot),g(We,ot,null),W(ee,ns),W(ee,et),n(e,Wt,r),n(e,Ne,r),n(e,Nt,r),n(e,Ve,r),n(e,Vt,r),n(e,te,r),W(te,ie),W(ie,pt),g(Fe,pt,null),W(te,rs),W(te,tt),n(e,Ft,r),n(e,ze,r),n(e,zt,r),n(e,He,r),n(e,Ht,r),g(Qe,e,r),n(e,Qt,r),n(e,qe,r),n(e,qt,r),g(Ye,e,r),n(e,Yt,r),n(e,Se,r),n(e,St,r),g(me,e,r),n(e,Lt,r),n(e,it,r),Pt=!0},p(e,[r]){const Le={};r&2&&(Le.$$scope={dirty:r,ctx:e}),Q.$set(Le);const mt={};r&2&&(mt.$$scope={dirty:r,ctx:e}),le.$set(mt);const ct={};r&2&&(ct.$$scope={dirty:r,ctx:e}),re.$set(ct);const Pe={};r&2&&(Pe.$$scope={dirty:r,ctx:e}),oe.$set(Pe);const ht={};r&2&&(ht.$$scope={dirty:r,ctx:e}),me.$set(ht)},i(e){Pt||(j(_.$$.fragment,e),j(k.$$.fragment,e),j(Z.$$.fragment,e),j(Q.$$.fragment,e),j(b.$$.fragment,e),j(we.$$.fragment,e),j(ye.$$.fragment,e),j(je.$$.fragment,e),j(Je.$$.fragment,e),j($e.$$.fragment,e),j(Ce.$$.fragment,e),j(Ie.$$.fragment,e),j(ke.$$.fragment,e),j(Xe.$$.fragment,e),j(Ae.$$.fragment,e),j(le.$$.fragment,e),j(Ee.$$.fragment,e),j(re.$$.fragment,e),j(oe.$$.fragment,e),j(We.$$.fragment,e),j(Fe.$$.fragment,e),j(Qe.$$.fragment,e),j(Ye.$$.fragment,e),j(me.$$.fragment,e),Pt=!0)},o(e){T(_.$$.fragment,e),T(k.$$.fragment,e),T(Z.$$.fragment,e),T(Q.$$.fragment,e),T(b.$$.fragment,e),T(we.$$.fragment,e),T(ye.$$.fragment,e),T(je.$$.fragment,e),T(Je.$$.fragment,e),T($e.$$.fragment,e),T(Ce.$$.fragment,e),T(Ie.$$.fragment,e),T(ke.$$.fragment,e),T(Xe.$$.fragment,e),T(Ae.$$.fragment,e),T(le.$$.fragment,e),T(Ee.$$.fragment,e),T(re.$$.fragment,e),T(oe.$$.fragment,e),T(We.$$.fragment,e),T(Fe.$$.fragment,e),T(Qe.$$.fragment,e),T(Ye.$$.fragment,e),T(me.$$.fragment,e),Pt=!1},d(e){e&&(t(m),t(a),t(c),t(M),t(z),t(U),t(v),t(V),t(C),t(x),t(u),t(H),t(q),t(L),t(Y),t(S),t(P),t(i),t(Me),t(fe),t(dt),t(ut),t(D),t(Mt),t(ge),t(ft),t(wt),t(Te),t(yt),t(gt),t(be),t(jt),t(Tt),t(_e),t(Jt),t(Ue),t(bt),t(K),t($t),t(_t),t(ve),t(Ut),t(Ct),t(Ze),t(It),t(xe),t(vt),t(Re),t(kt),t(Zt),t(Be),t(xt),t(Rt),t(Ge),t(Xt),t(Bt),t(O),t(At),t(Gt),t(Et),t(ee),t(Wt),t(Ne),t(Nt),t(Ve),t(Vt),t(te),t(Ft),t(ze),t(zt),t(He),t(Ht),t(Qt),t(qe),t(qt),t(Yt),t(Se),t(St),t(Lt),t(it)),t(l),J(_),J(k,e),J(Z,e),J(Q,e),J(b,e),J(we,e),J(ye),J(je,e),J(Je,e),J($e,e),J(Ce),J(Ie,e),J(ke,e),J(Xe,e),J(Ae,e),J(le,e),J(Ee),J(re,e),J(oe,e),J(We),J(Fe),J(Qe,e),J(Ye,e),J(me,e)}}}const ha={local:"question-answering",sections:[{local:"load-squad-dataset",title:"Load SQuAD dataset"},{local:"preprocess",title:"Preprocess"},{local:"train",title:"Train"},{local:"evaluate",title:"Evaluate"},{local:"inference",title:"Inference"}],title:"Question answering"};function da(I){return Hs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ja extends Qs{constructor(l){super(),qs(this,l,da,ca,zs,{})}}export{Ja as component};
