import{s as ba,o as Ta,n as vl}from"../chunks/scheduler.37c15a92.js";import{S as fa,i as Ua,g as J,s as r,r as M,m as ie,H as ha,A as ja,h as b,f as n,c as o,j as gl,u as h,x as f,n as re,B as ua,k as ql,y as g,a,v as u,t as m,b as _,d as p,w as d,p as B}from"../chunks/index.7cb9c9b8.js";import{T as _l}from"../chunks/Tip.d10b3fc9.js";import{Y as da}from"../chunks/Youtube.8666c400.js";import{C as T}from"../chunks/CodeBlock.abae2786.js";import{C as wa}from"../chunks/CourseFloatingBanner.df82c153.js";import{F as Ia}from"../chunks/FrameworkSwitchCourse.97630871.js";import{H as Bl,E as ka}from"../chunks/index.706e2c58.js";function ga(w){let s,i;return s=new wa({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 _a(w){let s,i;return s=new wa({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 Ba(w){let s,i;return s=new da({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 va(w){let s,i;return s=new da({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 Za(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 $a(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 xa(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 Ga(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 Ca(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 Wa(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 Ra(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 Na(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 Va(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 Xa(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 za(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:vl,d(t){t&&n(s)}}}function Ha(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:vl,d(t){t&&n(s)}}}function Qa(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 Ea(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 Fa(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 Ya(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 Sa(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 Aa(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 qa(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 La(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 Da(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 Pa(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 Ka(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:vl,d(t){t&&n(s)}}}function Oa(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:vl,d(t){t&&n(s)}}}function ei(w){let s,i,t,c,y,U,j,Ot,v,Z,Wt,oe,Ll="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.",es,$,x,Rt,me,ts,pe,Dl='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:',ss,ce,ls,Me,ns,he,Pl="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:",as,ue,is,de,rs,we,Kl="Let’s see how it does all of this!",os,ye,ms,Je,Ol='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>):',ps,G,C,Nt,be,en="Note that we tokenize the question and the context as a pair, with the question first.",cs,te,tn='<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"/>',Ms,Te,sn="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:",hs,fe,us,W,R,Vt,Ue,ln="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.",ds,je,nn="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>:",ws,N,V,Xt,Ie,an="Now that we have properly masked the logits corresponding to positions we don’t want to predict, we can apply the softmax:",ys,X,z,zt,ke,rn="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.",Js,I,Zl,Ht,on="start_index",$l,Qt,mn="end_index",xl,Et,pn="start_index",Gl,Ft,cn="end_index",Cl,bs,ya='<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>',Ts,O,Wl,fs,Ja='<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>',Us,Yt,Mn="start_index <= end_index",Rl,js,ge,hn="First let’s compute all the possible products:",Is,_e,ks,H,Q,St,Be,un="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>:",gs,ve,_s,Ze,dn="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):",Bs,$e,vs,se,Zs,xe,wn="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:",$s,Ge,xs,Ce,yn="Now we just have to format everything to get our result:",Gs,We,Cs,Re,Ws,Ne,Jn="Great! That’s the same as in our first example!",Rs,le,Ns,Ve,Vs,Xe,bn="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):",Xs,ze,zs,He,Hs,Qe,Tn="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:",Qs,Ee,Es,Fe,Fs,Ye,fn="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.",Ys,Se,Un="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:",Ss,Ae,As,qe,qs,Le,jn="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.",Ls,De,In="Let’s take a closer look at the result of the tokenization:",Ds,Pe,Ps,Ke,Ks,Oe,kn="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:",Os,et,el,tt,tl,st,gn="This is more useful when we tokenize several sentences together. For instance, this:",sl,lt,ll,nt,_n="gets us:",nl,at,al,it,Bn="which means the first sentence is split into 7 chunks as before, and the next 4 chunks come from the second sentence.",il,rt,vn="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:",rl,ot,ol,mt,Zn="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:",ml,E,F,At,pt,$n="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:",pl,ct,cl,Y,S,qt,Mt,xn="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):",Ml,A,q,Lt,ht,Gn="Then we can use the softmax to convert our logits to probabilities:",hl,L,D,Dt,ut,Cn="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:",ul,P,K,Pt,dt,dl,wt,Wn="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).",wl,ne,yl,yt,Rn="The <code>offsets</code> we grabbed earlier is actually a list of offsets, with one list per chunk of text:",Jl,Jt,bl,bt,Tl,Tt,Nn="If we ignore the first result, we get the same result as our pipeline for this long context — yay!",fl,ae,Ul,ft,Vn="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.",jl,Ut,Il,Kt,kl;y=new Ia({props:{fw:w[0]}}),j=new Bl({props:{title:"Fast tokenizers in the QA pipeline",local:"fast-tokenizers-in-the-qa-pipeline",headingTag:"h1"}});const Xn=[_a,ga],jt=[];function zn(e,l){return e[0]==="pt"?0:1}v=zn(w),Z=jt[v]=Xn[v](w);const Hn=[va,Ba],It=[];function Qn(e,l){return e[0]==="pt"?0:1}$=Qn(w),x=It[$]=Hn[$](w),me=new Bl({props:{title:"Using the question-answering pipeline",local:"using-the-question-answering-pipeline",headingTag:"h2"}}),ce=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}}),Me=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}}),ue=new T({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZ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ZGVsJTIwZmlsZXMlMjBjYW4lMjBiZSUyMHVzZWQlMjBpbmRlcGVuZGVudGx5JTIwb2YlMjB0aGUlMjBsaWJyYXJ5JTIwZm9yJTIwcXVpY2slMjBleHBlcmltZW50cy4lMEElMEElRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlMjBpcyUyMGJhY2tlZCUyMGJ5JTIwdGhlJTIwdGhyZWUlMjBtb3N0JTIwcG9wdWxhciUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMCVFMiU4MCU5NCUyMEpheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",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}}),de=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}}),ye=new Bl({props:{title:"Using a model for question answering",local:"using-a-model-for-question-answering",headingTag:"h2"}});const En=[$a,Za],kt=[];function Fn(e,l){return e[0]==="pt"?0:1}G=Fn(w),C=kt[G]=En[G](w),fe=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 Yn=[Ga,xa],gt=[];function Sn(e,l){return e[0]==="pt"?0:1}W=Sn(w),R=gt[W]=Yn[W](w);const An=[Wa,Ca],_t=[];function qn(e,l){return e[0]==="pt"?0:1}N=qn(w),V=_t[N]=An[N](w);const Ln=[Na,Ra],Bt=[];function Dn(e,l){return e[0]==="pt"?0:1}X=Dn(w),z=Bt[X]=Ln[X](w),_e=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 Pn=[Xa,Va],vt=[];function Kn(e,l){return e[0]==="pt"?0:1}H=Kn(w),Q=vt[H]=Pn[H](w),ve=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}}),$e=new T({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),se=new _l({props:{$$slots:{default:[za]},$$scope:{ctx:w}}}),Ge=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}}),We=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}}),Re=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 _l({props:{$$slots:{default:[Ha]},$$scope:{ctx:w}}}),Ve=new Bl({props:{title:"Handling long contexts",local:"handling-long-contexts",headingTag:"h2"}}),ze=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}}),He=new T({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Ee=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}}),Fe=new T({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU1RCUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZX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YW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",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}}),Ae=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}}),qe=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}}),Pe=new T({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Ke=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}}),et=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}}),tt=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}}),lt=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}}),at=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}}),ot=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 On=[Ea,Qa],Zt=[];function ea(e,l){return e[0]==="pt"?0:1}E=ea(w),F=Zt[E]=On[E](w),ct=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 ta=[Ya,Fa],$t=[];function sa(e,l){return e[0]==="pt"?0:1}Y=sa(w),S=$t[Y]=ta[Y](w);const la=[Aa,Sa],xt=[];function na(e,l){return e[0]==="pt"?0:1}A=na(w),q=xt[A]=la[A](w);const aa=[La,qa],Gt=[];function ia(e,l){return e[0]==="pt"?0:1}L=ia(w),D=Gt[L]=aa[L](w);const ra=[Pa,Da],Ct=[];function oa(e,l){return e[0]==="pt"?0:1}return P=oa(w),K=Ct[P]=ra[P](w),dt=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 _l({props:{$$slots:{default:[Ka]},$$scope:{ctx:w}}}),Jt=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}}),bt=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 _l({props:{$$slots:{default:[Oa]},$$scope:{ctx:w}}}),Ut=new ka({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),Ot=r(),Z.c(),Wt=r(),oe=J("p"),oe.innerHTML=Ll,es=r(),x.c(),Rt=r(),M(me.$$.fragment),ts=r(),pe=J("p"),pe.innerHTML=Dl,ss=r(),M(ce.$$.fragment),ls=r(),M(Me.$$.fragment),ns=r(),he=J("p"),he.textContent=Pl,as=r(),M(ue.$$.fragment),is=r(),M(de.$$.fragment),rs=r(),we=J("p"),we.textContent=Kl,os=r(),M(ye.$$.fragment),ms=r(),Je=J("p"),Je.innerHTML=Ol,ps=r(),C.c(),Nt=r(),be=J("p"),be.textContent=en,cs=r(),te=J("div"),te.innerHTML=tn,Ms=r(),Te=J("p"),Te.textContent=sn,hs=r(),M(fe.$$.fragment),us=r(),R.c(),Vt=r(),Ue=J("p"),Ue.innerHTML=ln,ds=r(),je=J("p"),je.innerHTML=nn,ws=r(),V.c(),Xt=r(),Ie=J("p"),Ie.textContent=an,ys=r(),z.c(),zt=r(),ke=J("p"),ke.innerHTML=rn,Js=r(),I=J("p"),Zl=ie("Assuming the events “The answer starts at "),Ht=J("code"),Ht.textContent=on,$l=ie("” and “The answer ends at "),Qt=J("code"),Qt.textContent=mn,xl=ie("” to be independent, the probability that the answer starts at "),Et=J("code"),Et.textContent=pn,Gl=ie(" and ends at "),Ft=J("code"),Ft.textContent=cn,Cl=ie(` is:
`),bs=new ha(!1),Ts=r(),O=J("p"),Wl=ie("So, to compute all the scores, we just need to compute all the products"),fs=new ha(!1),Us=ie(" where "),Yt=J("code"),Yt.textContent=Mn,Rl=ie("."),js=r(),ge=J("p"),ge.textContent=hn,Is=r(),M(_e.$$.fragment),ks=r(),Q.c(),St=r(),Be=J("p"),Be.innerHTML=un,gs=r(),M(ve.$$.fragment),_s=r(),Ze=J("p"),Ze.textContent=dn,Bs=r(),M($e.$$.fragment),vs=r(),M(se.$$.fragment),Zs=r(),xe=J("p"),xe.innerHTML=wn,$s=r(),M(Ge.$$.fragment),xs=r(),Ce=J("p"),Ce.textContent=yn,Gs=r(),M(We.$$.fragment),Cs=r(),M(Re.$$.fragment),Ws=r(),Ne=J("p"),Ne.textContent=Jn,Rs=r(),M(le.$$.fragment),Ns=r(),M(Ve.$$.fragment),Vs=r(),Xe=J("p"),Xe.innerHTML=bn,Xs=r(),M(ze.$$.fragment),zs=r(),M(He.$$.fragment),Hs=r(),Qe=J("p"),Qe.innerHTML=Tn,Qs=r(),M(Ee.$$.fragment),Es=r(),M(Fe.$$.fragment),Fs=r(),Ye=J("p"),Ye.innerHTML=fn,Ys=r(),Se=J("p"),Se.innerHTML=Un,Ss=r(),M(Ae.$$.fragment),As=r(),M(qe.$$.fragment),qs=r(),Le=J("p"),Le.innerHTML=jn,Ls=r(),De=J("p"),De.textContent=In,Ds=r(),M(Pe.$$.fragment),Ps=r(),M(Ke.$$.fragment),Ks=r(),Oe=J("p"),Oe.innerHTML=kn,Os=r(),M(et.$$.fragment),el=r(),M(tt.$$.fragment),tl=r(),st=J("p"),st.textContent=gn,sl=r(),M(lt.$$.fragment),ll=r(),nt=J("p"),nt.textContent=_n,nl=r(),M(at.$$.fragment),al=r(),it=J("p"),it.textContent=Bn,il=r(),rt=J("p"),rt.innerHTML=vn,rl=r(),M(ot.$$.fragment),ol=r(),mt=J("p"),mt.innerHTML=Zn,ml=r(),F.c(),At=r(),pt=J("p"),pt.textContent=$n,pl=r(),M(ct.$$.fragment),cl=r(),S.c(),qt=r(),Mt=J("p"),Mt.textContent=xn,Ml=r(),q.c(),Lt=r(),ht=J("p"),ht.textContent=Gn,hl=r(),D.c(),Dt=r(),ut=J("p"),ut.textContent=Cn,ul=r(),K.c(),Pt=r(),M(dt.$$.fragment),dl=r(),wt=J("p"),wt.textContent=Wn,wl=r(),M(ne.$$.fragment),yl=r(),yt=J("p"),yt.innerHTML=Rn,Jl=r(),M(Jt.$$.fragment),bl=r(),M(bt.$$.fragment),Tl=r(),Tt=J("p"),Tt.textContent=Nn,fl=r(),M(ae.$$.fragment),Ul=r(),ft=J("p"),ft.textContent=Vn,jl=r(),M(Ut.$$.fragment),Il=r(),Kt=J("p"),this.h()},l(e){const l=ja("svelte-u9bgzb",document.head);s=b(l,"META",{name:!0,content:!0}),l.forEach(n),i=o(e),t=b(e,"P",{}),gl(t).forEach(n),c=o(e),h(y.$$.fragment,e),U=o(e),h(j.$$.fragment,e),Ot=o(e),Z.l(e),Wt=o(e),oe=b(e,"P",{"data-svelte-h":!0}),f(oe)!=="svelte-lvoxg9"&&(oe.innerHTML=Ll),es=o(e),x.l(e),Rt=o(e),h(me.$$.fragment,e),ts=o(e),pe=b(e,"P",{"data-svelte-h":!0}),f(pe)!=="svelte-1rzsno5"&&(pe.innerHTML=Dl),ss=o(e),h(ce.$$.fragment,e),ls=o(e),h(Me.$$.fragment,e),ns=o(e),he=b(e,"P",{"data-svelte-h":!0}),f(he)!=="svelte-1pagerf"&&(he.textContent=Pl),as=o(e),h(ue.$$.fragment,e),is=o(e),h(de.$$.fragment,e),rs=o(e),we=b(e,"P",{"data-svelte-h":!0}),f(we)!=="svelte-sapdef"&&(we.textContent=Kl),os=o(e),h(ye.$$.fragment,e),ms=o(e),Je=b(e,"P",{"data-svelte-h":!0}),f(Je)!=="svelte-w4r3vw"&&(Je.innerHTML=Ol),ps=o(e),C.l(e),Nt=o(e),be=b(e,"P",{"data-svelte-h":!0}),f(be)!=="svelte-1f1yf5i"&&(be.textContent=en),cs=o(e),te=b(e,"DIV",{class:!0,"data-svelte-h":!0}),f(te)!=="svelte-47wedv"&&(te.innerHTML=tn),Ms=o(e),Te=b(e,"P",{"data-svelte-h":!0}),f(Te)!=="svelte-lbyhwl"&&(Te.textContent=sn),hs=o(e),h(fe.$$.fragment,e),us=o(e),R.l(e),Vt=o(e),Ue=b(e,"P",{"data-svelte-h":!0}),f(Ue)!=="svelte-bkvch0"&&(Ue.innerHTML=ln),ds=o(e),je=b(e,"P",{"data-svelte-h":!0}),f(je)!=="svelte-6ptczc"&&(je.innerHTML=nn),ws=o(e),V.l(e),Xt=o(e),Ie=b(e,"P",{"data-svelte-h":!0}),f(Ie)!=="svelte-1j5ys7d"&&(Ie.textContent=an),ys=o(e),z.l(e),zt=o(e),ke=b(e,"P",{"data-svelte-h":!0}),f(ke)!=="svelte-1qmjo9o"&&(ke.innerHTML=rn),Js=o(e),I=b(e,"P",{});var k=gl(I);Zl=re(k,"Assuming the events “The answer starts at "),Ht=b(k,"CODE",{"data-svelte-h":!0}),f(Ht)!=="svelte-8eqb3b"&&(Ht.textContent=on),$l=re(k,"” and “The answer ends at "),Qt=b(k,"CODE",{"data-svelte-h":!0}),f(Qt)!=="svelte-9cistc"&&(Qt.textContent=mn),xl=re(k,"” to be independent, the probability that the answer starts at "),Et=b(k,"CODE",{"data-svelte-h":!0}),f(Et)!=="svelte-8eqb3b"&&(Et.textContent=pn),Gl=re(k," and ends at "),Ft=b(k,"CODE",{"data-svelte-h":!0}),f(Ft)!=="svelte-9cistc"&&(Ft.textContent=cn),Cl=re(k,` is:
`),bs=ua(k,!1),k.forEach(n),Ts=o(e),O=b(e,"P",{});var ee=gl(O);Wl=re(ee,"So, to compute all the scores, we just need to compute all the products"),fs=ua(ee,!1),Us=re(ee," where "),Yt=b(ee,"CODE",{"data-svelte-h":!0}),f(Yt)!=="svelte-1kp3szf"&&(Yt.textContent=Mn),Rl=re(ee,"."),ee.forEach(n),js=o(e),ge=b(e,"P",{"data-svelte-h":!0}),f(ge)!=="svelte-193wrn1"&&(ge.textContent=hn),Is=o(e),h(_e.$$.fragment,e),ks=o(e),Q.l(e),St=o(e),Be=b(e,"P",{"data-svelte-h":!0}),f(Be)!=="svelte-1mc8mc3"&&(Be.innerHTML=un),gs=o(e),h(ve.$$.fragment,e),_s=o(e),Ze=b(e,"P",{"data-svelte-h":!0}),f(Ze)!=="svelte-mq04r0"&&(Ze.textContent=dn),Bs=o(e),h($e.$$.fragment,e),vs=o(e),h(se.$$.fragment,e),Zs=o(e),xe=b(e,"P",{"data-svelte-h":!0}),f(xe)!=="svelte-1vbvikx"&&(xe.innerHTML=wn),$s=o(e),h(Ge.$$.fragment,e),xs=o(e),Ce=b(e,"P",{"data-svelte-h":!0}),f(Ce)!=="svelte-o78gqr"&&(Ce.textContent=yn),Gs=o(e),h(We.$$.fragment,e),Cs=o(e),h(Re.$$.fragment,e),Ws=o(e),Ne=b(e,"P",{"data-svelte-h":!0}),f(Ne)!=="svelte-erpa1c"&&(Ne.textContent=Jn),Rs=o(e),h(le.$$.fragment,e),Ns=o(e),h(Ve.$$.fragment,e),Vs=o(e),Xe=b(e,"P",{"data-svelte-h":!0}),f(Xe)!=="svelte-1ny8u7i"&&(Xe.innerHTML=bn),Xs=o(e),h(ze.$$.fragment,e),zs=o(e),h(He.$$.fragment,e),Hs=o(e),Qe=b(e,"P",{"data-svelte-h":!0}),f(Qe)!=="svelte-1vshog5"&&(Qe.innerHTML=Tn),Qs=o(e),h(Ee.$$.fragment,e),Es=o(e),h(Fe.$$.fragment,e),Fs=o(e),Ye=b(e,"P",{"data-svelte-h":!0}),f(Ye)!=="svelte-cfs4jm"&&(Ye.innerHTML=fn),Ys=o(e),Se=b(e,"P",{"data-svelte-h":!0}),f(Se)!=="svelte-1nms3xo"&&(Se.innerHTML=Un),Ss=o(e),h(Ae.$$.fragment,e),As=o(e),h(qe.$$.fragment,e),qs=o(e),Le=b(e,"P",{"data-svelte-h":!0}),f(Le)!=="svelte-1qc9ozy"&&(Le.innerHTML=jn),Ls=o(e),De=b(e,"P",{"data-svelte-h":!0}),f(De)!=="svelte-1f82rb6"&&(De.textContent=In),Ds=o(e),h(Pe.$$.fragment,e),Ps=o(e),h(Ke.$$.fragment,e),Ks=o(e),Oe=b(e,"P",{"data-svelte-h":!0}),f(Oe)!=="svelte-k27ihj"&&(Oe.innerHTML=kn),Os=o(e),h(et.$$.fragment,e),el=o(e),h(tt.$$.fragment,e),tl=o(e),st=b(e,"P",{"data-svelte-h":!0}),f(st)!=="svelte-w7y7n8"&&(st.textContent=gn),sl=o(e),h(lt.$$.fragment,e),ll=o(e),nt=b(e,"P",{"data-svelte-h":!0}),f(nt)!=="svelte-b6k3qh"&&(nt.textContent=_n),nl=o(e),h(at.$$.fragment,e),al=o(e),it=b(e,"P",{"data-svelte-h":!0}),f(it)!=="svelte-dqom4c"&&(it.textContent=Bn),il=o(e),rt=b(e,"P",{"data-svelte-h":!0}),f(rt)!=="svelte-vpesag"&&(rt.innerHTML=vn),rl=o(e),h(ot.$$.fragment,e),ol=o(e),mt=b(e,"P",{"data-svelte-h":!0}),f(mt)!=="svelte-8qj5sv"&&(mt.innerHTML=Zn),ml=o(e),F.l(e),At=o(e),pt=b(e,"P",{"data-svelte-h":!0}),f(pt)!=="svelte-1rmefba"&&(pt.textContent=$n),pl=o(e),h(ct.$$.fragment,e),cl=o(e),S.l(e),qt=o(e),Mt=b(e,"P",{"data-svelte-h":!0}),f(Mt)!=="svelte-12rpmqq"&&(Mt.textContent=xn),Ml=o(e),q.l(e),Lt=o(e),ht=b(e,"P",{"data-svelte-h":!0}),f(ht)!=="svelte-xc3z5h"&&(ht.textContent=Gn),hl=o(e),D.l(e),Dt=o(e),ut=b(e,"P",{"data-svelte-h":!0}),f(ut)!=="svelte-t87wk3"&&(ut.textContent=Cn),ul=o(e),K.l(e),Pt=o(e),h(dt.$$.fragment,e),dl=o(e),wt=b(e,"P",{"data-svelte-h":!0}),f(wt)!=="svelte-s4nw2c"&&(wt.textContent=Wn),wl=o(e),h(ne.$$.fragment,e),yl=o(e),yt=b(e,"P",{"data-svelte-h":!0}),f(yt)!=="svelte-1ocnhs0"&&(yt.innerHTML=Rn),Jl=o(e),h(Jt.$$.fragment,e),bl=o(e),h(bt.$$.fragment,e),Tl=o(e),Tt=b(e,"P",{"data-svelte-h":!0}),f(Tt)!=="svelte-k6zbjj"&&(Tt.textContent=Nn),fl=o(e),h(ae.$$.fragment,e),Ul=o(e),ft=b(e,"P",{"data-svelte-h":!0}),f(ft)!=="svelte-1p6apew"&&(ft.textContent=Vn),jl=o(e),h(Ut.$$.fragment,e),Il=o(e),Kt=b(e,"P",{}),gl(Kt).forEach(n),this.h()},h(){ql(s,"name","hf:doc:metadata"),ql(s,"content",ti),ql(te,"class","flex justify-center"),bs.a=null,fs.a=Us},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,Ot,l),jt[v].m(e,l),a(e,Wt,l),a(e,oe,l),a(e,es,l),It[$].m(e,l),a(e,Rt,l),u(me,e,l),a(e,ts,l),a(e,pe,l),a(e,ss,l),u(ce,e,l),a(e,ls,l),u(Me,e,l),a(e,ns,l),a(e,he,l),a(e,as,l),u(ue,e,l),a(e,is,l),u(de,e,l),a(e,rs,l),a(e,we,l),a(e,os,l),u(ye,e,l),a(e,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e,st,l),a(e,sl,l),u(lt,e,l),a(e,ll,l),a(e,nt,l),a(e,nl,l),u(at,e,l),a(e,al,l),a(e,it,l),a(e,il,l),a(e,rt,l),a(e,rl,l),u(ot,e,l),a(e,ol,l),a(e,mt,l),a(e,ml,l),Zt[E].m(e,l),a(e,At,l),a(e,pt,l),a(e,pl,l),u(ct,e,l),a(e,cl,l),$t[Y].m(e,l),a(e,qt,l),a(e,Mt,l),a(e,Ml,l),xt[A].m(e,l),a(e,Lt,l),a(e,ht,l),a(e,hl,l),Gt[L].m(e,l),a(e,Dt,l),a(e,ut,l),a(e,ul,l),Ct[P].m(e,l),a(e,Pt,l),u(dt,e,l),a(e,dl,l),a(e,wt,l),a(e,wl,l),u(ne,e,l),a(e,yl,l),a(e,yt,l),a(e,Jl,l),u(Jt,e,l),a(e,bl,l),u(bt,e,l),a(e,Tl,l),a(e,Tt,l),a(e,fl,l),u(ae,e,l),a(e,Ul,l),a(e,ft,l),a(e,jl,l),u(Ut,e,l),a(e,Il,l),a(e,Kt,l),kl=!0},p(e,[l]){const k={};l&1&&(k.fw=e[0]),y.$set(k);let ee=v;v=zn(e),v!==ee&&(B(),m(jt[ee],1,1,()=>{jt[ee]=null}),_(),Z=jt[v],Z||(Z=jt[v]=Xn[v](e),Z.c()),p(Z,1),Z.m(Wt.parentNode,Wt));let Nl=$;$=Qn(e),$!==Nl&&(B(),m(It[Nl],1,1,()=>{It[Nl]=null}),_(),x=It[$],x||(x=It[$]=Hn[$](e),x.c()),p(x,1),x.m(Rt.parentNode,Rt));let Vl=G;G=Fn(e),G!==Vl&&(B(),m(kt[Vl],1,1,()=>{kt[Vl]=null}),_(),C=kt[G],C||(C=kt[G]=En[G](e),C.c()),p(C,1),C.m(Nt.parentNode,Nt));let Xl=W;W=Sn(e),W!==Xl&&(B(),m(gt[Xl],1,1,()=>{gt[Xl]=null}),_(),R=gt[W],R||(R=gt[W]=Yn[W](e),R.c()),p(R,1),R.m(Vt.parentNode,Vt));let zl=N;N=qn(e),N!==zl&&(B(),m(_t[zl],1,1,()=>{_t[zl]=null}),_(),V=_t[N],V||(V=_t[N]=An[N](e),V.c()),p(V,1),V.m(Xt.parentNode,Xt));let Hl=X;X=Dn(e),X!==Hl&&(B(),m(Bt[Hl],1,1,()=>{Bt[Hl]=null}),_(),z=Bt[X],z||(z=Bt[X]=Ln[X](e),z.c()),p(z,1),z.m(zt.parentNode,zt));let Ql=H;H=Kn(e),H!==Ql&&(B(),m(vt[Ql],1,1,()=>{vt[Ql]=null}),_(),Q=vt[H],Q||(Q=vt[H]=Pn[H](e),Q.c()),p(Q,1),Q.m(St.parentNode,St));const ma={};l&2&&(ma.$$scope={dirty:l,ctx:e}),se.$set(ma);const pa={};l&2&&(pa.$$scope={dirty:l,ctx:e}),le.$set(pa);let El=E;E=ea(e),E!==El&&(B(),m(Zt[El],1,1,()=>{Zt[El]=null}),_(),F=Zt[E],F||(F=Zt[E]=On[E](e),F.c()),p(F,1),F.m(At.parentNode,At));let Fl=Y;Y=sa(e),Y!==Fl&&(B(),m($t[Fl],1,1,()=>{$t[Fl]=null}),_(),S=$t[Y],S||(S=$t[Y]=ta[Y](e),S.c()),p(S,1),S.m(qt.parentNode,qt));let Yl=A;A=na(e),A!==Yl&&(B(),m(xt[Yl],1,1,()=>{xt[Yl]=null}),_(),q=xt[A],q||(q=xt[A]=la[A](e),q.c()),p(q,1),q.m(Lt.parentNode,Lt));let Sl=L;L=ia(e),L!==Sl&&(B(),m(Gt[Sl],1,1,()=>{Gt[Sl]=null}),_(),D=Gt[L],D||(D=Gt[L]=aa[L](e),D.c()),p(D,1),D.m(Dt.parentNode,Dt));let Al=P;P=oa(e),P!==Al&&(B(),m(Ct[Al],1,1,()=>{Ct[Al]=null}),_(),K=Ct[P],K||(K=Ct[P]=ra[P](e),K.c()),p(K,1),K.m(Pt.parentNode,Pt));const ca={};l&2&&(ca.$$scope={dirty:l,ctx:e}),ne.$set(ca);const Ma={};l&2&&(Ma.$$scope={dirty:l,ctx:e}),ae.$set(Ma)},i(e){kl||(p(y.$$.fragment,e),p(j.$$.fragment,e),p(Z),p(x),p(me.$$.fragment,e),p(ce.$$.fragment,e),p(Me.$$.fragment,e),p(ue.$$.fragment,e),p(de.$$.fragment,e),p(ye.$$.fragment,e),p(C),p(fe.$$.fragment,e),p(R),p(V),p(z),p(_e.$$.fragment,e),p(Q),p(ve.$$.fragment,e),p($e.$$.fragment,e),p(se.$$.fragment,e),p(Ge.$$.fragment,e),p(We.$$.fragment,e),p(Re.$$.fragment,e),p(le.$$.fragment,e),p(Ve.$$.fragment,e),p(ze.$$.fragment,e),p(He.$$.fragment,e),p(Ee.$$.fragment,e),p(Fe.$$.fragment,e),p(Ae.$$.fragment,e),p(qe.$$.fragment,e),p(Pe.$$.fragment,e),p(Ke.$$.fragment,e),p(et.$$.fragment,e),p(tt.$$.fragment,e),p(lt.$$.fragment,e),p(at.$$.fragment,e),p(ot.$$.fragment,e),p(F),p(ct.$$.fragment,e),p(S),p(q),p(D),p(K),p(dt.$$.fragment,e),p(ne.$$.fragment,e),p(Jt.$$.fragment,e),p(bt.$$.fragment,e),p(ae.$$.fragment,e),p(Ut.$$.fragment,e),kl=!0)},o(e){m(y.$$.fragment,e),m(j.$$.fragment,e),m(Z),m(x),m(me.$$.fragment,e),m(ce.$$.fragment,e),m(Me.$$.fragment,e),m(ue.$$.fragment,e),m(de.$$.fragment,e),m(ye.$$.fragment,e),m(C),m(fe.$$.fragment,e),m(R),m(V),m(z),m(_e.$$.fragment,e),m(Q),m(ve.$$.fragment,e),m($e.$$.fragment,e),m(se.$$.fragment,e),m(Ge.$$.fragment,e),m(We.$$.fragment,e),m(Re.$$.fragment,e),m(le.$$.fragment,e),m(Ve.$$.fragment,e),m(ze.$$.fragment,e),m(He.$$.fragment,e),m(Ee.$$.fragment,e),m(Fe.$$.fragment,e),m(Ae.$$.fragment,e),m(qe.$$.fragment,e),m(Pe.$$.fragment,e),m(Ke.$$.fragment,e),m(et.$$.fragment,e),m(tt.$$.fragment,e),m(lt.$$.fragment,e),m(at.$$.fragment,e),m(ot.$$.fragment,e),m(F),m(ct.$$.fragment,e),m(S),m(q),m(D),m(K),m(dt.$$.fragment,e),m(ne.$$.fragment,e),m(Jt.$$.fragment,e),m(bt.$$.fragment,e),m(ae.$$.fragment,e),m(Ut.$$.fragment,e),kl=!1},d(e){e&&(n(i),n(t),n(c),n(U),n(Ot),n(Wt),n(oe),n(es),n(Rt),n(ts),n(pe),n(ss),n(ls),n(ns),n(he),n(as),n(is),n(rs),n(we),n(os),n(ms),n(Je),n(ps),n(Nt),n(be),n(cs),n(te),n(Ms),n(Te),n(hs),n(us),n(Vt),n(Ue),n(ds),n(je),n(ws),n(Xt),n(Ie),n(ys),n(zt),n(ke),n(Js),n(I),n(Ts),n(O),n(js),n(ge),n(Is),n(ks),n(St),n(Be),n(gs),n(_s),n(Ze),n(Bs),n(vs),n(Zs),n(xe),n($s),n(xs),n(Ce),n(Gs),n(Cs),n(Ws),n(Ne),n(Rs),n(Ns),n(Vs),n(Xe),n(Xs),n(zs),n(Hs),n(Qe),n(Qs),n(Es),n(Fs),n(Ye),n(Ys),n(Se),n(Ss),n(As),n(qs),n(Le),n(Ls),n(De),n(Ds),n(Ps),n(Ks),n(Oe),n(Os),n(el),n(tl),n(st),n(sl),n(ll),n(nt),n(nl),n(al),n(it),n(il),n(rt),n(rl),n(ol),n(mt),n(ml),n(At),n(pt),n(pl),n(cl),n(qt),n(Mt),n(Ml),n(Lt),n(ht),n(hl),n(Dt),n(ut),n(ul),n(Pt),n(dl),n(wt),n(wl),n(yl),n(yt),n(Jl),n(bl),n(Tl),n(Tt),n(fl),n(Ul),n(ft),n(jl),n(Il),n(Kt)),n(s),d(y,e),d(j,e),jt[v].d(e),It[$].d(e),d(me,e),d(ce,e),d(Me,e),d(ue,e),d(de,e),d(ye,e),kt[G].d(e),d(fe,e),gt[W].d(e),_t[N].d(e),Bt[X].d(e),d(_e,e),vt[H].d(e),d(ve,e),d($e,e),d(se,e),d(Ge,e),d(We,e),d(Re,e),d(le,e),d(Ve,e),d(ze,e),d(He,e),d(Ee,e),d(Fe,e),d(Ae,e),d(qe,e),d(Pe,e),d(Ke,e),d(et,e),d(tt,e),d(lt,e),d(at,e),d(ot,e),Zt[E].d(e),d(ct,e),$t[Y].d(e),xt[A].d(e),Gt[L].d(e),Ct[P].d(e),d(dt,e),d(ne,e),d(Jt,e),d(bt,e),d(ae,e),d(Ut,e)}}}const ti='{"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 si(w,s,i){let t="pt";return Ta(()=>{const c=new URLSearchParams(window.location.search);i(0,t=c.get("fw")||"pt")}),[t]}class ci extends fa{constructor(s){super(),Ua(this,s,si,ei,ba,{})}}export{ci as component};
