import{s as da,o as ha,n as $s}from"../chunks/scheduler.37c15a92.js";import{S as Ua,i as fa,g as T,s as i,r as M,m as rt,H as Ja,A as ja,h as d,f as n,c as m,j as gs,u as J,x as U,n as it,E as ya,k as qs,y as g,a,v as y,t as p,b as B,d as o,w as u,p as Z}from"../chunks/index.2bf4358c.js";import{T as Bs}from"../chunks/Tip.363c041f.js";import{Y as ua}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as ba}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Ia}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Zs,E as _a}from"../chunks/EditOnGithub.8916dc7c.js";function ga(b){let e,r;return e=new ba({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/zh-CN/chapter6/section3b_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_tf.ipynb"}]}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ba(b){let e,r;return e=new ba({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/zh-CN/chapter6/section3b_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_pt.ipynb"}]}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Za(b){let e,r;return e=new ua({props:{id:"b3u8RzBCX9Y"}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function $a(b){let e,r;return e=new ua({props:{id:"_wxyB3j3mk4"}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function ka(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function va(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ga(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ca(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function xa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Wa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ra(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Na(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Va(b){let e,r="然后我们将屏蔽这些值 <strong>start_index &gt; end_index</strong> 通过将它们设置为 <strong>0</strong> （其他概率都是正数）。这 <strong>torch.triu()</strong> 函数返回作为参数传递的 2D 张量的上三角部分，因此它会为我们做屏蔽：",l,c,w;return c=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:"scores = np.triu(scores)",wrap:!1}}),{c(){e=T("p"),e.innerHTML=r,l=i(),M(c.$$.fragment)},l(f){e=d(f,"P",{"data-svelte-h":!0}),U(e)!=="svelte-7xs919"&&(e.innerHTML=r),l=m(f),J(c.$$.fragment,f)},m(f,j){a(f,e,j),a(f,l,j),y(c,f,j),w=!0},i(f){w||(o(c.$$.fragment,f),w=!0)},o(f){p(c.$$.fragment,f),w=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function Xa(b){let e,r="然后我们将屏蔽这些值 <strong>start_index &gt; end_index</strong> 通过将它们设置为 <strong>0</strong> （其他概率都是正数）。这 <strong>torch.triu()</strong> 函数返回作为参数传递的 2D 张量的上三角部分，因此它会为我们做屏蔽：",l,c,w;return c=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBc2NvcmVzJTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMp",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

scores = torch.triu(scores)`,wrap:!1}}),{c(){e=T("p"),e.innerHTML=r,l=i(),M(c.$$.fragment)},l(f){e=d(f,"P",{"data-svelte-h":!0}),U(e)!=="svelte-7xs919"&&(e.innerHTML=r),l=m(f),J(c.$$.fragment,f)},m(f,j){a(f,e,j),a(f,l,j),y(c,f,j),w=!0},i(f){w||(o(c.$$.fragment,f),w=!0)},o(f){p(c.$$.fragment,f),w=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function za(b){let e,r="✏️ <strong>试试看!</strong> 计算五个最可能的答案的开始和结束索引。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1xkmtwz"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Qa(b){let e,r="✏️ <strong>试试看!</strong> 使用您之前计算的最佳分数来显示五个最可能的答案。要检查您的结果，请返回到第一个管道并在调用它时传入。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-73o6zb"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Ha(b){let e,r,l,c;return e=new h({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}}),l=new h({props:{code:"KDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(e.$$.fragment),r=i(),M(l.$$.fragment)},l(w){J(e.$$.fragment,w),r=m(w),J(l.$$.fragment,w)},m(w,f){y(e,w,f),a(w,r,f),y(l,w,f),c=!0},i(w){c||(o(e.$$.fragment,w),o(l.$$.fragment,w),c=!0)},o(w){p(e.$$.fragment,w),p(l.$$.fragment,w),c=!1},d(w){w&&n(r),u(e,w),u(l,w)}}}function Ea(b){let e,r,l,c;return e=new h({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}}),l=new h({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(e.$$.fragment),r=i(),M(l.$$.fragment)},l(w){J(e.$$.fragment,w),r=m(w),J(l.$$.fragment,w)},m(w,f){y(e,w,f),a(w,r,f),y(l,w,f),c=!0},i(w){c||(o(e.$$.fragment,w),o(l.$$.fragment,w),c=!0)},o(w){p(e.$$.fragment,w),p(l.$$.fragment,w),c=!1},d(w){w&&n(r),u(e,w),u(l,w)}}}function Ya(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Fa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Sa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Aa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function qa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function La(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Da(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Pa(b){let e,r;return e=new h({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(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ka(b){let e,r="✏️ <strong>试试看!</strong> 修改上面的代码以返回五个最可能的答案的分数和跨度（总计，而不是每个块）。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1jaj12o"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Oa(b){let e,r="✏️ <strong>试试看!</strong> 使用您之前计算的最佳分数来显示五个最可能的答案（对于整个上下文，而不是每个块）。要检查您的结果，请返回到第一个管道并在调用它时传入。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1rmiqat"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function tr(b){let e,r,l,c,w,f,j,Ol,$,k,Wl,mt,Ls="我们现在将深入研究 <strong>question-answering</strong> 管道，看看如何利用偏移量从上下文中获取手头问题的答案，有点像我们在上一节中对分组实体所做的。然后我们将看到我们如何处理最终被截断的非常长的上下文。如果您对问答任务不感兴趣，可以跳过此部分。",te,v,G,Rl,pt,le,ot,Ds='正如我们在<a href="/course/chapter1">Chapter 1</a>，我们可以使用 <strong>question-answering</strong> 像这样的管道以获得问题的答案：',ee,ct,se,Mt,ne,Jt,Ps="与其他管道不同，它不能截断和拆分长于模型接受的最大长度的文本（因此可能会丢失文档末尾的信息），此管道可以处理非常长的上下文，并将返回回答这个问题，即使它在最后：",ae,yt,re,ut,ie,bt,Ks="让我们看看它是如何做到这一切的！",me,wt,pe,Tt,Os='与任何其他管道一样，我们首先对输入进行标记化，然后通过模型将其发送。默认情况下用于的检查点 <strong>question-answering</strong> 管道是<a href="https://huggingface.co/distilbert-base-cased-distilled-squad" rel="nofollow">distilbert-base-cased-distilled-squad</a>（名称中的“squad”来自模型微调的数据集；我们将在<a href="/course/chapter7/7">Chapter 7</a>):',oe,C,x,Nl,dt,tn="请注意，我们将问题和上下文标记为一对，首先是问题",ce,lt,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"/>',Me,ht,en="问答模型的工作方式与我们迄今为止看到的模型略有不同。以上图为例，该模型已经过训练，可以预测答案开始的标记的索引（此处为 21）和答案结束处的标记的索引（此处为 24）。这就是为什么这些模型不返回一个 logits 的张量，而是返回两个：一个用于对应于答案的开始标记的 logits，另一个用于对应于答案的结束标记的 logits。由于在这种情况下我们只有一个包含 66 个标记的输入，我们得到：",Je,Ut,ye,W,R,Vl,ft,sn="为了将这些 logits 转换为概率，我们将应用一个 softmax 函数——但在此之前，我们需要确保我们屏蔽了不属于上下文的索引。我们的输入是 <strong>[CLS] question [SEP] context [SEP]</strong> ，所以我们需要屏蔽问题的标记以及 <strong>[SEP]</strong> 令牌。我们将保留 <strong>[CLS]</strong> 然而，因为某些模型使用它来表示答案不在上下文中。",ue,jt,nn="由于我们将在之后应用 softmax，我们只需要用一个大的负数替换我们想要屏蔽的 logits。在这里，我们使用 <strong>-10000</strong> ：",be,N,V,Xl,It,an="现在我们已经正确屏蔽了与我们不想预测的位置相对应的 logits，我们可以应用 softmax：",we,X,z,zl,_t,rn="在这个阶段，我们可以采用开始和结束概率的 argmax——但我们最终可能会得到一个大于结束索引的开始索引，所以我们需要采取更多的预防措施。我们将计算每个可能的概率 <strong>start_index</strong> 和 <strong>end_index</strong> 在哪里 <strong>start_index &lt;= end_index</strong> ，然后取元组 <strong>(start_index, end_index)</strong> 以最高的概率。",Te,I,ks,Ql,mn="start_index",vs,Hl,pn="end_index",Gs,El,on="start_index",Cs,Yl,cn="end_index",xs,de,wa='<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>',he,O,Ws,Ue,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>',fe,Fl,Mn="start_index <= end_index",Rs,je,gt,Jn="首先让我们计算所有可能的产品：",Ie,Bt,_e,Q,H,Sl,Zt,yn="现在我们只需要得到最大值的索引。由于 PyTorch 将返回展平张量中的索引，因此我们需要使用地板除法 <strong>//</strong> 和模数 <strong>%</strong> 操作以获得 <strong>start_index</strong> 和 <strong>end_index</strong> ：",ge,$t,Be,kt,un="我们还没有完全完成，但至少我们已经有了正确的答案分数（您可以通过将其与上一节中的第一个结果进行比较来检查这一点）：",Ze,vt,$e,et,ke,Gt,bn="我们有 <strong>start_index</strong> 和 <strong>end_index</strong> 就标记而言的答案，所以现在我们只需要转换为上下文中的字符索引。这是偏移量非常有用的地方。我们可以像在令牌分类任务中一样抓住它们并使用它们：",ve,Ct,Ge,xt,wn="现在我们只需要格式化所有内容以获得我们的结果：",Ce,Wt,xe,Rt,We,Nt,Tn="太棒了！这和我们的第一个例子一样！",Re,st,Ne,Vt,Ve,Xt,dn="如果我们尝试对我们之前作为示例使用的问题和长上下文进行标记化，我们将获得比在 <strong>question-answering</strong> 管道（即 384）：",Xe,zt,ze,Qt,Qe,Ht,hn="因此，我们需要在最大长度处截断我们的输入。有几种方法可以做到这一点，但我们不想截断问题，只想截断上下文。由于上下文是第二个句子，我们将使用 <strong>“only_second”</strong> 截断策略。那么出现的问题是问题的答案可能不在截断上下文中。例如，在这里，我们选择了一个答案在上下文末尾的问题，当我们截断它时，答案不存在",He,Et,Ee,Yt,Ye,Ft,Un="这意味着模型将很难选择正确的答案。为了解决这个问题， <strong>question-answering</strong> 管道允许我们将上下文分成更小的块，指定最大长度。为确保我们不会在完全错误的位置拆分上下文以找到答案，它还包括块之间的一些重叠。",Fe,St,fn="我们可以让分词器（快或慢）通过添加来为我们做这件事 <strong>return_overflowing_tokens=True</strong> ，我们可以指定我们想要的重叠 <strong>stride</strong> 争论。这是一个使用较小句子的示例：",Se,At,Ae,qt,qe,Lt,jn="正如我们所看到的，句子已被分成多个块，使得每个条目 <strong>inputs[“input_ids”]</strong> 最多有 6 个标记（我们需要添加填充以使最后一个条目与其他条目的大小相同）并且每个条目之间有 2 个标记的重叠。",Le,Dt,In="让我们仔细看看标记化的结果：",De,Pt,Pe,Kt,Ke,Ot,_n="正如预期的那样，我们得到了输入 ID 和一个注意力掩码。最后一个键， <strong>overflow_to_sample_mapping</strong> , 是一个映射，它告诉我们每个结果对应哪个句子——这里我们有 7 个结果，它们都来自我们通过标记器的（唯一）句子：",Oe,tl,ts,ll,ls,el,gn="当我们将几个句子标记在一起时，这更有用。例如，这个：",es,sl,ss,nl,Bn="让我们：",ns,al,as,rl,Zn="这意味着第一个句子像以前一样分成 7 个块，接下来的 4 个块来自第二个句子。",rs,il,$n="现在让我们回到我们的长期背景。默认情况下 <strong>question-answering</strong> 管道使用的最大长度为 384，正如我们之前提到的，步长为 128，这对应于模型微调的方式（您可以通过传递 <strong>max_seq_len</strong> 和 <strong>stride</strong> 调用管道时的参数）。因此，我们将在标记化时使用这些参数。我们还将添加填充（具有相同长度的样本，因此我们可以构建张量）以及请求偏移量：",is,ml,ms,pl,kn="那些 <strong>inputs</strong> 将包含模型期望的输入 ID 和注意力掩码，以及偏移量和 <strong>overflow_to_sample_mapping</strong> 我们刚刚谈到。由于这两个不是模型使用的参数，我们将把它们从 <strong>inputs</strong> （我们不会存储地图，因为它在这里没有用）在将其转换为张量之前：",ps,E,Y,Al,ol,vn="我们的长上下文被分成两部分，这意味着在它通过我们的模型后，我们将有两组开始和结束 logits：",os,cl,cs,F,S,ql,Ml,Gn="和以前一样，我们在采用 softmax 之前首先屏蔽不属于上下文的标记。我们还屏蔽了所有填充标记（由注意掩码标记）：",Ms,A,q,Ll,Jl,Cn="然后我们可以使用 softmax 将我们的 logits 转换为概率：",Js,L,D,Dl,yl,xn="下一步与我们对小上下文所做的类似，但我们对两个块中的每一个都重复它。我们将分数归因于所有可能的答案跨度，然后取得分最高的跨度：",ys,P,K,Pl,ul,us,bl,Wn="这两个候选对应于模型能够在每个块中找到的最佳答案。该模型对正确答案在第二部分更有信心（这是一个好兆头！）。现在我们只需要将这两个标记跨度映射到上下文中的字符跨度（我们只需要映射第二个标记以获得我们的答案，但看看模型在第一个块中选择了什么很有趣）。",bs,nt,ws,wl,Rn="这 <strong>offsets</strong> 我们之前抓取的实际上是一个偏移量列表，每个文本块有一个列表：",Ts,Tl,ds,dl,hs,hl,Nn="如果我们忽略第一个结果，我们会得到与这个长上下文的管道相同的结果——是的！",Us,at,fs,Ul,Vn="我们对分词器功能的深入研究到此结束。我们将在下一章再次将所有这些付诸实践，届时我们将向您展示如何在一系列常见的 NLP 任务上微调模型。",js,fl,Is,Kl,_s;w=new Ia({props:{fw:b[0]}}),j=new Zs({props:{title:"QA 管道中的快速标记器",local:"QA 管道中的快速标记器",headingTag:"h1"}});const Xn=[Ba,ga],jl=[];function zn(t,s){return t[0]==="pt"?0:1}$=zn(b),k=jl[$]=Xn[$](b);const Qn=[$a,Za],Il=[];function Hn(t,s){return t[0]==="pt"?0:1}v=Hn(b),G=Il[v]=Qn[v](b),pt=new Zs({props:{title:"使用 question-answering 管道",local:"使用 question-answering 管道",headingTag:"h2"}}),ct=new h({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}}),Mt=new h({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}}),yt=new h({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTIwcHJvdmlkZXMlMjBBUElzJTIwdG8lMjBxdWlja2x5JTIwZG93bmxvYWQlMjBhbmQlMjB1c2UlMjB0aG9zZSUyMHByZXRyYWluZWQlMjBtb2RlbHMlMjBvbiUyMGElMjBnaXZlbiUyMHRleHQlMkMlMjBmaW5lLXR1bmUlMjB0aGVtJTIwb24lMjB5b3VyJTIwb3duJTIwZGF0YXNldHMlMjBhbmQlMEF0aGVuJTIwc2hhcmUlMjB0aGVtJTIwd2l0aCUyMHRoZSUyMGNvbW11bml0eSUyMG9uJTIwb3VyJTIwbW9kZWwlMjBodWIuJTIwQXQlMjB0aGUlMjBzYW1lJTIwdGltZSUyQyUyMGVhY2glMjBweXRob24lMjBtb2R1bGUlMjBkZWZpbmluZyUyMGFuJTIwYXJjaGl0ZWN0dXJlJTIwaXMlMjBmdWxseSUyMHN0YW5kYWxvbmUlMjBhbmQlMEFjYW4lMjBiZSUyMG1vZGlmaWVkJTIwdG8lMjBlbmFibGUlMjBxdWljayUyMHJlc2VhcmNoJTIwZXhwZXJpbWVudHMuJTBBJTBBV2h5JTIwc2hvdWxkJTIwSSUyMHVzZSUyMHRyYW5zZm9ybWVycyUzRiUwQSUwQTEuJTIwRWFzeS10by11c2UlMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTNBJTBBJTIwJTIwLSUyMEhpZ2glMjBwZXJmb3JtYW5jZSUyMG9uJTIwTkxVJTIwYW5kJTIwTkxHJTIwdGFza3MuJTBBJTIwJTIwLSUyMExvdyUyMGJhcnJpZXIlMjB0byUyMGVudHJ5JTIwZm9yJTIwZWR1Y2F0b3JzJTIwYW5kJTIwcHJhY3RpdGlvbmVycy4lMEElMjAlMjAtJTIwRmV3JTIwdXNlci1mYWNpbmclMjBhYnN0cmFjdGlvbnMlMjB3aXRoJTIwanVzdCUyMHRocmVlJTIwY2xhc3NlcyUyMHRvJTIwbGVhcm4uJTBBJTIwJTIwLSUyMEElMjB1bmlmaWVkJTIwQVBJJTIwZm9yJTIwdXNpbmclMjBhbGwlMjBvdXIlMjBwcmV0cmFpbmVkJTIwbW9kZWxzLiUwQSUyMCUyMC0lMjBMb3dlciUyMGNvbXB1dGUlMjBjb3N0cyUyQyUyMHNtYWxsZXIlMjBjYXJib24lMjBmb290cHJpbnQlM0ElMEElMEEyLiUyMFJlc2VhcmNoZXJzJTIwY2FuJTIwc2hhcmUlMjB0cmFpbmVkJTIwbW9kZWxzJTIwaW5zdGVhZCUyMG9mJTIwYWx3YXlzJTIwcmV0cmFpbmluZy4lMEElMjAlMjAtJTIwUHJhY3RpdGlvbmVycyUyMGNhbiUyMHJlZHVjZSUyMGNvbXB1dGUlMjB0aW1lJTIwYW5kJTIwcHJvZHVjdGlvbiUyMGNvc3RzLiUwQSUyMCUyMC0lMjBEb3plbnMlMjBvZiUyMGFyY2hpdGVjdHVyZXMlMjB3aXRoJTIwb3ZlciUyMDEwJTJDMDAwJTIwcHJldHJhaW5lZCUyMG1vZGVscyUyQyUyMHNvbWUlMjBpbiUyMG1vcmUlMjB0aGFuJTIwMTAwJTIwbGFuZ3VhZ2VzLiUwQSUwQTMuJTIwQ2hvb3NlJTIwdGhlJTIwcmlnaHQlMjBmcmFtZXdvcmslMjBmb3IlMjBldmVyeSUyMHBhcnQlMjBvZiUyMGElMjBtb2RlbCdzJTIwbGlmZXRpbWUlM0ElMEElMjAlMjAtJTIwVHJhaW4lMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTIwaW4lMjAzJTIwbGluZXMlMjBvZiUyMGNvZGUuJTBBJTIwJTIwLSUyME1vdmUlMjBhJTIwc2luZ2xlJTIwbW9kZWwlMjBiZXR3ZWVuJTIwVEYyLjAlMkZQeVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFscyUyMGFyZSUyMGV4cG9zZWQlMjBhcyUyMGNvbnNpc3RlbnRseSUyMGFzJTIwcG9zc2libGUuJTBBJTIwJTIwLSUyME1vZGVsJTIwZmlsZXMlMjBjYW4lMjBiZSUyMHVzZWQlMjBpbmRlcGVuZGVudGx5JTIwb2YlMjB0aGUlMjBsaWJyYXJ5JTIwZm9yJTIwcXVpY2slMjBleHBlcmltZW50cy4lMEElMEElRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlMjBpcyUyMGJhY2tlZCUyMGJ5JTIwdGhlJTIwdGhyZWUlMjBtb3N0JTIwcG9wdWxhciUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMCVFMiU4MCU5NCUyMEpheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",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}}),ut=new h({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}}),wt=new Zs({props:{title:"使用模型进行问答",local:"使用模型进行问答",headingTag:"h2"}});const En=[va,ka],_l=[];function Yn(t,s){return t[0]==="pt"?0:1}C=Yn(b),x=_l[C]=En[C](b),Ut=new h({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 Fn=[Ca,Ga],gl=[];function Sn(t,s){return t[0]==="pt"?0:1}W=Sn(b),R=gl[W]=Fn[W](b);const An=[Wa,xa],Bl=[];function qn(t,s){return t[0]==="pt"?0:1}N=qn(b),V=Bl[N]=An[N](b);const Ln=[Na,Ra],Zl=[];function Dn(t,s){return t[0]==="pt"?0:1}X=Dn(b),z=Zl[X]=Ln[X](b),Bt=new h({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],$l=[];function Kn(t,s){return t[0]==="pt"?0:1}Q=Kn(b),H=$l[Q]=Pn[Q](b),$t=new h({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}}),vt=new h({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),et=new Bs({props:{$$slots:{default:[za]},$$scope:{ctx:b}}}),Ct=new h({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}}),Wt=new h({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}}),Rt=new h({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}}),st=new Bs({props:{$$slots:{default:[Qa]},$$scope:{ctx:b}}}),Vt=new Zs({props:{title:"处理长上下文",local:"处理长上下文",headingTag:"h2"}}),zt=new h({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}}),Qt=new h({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Et=new h({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}}),Yt=new h({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU1RCUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwcHJvdmlkZXMlMjBBUElzJTIwdG8lMjBxdWlja2x5JTIwZG93bmxvYWQlMjBhbmQlMjB1c2UlMjB0aG9zZSUyMHByZXRyYWluZWQlMjBtb2RlbHMlMjBvbiUyMGElMjBnaXZlbiUyMHRleHQlMkMlMjBmaW5lLXR1bmUlMjB0aGVtJTIwb24lMjB5b3VyJTIwb3duJTIwZGF0YXNldHMlMjBhbmQlMEF0aGVuJTIwc2hhcmUlMjB0aGVtJTIwd2l0aCUyMHRoZSUyMGNvbW11bml0eSUyMG9uJTIwb3VyJTIwbW9kZWwlMjBodWIuJTIwQXQlMjB0aGUlMjBzYW1lJTIwdGltZSUyQyUyMGVhY2glMjBweXRob24lMjBtb2R1bGUlMjBkZWZpbmluZyUyMGFuJTIwYXJjaGl0ZWN0dXJlJTIwaXMlMjBmdWxseSUyMHN0YW5kYWxvbmUlMjBhbmQlMEFjYW4lMjBiZSUyMG1vZGlmaWVkJTIwdG8lMjBlbmFibGUlMjBxdWljayUyMHJlc2VhcmNoJTIwZXhwZXJpbWVudHMuJTBBJTBBV2h5JTIwc2hvdWxkJTIwSSUyMHVzZSUyMHRyYW5zZm9ybWVycyUzRiUwQSUwQTEuJTIwRWFzeS10by11c2UlMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTNBJTBBJTIwJTIwLSUyMEhpZ2glMjBwZXJmb3JtYW5jZSUyMG9uJTIwTkxVJTIwYW5kJTIwTkxHJTIwdGFza3MuJTBBJTIwJTIwLSUyMExvdyUyMGJhcnJpZXIlMjB0byUyMGVudHJ5JTIwZm9yJTIwZWR1Y2F0b3JzJTIwYW5kJTIwcHJhY3RpdGlvbmVycy4lMEElMjAlMjAtJTIwRmV3JTIwdXNlci1mYWNpbmclMjBhYnN0cmFjdGlvbnMlMjB3aXRoJTIwanVzdCUyMHRocmVlJTIwY2xhc3NlcyUyMHRvJTIwbGVhcm4uJTBBJTIwJTIwLSUyMEElMjB1bmlmaWVkJTIwQVBJJTIwZm9yJTIwdXNpbmclMjBhbGwlMjBvdXIlMjBwcmV0cmFpbmVkJTIwbW9kZWxzLiUwQSUyMCUyMC0lMjBMb3dlciUyMGNvbXB1dGUlMjBjb3N0cyUyQyUyMHNtYWxsZXIlMjBjYXJib24lMjBmb290cHJpbnQlM0ElMEElMEEyLiUyMFJlc2VhcmNoZXJzJTIwY2FuJTIwc2hhcmUlMjB0cmFpbmVkJTIwbW9kZWxzJTIwaW5zdGVhZCUyMG9mJTIwYWx3YXlzJTIwcmV0cmFpbmluZy4lMEElMjAlMjAtJTIwUHJhY3RpdGlvbmVycyUyMGNhbiUyMHJlZHVjZSUyMGNvbXB1dGUlMjB0aW1lJTIwYW5kJTIwcHJvZHVjdGlvbiUyMGNvc3RzLiUwQSUyMCUyMC0lMjBEb3plbnMlMjBvZiUyMGFyY2hpdGVjdHVyZXMlMjB3aXRoJTIwb3ZlciUyMDEwJTJDMDAwJTIwcHJldHJhaW5lZCUyMG1vZGVscyUyQyUyMHNvbWUlMjBpbiUyMG1vcmUlMjB0aGFuJTIwMTAwJTIwbGFuZ3VhZ2VzLiUwQSUwQTMuJTIwQ2hvb3NlJTIwdGhlJTIwcmlnaHQlMjBmcmFtZXdvcmslMjBmb3IlMjBldmVyeSUyMHBhcnQlMjBvZiUyMGElMjBtb2RlbCdzJTIwbGlmZXRpbWUlM0ElMEElMjAlMjAtJTIwVHJhaW4lMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTIwaW4lMjAzJTIwbGluZXMlMjBvZiUyMGNvZGUuJTBBJTIwJTIwLSUyME1vdmUlMjBhJTIwc2luZ2xlJTIwbW9kZWwlMjBiZXR3ZWVuJTIwVEYyLjAlMkZQeVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",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}}),At=new h({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}}),qt=new h({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}}),Pt=new h({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Kt=new h({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}}),tl=new h({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}}),ll=new h({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}}),sl=new h({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}}),al=new h({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}}),ml=new h({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,Ha],kl=[];function ta(t,s){return t[0]==="pt"?0:1}E=ta(b),Y=kl[E]=On[E](b),cl=new h({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=[Fa,Ya],vl=[];function ea(t,s){return t[0]==="pt"?0:1}F=ea(b),S=vl[F]=la[F](b);const sa=[Aa,Sa],Gl=[];function na(t,s){return t[0]==="pt"?0:1}A=na(b),q=Gl[A]=sa[A](b);const aa=[La,qa],Cl=[];function ra(t,s){return t[0]==="pt"?0:1}L=ra(b),D=Cl[L]=aa[L](b);const ia=[Pa,Da],xl=[];function ma(t,s){return t[0]==="pt"?0:1}return P=ma(b),K=xl[P]=ia[P](b),ul=new h({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}}),nt=new Bs({props:{$$slots:{default:[Ka]},$$scope:{ctx:b}}}),Tl=new h({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}}),dl=new h({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}}),at=new Bs({props:{$$slots:{default:[Oa]},$$scope:{ctx:b}}}),fl=new _a({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter6/3b.mdx"}}),{c(){e=T("meta"),r=i(),l=T("p"),c=i(),M(w.$$.fragment),f=i(),M(j.$$.fragment),Ol=i(),k.c(),Wl=i(),mt=T("p"),mt.innerHTML=Ls,te=i(),G.c(),Rl=i(),M(pt.$$.fragment),le=i(),ot=T("p"),ot.innerHTML=Ds,ee=i(),M(ct.$$.fragment),se=i(),M(Mt.$$.fragment),ne=i(),Jt=T("p"),Jt.textContent=Ps,ae=i(),M(yt.$$.fragment),re=i(),M(ut.$$.fragment),ie=i(),bt=T("p"),bt.textContent=Ks,me=i(),M(wt.$$.fragment),pe=i(),Tt=T("p"),Tt.innerHTML=Os,oe=i(),x.c(),Nl=i(),dt=T("p"),dt.textContent=tn,ce=i(),lt=T("div"),lt.innerHTML=ln,Me=i(),ht=T("p"),ht.textContent=en,Je=i(),M(Ut.$$.fragment),ye=i(),R.c(),Vl=i(),ft=T("p"),ft.innerHTML=sn,ue=i(),jt=T("p"),jt.innerHTML=nn,be=i(),V.c(),Xl=i(),It=T("p"),It.textContent=an,we=i(),z.c(),zl=i(),_t=T("p"),_t.innerHTML=rn,Te=i(),I=T("p"),ks=rt("假设事件“答案开始于 "),Ql=T("strong"),Ql.textContent=mn,vs=rt(" ”和“答案结束于 "),Hl=T("strong"),Hl.textContent=pn,Gs=rt(" ” 要独立，答案开始于的概率 "),El=T("strong"),El.textContent=on,Cs=rt(" 并结束于 "),Yl=T("strong"),Yl.textContent=cn,xs=rt(` 是：
`),de=new Ja(!1),he=i(),O=T("p"),Ws=rt("所以，要计算所有的分数，我们只需要计算所有的产品"),Ue=new Ja(!1),fe=rt(" where "),Fl=T("code"),Fl.textContent=Mn,Rs=rt("."),je=i(),gt=T("p"),gt.textContent=Jn,Ie=i(),M(Bt.$$.fragment),_e=i(),H.c(),Sl=i(),Zt=T("p"),Zt.innerHTML=yn,ge=i(),M($t.$$.fragment),Be=i(),kt=T("p"),kt.textContent=un,Ze=i(),M(vt.$$.fragment),$e=i(),M(et.$$.fragment),ke=i(),Gt=T("p"),Gt.innerHTML=bn,ve=i(),M(Ct.$$.fragment),Ge=i(),xt=T("p"),xt.textContent=wn,Ce=i(),M(Wt.$$.fragment),xe=i(),M(Rt.$$.fragment),We=i(),Nt=T("p"),Nt.textContent=Tn,Re=i(),M(st.$$.fragment),Ne=i(),M(Vt.$$.fragment),Ve=i(),Xt=T("p"),Xt.innerHTML=dn,Xe=i(),M(zt.$$.fragment),ze=i(),M(Qt.$$.fragment),Qe=i(),Ht=T("p"),Ht.innerHTML=hn,He=i(),M(Et.$$.fragment),Ee=i(),M(Yt.$$.fragment),Ye=i(),Ft=T("p"),Ft.innerHTML=Un,Fe=i(),St=T("p"),St.innerHTML=fn,Se=i(),M(At.$$.fragment),Ae=i(),M(qt.$$.fragment),qe=i(),Lt=T("p"),Lt.innerHTML=jn,Le=i(),Dt=T("p"),Dt.textContent=In,De=i(),M(Pt.$$.fragment),Pe=i(),M(Kt.$$.fragment),Ke=i(),Ot=T("p"),Ot.innerHTML=_n,Oe=i(),M(tl.$$.fragment),ts=i(),M(ll.$$.fragment),ls=i(),el=T("p"),el.textContent=gn,es=i(),M(sl.$$.fragment),ss=i(),nl=T("p"),nl.textContent=Bn,ns=i(),M(al.$$.fragment),as=i(),rl=T("p"),rl.textContent=Zn,rs=i(),il=T("p"),il.innerHTML=$n,is=i(),M(ml.$$.fragment),ms=i(),pl=T("p"),pl.innerHTML=kn,ps=i(),Y.c(),Al=i(),ol=T("p"),ol.textContent=vn,os=i(),M(cl.$$.fragment),cs=i(),S.c(),ql=i(),Ml=T("p"),Ml.textContent=Gn,Ms=i(),q.c(),Ll=i(),Jl=T("p"),Jl.textContent=Cn,Js=i(),D.c(),Dl=i(),yl=T("p"),yl.textContent=xn,ys=i(),K.c(),Pl=i(),M(ul.$$.fragment),us=i(),bl=T("p"),bl.textContent=Wn,bs=i(),M(nt.$$.fragment),ws=i(),wl=T("p"),wl.innerHTML=Rn,Ts=i(),M(Tl.$$.fragment),ds=i(),M(dl.$$.fragment),hs=i(),hl=T("p"),hl.textContent=Nn,Us=i(),M(at.$$.fragment),fs=i(),Ul=T("p"),Ul.textContent=Vn,js=i(),M(fl.$$.fragment),Is=i(),Kl=T("p"),this.h()},l(t){const s=ja("svelte-u9bgzb",document.head);e=d(s,"META",{name:!0,content:!0}),s.forEach(n),r=m(t),l=d(t,"P",{}),gs(l).forEach(n),c=m(t),J(w.$$.fragment,t),f=m(t),J(j.$$.fragment,t),Ol=m(t),k.l(t),Wl=m(t),mt=d(t,"P",{"data-svelte-h":!0}),U(mt)!=="svelte-1tbjo9v"&&(mt.innerHTML=Ls),te=m(t),G.l(t),Rl=m(t),J(pt.$$.fragment,t),le=m(t),ot=d(t,"P",{"data-svelte-h":!0}),U(ot)!=="svelte-1upsgwc"&&(ot.innerHTML=Ds),ee=m(t),J(ct.$$.fragment,t),se=m(t),J(Mt.$$.fragment,t),ne=m(t),Jt=d(t,"P",{"data-svelte-h":!0}),U(Jt)!=="svelte-svnm9x"&&(Jt.textContent=Ps),ae=m(t),J(yt.$$.fragment,t),re=m(t),J(ut.$$.fragment,t),ie=m(t),bt=d(t,"P",{"data-svelte-h":!0}),U(bt)!=="svelte-18mamau"&&(bt.textContent=Ks),me=m(t),J(wt.$$.fragment,t),pe=m(t),Tt=d(t,"P",{"data-svelte-h":!0}),U(Tt)!=="svelte-1o7v1j5"&&(Tt.innerHTML=Os),oe=m(t),x.l(t),Nl=m(t),dt=d(t,"P",{"data-svelte-h":!0}),U(dt)!=="svelte-1qv8wnk"&&(dt.textContent=tn),ce=m(t),lt=d(t,"DIV",{class:!0,"data-svelte-h":!0}),U(lt)!=="svelte-47wedv"&&(lt.innerHTML=ln),Me=m(t),ht=d(t,"P",{"data-svelte-h":!0}),U(ht)!=="svelte-17mwifa"&&(ht.textContent=en),Je=m(t),J(Ut.$$.fragment,t),ye=m(t),R.l(t),Vl=m(t),ft=d(t,"P",{"data-svelte-h":!0}),U(ft)!=="svelte-1i5e5rd"&&(ft.innerHTML=sn),ue=m(t),jt=d(t,"P",{"data-svelte-h":!0}),U(jt)!=="svelte-1wfxj0f"&&(jt.innerHTML=nn),be=m(t),V.l(t),Xl=m(t),It=d(t,"P",{"data-svelte-h":!0}),U(It)!=="svelte-12rww1s"&&(It.textContent=an),we=m(t),z.l(t),zl=m(t),_t=d(t,"P",{"data-svelte-h":!0}),U(_t)!=="svelte-1qu7wvu"&&(_t.innerHTML=rn),Te=m(t),I=d(t,"P",{});var _=gs(I);ks=it(_,"假设事件“答案开始于 "),Ql=d(_,"STRONG",{"data-svelte-h":!0}),U(Ql)!=="svelte-mrepff"&&(Ql.textContent=mn),vs=it(_," ”和“答案结束于 "),Hl=d(_,"STRONG",{"data-svelte-h":!0}),U(Hl)!=="svelte-wrb9ic"&&(Hl.textContent=pn),Gs=it(_," ” 要独立，答案开始于的概率 "),El=d(_,"STRONG",{"data-svelte-h":!0}),U(El)!=="svelte-mrepff"&&(El.textContent=on),Cs=it(_," 并结束于 "),Yl=d(_,"STRONG",{"data-svelte-h":!0}),U(Yl)!=="svelte-wrb9ic"&&(Yl.textContent=cn),xs=it(_,` 是：
`),de=ya(_,!1),_.forEach(n),he=m(t),O=d(t,"P",{});var tt=gs(O);Ws=it(tt,"所以，要计算所有的分数，我们只需要计算所有的产品"),Ue=ya(tt,!1),fe=it(tt," where "),Fl=d(tt,"CODE",{"data-svelte-h":!0}),U(Fl)!=="svelte-1kp3szf"&&(Fl.textContent=Mn),Rs=it(tt,"."),tt.forEach(n),je=m(t),gt=d(t,"P",{"data-svelte-h":!0}),U(gt)!=="svelte-ftdz7x"&&(gt.textContent=Jn),Ie=m(t),J(Bt.$$.fragment,t),_e=m(t),H.l(t),Sl=m(t),Zt=d(t,"P",{"data-svelte-h":!0}),U(Zt)!=="svelte-1t216q2"&&(Zt.innerHTML=yn),ge=m(t),J($t.$$.fragment,t),Be=m(t),kt=d(t,"P",{"data-svelte-h":!0}),U(kt)!=="svelte-9hgb6t"&&(kt.textContent=un),Ze=m(t),J(vt.$$.fragment,t),$e=m(t),J(et.$$.fragment,t),ke=m(t),Gt=d(t,"P",{"data-svelte-h":!0}),U(Gt)!=="svelte-184lypu"&&(Gt.innerHTML=bn),ve=m(t),J(Ct.$$.fragment,t),Ge=m(t),xt=d(t,"P",{"data-svelte-h":!0}),U(xt)!=="svelte-12e1hz5"&&(xt.textContent=wn),Ce=m(t),J(Wt.$$.fragment,t),xe=m(t),J(Rt.$$.fragment,t),We=m(t),Nt=d(t,"P",{"data-svelte-h":!0}),U(Nt)!=="svelte-1wn9ewg"&&(Nt.textContent=Tn),Re=m(t),J(st.$$.fragment,t),Ne=m(t),J(Vt.$$.fragment,t),Ve=m(t),Xt=d(t,"P",{"data-svelte-h":!0}),U(Xt)!=="svelte-ga1uja"&&(Xt.innerHTML=dn),Xe=m(t),J(zt.$$.fragment,t),ze=m(t),J(Qt.$$.fragment,t),Qe=m(t),Ht=d(t,"P",{"data-svelte-h":!0}),U(Ht)!=="svelte-1mcfr5m"&&(Ht.innerHTML=hn),He=m(t),J(Et.$$.fragment,t),Ee=m(t),J(Yt.$$.fragment,t),Ye=m(t),Ft=d(t,"P",{"data-svelte-h":!0}),U(Ft)!=="svelte-ujphot"&&(Ft.innerHTML=Un),Fe=m(t),St=d(t,"P",{"data-svelte-h":!0}),U(St)!=="svelte-nlzi6h"&&(St.innerHTML=fn),Se=m(t),J(At.$$.fragment,t),Ae=m(t),J(qt.$$.fragment,t),qe=m(t),Lt=d(t,"P",{"data-svelte-h":!0}),U(Lt)!=="svelte-1eker3k"&&(Lt.innerHTML=jn),Le=m(t),Dt=d(t,"P",{"data-svelte-h":!0}),U(Dt)!=="svelte-yo8d2q"&&(Dt.textContent=In),De=m(t),J(Pt.$$.fragment,t),Pe=m(t),J(Kt.$$.fragment,t),Ke=m(t),Ot=d(t,"P",{"data-svelte-h":!0}),U(Ot)!=="svelte-16m89ny"&&(Ot.innerHTML=_n),Oe=m(t),J(tl.$$.fragment,t),ts=m(t),J(ll.$$.fragment,t),ls=m(t),el=d(t,"P",{"data-svelte-h":!0}),U(el)!=="svelte-1hadpyl"&&(el.textContent=gn),es=m(t),J(sl.$$.fragment,t),ss=m(t),nl=d(t,"P",{"data-svelte-h":!0}),U(nl)!=="svelte-1f5xeog"&&(nl.textContent=Bn),ns=m(t),J(al.$$.fragment,t),as=m(t),rl=d(t,"P",{"data-svelte-h":!0}),U(rl)!=="svelte-1ezwa6u"&&(rl.textContent=Zn),rs=m(t),il=d(t,"P",{"data-svelte-h":!0}),U(il)!=="svelte-1gccsc8"&&(il.innerHTML=$n),is=m(t),J(ml.$$.fragment,t),ms=m(t),pl=d(t,"P",{"data-svelte-h":!0}),U(pl)!=="svelte-i2sfi8"&&(pl.innerHTML=kn),ps=m(t),Y.l(t),Al=m(t),ol=d(t,"P",{"data-svelte-h":!0}),U(ol)!=="svelte-17bzs4c"&&(ol.textContent=vn),os=m(t),J(cl.$$.fragment,t),cs=m(t),S.l(t),ql=m(t),Ml=d(t,"P",{"data-svelte-h":!0}),U(Ml)!=="svelte-kds8xc"&&(Ml.textContent=Gn),Ms=m(t),q.l(t),Ll=m(t),Jl=d(t,"P",{"data-svelte-h":!0}),U(Jl)!=="svelte-1fxln2y"&&(Jl.textContent=Cn),Js=m(t),D.l(t),Dl=m(t),yl=d(t,"P",{"data-svelte-h":!0}),U(yl)!=="svelte-10oaiq0"&&(yl.textContent=xn),ys=m(t),K.l(t),Pl=m(t),J(ul.$$.fragment,t),us=m(t),bl=d(t,"P",{"data-svelte-h":!0}),U(bl)!=="svelte-16im3pb"&&(bl.textContent=Wn),bs=m(t),J(nt.$$.fragment,t),ws=m(t),wl=d(t,"P",{"data-svelte-h":!0}),U(wl)!=="svelte-10y8f2p"&&(wl.innerHTML=Rn),Ts=m(t),J(Tl.$$.fragment,t),ds=m(t),J(dl.$$.fragment,t),hs=m(t),hl=d(t,"P",{"data-svelte-h":!0}),U(hl)!=="svelte-1uevfap"&&(hl.textContent=Nn),Us=m(t),J(at.$$.fragment,t),fs=m(t),Ul=d(t,"P",{"data-svelte-h":!0}),U(Ul)!=="svelte-1z05zjj"&&(Ul.textContent=Vn),js=m(t),J(fl.$$.fragment,t),Is=m(t),Kl=d(t,"P",{}),gs(Kl).forEach(n),this.h()},h(){qs(e,"name","hf:doc:metadata"),qs(e,"content",lr),qs(lt,"class","flex justify-center"),de.a=null,Ue.a=fe},m(t,s){g(document.head,e),a(t,r,s),a(t,l,s),a(t,c,s),y(w,t,s),a(t,f,s),y(j,t,s),a(t,Ol,s),jl[$].m(t,s),a(t,Wl,s),a(t,mt,s),a(t,te,s),Il[v].m(t,s),a(t,Rl,s),y(pt,t,s),a(t,le,s),a(t,ot,s),a(t,ee,s),y(ct,t,s),a(t,se,s),y(Mt,t,s),a(t,ne,s),a(t,Jt,s),a(t,ae,s),y(yt,t,s),a(t,re,s),y(ut,t,s),a(t,ie,s),a(t,bt,s),a(t,me,s),y(wt,t,s),a(t,pe,s),a(t,Tt,s),a(t,oe,s),_l[C].m(t,s),a(t,Nl,s),a(t,dt,s),a(t,ce,s),a(t,lt,s),a(t,Me,s),a(t,ht,s),a(t,Je,s),y(Ut,t,s),a(t,ye,s),gl[W].m(t,s),a(t,Vl,s),a(t,ft,s),a(t,ue,s),a(t,jt,s),a(t,be,s),Bl[N].m(t,s),a(t,Xl,s),a(t,It,s),a(t,we,s),Zl[X].m(t,s),a(t,zl,s),a(t,_t,s),a(t,Te,s),a(t,I,s),g(I,ks),g(I,Ql),g(I,vs),g(I,Hl),g(I,Gs),g(I,El),g(I,Cs),g(I,Yl),g(I,xs),de.m(wa,I),a(t,he,s),a(t,O,s),g(O,Ws),Ue.m(Ta,O),g(O,fe),g(O,Fl),g(O,Rs),a(t,je,s),a(t,gt,s),a(t,Ie,s),y(Bt,t,s),a(t,_e,s),$l[Q].m(t,s),a(t,Sl,s),a(t,Zt,s),a(t,ge,s),y($t,t,s),a(t,Be,s),a(t,kt,s),a(t,Ze,s),y(vt,t,s),a(t,$e,s),y(et,t,s),a(t,ke,s),a(t,Gt,s),a(t,ve,s),y(Ct,t,s),a(t,Ge,s),a(t,xt,s),a(t,Ce,s),y(Wt,t,s),a(t,xe,s),y(Rt,t,s),a(t,We,s),a(t,Nt,s),a(t,Re,s),y(st,t,s),a(t,Ne,s),y(Vt,t,s),a(t,Ve,s),a(t,Xt,s),a(t,Xe,s),y(zt,t,s),a(t,ze,s),y(Qt,t,s),a(t,Qe,s),a(t,Ht,s),a(t,He,s),y(Et,t,s),a(t,Ee,s),y(Yt,t,s),a(t,Ye,s),a(t,Ft,s),a(t,Fe,s),a(t,St,s),a(t,Se,s),y(At,t,s),a(t,Ae,s),y(qt,t,s),a(t,qe,s),a(t,Lt,s),a(t,Le,s),a(t,Dt,s),a(t,De,s),y(Pt,t,s),a(t,Pe,s),y(Kt,t,s),a(t,Ke,s),a(t,Ot,s),a(t,Oe,s),y(tl,t,s),a(t,ts,s),y(ll,t,s),a(t,ls,s),a(t,el,s),a(t,es,s),y(sl,t,s),a(t,ss,s),a(t,nl,s),a(t,ns,s),y(al,t,s),a(t,as,s),a(t,rl,s),a(t,rs,s),a(t,il,s),a(t,is,s),y(ml,t,s),a(t,ms,s),a(t,pl,s),a(t,ps,s),kl[E].m(t,s),a(t,Al,s),a(t,ol,s),a(t,os,s),y(cl,t,s),a(t,cs,s),vl[F].m(t,s),a(t,ql,s),a(t,Ml,s),a(t,Ms,s),Gl[A].m(t,s),a(t,Ll,s),a(t,Jl,s),a(t,Js,s),Cl[L].m(t,s),a(t,Dl,s),a(t,yl,s),a(t,ys,s),xl[P].m(t,s),a(t,Pl,s),y(ul,t,s),a(t,us,s),a(t,bl,s),a(t,bs,s),y(nt,t,s),a(t,ws,s),a(t,wl,s),a(t,Ts,s),y(Tl,t,s),a(t,ds,s),y(dl,t,s),a(t,hs,s),a(t,hl,s),a(t,Us,s),y(at,t,s),a(t,fs,s),a(t,Ul,s),a(t,js,s),y(fl,t,s),a(t,Is,s),a(t,Kl,s),_s=!0},p(t,[s]){const _={};s&1&&(_.fw=t[0]),w.$set(_);let tt=$;$=zn(t),$!==tt&&(Z(),p(jl[tt],1,1,()=>{jl[tt]=null}),B(),k=jl[$],k||(k=jl[$]=Xn[$](t),k.c()),o(k,1),k.m(Wl.parentNode,Wl));let Ns=v;v=Hn(t),v!==Ns&&(Z(),p(Il[Ns],1,1,()=>{Il[Ns]=null}),B(),G=Il[v],G||(G=Il[v]=Qn[v](t),G.c()),o(G,1),G.m(Rl.parentNode,Rl));let Vs=C;C=Yn(t),C!==Vs&&(Z(),p(_l[Vs],1,1,()=>{_l[Vs]=null}),B(),x=_l[C],x||(x=_l[C]=En[C](t),x.c()),o(x,1),x.m(Nl.parentNode,Nl));let Xs=W;W=Sn(t),W!==Xs&&(Z(),p(gl[Xs],1,1,()=>{gl[Xs]=null}),B(),R=gl[W],R||(R=gl[W]=Fn[W](t),R.c()),o(R,1),R.m(Vl.parentNode,Vl));let zs=N;N=qn(t),N!==zs&&(Z(),p(Bl[zs],1,1,()=>{Bl[zs]=null}),B(),V=Bl[N],V||(V=Bl[N]=An[N](t),V.c()),o(V,1),V.m(Xl.parentNode,Xl));let Qs=X;X=Dn(t),X!==Qs&&(Z(),p(Zl[Qs],1,1,()=>{Zl[Qs]=null}),B(),z=Zl[X],z||(z=Zl[X]=Ln[X](t),z.c()),o(z,1),z.m(zl.parentNode,zl));let Hs=Q;Q=Kn(t),Q!==Hs&&(Z(),p($l[Hs],1,1,()=>{$l[Hs]=null}),B(),H=$l[Q],H||(H=$l[Q]=Pn[Q](t),H.c()),o(H,1),H.m(Sl.parentNode,Sl));const pa={};s&2&&(pa.$$scope={dirty:s,ctx:t}),et.$set(pa);const oa={};s&2&&(oa.$$scope={dirty:s,ctx:t}),st.$set(oa);let Es=E;E=ta(t),E!==Es&&(Z(),p(kl[Es],1,1,()=>{kl[Es]=null}),B(),Y=kl[E],Y||(Y=kl[E]=On[E](t),Y.c()),o(Y,1),Y.m(Al.parentNode,Al));let Ys=F;F=ea(t),F!==Ys&&(Z(),p(vl[Ys],1,1,()=>{vl[Ys]=null}),B(),S=vl[F],S||(S=vl[F]=la[F](t),S.c()),o(S,1),S.m(ql.parentNode,ql));let Fs=A;A=na(t),A!==Fs&&(Z(),p(Gl[Fs],1,1,()=>{Gl[Fs]=null}),B(),q=Gl[A],q||(q=Gl[A]=sa[A](t),q.c()),o(q,1),q.m(Ll.parentNode,Ll));let Ss=L;L=ra(t),L!==Ss&&(Z(),p(Cl[Ss],1,1,()=>{Cl[Ss]=null}),B(),D=Cl[L],D||(D=Cl[L]=aa[L](t),D.c()),o(D,1),D.m(Dl.parentNode,Dl));let As=P;P=ma(t),P!==As&&(Z(),p(xl[As],1,1,()=>{xl[As]=null}),B(),K=xl[P],K||(K=xl[P]=ia[P](t),K.c()),o(K,1),K.m(Pl.parentNode,Pl));const ca={};s&2&&(ca.$$scope={dirty:s,ctx:t}),nt.$set(ca);const Ma={};s&2&&(Ma.$$scope={dirty:s,ctx:t}),at.$set(Ma)},i(t){_s||(o(w.$$.fragment,t),o(j.$$.fragment,t),o(k),o(G),o(pt.$$.fragment,t),o(ct.$$.fragment,t),o(Mt.$$.fragment,t),o(yt.$$.fragment,t),o(ut.$$.fragment,t),o(wt.$$.fragment,t),o(x),o(Ut.$$.fragment,t),o(R),o(V),o(z),o(Bt.$$.fragment,t),o(H),o($t.$$.fragment,t),o(vt.$$.fragment,t),o(et.$$.fragment,t),o(Ct.$$.fragment,t),o(Wt.$$.fragment,t),o(Rt.$$.fragment,t),o(st.$$.fragment,t),o(Vt.$$.fragment,t),o(zt.$$.fragment,t),o(Qt.$$.fragment,t),o(Et.$$.fragment,t),o(Yt.$$.fragment,t),o(At.$$.fragment,t),o(qt.$$.fragment,t),o(Pt.$$.fragment,t),o(Kt.$$.fragment,t),o(tl.$$.fragment,t),o(ll.$$.fragment,t),o(sl.$$.fragment,t),o(al.$$.fragment,t),o(ml.$$.fragment,t),o(Y),o(cl.$$.fragment,t),o(S),o(q),o(D),o(K),o(ul.$$.fragment,t),o(nt.$$.fragment,t),o(Tl.$$.fragment,t),o(dl.$$.fragment,t),o(at.$$.fragment,t),o(fl.$$.fragment,t),_s=!0)},o(t){p(w.$$.fragment,t),p(j.$$.fragment,t),p(k),p(G),p(pt.$$.fragment,t),p(ct.$$.fragment,t),p(Mt.$$.fragment,t),p(yt.$$.fragment,t),p(ut.$$.fragment,t),p(wt.$$.fragment,t),p(x),p(Ut.$$.fragment,t),p(R),p(V),p(z),p(Bt.$$.fragment,t),p(H),p($t.$$.fragment,t),p(vt.$$.fragment,t),p(et.$$.fragment,t),p(Ct.$$.fragment,t),p(Wt.$$.fragment,t),p(Rt.$$.fragment,t),p(st.$$.fragment,t),p(Vt.$$.fragment,t),p(zt.$$.fragment,t),p(Qt.$$.fragment,t),p(Et.$$.fragment,t),p(Yt.$$.fragment,t),p(At.$$.fragment,t),p(qt.$$.fragment,t),p(Pt.$$.fragment,t),p(Kt.$$.fragment,t),p(tl.$$.fragment,t),p(ll.$$.fragment,t),p(sl.$$.fragment,t),p(al.$$.fragment,t),p(ml.$$.fragment,t),p(Y),p(cl.$$.fragment,t),p(S),p(q),p(D),p(K),p(ul.$$.fragment,t),p(nt.$$.fragment,t),p(Tl.$$.fragment,t),p(dl.$$.fragment,t),p(at.$$.fragment,t),p(fl.$$.fragment,t),_s=!1},d(t){t&&(n(r),n(l),n(c),n(f),n(Ol),n(Wl),n(mt),n(te),n(Rl),n(le),n(ot),n(ee),n(se),n(ne),n(Jt),n(ae),n(re),n(ie),n(bt),n(me),n(pe),n(Tt),n(oe),n(Nl),n(dt),n(ce),n(lt),n(Me),n(ht),n(Je),n(ye),n(Vl),n(ft),n(ue),n(jt),n(be),n(Xl),n(It),n(we),n(zl),n(_t),n(Te),n(I),n(he),n(O),n(je),n(gt),n(Ie),n(_e),n(Sl),n(Zt),n(ge),n(Be),n(kt),n(Ze),n($e),n(ke),n(Gt),n(ve),n(Ge),n(xt),n(Ce),n(xe),n(We),n(Nt),n(Re),n(Ne),n(Ve),n(Xt),n(Xe),n(ze),n(Qe),n(Ht),n(He),n(Ee),n(Ye),n(Ft),n(Fe),n(St),n(Se),n(Ae),n(qe),n(Lt),n(Le),n(Dt),n(De),n(Pe),n(Ke),n(Ot),n(Oe),n(ts),n(ls),n(el),n(es),n(ss),n(nl),n(ns),n(as),n(rl),n(rs),n(il),n(is),n(ms),n(pl),n(ps),n(Al),n(ol),n(os),n(cs),n(ql),n(Ml),n(Ms),n(Ll),n(Jl),n(Js),n(Dl),n(yl),n(ys),n(Pl),n(us),n(bl),n(bs),n(ws),n(wl),n(Ts),n(ds),n(hs),n(hl),n(Us),n(fs),n(Ul),n(js),n(Is),n(Kl)),n(e),u(w,t),u(j,t),jl[$].d(t),Il[v].d(t),u(pt,t),u(ct,t),u(Mt,t),u(yt,t),u(ut,t),u(wt,t),_l[C].d(t),u(Ut,t),gl[W].d(t),Bl[N].d(t),Zl[X].d(t),u(Bt,t),$l[Q].d(t),u($t,t),u(vt,t),u(et,t),u(Ct,t),u(Wt,t),u(Rt,t),u(st,t),u(Vt,t),u(zt,t),u(Qt,t),u(Et,t),u(Yt,t),u(At,t),u(qt,t),u(Pt,t),u(Kt,t),u(tl,t),u(ll,t),u(sl,t),u(al,t),u(ml,t),kl[E].d(t),u(cl,t),vl[F].d(t),Gl[A].d(t),Cl[L].d(t),xl[P].d(t),u(ul,t),u(nt,t),u(Tl,t),u(dl,t),u(at,t),u(fl,t)}}}const lr='{"title":"QA 管道中的快速标记器","local":"QA 管道中的快速标记器","sections":[{"title":"使用 question-answering 管道","local":"使用 question-answering 管道","sections":[],"depth":2},{"title":"使用模型进行问答","local":"使用模型进行问答","sections":[],"depth":2},{"title":"处理长上下文","local":"处理长上下文","sections":[],"depth":2}],"depth":1}';function er(b,e,r){let l="pt";return ha(()=>{const c=new URLSearchParams(window.location.search);r(0,l=c.get("fw")||"pt")}),[l]}class cr extends Ua{constructor(e){super(),fa(this,e,er,tr,da,{})}}export{cr as component};
