import{s as da,o as ha,n as $s}from"../chunks/scheduler.37c15a92.js";import{S as Ua,i as fa,g as T,s as i,r as M,m as rt,H as Ja,A as ja,h as d,f as n,c as m,j as gs,u as J,x as U,n as it,E as ya,k as qs,y as g,a,v as y,t as p,b as Z,d as o,w as u,p as B}from"../chunks/index.2bf4358c.js";import{T as Zs}from"../chunks/Tip.363c041f.js";import{Y as ua}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4e987730.js";import{C as ba}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Ia}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Bs,E as _a}from"../chunks/index.49fc26ef.js";function ga(b){let e,r;return e=new ba({props:{chapter:6,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_tf.ipynb"}]}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Za(b){let e,r;return e=new ba({props:{chapter:6,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3b_pt.ipynb"}]}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ba(b){let e,r;return e=new ua({props:{id:"b3u8RzBCX9Y"}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function $a(b){let e,r;return e=new ua({props:{id:"_wxyB3j3mk4"}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function ka(b){let e,r;return e=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS1jYXNlZC1kaXN0aWxsZWQtc3F1YWQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIocXVlc3Rpb24lMkMlMjBjb250ZXh0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForQuestionAnswering

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-cased-distilled-squad&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = TFAutoModelForQuestionAnswering.from_pretrained(model_checkpoint)

inputs = tokenizer(question, context, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function va(b){let e,r;return e=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZyUwQSUwQW1vZGVsX2NoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtY2FzZWQtZGlzdGlsbGVkLXNxdWFkJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForQuestionAnswering

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-cased-distilled-squad&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)

inputs = tokenizer(question, context, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ga(b){let e,r;return e=new h({props:{code:"KDElMkMlMjA2NiklMjAoMSUyQyUyMDY2KQ==",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">66</span>) (<span class="hljs-number">1</span>, <span class="hljs-number">66</span>)',wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ca(b){let e,r;return e=new h({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNjYlNUQpJTIwdG9yY2guU2l6ZSglNUIxJTJDJTIwNjYlNUQp",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">66</span>]) torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">66</span>])',wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function xa(b){let e,r;return e=new h({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjBNYXNrJTIwZXZlcnl0aGluZyUyMGFwYXJ0JTIwZnJvbSUyMHRoZSUyMHRva2VucyUyMG9mJTIwdGhlJTIwY29udGV4dCUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjBVbm1hc2slMjB0aGUlMjAlNUJDTFMlNUQlMjB0b2tlbiUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEFtYXNrJTIwJTNEJTIwdGYuY29uc3RhbnQobWFzayklNUJOb25lJTVEJTBBJTBBc3RhcnRfbG9naXRzJTIwJTNEJTIwdGYud2hlcmUobWFzayUyQyUyMC0xMDAwMCUyQyUyMHN0YXJ0X2xvZ2l0cyklMEFlbmRfbG9naXRzJTIwJTNEJTIwdGYud2hlcmUobWFzayUyQyUyMC0xMDAwMCUyQyUyMGVuZF9sb2dpdHMp",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
mask = tf.constant(mask)[<span class="hljs-literal">None</span>]

start_logits = tf.where(mask, -<span class="hljs-number">10000</span>, start_logits)
end_logits = tf.where(mask, -<span class="hljs-number">10000</span>, end_logits)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Wa(b){let e,r;return e=new h({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjBNYXNrJTIwZXZlcnl0aGluZyUyMGFwYXJ0JTIwZnJvbSUyMHRoZSUyMHRva2VucyUyMG9mJTIwdGhlJTIwY29udGV4dCUwQW1hc2slMjAlM0QlMjAlNUJpJTIwISUzRCUyMDElMjBmb3IlMjBpJTIwaW4lMjBzZXF1ZW5jZV9pZHMlNUQlMEElMjMlMjBVbm1hc2slMjB0aGUlMjAlNUJDTFMlNUQlMjB0b2tlbiUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEFtYXNrJTIwJTNEJTIwdG9yY2gudGVuc29yKG1hc2spJTVCTm9uZSU1RCUwQSUwQXN0YXJ0X2xvZ2l0cyU1Qm1hc2slNUQlMjAlM0QlMjAtMTAwMDAlMEFlbmRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMA==",highlighted:`<span class="hljs-keyword">import</span> torch

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
mask = torch.tensor(mask)[<span class="hljs-literal">None</span>]

start_logits[mask] = -<span class="hljs-number">10000</span>
end_logits[mask] = -<span class="hljs-number">10000</span>`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ra(b){let e,r;return e=new h({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpJTVCMCU1RC5udW1weSgpJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0Zi5tYXRoLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGF4aXMlM0QtMSklNUIwJTVELm51bXB5KCk=",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Na(b){let e,r;return e=new h({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklNUIwJTVEJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0b3JjaC5ubi5mdW5jdGlvbmFsLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGRpbSUzRC0xKSU1QjAlNUQ=",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Va(b){let e,r="然後我們將屏蔽這些值 <strong>start_index &gt; end_index</strong> 通過將它們設置為 <strong>0</strong> （其他概率都是正數）。這 <strong>torch.triu()</strong> 函數返回作為參數傳遞的 2D 張量的上三角部分，因此它會為我們做屏蔽：",l,c,w;return c=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:"scores = np.triu(scores)",wrap:!1}}),{c(){e=T("p"),e.innerHTML=r,l=i(),M(c.$$.fragment)},l(f){e=d(f,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1ybcux8"&&(e.innerHTML=r),l=m(f),J(c.$$.fragment,f)},m(f,j){a(f,e,j),a(f,l,j),y(c,f,j),w=!0},i(f){w||(o(c.$$.fragment,f),w=!0)},o(f){p(c.$$.fragment,f),w=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function Xa(b){let e,r="然後我們將屏蔽這些值 <strong>start_index &gt; end_index</strong> 通過將它們設置為 <strong>0</strong> （其他概率都是正數）。這 <strong>torch.triu()</strong> 函數返回作為參數傳遞的 2D 張量的上三角部分，因此它會為我們做屏蔽：",l,c,w;return c=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMp",highlighted:"scores = torch.triu(scores)",wrap:!1}}),{c(){e=T("p"),e.innerHTML=r,l=i(),M(c.$$.fragment)},l(f){e=d(f,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1ybcux8"&&(e.innerHTML=r),l=m(f),J(c.$$.fragment,f)},m(f,j){a(f,e,j),a(f,l,j),y(c,f,j),w=!0},i(f){w||(o(c.$$.fragment,f),w=!0)},o(f){p(c.$$.fragment,f),w=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function za(b){let e,r="✏️ <strong>試試看!</strong> 計算五個最可能的答案的開始和結束索引。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1jz4o5h"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Qa(b){let e,r="✏️ <strong>試試看!</strong> 使用您之前計算的最佳分數來顯示五個最可能的答案。要檢查您的結果，請返回到第一個管道並在調用它時傳入。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-wt8pbw"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Ha(b){let e,r,l,c;return e=new h({props:{code:"XyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIpJTBBb2Zmc2V0cyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb2Zmc2V0X21hcHBpbmclMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW5wdXRzLmNvbnZlcnRfdG9fdGVuc29ycyglMjJ0ZiUyMiklMEFwcmludChpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUp",highlighted:`_ = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
offsets = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)

inputs = inputs.convert_to_tensors(<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)`,wrap:!1}}),l=new h({props:{code:"KDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(e.$$.fragment),r=i(),M(l.$$.fragment)},l(w){J(e.$$.fragment,w),r=m(w),J(l.$$.fragment,w)},m(w,f){y(e,w,f),a(w,r,f),y(l,w,f),c=!0},i(w){c||(o(e.$$.fragment,w),o(l.$$.fragment,w),c=!0)},o(w){p(e.$$.fragment,w),p(l.$$.fragment,w),c=!1},d(w){w&&n(r),u(e,w),u(l,w)}}}function Ea(b){let e,r,l,c;return e=new h({props:{code:"XyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIpJTBBb2Zmc2V0cyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb2Zmc2V0X21hcHBpbmclMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW5wdXRzLmNvbnZlcnRfdG9fdGVuc29ycyglMjJwdCUyMiklMEFwcmludChpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUp",highlighted:`_ = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
offsets = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)

inputs = inputs.convert_to_tensors(<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)`,wrap:!1}}),l=new h({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(e.$$.fragment),r=i(),M(l.$$.fragment)},l(w){J(e.$$.fragment,w),r=m(w),J(l.$$.fragment,w)},m(w,f){y(e,w,f),a(w,r,f),y(l,w,f),c=!0},i(w){c||(o(e.$$.fragment,w),o(l.$$.fragment,w),c=!0)},o(w){p(e.$$.fragment,w),p(l.$$.fragment,w),c=!1},d(w){w&&n(r),u(e,w),u(l,w)}}}function Ya(b){let e,r;return e=new h({props:{code:"KDIlMkMlMjAzODQpJTIwKDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>) (<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Fa(b){let e,r;return e=new h({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKSUyMHRvcmNoLlNpemUoJTVCMiUyQyUyMDM4NCU1RCk=",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>]) torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Sa(b){let e,r;return e=new h({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwTWFzayUyMGV2ZXJ5dGhpbmclMjBhcGFydCUyMGZyb20lMjB0aGUlMjB0b2tlbnMlMjBvZiUyMHRoZSUyMGNvbnRleHQlMEFtYXNrJTIwJTNEJTIwJTVCaSUyMCElM0QlMjAxJTIwZm9yJTIwaSUyMGluJTIwc2VxdWVuY2VfaWRzJTVEJTBBJTIzJTIwVW5tYXNrJTIwdGhlJTIwJTVCQ0xTJTVEJTIwdG9rZW4lMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwTWFzayUyMGFsbCUyMHRoZSUyMCU1QlBBRCU1RCUyMHRva2VucyUwQW1hc2slMjAlM0QlMjB0Zi5tYXRoLmxvZ2ljYWxfb3IodGYuY29uc3RhbnQobWFzayklNUJOb25lJTVEJTJDJTIwaW5wdXRzJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlNUQlMjAlM0QlM0QlMjAwKSUwQSUwQXN0YXJ0X2xvZ2l0cyUyMCUzRCUyMHRmLndoZXJlKG1hc2slMkMlMjAtMTAwMDAlMkMlMjBzdGFydF9sb2dpdHMpJTBBZW5kX2xvZ2l0cyUyMCUzRCUyMHRmLndoZXJlKG1hc2slMkMlMjAtMTAwMDAlMkMlMjBlbmRfbG9naXRzKQ==",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Mask all the [PAD] tokens</span>
mask = tf.math.logical_or(tf.constant(mask)[<span class="hljs-literal">None</span>], inputs[<span class="hljs-string">&quot;attention_mask&quot;</span>] == <span class="hljs-number">0</span>)

start_logits = tf.where(mask, -<span class="hljs-number">10000</span>, start_logits)
end_logits = tf.where(mask, -<span class="hljs-number">10000</span>, end_logits)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Aa(b){let e,r;return e=new h({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwTWFzayUyMGV2ZXJ5dGhpbmclMjBhcGFydCUyMGZyb20lMjB0aGUlMjB0b2tlbnMlMjBvZiUyMHRoZSUyMGNvbnRleHQlMEFtYXNrJTIwJTNEJTIwJTVCaSUyMCElM0QlMjAxJTIwZm9yJTIwaSUyMGluJTIwc2VxdWVuY2VfaWRzJTVEJTBBJTIzJTIwVW5tYXNrJTIwdGhlJTIwJTVCQ0xTJTVEJTIwdG9rZW4lMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwTWFzayUyMGFsbCUyMHRoZSUyMCU1QlBBRCU1RCUyMHRva2VucyUwQW1hc2slMjAlM0QlMjB0b3JjaC5sb2dpY2FsX29yKHRvcmNoLnRlbnNvcihtYXNrKSU1Qk5vbmUlNUQlMkMlMjAoaW5wdXRzJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlNUQlMjAlM0QlM0QlMjAwKSklMEElMEFzdGFydF9sb2dpdHMlNUJtYXNrJTVEJTIwJTNEJTIwLTEwMDAwJTBBZW5kX2xvZ2l0cyU1Qm1hc2slNUQlMjAlM0QlMjAtMTAwMDA=",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Mask everything apart from the tokens of the context</span>
mask = [i != <span class="hljs-number">1</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sequence_ids]
<span class="hljs-comment"># Unmask the [CLS] token</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Mask all the [PAD] tokens</span>
mask = torch.logical_or(torch.tensor(mask)[<span class="hljs-literal">None</span>], (inputs[<span class="hljs-string">&quot;attention_mask&quot;</span>] == <span class="hljs-number">0</span>))

start_logits[mask] = -<span class="hljs-number">10000</span>
end_logits[mask] = -<span class="hljs-number">10000</span>`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function qa(b){let e,r;return e=new h({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpLm51bXB5KCklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChlbmRfbG9naXRzJTJDJTIwYXhpcyUzRC0xKS5udW1weSgp",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>).numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>).numpy()`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function La(b){let e,r;return e=new h({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChlbmRfbG9naXRzJTJDJTIwZGltJTNELTEp",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Da(b){let e,r;return e=new h({props:{code:"Y2FuZGlkYXRlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMHN0YXJ0X3Byb2JzJTJDJTIwZW5kX3Byb2JzJTIwaW4lMjB6aXAoc3RhcnRfcHJvYmFiaWxpdGllcyUyQyUyMGVuZF9wcm9iYWJpbGl0aWVzKSUzQSUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyMCUzRCUyMHN0YXJ0X3Byb2JzJTVCJTNBJTJDJTIwTm9uZSU1RCUyMColMjBlbmRfcHJvYnMlNUJOb25lJTJDJTIwJTNBJTVEJTBBJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwbnAudHJpdShzY29yZXMpLmFyZ21heCgpLml0ZW0oKSUwQSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2lkeCUyMCUzRCUyMGlkeCUyMCUyRiUyRiUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEElMjAlMjAlMjAlMjBlbmRfaWR4JTIwJTNEJTIwaWR4JTIwJTI1JTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQSUyMCUyMCUyMCUyMHNjb3JlJTIwJTNEJTIwc2NvcmVzJTVCc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCU1RC5pdGVtKCklMEElMjAlMjAlMjAlMjBjYW5kaWRhdGVzLmFwcGVuZCgoc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCUyQyUyMHNjb3JlKSklMEElMEFwcmludChjYW5kaWRhdGVzKQ==",highlighted:`candidates = []
<span class="hljs-keyword">for</span> start_probs, end_probs <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(start_probabilities, end_probabilities):
    scores = start_probs[:, <span class="hljs-literal">None</span>] * end_probs[<span class="hljs-literal">None</span>, :]
    idx = np.triu(scores).argmax().item()

    start_idx = idx // scores.shape[<span class="hljs-number">1</span>]
    end_idx = idx % scores.shape[<span class="hljs-number">1</span>]
    score = scores[start_idx, end_idx].item()
    candidates.append((start_idx, end_idx, score))

<span class="hljs-built_in">print</span>(candidates)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Pa(b){let e,r;return e=new h({props:{code:"Y2FuZGlkYXRlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMHN0YXJ0X3Byb2JzJTJDJTIwZW5kX3Byb2JzJTIwaW4lMjB6aXAoc3RhcnRfcHJvYmFiaWxpdGllcyUyQyUyMGVuZF9wcm9iYWJpbGl0aWVzKSUzQSUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyMCUzRCUyMHN0YXJ0X3Byb2JzJTVCJTNBJTJDJTIwTm9uZSU1RCUyMColMjBlbmRfcHJvYnMlNUJOb25lJTJDJTIwJTNBJTVEJTBBJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMpLmFyZ21heCgpLml0ZW0oKSUwQSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2lkeCUyMCUzRCUyMGlkeCUyMCUyRiUyRiUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEElMjAlMjAlMjAlMjBlbmRfaWR4JTIwJTNEJTIwaWR4JTIwJTI1JTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQSUyMCUyMCUyMCUyMHNjb3JlJTIwJTNEJTIwc2NvcmVzJTVCc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCU1RC5pdGVtKCklMEElMjAlMjAlMjAlMjBjYW5kaWRhdGVzLmFwcGVuZCgoc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCUyQyUyMHNjb3JlKSklMEElMEFwcmludChjYW5kaWRhdGVzKQ==",highlighted:`candidates = []
<span class="hljs-keyword">for</span> start_probs, end_probs <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(start_probabilities, end_probabilities):
    scores = start_probs[:, <span class="hljs-literal">None</span>] * end_probs[<span class="hljs-literal">None</span>, :]
    idx = torch.triu(scores).argmax().item()

    start_idx = idx // scores.shape[<span class="hljs-number">1</span>]
    end_idx = idx % scores.shape[<span class="hljs-number">1</span>]
    score = scores[start_idx, end_idx].item()
    candidates.append((start_idx, end_idx, score))

<span class="hljs-built_in">print</span>(candidates)`,wrap:!1}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ka(b){let e,r="✏️ <strong>試試看!</strong> 修改上面的代碼以返回五個最可能的答案的分數和跨度（總計，而不是每個塊）。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-8ehzhl"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function Oa(b){let e,r="✏️ <strong>試試看!</strong> 使用您之前計算的最佳分數來顯示五個最可能的答案（對於整個上下文，而不是每個塊）。要檢查您的結果，請返回到第一個管道並在調用它時傳入。";return{c(){e=T("p"),e.innerHTML=r},l(l){e=d(l,"P",{"data-svelte-h":!0}),U(e)!=="svelte-1nkjcg9"&&(e.innerHTML=r)},m(l,c){a(l,e,c)},p:$s,d(l){l&&n(e)}}}function tr(b){let e,r,l,c,w,f,j,Ol,$,k,Wl,mt,Ls="我們現在將深入研究 <strong>question-answering</strong> 管道，看看如何利用偏移量從上下文中獲取手頭問題的答案，有點像我們在上一節中對分組實體所做的。然後我們將看到我們如何處理最終被截斷的非常長的上下文。如果您對問答任務不感興趣，可以跳過此部分。",te,v,G,Rl,pt,le,ot,Ds='正如我們在<a href="/course/chapter1">Chapter 1</a>，我們可以使用 <strong>question-answering</strong> 像這樣的管道以獲得問題的答案：',ee,ct,se,Mt,ne,Jt,Ps="與其他管道不同，它不能截斷和拆分長於模型接受的最大長度的文本（因此可能會丟失文檔末尾的信息），此管道可以處理非常長的上下文，並將返回回答這個問題，即使它在最後：",ae,yt,re,ut,ie,bt,Ks="讓我們看看它是如何做到這一切的！",me,wt,pe,Tt,Os='與任何其他管道一樣，我們首先對輸入進行標記化，然後通過模型將其發送。默認情況下用於的檢查點 <strong>question-answering</strong> 管道是<a href="https://huggingface.co/distilbert-base-cased-distilled-squad" rel="nofollow">distilbert-base-cased-distilled-squad</a>（名稱中的“squad”來自模型微調的數據集；我們將在<a href="/course/chapter7/7">Chapter 7</a>):',oe,C,x,Nl,dt,tn="請注意，我們將問題和上下文標記為一對，首先是問題",ce,lt,ln='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/question_tokens.svg" alt="An example of tokenization of question and context"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/question_tokens-dark.svg" alt="An example of tokenization of question and context"/>',Me,ht,en="問答模型的工作方式與我們迄今為止看到的模型略有不同。以上圖為例，該模型已經過訓練，可以預測答案開始的標記的索引（此處為 21）和答案結束處的標記的索引（此處為 24）。這就是為什麼這些模型不返回一個 logits 的張量，而是返回兩個：一個用於對應於答案的開始標記的 logits，另一個用於對應於答案的結束標記的 logits。由於在這種情況下我們只有一個包含 66 個標記的輸入，我們得到：",Je,Ut,ye,W,R,Vl,ft,sn="為了將這些 logits 轉換為概率，我們將應用一個 softmax 函數——但在此之前，我們需要確保我們屏蔽了不屬於上下文的索引。我們的輸入是 <strong>[CLS] question [SEP] context [SEP]</strong> ，所以我們需要屏蔽問題的標記以及 <strong>[SEP]</strong> 令牌。我們將保留 <strong>[CLS]</strong> 然而，因為某些模型使用它來表示答案不在上下文中。",ue,jt,nn="由於我們將在之後應用 softmax，我們只需要用一個大的負數替換我們想要屏蔽的 logits。在這裡，我們使用 <strong>-10000</strong> ：",be,N,V,Xl,It,an="現在我們已經正確屏蔽了與我們不想預測的位置相對應的 logits，我們可以應用 softmax：",we,X,z,zl,_t,rn="在這個階段，我們可以採用開始和結束概率的 argmax——但我們最終可能會得到一個大於結束索引的開始索引，所以我們需要採取更多的預防措施。我們將計算每個可能的概率 <strong>start_index</strong> 和 <strong>end_index</strong> 在哪裡 <strong>start_index &lt;= end_index</strong> ，然後取元組 <strong>(start_index, end_index)</strong> 以最高的概率。",Te,I,ks,Ql,mn="start_index",vs,Hl,pn="end_index",Gs,El,on="start_index",Cs,Yl,cn="end_index",xs,de,wa='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo><mo>×</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\\mathrm{start\\_probabilities}[\\mathrm{start\\_index}] \\times \\mathrm{end\\_probabilities}[\\mathrm{end\\_index}]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">start_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">start_index</span></span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">×</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">end_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">end_index</span></span><span class="mclose">]</span></span></span></span></span>',he,O,Ws,Ue,Ta='<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo><mo>×</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi></mrow><mo stretchy="false">[</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">_</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi></mrow><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\\mathrm{start\\_probabilities}[\\mathrm{start\\_index}] \\times \\mathrm{end\\_probabilities}[\\mathrm{end\\_index}]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">start_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">start_index</span></span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">×</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">end_probabilities</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathrm">end_index</span></span><span class="mclose">]</span></span></span></span>',fe,Fl,Mn="start_index <= end_index",Rs,je,gt,Jn="首先讓我們計算所有可能的產品：",Ie,Zt,_e,Q,H,Sl,Bt,yn="現在我們只需要得到最大值的索引。由於 PyTorch 將返回展平張量中的索引，因此我們需要使用地板除法 <strong>//</strong> 和模數 <strong>%</strong> 操作以獲得 <strong>start_index</strong> 和 <strong>end_index</strong> ：",ge,$t,Ze,kt,un="我們還沒有完全完成，但至少我們已經有了正確的答案分數（您可以通過將其與上一節中的第一個結果進行比較來檢查這一點）：",Be,vt,$e,et,ke,Gt,bn="我們有 <strong>start_index</strong> 和 <strong>end_index</strong> 就標記而言的答案，所以現在我們只需要轉換為上下文中的字符索引。這是偏移量非常有用的地方。我們可以像在令牌分類任務中一樣抓住它們並使用它們：",ve,Ct,Ge,xt,wn="現在我們只需要格式化所有內容以獲得我們的結果：",Ce,Wt,xe,Rt,We,Nt,Tn="太棒了！這和我們的第一個例子一樣！",Re,st,Ne,Vt,Ve,Xt,dn="如果我們嘗試對我們之前作為示例使用的問題和長上下文進行標記化，我們將獲得比在 <strong>question-answering</strong> 管道（即 384）：",Xe,zt,ze,Qt,Qe,Ht,hn="因此，我們需要在最大長度處截斷我們的輸入。有幾種方法可以做到這一點，但我們不想截斷問題，只想截斷上下文。由於上下文是第二個句子，我們將使用 <strong>“only_second”</strong> 截斷策略。那麼出現的問題是問題的答案可能不在截斷上下文中。例如，在這裡，我們選擇了一個答案在上下文末尾的問題，當我們截斷它時，答案不存在",He,Et,Ee,Yt,Ye,Ft,Un="這意味著模型將很難選擇正確的答案。為了解決這個問題， <strong>question-answering</strong> 管道允許我們將上下文分成更小的塊，指定最大長度。為確保我們不會在完全錯誤的位置拆分上下文以找到答案，它還包括塊之間的一些重疊。",Fe,St,fn="我們可以讓分詞器（快或慢）通過添加來為我們做這件事 <strong>return_overflowing_tokens=True</strong> ，我們可以指定我們想要的重疊 <strong>stride</strong> 爭論。這是一個使用較小句子的示例：",Se,At,Ae,qt,qe,Lt,jn="正如我們所看到的，句子已被分成多個塊，使得每個條目 <strong>inputs[“input_ids”]</strong> 最多有 6 個標記（我們需要添加填充以使最後一個條目與其他條目的大小相同）並且每個條目之間有 2 個標記的重疊。",Le,Dt,In="讓我們仔細看看標記化的結果：",De,Pt,Pe,Kt,Ke,Ot,_n="正如預期的那樣，我們得到了輸入 ID 和一個注意力掩碼。最後一個鍵， <strong>overflow_to_sample_mapping</strong> , 是一個映射，它告訴我們每個結果對應哪個句子——這裡我們有 7 個結果，它們都來自我們通過標記器的（唯一）句子：",Oe,tl,ts,ll,ls,el,gn="當我們將幾個句子標記在一起時，這更有用。例如，這個：",es,sl,ss,nl,Zn="讓我們：",ns,al,as,rl,Bn="這意味著第一個句子像以前一樣分成 7 個塊，接下來的 4 個塊來自第二個句子。",rs,il,$n="現在讓我們回到我們的長期背景。默認情況下 <strong>question-answering</strong> 管道使用的最大長度為 384，正如我們之前提到的，步長為 128，這對應於模型微調的方式（您可以通過傳遞 <strong>max_seq_len</strong> 和 <strong>stride</strong> 調用管道時的參數）。因此，我們將在標記化時使用這些參數。我們還將添加填充（具有相同長度的樣本，因此我們可以構建張量）以及請求偏移量：",is,ml,ms,pl,kn="那些 <strong>inputs</strong> 將包含模型期望的輸入 ID 和注意力掩碼，以及偏移量和 <strong>overflow_to_sample_mapping</strong> 我們剛剛談到。由於這兩個不是模型使用的參數，我們將把它們從 <strong>inputs</strong> （我們不會存儲地圖，因為它在這裡沒有用）在將其轉換為張量之前：",ps,E,Y,Al,ol,vn="我們的長上下文被分成兩部分，這意味著在它通過我們的模型後，我們將有兩組開始和結束 logits：",os,cl,cs,F,S,ql,Ml,Gn="和以前一樣，我們在採用 softmax 之前首先屏蔽不屬於上下文的標記。我們還屏蔽了所有填充標記（由注意掩碼標記）：",Ms,A,q,Ll,Jl,Cn="然後我們可以使用 softmax 將我們的 logits 轉換為概率：",Js,L,D,Dl,yl,xn="下一步與我們對小上下文所做的類似，但我們對兩個塊中的每一個都重複它。我們將分數歸因於所有可能的答案跨度，然後取得分最高的跨度：",ys,P,K,Pl,ul,us,bl,Wn="這兩個候選對應於模型能夠在每個塊中找到的最佳答案。該模型對正確答案在第二部分更有信心（這是一個好兆頭！）。現在我們只需要將這兩個標記跨度映射到上下文中的字符跨度（我們只需要映射第二個標記以獲得我們的答案，但看看模型在第一個塊中選擇了什麼很有趣）。",bs,nt,ws,wl,Rn="這 <strong>offsets</strong> 我們之前抓取的實際上是一個偏移量列表，每個文本塊有一個列表：",Ts,Tl,ds,dl,hs,hl,Nn="如果我們忽略第一個結果，我們會得到與這個長上下文的管道相同的結果——是的！",Us,at,fs,Ul,Vn="我們對分詞器功能的深入研究到此結束。我們將在下一章再次將所有這些付諸實踐，屆時我們將向您展示如何在一系列常見的 NLP 任務上微調模型。",js,fl,Is,Kl,_s;w=new Ia({props:{fw:b[0]}}),j=new Bs({props:{title:"QA 管道中的快速標記器",local:"qa-管道中的快速標記器",headingTag:"h1"}});const Xn=[Za,ga],jl=[];function zn(t,s){return t[0]==="pt"?0:1}$=zn(b),k=jl[$]=Xn[$](b);const Qn=[$a,Ba],Il=[];function Hn(t,s){return t[0]==="pt"?0:1}v=Hn(b),G=Il[v]=Qn[v](b),pt=new Bs({props:{title:"使用 question-answering 管道",local:"使用-question-answering-管道",headingTag:"h2"}}),ct=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcXVlc3Rpb25fYW5zd2VyZXIlMjAlM0QlMjBwaXBlbGluZSglMjJxdWVzdGlvbi1hbnN3ZXJpbmclMjIpJTBBY29udGV4dCUyMCUzRCUyMCUyMiUyMiUyMiUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMGlzJTIwYmFja2VkJTIwYnklMjB0aGUlMjB0aHJlZSUyMG1vc3QlMjBwb3B1bGFyJTIwZGVlcCUyMGxlYXJuaW5nJTIwbGlicmFyaWVzJTIwJUUyJTgwJTk0JTIwSmF4JTJDJTIwUHlUb3JjaCUyQyUyMGFuZCUyMFRlbnNvckZsb3clMjAlRTIlODAlOTQlMjB3aXRoJTIwYSUyMHNlYW1sZXNzJTIwaW50ZWdyYXRpb24lMEFiZXR3ZWVuJTIwdGhlbS4lMjBJdCdzJTIwc3RyYWlnaHRmb3J3YXJkJTIwdG8lMjB0cmFpbiUyMHlvdXIlMjBtb2RlbHMlMjB3aXRoJTIwb25lJTIwYmVmb3JlJTIwbG9hZGluZyUyMHRoZW0lMjBmb3IlMjBpbmZlcmVuY2UlMjB3aXRoJTIwdGhlJTIwb3RoZXIuJTBBJTIyJTIyJTIyJTBBcXVlc3Rpb24lMjAlM0QlMjAlMjJXaGljaCUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMGJhY2slMjAlRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlM0YlMjIlMEFxdWVzdGlvbl9hbnN3ZXJlcihxdWVzdGlvbiUzRHF1ZXN0aW9uJTJDJTIwY29udGV4dCUzRGNvbnRleHQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

question_answerer = pipeline(<span class="hljs-string">&quot;question-answering&quot;</span>)
context = <span class="hljs-string">&quot;&quot;&quot;
🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch, and TensorFlow — with a seamless integration
between them. It&#x27;s straightforward to train your models with one before loading them for inference with the other.
&quot;&quot;&quot;</span>
question = <span class="hljs-string">&quot;Which deep learning libraries back 🤗 Transformers?&quot;</span>
question_answerer(question=question, context=context)`,wrap:!1}}),Mt=new h({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTc3NzMlMkMlMEElMjAnc3RhcnQnJTNBJTIwNzglMkMlMEElMjAnZW5kJyUzQSUyMDEwNSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),yt=new h({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTIwcHJvdmlkZXMlMjBBUElzJTIwdG8lMjBxdWlja2x5JTIwZG93bmxvYWQlMjBhbmQlMjB1c2UlMjB0aG9zZSUyMHByZXRyYWluZWQlMjBtb2RlbHMlMjBvbiUyMGElMjBnaXZlbiUyMHRleHQlMkMlMjBmaW5lLXR1bmUlMjB0aGVtJTIwb24lMjB5b3VyJTIwb3duJTIwZGF0YXNldHMlMjBhbmQlMEF0aGVuJTIwc2hhcmUlMjB0aGVtJTIwd2l0aCUyMHRoZSUyMGNvbW11bml0eSUyMG9uJTIwb3VyJTIwbW9kZWwlMjBodWIuJTIwQXQlMjB0aGUlMjBzYW1lJTIwdGltZSUyQyUyMGVhY2glMjBweXRob24lMjBtb2R1bGUlMjBkZWZpbmluZyUyMGFuJTIwYXJjaGl0ZWN0dXJlJTIwaXMlMjBmdWxseSUyMHN0YW5kYWxvbmUlMjBhbmQlMEFjYW4lMjBiZSUyMG1vZGlmaWVkJTIwdG8lMjBlbmFibGUlMjBxdWljayUyMHJlc2VhcmNoJTIwZXhwZXJpbWVudHMuJTBBJTBBV2h5JTIwc2hvdWxkJTIwSSUyMHVzZSUyMHRyYW5zZm9ybWVycyUzRiUwQSUwQTEuJTIwRWFzeS10by11c2UlMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTNBJTBBJTIwJTIwLSUyMEhpZ2glMjBwZXJmb3JtYW5jZSUyMG9uJTIwTkxVJTIwYW5kJTIwTkxHJTIwdGFza3MuJTBBJTIwJTIwLSUyMExvdyUyMGJhcnJpZXIlMjB0byUyMGVudHJ5JTIwZm9yJTIwZWR1Y2F0b3JzJTIwYW5kJTIwcHJhY3RpdGlvbmVycy4lMEElMjAlMjAtJTIwRmV3JTIwdXNlci1mYWNpbmclMjBhYnN0cmFjdGlvbnMlMjB3aXRoJTIwanVzdCUyMHRocmVlJTIwY2xhc3NlcyUyMHRvJTIwbGVhcm4uJTBBJTIwJTIwLSUyMEElMjB1bmlmaWVkJTIwQVBJJTIwZm9yJTIwdXNpbmclMjBhbGwlMjBvdXIlMjBwcmV0cmFpbmVkJTIwbW9kZWxzLiUwQSUyMCUyMC0lMjBMb3dlciUyMGNvbXB1dGUlMjBjb3N0cyUyQyUyMHNtYWxsZXIlMjBjYXJib24lMjBmb290cHJpbnQlM0ElMEElMEEyLiUyMFJlc2VhcmNoZXJzJTIwY2FuJTIwc2hhcmUlMjB0cmFpbmVkJTIwbW9kZWxzJTIwaW5zdGVhZCUyMG9mJTIwYWx3YXlzJTIwcmV0cmFpbmluZy4lMEElMjAlMjAtJTIwUHJhY3RpdGlvbmVycyUyMGNhbiUyMHJlZHVjZSUyMGNvbXB1dGUlMjB0aW1lJTIwYW5kJTIwcHJvZHVjdGlvbiUyMGNvc3RzLiUwQSUyMCUyMC0lMjBEb3plbnMlMjBvZiUyMGFyY2hpdGVjdHVyZXMlMjB3aXRoJTIwb3ZlciUyMDEwJTJDMDAwJTIwcHJldHJhaW5lZCUyMG1vZGVscyUyQyUyMHNvbWUlMjBpbiUyMG1vcmUlMjB0aGFuJTIwMTAwJTIwbGFuZ3VhZ2VzLiUwQSUwQTMuJTIwQ2hvb3NlJTIwdGhlJTIwcmlnaHQlMjBmcmFtZXdvcmslMjBmb3IlMjBldmVyeSUyMHBhcnQlMjBvZiUyMGElMjBtb2RlbCdzJTIwbGlmZXRpbWUlM0ElMEElMjAlMjAtJTIwVHJhaW4lMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTIwaW4lMjAzJTIwbGluZXMlMjBvZiUyMGNvZGUuJTBBJTIwJTIwLSUyME1vdmUlMjBhJTIwc2luZ2xlJTIwbW9kZWwlMjBiZXR3ZWVuJTIwVEYyLjAlMkZQeVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFscyUyMGFyZSUyMGV4cG9zZWQlMjBhcyUyMGNvbnNpc3RlbnRseSUyMGFzJTIwcG9zc2libGUuJTBBJTIwJTIwLSUyME1vZGVsJTIwZmlsZXMlMjBjYW4lMjBiZSUyMHVzZWQlMjBpbmRlcGVuZGVudGx5JTIwb2YlMjB0aGUlMjBsaWJyYXJ5JTIwZm9yJTIwcXVpY2slMjBleHBlcmltZW50cy4lMEElMEElRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlMjBpcyUyMGJhY2tlZCUyMGJ5JTIwdGhlJTIwdGhyZWUlMjBtb3N0JTIwcG9wdWxhciUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMCVFMiU4MCU5NCUyMEpheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",highlighted:`long_context = <span class="hljs-string">&quot;&quot;&quot;
🤗 Transformers: State of the Art NLP

🤗 Transformers provides thousands of pretrained models to perform tasks on texts such as classification, information extraction,
question answering, summarization, translation, text generation and more in over 100 languages.
Its aim is to make cutting-edge NLP easier to use for everyone.

🤗 Transformers provides APIs to quickly download and use those pretrained models on a given text, fine-tune them on your own datasets and
then share them with the community on our model hub. At the same time, each python module defining an architecture is fully standalone and
can be modified to enable quick research experiments.

Why should I use transformers?

1. Easy-to-use state-of-the-art models:
  - High performance on NLU and NLG tasks.
  - Low barrier to entry for educators and practitioners.
  - Few user-facing abstractions with just three classes to learn.
  - A unified API for using all our pretrained models.
  - Lower compute costs, smaller carbon footprint:

2. Researchers can share trained models instead of always retraining.
  - Practitioners can reduce compute time and production costs.
  - Dozens of architectures with over 10,000 pretrained models, some in more than 100 languages.

3. Choose the right framework for every part of a model&#x27;s lifetime:
  - Train state-of-the-art models in 3 lines of code.
  - Move a single model between TF2.0/PyTorch frameworks at will.
  - Seamlessly pick the right framework for training, evaluation and production.

4. Easily customize a model or an example to your needs:
  - We provide examples for each architecture to reproduce the results published by its original authors.
  - Model internals are exposed as consistently as possible.
  - Model files can be used independently of the library for quick experiments.

🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch and TensorFlow — with a seamless integration
between them. It&#x27;s straightforward to train your models with one before loading them for inference with the other.
&quot;&quot;&quot;</span>
question_answerer(question=question, context=long_context)`,wrap:!1}}),ut=new h({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTcxNDklMkMlMEElMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUwQSUyMCdlbmQnJTNBJTIwMTkxOSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),wt=new Bs({props:{title:"使用模型進行問答",local:"使用模型進行問答",headingTag:"h2"}});const En=[va,ka],_l=[];function Yn(t,s){return t[0]==="pt"?0:1}C=Yn(b),x=_l[C]=En[C](b),Ut=new h({props:{code:"c3RhcnRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMlMEFlbmRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5lbmRfbG9naXRzJTBBcHJpbnQoc3RhcnRfbG9naXRzLnNoYXBlJTJDJTIwZW5kX2xvZ2l0cy5zaGFwZSk=",highlighted:`start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const Fn=[Ca,Ga],gl=[];function Sn(t,s){return t[0]==="pt"?0:1}W=Sn(b),R=gl[W]=Fn[W](b);const An=[Wa,xa],Zl=[];function qn(t,s){return t[0]==="pt"?0:1}N=qn(b),V=Zl[N]=An[N](b);const Ln=[Na,Ra],Bl=[];function Dn(t,s){return t[0]==="pt"?0:1}X=Dn(b),z=Bl[X]=Ln[X](b),Zt=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwc3RhcnRfcHJvYmFiaWxpdGllcyU1QiUzQSUyQyUyME5vbmUlNUQlMjAqJTIwZW5kX3Byb2JhYmlsaXRpZXMlNUJOb25lJTJDJTIwJTNBJTVE",highlighted:'scores = start_probabilities[:, <span class="hljs-literal">None</span>] * end_probabilities[<span class="hljs-literal">None</span>, :]',wrap:!1}});const Pn=[Xa,Va],$l=[];function Kn(t,s){return t[0]==="pt"?0:1}Q=Kn(b),H=$l[Q]=Pn[Q](b),$t=new h({props:{code:"bWF4X2luZGV4JTIwJTNEJTIwc2NvcmVzLmFyZ21heCgpLml0ZW0oKSUwQXN0YXJ0X2luZGV4JTIwJTNEJTIwbWF4X2luZGV4JTIwJTJGJTJGJTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQWVuZF9pbmRleCUyMCUzRCUyMG1heF9pbmRleCUyMCUyNSUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEFwcmludChzY29yZXMlNUJzdGFydF9pbmRleCUyQyUyMGVuZF9pbmRleCU1RCk=",highlighted:`max_index = scores.argmax().item()
start_index = max_index // scores.shape[<span class="hljs-number">1</span>]
end_index = max_index % scores.shape[<span class="hljs-number">1</span>]
<span class="hljs-built_in">print</span>(scores[start_index, end_index])`,wrap:!1}}),vt=new h({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),et=new Zs({props:{$$slots:{default:[za]},$$scope:{ctx:b}}}),Ct=new h({props:{code:"aW5wdXRzX3dpdGhfb2Zmc2V0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSklMEFvZmZzZXRzJTIwJTNEJTIwaW5wdXRzX3dpdGhfb2Zmc2V0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTBBJTBBc3RhcnRfY2hhciUyQyUyMF8lMjAlM0QlMjBvZmZzZXRzJTVCc3RhcnRfaW5kZXglNUQlMEFfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXRzJTVCZW5kX2luZGV4JTVEJTBBYW5zd2VyJTIwJTNEJTIwY29udGV4dCU1QnN0YXJ0X2NoYXIlM0FlbmRfY2hhciU1RA==",highlighted:`inputs_with_offsets = tokenizer(question, context, return_offsets_mapping=<span class="hljs-literal">True</span>)
offsets = inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]

start_char, _ = offsets[start_index]
_, end_char = offsets[end_index]
answer = context[start_char:end_char]`,wrap:!1}}),Wt=new h({props:{code:"cmVzdWx0JTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIyYW5zd2VyJTIyJTNBJTIwYW5zd2VyJTJDJTBBJTIwJTIwJTIwJTIwJTIyc3RhcnQlMjIlM0ElMjBzdGFydF9jaGFyJTJDJTBBJTIwJTIwJTIwJTIwJTIyZW5kJTIyJTNBJTIwZW5kX2NoYXIlMkMlMEElMjAlMjAlMjAlMjAlMjJzY29yZSUyMiUzQSUyMHNjb3JlcyU1QnN0YXJ0X2luZGV4JTJDJTIwZW5kX2luZGV4JTVEJTJDJTBBJTdEJTBBcHJpbnQocmVzdWx0KQ==",highlighted:`result = {
    <span class="hljs-string">&quot;answer&quot;</span>: answer,
    <span class="hljs-string">&quot;start&quot;</span>: start_char,
    <span class="hljs-string">&quot;end&quot;</span>: end_char,
    <span class="hljs-string">&quot;score&quot;</span>: scores[start_index, end_index],
}
<span class="hljs-built_in">print</span>(result)`,wrap:!1}}),Rt=new h({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnSmF4JTJDJTIwUHlUb3JjaCUyMGFuZCUyMFRlbnNvckZsb3cnJTJDJTBBJTIwJ3N0YXJ0JyUzQSUyMDc4JTJDJTBBJTIwJ2VuZCclM0ElMjAxMDUlMkMlMEElMjAnc2NvcmUnJTNBJTIwMC45Nzc3MyU3RA==",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
 <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</span>}`,wrap:!1}}),st=new Zs({props:{$$slots:{default:[Qa]},$$scope:{ctx:b}}}),Vt=new Bs({props:{title:"處理長上下文",local:"處理長上下文",headingTag:"h2"}}),zt=new h({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0KSUwQXByaW50KGxlbihpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKQ==",highlighted:`inputs = tokenizer(question, long_context)
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">len</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Qt=new h({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Et=new h({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0JTJDJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUyMHRydW5jYXRpb24lM0QlMjJvbmx5X3NlY29uZCUyMiklMEFwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCkp",highlighted:`inputs = tokenizer(question, long_context, max_length=<span class="hljs-number">384</span>, truncation=<span class="hljs-string">&quot;only_second&quot;</span>)
<span class="hljs-built_in">print</span>(tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Yt=new h({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU1RCUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwcHJvdmlkZXMlMjBBUElzJTIwdG8lMjBxdWlja2x5JTIwZG93bmxvYWQlMjBhbmQlMjB1c2UlMjB0aG9zZSUyMHByZXRyYWluZWQlMjBtb2RlbHMlMjBvbiUyMGElMjBnaXZlbiUyMHRleHQlMkMlMjBmaW5lLXR1bmUlMjB0aGVtJTIwb24lMjB5b3VyJTIwb3duJTIwZGF0YXNldHMlMjBhbmQlMEF0aGVuJTIwc2hhcmUlMjB0aGVtJTIwd2l0aCUyMHRoZSUyMGNvbW11bml0eSUyMG9uJTIwb3VyJTIwbW9kZWwlMjBodWIuJTIwQXQlMjB0aGUlMjBzYW1lJTIwdGltZSUyQyUyMGVhY2glMjBweXRob24lMjBtb2R1bGUlMjBkZWZpbmluZyUyMGFuJTIwYXJjaGl0ZWN0dXJlJTIwaXMlMjBmdWxseSUyMHN0YW5kYWxvbmUlMjBhbmQlMEFjYW4lMjBiZSUyMG1vZGlmaWVkJTIwdG8lMjBlbmFibGUlMjBxdWljayUyMHJlc2VhcmNoJTIwZXhwZXJpbWVudHMuJTBBJTBBV2h5JTIwc2hvdWxkJTIwSSUyMHVzZSUyMHRyYW5zZm9ybWVycyUzRiUwQSUwQTEuJTIwRWFzeS10by11c2UlMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTNBJTBBJTIwJTIwLSUyMEhpZ2glMjBwZXJmb3JtYW5jZSUyMG9uJTIwTkxVJTIwYW5kJTIwTkxHJTIwdGFza3MuJTBBJTIwJTIwLSUyMExvdyUyMGJhcnJpZXIlMjB0byUyMGVudHJ5JTIwZm9yJTIwZWR1Y2F0b3JzJTIwYW5kJTIwcHJhY3RpdGlvbmVycy4lMEElMjAlMjAtJTIwRmV3JTIwdXNlci1mYWNpbmclMjBhYnN0cmFjdGlvbnMlMjB3aXRoJTIwanVzdCUyMHRocmVlJTIwY2xhc3NlcyUyMHRvJTIwbGVhcm4uJTBBJTIwJTIwLSUyMEElMjB1bmlmaWVkJTIwQVBJJTIwZm9yJTIwdXNpbmclMjBhbGwlMjBvdXIlMjBwcmV0cmFpbmVkJTIwbW9kZWxzLiUwQSUyMCUyMC0lMjBMb3dlciUyMGNvbXB1dGUlMjBjb3N0cyUyQyUyMHNtYWxsZXIlMjBjYXJib24lMjBmb290cHJpbnQlM0ElMEElMEEyLiUyMFJlc2VhcmNoZXJzJTIwY2FuJTIwc2hhcmUlMjB0cmFpbmVkJTIwbW9kZWxzJTIwaW5zdGVhZCUyMG9mJTIwYWx3YXlzJTIwcmV0cmFpbmluZy4lMEElMjAlMjAtJTIwUHJhY3RpdGlvbmVycyUyMGNhbiUyMHJlZHVjZSUyMGNvbXB1dGUlMjB0aW1lJTIwYW5kJTIwcHJvZHVjdGlvbiUyMGNvc3RzLiUwQSUyMCUyMC0lMjBEb3plbnMlMjBvZiUyMGFyY2hpdGVjdHVyZXMlMjB3aXRoJTIwb3ZlciUyMDEwJTJDMDAwJTIwcHJldHJhaW5lZCUyMG1vZGVscyUyQyUyMHNvbWUlMjBpbiUyMG1vcmUlMjB0aGFuJTIwMTAwJTIwbGFuZ3VhZ2VzLiUwQSUwQTMuJTIwQ2hvb3NlJTIwdGhlJTIwcmlnaHQlMjBmcmFtZXdvcmslMjBmb3IlMjBldmVyeSUyMHBhcnQlMjBvZiUyMGElMjBtb2RlbCdzJTIwbGlmZXRpbWUlM0ElMEElMjAlMjAtJTIwVHJhaW4lMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTIwaW4lMjAzJTIwbGluZXMlMjBvZiUyMGNvZGUuJTBBJTIwJTIwLSUyME1vdmUlMjBhJTIwc2luZ2xlJTIwbW9kZWwlMjBiZXR3ZWVuJTIwVEYyLjAlMkZQeVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",highlighted:`<span class="hljs-string">&quot;&quot;&quot;
[CLS] Which deep learning libraries back [UNK] Transformers? [SEP] [UNK] Transformers : State of the Art NLP

[UNK] Transformers provides thousands of pretrained models to perform tasks on texts such as classification, information extraction,
question answering, summarization, translation, text generation and more in over 100 languages.
Its aim is to make cutting-edge NLP easier to use for everyone.

[UNK] Transformers provides APIs to quickly download and use those pretrained models on a given text, fine-tune them on your own datasets and
then share them with the community on our model hub. At the same time, each python module defining an architecture is fully standalone and
can be modified to enable quick research experiments.

Why should I use transformers?

1. Easy-to-use state-of-the-art models:
  - High performance on NLU and NLG tasks.
  - Low barrier to entry for educators and practitioners.
  - Few user-facing abstractions with just three classes to learn.
  - A unified API for using all our pretrained models.
  - Lower compute costs, smaller carbon footprint:

2. Researchers can share trained models instead of always retraining.
  - Practitioners can reduce compute time and production costs.
  - Dozens of architectures with over 10,000 pretrained models, some in more than 100 languages.

3. Choose the right framework for every part of a model&#x27;s lifetime:
  - Train state-of-the-art models in 3 lines of code.
  - Move a single model between TF2.0/PyTorch frameworks at will.
  - Seamlessly pick the right framework for training, evaluation and production.

4. Easily customize a model or an example to your needs:
  - We provide examples for each architecture to reproduce the results published by its original authors.
  - Model internal [SEP]
&quot;&quot;&quot;</span>`,wrap:!1}}),At=new h({props:{code:"c2VudGVuY2UlMjAlM0QlMjAlMjJUaGlzJTIwc2VudGVuY2UlMjBpcyUyMG5vdCUyMHRvbyUyMGxvbmclMjBidXQlMjB3ZSUyMGFyZSUyMGdvaW5nJTIwdG8lMjBzcGxpdCUyMGl0JTIwYW55d2F5LiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjBzZW50ZW5jZSUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTJDJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMjBtYXhfbGVuZ3RoJTNENiUyQyUyMHN0cmlkZSUzRDIlMEEpJTBBJTBBZm9yJTIwaWRzJTIwaW4lMjBpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlM0ElMEElMjAlMjAlMjAlMjBwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlkcykp",highlighted:`sentence = <span class="hljs-string">&quot;This sentence is not too long but we are going to split it anyway.&quot;</span>
inputs = tokenizer(
    sentence, truncation=<span class="hljs-literal">True</span>, return_overflowing_tokens=<span class="hljs-literal">True</span>, max_length=<span class="hljs-number">6</span>, stride=<span class="hljs-number">2</span>
)

<span class="hljs-keyword">for</span> ids <span class="hljs-keyword">in</span> inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]:
    <span class="hljs-built_in">print</span>(tokenizer.decode(ids))`,wrap:!1}}),qt=new h({props:{code:"JyU1QkNMUyU1RCUyMFRoaXMlMjBzZW50ZW5jZSUyMGlzJTIwbm90JTIwJTVCU0VQJTVEJyUwQSclNUJDTFMlNUQlMjBpcyUyMG5vdCUyMHRvbyUyMGxvbmclMjAlNUJTRVAlNUQnJTBBJyU1QkNMUyU1RCUyMHRvbyUyMGxvbmclMjBidXQlMjB3ZSUyMCU1QlNFUCU1RCclMEEnJTVCQ0xTJTVEJTIwYnV0JTIwd2UlMjBhcmUlMjBnb2luZyUyMCU1QlNFUCU1RCclMEEnJTVCQ0xTJTVEJTIwYXJlJTIwZ29pbmclMjB0byUyMHNwbGl0JTIwJTVCU0VQJTVEJyUwQSclNUJDTFMlNUQlMjB0byUyMHNwbGl0JTIwaXQlMjBhbnl3YXklMjAlNUJTRVAlNUQnJTBBJyU1QkNMUyU1RCUyMGl0JTIwYW55d2F5LiUyMCU1QlNFUCU1RCc=",highlighted:`<span class="hljs-string">&#x27;[CLS] This sentence is not [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] is not too long [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] too long but we [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] but we are going [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] are going to split [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] to split it anyway [SEP]&#x27;</span>
<span class="hljs-string">&#x27;[CLS] it anyway. [SEP]&#x27;</span>`,wrap:!1}}),Pt=new h({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Kt=new h({props:{code:"ZGljdF9rZXlzKCU1QidpbnB1dF9pZHMnJTJDJTIwJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyclNUQp",highlighted:'dict_keys([<span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;overflow_to_sample_mapping&#x27;</span>])',wrap:!1}}),tl=new h({props:{code:"cHJpbnQoaW5wdXRzJTVCJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIlNUQp",highlighted:'<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>])',wrap:!1}}),ll=new h({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RA==",highlighted:'[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]',wrap:!1}}),sl=new h({props:{code:"c2VudGVuY2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIyVGhpcyUyMHNlbnRlbmNlJTIwaXMlMjBub3QlMjB0b28lMjBsb25nJTIwYnV0JTIwd2UlMjBhcmUlMjBnb2luZyUyMHRvJTIwc3BsaXQlMjBpdCUyMGFueXdheS4lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJUaGlzJTIwc2VudGVuY2UlMjBpcyUyMHNob3J0ZXIlMjBidXQlMjB3aWxsJTIwc3RpbGwlMjBnZXQlMjBzcGxpdC4lMjIlMkMlMEElNUQlMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwc2VudGVuY2VzJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUlMkMlMjByZXR1cm5fb3ZlcmZsb3dpbmdfdG9rZW5zJTNEVHJ1ZSUyQyUyMG1heF9sZW5ndGglM0Q2JTJDJTIwc3RyaWRlJTNEMiUwQSklMEElMEFwcmludChpbnB1dHMlNUIlMjJvdmVyZmxvd190b19zYW1wbGVfbWFwcGluZyUyMiU1RCk=",highlighted:`sentences = [
    <span class="hljs-string">&quot;This sentence is not too long but we are going to split it anyway.&quot;</span>,
    <span class="hljs-string">&quot;This sentence is shorter but will still get split.&quot;</span>,
]
inputs = tokenizer(
    sentences, truncation=<span class="hljs-literal">True</span>, return_overflowing_tokens=<span class="hljs-literal">True</span>, max_length=<span class="hljs-number">6</span>, stride=<span class="hljs-number">2</span>
)

<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>])`,wrap:!1}}),al=new h({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElNUQ=",highlighted:'[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]',wrap:!1}}),ml=new h({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHF1ZXN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwbG9uZ19jb250ZXh0JTJDJTBBJTIwJTIwJTIwJTIwc3RyaWRlJTNEMTI4JTJDJTBBJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUwQSUyMCUyMCUyMCUyMHBhZGRpbmclM0QlMjJsb25nZXN0JTIyJTJDJTBBJTIwJTIwJTIwJTIwdHJ1bmNhdGlvbiUzRCUyMm9ubHlfc2Vjb25kJTIyJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`inputs = tokenizer(
    question,
    long_context,
    stride=<span class="hljs-number">128</span>,
    max_length=<span class="hljs-number">384</span>,
    padding=<span class="hljs-string">&quot;longest&quot;</span>,
    truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
    return_overflowing_tokens=<span class="hljs-literal">True</span>,
    return_offsets_mapping=<span class="hljs-literal">True</span>,
)`,wrap:!1}});const On=[Ea,Ha],kl=[];function ta(t,s){return t[0]==="pt"?0:1}E=ta(b),Y=kl[E]=On[E](b),cl=new h({props:{code:"b3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQXN0YXJ0X2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuc3RhcnRfbG9naXRzJTBBZW5kX2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuZW5kX2xvZ2l0cyUwQXByaW50KHN0YXJ0X2xvZ2l0cy5zaGFwZSUyQyUyMGVuZF9sb2dpdHMuc2hhcGUp",highlighted:`outputs = model(**inputs)

start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const la=[Fa,Ya],vl=[];function ea(t,s){return t[0]==="pt"?0:1}F=ea(b),S=vl[F]=la[F](b);const sa=[Aa,Sa],Gl=[];function na(t,s){return t[0]==="pt"?0:1}A=na(b),q=Gl[A]=sa[A](b);const aa=[La,qa],Cl=[];function ra(t,s){return t[0]==="pt"?0:1}L=ra(b),D=Cl[L]=aa[L](b);const ia=[Pa,Da],xl=[];function ma(t,s){return t[0]==="pt"?0:1}return P=ma(b),K=xl[P]=ia[P](b),ul=new h({props:{code:"JTVCKDAlMkMlMjAxOCUyQyUyMDAuMzM4NjcpJTJDJTIwKDE3MyUyQyUyMDE4NCUyQyUyMDAuOTcxNDkpJTVE",highlighted:'[(<span class="hljs-number">0</span>, <span class="hljs-number">18</span>, <span class="hljs-number">0.33867</span>), (<span class="hljs-number">173</span>, <span class="hljs-number">184</span>, <span class="hljs-number">0.97149</span>)]',wrap:!1}}),nt=new Zs({props:{$$slots:{default:[Ka]},$$scope:{ctx:b}}}),Tl=new h({props:{code:"Zm9yJTIwY2FuZGlkYXRlJTJDJTIwb2Zmc2V0JTIwaW4lMjB6aXAoY2FuZGlkYXRlcyUyQyUyMG9mZnNldHMpJTNBJTBBJTIwJTIwJTIwJTIwc3RhcnRfdG9rZW4lMkMlMjBlbmRfdG9rZW4lMkMlMjBzY29yZSUyMCUzRCUyMGNhbmRpZGF0ZSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2NoYXIlMkMlMjBfJTIwJTNEJTIwb2Zmc2V0JTVCc3RhcnRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXQlNUJlbmRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBhbnN3ZXIlMjAlM0QlMjBsb25nX2NvbnRleHQlNUJzdGFydF9jaGFyJTNBZW5kX2NoYXIlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjAlN0IlMjJhbnN3ZXIlMjIlM0ElMjBhbnN3ZXIlMkMlMjAlMjJzdGFydCUyMiUzQSUyMHN0YXJ0X2NoYXIlMkMlMjAlMjJlbmQlMjIlM0ElMjBlbmRfY2hhciUyQyUyMCUyMnNjb3JlJTIyJTNBJTIwc2NvcmUlN0QlMEElMjAlMjAlMjAlMjBwcmludChyZXN1bHQp",highlighted:`<span class="hljs-keyword">for</span> candidate, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(candidates, offsets):
    start_token, end_token, score = candidate
    start_char, _ = offset[start_token]
    _, end_char = offset[end_token]
    answer = long_context[start_char:end_char]
    result = {<span class="hljs-string">&quot;answer&quot;</span>: answer, <span class="hljs-string">&quot;start&quot;</span>: start_char, <span class="hljs-string">&quot;end&quot;</span>: end_char, <span class="hljs-string">&quot;score&quot;</span>: score}
    <span class="hljs-built_in">print</span>(result)`,wrap:!1}}),dl=new h({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnJTVDbiVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUzQSUyMFN0YXRlJTIwb2YlMjB0aGUlMjBBcnQlMjBOTFAnJTJDJTIwJ3N0YXJ0JyUzQSUyMDAlMkMlMjAnZW5kJyUzQSUyMDM3JTJDJTIwJ3Njb3JlJyUzQSUyMDAuMzM4NjclN0QlMEElN0InYW5zd2VyJyUzQSUyMCdKYXglMkMlMjBQeVRvcmNoJTIwYW5kJTIwVGVuc29yRmxvdyclMkMlMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUyMCdlbmQnJTNBJTIwMTkxOSUyQyUyMCdzY29yZSclM0ElMjAwLjk3MTQ5JTdE",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;\\n🤗 Transformers: State of the Art NLP&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">37</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.33867</span>}
{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>}`,wrap:!1}}),at=new Zs({props:{$$slots:{default:[Oa]},$$scope:{ctx:b}}}),fl=new _a({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter6/3b.mdx"}}),{c(){e=T("meta"),r=i(),l=T("p"),c=i(),M(w.$$.fragment),f=i(),M(j.$$.fragment),Ol=i(),k.c(),Wl=i(),mt=T("p"),mt.innerHTML=Ls,te=i(),G.c(),Rl=i(),M(pt.$$.fragment),le=i(),ot=T("p"),ot.innerHTML=Ds,ee=i(),M(ct.$$.fragment),se=i(),M(Mt.$$.fragment),ne=i(),Jt=T("p"),Jt.textContent=Ps,ae=i(),M(yt.$$.fragment),re=i(),M(ut.$$.fragment),ie=i(),bt=T("p"),bt.textContent=Ks,me=i(),M(wt.$$.fragment),pe=i(),Tt=T("p"),Tt.innerHTML=Os,oe=i(),x.c(),Nl=i(),dt=T("p"),dt.textContent=tn,ce=i(),lt=T("div"),lt.innerHTML=ln,Me=i(),ht=T("p"),ht.textContent=en,Je=i(),M(Ut.$$.fragment),ye=i(),R.c(),Vl=i(),ft=T("p"),ft.innerHTML=sn,ue=i(),jt=T("p"),jt.innerHTML=nn,be=i(),V.c(),Xl=i(),It=T("p"),It.textContent=an,we=i(),z.c(),zl=i(),_t=T("p"),_t.innerHTML=rn,Te=i(),I=T("p"),ks=rt("假設事件“答案開始於 "),Ql=T("strong"),Ql.textContent=mn,vs=rt(" ”和“答案結束於 "),Hl=T("strong"),Hl.textContent=pn,Gs=rt(" ” 要獨立，答案開始於的概率 "),El=T("strong"),El.textContent=on,Cs=rt(" 並結束於 "),Yl=T("strong"),Yl.textContent=cn,xs=rt(` 是：
`),de=new Ja(!1),he=i(),O=T("p"),Ws=rt("所以，要計算所有的分數，我們只需要計算所有的產品"),Ue=new Ja(!1),fe=rt(" where "),Fl=T("code"),Fl.textContent=Mn,Rs=rt("."),je=i(),gt=T("p"),gt.textContent=Jn,Ie=i(),M(Zt.$$.fragment),_e=i(),H.c(),Sl=i(),Bt=T("p"),Bt.innerHTML=yn,ge=i(),M($t.$$.fragment),Ze=i(),kt=T("p"),kt.textContent=un,Be=i(),M(vt.$$.fragment),$e=i(),M(et.$$.fragment),ke=i(),Gt=T("p"),Gt.innerHTML=bn,ve=i(),M(Ct.$$.fragment),Ge=i(),xt=T("p"),xt.textContent=wn,Ce=i(),M(Wt.$$.fragment),xe=i(),M(Rt.$$.fragment),We=i(),Nt=T("p"),Nt.textContent=Tn,Re=i(),M(st.$$.fragment),Ne=i(),M(Vt.$$.fragment),Ve=i(),Xt=T("p"),Xt.innerHTML=dn,Xe=i(),M(zt.$$.fragment),ze=i(),M(Qt.$$.fragment),Qe=i(),Ht=T("p"),Ht.innerHTML=hn,He=i(),M(Et.$$.fragment),Ee=i(),M(Yt.$$.fragment),Ye=i(),Ft=T("p"),Ft.innerHTML=Un,Fe=i(),St=T("p"),St.innerHTML=fn,Se=i(),M(At.$$.fragment),Ae=i(),M(qt.$$.fragment),qe=i(),Lt=T("p"),Lt.innerHTML=jn,Le=i(),Dt=T("p"),Dt.textContent=In,De=i(),M(Pt.$$.fragment),Pe=i(),M(Kt.$$.fragment),Ke=i(),Ot=T("p"),Ot.innerHTML=_n,Oe=i(),M(tl.$$.fragment),ts=i(),M(ll.$$.fragment),ls=i(),el=T("p"),el.textContent=gn,es=i(),M(sl.$$.fragment),ss=i(),nl=T("p"),nl.textContent=Zn,ns=i(),M(al.$$.fragment),as=i(),rl=T("p"),rl.textContent=Bn,rs=i(),il=T("p"),il.innerHTML=$n,is=i(),M(ml.$$.fragment),ms=i(),pl=T("p"),pl.innerHTML=kn,ps=i(),Y.c(),Al=i(),ol=T("p"),ol.textContent=vn,os=i(),M(cl.$$.fragment),cs=i(),S.c(),ql=i(),Ml=T("p"),Ml.textContent=Gn,Ms=i(),q.c(),Ll=i(),Jl=T("p"),Jl.textContent=Cn,Js=i(),D.c(),Dl=i(),yl=T("p"),yl.textContent=xn,ys=i(),K.c(),Pl=i(),M(ul.$$.fragment),us=i(),bl=T("p"),bl.textContent=Wn,bs=i(),M(nt.$$.fragment),ws=i(),wl=T("p"),wl.innerHTML=Rn,Ts=i(),M(Tl.$$.fragment),ds=i(),M(dl.$$.fragment),hs=i(),hl=T("p"),hl.textContent=Nn,Us=i(),M(at.$$.fragment),fs=i(),Ul=T("p"),Ul.textContent=Vn,js=i(),M(fl.$$.fragment),Is=i(),Kl=T("p"),this.h()},l(t){const s=ja("svelte-u9bgzb",document.head);e=d(s,"META",{name:!0,content:!0}),s.forEach(n),r=m(t),l=d(t,"P",{}),gs(l).forEach(n),c=m(t),J(w.$$.fragment,t),f=m(t),J(j.$$.fragment,t),Ol=m(t),k.l(t),Wl=m(t),mt=d(t,"P",{"data-svelte-h":!0}),U(mt)!=="svelte-1es6raf"&&(mt.innerHTML=Ls),te=m(t),G.l(t),Rl=m(t),J(pt.$$.fragment,t),le=m(t),ot=d(t,"P",{"data-svelte-h":!0}),U(ot)!=="svelte-1awydz0"&&(ot.innerHTML=Ds),ee=m(t),J(ct.$$.fragment,t),se=m(t),J(Mt.$$.fragment,t),ne=m(t),Jt=d(t,"P",{"data-svelte-h":!0}),U(Jt)!=="svelte-6pojq9"&&(Jt.textContent=Ps),ae=m(t),J(yt.$$.fragment,t),re=m(t),J(ut.$$.fragment,t),ie=m(t),bt=d(t,"P",{"data-svelte-h":!0}),U(bt)!=="svelte-fgyjer"&&(bt.textContent=Ks),me=m(t),J(wt.$$.fragment,t),pe=m(t),Tt=d(t,"P",{"data-svelte-h":!0}),U(Tt)!=="svelte-1h6i42m"&&(Tt.innerHTML=Os),oe=m(t),x.l(t),Nl=m(t),dt=d(t,"P",{"data-svelte-h":!0}),U(dt)!=="svelte-99imm6"&&(dt.textContent=tn),ce=m(t),lt=d(t,"DIV",{class:!0,"data-svelte-h":!0}),U(lt)!=="svelte-47wedv"&&(lt.innerHTML=ln),Me=m(t),ht=d(t,"P",{"data-svelte-h":!0}),U(ht)!=="svelte-tr2r9i"&&(ht.textContent=en),Je=m(t),J(Ut.$$.fragment,t),ye=m(t),R.l(t),Vl=m(t),ft=d(t,"P",{"data-svelte-h":!0}),U(ft)!=="svelte-cmx067"&&(ft.innerHTML=sn),ue=m(t),jt=d(t,"P",{"data-svelte-h":!0}),U(jt)!=="svelte-pem99v"&&(jt.innerHTML=nn),be=m(t),V.l(t),Xl=m(t),It=d(t,"P",{"data-svelte-h":!0}),U(It)!=="svelte-tkv9lz"&&(It.textContent=an),we=m(t),z.l(t),zl=m(t),_t=d(t,"P",{"data-svelte-h":!0}),U(_t)!=="svelte-1da74n7"&&(_t.innerHTML=rn),Te=m(t),I=d(t,"P",{});var _=gs(I);ks=it(_,"假設事件“答案開始於 "),Ql=d(_,"STRONG",{"data-svelte-h":!0}),U(Ql)!=="svelte-mrepff"&&(Ql.textContent=mn),vs=it(_," ”和“答案結束於 "),Hl=d(_,"STRONG",{"data-svelte-h":!0}),U(Hl)!=="svelte-wrb9ic"&&(Hl.textContent=pn),Gs=it(_," ” 要獨立，答案開始於的概率 "),El=d(_,"STRONG",{"data-svelte-h":!0}),U(El)!=="svelte-mrepff"&&(El.textContent=on),Cs=it(_," 並結束於 "),Yl=d(_,"STRONG",{"data-svelte-h":!0}),U(Yl)!=="svelte-wrb9ic"&&(Yl.textContent=cn),xs=it(_,` 是：
`),de=ya(_,!1),_.forEach(n),he=m(t),O=d(t,"P",{});var tt=gs(O);Ws=it(tt,"所以，要計算所有的分數，我們只需要計算所有的產品"),Ue=ya(tt,!1),fe=it(tt," where "),Fl=d(tt,"CODE",{"data-svelte-h":!0}),U(Fl)!=="svelte-1kp3szf"&&(Fl.textContent=Mn),Rs=it(tt,"."),tt.forEach(n),je=m(t),gt=d(t,"P",{"data-svelte-h":!0}),U(gt)!=="svelte-ooq7u2"&&(gt.textContent=Jn),Ie=m(t),J(Zt.$$.fragment,t),_e=m(t),H.l(t),Sl=m(t),Bt=d(t,"P",{"data-svelte-h":!0}),U(Bt)!=="svelte-1tf4nt5"&&(Bt.innerHTML=yn),ge=m(t),J($t.$$.fragment,t),Ze=m(t),kt=d(t,"P",{"data-svelte-h":!0}),U(kt)!=="svelte-1atzg7i"&&(kt.textContent=un),Be=m(t),J(vt.$$.fragment,t),$e=m(t),J(et.$$.fragment,t),ke=m(t),Gt=d(t,"P",{"data-svelte-h":!0}),U(Gt)!=="svelte-bgxhl0"&&(Gt.innerHTML=bn),ve=m(t),J(Ct.$$.fragment,t),Ge=m(t),xt=d(t,"P",{"data-svelte-h":!0}),U(xt)!=="svelte-4n6hkj"&&(xt.textContent=wn),Ce=m(t),J(Wt.$$.fragment,t),xe=m(t),J(Rt.$$.fragment,t),We=m(t),Nt=d(t,"P",{"data-svelte-h":!0}),U(Nt)!=="svelte-yawc34"&&(Nt.textContent=Tn),Re=m(t),J(st.$$.fragment,t),Ne=m(t),J(Vt.$$.fragment,t),Ve=m(t),Xt=d(t,"P",{"data-svelte-h":!0}),U(Xt)!=="svelte-1muk70g"&&(Xt.innerHTML=dn),Xe=m(t),J(zt.$$.fragment,t),ze=m(t),J(Qt.$$.fragment,t),Qe=m(t),Ht=d(t,"P",{"data-svelte-h":!0}),U(Ht)!=="svelte-1enzoac"&&(Ht.innerHTML=hn),He=m(t),J(Et.$$.fragment,t),Ee=m(t),J(Yt.$$.fragment,t),Ye=m(t),Ft=d(t,"P",{"data-svelte-h":!0}),U(Ft)!=="svelte-30y3h"&&(Ft.innerHTML=Un),Fe=m(t),St=d(t,"P",{"data-svelte-h":!0}),U(St)!=="svelte-41f44v"&&(St.innerHTML=fn),Se=m(t),J(At.$$.fragment,t),Ae=m(t),J(qt.$$.fragment,t),qe=m(t),Lt=d(t,"P",{"data-svelte-h":!0}),U(Lt)!=="svelte-4zomzx"&&(Lt.innerHTML=jn),Le=m(t),Dt=d(t,"P",{"data-svelte-h":!0}),U(Dt)!=="svelte-1kq1278"&&(Dt.textContent=In),De=m(t),J(Pt.$$.fragment,t),Pe=m(t),J(Kt.$$.fragment,t),Ke=m(t),Ot=d(t,"P",{"data-svelte-h":!0}),U(Ot)!=="svelte-1p9jn19"&&(Ot.innerHTML=_n),Oe=m(t),J(tl.$$.fragment,t),ts=m(t),J(ll.$$.fragment,t),ls=m(t),el=d(t,"P",{"data-svelte-h":!0}),U(el)!=="svelte-3cpg2i"&&(el.textContent=gn),es=m(t),J(sl.$$.fragment,t),ss=m(t),nl=d(t,"P",{"data-svelte-h":!0}),U(nl)!=="svelte-110kj3t"&&(nl.textContent=Zn),ns=m(t),J(al.$$.fragment,t),as=m(t),rl=d(t,"P",{"data-svelte-h":!0}),U(rl)!=="svelte-l8lrf9"&&(rl.textContent=Bn),rs=m(t),il=d(t,"P",{"data-svelte-h":!0}),U(il)!=="svelte-1tpvsga"&&(il.innerHTML=$n),is=m(t),J(ml.$$.fragment,t),ms=m(t),pl=d(t,"P",{"data-svelte-h":!0}),U(pl)!=="svelte-hwr3uf"&&(pl.innerHTML=kn),ps=m(t),Y.l(t),Al=m(t),ol=d(t,"P",{"data-svelte-h":!0}),U(ol)!=="svelte-17nwfy2"&&(ol.textContent=vn),os=m(t),J(cl.$$.fragment,t),cs=m(t),S.l(t),ql=m(t),Ml=d(t,"P",{"data-svelte-h":!0}),U(Ml)!=="svelte-ef6u09"&&(Ml.textContent=Gn),Ms=m(t),q.l(t),Ll=m(t),Jl=d(t,"P",{"data-svelte-h":!0}),U(Jl)!=="svelte-1ad2oof"&&(Jl.textContent=Cn),Js=m(t),D.l(t),Dl=m(t),yl=d(t,"P",{"data-svelte-h":!0}),U(yl)!=="svelte-w3qxvo"&&(yl.textContent=xn),ys=m(t),K.l(t),Pl=m(t),J(ul.$$.fragment,t),us=m(t),bl=d(t,"P",{"data-svelte-h":!0}),U(bl)!=="svelte-15fc8pg"&&(bl.textContent=Wn),bs=m(t),J(nt.$$.fragment,t),ws=m(t),wl=d(t,"P",{"data-svelte-h":!0}),U(wl)!=="svelte-1ef7syq"&&(wl.innerHTML=Rn),Ts=m(t),J(Tl.$$.fragment,t),ds=m(t),J(dl.$$.fragment,t),hs=m(t),hl=d(t,"P",{"data-svelte-h":!0}),U(hl)!=="svelte-dqro2f"&&(hl.textContent=Nn),Us=m(t),J(at.$$.fragment,t),fs=m(t),Ul=d(t,"P",{"data-svelte-h":!0}),U(Ul)!=="svelte-1rdohsq"&&(Ul.textContent=Vn),js=m(t),J(fl.$$.fragment,t),Is=m(t),Kl=d(t,"P",{}),gs(Kl).forEach(n),this.h()},h(){qs(e,"name","hf:doc:metadata"),qs(e,"content",lr),qs(lt,"class","flex justify-center"),de.a=null,Ue.a=fe},m(t,s){g(document.head,e),a(t,r,s),a(t,l,s),a(t,c,s),y(w,t,s),a(t,f,s),y(j,t,s),a(t,Ol,s),jl[$].m(t,s),a(t,Wl,s),a(t,mt,s),a(t,te,s),Il[v].m(t,s),a(t,Rl,s),y(pt,t,s),a(t,le,s),a(t,ot,s),a(t,ee,s),y(ct,t,s),a(t,se,s),y(Mt,t,s),a(t,ne,s),a(t,Jt,s),a(t,ae,s),y(yt,t,s),a(t,re,s),y(ut,t,s),a(t,ie,s),a(t,bt,s),a(t,me,s),y(wt,t,s),a(t,pe,s),a(t,Tt,s),a(t,oe,s),_l[C].m(t,s),a(t,Nl,s),a(t,dt,s),a(t,ce,s),a(t,lt,s),a(t,Me,s),a(t,ht,s),a(t,Je,s),y(Ut,t,s),a(t,ye,s),gl[W].m(t,s),a(t,Vl,s),a(t,ft,s),a(t,ue,s),a(t,jt,s),a(t,be,s),Zl[N].m(t,s),a(t,Xl,s),a(t,It,s),a(t,we,s),Bl[X].m(t,s),a(t,zl,s),a(t,_t,s),a(t,Te,s),a(t,I,s),g(I,ks),g(I,Ql),g(I,vs),g(I,Hl),g(I,Gs),g(I,El),g(I,Cs),g(I,Yl),g(I,xs),de.m(wa,I),a(t,he,s),a(t,O,s),g(O,Ws),Ue.m(Ta,O),g(O,fe),g(O,Fl),g(O,Rs),a(t,je,s),a(t,gt,s),a(t,Ie,s),y(Zt,t,s),a(t,_e,s),$l[Q].m(t,s),a(t,Sl,s),a(t,Bt,s),a(t,ge,s),y($t,t,s),a(t,Ze,s),a(t,kt,s),a(t,Be,s),y(vt,t,s),a(t,$e,s),y(et,t,s),a(t,ke,s),a(t,Gt,s),a(t,ve,s),y(Ct,t,s),a(t,Ge,s),a(t,xt,s),a(t,Ce,s),y(Wt,t,s),a(t,xe,s),y(Rt,t,s),a(t,We,s),a(t,Nt,s),a(t,Re,s),y(st,t,s),a(t,Ne,s),y(Vt,t,s),a(t,Ve,s),a(t,Xt,s),a(t,Xe,s),y(zt,t,s),a(t,ze,s),y(Qt,t,s),a(t,Qe,s),a(t,Ht,s),a(t,He,s),y(Et,t,s),a(t,Ee,s),y(Yt,t,s),a(t,Ye,s),a(t,Ft,s),a(t,Fe,s),a(t,St,s),a(t,Se,s),y(At,t,s),a(t,Ae,s),y(qt,t,s),a(t,qe,s),a(t,Lt,s),a(t,Le,s),a(t,Dt,s),a(t,De,s),y(Pt,t,s),a(t,Pe,s),y(Kt,t,s),a(t,Ke,s),a(t,Ot,s),a(t,Oe,s),y(tl,t,s),a(t,ts,s),y(ll,t,s),a(t,ls,s),a(t,el,s),a(t,es,s),y(sl,t,s),a(t,ss,s),a(t,nl,s),a(t,ns,s),y(al,t,s),a(t,as,s),a(t,rl,s),a(t,rs,s),a(t,il,s),a(t,is,s),y(ml,t,s),a(t,ms,s),a(t,pl,s),a(t,ps,s),kl[E].m(t,s),a(t,Al,s),a(t,ol,s),a(t,os,s),y(cl,t,s),a(t,cs,s),vl[F].m(t,s),a(t,ql,s),a(t,Ml,s),a(t,Ms,s),Gl[A].m(t,s),a(t,Ll,s),a(t,Jl,s),a(t,Js,s),Cl[L].m(t,s),a(t,Dl,s),a(t,yl,s),a(t,ys,s),xl[P].m(t,s),a(t,Pl,s),y(ul,t,s),a(t,us,s),a(t,bl,s),a(t,bs,s),y(nt,t,s),a(t,ws,s),a(t,wl,s),a(t,Ts,s),y(Tl,t,s),a(t,ds,s),y(dl,t,s),a(t,hs,s),a(t,hl,s),a(t,Us,s),y(at,t,s),a(t,fs,s),a(t,Ul,s),a(t,js,s),y(fl,t,s),a(t,Is,s),a(t,Kl,s),_s=!0},p(t,[s]){const _={};s&1&&(_.fw=t[0]),w.$set(_);let tt=$;$=zn(t),$!==tt&&(B(),p(jl[tt],1,1,()=>{jl[tt]=null}),Z(),k=jl[$],k||(k=jl[$]=Xn[$](t),k.c()),o(k,1),k.m(Wl.parentNode,Wl));let Ns=v;v=Hn(t),v!==Ns&&(B(),p(Il[Ns],1,1,()=>{Il[Ns]=null}),Z(),G=Il[v],G||(G=Il[v]=Qn[v](t),G.c()),o(G,1),G.m(Rl.parentNode,Rl));let Vs=C;C=Yn(t),C!==Vs&&(B(),p(_l[Vs],1,1,()=>{_l[Vs]=null}),Z(),x=_l[C],x||(x=_l[C]=En[C](t),x.c()),o(x,1),x.m(Nl.parentNode,Nl));let Xs=W;W=Sn(t),W!==Xs&&(B(),p(gl[Xs],1,1,()=>{gl[Xs]=null}),Z(),R=gl[W],R||(R=gl[W]=Fn[W](t),R.c()),o(R,1),R.m(Vl.parentNode,Vl));let zs=N;N=qn(t),N!==zs&&(B(),p(Zl[zs],1,1,()=>{Zl[zs]=null}),Z(),V=Zl[N],V||(V=Zl[N]=An[N](t),V.c()),o(V,1),V.m(Xl.parentNode,Xl));let Qs=X;X=Dn(t),X!==Qs&&(B(),p(Bl[Qs],1,1,()=>{Bl[Qs]=null}),Z(),z=Bl[X],z||(z=Bl[X]=Ln[X](t),z.c()),o(z,1),z.m(zl.parentNode,zl));let Hs=Q;Q=Kn(t),Q!==Hs&&(B(),p($l[Hs],1,1,()=>{$l[Hs]=null}),Z(),H=$l[Q],H||(H=$l[Q]=Pn[Q](t),H.c()),o(H,1),H.m(Sl.parentNode,Sl));const pa={};s&2&&(pa.$$scope={dirty:s,ctx:t}),et.$set(pa);const oa={};s&2&&(oa.$$scope={dirty:s,ctx:t}),st.$set(oa);let Es=E;E=ta(t),E!==Es&&(B(),p(kl[Es],1,1,()=>{kl[Es]=null}),Z(),Y=kl[E],Y||(Y=kl[E]=On[E](t),Y.c()),o(Y,1),Y.m(Al.parentNode,Al));let Ys=F;F=ea(t),F!==Ys&&(B(),p(vl[Ys],1,1,()=>{vl[Ys]=null}),Z(),S=vl[F],S||(S=vl[F]=la[F](t),S.c()),o(S,1),S.m(ql.parentNode,ql));let Fs=A;A=na(t),A!==Fs&&(B(),p(Gl[Fs],1,1,()=>{Gl[Fs]=null}),Z(),q=Gl[A],q||(q=Gl[A]=sa[A](t),q.c()),o(q,1),q.m(Ll.parentNode,Ll));let Ss=L;L=ra(t),L!==Ss&&(B(),p(Cl[Ss],1,1,()=>{Cl[Ss]=null}),Z(),D=Cl[L],D||(D=Cl[L]=aa[L](t),D.c()),o(D,1),D.m(Dl.parentNode,Dl));let As=P;P=ma(t),P!==As&&(B(),p(xl[As],1,1,()=>{xl[As]=null}),Z(),K=xl[P],K||(K=xl[P]=ia[P](t),K.c()),o(K,1),K.m(Pl.parentNode,Pl));const ca={};s&2&&(ca.$$scope={dirty:s,ctx:t}),nt.$set(ca);const Ma={};s&2&&(Ma.$$scope={dirty:s,ctx:t}),at.$set(Ma)},i(t){_s||(o(w.$$.fragment,t),o(j.$$.fragment,t),o(k),o(G),o(pt.$$.fragment,t),o(ct.$$.fragment,t),o(Mt.$$.fragment,t),o(yt.$$.fragment,t),o(ut.$$.fragment,t),o(wt.$$.fragment,t),o(x),o(Ut.$$.fragment,t),o(R),o(V),o(z),o(Zt.$$.fragment,t),o(H),o($t.$$.fragment,t),o(vt.$$.fragment,t),o(et.$$.fragment,t),o(Ct.$$.fragment,t),o(Wt.$$.fragment,t),o(Rt.$$.fragment,t),o(st.$$.fragment,t),o(Vt.$$.fragment,t),o(zt.$$.fragment,t),o(Qt.$$.fragment,t),o(Et.$$.fragment,t),o(Yt.$$.fragment,t),o(At.$$.fragment,t),o(qt.$$.fragment,t),o(Pt.$$.fragment,t),o(Kt.$$.fragment,t),o(tl.$$.fragment,t),o(ll.$$.fragment,t),o(sl.$$.fragment,t),o(al.$$.fragment,t),o(ml.$$.fragment,t),o(Y),o(cl.$$.fragment,t),o(S),o(q),o(D),o(K),o(ul.$$.fragment,t),o(nt.$$.fragment,t),o(Tl.$$.fragment,t),o(dl.$$.fragment,t),o(at.$$.fragment,t),o(fl.$$.fragment,t),_s=!0)},o(t){p(w.$$.fragment,t),p(j.$$.fragment,t),p(k),p(G),p(pt.$$.fragment,t),p(ct.$$.fragment,t),p(Mt.$$.fragment,t),p(yt.$$.fragment,t),p(ut.$$.fragment,t),p(wt.$$.fragment,t),p(x),p(Ut.$$.fragment,t),p(R),p(V),p(z),p(Zt.$$.fragment,t),p(H),p($t.$$.fragment,t),p(vt.$$.fragment,t),p(et.$$.fragment,t),p(Ct.$$.fragment,t),p(Wt.$$.fragment,t),p(Rt.$$.fragment,t),p(st.$$.fragment,t),p(Vt.$$.fragment,t),p(zt.$$.fragment,t),p(Qt.$$.fragment,t),p(Et.$$.fragment,t),p(Yt.$$.fragment,t),p(At.$$.fragment,t),p(qt.$$.fragment,t),p(Pt.$$.fragment,t),p(Kt.$$.fragment,t),p(tl.$$.fragment,t),p(ll.$$.fragment,t),p(sl.$$.fragment,t),p(al.$$.fragment,t),p(ml.$$.fragment,t),p(Y),p(cl.$$.fragment,t),p(S),p(q),p(D),p(K),p(ul.$$.fragment,t),p(nt.$$.fragment,t),p(Tl.$$.fragment,t),p(dl.$$.fragment,t),p(at.$$.fragment,t),p(fl.$$.fragment,t),_s=!1},d(t){t&&(n(r),n(l),n(c),n(f),n(Ol),n(Wl),n(mt),n(te),n(Rl),n(le),n(ot),n(ee),n(se),n(ne),n(Jt),n(ae),n(re),n(ie),n(bt),n(me),n(pe),n(Tt),n(oe),n(Nl),n(dt),n(ce),n(lt),n(Me),n(ht),n(Je),n(ye),n(Vl),n(ft),n(ue),n(jt),n(be),n(Xl),n(It),n(we),n(zl),n(_t),n(Te),n(I),n(he),n(O),n(je),n(gt),n(Ie),n(_e),n(Sl),n(Bt),n(ge),n(Ze),n(kt),n(Be),n($e),n(ke),n(Gt),n(ve),n(Ge),n(xt),n(Ce),n(xe),n(We),n(Nt),n(Re),n(Ne),n(Ve),n(Xt),n(Xe),n(ze),n(Qe),n(Ht),n(He),n(Ee),n(Ye),n(Ft),n(Fe),n(St),n(Se),n(Ae),n(qe),n(Lt),n(Le),n(Dt),n(De),n(Pe),n(Ke),n(Ot),n(Oe),n(ts),n(ls),n(el),n(es),n(ss),n(nl),n(ns),n(as),n(rl),n(rs),n(il),n(is),n(ms),n(pl),n(ps),n(Al),n(ol),n(os),n(cs),n(ql),n(Ml),n(Ms),n(Ll),n(Jl),n(Js),n(Dl),n(yl),n(ys),n(Pl),n(us),n(bl),n(bs),n(ws),n(wl),n(Ts),n(ds),n(hs),n(hl),n(Us),n(fs),n(Ul),n(js),n(Is),n(Kl)),n(e),u(w,t),u(j,t),jl[$].d(t),Il[v].d(t),u(pt,t),u(ct,t),u(Mt,t),u(yt,t),u(ut,t),u(wt,t),_l[C].d(t),u(Ut,t),gl[W].d(t),Zl[N].d(t),Bl[X].d(t),u(Zt,t),$l[Q].d(t),u($t,t),u(vt,t),u(et,t),u(Ct,t),u(Wt,t),u(Rt,t),u(st,t),u(Vt,t),u(zt,t),u(Qt,t),u(Et,t),u(Yt,t),u(At,t),u(qt,t),u(Pt,t),u(Kt,t),u(tl,t),u(ll,t),u(sl,t),u(al,t),u(ml,t),kl[E].d(t),u(cl,t),vl[F].d(t),Gl[A].d(t),Cl[L].d(t),xl[P].d(t),u(ul,t),u(nt,t),u(Tl,t),u(dl,t),u(at,t),u(fl,t)}}}const lr='{"title":"QA 管道中的快速標記器","local":"qa-管道中的快速標記器","sections":[{"title":"使用 question-answering 管道","local":"使用-question-answering-管道","sections":[],"depth":2},{"title":"使用模型進行問答","local":"使用模型進行問答","sections":[],"depth":2},{"title":"處理長上下文","local":"處理長上下文","sections":[],"depth":2}],"depth":1}';function er(b,e,r){let l="pt";return ha(()=>{const c=new URLSearchParams(window.location.search);r(0,l=c.get("fw")||"pt")}),[l]}class cr extends Ua{constructor(e){super(),fa(this,e,er,tr,da,{})}}export{cr as component};
