import{s as oa,o as Ma,n as Is}from"../chunks/scheduler.37c15a92.js";import{S as Ja,i as ya,g as b,s as r,r as M,m as Le,H as ua,A as da,h as U,f as n,c as p,j as Es,u as J,x as f,n as De,E as Ta,k as Hs,y as O,a,v as y,t as m,b as k,d as c,w as u,p as B}from"../chunks/index.2bf4358c.js";import{T as hs}from"../chunks/Tip.363c041f.js";import{Y as pa}from"../chunks/Youtube.1e50a667.js";import{C as w}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as ma}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as ba}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as js,E as Ua}from"../chunks/EditOnGithub.8916dc7c.js";function wa(d){let t,i;return t=new ma({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function fa(d){let t,i;return t=new ma({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function ha(d){let t,i;return t=new pa({props:{id:"b3u8RzBCX9Y"}}),{c(){M(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function ja(d){let t,i;return t=new pa({props:{id:"_wxyB3j3mk4"}}),{c(){M(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ia(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function _a(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function ka(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ba(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function $a(d){let t,i;return t=new w({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjAlRTUlQjElOEYlRTglOTQlQkQlRTklOTklQTQlMjBjb250ZXh0JTIwJUU0JUI5JThCJUU1JUE0JTk2JUU3JTlBJTg0JUU2JTg5JTgwJUU2JTlDJTg5JUU1JTg2JTg1JUU1JUFFJUI5JTBBbWFzayUyMCUzRCUyMCU1QmklMjAhJTNEJTIwMSUyMGZvciUyMGklMjBpbiUyMHNlcXVlbmNlX2lkcyU1RCUwQSUyMyUyMCVFNCVCOCU4RCVFNSVCMSU4RiVFOCU5NCVCRCUyMCU1QkNMUyU1RCUyMHRva2VuJTBBbWFzayU1QjAlNUQlMjAlM0QlMjBGYWxzZSUwQW1hc2slMjAlM0QlMjB0Zi5jb25zdGFudChtYXNrKSU1Qk5vbmUlNUQlMEElMEFzdGFydF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwc3RhcnRfbG9naXRzKSUwQWVuZF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwZW5kX2xvZ2l0cyk=",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># 屏蔽除 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"># 不屏蔽 [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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Za(d){let t,i;return t=new w({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjAlRTUlQjElOEYlRTglOTQlQkQlRTklOTklQTQlMjBjb250ZXh0JTIwJUU0JUI5JThCJUU1JUE0JTk2JUU3JTlBJTg0JUU2JTg5JTgwJUU2JTlDJTg5JUU1JTg2JTg1JUU1JUFFJUI5JTBBbWFzayUyMCUzRCUyMCU1QmklMjAhJTNEJTIwMSUyMGZvciUyMGklMjBpbiUyMHNlcXVlbmNlX2lkcyU1RCUwQSUyMyUyMCVFNCVCOCU4RCVFNSVCMSU4RiVFOCU5NCVCRCUyMCU1QkNMUyU1RCUyMHRva2VuJTBBbWFzayU1QjAlNUQlMjAlM0QlMjBGYWxzZSUwQW1hc2slMjAlM0QlMjB0b3JjaC50ZW5zb3IobWFzayklNUJOb25lJTVEJTBBJTBBc3RhcnRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMCUwQWVuZF9sb2dpdHMlNUJtYXNrJTVEJTIwJTNEJTIwLTEwMDAw",highlighted:`<span class="hljs-keyword">import</span> torch

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># 屏蔽除 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"># 不屏蔽 [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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ca(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function ga(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ga(d){let t,i="然后我们将 <code>start_index &gt; end_index</code> 的值设置为 <code>0</code> 来屏蔽他们（其他概率都是正数）。 <code>np.triu()</code> 函数返回传入的 2D 张量的上三角部分，所以我们做可以使用它来完成屏蔽：",e,o,T;return o=new w({props:{code:"c2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:"scores = np.triu(scores)",wrap:!1}}),{c(){t=b("p"),t.innerHTML=i,e=r(),M(o.$$.fragment)},l(h){t=U(h,"P",{"data-svelte-h":!0}),f(t)!=="svelte-1qbkfuh"&&(t.innerHTML=i),e=p(h),J(o.$$.fragment,h)},m(h,j){a(h,t,j),a(h,e,j),y(o,h,j),T=!0},i(h){T||(c(o.$$.fragment,h),T=!0)},o(h){m(o.$$.fragment,h),T=!1},d(h){h&&(n(t),n(e)),u(o,h)}}}function Na(d){let t,i="然后我们将 <code>start_index &gt; end_index</code> 的值设置为 <code>0</code> 来屏蔽他们（其他概率都是正数）。 <code>torch.triu()</code> 函数返回传入的 2D 张量的上三角部分，所以我们可以使用它来完成屏蔽：",e,o,T;return o=new w({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(){t=b("p"),t.innerHTML=i,e=r(),M(o.$$.fragment)},l(h){t=U(h,"P",{"data-svelte-h":!0}),f(t)!=="svelte-1iaandt"&&(t.innerHTML=i),e=p(h),J(o.$$.fragment,h)},m(h,j){a(h,t,j),a(h,e,j),y(o,h,j),T=!0},i(h){T||(c(o.$$.fragment,h),T=!0)},o(h){m(o.$$.fragment,h),T=!1},d(h){h&&(n(t),n(e)),u(o,h)}}}function xa(d){let t,i="✏️ <strong>试试看！</strong> 计算五个最可能的答案的开始和结束索引。";return{c(){t=b("p"),t.innerHTML=i},l(e){t=U(e,"P",{"data-svelte-h":!0}),f(t)!=="svelte-1k4r1lf"&&(t.innerHTML=i)},m(e,o){a(e,t,o)},p:Is,d(e){e&&n(t)}}}function Va(d){let t,i="✏️ <strong>试试看！</strong> 使用你之前计算的最佳分数来显示五个最可能的答案。你可以回到之前的 QA pipeline，并在调用时传入 <code>top_k=5</code> 来对比检查你的结果。";return{c(){t=b("p"),t.innerHTML=i},l(e){t=U(e,"P",{"data-svelte-h":!0}),f(t)!=="svelte-pwms1g"&&(t.innerHTML=i)},m(e,o){a(e,t,o)},p:Is,d(e){e&&n(t)}}}function Ra(d){let t,i,e,o;return t=new w({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}}),e=new w({props:{code:"KDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(t.$$.fragment),i=r(),M(e.$$.fragment)},l(T){J(t.$$.fragment,T),i=p(T),J(e.$$.fragment,T)},m(T,h){y(t,T,h),a(T,i,h),y(e,T,h),o=!0},i(T){o||(c(t.$$.fragment,T),c(e.$$.fragment,T),o=!0)},o(T){m(t.$$.fragment,T),m(e.$$.fragment,T),o=!1},d(T){T&&n(i),u(t,T),u(e,T)}}}function Wa(d){let t,i,e,o;return t=new w({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}}),e=new w({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(t.$$.fragment),i=r(),M(e.$$.fragment)},l(T){J(t.$$.fragment,T),i=p(T),J(e.$$.fragment,T)},m(T,h){y(t,T,h),a(T,i,h),y(e,T,h),o=!0},i(T){o||(c(t.$$.fragment,T),c(e.$$.fragment,T),o=!0)},o(T){m(t.$$.fragment,T),m(e.$$.fragment,T),o=!1},d(T){T&&n(i),u(t,T),u(e,T)}}}function va(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Qa(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Xa(d){let t,i;return t=new w({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwJUU1JUIxJThGJUU4JTk0JUJEJUU5JTk5JUE0JTIwY29udGV4dCUyMHRva2VucyUyMCVFNCVCOSU4QiVFNSVBNCU5NiVFNyU5QSU4NCVFNiU4OSU4MCVFNiU5QyU4OSVFNSU4NiU4NSVFNSVBRSVCOSUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjAlRTUlOEYlOTYlRTYlQjYlODglRTUlQUYlQjklMjAlNUJDTFMlNUQlMjB0b2tlbiVFNyU5QSU4NCVFNSVCMSU4RiVFOCU5NCVCRCUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEElMjMlMjAlRTUlQjElOEYlRTglOTQlQkQlRTYlODklODAlRTYlOUMlODklRTclOUElODQlMjAlNUJQQUQlNUQlMjB0b2tlbnMlMEFtYXNrJTIwJTNEJTIwdGYubWF0aC5sb2dpY2FsX29yKHRmLmNvbnN0YW50KG1hc2spJTVCTm9uZSU1RCUyQyUyMGlucHV0cyU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTIwJTNEJTNEJTIwMCklMEElMEFzdGFydF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwc3RhcnRfbG9naXRzKSUwQWVuZF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwZW5kX2xvZ2l0cyk=",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># 屏蔽除 context tokens 之外的所有内容</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"># 取消对 [CLS] token的屏蔽</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># 屏蔽所有的 [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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function za(d){let t,i;return t=new w({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwJUU1JUIxJThGJUU4JTk0JUJEJUU5JTk5JUE0JTIwY29udGV4dCUyMHRva2VucyUyMCVFNCVCOSU4QiVFNSVBNCU5NiVFNyU5QSU4NCVFNiU4OSU4MCVFNiU5QyU4OSVFNSU4NiU4NSVFNSVBRSVCOSUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjAlRTUlOEYlOTYlRTYlQjYlODglRTUlQUYlQjklMjAlNUJDTFMlNUQlMjB0b2tlbiUyMCVFNyU5QSU4NCVFNSVCMSU4RiVFOCU5NCVCRCUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEElMjMlMjAlRTUlQjElOEYlRTglOTQlQkQlRTYlODklODAlRTYlOUMlODklRTclOUElODQlMjAlNUJQQUQlNUQlMjB0b2tlbnMlMEFtYXNrJTIwJTNEJTIwdG9yY2gubG9naWNhbF9vcih0b3JjaC50ZW5zb3IobWFzayklNUJOb25lJTVEJTJDJTIwKGlucHV0cyU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTIwJTNEJTNEJTIwMCkpJTBBJTBBc3RhcnRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMCUwQWVuZF9sb2dpdHMlNUJtYXNrJTVEJTIwJTNEJTIwLTEwMDAw",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># 屏蔽除 context tokens 之外的所有内容</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"># 取消对 [CLS] token 的屏蔽</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># 屏蔽所有的 [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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ea(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ha(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Fa(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Ya(d){let t,i;return t=new w({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(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,o){y(t,e,o),i=!0},i(e){i||(c(t.$$.fragment,e),i=!0)},o(e){m(t.$$.fragment,e),i=!1},d(e){u(t,e)}}}function Sa(d){let t,i="✏️ <strong>试试看！</strong>  调整上面的代码，以返回五个最可能的答案的得分和范围（对于整个上下文，而不是单个块）。";return{c(){t=b("p"),t.innerHTML=i},l(e){t=U(e,"P",{"data-svelte-h":!0}),f(t)!=="svelte-pkywgj"&&(t.innerHTML=i)},m(e,o){a(e,t,o)},p:Is,d(e){e&&n(t)}}}function Aa(d){let t,i="✏️ <strong>试试看！</strong> 使用你之前计算的最佳分数来显示五个最可能的答案（对于整个上下文，而不是单个块）。如果想要与 pipeline 对比检查你的结果的话，返回之前的 QA 管道，并在调用时传入 <code>top_k=5</code> 的参数。";return{c(){t=b("p"),t.innerHTML=i},l(e){t=U(e,"P",{"data-svelte-h":!0}),f(t)!=="svelte-y38dk2"&&(t.innerHTML=i)},m(e,o){a(e,t,o)},p:Is,d(e){e&&n(t)}}}function qa(d){let t,i,e,o,T,h,j,Pe,$,Z,Ge,nl,Fs="我们现在将深入研究 <code>question-answering</code> 管道，看看如何利用偏移量从上下文（context）中获取当前问题的答案，这与我们在上一节中处理分组实体的方式有些相似。我们会看到如何处理那些因为过长而最终被截断的上下文（context）。如果你对问答任务不感兴趣，可以跳过这一节。",Oe,C,g,Ne,al,Ke,il,Ys='正如我们在 <a href="/course/chapter1">第一章</a> ，我们可以使用 <code>question-answering</code> 像这样的管道以获得问题的答案：',lt,rl,et,pl,tt,ml,Ss="与其他不能处理超过模型接受的最大长度的文本的管道不同，这个管道可以处理非常长的上下文（context），并且即使答案在末尾也能返回问题的答案：",st,cl,nt,ol,at,Ml,As="让我们看看它是如何做到这一点的！",it,Jl,rt,yl,qs='与任何其他管道一样，我们首先对输入进行 tokenize，然后将其传入模型。 <code>question-answering</code> 管道默认情况下用于的 checkpoint 是 <a href="https://huggingface.co/distilbert-base-cased-distilled-squad" rel="nofollow">distilbert-base-cased-distilled-squad</a> （名字中的”squad”源自模型微调所用的数据集；我们将在 <a href="/course/chapter7/7">第七章</a> 详细讨论 SQuAD 数据集）:',pt,G,N,xe,ul,Ls="请注意在这里，我们将问题放在前面和上下文放后面，一起作为一对进行tokenization。",mt,K,Ds='<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"/>',ct,dl,Ps="问答模型的工作方式与我们迄今为止看到的模型略有不同。以上图为例，模型训练的目标是来预测答案开始的 token 的索引（这里是 21）和答案结束的 token 的索引（这里是 24）。这就是为什么这些模型不返回一个 logits 的张量，而是返回两个：一个对应于答案的开始 token 的 logits，另一个对应于答案的结束 token 的 logits。在这个例子中，我们的输入包含了 66 个 token ，因此我们得到：",ot,Tl,Mt,x,V,Ve,bl,Os="为了将这些 logits 转换为概率，我们将使用一个 softmax 函数——但在此之前，我们需要确保我们屏蔽了不属于上下文的索引。我们的输入格式是 <code>[CLS] question [SEP] context [SEP]</code> ，所以我们需要屏蔽 question 的 tokens 以及 <code>[SEP]</code>  token 。不过，我们将保留 <code>[CLS]</code> ，因为某些模型使用它来表示答案不在上下文中。",Jt,Ul,Ks="由于我们将在之后使用 softmax，我们只需要将我们想要屏蔽的 logits 替换为一个大的负数就可以在计算 softmax 的时候屏蔽他们。在这里，我们使用 <code>-10000</code> ：",yt,R,W,Re,wl,ln="现在我们已经屏蔽了与我们不想预测的位置相对应的 logits，接下来我们可以使用 softmax：",ut,v,Q,We,fl,en="在这个阶段，我们可以取开始和结束概率的 argmax —— 但是我们可能会得到一个比结束索引大的开始索引，因此我们需要采取一些更多的措施来处理这些特殊情况。我们将在满足 <code>start_index &lt;= end_index</code> 的前提下计算每个可能的 <code>start_index</code> 和 <code>end_index</code> 的概率，然后取概率最高的 <code>(start_index, end_index)</code> 元组。",dt,I,_s,ve,tn="start_index",ks,Qe,sn="end_index",Bs,Xe,nn="start_index",$s,ze,an="end_index",Zs,Tt,ca='<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>',bt,hl,rn="所以，要计算所有的分数，我们只需要计算所有的 <code>start_index &lt;= end_index</code> 的 ($$\\mathrm{start_probabilities}[\\mathrm{start_index}] \\times\\mathrm{end_probabilities}[\\mathrm{end_index}]$$)  的乘积。",Ut,jl,pn="首先让我们计算所有可能的乘积：",wt,Il,ft,X,z,Ee,_l,mn="现在我们只需要得到最大值的索引。由于 PyTorch 将返回展平（flattened）后张量中的索引，因此我们需要使用向下取整的除法 <code>//</code> 和取模 <code>%</code> 操作来获得 <code>start_index</code> 和 <code>end_index</code> ：",ht,kl,jt,Bl,cn="我们还没有完全完成，但至少我们已经有了正确的答案分数（你可以通过将其与上一节中的第一个结果进行比较来检查这一点）：",It,$l,_t,ll,kt,Zl,on="我们有了答案的 <code>start_index</code> 和 <code>end_index</code> ，所以现在我们只需要将他们转换为上下文中的字符索引。这就是偏移量将会非常有用的地方。我们可以像我们在 token 分类任务中那样获取偏移量并使用它们：",Bt,Cl,$t,gl,Mn="现在我们只需要格式化所有内容，获取我们的结果：",Zt,Gl,Ct,Nl,gt,xl,Jn="太棒了！这和我们上面获取的结果一样！",Gt,el,Nt,Vl,xt,Rl,yn="如果我们尝试将我们之前使用的长问题和长上下文进行 tokenize，我们将得到一个比 <code>question-answering</code> pipeline 中使用的最大长度（384）更大的 tokens 数量：",Vt,Wl,Rt,vl,Wt,Ql,un="所以，我们需要将我们的输入截断到模型允许输入的最大长度。我们可以用几种方式做到这一点，但我们不想截断问题部分，只想截断上下文部分，并且由于上下文部分是第二项，因此我们将使用 <code>&quot;only_second&quot;</code> 截断策略。然后又出现了新的问题：问题的答案可能在截断后被丢弃了，并没有在截断后保留下来的上下文文本中。例如，我们选了一个问题，其中的答案在上下文的末尾，当我们截断它时，答案就不在里面了：",vt,Xl,Qt,zl,Xt,El,dn="这意味着模型将很难找到正确的答案。为了解决这个问题， <code>question-answering</code> 管道允许我们将上下文分成更小的块，指定最大长度。为了确保我们不在刚好可能找到答案的地方将上下文分割，它还在各块之间包含了一些重叠。",zt,Hl,Tn="我们可以通过添加 <code>return_overflowing_tokens=True</code> 参数，并可以用 <code>stride</code> 参数指定我们想要的重叠长度来让 tokenizer （快速或慢速）为我们做这个工作。下面是一个使用较短的句子的例子：",Et,Fl,Ht,Yl,Ft,Sl,bn="正如我们所看到的，句子已被分成多个块，使得每个条目 <code>inputs[&quot;input_ids&quot;]</code> 最多有 6 个 token （我们需要添加填充以使分割后的最后一个条目与其他条目的大小相同）并且每个条目之间有 2 个 token 的重叠。",Yt,Al,Un="让我们仔细看看tokenization的结果：",St,ql,At,Ll,qt,Dl,wn="正如我们所预期的，我们得到了inputs ID 和注意力掩码。最后一个键，overflow_to_sample_mapping，是一个映射，告诉我们每个结果对应哪个句子——在这里，我们有 7 个结果，它们都来自我们传递给 tokenizer 的（唯一的）句子：",Lt,Pl,Dt,Ol,Pt,Kl,fn="当我们一起对多个句子 tokenize 时，这会更有用。例如，这个：",Ot,le,Kt,ee,hn="输出的结果是：",ls,te,es,se,jn="这意味着第一句话被分割成 7 个块，就像上面的例子一样，后面的 4 个块来自第二句话。",ts,ne,In="现在让我们回到我们的长上下文。默认情况下， <code>question-answering pipeline</code> 使用我们之前提到的 384 作为最大长度，步长为 128，这与模型的微调方式相对应（你可以通过在调用 pipeline 时传递 <code>max_seq_len</code> 和 <code>stride</code> 参数来调整这些参数）。因此，我们在 tokenization 时将使用微调时使用的这些参数。我们还会添加填充（使样本具有相同的长度，这样我们就可以构建拼接成一个矩形的张量），并获取偏移量：",ss,ae,ns,ie,_n="这些 <code>inputs</code> 将包含模型期望的inputs ID 和注意力掩码，以及我们刚刚谈到的偏移量和 <code>overflow_to_sample_mapping</code> 。由于模型不需要这两个参数，我们将它们从 <code>inputs</code> 中删除（我们不会存储映射的字典，因为这在这里没有用）然后将 <code>inputs</code> 转换为张量：",as,E,H,He,re,kn="我们的长上下文被分成两部分，这意味着在经过我们的模型后，我们将得到两组开始和结束的 logits：",is,pe,rs,F,Y,Fe,me,Bn="和以前一样，我们在计算 softmax 之前屏蔽不属于上下文的 token 。我们还屏蔽了所有填充 token （如注意力掩码）：",ps,S,A,Ye,ce,$n="然后我们可以使用 softmax 将我们的 logits 转换为概率：",ms,q,L,Se,oe,Zn="下一步与我们对短的上下文所做的类似，但在这里我们将对两个块分别进行处理。我们为所有可能的回答范围赋予一个得分，然后选择得分最高的范围：",cs,D,P,Ae,Me,os,Je,Cn="这两个候选范围对应的是模型在每个块中能够找到的最好的答案。模型对于正确的答案在第二部分更有信心（这是个好兆头！）。现在我们只需要将这两个 token 范围映射到上下文中的字符范围（我们只需要映射第二个就能得到我们的答案，但是看看模型在第一块中选取了什么作为答案还是很有意思的）。",Ms,tl,Js,ye,gn="我们之前抓取 <code>offsets</code> 的实际上是一个偏移量列表，每个文本块都有一个列表：",ys,ue,us,de,ds,Te,Gn="如果我们选择分数最高的第二个结果，我们会得到与 QA 管道相同结果——耶！",Ts,sl,bs,be,Nn="我们已经结束了我们对 tokenizer 能力的深入探究。在下一章，我们将展示如何在一系列常见的 NLP 任务上微调模型，我们将对这些内容再次付诸实践。",Us,Ue,ws,qe,fs;T=new ba({props:{fw:d[0]}}),j=new js({props:{title:"在 QA 管道中使用快速 tokenizer",local:"在 QA 管道中使用快速 tokenizer",headingTag:"h1"}});const xn=[fa,wa],we=[];function Vn(l,s){return l[0]==="pt"?0:1}$=Vn(d),Z=we[$]=xn[$](d);const Rn=[ja,ha],fe=[];function Wn(l,s){return l[0]==="pt"?0:1}C=Wn(d),g=fe[C]=Rn[C](d),al=new js({props:{title:"使用 question-answering 管道",local:"使用 question-answering 管道",headingTag:"h2"}}),rl=new w({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}}),pl=new w({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}}),cl=new w({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xh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bG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",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}}),ol=new w({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}}),Jl=new js({props:{title:"使用模型进行问答",local:"使用模型进行问答",headingTag:"h2"}});const vn=[_a,Ia],he=[];function Qn(l,s){return l[0]==="pt"?0:1}G=Qn(d),N=he[G]=vn[G](d),Tl=new w({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 Xn=[Ba,ka],je=[];function zn(l,s){return l[0]==="pt"?0:1}x=zn(d),V=je[x]=Xn[x](d);const En=[Za,$a],Ie=[];function Hn(l,s){return l[0]==="pt"?0:1}R=Hn(d),W=Ie[R]=En[R](d);const Fn=[ga,Ca],_e=[];function Yn(l,s){return l[0]==="pt"?0:1}v=Yn(d),Q=_e[v]=Fn[v](d),Il=new w({props:{code:"c2NvcmVzJTIwJTNEJTIwc3RhcnRfcHJvYmFiaWxpdGllcyU1QiUzQSUyQyUyME5vbmUlNUQlMjAqJTIwZW5kX3Byb2JhYmlsaXRpZXMlNUJOb25lJTJDJTIwJTNBJTVE",highlighted:'scores = start_probabilities[:, <span class="hljs-literal">None</span>] * end_probabilities[<span class="hljs-literal">None</span>, :]',wrap:!1}});const Sn=[Na,Ga],ke=[];function An(l,s){return l[0]==="pt"?0:1}X=An(d),z=ke[X]=Sn[X](d),kl=new w({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}}),$l=new w({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),ll=new hs({props:{$$slots:{default:[xa]},$$scope:{ctx:d}}}),Cl=new w({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}}),Gl=new w({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}}),Nl=new w({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}}),el=new hs({props:{$$slots:{default:[Va]},$$scope:{ctx:d}}}),Vl=new js({props:{title:"处理长文本",local:"处理长文本",headingTag:"h2"}}),Wl=new w({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}}),vl=new w({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Xl=new w({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}}),zl=new w({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMj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XRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",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}}),Fl=new w({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}}),Yl=new w({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}}),ql=new w({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Ll=new w({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}}),Pl=new w({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}}),Ol=new w({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}}),le=new w({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}}),te=new w({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}}),ae=new w({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 qn=[Wa,Ra],Be=[];function Ln(l,s){return l[0]==="pt"?0:1}E=Ln(d),H=Be[E]=qn[E](d),pe=new w({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 Dn=[Qa,va],$e=[];function Pn(l,s){return l[0]==="pt"?0:1}F=Pn(d),Y=$e[F]=Dn[F](d);const On=[za,Xa],Ze=[];function Kn(l,s){return l[0]==="pt"?0:1}S=Kn(d),A=Ze[S]=On[S](d);const la=[Ha,Ea],Ce=[];function ea(l,s){return l[0]==="pt"?0:1}q=ea(d),L=Ce[q]=la[q](d);const ta=[Ya,Fa],ge=[];function sa(l,s){return l[0]==="pt"?0:1}return D=sa(d),P=ge[D]=ta[D](d),Me=new w({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}}),tl=new hs({props:{$$slots:{default:[Sa]},$$scope:{ctx:d}}}),ue=new w({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}}),de=new w({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}}),sl=new hs({props:{$$slots:{default:[Aa]},$$scope:{ctx:d}}}),Ue=new Ua({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter6/3b.mdx"}}),{c(){t=b("meta"),i=r(),e=b("p"),o=r(),M(T.$$.fragment),h=r(),M(j.$$.fragment),Pe=r(),Z.c(),Ge=r(),nl=b("p"),nl.innerHTML=Fs,Oe=r(),g.c(),Ne=r(),M(al.$$.fragment),Ke=r(),il=b("p"),il.innerHTML=Ys,lt=r(),M(rl.$$.fragment),et=r(),M(pl.$$.fragment),tt=r(),ml=b("p"),ml.textContent=Ss,st=r(),M(cl.$$.fragment),nt=r(),M(ol.$$.fragment),at=r(),Ml=b("p"),Ml.textContent=As,it=r(),M(Jl.$$.fragment),rt=r(),yl=b("p"),yl.innerHTML=qs,pt=r(),N.c(),xe=r(),ul=b("p"),ul.textContent=Ls,mt=r(),K=b("div"),K.innerHTML=Ds,ct=r(),dl=b("p"),dl.textContent=Ps,ot=r(),M(Tl.$$.fragment),Mt=r(),V.c(),Ve=r(),bl=b("p"),bl.innerHTML=Os,Jt=r(),Ul=b("p"),Ul.innerHTML=Ks,yt=r(),W.c(),Re=r(),wl=b("p"),wl.textContent=ln,ut=r(),Q.c(),We=r(),fl=b("p"),fl.innerHTML=en,dt=r(),I=b("p"),_s=Le("假设事件”答案开始于 "),ve=b("code"),ve.textContent=tn,ks=Le(" “和”答案结束于 "),Qe=b("code"),Qe.textContent=sn,Bs=Le(" “是独立的，答案在 "),Xe=b("code"),Xe.textContent=nn,$s=Le(" 开始并在 "),ze=b("code"),ze.textContent=an,Zs=Le(` 结束的概率是：
`),Tt=new ua(!1),bt=r(),hl=b("p"),hl.innerHTML=rn,Ut=r(),jl=b("p"),jl.textContent=pn,wt=r(),M(Il.$$.fragment),ft=r(),z.c(),Ee=r(),_l=b("p"),_l.innerHTML=mn,ht=r(),M(kl.$$.fragment),jt=r(),Bl=b("p"),Bl.textContent=cn,It=r(),M($l.$$.fragment),_t=r(),M(ll.$$.fragment),kt=r(),Zl=b("p"),Zl.innerHTML=on,Bt=r(),M(Cl.$$.fragment),$t=r(),gl=b("p"),gl.textContent=Mn,Zt=r(),M(Gl.$$.fragment),Ct=r(),M(Nl.$$.fragment),gt=r(),xl=b("p"),xl.textContent=Jn,Gt=r(),M(el.$$.fragment),Nt=r(),M(Vl.$$.fragment),xt=r(),Rl=b("p"),Rl.innerHTML=yn,Vt=r(),M(Wl.$$.fragment),Rt=r(),M(vl.$$.fragment),Wt=r(),Ql=b("p"),Ql.innerHTML=un,vt=r(),M(Xl.$$.fragment),Qt=r(),M(zl.$$.fragment),Xt=r(),El=b("p"),El.innerHTML=dn,zt=r(),Hl=b("p"),Hl.innerHTML=Tn,Et=r(),M(Fl.$$.fragment),Ht=r(),M(Yl.$$.fragment),Ft=r(),Sl=b("p"),Sl.innerHTML=bn,Yt=r(),Al=b("p"),Al.textContent=Un,St=r(),M(ql.$$.fragment),At=r(),M(Ll.$$.fragment),qt=r(),Dl=b("p"),Dl.textContent=wn,Lt=r(),M(Pl.$$.fragment),Dt=r(),M(Ol.$$.fragment),Pt=r(),Kl=b("p"),Kl.textContent=fn,Ot=r(),M(le.$$.fragment),Kt=r(),ee=b("p"),ee.textContent=hn,ls=r(),M(te.$$.fragment),es=r(),se=b("p"),se.textContent=jn,ts=r(),ne=b("p"),ne.innerHTML=In,ss=r(),M(ae.$$.fragment),ns=r(),ie=b("p"),ie.innerHTML=_n,as=r(),H.c(),He=r(),re=b("p"),re.textContent=kn,is=r(),M(pe.$$.fragment),rs=r(),Y.c(),Fe=r(),me=b("p"),me.textContent=Bn,ps=r(),A.c(),Ye=r(),ce=b("p"),ce.textContent=$n,ms=r(),L.c(),Se=r(),oe=b("p"),oe.textContent=Zn,cs=r(),P.c(),Ae=r(),M(Me.$$.fragment),os=r(),Je=b("p"),Je.textContent=Cn,Ms=r(),M(tl.$$.fragment),Js=r(),ye=b("p"),ye.innerHTML=gn,ys=r(),M(ue.$$.fragment),us=r(),M(de.$$.fragment),ds=r(),Te=b("p"),Te.textContent=Gn,Ts=r(),M(sl.$$.fragment),bs=r(),be=b("p"),be.textContent=Nn,Us=r(),M(Ue.$$.fragment),ws=r(),qe=b("p"),this.h()},l(l){const s=da("svelte-u9bgzb",document.head);t=U(s,"META",{name:!0,content:!0}),s.forEach(n),i=p(l),e=U(l,"P",{}),Es(e).forEach(n),o=p(l),J(T.$$.fragment,l),h=p(l),J(j.$$.fragment,l),Pe=p(l),Z.l(l),Ge=p(l),nl=U(l,"P",{"data-svelte-h":!0}),f(nl)!=="svelte-1qnmyqa"&&(nl.innerHTML=Fs),Oe=p(l),g.l(l),Ne=p(l),J(al.$$.fragment,l),Ke=p(l),il=U(l,"P",{"data-svelte-h":!0}),f(il)!=="svelte-rh3xmu"&&(il.innerHTML=Ys),lt=p(l),J(rl.$$.fragment,l),et=p(l),J(pl.$$.fragment,l),tt=p(l),ml=U(l,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-1ydwudr"&&(ml.textContent=Ss),st=p(l),J(cl.$$.fragment,l),nt=p(l),J(ol.$$.fragment,l),at=p(l),Ml=U(l,"P",{"data-svelte-h":!0}),f(Ml)!=="svelte-ao9l2g"&&(Ml.textContent=As),it=p(l),J(Jl.$$.fragment,l),rt=p(l),yl=U(l,"P",{"data-svelte-h":!0}),f(yl)!=="svelte-1a2ccf3"&&(yl.innerHTML=qs),pt=p(l),N.l(l),xe=p(l),ul=U(l,"P",{"data-svelte-h":!0}),f(ul)!=="svelte-11tnr15"&&(ul.textContent=Ls),mt=p(l),K=U(l,"DIV",{class:!0,"data-svelte-h":!0}),f(K)!=="svelte-47wedv"&&(K.innerHTML=Ds),ct=p(l),dl=U(l,"P",{"data-svelte-h":!0}),f(dl)!=="svelte-fxh3w2"&&(dl.textContent=Ps),ot=p(l),J(Tl.$$.fragment,l),Mt=p(l),V.l(l),Ve=p(l),bl=U(l,"P",{"data-svelte-h":!0}),f(bl)!=="svelte-6zdey1"&&(bl.innerHTML=Os),Jt=p(l),Ul=U(l,"P",{"data-svelte-h":!0}),f(Ul)!=="svelte-s3s5n4"&&(Ul.innerHTML=Ks),yt=p(l),W.l(l),Re=p(l),wl=U(l,"P",{"data-svelte-h":!0}),f(wl)!=="svelte-1cy52pt"&&(wl.textContent=ln),ut=p(l),Q.l(l),We=p(l),fl=U(l,"P",{"data-svelte-h":!0}),f(fl)!=="svelte-16dtpm4"&&(fl.innerHTML=en),dt=p(l),I=U(l,"P",{});var _=Es(I);_s=De(_,"假设事件”答案开始于 "),ve=U(_,"CODE",{"data-svelte-h":!0}),f(ve)!=="svelte-8eqb3b"&&(ve.textContent=tn),ks=De(_," “和”答案结束于 "),Qe=U(_,"CODE",{"data-svelte-h":!0}),f(Qe)!=="svelte-9cistc"&&(Qe.textContent=sn),Bs=De(_," “是独立的，答案在 "),Xe=U(_,"CODE",{"data-svelte-h":!0}),f(Xe)!=="svelte-8eqb3b"&&(Xe.textContent=nn),$s=De(_," 开始并在 "),ze=U(_,"CODE",{"data-svelte-h":!0}),f(ze)!=="svelte-9cistc"&&(ze.textContent=an),Zs=De(_,` 结束的概率是：
`),Tt=Ta(_,!1),_.forEach(n),bt=p(l),hl=U(l,"P",{"data-svelte-h":!0}),f(hl)!=="svelte-lntjda"&&(hl.innerHTML=rn),Ut=p(l),jl=U(l,"P",{"data-svelte-h":!0}),f(jl)!=="svelte-1x6eenm"&&(jl.textContent=pn),wt=p(l),J(Il.$$.fragment,l),ft=p(l),z.l(l),Ee=p(l),_l=U(l,"P",{"data-svelte-h":!0}),f(_l)!=="svelte-1p41xth"&&(_l.innerHTML=mn),ht=p(l),J(kl.$$.fragment,l),jt=p(l),Bl=U(l,"P",{"data-svelte-h":!0}),f(Bl)!=="svelte-1i8krp9"&&(Bl.textContent=cn),It=p(l),J($l.$$.fragment,l),_t=p(l),J(ll.$$.fragment,l),kt=p(l),Zl=U(l,"P",{"data-svelte-h":!0}),f(Zl)!=="svelte-hddtp1"&&(Zl.innerHTML=on),Bt=p(l),J(Cl.$$.fragment,l),$t=p(l),gl=U(l,"P",{"data-svelte-h":!0}),f(gl)!=="svelte-r4atex"&&(gl.textContent=Mn),Zt=p(l),J(Gl.$$.fragment,l),Ct=p(l),J(Nl.$$.fragment,l),gt=p(l),xl=U(l,"P",{"data-svelte-h":!0}),f(xl)!=="svelte-ilbyxn"&&(xl.textContent=Jn),Gt=p(l),J(el.$$.fragment,l),Nt=p(l),J(Vl.$$.fragment,l),xt=p(l),Rl=U(l,"P",{"data-svelte-h":!0}),f(Rl)!=="svelte-1mk8eeh"&&(Rl.innerHTML=yn),Vt=p(l),J(Wl.$$.fragment,l),Rt=p(l),J(vl.$$.fragment,l),Wt=p(l),Ql=U(l,"P",{"data-svelte-h":!0}),f(Ql)!=="svelte-17s8uoe"&&(Ql.innerHTML=un),vt=p(l),J(Xl.$$.fragment,l),Qt=p(l),J(zl.$$.fragment,l),Xt=p(l),El=U(l,"P",{"data-svelte-h":!0}),f(El)!=="svelte-kg5kfe"&&(El.innerHTML=dn),zt=p(l),Hl=U(l,"P",{"data-svelte-h":!0}),f(Hl)!=="svelte-5qvawo"&&(Hl.innerHTML=Tn),Et=p(l),J(Fl.$$.fragment,l),Ht=p(l),J(Yl.$$.fragment,l),Ft=p(l),Sl=U(l,"P",{"data-svelte-h":!0}),f(Sl)!=="svelte-1th2wqp"&&(Sl.innerHTML=bn),Yt=p(l),Al=U(l,"P",{"data-svelte-h":!0}),f(Al)!=="svelte-1koiece"&&(Al.textContent=Un),St=p(l),J(ql.$$.fragment,l),At=p(l),J(Ll.$$.fragment,l),qt=p(l),Dl=U(l,"P",{"data-svelte-h":!0}),f(Dl)!=="svelte-1sfrff4"&&(Dl.textContent=wn),Lt=p(l),J(Pl.$$.fragment,l),Dt=p(l),J(Ol.$$.fragment,l),Pt=p(l),Kl=U(l,"P",{"data-svelte-h":!0}),f(Kl)!=="svelte-ofdnhc"&&(Kl.textContent=fn),Ot=p(l),J(le.$$.fragment,l),Kt=p(l),ee=U(l,"P",{"data-svelte-h":!0}),f(ee)!=="svelte-91xktt"&&(ee.textContent=hn),ls=p(l),J(te.$$.fragment,l),es=p(l),se=U(l,"P",{"data-svelte-h":!0}),f(se)!=="svelte-j9bgq4"&&(se.textContent=jn),ts=p(l),ne=U(l,"P",{"data-svelte-h":!0}),f(ne)!=="svelte-1fxmi0w"&&(ne.innerHTML=In),ss=p(l),J(ae.$$.fragment,l),ns=p(l),ie=U(l,"P",{"data-svelte-h":!0}),f(ie)!=="svelte-j6o9za"&&(ie.innerHTML=_n),as=p(l),H.l(l),He=p(l),re=U(l,"P",{"data-svelte-h":!0}),f(re)!=="svelte-46gt4g"&&(re.textContent=kn),is=p(l),J(pe.$$.fragment,l),rs=p(l),Y.l(l),Fe=p(l),me=U(l,"P",{"data-svelte-h":!0}),f(me)!=="svelte-gzqwi2"&&(me.textContent=Bn),ps=p(l),A.l(l),Ye=p(l),ce=U(l,"P",{"data-svelte-h":!0}),f(ce)!=="svelte-1fxln2y"&&(ce.textContent=$n),ms=p(l),L.l(l),Se=p(l),oe=U(l,"P",{"data-svelte-h":!0}),f(oe)!=="svelte-arqgbb"&&(oe.textContent=Zn),cs=p(l),P.l(l),Ae=p(l),J(Me.$$.fragment,l),os=p(l),Je=U(l,"P",{"data-svelte-h":!0}),f(Je)!=="svelte-1nxkykz"&&(Je.textContent=Cn),Ms=p(l),J(tl.$$.fragment,l),Js=p(l),ye=U(l,"P",{"data-svelte-h":!0}),f(ye)!=="svelte-1o2opb5"&&(ye.innerHTML=gn),ys=p(l),J(ue.$$.fragment,l),us=p(l),J(de.$$.fragment,l),ds=p(l),Te=U(l,"P",{"data-svelte-h":!0}),f(Te)!=="svelte-dwz8ii"&&(Te.textContent=Gn),Ts=p(l),J(sl.$$.fragment,l),bs=p(l),be=U(l,"P",{"data-svelte-h":!0}),f(be)!=="svelte-1trl7f8"&&(be.textContent=Nn),Us=p(l),J(Ue.$$.fragment,l),ws=p(l),qe=U(l,"P",{}),Es(qe).forEach(n),this.h()},h(){Hs(t,"name","hf:doc:metadata"),Hs(t,"content",La),Hs(K,"class","flex justify-center"),Tt.a=null},m(l,s){O(document.head,t),a(l,i,s),a(l,e,s),a(l,o,s),y(T,l,s),a(l,h,s),y(j,l,s),a(l,Pe,s),we[$].m(l,s),a(l,Ge,s),a(l,nl,s),a(l,Oe,s),fe[C].m(l,s),a(l,Ne,s),y(al,l,s),a(l,Ke,s),a(l,il,s),a(l,lt,s),y(rl,l,s),a(l,et,s),y(pl,l,s),a(l,tt,s),a(l,ml,s),a(l,st,s),y(cl,l,s),a(l,nt,s),y(ol,l,s),a(l,at,s),a(l,Ml,s),a(l,it,s),y(Jl,l,s),a(l,rt,s),a(l,yl,s),a(l,pt,s),he[G].m(l,s),a(l,xe,s),a(l,ul,s),a(l,mt,s),a(l,K,s),a(l,ct,s),a(l,dl,s),a(l,ot,s),y(Tl,l,s),a(l,Mt,s),je[x].m(l,s),a(l,Ve,s),a(l,bl,s),a(l,Jt,s),a(l,Ul,s),a(l,yt,s),Ie[R].m(l,s),a(l,Re,s),a(l,wl,s),a(l,ut,s),_e[v].m(l,s),a(l,We,s),a(l,fl,s),a(l,dt,s),a(l,I,s),O(I,_s),O(I,ve),O(I,ks),O(I,Qe),O(I,Bs),O(I,Xe),O(I,$s),O(I,ze),O(I,Zs),Tt.m(ca,I),a(l,bt,s),a(l,hl,s),a(l,Ut,s),a(l,jl,s),a(l,wt,s),y(Il,l,s),a(l,ft,s),ke[X].m(l,s),a(l,Ee,s),a(l,_l,s),a(l,ht,s),y(kl,l,s),a(l,jt,s),a(l,Bl,s),a(l,It,s),y($l,l,s),a(l,_t,s),y(ll,l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]){const _={};s&1&&(_.fw=l[0]),T.$set(_);let Cs=$;$=Vn(l),$!==Cs&&(B(),m(we[Cs],1,1,()=>{we[Cs]=null}),k(),Z=we[$],Z||(Z=we[$]=xn[$](l),Z.c()),c(Z,1),Z.m(Ge.parentNode,Ge));let gs=C;C=Wn(l),C!==gs&&(B(),m(fe[gs],1,1,()=>{fe[gs]=null}),k(),g=fe[C],g||(g=fe[C]=Rn[C](l),g.c()),c(g,1),g.m(Ne.parentNode,Ne));let Gs=G;G=Qn(l),G!==Gs&&(B(),m(he[Gs],1,1,()=>{he[Gs]=null}),k(),N=he[G],N||(N=he[G]=vn[G](l),N.c()),c(N,1),N.m(xe.parentNode,xe));let Ns=x;x=zn(l),x!==Ns&&(B(),m(je[Ns],1,1,()=>{je[Ns]=null}),k(),V=je[x],V||(V=je[x]=Xn[x](l),V.c()),c(V,1),V.m(Ve.parentNode,Ve));let xs=R;R=Hn(l),R!==xs&&(B(),m(Ie[xs],1,1,()=>{Ie[xs]=null}),k(),W=Ie[R],W||(W=Ie[R]=En[R](l),W.c()),c(W,1),W.m(Re.parentNode,Re));let Vs=v;v=Yn(l),v!==Vs&&(B(),m(_e[Vs],1,1,()=>{_e[Vs]=null}),k(),Q=_e[v],Q||(Q=_e[v]=Fn[v](l),Q.c()),c(Q,1),Q.m(We.parentNode,We));let Rs=X;X=An(l),X!==Rs&&(B(),m(ke[Rs],1,1,()=>{ke[Rs]=null}),k(),z=ke[X],z||(z=ke[X]=Sn[X](l),z.c()),c(z,1),z.m(Ee.parentNode,Ee));const na={};s&2&&(na.$$scope={dirty:s,ctx:l}),ll.$set(na);const aa={};s&2&&(aa.$$scope={dirty:s,ctx:l}),el.$set(aa);let Ws=E;E=Ln(l),E!==Ws&&(B(),m(Be[Ws],1,1,()=>{Be[Ws]=null}),k(),H=Be[E],H||(H=Be[E]=qn[E](l),H.c()),c(H,1),H.m(He.parentNode,He));let vs=F;F=Pn(l),F!==vs&&(B(),m($e[vs],1,1,()=>{$e[vs]=null}),k(),Y=$e[F],Y||(Y=$e[F]=Dn[F](l),Y.c()),c(Y,1),Y.m(Fe.parentNode,Fe));let Qs=S;S=Kn(l),S!==Qs&&(B(),m(Ze[Qs],1,1,()=>{Ze[Qs]=null}),k(),A=Ze[S],A||(A=Ze[S]=On[S](l),A.c()),c(A,1),A.m(Ye.parentNode,Ye));let Xs=q;q=ea(l),q!==Xs&&(B(),m(Ce[Xs],1,1,()=>{Ce[Xs]=null}),k(),L=Ce[q],L||(L=Ce[q]=la[q](l),L.c()),c(L,1),L.m(Se.parentNode,Se));let zs=D;D=sa(l),D!==zs&&(B(),m(ge[zs],1,1,()=>{ge[zs]=null}),k(),P=ge[D],P||(P=ge[D]=ta[D](l),P.c()),c(P,1),P.m(Ae.parentNode,Ae));const ia={};s&2&&(ia.$$scope={dirty:s,ctx:l}),tl.$set(ia);const ra={};s&2&&(ra.$$scope={dirty:s,ctx:l}),sl.$set(ra)},i(l){fs||(c(T.$$.fragment,l),c(j.$$.fragment,l),c(Z),c(g),c(al.$$.fragment,l),c(rl.$$.fragment,l),c(pl.$$.fragment,l),c(cl.$$.fragment,l),c(ol.$$.fragment,l),c(Jl.$$.fragment,l),c(N),c(Tl.$$.fragment,l),c(V),c(W),c(Q),c(Il.$$.fragment,l),c(z),c(kl.$$.fragment,l),c($l.$$.fragment,l),c(ll.$$.fragment,l),c(Cl.$$.fragment,l),c(Gl.$$.fragment,l),c(Nl.$$.fragment,l),c(el.$$.fragment,l),c(Vl.$$.fragment,l),c(Wl.$$.fragment,l),c(vl.$$.fragment,l),c(Xl.$$.fragment,l),c(zl.$$.fragment,l),c(Fl.$$.fragment,l),c(Yl.$$.fragment,l),c(ql.$$.fragment,l),c(Ll.$$.fragment,l),c(Pl.$$.fragment,l),c(Ol.$$.fragment,l),c(le.$$.fragment,l),c(te.$$.fragment,l),c(ae.$$.fragment,l),c(H),c(pe.$$.fragment,l),c(Y),c(A),c(L),c(P),c(Me.$$.fragment,l),c(tl.$$.fragment,l),c(ue.$$.fragment,l),c(de.$$.fragment,l),c(sl.$$.fragment,l),c(Ue.$$.fragment,l),fs=!0)},o(l){m(T.$$.fragment,l),m(j.$$.fragment,l),m(Z),m(g),m(al.$$.fragment,l),m(rl.$$.fragment,l),m(pl.$$.fragment,l),m(cl.$$.fragment,l),m(ol.$$.fragment,l),m(Jl.$$.fragment,l),m(N),m(Tl.$$.fragment,l),m(V),m(W),m(Q),m(Il.$$.fragment,l),m(z),m(kl.$$.fragment,l),m($l.$$.fragment,l),m(ll.$$.fragment,l),m(Cl.$$.fragment,l),m(Gl.$$.fragment,l),m(Nl.$$.fragment,l),m(el.$$.fragment,l),m(Vl.$$.fragment,l),m(Wl.$$.fragment,l),m(vl.$$.fragment,l),m(Xl.$$.fragment,l),m(zl.$$.fragment,l),m(Fl.$$.fragment,l),m(Yl.$$.fragment,l),m(ql.$$.fragment,l),m(Ll.$$.fragment,l),m(Pl.$$.fragment,l),m(Ol.$$.fragment,l),m(le.$$.fragment,l),m(te.$$.fragment,l),m(ae.$$.fragment,l),m(H),m(pe.$$.fragment,l),m(Y),m(A),m(L),m(P),m(Me.$$.fragment,l),m(tl.$$.fragment,l),m(ue.$$.fragment,l),m(de.$$.fragment,l),m(sl.$$.fragment,l),m(Ue.$$.fragment,l),fs=!1},d(l){l&&(n(i),n(e),n(o),n(h),n(Pe),n(Ge),n(nl),n(Oe),n(Ne),n(Ke),n(il),n(lt),n(et),n(tt),n(ml),n(st),n(nt),n(at),n(Ml),n(it),n(rt),n(yl),n(pt),n(xe),n(ul),n(mt),n(K),n(ct),n(dl),n(ot),n(Mt),n(Ve),n(bl),n(Jt),n(Ul),n(yt),n(Re),n(wl),n(ut),n(We),n(fl),n(dt),n(I),n(bt),n(hl),n(Ut),n(jl),n(wt),n(ft),n(Ee),n(_l),n(ht),n(jt),n(Bl),n(It),n(_t),n(kt),n(Zl),n(Bt),n($t),n(gl),n(Zt),n(Ct),n(gt),n(xl),n(Gt),n(Nt),n(xt),n(Rl),n(Vt),n(Rt),n(Wt),n(Ql),n(vt),n(Qt),n(Xt),n(El),n(zt),n(Hl),n(Et),n(Ht),n(Ft),n(Sl),n(Yt),n(Al),n(St),n(At),n(qt),n(Dl),n(Lt),n(Dt),n(Pt),n(Kl),n(Ot),n(Kt),n(ee),n(ls),n(es),n(se),n(ts),n(ne),n(ss),n(ns),n(ie),n(as),n(He),n(re),n(is),n(rs),n(Fe),n(me),n(ps),n(Ye),n(ce),n(ms),n(Se),n(oe),n(cs),n(Ae),n(os),n(Je),n(Ms),n(Js),n(ye),n(ys),n(us),n(ds),n(Te),n(Ts),n(bs),n(be),n(Us),n(ws),n(qe)),n(t),u(T,l),u(j,l),we[$].d(l),fe[C].d(l),u(al,l),u(rl,l),u(pl,l),u(cl,l),u(ol,l),u(Jl,l),he[G].d(l),u(Tl,l),je[x].d(l),Ie[R].d(l),_e[v].d(l),u(Il,l),ke[X].d(l),u(kl,l),u($l,l),u(ll,l),u(Cl,l),u(Gl,l),u(Nl,l),u(el,l),u(Vl,l),u(Wl,l),u(vl,l),u(Xl,l),u(zl,l),u(Fl,l),u(Yl,l),u(ql,l),u(Ll,l),u(Pl,l),u(Ol,l),u(le,l),u(te,l),u(ae,l),Be[E].d(l),u(pe,l),$e[F].d(l),Ze[S].d(l),Ce[q].d(l),ge[D].d(l),u(Me,l),u(tl,l),u(ue,l),u(de,l),u(sl,l),u(Ue,l)}}}const La='{"title":"在 QA 管道中使用快速 tokenizer","local":"在 QA 管道中使用快速 tokenizer","sections":[{"title":"使用 question-answering 管道","local":"使用 question-answering 管道","sections":[],"depth":2},{"title":"使用模型进行问答","local":"使用模型进行问答","sections":[],"depth":2},{"title":"处理长文本","local":"处理长文本","sections":[],"depth":2}],"depth":1}';function Da(d,t,i){let e="pt";return Ma(()=>{const o=new URLSearchParams(window.location.search);i(0,e=o.get("fw")||"pt")}),[e]}class ai extends Ja{constructor(t){super(),ya(this,t,Da,qa,oa,{})}}export{ai as component};
