import{s as fa,o as Ua,n as $l}from"../chunks/scheduler.cc52f4b9.js";import{S as ja,i as Ia,e as J,s as r,c as M,q as ie,H as da,h as ka,a as b,d as n,b as o,f as vl,g as h,j as f,r as re,u as wa,k as Dl,l as g,m as a,n as u,o as m,E as _,t as p,p as d,F as v}from"../chunks/index.5b747fde.js";import{T as Bl}from"../chunks/Tip.f0925d57.js";import{C as ga,H as Zl,E as _a}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d38ac5a9.js";import{Y as ya}from"../chunks/Youtube.8bb4154e.js";import{C as T}from"../chunks/CodeBlock.665bfc37.js";import{C as Ja}from"../chunks/CourseFloatingBanner.b33fcd79.js";import{F as va}from"../chunks/FrameworkSwitchCourse.b3b657b3.js";function Ba(w){let s,i;return s=new Ja({props:{chapter:6,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/chapter6/section3b_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter6/section3b_tf.ipynb"}]}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Za(w){let s,i;return s=new Ja({props:{chapter:6,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/chapter6/section3b_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter6/section3b_pt.ipynb"}]}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function $a(w){let s,i;return s=new ya({props:{id:"b3u8RzBCX9Y"}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function xa(w){let s,i;return s=new ya({props:{id:"_wxyB3j3mk4"}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Ga(w){let s,i;return s=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS1jYXNlZC1kaXN0aWxsZWQtc3F1YWQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIocXVlc3Rpb24lMkMlMjBjb250ZXh0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForQuestionAnswering

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-cased-distilled-squad&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = TFAutoModelForQuestionAnswering.from_pretrained(model_checkpoint)

inputs = tokenizer(question, context, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Ca(w){let s,i;return s=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZyUwQSUwQW1vZGVsX2NoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtY2FzZWQtZGlzdGlsbGVkLXNxdWFkJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForQuestionAnswering

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-cased-distilled-squad&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)

inputs = tokenizer(question, context, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Wa(w){let s,i;return s=new T({props:{code:"KDElMkMlMjA2NiklMjAoMSUyQyUyMDY2KQ==",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">66</span>) (<span class="hljs-number">1</span>, <span class="hljs-number">66</span>)',wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Ra(w){let s,i;return s=new T({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNjYlNUQpJTIwdG9yY2guU2l6ZSglNUIxJTJDJTIwNjYlNUQp",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">66</span>]) torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">66</span>])',wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Na(w){let s,i;return s=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjBNYXNrJTIwZXZlcnl0aGluZyUyMGFwYXJ0JTIwZnJvbSUyMHRoZSUyMHRva2VucyUyMG9mJTIwdGhlJTIwY29udGV4dCUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjBVbm1hc2slMjB0aGUlMjAlNUJDTFMlNUQlMjB0b2tlbiUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEFtYXNrJTIwJTNEJTIwdGYuY29uc3RhbnQobWFzayklNUJOb25lJTVEJTBBJTBBc3RhcnRfbG9naXRzJTIwJTNEJTIwdGYud2hlcmUobWFzayUyQyUyMC0xMDAwMCUyQyUyMHN0YXJ0X2xvZ2l0cyklMEFlbmRfbG9naXRzJTIwJTNEJTIwdGYud2hlcmUobWFzayUyQyUyMC0xMDAwMCUyQyUyMGVuZF9sb2dpdHMp",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
mask = tf.constant(mask)[<span class="hljs-literal">None</span>]

start_logits = tf.where(mask, -<span class="hljs-number">10000</span>, start_logits)
end_logits = tf.where(mask, -<span class="hljs-number">10000</span>, end_logits)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Va(w){let s,i;return s=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjBNYXNrJTIwZXZlcnl0aGluZyUyMGFwYXJ0JTIwZnJvbSUyMHRoZSUyMHRva2VucyUyMG9mJTIwdGhlJTIwY29udGV4dCUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjBVbm1hc2slMjB0aGUlMjAlNUJDTFMlNUQlMjB0b2tlbiUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEFtYXNrJTIwJTNEJTIwdG9yY2gudGVuc29yKG1hc2spJTVCTm9uZSU1RCUwQSUwQXN0YXJ0X2xvZ2l0cyU1Qm1hc2slNUQlMjAlM0QlMjAtMTAwMDAlMEFlbmRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMA==",highlighted:`<span class="hljs-keyword">import</span> torch

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
mask = torch.tensor(mask)[<span class="hljs-literal">None</span>]

start_logits[mask] = -<span class="hljs-number">10000</span>
end_logits[mask] = -<span class="hljs-number">10000</span>`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Xa(w){let s,i;return s=new T({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpJTVCMCU1RC5udW1weSgpJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0Zi5tYXRoLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGF4aXMlM0QtMSklNUIwJTVELm51bXB5KCk=",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function za(w){let s,i;return s=new T({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklNUIwJTVEJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0b3JjaC5ubi5mdW5jdGlvbmFsLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGRpbSUzRC0xKSU1QjAlNUQ=",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Ha(w){let s,i="Then we’ll mask the values where <code>start_index &gt; end_index</code> by setting them to <code>0</code> (the other probabilities are all positive numbers). The <code>np.triu()</code> function returns the upper triangular part of the 2D tensor passed as an argument, so it will do that masking for us:",t,c,y;return c=new T({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBc2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

scores = np.triu(scores)`,wrap:!1}}),{c(){s=J("p"),s.innerHTML=i,t=r(),M(c.$$.fragment)},l(U){s=b(U,"P",{"data-svelte-h":!0}),f(s)!=="svelte-sxoqrk"&&(s.innerHTML=i),t=o(U),h(c.$$.fragment,U)},m(U,j){a(U,s,j),a(U,t,j),u(c,U,j),y=!0},i(U){y||(p(c.$$.fragment,U),y=!0)},o(U){m(c.$$.fragment,U),y=!1},d(U){U&&(n(s),n(t)),d(c,U)}}}function Qa(w){let s,i="Then we’ll mask the values where <code>start_index &gt; end_index</code> by setting them to <code>0</code> (the other probabilities are all positive numbers). The <code>torch.triu()</code> function returns the upper triangular part of the 2D tensor passed as an argument, so it will do that masking for us:",t,c,y;return c=new T({props:{code:"c2NvcmVzJTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMp",highlighted:"scores = torch.triu(scores)",wrap:!1}}),{c(){s=J("p"),s.innerHTML=i,t=r(),M(c.$$.fragment)},l(U){s=b(U,"P",{"data-svelte-h":!0}),f(s)!=="svelte-1htym8"&&(s.innerHTML=i),t=o(U),h(c.$$.fragment,U)},m(U,j){a(U,s,j),a(U,t,j),u(c,U,j),y=!0},i(U){y||(p(c.$$.fragment,U),y=!0)},o(U){m(c.$$.fragment,U),y=!1},d(U){U&&(n(s),n(t)),d(c,U)}}}function Ea(w){let s,i="✏️ <strong>Try it out!</strong> Compute the start and end indices for the five most likely answers.";return{c(){s=J("p"),s.innerHTML=i},l(t){s=b(t,"P",{"data-svelte-h":!0}),f(s)!=="svelte-1agqe6l"&&(s.innerHTML=i)},m(t,c){a(t,s,c)},p:$l,d(t){t&&n(s)}}}function Fa(w){let s,i="✏️ <strong>Try it out!</strong> Use the best scores you computed earlier to show the five most likely answers. To check your results, go back to the first pipeline and pass in <code>top_k=5</code> when calling it.";return{c(){s=J("p"),s.innerHTML=i},l(t){s=b(t,"P",{"data-svelte-h":!0}),f(s)!=="svelte-gm880d"&&(s.innerHTML=i)},m(t,c){a(t,s,c)},p:$l,d(t){t&&n(s)}}}function Ya(w){let s,i,t,c;return s=new T({props:{code:"XyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIpJTBBb2Zmc2V0cyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb2Zmc2V0X21hcHBpbmclMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW5wdXRzLmNvbnZlcnRfdG9fdGVuc29ycyglMjJ0ZiUyMiklMEFwcmludChpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUp",highlighted:`_ = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
offsets = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)

inputs = inputs.convert_to_tensors(<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)`,wrap:!1}}),t=new T({props:{code:"KDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(s.$$.fragment),i=r(),M(t.$$.fragment)},l(y){h(s.$$.fragment,y),i=o(y),h(t.$$.fragment,y)},m(y,U){u(s,y,U),a(y,i,U),u(t,y,U),c=!0},i(y){c||(p(s.$$.fragment,y),p(t.$$.fragment,y),c=!0)},o(y){m(s.$$.fragment,y),m(t.$$.fragment,y),c=!1},d(y){y&&n(i),d(s,y),d(t,y)}}}function Sa(w){let s,i,t,c;return s=new T({props:{code:"XyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIpJTBBb2Zmc2V0cyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb2Zmc2V0X21hcHBpbmclMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW5wdXRzLmNvbnZlcnRfdG9fdGVuc29ycyglMjJwdCUyMiklMEFwcmludChpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUp",highlighted:`_ = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
offsets = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)

inputs = inputs.convert_to_tensors(<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)`,wrap:!1}}),t=new T({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(s.$$.fragment),i=r(),M(t.$$.fragment)},l(y){h(s.$$.fragment,y),i=o(y),h(t.$$.fragment,y)},m(y,U){u(s,y,U),a(y,i,U),u(t,y,U),c=!0},i(y){c||(p(s.$$.fragment,y),p(t.$$.fragment,y),c=!0)},o(y){m(s.$$.fragment,y),m(t.$$.fragment,y),c=!1},d(y){y&&n(i),d(s,y),d(t,y)}}}function Aa(w){let s,i;return s=new T({props:{code:"KDIlMkMlMjAzODQpJTIwKDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>) (<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function qa(w){let s,i;return s=new T({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKSUyMHRvcmNoLlNpemUoJTVCMiUyQyUyMDM4NCU1RCk=",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>]) torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function La(w){let s,i;return s=new T({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwTWFzayUyMGV2ZXJ5dGhpbmclMjBhcGFydCUyMGZyb20lMjB0aGUlMjB0b2tlbnMlMjBvZiUyMHRoZSUyMGNvbnRleHQlMEFtYXNrJTIwJTNEJTIwJTVCaSUyMCElM0QlMjAxJTIwZm9yJTIwaSUyMGluJTIwc2VxdWVuY2VfaWRzJTVEJTBBJTIzJTIwVW5tYXNrJTIwdGhlJTIwJTVCQ0xTJTVEJTIwdG9rZW4lMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwTWFzayUyMGFsbCUyMHRoZSUyMCU1QlBBRCU1RCUyMHRva2VucyUwQW1hc2slMjAlM0QlMjB0Zi5tYXRoLmxvZ2ljYWxfb3IodGYuY29uc3RhbnQobWFzayklNUJOb25lJTVEJTJDJTIwaW5wdXRzJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlNUQlMjAlM0QlM0QlMjAwKSUwQSUwQXN0YXJ0X2xvZ2l0cyUyMCUzRCUyMHRmLndoZXJlKG1hc2slMkMlMjAtMTAwMDAlMkMlMjBzdGFydF9sb2dpdHMpJTBBZW5kX2xvZ2l0cyUyMCUzRCUyMHRmLndoZXJlKG1hc2slMkMlMjAtMTAwMDAlMkMlMjBlbmRfbG9naXRzKQ==",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Mask all the [PAD] tokens</span>
mask = tf.math.logical_or(tf.constant(mask)[<span class="hljs-literal">None</span>], inputs[<span class="hljs-string">&quot;attention_mask&quot;</span>] == <span class="hljs-number">0</span>)

start_logits = tf.where(mask, -<span class="hljs-number">10000</span>, start_logits)
end_logits = tf.where(mask, -<span class="hljs-number">10000</span>, end_logits)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Da(w){let s,i;return s=new T({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwTWFzayUyMGV2ZXJ5dGhpbmclMjBhcGFydCUyMGZyb20lMjB0aGUlMjB0b2tlbnMlMjBvZiUyMHRoZSUyMGNvbnRleHQlMEFtYXNrJTIwJTNEJTIwJTVCaSUyMCElM0QlMjAxJTIwZm9yJTIwaSUyMGluJTIwc2VxdWVuY2VfaWRzJTVEJTBBJTIzJTIwVW5tYXNrJTIwdGhlJTIwJTVCQ0xTJTVEJTIwdG9rZW4lMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwTWFzayUyMGFsbCUyMHRoZSUyMCU1QlBBRCU1RCUyMHRva2VucyUwQW1hc2slMjAlM0QlMjB0b3JjaC5sb2dpY2FsX29yKHRvcmNoLnRlbnNvcihtYXNrKSU1Qk5vbmUlNUQlMkMlMjAoaW5wdXRzJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlNUQlMjAlM0QlM0QlMjAwKSklMEElMEFzdGFydF9sb2dpdHMlNUJtYXNrJTVEJTIwJTNEJTIwLTEwMDAwJTBBZW5kX2xvZ2l0cyU1Qm1hc2slNUQlMjAlM0QlMjAtMTAwMDA=",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Mask all the [PAD] tokens</span>
mask = torch.logical_or(torch.tensor(mask)[<span class="hljs-literal">None</span>], (inputs[<span class="hljs-string">&quot;attention_mask&quot;</span>] == <span class="hljs-number">0</span>))

start_logits[mask] = -<span class="hljs-number">10000</span>
end_logits[mask] = -<span class="hljs-number">10000</span>`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Pa(w){let s,i;return s=new T({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpLm51bXB5KCklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChlbmRfbG9naXRzJTJDJTIwYXhpcyUzRC0xKS5udW1weSgp",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>).numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>).numpy()`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Ka(w){let s,i;return s=new T({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChlbmRfbG9naXRzJTJDJTIwZGltJTNELTEp",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function Oa(w){let s,i;return s=new T({props:{code:"Y2FuZGlkYXRlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMHN0YXJ0X3Byb2JzJTJDJTIwZW5kX3Byb2JzJTIwaW4lMjB6aXAoc3RhcnRfcHJvYmFiaWxpdGllcyUyQyUyMGVuZF9wcm9iYWJpbGl0aWVzKSUzQSUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyMCUzRCUyMHN0YXJ0X3Byb2JzJTVCJTNBJTJDJTIwTm9uZSU1RCUyMColMjBlbmRfcHJvYnMlNUJOb25lJTJDJTIwJTNBJTVEJTBBJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwbnAudHJpdShzY29yZXMpLmFyZ21heCgpLml0ZW0oKSUwQSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2lkeCUyMCUzRCUyMGlkeCUyMCUyRiUyRiUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEElMjAlMjAlMjAlMjBlbmRfaWR4JTIwJTNEJTIwaWR4JTIwJTI1JTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQSUyMCUyMCUyMCUyMHNjb3JlJTIwJTNEJTIwc2NvcmVzJTVCc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCU1RC5pdGVtKCklMEElMjAlMjAlMjAlMjBjYW5kaWRhdGVzLmFwcGVuZCgoc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCUyQyUyMHNjb3JlKSklMEElMEFwcmludChjYW5kaWRhdGVzKQ==",highlighted:`candidates = []
<span class="hljs-keyword">for</span> start_probs, end_probs <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(start_probabilities, end_probabilities):
    scores = start_probs[:, <span class="hljs-literal">None</span>] * end_probs[<span class="hljs-literal">None</span>, :]
    idx = np.triu(scores).argmax().item()

    start_idx = idx // scores.shape[<span class="hljs-number">1</span>]
    end_idx = idx % scores.shape[<span class="hljs-number">1</span>]
    score = scores[start_idx, end_idx].item()
    candidates.append((start_idx, end_idx, score))

<span class="hljs-built_in">print</span>(candidates)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function ei(w){let s,i;return s=new T({props:{code:"Y2FuZGlkYXRlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMHN0YXJ0X3Byb2JzJTJDJTIwZW5kX3Byb2JzJTIwaW4lMjB6aXAoc3RhcnRfcHJvYmFiaWxpdGllcyUyQyUyMGVuZF9wcm9iYWJpbGl0aWVzKSUzQSUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyMCUzRCUyMHN0YXJ0X3Byb2JzJTVCJTNBJTJDJTIwTm9uZSU1RCUyMColMjBlbmRfcHJvYnMlNUJOb25lJTJDJTIwJTNBJTVEJTBBJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMpLmFyZ21heCgpLml0ZW0oKSUwQSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2lkeCUyMCUzRCUyMGlkeCUyMCUyRiUyRiUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEElMjAlMjAlMjAlMjBlbmRfaWR4JTIwJTNEJTIwaWR4JTIwJTI1JTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQSUyMCUyMCUyMCUyMHNjb3JlJTIwJTNEJTIwc2NvcmVzJTVCc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCU1RC5pdGVtKCklMEElMjAlMjAlMjAlMjBjYW5kaWRhdGVzLmFwcGVuZCgoc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCUyQyUyMHNjb3JlKSklMEElMEFwcmludChjYW5kaWRhdGVzKQ==",highlighted:`candidates = []
<span class="hljs-keyword">for</span> start_probs, end_probs <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(start_probabilities, end_probabilities):
    scores = start_probs[:, <span class="hljs-literal">None</span>] * end_probs[<span class="hljs-literal">None</span>, :]
    idx = torch.triu(scores).argmax().item()

    start_idx = idx // scores.shape[<span class="hljs-number">1</span>]
    end_idx = idx % scores.shape[<span class="hljs-number">1</span>]
    score = scores[start_idx, end_idx].item()
    candidates.append((start_idx, end_idx, score))

<span class="hljs-built_in">print</span>(candidates)`,wrap:!1}}),{c(){M(s.$$.fragment)},l(t){h(s.$$.fragment,t)},m(t,c){u(s,t,c),i=!0},i(t){i||(p(s.$$.fragment,t),i=!0)},o(t){m(s.$$.fragment,t),i=!1},d(t){d(s,t)}}}function ti(w){let s,i="✏️ <strong>Try it out!</strong> Adapt the code above to return the scores and spans for the five most likely answers (in total, not per chunk).";return{c(){s=J("p"),s.innerHTML=i},l(t){s=b(t,"P",{"data-svelte-h":!0}),f(s)!=="svelte-ox2gfp"&&(s.innerHTML=i)},m(t,c){a(t,s,c)},p:$l,d(t){t&&n(s)}}}function si(w){let s,i="✏️ <strong>Try it out!</strong> Use the best scores you computed before to show the five most likely answers (for the whole context, not each chunk). To check your results, go back to the first pipeline and pass in <code>top_k=5</code> when calling it.";return{c(){s=J("p"),s.innerHTML=i},l(t){s=b(t,"P",{"data-svelte-h":!0}),f(s)!=="svelte-5r45to"&&(s.innerHTML=i)},m(t,c){a(t,s,c)},p:$l,d(t){t&&n(s)}}}function li(w){let s,i,t,c,y,U,j,es,oe,ts,B,Z,Rt,me,Pl="We will now dive into the <code>question-answering</code> pipeline and see how to leverage the offsets to grab the answer to the question at hand from the context, a bit like we did for the grouped entities in the previous section. Then we will see how we can deal with very long contexts that end up being truncated. You can skip this section if you’re not interested in the question answering task.",ss,$,x,Nt,pe,ls,ce,Kl='As we saw in <a href="/course/chapter1">Chapter 1</a>, we can use the <code>question-answering</code> pipeline like this to get the answer to a question:',ns,Me,as,he,is,ue,Ol="Unlike the other pipelines, which can’t truncate and split texts that are longer than the maximum length accepted by the model (and thus may miss information at the end of a document), this pipeline can deal with very long contexts and will return the answer to the question even if it’s at the end:",rs,de,os,we,ms,ye,en="Let’s see how it does all of this!",ps,Je,cs,be,tn='Like with any other pipeline, we start by tokenizing our input and then send it through the model. The checkpoint used by default for the <code>question-answering</code> pipeline is <a href="https://huggingface.co/distilbert-base-cased-distilled-squad" rel="nofollow"><code>distilbert-base-cased-distilled-squad</code></a> (the “squad” in the name comes from the dataset on which the model was fine-tuned; we’ll talk more about the SQuAD dataset in <a href="/course/chapter7/7">Chapter 7</a>):',Ms,G,C,Vt,Te,sn="Note that we tokenize the question and the context as a pair, with the question first.",hs,te,ln='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/question_tokens.svg" alt="An example of tokenization of question and context"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/question_tokens-dark.svg" alt="An example of tokenization of question and context"/>',us,fe,nn="Models for question answering work a little differently from the models we’ve seen up to now. Using the picture above as an example, the model has been trained to predict the index of the token starting the answer (here 21) and the index of the token where the answer ends (here 24). This is why those models don’t return one tensor of logits but two: one for the logits corresponding to the start token of the answer, and one for the logits corresponding to the end token of the answer. Since in this case we have only one input containing 66 tokens, we get:",ds,Ue,ws,W,R,Xt,je,an="To convert those logits into probabilities, we will apply a softmax function — but before that, we need to make sure we mask the indices that are not part of the context. Our input is <code>[CLS] question [SEP] context [SEP]</code>, so we need to mask the tokens of the question as well as the <code>[SEP]</code> token. We’ll keep the <code>[CLS]</code> token, however, as some models use it to indicate that the answer is not in the context.",ys,Ie,rn="Since we will apply a softmax afterward, we just need to replace the logits we want to mask with a large negative number. Here, we use <code>-10000</code>:",Js,N,V,zt,ke,on="Now that we have properly masked the logits corresponding to positions we don’t want to predict, we can apply the softmax:",bs,X,z,Ht,ge,mn="At this stage, we could take the argmax of the start and end probabilities — but we might end up with a start index that is greater than the end index, so we need to take a few more precautions. We will compute the probabilities of each possible <code>start_index</code> and <code>end_index</code> where <code>start_index &lt;= end_index</code>, then take the tuple <code>(start_index, end_index)</code> with the highest probability.",Ts,I,xl,Qt,pn="start_index",Gl,Et,cn="end_index",Cl,Ft,Mn="start_index",Wl,Yt,hn="end_index",Rl,fs,ba='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo><mo>×</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\\mathrm{start\\_probabilities}[\\mathrm{start\\_index}] \\times \\mathrm{end\\_probabilities}[\\mathrm{end\\_index}]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">start_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">start_index</span></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:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">end_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">end_index</span></span><span class="mclose">]</span></span></span></span></span>',Us,O,Nl,js,Ta='<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo><mo>×</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\\mathrm{start\\_probabilities}[\\mathrm{start\\_index}] \\times \\mathrm{end\\_probabilities}[\\mathrm{end\\_index}]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">start_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">start_index</span></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:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">end_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">end_index</span></span><span class="mclose">]</span></span></span></span>',Is,St,un="start_index <= end_index",Vl,ks,_e,dn="First let’s compute all the possible products:",gs,ve,_s,H,Q,At,Be,wn="Now we just have to get the index of the maximum. Since PyTorch will return the index in the flattened tensor, we need to use the floor division <code>//</code> and modulus <code>%</code> operations to get the <code>start_index</code> and <code>end_index</code>:",vs,Ze,Bs,$e,yn="We’re not quite done yet, but at least we already have the correct score for the answer (you can check this by comparing it to the first result in the previous section):",Zs,xe,$s,se,xs,Ge,Jn="We have the <code>start_index</code> and <code>end_index</code> of the answer in terms of tokens, so now we just need to convert to the character indices in the context. This is where the offsets will be super useful. We can grab them and use them like we did in the token classification task:",Gs,Ce,Cs,We,bn="Now we just have to format everything to get our result:",Ws,Re,Rs,Ne,Ns,Ve,Tn="Great! That’s the same as in our first example!",Vs,le,Xs,Xe,zs,ze,fn="If we try to tokenize the question and long context we used as an example previously, we’ll get a number of tokens higher than the maximum length used in the <code>question-answering</code> pipeline (which is 384):",Hs,He,Qs,Qe,Es,Ee,Un="So, we’ll need to truncate our inputs at that maximum length. There are several ways we can do this, but we don’t want to truncate the question, only the context. Since the context is the second sentence, we’ll use the <code>&quot;only_second&quot;</code> truncation strategy. The problem that arises then is that the answer to the question may not be in the truncated context. Here, for instance, we picked a question where the answer is toward the end of the context, and when we truncate it that answer is not present:",Fs,Fe,Ys,Ye,Ss,Se,jn="This means the model will have a hard time picking the correct answer. To fix this, the <code>question-answering</code> pipeline allows us to split the context into smaller chunks, specifying the maximum length. To make sure we don’t split the context at exactly the wrong place to make it possible to find the answer, it also includes some overlap between the chunks.",As,Ae,In="We can have the tokenizer (fast or slow) do this for us by adding <code>return_overflowing_tokens=True</code>, and we can specify the overlap we want with the <code>stride</code> argument. Here is an example, using a smaller sentence:",qs,qe,Ls,Le,Ds,De,kn="As we can see, the sentence has been split into chunks in such a way that each entry in <code>inputs[&quot;input_ids&quot;]</code> has at most 6 tokens (we would need to add padding to have the last entry be the same size as the others) and there is an overlap of 2 tokens between each of the entries.",Ps,Pe,gn="Let’s take a closer look at the result of the tokenization:",Ks,Ke,Os,Oe,el,et,_n="As expected, we get input IDs and an attention mask. The last key, <code>overflow_to_sample_mapping</code>, is a map that tells us which sentence each of the results corresponds to — here we have 7 results that all come from the (only) sentence we passed the tokenizer:",tl,tt,sl,st,ll,lt,vn="This is more useful when we tokenize several sentences together. For instance, this:",nl,nt,al,at,Bn="gets us:",il,it,rl,rt,Zn="which means the first sentence is split into 7 chunks as before, and the next 4 chunks come from the second sentence.",ol,ot,$n="Now let’s go back to our long context. By default the <code>question-answering</code> pipeline uses a maximum length of 384, as we mentioned earlier, and a stride of 128, which correspond to the way the model was fine-tuned (you can adjust those parameters by passing <code>max_seq_len</code> and <code>stride</code> arguments when calling the pipeline). We will thus use those parameters when tokenizing. We’ll also add padding (to have samples of the same length, so we can build tensors) as well as ask for the offsets:",ml,mt,pl,pt,xn="Those <code>inputs</code> will contain the input IDs and attention masks the model expects, as well as the offsets and the <code>overflow_to_sample_mapping</code> we just talked about. Since those two are not parameters used by the model, we’ll pop them out of the <code>inputs</code> (and we won’t store the map, since it’s not useful here) before converting it to a tensor:",cl,E,F,qt,ct,Gn="Our long context was split in two, which means that after it goes through our model, we will have two sets of start and end logits:",Ml,Mt,hl,Y,S,Lt,ht,Cn="Like before, we first mask the tokens that are not part of the context before taking the softmax. We also mask all the padding tokens (as flagged by the attention mask):",ul,A,q,Dt,ut,Wn="Then we can use the softmax to convert our logits to probabilities:",dl,L,D,Pt,dt,Rn="The next step is similar to what we did for the small context, but we repeat it for each of our two chunks. We attribute a score to all possible spans of answer, then take the span with the best score:",wl,P,K,Kt,wt,yl,yt,Nn="Those two candidates correspond to the best answers the model was able to find in each chunk. The model is way more confident the right answer is in the second part (which is a good sign!). Now we just have to map those two token spans to spans of characters in the context (we only need to map the second one to have our answer, but it’s interesting to see what the model has picked in the first chunk).",Jl,ne,bl,Jt,Vn="The <code>offsets</code> we grabbed earlier is actually a list of offsets, with one list per chunk of text:",Tl,bt,fl,Tt,Ul,ft,Xn="If we ignore the first result, we get the same result as our pipeline for this long context — yay!",jl,ae,Il,Ut,zn="This concludes our deep dive into the tokenizer’s capabilities. We will put all of this in practice again in the next chapter, when we show you how to fine-tune a model on a range of common NLP tasks.",kl,jt,gl,Ot,_l;y=new va({props:{fw:w[0]}}),j=new ga({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),oe=new Zl({props:{title:"Fast tokenizers in the QA pipeline",local:"fast-tokenizers-in-the-qa-pipeline",headingTag:"h1"}});const Hn=[Za,Ba],It=[];function Qn(e,l){return e[0]==="pt"?0:1}B=Qn(w),Z=It[B]=Hn[B](w);const En=[xa,$a],kt=[];function Fn(e,l){return e[0]==="pt"?0:1}$=Fn(w),x=kt[$]=En[$](w),pe=new Zl({props:{title:"Using the question-answering pipeline",local:"using-the-question-answering-pipeline",headingTag:"h2"}}),Me=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcXVlc3Rpb25fYW5zd2VyZXIlMjAlM0QlMjBwaXBlbGluZSglMjJxdWVzdGlvbi1hbnN3ZXJpbmclMjIpJTBBY29udGV4dCUyMCUzRCUyMCUyMiUyMiUyMiUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMGlzJTIwYmFja2VkJTIwYnklMjB0aGUlMjB0aHJlZSUyMG1vc3QlMjBwb3B1bGFyJTIwZGVlcCUyMGxlYXJuaW5nJTIwbGlicmFyaWVzJTIwJUUyJTgwJTk0JTIwSmF4JTJDJTIwUHlUb3JjaCUyQyUyMGFuZCUyMFRlbnNvckZsb3clMjAlRTIlODAlOTQlMjB3aXRoJTIwYSUyMHNlYW1sZXNzJTIwaW50ZWdyYXRpb24lMEFiZXR3ZWVuJTIwdGhlbS4lMjBJdCdzJTIwc3RyYWlnaHRmb3J3YXJkJTIwdG8lMjB0cmFpbiUyMHlvdXIlMjBtb2RlbHMlMjB3aXRoJTIwb25lJTIwYmVmb3JlJTIwbG9hZGluZyUyMHRoZW0lMjBmb3IlMjBpbmZlcmVuY2UlMjB3aXRoJTIwdGhlJTIwb3RoZXIuJTBBJTIyJTIyJTIyJTBBcXVlc3Rpb24lMjAlM0QlMjAlMjJXaGljaCUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMGJhY2slMjAlRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlM0YlMjIlMEFxdWVzdGlvbl9hbnN3ZXJlcihxdWVzdGlvbiUzRHF1ZXN0aW9uJTJDJTIwY29udGV4dCUzRGNvbnRleHQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

question_answerer = pipeline(<span class="hljs-string">&quot;question-answering&quot;</span>)
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}}),he=new T({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTc3NzMlMkMlMEElMjAnc3RhcnQnJTNBJTIwNzglMkMlMEElMjAnZW5kJyUzQSUyMDEwNSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</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}}),de=new T({props:{code:"bG9uZ19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GVybmFscyUyMGFyZSUyMGV4cG9zZWQlMjBhcyUyMGNvbnNpc3RlbnRseSUyMGFzJTIwcG9zc2libGUuJTBBJTIwJTIwLSUyME1vZGVsJTIwZmlsZXMlMjBjYW4lMjBiZSUyMHVzZWQlMjBpbmRlcGVuZGVudGx5JTIwb2YlMjB0aGUlMjBsaWJyYXJ5JTIwZm9yJTIwcXVpY2slMjBleHBlcmltZW50cy4lMEElMEElRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlMjBpcyUyMGJhY2tlZCUyMGJ5JTIwdGhlJTIwdGhyZWUlMjBtb3N0JTIwcG9wdWxhciUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMCVFMiU4MCU5NCUyMEpheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",highlighted:`long_context = <span class="hljs-string">&quot;&quot;&quot;
🤗 Transformers: State of the Art NLP

🤗 Transformers provides thousands of pretrained models to perform tasks on texts such as classification, information extraction,
question answering, summarization, translation, text generation and more in over 100 languages.
Its aim is to make cutting-edge NLP easier to use for everyone.

🤗 Transformers provides APIs to quickly download and use those pretrained models on a given text, fine-tune them on your own datasets and
then share them with the community on our model hub. At the same time, each python module defining an architecture is fully standalone and
can be modified to enable quick research experiments.

Why should I use transformers?

1. Easy-to-use state-of-the-art models:
  - High performance on NLU and NLG tasks.
  - Low barrier to entry for educators and practitioners.
  - Few user-facing abstractions with just three classes to learn.
  - A unified API for using all our pretrained models.
  - Lower compute costs, smaller carbon footprint:

2. Researchers can share trained models instead of always retraining.
  - Practitioners can reduce compute time and production costs.
  - Dozens of architectures with over 10,000 pretrained models, some in more than 100 languages.

3. Choose the right framework for every part of a model&#x27;s lifetime:
  - Train state-of-the-art models in 3 lines of code.
  - Move a single model between TF2.0/PyTorch frameworks at will.
  - Seamlessly pick the right framework for training, evaluation and production.

4. Easily customize a model or an example to your needs:
  - We provide examples for each architecture to reproduce the results published by its original authors.
  - Model internals are exposed as consistently as possible.
  - Model files can be used independently of the library for quick experiments.

🤗 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_answerer(question=question, context=long_context)`,wrap:!1}}),we=new T({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTcxNDklMkMlMEElMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUwQSUyMCdlbmQnJTNBJTIwMTkxOSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),Je=new Zl({props:{title:"Using a model for question answering",local:"using-a-model-for-question-answering",headingTag:"h2"}});const Yn=[Ca,Ga],gt=[];function Sn(e,l){return e[0]==="pt"?0:1}G=Sn(w),C=gt[G]=Yn[G](w),Ue=new T({props:{code:"c3RhcnRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMlMEFlbmRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5lbmRfbG9naXRzJTBBcHJpbnQoc3RhcnRfbG9naXRzLnNoYXBlJTJDJTIwZW5kX2xvZ2l0cy5zaGFwZSk=",highlighted:`start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const An=[Ra,Wa],_t=[];function qn(e,l){return e[0]==="pt"?0:1}W=qn(w),R=_t[W]=An[W](w);const Ln=[Va,Na],vt=[];function Dn(e,l){return e[0]==="pt"?0:1}N=Dn(w),V=vt[N]=Ln[N](w);const Pn=[za,Xa],Bt=[];function Kn(e,l){return e[0]==="pt"?0:1}X=Kn(w),z=Bt[X]=Pn[X](w),ve=new T({props:{code:"c2NvcmVzJTIwJTNEJTIwc3RhcnRfcHJvYmFiaWxpdGllcyU1QiUzQSUyQyUyME5vbmUlNUQlMjAqJTIwZW5kX3Byb2JhYmlsaXRpZXMlNUJOb25lJTJDJTIwJTNBJTVE",highlighted:'scores = start_probabilities[:, <span class="hljs-literal">None</span>] * end_probabilities[<span class="hljs-literal">None</span>, :]',wrap:!1}});const On=[Qa,Ha],Zt=[];function ea(e,l){return e[0]==="pt"?0:1}H=ea(w),Q=Zt[H]=On[H](w),Ze=new T({props:{code:"bWF4X2luZGV4JTIwJTNEJTIwc2NvcmVzLmFyZ21heCgpLml0ZW0oKSUwQXN0YXJ0X2luZGV4JTIwJTNEJTIwbWF4X2luZGV4JTIwJTJGJTJGJTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQWVuZF9pbmRleCUyMCUzRCUyMG1heF9pbmRleCUyMCUyNSUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEFwcmludChzY29yZXMlNUJzdGFydF9pbmRleCUyQyUyMGVuZF9pbmRleCU1RCk=",highlighted:`max_index = scores.argmax().item()
start_index = max_index // scores.shape[<span class="hljs-number">1</span>]
end_index = max_index % scores.shape[<span class="hljs-number">1</span>]
<span class="hljs-built_in">print</span>(scores[start_index, end_index])`,wrap:!1}}),xe=new T({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),se=new Bl({props:{$$slots:{default:[Ea]},$$scope:{ctx:w}}}),Ce=new T({props:{code:"aW5wdXRzX3dpdGhfb2Zmc2V0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSklMEFvZmZzZXRzJTIwJTNEJTIwaW5wdXRzX3dpdGhfb2Zmc2V0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTBBJTBBc3RhcnRfY2hhciUyQyUyMF8lMjAlM0QlMjBvZmZzZXRzJTVCc3RhcnRfaW5kZXglNUQlMEFfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXRzJTVCZW5kX2luZGV4JTVEJTBBYW5zd2VyJTIwJTNEJTIwY29udGV4dCU1QnN0YXJ0X2NoYXIlM0FlbmRfY2hhciU1RA==",highlighted:`inputs_with_offsets = tokenizer(question, context, return_offsets_mapping=<span class="hljs-literal">True</span>)
offsets = inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]

start_char, _ = offsets[start_index]
_, end_char = offsets[end_index]
answer = context[start_char:end_char]`,wrap:!1}}),Re=new T({props:{code:"cmVzdWx0JTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIyYW5zd2VyJTIyJTNBJTIwYW5zd2VyJTJDJTBBJTIwJTIwJTIwJTIwJTIyc3RhcnQlMjIlM0ElMjBzdGFydF9jaGFyJTJDJTBBJTIwJTIwJTIwJTIwJTIyZW5kJTIyJTNBJTIwZW5kX2NoYXIlMkMlMEElMjAlMjAlMjAlMjAlMjJzY29yZSUyMiUzQSUyMHNjb3JlcyU1QnN0YXJ0X2luZGV4JTJDJTIwZW5kX2luZGV4JTVEJTJDJTBBJTdEJTBBcHJpbnQocmVzdWx0KQ==",highlighted:`result = {
    <span class="hljs-string">&quot;answer&quot;</span>: answer,
    <span class="hljs-string">&quot;start&quot;</span>: start_char,
    <span class="hljs-string">&quot;end&quot;</span>: end_char,
    <span class="hljs-string">&quot;score&quot;</span>: scores[start_index, end_index],
}
<span class="hljs-built_in">print</span>(result)`,wrap:!1}}),Ne=new T({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnSmF4JTJDJTIwUHlUb3JjaCUyMGFuZCUyMFRlbnNvckZsb3cnJTJDJTBBJTIwJ3N0YXJ0JyUzQSUyMDc4JTJDJTBBJTIwJ2VuZCclM0ElMjAxMDUlMkMlMEElMjAnc2NvcmUnJTNBJTIwMC45Nzc3MyU3RA==",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</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;score&#x27;</span>: <span class="hljs-number">0.97773</span>}`,wrap:!1}}),le=new Bl({props:{$$slots:{default:[Fa]},$$scope:{ctx:w}}}),Xe=new Zl({props:{title:"Handling long contexts",local:"handling-long-contexts",headingTag:"h2"}}),He=new T({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0KSUwQXByaW50KGxlbihpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKQ==",highlighted:`inputs = tokenizer(question, long_context)
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">len</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Qe=new T({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Fe=new T({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0JTJDJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUyMHRydW5jYXRpb24lM0QlMjJvbmx5X3NlY29uZCUyMiklMEFwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCkp",highlighted:`inputs = tokenizer(question, long_context, max_length=<span class="hljs-number">384</span>, truncation=<span class="hljs-string">&quot;only_second&quot;</span>)
<span class="hljs-built_in">print</span>(tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Ye=new T({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU1RCUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4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eVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",highlighted:`<span class="hljs-string">&quot;&quot;&quot;
[CLS] Which deep learning libraries back [UNK] Transformers? [SEP] [UNK] Transformers : State of the Art NLP

[UNK] Transformers provides thousands of pretrained models to perform tasks on texts such as classification, information extraction,
question answering, summarization, translation, text generation and more in over 100 languages.
Its aim is to make cutting-edge NLP easier to use for everyone.

[UNK] Transformers provides APIs to quickly download and use those pretrained models on a given text, fine-tune them on your own datasets and
then share them with the community on our model hub. At the same time, each python module defining an architecture is fully standalone and
can be modified to enable quick research experiments.

Why should I use transformers?

1. Easy-to-use state-of-the-art models:
  - High performance on NLU and NLG tasks.
  - Low barrier to entry for educators and practitioners.
  - Few user-facing abstractions with just three classes to learn.
  - A unified API for using all our pretrained models.
  - Lower compute costs, smaller carbon footprint:

2. Researchers can share trained models instead of always retraining.
  - Practitioners can reduce compute time and production costs.
  - Dozens of architectures with over 10,000 pretrained models, some in more than 100 languages.

3. Choose the right framework for every part of a model&#x27;s lifetime:
  - Train state-of-the-art models in 3 lines of code.
  - Move a single model between TF2.0/PyTorch frameworks at will.
  - Seamlessly pick the right framework for training, evaluation and production.

4. Easily customize a model or an example to your needs:
  - We provide examples for each architecture to reproduce the results published by its original authors.
  - Model internal [SEP]
&quot;&quot;&quot;</span>`,wrap:!1}}),qe=new T({props:{code:"c2VudGVuY2UlMjAlM0QlMjAlMjJUaGlzJTIwc2VudGVuY2UlMjBpcyUyMG5vdCUyMHRvbyUyMGxvbmclMjBidXQlMjB3ZSUyMGFyZSUyMGdvaW5nJTIwdG8lMjBzcGxpdCUyMGl0JTIwYW55d2F5LiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjBzZW50ZW5jZSUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTJDJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMjBtYXhfbGVuZ3RoJTNENiUyQyUyMHN0cmlkZSUzRDIlMEEpJTBBJTBBZm9yJTIwaWRzJTIwaW4lMjBpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlM0ElMEElMjAlMjAlMjAlMjBwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlkcykp",highlighted:`sentence = <span class="hljs-string">&quot;This sentence is not too long but we are going to split it anyway.&quot;</span>
inputs = tokenizer(
    sentence, truncation=<span class="hljs-literal">True</span>, return_overflowing_tokens=<span class="hljs-literal">True</span>, max_length=<span class="hljs-number">6</span>, stride=<span class="hljs-number">2</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-built_in">print</span>(tokenizer.decode(ids))`,wrap:!1}}),Le=new T({props:{code:"JyU1QkNMUyU1RCUyMFRoaXMlMjBzZW50ZW5jZSUyMGlzJTIwbm90JTIwJTVCU0VQJTVEJyUwQSclNUJDTFMlNUQlMjBpcyUyMG5vdCUyMHRvbyUyMGxvbmclMjAlNUJTRVAlNUQnJTBBJyU1QkNMUyU1RCUyMHRvbyUyMGxvbmclMjBidXQlMjB3ZSUyMCU1QlNFUCU1RCclMEEnJTVCQ0xTJTVEJTIwYnV0JTIwd2UlMjBhcmUlMjBnb2luZyUyMCU1QlNFUCU1RCclMEEnJTVCQ0xTJTVEJTIwYXJlJTIwZ29pbmclMjB0byUyMHNwbGl0JTIwJTVCU0VQJTVEJyUwQSclNUJDTFMlNUQlMjB0byUyMHNwbGl0JTIwaXQlMjBhbnl3YXklMjAlNUJTRVAlNUQnJTBBJyU1QkNMUyU1RCUyMGl0JTIwYW55d2F5LiUyMCU1QlNFUCU1RCc=",highlighted:`<span class="hljs-string">&#x27;[CLS] This sentence is not [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] is not too long [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] too long but we [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] but we are going [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] are going to split [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] to split it anyway [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] it anyway. [SEP]&#x27;</span>`,wrap:!1}}),Ke=new T({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Oe=new T({props:{code:"ZGljdF9rZXlzKCU1QidpbnB1dF9pZHMnJTJDJTIwJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyclNUQp",highlighted:'dict_keys([<span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;overflow_to_sample_mapping&#x27;</span>])',wrap:!1}}),tt=new T({props:{code:"cHJpbnQoaW5wdXRzJTVCJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIlNUQp",highlighted:'<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>])',wrap:!1}}),st=new T({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RA==",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>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]',wrap:!1}}),nt=new T({props:{code:"c2VudGVuY2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIyVGhpcyUyMHNlbnRlbmNlJTIwaXMlMjBub3QlMjB0b28lMjBsb25nJTIwYnV0JTIwd2UlMjBhcmUlMjBnb2luZyUyMHRvJTIwc3BsaXQlMjBpdCUyMGFueXdheS4lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJUaGlzJTIwc2VudGVuY2UlMjBpcyUyMHNob3J0ZXIlMjBidXQlMjB3aWxsJTIwc3RpbGwlMjBnZXQlMjBzcGxpdC4lMjIlMkMlMEElNUQlMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwc2VudGVuY2VzJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUlMkMlMjByZXR1cm5fb3ZlcmZsb3dpbmdfdG9rZW5zJTNEVHJ1ZSUyQyUyMG1heF9sZW5ndGglM0Q2JTJDJTIwc3RyaWRlJTNEMiUwQSklMEElMEFwcmludChpbnB1dHMlNUIlMjJvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyUyMiU1RCk=",highlighted:`sentences = [
    <span class="hljs-string">&quot;This sentence is not too long but we are going to split it anyway.&quot;</span>,
    <span class="hljs-string">&quot;This sentence is shorter but will still get split.&quot;</span>,
]
inputs = tokenizer(
    sentences, truncation=<span class="hljs-literal">True</span>, return_overflowing_tokens=<span class="hljs-literal">True</span>, max_length=<span class="hljs-number">6</span>, stride=<span class="hljs-number">2</span>
)

<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>])`,wrap:!1}}),it=new T({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElNUQ=",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>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]',wrap:!1}}),mt=new T({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHF1ZXN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwbG9uZ19jb250ZXh0JTJDJTBBJTIwJTIwJTIwJTIwc3RyaWRlJTNEMTI4JTJDJTBBJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUwQSUyMCUyMCUyMCUyMHBhZGRpbmclM0QlMjJsb25nZXN0JTIyJTJDJTBBJTIwJTIwJTIwJTIwdHJ1bmNhdGlvbiUzRCUyMm9ubHlfc2Vjb25kJTIyJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`inputs = tokenizer(
    question,
    long_context,
    stride=<span class="hljs-number">128</span>,
    max_length=<span class="hljs-number">384</span>,
    padding=<span class="hljs-string">&quot;longest&quot;</span>,
    truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
    return_overflowing_tokens=<span class="hljs-literal">True</span>,
    return_offsets_mapping=<span class="hljs-literal">True</span>,
)`,wrap:!1}});const ta=[Sa,Ya],$t=[];function sa(e,l){return e[0]==="pt"?0:1}E=sa(w),F=$t[E]=ta[E](w),Mt=new T({props:{code:"b3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQXN0YXJ0X2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuc3RhcnRfbG9naXRzJTBBZW5kX2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuZW5kX2xvZ2l0cyUwQXByaW50KHN0YXJ0X2xvZ2l0cy5zaGFwZSUyQyUyMGVuZF9sb2dpdHMuc2hhcGUp",highlighted:`outputs = model(**inputs)

start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const la=[qa,Aa],xt=[];function na(e,l){return e[0]==="pt"?0:1}Y=na(w),S=xt[Y]=la[Y](w);const aa=[Da,La],Gt=[];function ia(e,l){return e[0]==="pt"?0:1}A=ia(w),q=Gt[A]=aa[A](w);const ra=[Ka,Pa],Ct=[];function oa(e,l){return e[0]==="pt"?0:1}L=oa(w),D=Ct[L]=ra[L](w);const ma=[ei,Oa],Wt=[];function pa(e,l){return e[0]==="pt"?0:1}return P=pa(w),K=Wt[P]=ma[P](w),wt=new T({props:{code:"JTVCKDAlMkMlMjAxOCUyQyUyMDAuMzM4NjcpJTJDJTIwKDE3MyUyQyUyMDE4NCUyQyUyMDAuOTcxNDkpJTVE",highlighted:'[(<span class="hljs-number">0</span>, <span class="hljs-number">18</span>, <span class="hljs-number">0.33867</span>), (<span class="hljs-number">173</span>, <span class="hljs-number">184</span>, <span class="hljs-number">0.97149</span>)]',wrap:!1}}),ne=new Bl({props:{$$slots:{default:[ti]},$$scope:{ctx:w}}}),bt=new T({props:{code:"Zm9yJTIwY2FuZGlkYXRlJTJDJTIwb2Zmc2V0JTIwaW4lMjB6aXAoY2FuZGlkYXRlcyUyQyUyMG9mZnNldHMpJTNBJTBBJTIwJTIwJTIwJTIwc3RhcnRfdG9rZW4lMkMlMjBlbmRfdG9rZW4lMkMlMjBzY29yZSUyMCUzRCUyMGNhbmRpZGF0ZSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2NoYXIlMkMlMjBfJTIwJTNEJTIwb2Zmc2V0JTVCc3RhcnRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXQlNUJlbmRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBhbnN3ZXIlMjAlM0QlMjBsb25nX2NvbnRleHQlNUJzdGFydF9jaGFyJTNBZW5kX2NoYXIlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjAlN0IlMjJhbnN3ZXIlMjIlM0ElMjBhbnN3ZXIlMkMlMjAlMjJzdGFydCUyMiUzQSUyMHN0YXJ0X2NoYXIlMkMlMjAlMjJlbmQlMjIlM0ElMjBlbmRfY2hhciUyQyUyMCUyMnNjb3JlJTIyJTNBJTIwc2NvcmUlN0QlMEElMjAlMjAlMjAlMjBwcmludChyZXN1bHQp",highlighted:`<span class="hljs-keyword">for</span> candidate, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(candidates, offsets):
    start_token, end_token, score = candidate
    start_char, _ = offset[start_token]
    _, end_char = offset[end_token]
    answer = long_context[start_char:end_char]
    result = {<span class="hljs-string">&quot;answer&quot;</span>: answer, <span class="hljs-string">&quot;start&quot;</span>: start_char, <span class="hljs-string">&quot;end&quot;</span>: end_char, <span class="hljs-string">&quot;score&quot;</span>: score}
    <span class="hljs-built_in">print</span>(result)`,wrap:!1}}),Tt=new T({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnJTVDbiVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUzQSUyMFN0YXRlJTIwb2YlMjB0aGUlMjBBcnQlMjBOTFAnJTJDJTIwJ3N0YXJ0JyUzQSUyMDAlMkMlMjAnZW5kJyUzQSUyMDM3JTJDJTIwJ3Njb3JlJyUzQSUyMDAuMzM4NjclN0QlMEElN0InYW5zd2VyJyUzQSUyMCdKYXglMkMlMjBQeVRvcmNoJTIwYW5kJTIwVGVuc29yRmxvdyclMkMlMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUyMCdlbmQnJTNBJTIwMTkxOSUyQyUyMCdzY29yZSclM0ElMjAwLjk3MTQ5JTdE",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;\\n🤗 Transformers: State of the Art NLP&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">37</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.33867</span>}
{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>}`,wrap:!1}}),ae=new Bl({props:{$$slots:{default:[si]},$$scope:{ctx:w}}}),jt=new _a({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter6/3b.mdx"}}),{c(){s=J("meta"),i=r(),t=J("p"),c=r(),M(y.$$.fragment),U=r(),M(j.$$.fragment),es=r(),M(oe.$$.fragment),ts=r(),Z.c(),Rt=r(),me=J("p"),me.innerHTML=Pl,ss=r(),x.c(),Nt=r(),M(pe.$$.fragment),ls=r(),ce=J("p"),ce.innerHTML=Kl,ns=r(),M(Me.$$.fragment),as=r(),M(he.$$.fragment),is=r(),ue=J("p"),ue.textContent=Ol,rs=r(),M(de.$$.fragment),os=r(),M(we.$$.fragment),ms=r(),ye=J("p"),ye.textContent=en,ps=r(),M(Je.$$.fragment),cs=r(),be=J("p"),be.innerHTML=tn,Ms=r(),C.c(),Vt=r(),Te=J("p"),Te.textContent=sn,hs=r(),te=J("div"),te.innerHTML=ln,us=r(),fe=J("p"),fe.textContent=nn,ds=r(),M(Ue.$$.fragment),ws=r(),R.c(),Xt=r(),je=J("p"),je.innerHTML=an,ys=r(),Ie=J("p"),Ie.innerHTML=rn,Js=r(),V.c(),zt=r(),ke=J("p"),ke.textContent=on,bs=r(),z.c(),Ht=r(),ge=J("p"),ge.innerHTML=mn,Ts=r(),I=J("p"),xl=ie("Assuming the events “The answer starts at "),Qt=J("code"),Qt.textContent=pn,Gl=ie("” and “The answer ends at "),Et=J("code"),Et.textContent=cn,Cl=ie("” to be independent, the probability that the answer starts at "),Ft=J("code"),Ft.textContent=Mn,Wl=ie(" and ends at "),Yt=J("code"),Yt.textContent=hn,Rl=ie(` is:
`),fs=new da(!1),Us=r(),O=J("p"),Nl=ie("So, to compute all the scores, we just need to compute all the products"),js=new da(!1),Is=ie(" where "),St=J("code"),St.textContent=un,Vl=ie("."),ks=r(),_e=J("p"),_e.textContent=dn,gs=r(),M(ve.$$.fragment),_s=r(),Q.c(),At=r(),Be=J("p"),Be.innerHTML=wn,vs=r(),M(Ze.$$.fragment),Bs=r(),$e=J("p"),$e.textContent=yn,Zs=r(),M(xe.$$.fragment),$s=r(),M(se.$$.fragment),xs=r(),Ge=J("p"),Ge.innerHTML=Jn,Gs=r(),M(Ce.$$.fragment),Cs=r(),We=J("p"),We.textContent=bn,Ws=r(),M(Re.$$.fragment),Rs=r(),M(Ne.$$.fragment),Ns=r(),Ve=J("p"),Ve.textContent=Tn,Vs=r(),M(le.$$.fragment),Xs=r(),M(Xe.$$.fragment),zs=r(),ze=J("p"),ze.innerHTML=fn,Hs=r(),M(He.$$.fragment),Qs=r(),M(Qe.$$.fragment),Es=r(),Ee=J("p"),Ee.innerHTML=Un,Fs=r(),M(Fe.$$.fragment),Ys=r(),M(Ye.$$.fragment),Ss=r(),Se=J("p"),Se.innerHTML=jn,As=r(),Ae=J("p"),Ae.innerHTML=In,qs=r(),M(qe.$$.fragment),Ls=r(),M(Le.$$.fragment),Ds=r(),De=J("p"),De.innerHTML=kn,Ps=r(),Pe=J("p"),Pe.textContent=gn,Ks=r(),M(Ke.$$.fragment),Os=r(),M(Oe.$$.fragment),el=r(),et=J("p"),et.innerHTML=_n,tl=r(),M(tt.$$.fragment),sl=r(),M(st.$$.fragment),ll=r(),lt=J("p"),lt.textContent=vn,nl=r(),M(nt.$$.fragment),al=r(),at=J("p"),at.textContent=Bn,il=r(),M(it.$$.fragment),rl=r(),rt=J("p"),rt.textContent=Zn,ol=r(),ot=J("p"),ot.innerHTML=$n,ml=r(),M(mt.$$.fragment),pl=r(),pt=J("p"),pt.innerHTML=xn,cl=r(),F.c(),qt=r(),ct=J("p"),ct.textContent=Gn,Ml=r(),M(Mt.$$.fragment),hl=r(),S.c(),Lt=r(),ht=J("p"),ht.textContent=Cn,ul=r(),q.c(),Dt=r(),ut=J("p"),ut.textContent=Wn,dl=r(),D.c(),Pt=r(),dt=J("p"),dt.textContent=Rn,wl=r(),K.c(),Kt=r(),M(wt.$$.fragment),yl=r(),yt=J("p"),yt.textContent=Nn,Jl=r(),M(ne.$$.fragment),bl=r(),Jt=J("p"),Jt.innerHTML=Vn,Tl=r(),M(bt.$$.fragment),fl=r(),M(Tt.$$.fragment),Ul=r(),ft=J("p"),ft.textContent=Xn,jl=r(),M(ae.$$.fragment),Il=r(),Ut=J("p"),Ut.textContent=zn,kl=r(),M(jt.$$.fragment),gl=r(),Ot=J("p"),this.h()},l(e){const l=ka("svelte-u9bgzb",document.head);s=b(l,"META",{name:!0,content:!0}),l.forEach(n),i=o(e),t=b(e,"P",{}),vl(t).forEach(n),c=o(e),h(y.$$.fragment,e),U=o(e),h(j.$$.fragment,e),es=o(e),h(oe.$$.fragment,e),ts=o(e),Z.l(e),Rt=o(e),me=b(e,"P",{"data-svelte-h":!0}),f(me)!=="svelte-lvoxg9"&&(me.innerHTML=Pl),ss=o(e),x.l(e),Nt=o(e),h(pe.$$.fragment,e),ls=o(e),ce=b(e,"P",{"data-svelte-h":!0}),f(ce)!=="svelte-1rzsno5"&&(ce.innerHTML=Kl),ns=o(e),h(Me.$$.fragment,e),as=o(e),h(he.$$.fragment,e),is=o(e),ue=b(e,"P",{"data-svelte-h":!0}),f(ue)!=="svelte-1pagerf"&&(ue.textContent=Ol),rs=o(e),h(de.$$.fragment,e),os=o(e),h(we.$$.fragment,e),ms=o(e),ye=b(e,"P",{"data-svelte-h":!0}),f(ye)!=="svelte-sapdef"&&(ye.textContent=en),ps=o(e),h(Je.$$.fragment,e),cs=o(e),be=b(e,"P",{"data-svelte-h":!0}),f(be)!=="svelte-w4r3vw"&&(be.innerHTML=tn),Ms=o(e),C.l(e),Vt=o(e),Te=b(e,"P",{"data-svelte-h":!0}),f(Te)!=="svelte-1f1yf5i"&&(Te.textContent=sn),hs=o(e),te=b(e,"DIV",{class:!0,"data-svelte-h":!0}),f(te)!=="svelte-47wedv"&&(te.innerHTML=ln),us=o(e),fe=b(e,"P",{"data-svelte-h":!0}),f(fe)!=="svelte-lbyhwl"&&(fe.textContent=nn),ds=o(e),h(Ue.$$.fragment,e),ws=o(e),R.l(e),Xt=o(e),je=b(e,"P",{"data-svelte-h":!0}),f(je)!=="svelte-bkvch0"&&(je.innerHTML=an),ys=o(e),Ie=b(e,"P",{"data-svelte-h":!0}),f(Ie)!=="svelte-6ptczc"&&(Ie.innerHTML=rn),Js=o(e),V.l(e),zt=o(e),ke=b(e,"P",{"data-svelte-h":!0}),f(ke)!=="svelte-1j5ys7d"&&(ke.textContent=on),bs=o(e),z.l(e),Ht=o(e),ge=b(e,"P",{"data-svelte-h":!0}),f(ge)!=="svelte-1qmjo9o"&&(ge.innerHTML=mn),Ts=o(e),I=b(e,"P",{});var k=vl(I);xl=re(k,"Assuming the events “The answer starts at "),Qt=b(k,"CODE",{"data-svelte-h":!0}),f(Qt)!=="svelte-8eqb3b"&&(Qt.textContent=pn),Gl=re(k,"” and “The answer ends at "),Et=b(k,"CODE",{"data-svelte-h":!0}),f(Et)!=="svelte-9cistc"&&(Et.textContent=cn),Cl=re(k,"” to be independent, the probability that the answer starts at "),Ft=b(k,"CODE",{"data-svelte-h":!0}),f(Ft)!=="svelte-8eqb3b"&&(Ft.textContent=Mn),Wl=re(k," and ends at "),Yt=b(k,"CODE",{"data-svelte-h":!0}),f(Yt)!=="svelte-9cistc"&&(Yt.textContent=hn),Rl=re(k,` is:
`),fs=wa(k,!1),k.forEach(n),Us=o(e),O=b(e,"P",{});var ee=vl(O);Nl=re(ee,"So, to compute all the scores, we just need to compute all the products"),js=wa(ee,!1),Is=re(ee," where "),St=b(ee,"CODE",{"data-svelte-h":!0}),f(St)!=="svelte-1kp3szf"&&(St.textContent=un),Vl=re(ee,"."),ee.forEach(n),ks=o(e),_e=b(e,"P",{"data-svelte-h":!0}),f(_e)!=="svelte-193wrn1"&&(_e.textContent=dn),gs=o(e),h(ve.$$.fragment,e),_s=o(e),Q.l(e),At=o(e),Be=b(e,"P",{"data-svelte-h":!0}),f(Be)!=="svelte-1mc8mc3"&&(Be.innerHTML=wn),vs=o(e),h(Ze.$$.fragment,e),Bs=o(e),$e=b(e,"P",{"data-svelte-h":!0}),f($e)!=="svelte-mq04r0"&&($e.textContent=yn),Zs=o(e),h(xe.$$.fragment,e),$s=o(e),h(se.$$.fragment,e),xs=o(e),Ge=b(e,"P",{"data-svelte-h":!0}),f(Ge)!=="svelte-1vbvikx"&&(Ge.innerHTML=Jn),Gs=o(e),h(Ce.$$.fragment,e),Cs=o(e),We=b(e,"P",{"data-svelte-h":!0}),f(We)!=="svelte-o78gqr"&&(We.textContent=bn),Ws=o(e),h(Re.$$.fragment,e),Rs=o(e),h(Ne.$$.fragment,e),Ns=o(e),Ve=b(e,"P",{"data-svelte-h":!0}),f(Ve)!=="svelte-erpa1c"&&(Ve.textContent=Tn),Vs=o(e),h(le.$$.fragment,e),Xs=o(e),h(Xe.$$.fragment,e),zs=o(e),ze=b(e,"P",{"data-svelte-h":!0}),f(ze)!=="svelte-1ny8u7i"&&(ze.innerHTML=fn),Hs=o(e),h(He.$$.fragment,e),Qs=o(e),h(Qe.$$.fragment,e),Es=o(e),Ee=b(e,"P",{"data-svelte-h":!0}),f(Ee)!=="svelte-1vshog5"&&(Ee.innerHTML=Un),Fs=o(e),h(Fe.$$.fragment,e),Ys=o(e),h(Ye.$$.fragment,e),Ss=o(e),Se=b(e,"P",{"data-svelte-h":!0}),f(Se)!=="svelte-cfs4jm"&&(Se.innerHTML=jn),As=o(e),Ae=b(e,"P",{"data-svelte-h":!0}),f(Ae)!=="svelte-1nms3xo"&&(Ae.innerHTML=In),qs=o(e),h(qe.$$.fragment,e),Ls=o(e),h(Le.$$.fragment,e),Ds=o(e),De=b(e,"P",{"data-svelte-h":!0}),f(De)!=="svelte-1qc9ozy"&&(De.innerHTML=kn),Ps=o(e),Pe=b(e,"P",{"data-svelte-h":!0}),f(Pe)!=="svelte-1f82rb6"&&(Pe.textContent=gn),Ks=o(e),h(Ke.$$.fragment,e),Os=o(e),h(Oe.$$.fragment,e),el=o(e),et=b(e,"P",{"data-svelte-h":!0}),f(et)!=="svelte-k27ihj"&&(et.innerHTML=_n),tl=o(e),h(tt.$$.fragment,e),sl=o(e),h(st.$$.fragment,e),ll=o(e),lt=b(e,"P",{"data-svelte-h":!0}),f(lt)!=="svelte-w7y7n8"&&(lt.textContent=vn),nl=o(e),h(nt.$$.fragment,e),al=o(e),at=b(e,"P",{"data-svelte-h":!0}),f(at)!=="svelte-b6k3qh"&&(at.textContent=Bn),il=o(e),h(it.$$.fragment,e),rl=o(e),rt=b(e,"P",{"data-svelte-h":!0}),f(rt)!=="svelte-dqom4c"&&(rt.textContent=Zn),ol=o(e),ot=b(e,"P",{"data-svelte-h":!0}),f(ot)!=="svelte-vpesag"&&(ot.innerHTML=$n),ml=o(e),h(mt.$$.fragment,e),pl=o(e),pt=b(e,"P",{"data-svelte-h":!0}),f(pt)!=="svelte-8qj5sv"&&(pt.innerHTML=xn),cl=o(e),F.l(e),qt=o(e),ct=b(e,"P",{"data-svelte-h":!0}),f(ct)!=="svelte-1rmefba"&&(ct.textContent=Gn),Ml=o(e),h(Mt.$$.fragment,e),hl=o(e),S.l(e),Lt=o(e),ht=b(e,"P",{"data-svelte-h":!0}),f(ht)!=="svelte-12rpmqq"&&(ht.textContent=Cn),ul=o(e),q.l(e),Dt=o(e),ut=b(e,"P",{"data-svelte-h":!0}),f(ut)!=="svelte-xc3z5h"&&(ut.textContent=Wn),dl=o(e),D.l(e),Pt=o(e),dt=b(e,"P",{"data-svelte-h":!0}),f(dt)!=="svelte-t87wk3"&&(dt.textContent=Rn),wl=o(e),K.l(e),Kt=o(e),h(wt.$$.fragment,e),yl=o(e),yt=b(e,"P",{"data-svelte-h":!0}),f(yt)!=="svelte-s4nw2c"&&(yt.textContent=Nn),Jl=o(e),h(ne.$$.fragment,e),bl=o(e),Jt=b(e,"P",{"data-svelte-h":!0}),f(Jt)!=="svelte-1ocnhs0"&&(Jt.innerHTML=Vn),Tl=o(e),h(bt.$$.fragment,e),fl=o(e),h(Tt.$$.fragment,e),Ul=o(e),ft=b(e,"P",{"data-svelte-h":!0}),f(ft)!=="svelte-k6zbjj"&&(ft.textContent=Xn),jl=o(e),h(ae.$$.fragment,e),Il=o(e),Ut=b(e,"P",{"data-svelte-h":!0}),f(Ut)!=="svelte-1p6apew"&&(Ut.textContent=zn),kl=o(e),h(jt.$$.fragment,e),gl=o(e),Ot=b(e,"P",{}),vl(Ot).forEach(n),this.h()},h(){Dl(s,"name","hf:doc:metadata"),Dl(s,"content",ni),Dl(te,"class","flex justify-center"),fs.a=null,js.a=Is},m(e,l){g(document.head,s),a(e,i,l),a(e,t,l),a(e,c,l),u(y,e,l),a(e,U,l),u(j,e,l),a(e,es,l),u(oe,e,l),a(e,ts,l),It[B].m(e,l),a(e,Rt,l),a(e,me,l),a(e,ss,l),kt[$].m(e,l),a(e,Nt,l),u(pe,e,l),a(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l),a(e,Ds,l),a(e,De,l),a(e,Ps,l),a(e,Pe,l),a(e,Ks,l),u(Ke,e,l),a(e,Os,l),u(Oe,e,l),a(e,el,l),a(e,et,l),a(e,tl,l),u(tt,e,l),a(e,sl,l),u(st,e,l),a(e,ll,l),a(e,lt,l),a(e,nl,l),u(nt,e,l),a(e,al,l),a(e,at,l),a(e,il,l),u(it,e,l),a(e,rl,l),a(e,rt,l),a(e,ol,l),a(e,ot,l),a(e,ml,l),u(mt,e,l),a(e,pl,l),a(e,pt,l),a(e,cl,l),$t[E].m(e,l),a(e,qt,l),a(e,ct,l),a(e,Ml,l),u(Mt,e,l),a(e,hl,l),xt[Y].m(e,l),a(e,Lt,l),a(e,ht,l),a(e,ul,l),Gt[A].m(e,l),a(e,Dt,l),a(e,ut,l),a(e,dl,l),Ct[L].m(e,l),a(e,Pt,l),a(e,dt,l),a(e,wl,l),Wt[P].m(e,l),a(e,Kt,l),u(wt,e,l),a(e,yl,l),a(e,yt,l),a(e,Jl,l),u(ne,e,l),a(e,bl,l),a(e,Jt,l),a(e,Tl,l),u(bt,e,l),a(e,fl,l),u(Tt,e,l),a(e,Ul,l),a(e,ft,l),a(e,jl,l),u(ae,e,l),a(e,Il,l),a(e,Ut,l),a(e,kl,l),u(jt,e,l),a(e,gl,l),a(e,Ot,l),_l=!0},p(e,[l]){const k={};l&1&&(k.fw=e[0]),y.$set(k);let ee=B;B=Qn(e),B!==ee&&(v(),m(It[ee],1,1,()=>{It[ee]=null}),_(),Z=It[B],Z||(Z=It[B]=Hn[B](e),Z.c()),p(Z,1),Z.m(Rt.parentNode,Rt));let Xl=$;$=Fn(e),$!==Xl&&(v(),m(kt[Xl],1,1,()=>{kt[Xl]=null}),_(),x=kt[$],x||(x=kt[$]=En[$](e),x.c()),p(x,1),x.m(Nt.parentNode,Nt));let zl=G;G=Sn(e),G!==zl&&(v(),m(gt[zl],1,1,()=>{gt[zl]=null}),_(),C=gt[G],C||(C=gt[G]=Yn[G](e),C.c()),p(C,1),C.m(Vt.parentNode,Vt));let Hl=W;W=qn(e),W!==Hl&&(v(),m(_t[Hl],1,1,()=>{_t[Hl]=null}),_(),R=_t[W],R||(R=_t[W]=An[W](e),R.c()),p(R,1),R.m(Xt.parentNode,Xt));let Ql=N;N=Dn(e),N!==Ql&&(v(),m(vt[Ql],1,1,()=>{vt[Ql]=null}),_(),V=vt[N],V||(V=vt[N]=Ln[N](e),V.c()),p(V,1),V.m(zt.parentNode,zt));let El=X;X=Kn(e),X!==El&&(v(),m(Bt[El],1,1,()=>{Bt[El]=null}),_(),z=Bt[X],z||(z=Bt[X]=Pn[X](e),z.c()),p(z,1),z.m(Ht.parentNode,Ht));let Fl=H;H=ea(e),H!==Fl&&(v(),m(Zt[Fl],1,1,()=>{Zt[Fl]=null}),_(),Q=Zt[H],Q||(Q=Zt[H]=On[H](e),Q.c()),p(Q,1),Q.m(At.parentNode,At));const ca={};l&2&&(ca.$$scope={dirty:l,ctx:e}),se.$set(ca);const Ma={};l&2&&(Ma.$$scope={dirty:l,ctx:e}),le.$set(Ma);let Yl=E;E=sa(e),E!==Yl&&(v(),m($t[Yl],1,1,()=>{$t[Yl]=null}),_(),F=$t[E],F||(F=$t[E]=ta[E](e),F.c()),p(F,1),F.m(qt.parentNode,qt));let Sl=Y;Y=na(e),Y!==Sl&&(v(),m(xt[Sl],1,1,()=>{xt[Sl]=null}),_(),S=xt[Y],S||(S=xt[Y]=la[Y](e),S.c()),p(S,1),S.m(Lt.parentNode,Lt));let Al=A;A=ia(e),A!==Al&&(v(),m(Gt[Al],1,1,()=>{Gt[Al]=null}),_(),q=Gt[A],q||(q=Gt[A]=aa[A](e),q.c()),p(q,1),q.m(Dt.parentNode,Dt));let ql=L;L=oa(e),L!==ql&&(v(),m(Ct[ql],1,1,()=>{Ct[ql]=null}),_(),D=Ct[L],D||(D=Ct[L]=ra[L](e),D.c()),p(D,1),D.m(Pt.parentNode,Pt));let Ll=P;P=pa(e),P!==Ll&&(v(),m(Wt[Ll],1,1,()=>{Wt[Ll]=null}),_(),K=Wt[P],K||(K=Wt[P]=ma[P](e),K.c()),p(K,1),K.m(Kt.parentNode,Kt));const ha={};l&2&&(ha.$$scope={dirty:l,ctx:e}),ne.$set(ha);const ua={};l&2&&(ua.$$scope={dirty:l,ctx:e}),ae.$set(ua)},i(e){_l||(p(y.$$.fragment,e),p(j.$$.fragment,e),p(oe.$$.fragment,e),p(Z),p(x),p(pe.$$.fragment,e),p(Me.$$.fragment,e),p(he.$$.fragment,e),p(de.$$.fragment,e),p(we.$$.fragment,e),p(Je.$$.fragment,e),p(C),p(Ue.$$.fragment,e),p(R),p(V),p(z),p(ve.$$.fragment,e),p(Q),p(Ze.$$.fragment,e),p(xe.$$.fragment,e),p(se.$$.fragment,e),p(Ce.$$.fragment,e),p(Re.$$.fragment,e),p(Ne.$$.fragment,e),p(le.$$.fragment,e),p(Xe.$$.fragment,e),p(He.$$.fragment,e),p(Qe.$$.fragment,e),p(Fe.$$.fragment,e),p(Ye.$$.fragment,e),p(qe.$$.fragment,e),p(Le.$$.fragment,e),p(Ke.$$.fragment,e),p(Oe.$$.fragment,e),p(tt.$$.fragment,e),p(st.$$.fragment,e),p(nt.$$.fragment,e),p(it.$$.fragment,e),p(mt.$$.fragment,e),p(F),p(Mt.$$.fragment,e),p(S),p(q),p(D),p(K),p(wt.$$.fragment,e),p(ne.$$.fragment,e),p(bt.$$.fragment,e),p(Tt.$$.fragment,e),p(ae.$$.fragment,e),p(jt.$$.fragment,e),_l=!0)},o(e){m(y.$$.fragment,e),m(j.$$.fragment,e),m(oe.$$.fragment,e),m(Z),m(x),m(pe.$$.fragment,e),m(Me.$$.fragment,e),m(he.$$.fragment,e),m(de.$$.fragment,e),m(we.$$.fragment,e),m(Je.$$.fragment,e),m(C),m(Ue.$$.fragment,e),m(R),m(V),m(z),m(ve.$$.fragment,e),m(Q),m(Ze.$$.fragment,e),m(xe.$$.fragment,e),m(se.$$.fragment,e),m(Ce.$$.fragment,e),m(Re.$$.fragment,e),m(Ne.$$.fragment,e),m(le.$$.fragment,e),m(Xe.$$.fragment,e),m(He.$$.fragment,e),m(Qe.$$.fragment,e),m(Fe.$$.fragment,e),m(Ye.$$.fragment,e),m(qe.$$.fragment,e),m(Le.$$.fragment,e),m(Ke.$$.fragment,e),m(Oe.$$.fragment,e),m(tt.$$.fragment,e),m(st.$$.fragment,e),m(nt.$$.fragment,e),m(it.$$.fragment,e),m(mt.$$.fragment,e),m(F),m(Mt.$$.fragment,e),m(S),m(q),m(D),m(K),m(wt.$$.fragment,e),m(ne.$$.fragment,e),m(bt.$$.fragment,e),m(Tt.$$.fragment,e),m(ae.$$.fragment,e),m(jt.$$.fragment,e),_l=!1},d(e){e&&(n(i),n(t),n(c),n(U),n(es),n(ts),n(Rt),n(me),n(ss),n(Nt),n(ls),n(ce),n(ns),n(as),n(is),n(ue),n(rs),n(os),n(ms),n(ye),n(ps),n(cs),n(be),n(Ms),n(Vt),n(Te),n(hs),n(te),n(us),n(fe),n(ds),n(ws),n(Xt),n(je),n(ys),n(Ie),n(Js),n(zt),n(ke),n(bs),n(Ht),n(ge),n(Ts),n(I),n(Us),n(O),n(ks),n(_e),n(gs),n(_s),n(At),n(Be),n(vs),n(Bs),n($e),n(Zs),n($s),n(xs),n(Ge),n(Gs),n(Cs),n(We),n(Ws),n(Rs),n(Ns),n(Ve),n(Vs),n(Xs),n(zs),n(ze),n(Hs),n(Qs),n(Es),n(Ee),n(Fs),n(Ys),n(Ss),n(Se),n(As),n(Ae),n(qs),n(Ls),n(Ds),n(De),n(Ps),n(Pe),n(Ks),n(Os),n(el),n(et),n(tl),n(sl),n(ll),n(lt),n(nl),n(al),n(at),n(il),n(rl),n(rt),n(ol),n(ot),n(ml),n(pl),n(pt),n(cl),n(qt),n(ct),n(Ml),n(hl),n(Lt),n(ht),n(ul),n(Dt),n(ut),n(dl),n(Pt),n(dt),n(wl),n(Kt),n(yl),n(yt),n(Jl),n(bl),n(Jt),n(Tl),n(fl),n(Ul),n(ft),n(jl),n(Il),n(Ut),n(kl),n(gl),n(Ot)),n(s),d(y,e),d(j,e),d(oe,e),It[B].d(e),kt[$].d(e),d(pe,e),d(Me,e),d(he,e),d(de,e),d(we,e),d(Je,e),gt[G].d(e),d(Ue,e),_t[W].d(e),vt[N].d(e),Bt[X].d(e),d(ve,e),Zt[H].d(e),d(Ze,e),d(xe,e),d(se,e),d(Ce,e),d(Re,e),d(Ne,e),d(le,e),d(Xe,e),d(He,e),d(Qe,e),d(Fe,e),d(Ye,e),d(qe,e),d(Le,e),d(Ke,e),d(Oe,e),d(tt,e),d(st,e),d(nt,e),d(it,e),d(mt,e),$t[E].d(e),d(Mt,e),xt[Y].d(e),Gt[A].d(e),Ct[L].d(e),Wt[P].d(e),d(wt,e),d(ne,e),d(bt,e),d(Tt,e),d(ae,e),d(jt,e)}}}const ni='{"title":"Fast tokenizers in the QA pipeline","local":"fast-tokenizers-in-the-qa-pipeline","sections":[{"title":"Using the question-answering pipeline","local":"using-the-question-answering-pipeline","sections":[],"depth":2},{"title":"Using a model for question answering","local":"using-a-model-for-question-answering","sections":[],"depth":2},{"title":"Handling long contexts","local":"handling-long-contexts","sections":[],"depth":2}],"depth":1}';function ai(w,s,i){let t="pt";return Ua(()=>{const c=new URLSearchParams(window.location.search);i(0,t=c.get("fw")||"pt")}),[t]}class ui extends ja{constructor(s){super(),Ia(this,s,ai,li,fa,{})}}export{ui as component};
