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