import{s as Ua,o as fa,n as vs}from"../chunks/scheduler.cc52f4b9.js";import{S as ja,i as Ia,e as w,s as i,c as M,q as rt,H as ua,h as _a,a as d,d as n,b as m,f as Bs,g as J,j as U,r as it,x as ba,k as Ds,l as g,m as a,n as y,o as p,u as Z,t as o,p as u,v as B}from"../chunks/index.9480bb2b.js";import{T as $s}from"../chunks/Tip.f7b80743.js";import{C as ga,H as ks,E as Za}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.52103c90.js";import{Y as Ta}from"../chunks/Youtube.7b12d9e8.js";import{C as h}from"../chunks/CodeBlock.c5404643.js";import{C as wa}from"../chunks/CourseFloatingBanner.78fb31df.js";import{F as Ba}from"../chunks/FrameworkSwitchCourse.42d12053.js";function $a(b){let e,r;return e=new wa({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 ka(b){let e,r;return e=new wa({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 va(b){let e,r;return e=new Ta({props:{id:"b3u8RzBCX9Y"}}),{c(){M(e.$$.fragment)},l(l){J(e.$$.fragment,l)},m(l,c){y(e,l,c),r=!0},i(l){r||(o(e.$$.fragment,l),r=!0)},o(l){p(e.$$.fragment,l),r=!1},d(l){u(e,l)}}}function Ga(b){let e,r;return e=new Ta({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 Ca(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 xa(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 Wa(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 Ra(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 Na(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 Va(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 Xa(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 za(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 Qa(b){let e,r="然後我們將屏蔽這些值 <strong>start_index &gt; end_index</strong> 通過將它們設置為 <strong>0</strong> （其他概率都是正數）。這 <strong>torch.triu()</strong> 函數返回作為參數傳遞的 2D 張量的上三角部分，因此它會為我們做屏蔽：",l,c,T;return c=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:"scores = np.triu(scores)",wrap:!1}}),{c(){e=w("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),T=!0},i(f){T||(o(c.$$.fragment,f),T=!0)},o(f){p(c.$$.fragment,f),T=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function Ha(b){let e,r="然後我們將屏蔽這些值 <strong>start_index &gt; end_index</strong> 通過將它們設置為 <strong>0</strong> （其他概率都是正數）。這 <strong>torch.triu()</strong> 函數返回作為參數傳遞的 2D 張量的上三角部分，因此它會為我們做屏蔽：",l,c,T;return c=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMp",highlighted:"scores = torch.triu(scores)",wrap:!1}}),{c(){e=w("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),T=!0},i(f){T||(o(c.$$.fragment,f),T=!0)},o(f){p(c.$$.fragment,f),T=!1},d(f){f&&(n(e),n(l)),u(c,f)}}}function Ea(b){let e,r="✏️ <strong>試試看!</strong> 計算五個最可能的答案的開始和結束索引。";return{c(){e=w("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:vs,d(l){l&&n(e)}}}function Ya(b){let e,r="✏️ <strong>試試看!</strong> 使用您之前計算的最佳分數來顯示五個最可能的答案。要檢查您的結果，請返回到第一個管道並在調用它時傳入。";return{c(){e=w("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:vs,d(l){l&&n(e)}}}function Fa(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(T){J(e.$$.fragment,T),r=m(T),J(l.$$.fragment,T)},m(T,f){y(e,T,f),a(T,r,f),y(l,T,f),c=!0},i(T){c||(o(e.$$.fragment,T),o(l.$$.fragment,T),c=!0)},o(T){p(e.$$.fragment,T),p(l.$$.fragment,T),c=!1},d(T){T&&n(r),u(e,T),u(l,T)}}}function Sa(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(T){J(e.$$.fragment,T),r=m(T),J(l.$$.fragment,T)},m(T,f){y(e,T,f),a(T,r,f),y(l,T,f),c=!0},i(T){c||(o(e.$$.fragment,T),o(l.$$.fragment,T),c=!0)},o(T){p(e.$$.fragment,T),p(l.$$.fragment,T),c=!1},d(T){T&&n(r),u(e,T),u(l,T)}}}function Aa(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 qa(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 La(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 Da(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 Pa(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 Ka(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 Oa(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 tr(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 lr(b){let e,r="✏️ <strong>試試看!</strong> 修改上面的代碼以返回五個最可能的答案的分數和跨度（總計，而不是每個塊）。";return{c(){e=w("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:vs,d(l){l&&n(e)}}}function er(b){let e,r="✏️ <strong>試試看!</strong> 使用您之前計算的最佳分數來顯示五個最可能的答案（對於整個上下文，而不是每個塊）。要檢查您的結果，請返回到第一個管道並在調用它時傳入。";return{c(){e=w("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:vs,d(l){l&&n(e)}}}function sr(b){let e,r,l,c,T,f,j,te,mt,le,$,k,Rl,pt,Ps="我們現在將深入研究 <strong>question-answering</strong> 管道，看看如何利用偏移量從上下文中獲取手頭問題的答案，有點像我們在上一節中對分組實體所做的。然後我們將看到我們如何處理最終被截斷的非常長的上下文。如果您對問答任務不感興趣，可以跳過此部分。",ee,v,G,Nl,ot,se,ct,Ks='正如我們在<a href="/course/chapter1">Chapter 1</a>，我們可以使用 <strong>question-answering</strong> 像這樣的管道以獲得問題的答案：',ne,Mt,ae,Jt,re,yt,Os="與其他管道不同，它不能截斷和拆分長於模型接受的最大長度的文本（因此可能會丟失文檔末尾的信息），此管道可以處理非常長的上下文，並將返回回答這個問題，即使它在最後：",ie,ut,me,bt,pe,Tt,tn="讓我們看看它是如何做到這一切的！",oe,wt,ce,dt,ln='與任何其他管道一樣，我們首先對輸入進行標記化，然後通過模型將其發送。默認情況下用於的檢查點 <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>):',Me,C,x,Vl,ht,en="請注意，我們將問題和上下文標記為一對，首先是問題",Je,lt,sn='<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"/>',ye,Ut,nn="問答模型的工作方式與我們迄今為止看到的模型略有不同。以上圖為例，該模型已經過訓練，可以預測答案開始的標記的索引（此處為 21）和答案結束處的標記的索引（此處為 24）。這就是為什麼這些模型不返回一個 logits 的張量，而是返回兩個：一個用於對應於答案的開始標記的 logits，另一個用於對應於答案的結束標記的 logits。由於在這種情況下我們只有一個包含 66 個標記的輸入，我們得到：",ue,ft,be,W,R,Xl,jt,an="為了將這些 logits 轉換為概率，我們將應用一個 softmax 函數——但在此之前，我們需要確保我們屏蔽了不屬於上下文的索引。我們的輸入是 <strong>[CLS] question [SEP] context [SEP]</strong> ，所以我們需要屏蔽問題的標記以及 <strong>[SEP]</strong> 令牌。我們將保留 <strong>[CLS]</strong> 然而，因為某些模型使用它來表示答案不在上下文中。",Te,It,rn="由於我們將在之後應用 softmax，我們只需要用一個大的負數替換我們想要屏蔽的 logits。在這裡，我們使用 <strong>-10000</strong> ：",we,N,V,zl,_t,mn="現在我們已經正確屏蔽了與我們不想預測的位置相對應的 logits，我們可以應用 softmax：",de,X,z,Ql,gt,pn="在這個階段，我們可以採用開始和結束概率的 argmax——但我們最終可能會得到一個大於結束索引的開始索引，所以我們需要採取更多的預防措施。我們將計算每個可能的概率 <strong>start_index</strong> 和 <strong>end_index</strong> 在哪裡 <strong>start_index &lt;= end_index</strong> ，然後取元組 <strong>(start_index, end_index)</strong> 以最高的概率。",he,I,Gs,Hl,on="start_index",Cs,El,cn="end_index",xs,Yl,Mn="start_index",Ws,Fl,Jn="end_index",Rs,Ue,da='<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>',fe,O,Ns,je,ha='<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>',Ie,Sl,yn="start_index <= end_index",Vs,_e,Zt,un="首先讓我們計算所有可能的產品：",ge,Bt,Ze,Q,H,Al,$t,bn="現在我們只需要得到最大值的索引。由於 PyTorch 將返回展平張量中的索引，因此我們需要使用地板除法 <strong>//</strong> 和模數 <strong>%</strong> 操作以獲得 <strong>start_index</strong> 和 <strong>end_index</strong> ：",Be,kt,$e,vt,Tn="我們還沒有完全完成，但至少我們已經有了正確的答案分數（您可以通過將其與上一節中的第一個結果進行比較來檢查這一點）：",ke,Gt,ve,et,Ge,Ct,wn="我們有 <strong>start_index</strong> 和 <strong>end_index</strong> 就標記而言的答案，所以現在我們只需要轉換為上下文中的字符索引。這是偏移量非常有用的地方。我們可以像在令牌分類任務中一樣抓住它們並使用它們：",Ce,xt,xe,Wt,dn="現在我們只需要格式化所有內容以獲得我們的結果：",We,Rt,Re,Nt,Ne,Vt,hn="太棒了！這和我們的第一個例子一樣！",Ve,st,Xe,Xt,ze,zt,Un="如果我們嘗試對我們之前作為示例使用的問題和長上下文進行標記化，我們將獲得比在 <strong>question-answering</strong> 管道（即 384）：",Qe,Qt,He,Ht,Ee,Et,fn="因此，我們需要在最大長度處截斷我們的輸入。有幾種方法可以做到這一點，但我們不想截斷問題，只想截斷上下文。由於上下文是第二個句子，我們將使用 <strong>“only_second”</strong> 截斷策略。那麼出現的問題是問題的答案可能不在截斷上下文中。例如，在這裡，我們選擇了一個答案在上下文末尾的問題，當我們截斷它時，答案不存在",Ye,Yt,Fe,Ft,Se,St,jn="這意味著模型將很難選擇正確的答案。為了解決這個問題， <strong>question-answering</strong> 管道允許我們將上下文分成更小的塊，指定最大長度。為確保我們不會在完全錯誤的位置拆分上下文以找到答案，它還包括塊之間的一些重疊。",Ae,At,In="我們可以讓分詞器（快或慢）通過添加來為我們做這件事 <strong>return_overflowing_tokens=True</strong> ，我們可以指定我們想要的重疊 <strong>stride</strong> 爭論。這是一個使用較小句子的示例：",qe,qt,Le,Lt,De,Dt,_n="正如我們所看到的，句子已被分成多個塊，使得每個條目 <strong>inputs[“input_ids”]</strong> 最多有 6 個標記（我們需要添加填充以使最後一個條目與其他條目的大小相同）並且每個條目之間有 2 個標記的重疊。",Pe,Pt,gn="讓我們仔細看看標記化的結果：",Ke,Kt,Oe,Ot,ts,tl,Zn="正如預期的那樣，我們得到了輸入 ID 和一個注意力掩碼。最後一個鍵， <strong>overflow_to_sample_mapping</strong> , 是一個映射，它告訴我們每個結果對應哪個句子——這裡我們有 7 個結果，它們都來自我們通過標記器的（唯一）句子：",ls,ll,es,el,ss,sl,Bn="當我們將幾個句子標記在一起時，這更有用。例如，這個：",ns,nl,as,al,$n="讓我們：",rs,rl,is,il,kn="這意味著第一個句子像以前一樣分成 7 個塊，接下來的 4 個塊來自第二個句子。",ms,ml,vn="現在讓我們回到我們的長期背景。默認情況下 <strong>question-answering</strong> 管道使用的最大長度為 384，正如我們之前提到的，步長為 128，這對應於模型微調的方式（您可以通過傳遞 <strong>max_seq_len</strong> 和 <strong>stride</strong> 調用管道時的參數）。因此，我們將在標記化時使用這些參數。我們還將添加填充（具有相同長度的樣本，因此我們可以構建張量）以及請求偏移量：",ps,pl,os,ol,Gn="那些 <strong>inputs</strong> 將包含模型期望的輸入 ID 和注意力掩碼，以及偏移量和 <strong>overflow_to_sample_mapping</strong> 我們剛剛談到。由於這兩個不是模型使用的參數，我們將把它們從 <strong>inputs</strong> （我們不會存儲地圖，因為它在這裡沒有用）在將其轉換為張量之前：",cs,E,Y,ql,cl,Cn="我們的長上下文被分成兩部分，這意味著在它通過我們的模型後，我們將有兩組開始和結束 logits：",Ms,Ml,Js,F,S,Ll,Jl,xn="和以前一樣，我們在採用 softmax 之前首先屏蔽不屬於上下文的標記。我們還屏蔽了所有填充標記（由注意掩碼標記）：",ys,A,q,Dl,yl,Wn="然後我們可以使用 softmax 將我們的 logits 轉換為概率：",us,L,D,Pl,ul,Rn="下一步與我們對小上下文所做的類似，但我們對兩個塊中的每一個都重複它。我們將分數歸因於所有可能的答案跨度，然後取得分最高的跨度：",bs,P,K,Kl,bl,Ts,Tl,Nn="這兩個候選對應於模型能夠在每個塊中找到的最佳答案。該模型對正確答案在第二部分更有信心（這是一個好兆頭！）。現在我們只需要將這兩個標記跨度映射到上下文中的字符跨度（我們只需要映射第二個標記以獲得我們的答案，但看看模型在第一個塊中選擇了什麼很有趣）。",ws,nt,ds,wl,Vn="這 <strong>offsets</strong> 我們之前抓取的實際上是一個偏移量列表，每個文本塊有一個列表：",hs,dl,Us,hl,fs,Ul,Xn="如果我們忽略第一個結果，我們會得到與這個長上下文的管道相同的結果——是的！",js,at,Is,fl,zn="我們對分詞器功能的深入研究到此結束。我們將在下一章再次將所有這些付諸實踐，屆時我們將向您展示如何在一系列常見的 NLP 任務上微調模型。",_s,jl,gs,Ol,Zs;T=new Ba({props:{fw:b[0]}}),j=new ga({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),mt=new ks({props:{title:"QA 管道中的快速標記器",local:"qa-管道中的快速標記器",headingTag:"h1"}});const Qn=[ka,$a],Il=[];function Hn(t,s){return t[0]==="pt"?0:1}$=Hn(b),k=Il[$]=Qn[$](b);const En=[Ga,va],_l=[];function Yn(t,s){return t[0]==="pt"?0:1}v=Yn(b),G=_l[v]=En[v](b),ot=new ks({props:{title:"使用 question-answering 管道",local:"使用-question-answering-管道",headingTag:"h2"}}),Mt=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}}),Jt=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}}),ut=new h({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJUY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9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",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}}),bt=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 ks({props:{title:"使用模型進行問答",local:"使用模型進行問答",headingTag:"h2"}});const Fn=[xa,Ca],gl=[];function Sn(t,s){return t[0]==="pt"?0:1}C=Sn(b),x=gl[C]=Fn[C](b),ft=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 An=[Ra,Wa],Zl=[];function qn(t,s){return t[0]==="pt"?0:1}W=qn(b),R=Zl[W]=An[W](b);const Ln=[Va,Na],Bl=[];function Dn(t,s){return t[0]==="pt"?0:1}N=Dn(b),V=Bl[N]=Ln[N](b);const Pn=[za,Xa],$l=[];function Kn(t,s){return t[0]==="pt"?0:1}X=Kn(b),z=$l[X]=Pn[X](b),Bt=new h({props:{code:"c2NvcmVzJTIwJTNEJTIwc3RhcnRfcHJvYmFiaWxpdGllcyU1QiUzQSUyQyUyME5vbmUlNUQlMjAqJTIwZW5kX3Byb2JhYmlsaXRpZXMlNUJOb25lJTJDJTIwJTNBJTVE",highlighted:'scores = start_probabilities[:, <span class="hljs-literal">None</span>] * end_probabilities[<span class="hljs-literal">None</span>, :]',wrap:!1}});const On=[Ha,Qa],kl=[];function ta(t,s){return t[0]==="pt"?0:1}Q=ta(b),H=kl[Q]=On[Q](b),kt=new h({props:{code:"bWF4X2luZGV4JTIwJTNEJTIwc2NvcmVzLmFyZ21heCgpLml0ZW0oKSUwQXN0YXJ0X2luZGV4JTIwJTNEJTIwbWF4X2luZGV4JTIwJTJGJTJGJTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQWVuZF9pbmRleCUyMCUzRCUyMG1heF9pbmRleCUyMCUyNSUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEFwcmludChzY29yZXMlNUJzdGFydF9pbmRleCUyQyUyMGVuZF9pbmRleCU1RCk=",highlighted:`max_index = scores.argmax().item()
start_index = max_index // scores.shape[<span class="hljs-number">1</span>]
end_index = max_index % scores.shape[<span class="hljs-number">1</span>]
<span class="hljs-built_in">print</span>(scores[start_index, end_index])`,wrap:!1}}),Gt=new h({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),et=new $s({props:{$$slots:{default:[Ea]},$$scope:{ctx:b}}}),xt=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}}),Rt=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}}),Nt=new h({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnSmF4JTJDJTIwUHlUb3JjaCUyMGFuZCUyMFRlbnNvckZsb3cnJTJDJTBBJTIwJ3N0YXJ0JyUzQSUyMDc4JTJDJTBBJTIwJ2VuZCclM0ElMjAxMDUlMkMlMEElMjAnc2NvcmUnJTNBJTIwMC45Nzc3MyU3RA==",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
 <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</span>}`,wrap:!1}}),st=new $s({props:{$$slots:{default:[Ya]},$$scope:{ctx:b}}}),Xt=new ks({props:{title:"處理長上下文",local:"處理長上下文",headingTag:"h2"}}),Qt=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}}),Ht=new h({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Yt=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}}),Ft=new h({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU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ZGVscyUyQyUyMHNvbWUlMjBpbiUyMG1vcmUlMjB0aGFuJTIwMTAwJTIwbGFuZ3VhZ2VzLiUwQSUwQTMuJTIwQ2hvb3NlJTIwdGhlJTIwcmlnaHQlMjBmcmFtZXdvcmslMjBmb3IlMjBldmVyeSUyMHBhcnQlMjBvZiUyMGElMjBtb2RlbCdzJTIwbGlmZXRpbWUlM0ElMEElMjAlMjAtJTIwVHJhaW4lMjBzdGF0ZS1vZi10aGUtYXJ0JTIwbW9kZWxzJTIwaW4lMjAzJTIwbGluZXMlMjBvZiUyMGNvZGUuJTBBJTIwJTIwLSUyME1vdmUlMjBhJTIwc2luZ2xlJTIwbW9kZWwlMjBiZXR3ZWVuJTIwVEYyLjAlMkZQeVRvcmNoJTIwZnJhbWV3b3JrcyUyMGF0JTIwd2lsbC4lMEElMjAlMjAtJTIwU2VhbWxlc3NseSUyMHBpY2slMjB0aGUlMjByaWdodCUyMGZyYW1ld29yayUyMGZvciUyMHRyYWluaW5nJTJDJTIwZXZhbHVhdGlvbiUyMGFuZCUyMHByb2R1Y3Rpb24uJTBBJTBBNC4lMjBFYXNpbHklMjBjdXN0b21pemUlMjBhJTIwbW9kZWwlMjBvciUyMGFuJTIwZXhhbXBsZSUyMHRvJTIweW91ciUyMG5lZWRzJTNBJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",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}}),qt=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}}),Lt=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}}),Kt=new h({props:{code:"cHJpbnQoaW5wdXRzLmtleXMoKSk=",highlighted:'<span class="hljs-built_in">print</span>(inputs.keys())',wrap:!1}}),Ot=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}}),ll=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}}),el=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}}),nl=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}}),rl=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}}),pl=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 la=[Sa,Fa],vl=[];function ea(t,s){return t[0]==="pt"?0:1}E=ea(b),Y=vl[E]=la[E](b),Ml=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 sa=[qa,Aa],Gl=[];function na(t,s){return t[0]==="pt"?0:1}F=na(b),S=Gl[F]=sa[F](b);const aa=[Da,La],Cl=[];function ra(t,s){return t[0]==="pt"?0:1}A=ra(b),q=Cl[A]=aa[A](b);const ia=[Ka,Pa],xl=[];function ma(t,s){return t[0]==="pt"?0:1}L=ma(b),D=xl[L]=ia[L](b);const pa=[tr,Oa],Wl=[];function oa(t,s){return t[0]==="pt"?0:1}return P=oa(b),K=Wl[P]=pa[P](b),bl=new h({props:{code:"JTVCKDAlMkMlMjAxOCUyQyUyMDAuMzM4NjcpJTJDJTIwKDE3MyUyQyUyMDE4NCUyQyUyMDAuOTcxNDkpJTVE",highlighted:'[(<span class="hljs-number">0</span>, <span class="hljs-number">18</span>, <span class="hljs-number">0.33867</span>), (<span class="hljs-number">173</span>, <span class="hljs-number">184</span>, <span class="hljs-number">0.97149</span>)]',wrap:!1}}),nt=new $s({props:{$$slots:{default:[lr]},$$scope:{ctx:b}}}),dl=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}}),hl=new h({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnJTVDbiVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUzQSUyMFN0YXRlJTIwb2YlMjB0aGUlMjBBcnQlMjBOTFAnJTJDJTIwJ3N0YXJ0JyUzQSUyMDAlMkMlMjAnZW5kJyUzQSUyMDM3JTJDJTIwJ3Njb3JlJyUzQSUyMDAuMzM4NjclN0QlMEElN0InYW5zd2VyJyUzQSUyMCdKYXglMkMlMjBQeVRvcmNoJTIwYW5kJTIwVGVuc29yRmxvdyclMkMlMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUyMCdlbmQnJTNBJTIwMTkxOSUyQyUyMCdzY29yZSclM0ElMjAwLjk3MTQ5JTdE",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;\\n🤗 Transformers: State of the Art NLP&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">37</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.33867</span>}
{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>}`,wrap:!1}}),at=new $s({props:{$$slots:{default:[er]},$$scope:{ctx:b}}}),jl=new Za({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter6/3b.mdx"}}),{c(){e=w("meta"),r=i(),l=w("p"),c=i(),M(T.$$.fragment),f=i(),M(j.$$.fragment),te=i(),M(mt.$$.fragment),le=i(),k.c(),Rl=i(),pt=w("p"),pt.innerHTML=Ps,ee=i(),G.c(),Nl=i(),M(ot.$$.fragment),se=i(),ct=w("p"),ct.innerHTML=Ks,ne=i(),M(Mt.$$.fragment),ae=i(),M(Jt.$$.fragment),re=i(),yt=w("p"),yt.textContent=Os,ie=i(),M(ut.$$.fragment),me=i(),M(bt.$$.fragment),pe=i(),Tt=w("p"),Tt.textContent=tn,oe=i(),M(wt.$$.fragment),ce=i(),dt=w("p"),dt.innerHTML=ln,Me=i(),x.c(),Vl=i(),ht=w("p"),ht.textContent=en,Je=i(),lt=w("div"),lt.innerHTML=sn,ye=i(),Ut=w("p"),Ut.textContent=nn,ue=i(),M(ft.$$.fragment),be=i(),R.c(),Xl=i(),jt=w("p"),jt.innerHTML=an,Te=i(),It=w("p"),It.innerHTML=rn,we=i(),V.c(),zl=i(),_t=w("p"),_t.textContent=mn,de=i(),z.c(),Ql=i(),gt=w("p"),gt.innerHTML=pn,he=i(),I=w("p"),Gs=rt("假設事件“答案開始於 "),Hl=w("strong"),Hl.textContent=on,Cs=rt(" ”和“答案結束於 "),El=w("strong"),El.textContent=cn,xs=rt(" ” 要獨立，答案開始於的概率 "),Yl=w("strong"),Yl.textContent=Mn,Ws=rt(" 並結束於 "),Fl=w("strong"),Fl.textContent=Jn,Rs=rt(` 是：
`),Ue=new ua(!1),fe=i(),O=w("p"),Ns=rt("所以，要計算所有的分數，我們只需要計算所有的產品"),je=new ua(!1),Ie=rt(" where "),Sl=w("code"),Sl.textContent=yn,Vs=rt("."),_e=i(),Zt=w("p"),Zt.textContent=un,ge=i(),M(Bt.$$.fragment),Ze=i(),H.c(),Al=i(),$t=w("p"),$t.innerHTML=bn,Be=i(),M(kt.$$.fragment),$e=i(),vt=w("p"),vt.textContent=Tn,ke=i(),M(Gt.$$.fragment),ve=i(),M(et.$$.fragment),Ge=i(),Ct=w("p"),Ct.innerHTML=wn,Ce=i(),M(xt.$$.fragment),xe=i(),Wt=w("p"),Wt.textContent=dn,We=i(),M(Rt.$$.fragment),Re=i(),M(Nt.$$.fragment),Ne=i(),Vt=w("p"),Vt.textContent=hn,Ve=i(),M(st.$$.fragment),Xe=i(),M(Xt.$$.fragment),ze=i(),zt=w("p"),zt.innerHTML=Un,Qe=i(),M(Qt.$$.fragment),He=i(),M(Ht.$$.fragment),Ee=i(),Et=w("p"),Et.innerHTML=fn,Ye=i(),M(Yt.$$.fragment),Fe=i(),M(Ft.$$.fragment),Se=i(),St=w("p"),St.innerHTML=jn,Ae=i(),At=w("p"),At.innerHTML=In,qe=i(),M(qt.$$.fragment),Le=i(),M(Lt.$$.fragment),De=i(),Dt=w("p"),Dt.innerHTML=_n,Pe=i(),Pt=w("p"),Pt.textContent=gn,Ke=i(),M(Kt.$$.fragment),Oe=i(),M(Ot.$$.fragment),ts=i(),tl=w("p"),tl.innerHTML=Zn,ls=i(),M(ll.$$.fragment),es=i(),M(el.$$.fragment),ss=i(),sl=w("p"),sl.textContent=Bn,ns=i(),M(nl.$$.fragment),as=i(),al=w("p"),al.textContent=$n,rs=i(),M(rl.$$.fragment),is=i(),il=w("p"),il.textContent=kn,ms=i(),ml=w("p"),ml.innerHTML=vn,ps=i(),M(pl.$$.fragment),os=i(),ol=w("p"),ol.innerHTML=Gn,cs=i(),Y.c(),ql=i(),cl=w("p"),cl.textContent=Cn,Ms=i(),M(Ml.$$.fragment),Js=i(),S.c(),Ll=i(),Jl=w("p"),Jl.textContent=xn,ys=i(),q.c(),Dl=i(),yl=w("p"),yl.textContent=Wn,us=i(),D.c(),Pl=i(),ul=w("p"),ul.textContent=Rn,bs=i(),K.c(),Kl=i(),M(bl.$$.fragment),Ts=i(),Tl=w("p"),Tl.textContent=Nn,ws=i(),M(nt.$$.fragment),ds=i(),wl=w("p"),wl.innerHTML=Vn,hs=i(),M(dl.$$.fragment),Us=i(),M(hl.$$.fragment),fs=i(),Ul=w("p"),Ul.textContent=Xn,js=i(),M(at.$$.fragment),Is=i(),fl=w("p"),fl.textContent=zn,_s=i(),M(jl.$$.fragment),gs=i(),Ol=w("p"),this.h()},l(t){const s=_a("svelte-u9bgzb",document.head);e=d(s,"META",{name:!0,content:!0}),s.forEach(n),r=m(t),l=d(t,"P",{}),Bs(l).forEach(n),c=m(t),J(T.$$.fragment,t),f=m(t),J(j.$$.fragment,t),te=m(t),J(mt.$$.fragment,t),le=m(t),k.l(t),Rl=m(t),pt=d(t,"P",{"data-svelte-h":!0}),U(pt)!=="svelte-1es6raf"&&(pt.innerHTML=Ps),ee=m(t),G.l(t),Nl=m(t),J(ot.$$.fragment,t),se=m(t),ct=d(t,"P",{"data-svelte-h":!0}),U(ct)!=="svelte-1awydz0"&&(ct.innerHTML=Ks),ne=m(t),J(Mt.$$.fragment,t),ae=m(t),J(Jt.$$.fragment,t),re=m(t),yt=d(t,"P",{"data-svelte-h":!0}),U(yt)!=="svelte-6pojq9"&&(yt.textContent=Os),ie=m(t),J(ut.$$.fragment,t),me=m(t),J(bt.$$.fragment,t),pe=m(t),Tt=d(t,"P",{"data-svelte-h":!0}),U(Tt)!=="svelte-fgyjer"&&(Tt.textContent=tn),oe=m(t),J(wt.$$.fragment,t),ce=m(t),dt=d(t,"P",{"data-svelte-h":!0}),U(dt)!=="svelte-1h6i42m"&&(dt.innerHTML=ln),Me=m(t),x.l(t),Vl=m(t),ht=d(t,"P",{"data-svelte-h":!0}),U(ht)!=="svelte-99imm6"&&(ht.textContent=en),Je=m(t),lt=d(t,"DIV",{class:!0,"data-svelte-h":!0}),U(lt)!=="svelte-47wedv"&&(lt.innerHTML=sn),ye=m(t),Ut=d(t,"P",{"data-svelte-h":!0}),U(Ut)!=="svelte-tr2r9i"&&(Ut.textContent=nn),ue=m(t),J(ft.$$.fragment,t),be=m(t),R.l(t),Xl=m(t),jt=d(t,"P",{"data-svelte-h":!0}),U(jt)!=="svelte-cmx067"&&(jt.innerHTML=an),Te=m(t),It=d(t,"P",{"data-svelte-h":!0}),U(It)!=="svelte-pem99v"&&(It.innerHTML=rn),we=m(t),V.l(t),zl=m(t),_t=d(t,"P",{"data-svelte-h":!0}),U(_t)!=="svelte-tkv9lz"&&(_t.textContent=mn),de=m(t),z.l(t),Ql=m(t),gt=d(t,"P",{"data-svelte-h":!0}),U(gt)!=="svelte-1da74n7"&&(gt.innerHTML=pn),he=m(t),I=d(t,"P",{});var _=Bs(I);Gs=it(_,"假設事件“答案開始於 "),Hl=d(_,"STRONG",{"data-svelte-h":!0}),U(Hl)!=="svelte-mrepff"&&(Hl.textContent=on),Cs=it(_," ”和“答案結束於 "),El=d(_,"STRONG",{"data-svelte-h":!0}),U(El)!=="svelte-wrb9ic"&&(El.textContent=cn),xs=it(_," ” 要獨立，答案開始於的概率 "),Yl=d(_,"STRONG",{"data-svelte-h":!0}),U(Yl)!=="svelte-mrepff"&&(Yl.textContent=Mn),Ws=it(_," 並結束於 "),Fl=d(_,"STRONG",{"data-svelte-h":!0}),U(Fl)!=="svelte-wrb9ic"&&(Fl.textContent=Jn),Rs=it(_,` 是：
`),Ue=ba(_,!1),_.forEach(n),fe=m(t),O=d(t,"P",{});var tt=Bs(O);Ns=it(tt,"所以，要計算所有的分數，我們只需要計算所有的產品"),je=ba(tt,!1),Ie=it(tt," where "),Sl=d(tt,"CODE",{"data-svelte-h":!0}),U(Sl)!=="svelte-1kp3szf"&&(Sl.textContent=yn),Vs=it(tt,"."),tt.forEach(n),_e=m(t),Zt=d(t,"P",{"data-svelte-h":!0}),U(Zt)!=="svelte-ooq7u2"&&(Zt.textContent=un),ge=m(t),J(Bt.$$.fragment,t),Ze=m(t),H.l(t),Al=m(t),$t=d(t,"P",{"data-svelte-h":!0}),U($t)!=="svelte-1tf4nt5"&&($t.innerHTML=bn),Be=m(t),J(kt.$$.fragment,t),$e=m(t),vt=d(t,"P",{"data-svelte-h":!0}),U(vt)!=="svelte-1atzg7i"&&(vt.textContent=Tn),ke=m(t),J(Gt.$$.fragment,t),ve=m(t),J(et.$$.fragment,t),Ge=m(t),Ct=d(t,"P",{"data-svelte-h":!0}),U(Ct)!=="svelte-bgxhl0"&&(Ct.innerHTML=wn),Ce=m(t),J(xt.$$.fragment,t),xe=m(t),Wt=d(t,"P",{"data-svelte-h":!0}),U(Wt)!=="svelte-4n6hkj"&&(Wt.textContent=dn),We=m(t),J(Rt.$$.fragment,t),Re=m(t),J(Nt.$$.fragment,t),Ne=m(t),Vt=d(t,"P",{"data-svelte-h":!0}),U(Vt)!=="svelte-yawc34"&&(Vt.textContent=hn),Ve=m(t),J(st.$$.fragment,t),Xe=m(t),J(Xt.$$.fragment,t),ze=m(t),zt=d(t,"P",{"data-svelte-h":!0}),U(zt)!=="svelte-1muk70g"&&(zt.innerHTML=Un),Qe=m(t),J(Qt.$$.fragment,t),He=m(t),J(Ht.$$.fragment,t),Ee=m(t),Et=d(t,"P",{"data-svelte-h":!0}),U(Et)!=="svelte-1enzoac"&&(Et.innerHTML=fn),Ye=m(t),J(Yt.$$.fragment,t),Fe=m(t),J(Ft.$$.fragment,t),Se=m(t),St=d(t,"P",{"data-svelte-h":!0}),U(St)!=="svelte-30y3h"&&(St.innerHTML=jn),Ae=m(t),At=d(t,"P",{"data-svelte-h":!0}),U(At)!=="svelte-41f44v"&&(At.innerHTML=In),qe=m(t),J(qt.$$.fragment,t),Le=m(t),J(Lt.$$.fragment,t),De=m(t),Dt=d(t,"P",{"data-svelte-h":!0}),U(Dt)!=="svelte-4zomzx"&&(Dt.innerHTML=_n),Pe=m(t),Pt=d(t,"P",{"data-svelte-h":!0}),U(Pt)!=="svelte-1kq1278"&&(Pt.textContent=gn),Ke=m(t),J(Kt.$$.fragment,t),Oe=m(t),J(Ot.$$.fragment,t),ts=m(t),tl=d(t,"P",{"data-svelte-h":!0}),U(tl)!=="svelte-1p9jn19"&&(tl.innerHTML=Zn),ls=m(t),J(ll.$$.fragment,t),es=m(t),J(el.$$.fragment,t),ss=m(t),sl=d(t,"P",{"data-svelte-h":!0}),U(sl)!=="svelte-3cpg2i"&&(sl.textContent=Bn),ns=m(t),J(nl.$$.fragment,t),as=m(t),al=d(t,"P",{"data-svelte-h":!0}),U(al)!=="svelte-110kj3t"&&(al.textContent=$n),rs=m(t),J(rl.$$.fragment,t),is=m(t),il=d(t,"P",{"data-svelte-h":!0}),U(il)!=="svelte-l8lrf9"&&(il.textContent=kn),ms=m(t),ml=d(t,"P",{"data-svelte-h":!0}),U(ml)!=="svelte-1tpvsga"&&(ml.innerHTML=vn),ps=m(t),J(pl.$$.fragment,t),os=m(t),ol=d(t,"P",{"data-svelte-h":!0}),U(ol)!=="svelte-hwr3uf"&&(ol.innerHTML=Gn),cs=m(t),Y.l(t),ql=m(t),cl=d(t,"P",{"data-svelte-h":!0}),U(cl)!=="svelte-17nwfy2"&&(cl.textContent=Cn),Ms=m(t),J(Ml.$$.fragment,t),Js=m(t),S.l(t),Ll=m(t),Jl=d(t,"P",{"data-svelte-h":!0}),U(Jl)!=="svelte-ef6u09"&&(Jl.textContent=xn),ys=m(t),q.l(t),Dl=m(t),yl=d(t,"P",{"data-svelte-h":!0}),U(yl)!=="svelte-1ad2oof"&&(yl.textContent=Wn),us=m(t),D.l(t),Pl=m(t),ul=d(t,"P",{"data-svelte-h":!0}),U(ul)!=="svelte-w3qxvo"&&(ul.textContent=Rn),bs=m(t),K.l(t),Kl=m(t),J(bl.$$.fragment,t),Ts=m(t),Tl=d(t,"P",{"data-svelte-h":!0}),U(Tl)!=="svelte-15fc8pg"&&(Tl.textContent=Nn),ws=m(t),J(nt.$$.fragment,t),ds=m(t),wl=d(t,"P",{"data-svelte-h":!0}),U(wl)!=="svelte-1ef7syq"&&(wl.innerHTML=Vn),hs=m(t),J(dl.$$.fragment,t),Us=m(t),J(hl.$$.fragment,t),fs=m(t),Ul=d(t,"P",{"data-svelte-h":!0}),U(Ul)!=="svelte-dqro2f"&&(Ul.textContent=Xn),js=m(t),J(at.$$.fragment,t),Is=m(t),fl=d(t,"P",{"data-svelte-h":!0}),U(fl)!=="svelte-1rdohsq"&&(fl.textContent=zn),_s=m(t),J(jl.$$.fragment,t),gs=m(t),Ol=d(t,"P",{}),Bs(Ol).forEach(n),this.h()},h(){Ds(e,"name","hf:doc:metadata"),Ds(e,"content",nr),Ds(lt,"class","flex justify-center"),Ue.a=null,je.a=Ie},m(t,s){g(document.head,e),a(t,r,s),a(t,l,s),a(t,c,s),y(T,t,s),a(t,f,s),y(j,t,s),a(t,te,s),y(mt,t,s),a(t,le,s),Il[$].m(t,s),a(t,Rl,s),a(t,pt,s),a(t,ee,s),_l[v].m(t,s),a(t,Nl,s),y(ot,t,s),a(t,se,s),a(t,ct,s),a(t,ne,s),y(Mt,t,s),a(t,ae,s),y(Jt,t,s),a(t,re,s),a(t,yt,s),a(t,ie,s),y(ut,t,s),a(t,me,s),y(bt,t,s),a(t,pe,s),a(t,Tt,s),a(t,oe,s),y(wt,t,s),a(t,ce,s),a(t,dt,s),a(t,Me,s),gl[C].m(t,s),a(t,Vl,s),a(t,ht,s),a(t,Je,s),a(t,lt,s),a(t,ye,s),a(t,Ut,s),a(t,ue,s),y(ft,t,s),a(t,be,s),Zl[W].m(t,s),a(t,Xl,s),a(t,jt,s),a(t,Te,s),a(t,It,s),a(t,we,s),Bl[N].m(t,s),a(t,zl,s),a(t,_t,s),a(t,de,s),$l[X].m(t,s),a(t,Ql,s),a(t,gt,s),a(t,he,s),a(t,I,s),g(I,Gs),g(I,Hl),g(I,Cs),g(I,El),g(I,xs),g(I,Yl),g(I,Ws),g(I,Fl),g(I,Rs),Ue.m(da,I),a(t,fe,s),a(t,O,s),g(O,Ns),je.m(ha,O),g(O,Ie),g(O,Sl),g(O,Vs),a(t,_e,s),a(t,Zt,s),a(t,ge,s),y(Bt,t,s),a(t,Ze,s),kl[Q].m(t,s),a(t,Al,s),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s),y(at,t,s),a(t,Is,s),a(t,fl,s),a(t,_s,s),y(jl,t,s),a(t,gs,s),a(t,Ol,s),Zs=!0},p(t,[s]){const _={};s&1&&(_.fw=t[0]),T.$set(_);let tt=$;$=Hn(t),$!==tt&&(B(),p(Il[tt],1,1,()=>{Il[tt]=null}),Z(),k=Il[$],k||(k=Il[$]=Qn[$](t),k.c()),o(k,1),k.m(Rl.parentNode,Rl));let Xs=v;v=Yn(t),v!==Xs&&(B(),p(_l[Xs],1,1,()=>{_l[Xs]=null}),Z(),G=_l[v],G||(G=_l[v]=En[v](t),G.c()),o(G,1),G.m(Nl.parentNode,Nl));let zs=C;C=Sn(t),C!==zs&&(B(),p(gl[zs],1,1,()=>{gl[zs]=null}),Z(),x=gl[C],x||(x=gl[C]=Fn[C](t),x.c()),o(x,1),x.m(Vl.parentNode,Vl));let Qs=W;W=qn(t),W!==Qs&&(B(),p(Zl[Qs],1,1,()=>{Zl[Qs]=null}),Z(),R=Zl[W],R||(R=Zl[W]=An[W](t),R.c()),o(R,1),R.m(Xl.parentNode,Xl));let Hs=N;N=Dn(t),N!==Hs&&(B(),p(Bl[Hs],1,1,()=>{Bl[Hs]=null}),Z(),V=Bl[N],V||(V=Bl[N]=Ln[N](t),V.c()),o(V,1),V.m(zl.parentNode,zl));let Es=X;X=Kn(t),X!==Es&&(B(),p($l[Es],1,1,()=>{$l[Es]=null}),Z(),z=$l[X],z||(z=$l[X]=Pn[X](t),z.c()),o(z,1),z.m(Ql.parentNode,Ql));let Ys=Q;Q=ta(t),Q!==Ys&&(B(),p(kl[Ys],1,1,()=>{kl[Ys]=null}),Z(),H=kl[Q],H||(H=kl[Q]=On[Q](t),H.c()),o(H,1),H.m(Al.parentNode,Al));const ca={};s&2&&(ca.$$scope={dirty:s,ctx:t}),et.$set(ca);const Ma={};s&2&&(Ma.$$scope={dirty:s,ctx:t}),st.$set(Ma);let Fs=E;E=ea(t),E!==Fs&&(B(),p(vl[Fs],1,1,()=>{vl[Fs]=null}),Z(),Y=vl[E],Y||(Y=vl[E]=la[E](t),Y.c()),o(Y,1),Y.m(ql.parentNode,ql));let Ss=F;F=na(t),F!==Ss&&(B(),p(Gl[Ss],1,1,()=>{Gl[Ss]=null}),Z(),S=Gl[F],S||(S=Gl[F]=sa[F](t),S.c()),o(S,1),S.m(Ll.parentNode,Ll));let As=A;A=ra(t),A!==As&&(B(),p(Cl[As],1,1,()=>{Cl[As]=null}),Z(),q=Cl[A],q||(q=Cl[A]=aa[A](t),q.c()),o(q,1),q.m(Dl.parentNode,Dl));let qs=L;L=ma(t),L!==qs&&(B(),p(xl[qs],1,1,()=>{xl[qs]=null}),Z(),D=xl[L],D||(D=xl[L]=ia[L](t),D.c()),o(D,1),D.m(Pl.parentNode,Pl));let Ls=P;P=oa(t),P!==Ls&&(B(),p(Wl[Ls],1,1,()=>{Wl[Ls]=null}),Z(),K=Wl[P],K||(K=Wl[P]=pa[P](t),K.c()),o(K,1),K.m(Kl.parentNode,Kl));const Ja={};s&2&&(Ja.$$scope={dirty:s,ctx:t}),nt.$set(Ja);const ya={};s&2&&(ya.$$scope={dirty:s,ctx:t}),at.$set(ya)},i(t){Zs||(o(T.$$.fragment,t),o(j.$$.fragment,t),o(mt.$$.fragment,t),o(k),o(G),o(ot.$$.fragment,t),o(Mt.$$.fragment,t),o(Jt.$$.fragment,t),o(ut.$$.fragment,t),o(bt.$$.fragment,t),o(wt.$$.fragment,t),o(x),o(ft.$$.fragment,t),o(R),o(V),o(z),o(Bt.$$.fragment,t),o(H),o(kt.$$.fragment,t),o(Gt.$$.fragment,t),o(et.$$.fragment,t),o(xt.$$.fragment,t),o(Rt.$$.fragment,t),o(Nt.$$.fragment,t),o(st.$$.fragment,t),o(Xt.$$.fragment,t),o(Qt.$$.fragment,t),o(Ht.$$.fragment,t),o(Yt.$$.fragment,t),o(Ft.$$.fragment,t),o(qt.$$.fragment,t),o(Lt.$$.fragment,t),o(Kt.$$.fragment,t),o(Ot.$$.fragment,t),o(ll.$$.fragment,t),o(el.$$.fragment,t),o(nl.$$.fragment,t),o(rl.$$.fragment,t),o(pl.$$.fragment,t),o(Y),o(Ml.$$.fragment,t),o(S),o(q),o(D),o(K),o(bl.$$.fragment,t),o(nt.$$.fragment,t),o(dl.$$.fragment,t),o(hl.$$.fragment,t),o(at.$$.fragment,t),o(jl.$$.fragment,t),Zs=!0)},o(t){p(T.$$.fragment,t),p(j.$$.fragment,t),p(mt.$$.fragment,t),p(k),p(G),p(ot.$$.fragment,t),p(Mt.$$.fragment,t),p(Jt.$$.fragment,t),p(ut.$$.fragment,t),p(bt.$$.fragment,t),p(wt.$$.fragment,t),p(x),p(ft.$$.fragment,t),p(R),p(V),p(z),p(Bt.$$.fragment,t),p(H),p(kt.$$.fragment,t),p(Gt.$$.fragment,t),p(et.$$.fragment,t),p(xt.$$.fragment,t),p(Rt.$$.fragment,t),p(Nt.$$.fragment,t),p(st.$$.fragment,t),p(Xt.$$.fragment,t),p(Qt.$$.fragment,t),p(Ht.$$.fragment,t),p(Yt.$$.fragment,t),p(Ft.$$.fragment,t),p(qt.$$.fragment,t),p(Lt.$$.fragment,t),p(Kt.$$.fragment,t),p(Ot.$$.fragment,t),p(ll.$$.fragment,t),p(el.$$.fragment,t),p(nl.$$.fragment,t),p(rl.$$.fragment,t),p(pl.$$.fragment,t),p(Y),p(Ml.$$.fragment,t),p(S),p(q),p(D),p(K),p(bl.$$.fragment,t),p(nt.$$.fragment,t),p(dl.$$.fragment,t),p(hl.$$.fragment,t),p(at.$$.fragment,t),p(jl.$$.fragment,t),Zs=!1},d(t){t&&(n(r),n(l),n(c),n(f),n(te),n(le),n(Rl),n(pt),n(ee),n(Nl),n(se),n(ct),n(ne),n(ae),n(re),n(yt),n(ie),n(me),n(pe),n(Tt),n(oe),n(ce),n(dt),n(Me),n(Vl),n(ht),n(Je),n(lt),n(ye),n(Ut),n(ue),n(be),n(Xl),n(jt),n(Te),n(It),n(we),n(zl),n(_t),n(de),n(Ql),n(gt),n(he),n(I),n(fe),n(O),n(_e),n(Zt),n(ge),n(Ze),n(Al),n($t),n(Be),n($e),n(vt),n(ke),n(ve),n(Ge),n(Ct),n(Ce),n(xe),n(Wt),n(We),n(Re),n(Ne),n(Vt),n(Ve),n(Xe),n(ze),n(zt),n(Qe),n(He),n(Ee),n(Et),n(Ye),n(Fe),n(Se),n(St),n(Ae),n(At),n(qe),n(Le),n(De),n(Dt),n(Pe),n(Pt),n(Ke),n(Oe),n(ts),n(tl),n(ls),n(es),n(ss),n(sl),n(ns),n(as),n(al),n(rs),n(is),n(il),n(ms),n(ml),n(ps),n(os),n(ol),n(cs),n(ql),n(cl),n(Ms),n(Js),n(Ll),n(Jl),n(ys),n(Dl),n(yl),n(us),n(Pl),n(ul),n(bs),n(Kl),n(Ts),n(Tl),n(ws),n(ds),n(wl),n(hs),n(Us),n(fs),n(Ul),n(js),n(Is),n(fl),n(_s),n(gs),n(Ol)),n(e),u(T,t),u(j,t),u(mt,t),Il[$].d(t),_l[v].d(t),u(ot,t),u(Mt,t),u(Jt,t),u(ut,t),u(bt,t),u(wt,t),gl[C].d(t),u(ft,t),Zl[W].d(t),Bl[N].d(t),$l[X].d(t),u(Bt,t),kl[Q].d(t),u(kt,t),u(Gt,t),u(et,t),u(xt,t),u(Rt,t),u(Nt,t),u(st,t),u(Xt,t),u(Qt,t),u(Ht,t),u(Yt,t),u(Ft,t),u(qt,t),u(Lt,t),u(Kt,t),u(Ot,t),u(ll,t),u(el,t),u(nl,t),u(rl,t),u(pl,t),vl[E].d(t),u(Ml,t),Gl[F].d(t),Cl[A].d(t),xl[L].d(t),Wl[P].d(t),u(bl,t),u(nt,t),u(dl,t),u(hl,t),u(at,t),u(jl,t)}}}const nr='{"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 ar(b,e,r){let l="pt";return fa(()=>{const c=new URLSearchParams(window.location.search);r(0,l=c.get("fw")||"pt")}),[l]}class yr extends ja{constructor(e){super(),Ia(this,e,ar,sr,Ua,{})}}export{yr as component};
