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