import{s as Ua,o as fa,n as Ze}from"../chunks/scheduler.cc52f4b9.js";import{S as ga,i as ja,e as b,s as c,c as h,q as it,H as ua,h as ka,a as T,d as s,b as r,f as Be,g as M,j as U,r as ct,x as ya,k as Pe,l as I,m as a,n as J,o as m,u as v,t as o,p as u,v as _}from"../chunks/index.9480bb2b.js";import{T as Ce}from"../chunks/Tip.f7b80743.js";import{C as Ia,H as $e,E as va}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.7aac1ff7.js";import{Y as da}from"../chunks/Youtube.7b12d9e8.js";import{C as w}from"../chunks/CodeBlock.ca838256.js";import{C as ba}from"../chunks/CourseFloatingBanner.d5461535.js";import{F as _a}from"../chunks/FrameworkSwitchCourse.42d12053.js";function Ba(y){let l,i;return l=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/vi/chapter6/section3b_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/vi/chapter6/section3b_tf.ipynb"}]}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Ca(y){let l,i;return l=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/vi/chapter6/section3b_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/vi/chapter6/section3b_pt.ipynb"}]}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function $a(y){let l,i;return l=new da({props:{id:"b3u8RzBCX9Y"}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Za(y){let l,i;return l=new da({props:{id:"_wxyB3j3mk4"}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function xa(y){let l,i;return l=new w({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS1jYXNlZC1kaXN0aWxsZWQtc3F1YWQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIocXVlc3Rpb24lMkMlMjBjb250ZXh0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForQuestionAnswering

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

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

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

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

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Che tất cả mọi thứ trừ token của ngữ cảnh</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"># Hiển thị token [CLS]</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(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Wa(y){let l,i;return l=new w({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFzZXF1ZW5jZV9pZHMlMjAlM0QlMjBpbnB1dHMuc2VxdWVuY2VfaWRzKCklMEElMjMlMjBDaGUlMjB0JUUxJUJBJUE1dCUyMGMlRTElQkElQTMlMjBtJUUxJUJCJThEaSUyMHRoJUUxJUJCJUE5JTIwdHIlRTElQkIlQUIlMjB0b2tlbiUyMGMlRTElQkIlQTdhJTIwbmclRTElQkIlQUYlMjBjJUUxJUJBJUEzbmglMEFtYXNrJTIwJTNEJTIwJTVCaSUyMCElM0QlMjAxJTIwZm9yJTIwaSUyMGluJTIwc2VxdWVuY2VfaWRzJTVEJTBBJTIzJTIwSGklRTElQkIlODNuJTIwdGglRTElQkIlOEIlMjB0b2tlbiUyMCU1QkNMUyU1RCUwQW1hc2slNUIwJTVEJTIwJTNEJTIwRmFsc2UlMEFtYXNrJTIwJTNEJTIwdG9yY2gudGVuc29yKG1hc2spJTVCTm9uZSU1RCUwQSUwQXN0YXJ0X2xvZ2l0cyU1Qm1hc2slNUQlMjAlM0QlMjAtMTAwMDAlMEFlbmRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMA==",highlighted:`<span class="hljs-keyword">import</span> torch

sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Che tất cả mọi thứ trừ token của ngữ cảnh</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"># Hiển thị token [CLS]</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(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Xa(y){let l,i;return l=new w({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpJTVCMCU1RC5udW1weSgpJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0Zi5tYXRoLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGF4aXMlM0QtMSklNUIwJTVELm51bXB5KCk=",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].numpy()`,wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function za(y){let l,i;return l=new w({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklNUIwJTVEJTBBZW5kX3Byb2JhYmlsaXRpZXMlMjAlM0QlMjB0b3JjaC5ubi5mdW5jdGlvbmFsLnNvZnRtYXgoZW5kX2xvZ2l0cyUyQyUyMGRpbSUzRC0xKSU1QjAlNUQ=",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Qa(y){let l,i="Sau đó, chúng tôi sẽ che các giá trị trong đó <code>start_index &gt; end_index</code> bằng cách đặt chúng thành <code>0</code> (các xác suất khác đều là số dương). Hàm <code>np.triu()</code> trả về phần tam giác phía trên của tensor 2D được truyền dưới dạng tham số, vì vậy nó sẽ thực hiện việc che đó cho chúng ta:",n,p,d;return p=new w({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBc2NvcmVzJTIwJTNEJTIwbnAudHJpdShzY29yZXMp",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

scores = np.triu(scores)`,wrap:!1}}),{c(){l=b("p"),l.innerHTML=i,n=c(),h(p.$$.fragment)},l(f){l=T(f,"P",{"data-svelte-h":!0}),U(l)!=="svelte-1oqxu7v"&&(l.innerHTML=i),n=r(f),M(p.$$.fragment,f)},m(f,g){a(f,l,g),a(f,n,g),J(p,f,g),d=!0},i(f){d||(o(p.$$.fragment,f),d=!0)},o(f){m(p.$$.fragment,f),d=!1},d(f){f&&(s(l),s(n)),u(p,f)}}}function Ea(y){let l,i="Sau đó, chúng tôi sẽ che các giá trị trong đó <code>start_index &gt; end_index</code> bằng cách đặt chúng thành <code>0</code> (các xác suất khác đều là số dương). Hàm <code>torch.triu()</code> trả về phần tam giác phía trên của tensor 2D được truyền dưới dạng tham số, vì vậy nó sẽ thực hiện việc che đó cho chúng ta:",n,p,d;return p=new w({props:{code:"c2NvcmVzJTIwJTNEJTIwdG9yY2gudHJpdShzY29yZXMp",highlighted:"scores = torch.triu(scores)",wrap:!1}}),{c(){l=b("p"),l.innerHTML=i,n=c(),h(p.$$.fragment)},l(f){l=T(f,"P",{"data-svelte-h":!0}),U(l)!=="svelte-1cu0hmx"&&(l.innerHTML=i),n=r(f),M(p.$$.fragment,f)},m(f,g){a(f,l,g),a(f,n,g),J(p,f,g),d=!0},i(f){d||(o(p.$$.fragment,f),d=!0)},o(f){m(p.$$.fragment,f),d=!1},d(f){f&&(s(l),s(n)),u(p,f)}}}function Ha(y){let l,i="✏️ <strong>Thử nghiệm thôi!</strong> Tính chỉ mục bắt đầu và kết thúc cho năm cấu trả lời đầu tiện.";return{c(){l=b("p"),l.innerHTML=i},l(n){l=T(n,"P",{"data-svelte-h":!0}),U(l)!=="svelte-kp1d7g"&&(l.innerHTML=i)},m(n,p){a(n,l,p)},p:Ze,d(n){n&&s(l)}}}function Fa(y){let l,i="✏️ <strong>Thử nghiệm thôi!</strong> Sử dụng điểm tốt nhất mà bạn đã tính toán trước đó để hiển thị năm câu trả lời có khả năng nhất. Để kiểm tra kết quả của bạn, hãy quay lại đường dẫn đầu tiên và truyền vào <code>top_k=5</code> khi gọi nó.";return{c(){l=b("p"),l.innerHTML=i},l(n){l=T(n,"P",{"data-svelte-h":!0}),U(l)!=="svelte-1y0c4jh"&&(l.innerHTML=i)},m(n,p){a(n,l,p)},p:Ze,d(n){n&&s(l)}}}function Ya(y){let l,i,n,p;return l=new w({props:{code:"XyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb3ZlcmZsb3dfdG9fc2FtcGxlX21hcHBpbmclMjIpJTBBb2Zmc2V0cyUyMCUzRCUyMGlucHV0cy5wb3AoJTIyb2Zmc2V0X21hcHBpbmclMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW5wdXRzLmNvbnZlcnRfdG9fdGVuc29ycyglMjJ0ZiUyMiklMEFwcmludChpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUp",highlighted:`_ = inputs.pop(<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>)
offsets = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)

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

inputs = inputs.convert_to_tensors(<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)`,wrap:!1}}),n=new w({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){h(l.$$.fragment),i=c(),h(n.$$.fragment)},l(d){M(l.$$.fragment,d),i=r(d),M(n.$$.fragment,d)},m(d,f){J(l,d,f),a(d,i,f),J(n,d,f),p=!0},i(d){p||(o(l.$$.fragment,d),o(n.$$.fragment,d),p=!0)},o(d){m(l.$$.fragment,d),m(n.$$.fragment,d),p=!1},d(d){d&&s(i),u(l,d),u(n,d)}}}function Aa(y){let l,i;return l=new w({props:{code:"KDIlMkMlMjAzODQpJTIwKDIlMkMlMjAzODQp",highlighted:'(<span class="hljs-number">2</span>, <span class="hljs-number">384</span>) (<span class="hljs-number">2</span>, <span class="hljs-number">384</span>)',wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function qa(y){let l,i;return l=new w({props:{code:"dG9yY2guU2l6ZSglNUIyJTJDJTIwMzg0JTVEKSUyMHRvcmNoLlNpemUoJTVCMiUyQyUyMDM4NCU1RCk=",highlighted:'torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>]) torch.Size([<span class="hljs-number">2</span>, <span class="hljs-number">384</span>])',wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function La(y){let l,i;return l=new w({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwQ2hlJTIwdCVFMSVCQSVBNXQlMjBjJUUxJUJBJUEzJTIwbSVFMSVCQiU4RGklMjB0aCVFMSVCQiVBOSUyMHRyJUUxJUJCJUFCJTIwdG9rZW4lMjBjJUUxJUJCJUE3YSUyMG5nJUUxJUJCJUFGJTIwYyVFMSVCQSVBM25oJTBBbWFzayUyMCUzRCUyMCU1QmklMjAhJTNEJTIwMSUyMGZvciUyMGklMjBpbiUyMHNlcXVlbmNlX2lkcyU1RCUwQSUyMyUyMEhpJUUxJUJCJTgzbiUyMHRoJUUxJUJCJThCJTIwdG9rZW4lMjAlNUJDTFMlNUQlMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwQ2hlJTIwdCVFMSVCQSVBNXQlMjBjJUUxJUJBJUEzJTIwdG9rZW4lMjAlNUJQQUQlNUQlMEFtYXNrJTIwJTNEJTIwdGYubWF0aC5sb2dpY2FsX29yKHRmLmNvbnN0YW50KG1hc2spJTVCTm9uZSU1RCUyQyUyMGlucHV0cyU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTIwJTNEJTNEJTIwMCklMEElMEFzdGFydF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwc3RhcnRfbG9naXRzKSUwQWVuZF9sb2dpdHMlMjAlM0QlMjB0Zi53aGVyZShtYXNrJTJDJTIwLTEwMDAwJTJDJTIwZW5kX2xvZ2l0cyk=",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Che tất cả mọi thứ trừ token của ngữ cảnh</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"># Hiển thị token [CLS]</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Che tất cả token [PAD]</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(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Da(y){let l,i;return l=new w({props:{code:"c2VxdWVuY2VfaWRzJTIwJTNEJTIwaW5wdXRzLnNlcXVlbmNlX2lkcygpJTBBJTIzJTIwQ2hlJTIwdCVFMSVCQSVBNXQlMjBjJUUxJUJBJUEzJTIwbSVFMSVCQiU4RGklMjB0aCVFMSVCQiVBOSUyMHRyJUUxJUJCJUFCJTIwdG9rZW4lMjBjJUUxJUJCJUE3YSUyMG5nJUUxJUJCJUFGJTIwYyVFMSVCQSVBM25oJTBBbWFzayUyMCUzRCUyMCU1QmklMjAhJTNEJTIwMSUyMGZvciUyMGklMjBpbiUyMHNlcXVlbmNlX2lkcyU1RCUwQSUyMyUyMEhpJUUxJUJCJTgzbiUyMHRoJUUxJUJCJThCJTIwdG9rZW4lMjAlNUJDTFMlNUQlMEFtYXNrJTVCMCU1RCUyMCUzRCUyMEZhbHNlJTBBJTIzJTIwQ2hlJTIwdCVFMSVCQSVBNXQlMjBjJUUxJUJBJUEzJTIwdG9rZW4lMjAlNUJQQUQlNUQlMEFtYXNrJTIwJTNEJTIwdG9yY2gubG9naWNhbF9vcih0b3JjaC50ZW5zb3IobWFzayklNUJOb25lJTVEJTJDJTIwKGlucHV0cyU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTVEJTIwJTNEJTNEJTIwMCkpJTBBJTBBc3RhcnRfbG9naXRzJTVCbWFzayU1RCUyMCUzRCUyMC0xMDAwMCUwQWVuZF9sb2dpdHMlNUJtYXNrJTVEJTIwJTNEJTIwLTEwMDAw",highlighted:`sequence_ids = inputs.sequence_ids()
<span class="hljs-comment"># Che tất cả mọi thứ trừ token của ngữ cảnh</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"># Hiển thị token [CLS]</span>
mask[<span class="hljs-number">0</span>] = <span class="hljs-literal">False</span>
<span class="hljs-comment"># Che tất cả token [PAD]</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(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Pa(y){let l,i;return l=new w({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBheGlzJTNELTEpLm51bXB5KCklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRmLm1hdGguc29mdG1heChlbmRfbG9naXRzJTJDJTIwYXhpcyUzRC0xKS5udW1weSgp",highlighted:`start_probabilities = tf.math.softmax(start_logits, axis=-<span class="hljs-number">1</span>).numpy()
end_probabilities = tf.math.softmax(end_logits, axis=-<span class="hljs-number">1</span>).numpy()`,wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Ka(y){let l,i;return l=new w({props:{code:"c3RhcnRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChzdGFydF9sb2dpdHMlMkMlMjBkaW0lM0QtMSklMEFlbmRfcHJvYmFiaWxpdGllcyUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuc29mdG1heChlbmRfbG9naXRzJTJDJTIwZGltJTNELTEp",highlighted:`start_probabilities = torch.nn.functional.softmax(start_logits, dim=-<span class="hljs-number">1</span>)
end_probabilities = torch.nn.functional.softmax(end_logits, dim=-<span class="hljs-number">1</span>)`,wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function Oa(y){let l,i;return l=new w({props:{code:"Y2FuZGlkYXRlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMHN0YXJ0X3Byb2JzJTJDJTIwZW5kX3Byb2JzJTIwaW4lMjB6aXAoc3RhcnRfcHJvYmFiaWxpdGllcyUyQyUyMGVuZF9wcm9iYWJpbGl0aWVzKSUzQSUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyMCUzRCUyMHN0YXJ0X3Byb2JzJTVCJTNBJTJDJTIwTm9uZSU1RCUyMColMjBlbmRfcHJvYnMlNUJOb25lJTJDJTIwJTNBJTVEJTBBJTIwJTIwJTIwJTIwaWR4JTIwJTNEJTIwbnAudHJpdShzY29yZXMpLmFyZ21heCgpLml0ZW0oKSUwQSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2lkeCUyMCUzRCUyMGlkeCUyMCUyRiUyRiUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEElMjAlMjAlMjAlMjBlbmRfaWR4JTIwJTNEJTIwaWR4JTIwJTI1JTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQSUyMCUyMCUyMCUyMHNjb3JlJTIwJTNEJTIwc2NvcmVzJTVCc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCU1RC5pdGVtKCklMEElMjAlMjAlMjAlMjBjYW5kaWRhdGVzLmFwcGVuZCgoc3RhcnRfaWR4JTJDJTIwZW5kX2lkeCUyQyUyMHNjb3JlKSklMEElMEFwcmludChjYW5kaWRhdGVzKQ==",highlighted:`candidates = []
<span class="hljs-keyword">for</span> start_probs, end_probs <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(start_probabilities, end_probabilities):
    scores = start_probs[:, <span class="hljs-literal">None</span>] * end_probs[<span class="hljs-literal">None</span>, :]
    idx = np.triu(scores).argmax().item()

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

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

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

<span class="hljs-built_in">print</span>(candidates)`,wrap:!1}}),{c(){h(l.$$.fragment)},l(n){M(l.$$.fragment,n)},m(n,p){J(l,n,p),i=!0},i(n){i||(o(l.$$.fragment,n),i=!0)},o(n){m(l.$$.fragment,n),i=!1},d(n){u(l,n)}}}function ni(y){let l,i="✏️ <strong>Thử nghiệm thôi!</strong> Hãy điều chỉnh đoạn mã trên để trả về điểm và khoảng cho năm câu trả lời có nhiều khả năng nhất (tổng cộng, không phải cho mỗi đoạn).";return{c(){l=b("p"),l.innerHTML=i},l(n){l=T(n,"P",{"data-svelte-h":!0}),U(l)!=="svelte-24pghw"&&(l.innerHTML=i)},m(n,p){a(n,l,p)},p:Ze,d(n){n&&s(l)}}}function li(y){let l,i="✏️ <strong>Thử nghiệm thôi!</strong> Sử dụng điểm tốt nhất bạn đã tính toán trước đó để hiển thị năm câu trả lời có khả năng xảy ra nhất (cho toàn bộ ngữ cảnh, không phải từng đoạn). Để kiểm tra kết quả của bạn, hãy quay lại pipeline đầu tiên và truyền vào <code>top_k=5</code> khi gọi nó.";return{c(){l=b("p"),l.innerHTML=i},l(n){l=T(n,"P",{"data-svelte-h":!0}),U(l)!=="svelte-497a89"&&(l.innerHTML=i)},m(n,p){a(n,l,p)},p:Ze,d(n){n&&s(l)}}}function ei(y){let l,i,n,p,d,f,g,nl,rt,ll,B,C,Rn,mt,Ke="Giờ chúng ta sẽ đi sâu vào pipeline <code>question-answering</code> và xem cách tận dụng các offset để lấy câu trả lời cho các câu hỏi dựa theo từ ngữ cảnh, giống như chúng ta đã làm với các thực thể được nhóm trong phần trước. Sau đó, chúng ta sẽ xem làm thế nào có thể đối phó với những ngữ cảnh rất dài mà cuối cùng lại bị cắt bớt. Bạn có thể bỏ qua phần này nếu không quan tâm đến tác vụ hỏi đáp.",el,$,Z,Wn,ot,sl,pt,Oe='Như đã thấy trong <a href="/course/chapter1">Chương 1</a>, ta có thể sử dụng pipeline <code>question-answering</code> như sau để nhận được câu trả lời cho câu hỏi:',al,ht,il,Mt,cl,Jt,ts="Không như các pipeline khác không thể cắt gọn và chia văn bản dài hơn độ dài tối đa cho phép của mô hình (dẫn đến bỏ lỡ những thông tin ở phần cuối văn bản), pipeline này có thể xử lý tốt với những ngữ cảnh dài và sẽ trả về câu trả lời kể cả khi nó nằm ở cuối văn bản:",rl,ut,ml,yt,ol,dt,ns="Hãy cùng nhau xem nó làm thế nào!",pl,bt,hl,Tt,ls='Như những pipeline khác, ta sẽ bắt đầu với việc tokenize đầu vào và sau đó truyền chúng vào trong mô hình. Mặc định checkpoint được sử dụng cho pipeline <code>question-answering</code> là <a href="https://huggingface.co/distilbert-base-cased-distilled-squad" rel="nofollow"><code>distilbert-base-cased-distilled-squad</code></a> ( “squad” trong tên bắt nguồn từ bộ dữ liệu mà mô hình sử dụng để tinh chỉnh; ta sẽ nói sâu hơn về bộ dữ liệu SQuAD này ở  <a href="/course/chapter7/7">Chương 7</a>):',Ml,x,G,Xn,wt,es="Lưu ý rằng chúng ta tokenize câu hỏi và ngữ cảnh như một cặp, với câu hỏi đứng trước.",Jl,nt,ss='<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"/>',ul,Ut,as="Các mô hình hỏi đáp hoạt động hơi khác so với các mô hình mà ta đã thấy cho đến nay. Sử dụng hình trên làm ví dụ, mô hình đã được huấn luyện để dự đoán chỉ mục của token bắt đầu câu trả lời (ở đây là 21) và chỉ mục của token nơi câu trả lời kết thúc (ở đây là 24). Đây là lý do tại sao các mô hình đó không trả về một tensor logit mà là hai: một cho các logit tương ứng với token bắt đầu của câu trả lời và một cho các các logit tương ứng với token kết thúc của câu trả lời. Vì trong trường hợp này, chúng ta chỉ có một đầu vào chứa 66 token, ta nhận được:",yl,ft,dl,V,N,zn,gt,is="Để chuyển đổi các logit đó thành xác suất, chúng ta sẽ áp dụng một hàm softmax - nhưng trước đó, chúng ta cần đảm bảo rằng chúng ta che dấu các chỉ mục không phải là một phần của ngữ cảnh. Đầu vào của chúng tôi là <code>[CLS] question [SEP] context [SEP]</code>, vì vậy chúng ta cần che dấu các token của câu hỏi cũng như token <code>[SEP]</code>. Tuy nhiên, chúng ta sẽ giữ token <code>[CLS]</code> vì một số mô hình sử dụng nó để chỉ ra rằng câu trả lời không nằm trong ngữ cảnh.",bl,jt,cs="Vì chúng ta sẽ áp dụng softmax sau đó, chúng ta chỉ cần thay thế các logit muốn che bằng một số âm lớn. Ở đây, chúng ta sử dụng <code>-10000</code>:",Tl,R,W,Qn,kt,rs="Giờ chúng ta đã che các logit tương ứng với các vị trí mà chúng ta không muốn dự đoán, chúng ta có thể áp dụng softmax:",wl,X,z,En,It,ms="Ở giai đoạn này, chúng ta có thể lấy argmax xác suất bắt đầu và kết thúc - nhưng chúng ta có thể kết thúc với chỉ mục bắt đầu lớn hơn kết thúc, vì vậy chúng ta cần thực hiện thêm một số biện pháp phòng ngừa. Chúng ta sẽ tính toán xác suất của từng <code>start_index</code> và <code>end_index</code> có thể trong đó <code>start_index &lt;= end_index</code>, sau đó lấy <code>(start_index, end_index)</code> với xác suất cao nhất.",Ul,j,xe,Hn,os="start_index",Ge,Fn,ps="end_index",Ve,Yn,hs="start_index",Ne,Sn,Ms="end_index",Re,fl,Ta='<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>',gl,O,We,jl,wa='<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>',kl,An,Js="start_index <= end_index",Xe,Il,vt,us="Đầu tiên, hãy tính toán tất cả các đầu ra có thể có:",vl,_t,_l,Q,E,qn,Bt,ys="Bây giờ chúng ta chỉ cần lấy chỉ mục tối đa. Vì PyTorch sẽ trả về chỉ mục trong tensor phẳng, chúng ta cần sử dụng phép chia làm tròn xuống <code>//</code> và lấy dư <code>%</code> để nhận được <code>start_index</code> và <code>end_index</code>:",Bl,Ct,Cl,$t,ds="Chúng ta chưa xong đâu, nhưng ít nhất chúng ta đã có điểm chính xác cho câu trả lời (bạn có thể kiểm tra điều này bằng cách so sánh nó với kết quả đầu tiên trong phần trước):",$l,Zt,Zl,lt,xl,xt,bs="Ta có <code>start_index</code> và <code>end_index</code> của câu trả lời theo token nên ta chỉ cần chuyển đổi các chỉ mục kí tự trong ngữ cảnh. Đấy là nơi offset sẽ cực kì hữu ích. Ta có thể lấy và sử dụng chúng như cách ta làm trong tác vụ phân loại token:",Gl,Gt,Vl,Vt,Ts="Bây giờ chúng ta chỉ cần định dạng mọi thứ để có được kết quả:",Nl,Nt,Rl,Rt,Wl,Wt,ws="Tuyệt quá! Kết quả đó giống như trong ví dụ đầu tiên của chúng ta!",Xl,et,zl,Xt,Ql,zt,Us="Nếu chúng ta cố gắng tokenize các câu hỏi và ngữ cảnh dài ta từng lấy làm ví dụ trước đó, ta sẽ nhận được số token nhiều hơn độ dài tối da sử dụng trong pipeline <code>question-answering</code> (đó là 384):",El,Qt,Hl,Et,Fl,Ht,fs="Vì vậy, chúng ta sẽ cần phải cắt bớt đầu vào của mình ở độ dài tối đa đó. Có một số cách ta có thể làm điều này, nhưng chúng ta không muốn cắt ngắn câu hỏi, chỉ cắt bỏ ngữ cảnh. Vì ngữ cảnh là câu thứ hai, chúng ta sẽ sử dụng chiến lược cắt ngắn <code>&quot;only_second&quot;</code>. Vấn đề nảy sinh sau đó là câu trả lời cho câu hỏi có thể không nằm trong ngữ cảnh đã bị cắt ngắn. Ví dụ: ở đây, chúng ta đã chọn một câu hỏi trong đó câu trả lời nằm ở cuối ngữ cảnh và khi cắt ngắn câu trả lời đó thì câu trả lời không còn:",Yl,Ft,Sl,Yt,Al,St,gs="Điều này có nghĩa là mô hình sẽ gặp khó khăn trong việc chọn ra câu trả lời chính xác. Để khắc phục điều này, pipeline hỏi đáp cho phép chúng ta chia ngữ cảnh thành các phần nhỏ hơn, chỉ định độ dài tối đa. Để đảm bảo rằng chúng ta không chia bối cảnh chính xác ở vị trí sai để có thể tìm ra câu trả lời, nó cũng bao gồm một số phần trùng lặp giữa các phần.",ql,At,js="Chúng ta có thể yêu cầu tokenizer (nhanh hoặc chậm) thực hiện việc này bằng cách thêm <code>return_overflowing_tokens=True</code> và ta có thể chỉ định sự giao thoa mà ta muốn qua than số <code>stride</code>. Đây là một ví dụ, sử dụng một câu nhỏ hơn:",Ll,qt,Dl,Lt,Pl,Dt,ks="Có thể thấy, câu đã bị chia thành các đoạn sao cho mỗi phần trong <code>inputs[&quot;input_ids&quot;]</code> có nhiều nhất 6 token (ta sẽ cần thêm đệm để đảm bảo chúng có cùng kích thước) và sẽ có sử giao thoa của 2 token giữa các phần.",Kl,Pt,Is="Hãy cùng nhìn kĩ hơn vào kết quả tokenize:",Ol,Kt,te,Ot,ne,tn,vs="Như dự đoán, ta nhận được ID đầu vào và attention mask.Ở đây, <code>overflow_to_sample_mapping</code> là một phép ánh xạ cho ta biết câu nào trong kết quả liên quan — ta có 7 kết quả dều từ câu mà ta truyền vào tokenizer:",le,nn,ee,ln,se,en,_s="Điều này hữu ích hơn khi ta tokenize nhiều câu cùng nhau, Ví dụ:",ae,sn,ie,an,Bs="trả cho ta:",ce,cn,re,rn,Cs="nghĩa là câu đầu tiên được chia thành 7 đoạn như phần phía trước, và 4 đoạn tiếp theo đến từ câu thứ hai.",me,mn,$s="Bây giờ chúng ta hãy cùng quay trở lại ngữ cảnh dài. Theo mặc định, pipeline `<code>question-answering</code> sử dụng độ dài tối đa là 384, như đã đề cập trước đó và khoảng cách 128, tương ứng với cách mô hình được tinh chỉnh (bạn có thể điều chỉnh các tham số đó bằng cách truyền <code>max_seq_len</code> và <code>stride</code> khi gọi pipeline). Do đó, chúng ta sẽ sử dụng các tham số đó khi tokenize. Chúng ta cũng sẽ thêm phần đệm (để có các mẫu có cùng chiều dài, vì vậy chúng ta có thể tạo ra các tensor) cũng như yêu cầu các offset:",oe,on,pe,pn,Zs="Các <code>inputs</code> sẽ chứa các ID đầu vào và các attention mask mà mô hình kì vọng, cũng như offset và <code>overflow_to_sample_mapping</code> ta vừa trao đổi ở trên. Vì hai tham số đó không phải là tham số được sử dụng bởi mô hình, chúng ta sẽ đưa chúng ra khỏi <code>inputs</code> (và không lưu trữ ánh xạ, vì nó không hữu ích ở đây) trước khi chuyển đổi nó thành tensor:",he,H,F,Ln,hn,xs="Bối cảnh dài của chúng ta được chia làm hai, đồng nghĩa sau khi nó đi qua mô hình, chúng ta sẽ có hai bộ logit bắt đầu và kết thúc:",Me,Mn,Je,Y,S,Dn,Jn,Gs="Giống như trước đây, đầu tiên chúng ta che các token không phải là một phần của ngữ cảnh trước khi sử dụng softmax. Chúng ta cũng che tất cả các token đệm (được gắn mác bởi attention mask):",ue,A,q,Pn,un,Vs="Sau đó, chúng ta có thể sử dụng softmax để chuyển đổi các logit của chúng ta thành xác suất:",ye,L,D,Kn,yn,Ns="Bước tiếp theo tương tự như những gì chúng ta đã làm cho bối cảnh nhỏ, nhưng chúng ta lặp lại nó cho mỗi phần trong hai phần của mình. Chúng ta tính điểm cho tất cả các khoảng câu trả lời có thể có, sau đó lấy phần có điểm tốt nhất:",de,P,K,On,dn,be,bn,Rs="Hai ứng cử viên đó tương ứng với các câu trả lời tốt nhất mà mô hình có thể tìm thấy trong mỗi đoạn. Mô hình chắc chắn hơn rằng câu trả lời đúng nằm ở phần thứ hai (đó là một dấu hiệu tốt!). Bây giờ chúng ta chỉ cần ánh xạ khoảng hai token đó với khoảng các ký tự trong ngữ cảnh (chúng ta chỉ cần lập ánh xạ cái thứ hai để có câu trả lời, nhưng thật thú vị khi xem mô hình đã chọn những gì trong đoạn đầu tiên).",Te,st,we,Tn,Ws="<code>offsets</code> mà chúng ta đã nắm được trước đó thực sự là một danh sách các offset, với một danh sách trên mỗi đoạn văn bản:",Ue,wn,fe,Un,ge,fn,Xs="Nếu chúng ta bỏ qua kết quả đầu tiên, chúng ta sẽ nhận được kết quả tương tự như pipeline cho ngữ cảnh dài này - yayy!",je,at,ke,gn,zs="Điều này kết thúc phần đi sâu vào các khả năng của tokenizer. Chúng ta sẽ đưa tất cả những điều này vào thực tế một lần nữa trong chương tiếp theo, khi chúng tôi hướng dẫn bạn cách tinh chỉnh một mô hình về một loạt các tác vụ NLP phổ biến.",Ie,jn,ve,tl,_e;d=new _a({props:{fw:y[0]}}),g=new Ia({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),rt=new $e({props:{title:"Fast tokenizers in the QA pipeline",local:"fast-tokenizers-in-the-qa-pipeline",headingTag:"h1"}});const Qs=[Ca,Ba],kn=[];function Es(t,e){return t[0]==="pt"?0:1}B=Es(y),C=kn[B]=Qs[B](y);const Hs=[Za,$a],In=[];function Fs(t,e){return t[0]==="pt"?0:1}$=Fs(y),Z=In[$]=Hs[$](y),ot=new $e({props:{title:"Sử dụng pipeline question-answering",local:"sử-dụng-pipeline-question-answering",headingTag:"h2"}}),ht=new w({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcXVlc3Rpb25fYW5zd2VyZXIlMjAlM0QlMjBwaXBlbGluZSglMjJxdWVzdGlvbi1hbnN3ZXJpbmclMjIpJTBBY29udGV4dCUyMCUzRCUyMCUyMiUyMiUyMiUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMGlzJTIwYmFja2VkJTIwYnklMjB0aGUlMjB0aHJlZSUyMG1vc3QlMjBwb3B1bGFyJTIwZGVlcCUyMGxlYXJuaW5nJTIwbGlicmFyaWVzJTIwJUUyJTgwJTk0JTIwSmF4JTJDJTIwUHlUb3JjaCUyQyUyMGFuZCUyMFRlbnNvckZsb3clMjAlRTIlODAlOTQlMjB3aXRoJTIwYSUyMHNlYW1sZXNzJTIwaW50ZWdyYXRpb24lMEFiZXR3ZWVuJTIwdGhlbS4lMjBJdCdzJTIwc3RyYWlnaHRmb3J3YXJkJTIwdG8lMjB0cmFpbiUyMHlvdXIlMjBtb2RlbHMlMjB3aXRoJTIwb25lJTIwYmVmb3JlJTIwbG9hZGluZyUyMHRoZW0lMjBmb3IlMjBpbmZlcmVuY2UlMjB3aXRoJTIwdGhlJTIwb3RoZXIuJTBBJTIyJTIyJTIyJTBBcXVlc3Rpb24lMjAlM0QlMjAlMjJXaGljaCUyMGRlZXAlMjBsZWFybmluZyUyMGxpYnJhcmllcyUyMGJhY2slMjAlRjAlOUYlQTQlOTclMjBUcmFuc2Zvcm1lcnMlM0YlMjIlMEFxdWVzdGlvbl9hbnN3ZXJlcihxdWVzdGlvbiUzRHF1ZXN0aW9uJTJDJTIwY29udGV4dCUzRGNvbnRleHQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

question_answerer = pipeline(<span class="hljs-string">&quot;question-answering&quot;</span>)
context = <span class="hljs-string">&quot;&quot;&quot;
🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch, and TensorFlow — with a seamless integration
between them. It&#x27;s straightforward to train your models with one before loading them for inference with the other.
&quot;&quot;&quot;</span>
question = <span class="hljs-string">&quot;Which deep learning libraries back 🤗 Transformers?&quot;</span>
question_answerer(question=question, context=context)`,wrap:!1}}),Mt=new w({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTc3NzMlMkMlMEElMjAnc3RhcnQnJTNBJTIwNzglMkMlMEElMjAnZW5kJyUzQSUyMDEwNSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),ut=new w({props:{code:"bG9uZ19jb250ZXh0JTIwJTNEJTIwJTIyJTIyJTIyJTBBJUYwJTlGJUE0JTk3JTIwVHJhbnNmb3JtZXJzJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3R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ZyUyMGxpYnJhcmllcyUyMCVFMiU4MCU5NCUyMEpheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JTIwJUUyJTgwJTk0JTIwd2l0aCUyMGElMjBzZWFtbGVzcyUyMGludGVncmF0aW9uJTBBYmV0d2VlbiUyMHRoZW0uJTIwSXQncyUyMHN0cmFpZ2h0Zm9yd2FyZCUyMHRvJTIwdHJhaW4lMjB5b3VyJTIwbW9kZWxzJTIwd2l0aCUyMG9uZSUyMGJlZm9yZSUyMGxvYWRpbmclMjB0aGVtJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2l0aCUyMHRoZSUyMG90aGVyLiUwQSUyMiUyMiUyMiUwQXF1ZXN0aW9uX2Fuc3dlcmVyKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBjb250ZXh0JTNEbG9uZ19jb250ZXh0KQ==",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}}),yt=new w({props:{code:"JTdCJ3Njb3JlJyUzQSUyMDAuOTcxNDklMkMlMEElMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUwQSUyMCdlbmQnJTNBJTIwMTkxOSUyQyUwQSUyMCdhbnN3ZXInJTNBJTIwJ0pheCUyQyUyMFB5VG9yY2glMjBhbmQlMjBUZW5zb3JGbG93JyU3RA==",highlighted:`{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>,
 <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>}`,wrap:!1}}),bt=new $e({props:{title:"Sử dụng mô hình cho tác vụ hỏi đáp",local:"sử-dụng-mô-hình-cho-tác-vụ-hỏi-đáp",headingTag:"h2"}});const Ys=[Ga,xa],vn=[];function Ss(t,e){return t[0]==="pt"?0:1}x=Ss(y),G=vn[x]=Ys[x](y),ft=new w({props:{code:"c3RhcnRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5zdGFydF9sb2dpdHMlMEFlbmRfbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5lbmRfbG9naXRzJTBBcHJpbnQoc3RhcnRfbG9naXRzLnNoYXBlJTJDJTIwZW5kX2xvZ2l0cy5zaGFwZSk=",highlighted:`start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const As=[Na,Va],_n=[];function qs(t,e){return t[0]==="pt"?0:1}V=qs(y),N=_n[V]=As[V](y);const Ls=[Wa,Ra],Bn=[];function Ds(t,e){return t[0]==="pt"?0:1}R=Ds(y),W=Bn[R]=Ls[R](y);const Ps=[za,Xa],Cn=[];function Ks(t,e){return t[0]==="pt"?0:1}X=Ks(y),z=Cn[X]=Ps[X](y),_t=new w({props:{code:"c2NvcmVzJTIwJTNEJTIwc3RhcnRfcHJvYmFiaWxpdGllcyU1QiUzQSUyQyUyME5vbmUlNUQlMjAqJTIwZW5kX3Byb2JhYmlsaXRpZXMlNUJOb25lJTJDJTIwJTNBJTVE",highlighted:'scores = start_probabilities[:, <span class="hljs-literal">None</span>] * end_probabilities[<span class="hljs-literal">None</span>, :]',wrap:!1}});const Os=[Ea,Qa],$n=[];function ta(t,e){return t[0]==="pt"?0:1}Q=ta(y),E=$n[Q]=Os[Q](y),Ct=new w({props:{code:"bWF4X2luZGV4JTIwJTNEJTIwc2NvcmVzLmFyZ21heCgpLml0ZW0oKSUwQXN0YXJ0X2luZGV4JTIwJTNEJTIwbWF4X2luZGV4JTIwJTJGJTJGJTIwc2NvcmVzLnNoYXBlJTVCMSU1RCUwQWVuZF9pbmRleCUyMCUzRCUyMG1heF9pbmRleCUyMCUyNSUyMHNjb3Jlcy5zaGFwZSU1QjElNUQlMEFwcmludChzY29yZXMlNUJzdGFydF9pbmRleCUyQyUyMGVuZF9pbmRleCU1RCk=",highlighted:`max_index = scores.argmax().item()
start_index = max_index // scores.shape[<span class="hljs-number">1</span>]
end_index = max_index % scores.shape[<span class="hljs-number">1</span>]
<span class="hljs-built_in">print</span>(scores[start_index, end_index])`,wrap:!1}}),Zt=new w({props:{code:"MC45Nzc3Mw==",highlighted:'<span class="hljs-number">0.97773</span>',wrap:!1}}),lt=new Ce({props:{$$slots:{default:[Ha]},$$scope:{ctx:y}}}),Gt=new w({props:{code:"aW5wdXRzX3dpdGhfb2Zmc2V0cyUyMCUzRCUyMHRva2VuaXplcihxdWVzdGlvbiUyQyUyMGNvbnRleHQlMkMlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSklMEFvZmZzZXRzJTIwJTNEJTIwaW5wdXRzX3dpdGhfb2Zmc2V0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTBBJTBBc3RhcnRfY2hhciUyQyUyMF8lMjAlM0QlMjBvZmZzZXRzJTVCc3RhcnRfaW5kZXglNUQlMEFfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXRzJTVCZW5kX2luZGV4JTVEJTBBYW5zd2VyJTIwJTNEJTIwY29udGV4dCU1QnN0YXJ0X2NoYXIlM0FlbmRfY2hhciU1RA==",highlighted:`inputs_with_offsets = tokenizer(question, context, return_offsets_mapping=<span class="hljs-literal">True</span>)
offsets = inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]

start_char, _ = offsets[start_index]
_, end_char = offsets[end_index]
answer = context[start_char:end_char]`,wrap:!1}}),Nt=new w({props:{code:"cmVzdWx0JTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIyYW5zd2VyJTIyJTNBJTIwYW5zd2VyJTJDJTBBJTIwJTIwJTIwJTIwJTIyc3RhcnQlMjIlM0ElMjBzdGFydF9jaGFyJTJDJTBBJTIwJTIwJTIwJTIwJTIyZW5kJTIyJTNBJTIwZW5kX2NoYXIlMkMlMEElMjAlMjAlMjAlMjAlMjJzY29yZSUyMiUzQSUyMHNjb3JlcyU1QnN0YXJ0X2luZGV4JTJDJTIwZW5kX2luZGV4JTVEJTJDJTBBJTdEJTBBcHJpbnQocmVzdWx0KQ==",highlighted:`result = {
    <span class="hljs-string">&quot;answer&quot;</span>: answer,
    <span class="hljs-string">&quot;start&quot;</span>: start_char,
    <span class="hljs-string">&quot;end&quot;</span>: end_char,
    <span class="hljs-string">&quot;score&quot;</span>: scores[start_index, end_index],
}
<span class="hljs-built_in">print</span>(result)`,wrap:!1}}),Rt=new w({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnSmF4JTJDJTIwUHlUb3JjaCUyMGFuZCUyMFRlbnNvckZsb3cnJTJDJTBBJTIwJ3N0YXJ0JyUzQSUyMDc4JTJDJTBBJTIwJ2VuZCclM0ElMjAxMDUlMkMlMEElMjAnc2NvcmUnJTNBJTIwMC45Nzc3MyU3RA==",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>,
 <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">78</span>,
 <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">105</span>,
 <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97773</span>}`,wrap:!1}}),et=new Ce({props:{$$slots:{default:[Fa]},$$scope:{ctx:y}}}),Xt=new $e({props:{title:"Xử lý các ngữ cảnh dài",local:"xử-lý-các-ngữ-cảnh-dài",headingTag:"h2"}}),Qt=new w({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0KSUwQXByaW50KGxlbihpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKQ==",highlighted:`inputs = tokenizer(question, long_context)
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">len</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Et=new w({props:{code:"NDYx",highlighted:'<span class="hljs-number">461</span>',wrap:!1}}),Ft=new w({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHF1ZXN0aW9uJTJDJTIwbG9uZ19jb250ZXh0JTJDJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUyMHRydW5jYXRpb24lM0QlMjJvbmx5X3NlY29uZCUyMiklMEFwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCkp",highlighted:`inputs = tokenizer(question, long_context, max_length=<span class="hljs-number">384</span>, truncation=<span class="hljs-string">&quot;only_second&quot;</span>)
<span class="hljs-built_in">print</span>(tokenizer.decode(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))`,wrap:!1}}),Yt=new w({props:{code:"JTIyJTIyJTIyJTBBJTVCQ0xTJTVEJTIwV2hpY2glMjBkZWVwJTIwbGVhcm5pbmclMjBsaWJyYXJpZXMlMjBiYWNrJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTNGJTIwJTVCU0VQJTVEJTIwJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwJTNBJTIwU3RhdGUlMjBvZiUyMHRoZSUyMEFydCUyME5MUCUwQSUwQSU1QlVOSyU1RCUyMFRyYW5zZm9ybWVycyUyMHByb3ZpZGVzJTIwdGhvdXNhbmRzJTIwb2YlMjBwcmV0cmFpbmVkJTIwbW9kZWxzJTIwdG8lMjBwZXJmb3JtJTIwdGFza3MlMjBvbiUyMHRleHRzJTIwc3VjaCUyMGFzJTIwY2xhc3NpZmljYXRpb24lMkMlMjBpbmZvcm1hdGlvbiUyMGV4dHJhY3Rpb24lMkMlMEFxdWVzdGlvbiUyMGFuc3dlcmluZyUyQyUyMHN1bW1hcml6YXRpb24lMkMlMjB0cmFuc2xhdGlvbiUyQyUyMHRleHQlMjBnZW5lcmF0aW9uJTIwYW5kJTIwbW9yZSUyMGluJTIwb3ZlciUyMDEwMCUyMGxhbmd1YWdlcy4lMEFJdHMlMjBhaW0lMjBpcyUyMHRvJTIwbWFrZSUyMGN1dHRpbmctZWRnZSUyME5MUCUyMGVhc2llciUyMHRvJTIwdXNlJTIwZm9yJTIwZXZlcnlvbmUuJTBBJTBBJTVCVU5LJTVEJTIwVHJhbnNmb3JtZXJzJTIwcHJvdmlkZXMlMjBBUElzJTIwdG8lMjBxdWlja2x5JTIwZG93bmxvYWQlMjBhbmQlMjB1c2UlMjB0aG9zZSUyMHByZXRyYWluZWQlMjBtb2RlbHMlMjBvbiUyMGElMjBnaXZlb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BJTBBJTIwJTIwLSUyMFdlJTIwcHJvdmlkZSUyMGV4YW1wbGVzJTIwZm9yJTIwZWFjaCUyMGFyY2hpdGVjdHVyZSUyMHRvJTIwcmVwcm9kdWNlJTIwdGhlJTIwcmVzdWx0cyUyMHB1Ymxpc2hlZCUyMGJ5JTIwaXRzJTIwb3JpZ2luYWwlMjBhdXRob3JzLiUwQSUyMCUyMC0lMjBNb2RlbCUyMGludGVybmFsJTIwJTVCU0VQJTVEJTBBJTIyJTIyJTIy",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 w({props:{code:"c2VudGVuY2UlMjAlM0QlMjAlMjJUaGlzJTIwc2VudGVuY2UlMjBpcyUyMG5vdCUyMHRvbyUyMGxvbmclMjBidXQlMjB3ZSUyMGFyZSUyMGdvaW5nJTIwdG8lMjBzcGxpdCUyMGl0JTIwYW55d2F5LiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjBzZW50ZW5jZSUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTJDJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMjBtYXhfbGVuZ3RoJTNENiUyQyUyMHN0cmlkZSUzRDIlMEEpJTBBJTBBZm9yJTIwaWRzJTIwaW4lMjBpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlM0ElMEElMjAlMjAlMjAlMjBwcmludCh0b2tlbml6ZXIuZGVjb2RlKGlkcykp",highlighted:`sentence = <span class="hljs-string">&quot;This sentence is not too long but we are going to split it anyway.&quot;</span>
inputs = tokenizer(
    sentence, truncation=<span class="hljs-literal">True</span>, return_overflowing_tokens=<span class="hljs-literal">True</span>, max_length=<span class="hljs-number">6</span>, stride=<span class="hljs-number">2</span>
)

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

<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;overflow_to_sample_mapping&quot;</span>])`,wrap:!1}}),cn=new w({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElNUQ=",highlighted:'[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]',wrap:!1}}),on=new w({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMHF1ZXN0aW9uJTJDJTBBJTIwJTIwJTIwJTIwbG9uZ19jb250ZXh0JTJDJTBBJTIwJTIwJTIwJTIwc3RyaWRlJTNEMTI4JTJDJTBBJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDM4NCUyQyUwQSUyMCUyMCUyMCUyMHBhZGRpbmclM0QlMjJsb25nZXN0JTIyJTJDJTBBJTIwJTIwJTIwJTIwdHJ1bmNhdGlvbiUzRCUyMm9ubHlfc2Vjb25kJTIyJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX292ZXJmbG93aW5nX3Rva2VucyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`inputs = tokenizer(
    question,
    long_context,
    stride=<span class="hljs-number">128</span>,
    max_length=<span class="hljs-number">384</span>,
    padding=<span class="hljs-string">&quot;longest&quot;</span>,
    truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
    return_overflowing_tokens=<span class="hljs-literal">True</span>,
    return_offsets_mapping=<span class="hljs-literal">True</span>,
)`,wrap:!1}});const na=[Sa,Ya],Zn=[];function la(t,e){return t[0]==="pt"?0:1}H=la(y),F=Zn[H]=na[H](y),Mn=new w({props:{code:"b3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUwQXN0YXJ0X2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuc3RhcnRfbG9naXRzJTBBZW5kX2xvZ2l0cyUyMCUzRCUyMG91dHB1dHMuZW5kX2xvZ2l0cyUwQXByaW50KHN0YXJ0X2xvZ2l0cy5zaGFwZSUyQyUyMGVuZF9sb2dpdHMuc2hhcGUp",highlighted:`outputs = model(**inputs)

start_logits = outputs.start_logits
end_logits = outputs.end_logits
<span class="hljs-built_in">print</span>(start_logits.shape, end_logits.shape)`,wrap:!1}});const ea=[qa,Aa],xn=[];function sa(t,e){return t[0]==="pt"?0:1}Y=sa(y),S=xn[Y]=ea[Y](y);const aa=[Da,La],Gn=[];function ia(t,e){return t[0]==="pt"?0:1}A=ia(y),q=Gn[A]=aa[A](y);const ca=[Ka,Pa],Vn=[];function ra(t,e){return t[0]==="pt"?0:1}L=ra(y),D=Vn[L]=ca[L](y);const ma=[ti,Oa],Nn=[];function oa(t,e){return t[0]==="pt"?0:1}return P=oa(y),K=Nn[P]=ma[P](y),dn=new w({props:{code:"JTVCKDAlMkMlMjAxOCUyQyUyMDAuMzM4NjcpJTJDJTIwKDE3MyUyQyUyMDE4NCUyQyUyMDAuOTcxNDkpJTVE",highlighted:'[(<span class="hljs-number">0</span>, <span class="hljs-number">18</span>, <span class="hljs-number">0.33867</span>), (<span class="hljs-number">173</span>, <span class="hljs-number">184</span>, <span class="hljs-number">0.97149</span>)]',wrap:!1}}),st=new Ce({props:{$$slots:{default:[ni]},$$scope:{ctx:y}}}),wn=new w({props:{code:"Zm9yJTIwY2FuZGlkYXRlJTJDJTIwb2Zmc2V0JTIwaW4lMjB6aXAoY2FuZGlkYXRlcyUyQyUyMG9mZnNldHMpJTNBJTBBJTIwJTIwJTIwJTIwc3RhcnRfdG9rZW4lMkMlMjBlbmRfdG9rZW4lMkMlMjBzY29yZSUyMCUzRCUyMGNhbmRpZGF0ZSUwQSUyMCUyMCUyMCUyMHN0YXJ0X2NoYXIlMkMlMjBfJTIwJTNEJTIwb2Zmc2V0JTVCc3RhcnRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBfJTJDJTIwZW5kX2NoYXIlMjAlM0QlMjBvZmZzZXQlNUJlbmRfdG9rZW4lNUQlMEElMjAlMjAlMjAlMjBhbnN3ZXIlMjAlM0QlMjBsb25nX2NvbnRleHQlNUJzdGFydF9jaGFyJTNBZW5kX2NoYXIlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjAlN0IlMjJhbnN3ZXIlMjIlM0ElMjBhbnN3ZXIlMkMlMjAlMjJzdGFydCUyMiUzQSUyMHN0YXJ0X2NoYXIlMkMlMjAlMjJlbmQlMjIlM0ElMjBlbmRfY2hhciUyQyUyMCUyMnNjb3JlJTIyJTNBJTIwc2NvcmUlN0QlMEElMjAlMjAlMjAlMjBwcmludChyZXN1bHQp",highlighted:`<span class="hljs-keyword">for</span> candidate, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(candidates, offsets):
    start_token, end_token, score = candidate
    start_char, _ = offset[start_token]
    _, end_char = offset[end_token]
    answer = long_context[start_char:end_char]
    result = {<span class="hljs-string">&quot;answer&quot;</span>: answer, <span class="hljs-string">&quot;start&quot;</span>: start_char, <span class="hljs-string">&quot;end&quot;</span>: end_char, <span class="hljs-string">&quot;score&quot;</span>: score}
    <span class="hljs-built_in">print</span>(result)`,wrap:!1}}),Un=new w({props:{code:"JTdCJ2Fuc3dlciclM0ElMjAnJTVDbiVGMCU5RiVBNCU5NyUyMFRyYW5zZm9ybWVycyUzQSUyMFN0YXRlJTIwb2YlMjB0aGUlMjBBcnQlMjBOTFAnJTJDJTIwJ3N0YXJ0JyUzQSUyMDAlMkMlMjAnZW5kJyUzQSUyMDM3JTJDJTIwJ3Njb3JlJyUzQSUyMDAuMzM4NjclN0QlMEElN0InYW5zd2VyJyUzQSUyMCdKYXglMkMlMjBQeVRvcmNoJTIwYW5kJTIwVGVuc29yRmxvdyclMkMlMjAnc3RhcnQnJTNBJTIwMTg5MiUyQyUyMCdlbmQnJTNBJTIwMTkxOSUyQyUyMCdzY29yZSclM0ElMjAwLjk3MTQ5JTdE",highlighted:`{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;\\n🤗 Transformers: State of the Art NLP&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">37</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.33867</span>}
{<span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Jax, PyTorch and TensorFlow&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">1892</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">1919</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97149</span>}`,wrap:!1}}),at=new Ce({props:{$$slots:{default:[li]},$$scope:{ctx:y}}}),jn=new va({props:{source:"https://github.com/huggingface/course/blob/main/chapters/vi/chapter6/3b.mdx"}}),{c(){l=b("meta"),i=c(),n=b("p"),p=c(),h(d.$$.fragment),f=c(),h(g.$$.fragment),nl=c(),h(rt.$$.fragment),ll=c(),C.c(),Rn=c(),mt=b("p"),mt.innerHTML=Ke,el=c(),Z.c(),Wn=c(),h(ot.$$.fragment),sl=c(),pt=b("p"),pt.innerHTML=Oe,al=c(),h(ht.$$.fragment),il=c(),h(Mt.$$.fragment),cl=c(),Jt=b("p"),Jt.textContent=ts,rl=c(),h(ut.$$.fragment),ml=c(),h(yt.$$.fragment),ol=c(),dt=b("p"),dt.textContent=ns,pl=c(),h(bt.$$.fragment),hl=c(),Tt=b("p"),Tt.innerHTML=ls,Ml=c(),G.c(),Xn=c(),wt=b("p"),wt.textContent=es,Jl=c(),nt=b("div"),nt.innerHTML=ss,ul=c(),Ut=b("p"),Ut.textContent=as,yl=c(),h(ft.$$.fragment),dl=c(),N.c(),zn=c(),gt=b("p"),gt.innerHTML=is,bl=c(),jt=b("p"),jt.innerHTML=cs,Tl=c(),W.c(),Qn=c(),kt=b("p"),kt.textContent=rs,wl=c(),z.c(),En=c(),It=b("p"),It.innerHTML=ms,Ul=c(),j=b("p"),xe=it("Giả sử các sự kiện “Câu trả lời bắt đầu ở "),Hn=b("code"),Hn.textContent=os,Ge=it("” và “Câu trả lời kết thúc ở "),Fn=b("code"),Fn.textContent=ps,Ve=it("” là độc lập, xác suất để câu trả lời bắt đầu tại "),Yn=b("code"),Yn.textContent=hs,Ne=it(" và kết thúc tại "),Sn=b("code"),Sn.textContent=Ms,Re=it(` là:
`),fl=new ua(!1),gl=c(),O=b("p"),We=it("Vì vậy, để tính tất cả các điểm, chúng ta chỉ cần tính tích"),jl=new ua(!1),kl=it(" với "),An=b("code"),An.textContent=Js,Xe=it("."),Il=c(),vt=b("p"),vt.textContent=us,vl=c(),h(_t.$$.fragment),_l=c(),E.c(),qn=c(),Bt=b("p"),Bt.innerHTML=ys,Bl=c(),h(Ct.$$.fragment),Cl=c(),$t=b("p"),$t.textContent=ds,$l=c(),h(Zt.$$.fragment),Zl=c(),h(lt.$$.fragment),xl=c(),xt=b("p"),xt.innerHTML=bs,Gl=c(),h(Gt.$$.fragment),Vl=c(),Vt=b("p"),Vt.textContent=Ts,Nl=c(),h(Nt.$$.fragment),Rl=c(),h(Rt.$$.fragment),Wl=c(),Wt=b("p"),Wt.textContent=ws,Xl=c(),h(et.$$.fragment),zl=c(),h(Xt.$$.fragment),Ql=c(),zt=b("p"),zt.innerHTML=Us,El=c(),h(Qt.$$.fragment),Hl=c(),h(Et.$$.fragment),Fl=c(),Ht=b("p"),Ht.innerHTML=fs,Yl=c(),h(Ft.$$.fragment),Sl=c(),h(Yt.$$.fragment),Al=c(),St=b("p"),St.textContent=gs,ql=c(),At=b("p"),At.innerHTML=js,Ll=c(),h(qt.$$.fragment),Dl=c(),h(Lt.$$.fragment),Pl=c(),Dt=b("p"),Dt.innerHTML=ks,Kl=c(),Pt=b("p"),Pt.textContent=Is,Ol=c(),h(Kt.$$.fragment),te=c(),h(Ot.$$.fragment),ne=c(),tn=b("p"),tn.innerHTML=vs,le=c(),h(nn.$$.fragment),ee=c(),h(ln.$$.fragment),se=c(),en=b("p"),en.textContent=_s,ae=c(),h(sn.$$.fragment),ie=c(),an=b("p"),an.textContent=Bs,ce=c(),h(cn.$$.fragment),re=c(),rn=b("p"),rn.textContent=Cs,me=c(),mn=b("p"),mn.innerHTML=$s,oe=c(),h(on.$$.fragment),pe=c(),pn=b("p"),pn.innerHTML=Zs,he=c(),F.c(),Ln=c(),hn=b("p"),hn.textContent=xs,Me=c(),h(Mn.$$.fragment),Je=c(),S.c(),Dn=c(),Jn=b("p"),Jn.textContent=Gs,ue=c(),q.c(),Pn=c(),un=b("p"),un.textContent=Vs,ye=c(),D.c(),Kn=c(),yn=b("p"),yn.textContent=Ns,de=c(),K.c(),On=c(),h(dn.$$.fragment),be=c(),bn=b("p"),bn.textContent=Rs,Te=c(),h(st.$$.fragment),we=c(),Tn=b("p"),Tn.innerHTML=Ws,Ue=c(),h(wn.$$.fragment),fe=c(),h(Un.$$.fragment),ge=c(),fn=b("p"),fn.textContent=Xs,je=c(),h(at.$$.fragment),ke=c(),gn=b("p"),gn.textContent=zs,Ie=c(),h(jn.$$.fragment),ve=c(),tl=b("p"),this.h()},l(t){const e=ka("svelte-u9bgzb",document.head);l=T(e,"META",{name:!0,content:!0}),e.forEach(s),i=r(t),n=T(t,"P",{}),Be(n).forEach(s),p=r(t),M(d.$$.fragment,t),f=r(t),M(g.$$.fragment,t),nl=r(t),M(rt.$$.fragment,t),ll=r(t),C.l(t),Rn=r(t),mt=T(t,"P",{"data-svelte-h":!0}),U(mt)!=="svelte-yxy9gx"&&(mt.innerHTML=Ke),el=r(t),Z.l(t),Wn=r(t),M(ot.$$.fragment,t),sl=r(t),pt=T(t,"P",{"data-svelte-h":!0}),U(pt)!=="svelte-vnjte0"&&(pt.innerHTML=Oe),al=r(t),M(ht.$$.fragment,t),il=r(t),M(Mt.$$.fragment,t),cl=r(t),Jt=T(t,"P",{"data-svelte-h":!0}),U(Jt)!=="svelte-s9ftvh"&&(Jt.textContent=ts),rl=r(t),M(ut.$$.fragment,t),ml=r(t),M(yt.$$.fragment,t),ol=r(t),dt=T(t,"P",{"data-svelte-h":!0}),U(dt)!=="svelte-1lyz06"&&(dt.textContent=ns),pl=r(t),M(bt.$$.fragment,t),hl=r(t),Tt=T(t,"P",{"data-svelte-h":!0}),U(Tt)!=="svelte-14f47ia"&&(Tt.innerHTML=ls),Ml=r(t),G.l(t),Xn=r(t),wt=T(t,"P",{"data-svelte-h":!0}),U(wt)!=="svelte-1b7s8e9"&&(wt.textContent=es),Jl=r(t),nt=T(t,"DIV",{class:!0,"data-svelte-h":!0}),U(nt)!=="svelte-47wedv"&&(nt.innerHTML=ss),ul=r(t),Ut=T(t,"P",{"data-svelte-h":!0}),U(Ut)!=="svelte-1f3nki3"&&(Ut.textContent=as),yl=r(t),M(ft.$$.fragment,t),dl=r(t),N.l(t),zn=r(t),gt=T(t,"P",{"data-svelte-h":!0}),U(gt)!=="svelte-23keky"&&(gt.innerHTML=is),bl=r(t),jt=T(t,"P",{"data-svelte-h":!0}),U(jt)!=="svelte-xi76ei"&&(jt.innerHTML=cs),Tl=r(t),W.l(t),Qn=r(t),kt=T(t,"P",{"data-svelte-h":!0}),U(kt)!=="svelte-26cll"&&(kt.textContent=rs),wl=r(t),z.l(t),En=r(t),It=T(t,"P",{"data-svelte-h":!0}),U(It)!=="svelte-11o0luf"&&(It.innerHTML=ms),Ul=r(t),j=T(t,"P",{});var k=Be(j);xe=ct(k,"Giả sử các sự kiện “Câu trả lời bắt đầu ở "),Hn=T(k,"CODE",{"data-svelte-h":!0}),U(Hn)!=="svelte-8eqb3b"&&(Hn.textContent=os),Ge=ct(k,"” và “Câu trả lời kết thúc ở "),Fn=T(k,"CODE",{"data-svelte-h":!0}),U(Fn)!=="svelte-9cistc"&&(Fn.textContent=ps),Ve=ct(k,"” là độc lập, xác suất để câu trả lời bắt đầu tại "),Yn=T(k,"CODE",{"data-svelte-h":!0}),U(Yn)!=="svelte-8eqb3b"&&(Yn.textContent=hs),Ne=ct(k," và kết thúc tại "),Sn=T(k,"CODE",{"data-svelte-h":!0}),U(Sn)!=="svelte-9cistc"&&(Sn.textContent=Ms),Re=ct(k,` là:
`),fl=ya(k,!1),k.forEach(s),gl=r(t),O=T(t,"P",{});var tt=Be(O);We=ct(tt,"Vì vậy, để tính tất cả các điểm, chúng ta chỉ cần tính tích"),jl=ya(tt,!1),kl=ct(tt," với "),An=T(tt,"CODE",{"data-svelte-h":!0}),U(An)!=="svelte-1kp3szf"&&(An.textContent=Js),Xe=ct(tt,"."),tt.forEach(s),Il=r(t),vt=T(t,"P",{"data-svelte-h":!0}),U(vt)!=="svelte-1xmjzd"&&(vt.textContent=us),vl=r(t),M(_t.$$.fragment,t),_l=r(t),E.l(t),qn=r(t),Bt=T(t,"P",{"data-svelte-h":!0}),U(Bt)!=="svelte-2b9cpo"&&(Bt.innerHTML=ys),Bl=r(t),M(Ct.$$.fragment,t),Cl=r(t),$t=T(t,"P",{"data-svelte-h":!0}),U($t)!=="svelte-flep9b"&&($t.textContent=ds),$l=r(t),M(Zt.$$.fragment,t),Zl=r(t),M(lt.$$.fragment,t),xl=r(t),xt=T(t,"P",{"data-svelte-h":!0}),U(xt)!=="svelte-bd0wb9"&&(xt.innerHTML=bs),Gl=r(t),M(Gt.$$.fragment,t),Vl=r(t),Vt=T(t,"P",{"data-svelte-h":!0}),U(Vt)!=="svelte-13pxc0p"&&(Vt.textContent=Ts),Nl=r(t),M(Nt.$$.fragment,t),Rl=r(t),M(Rt.$$.fragment,t),Wl=r(t),Wt=T(t,"P",{"data-svelte-h":!0}),U(Wt)!=="svelte-1plqxrv"&&(Wt.textContent=ws),Xl=r(t),M(et.$$.fragment,t),zl=r(t),M(Xt.$$.fragment,t),Ql=r(t),zt=T(t,"P",{"data-svelte-h":!0}),U(zt)!=="svelte-9nxsrn"&&(zt.innerHTML=Us),El=r(t),M(Qt.$$.fragment,t),Hl=r(t),M(Et.$$.fragment,t),Fl=r(t),Ht=T(t,"P",{"data-svelte-h":!0}),U(Ht)!=="svelte-6gx3ai"&&(Ht.innerHTML=fs),Yl=r(t),M(Ft.$$.fragment,t),Sl=r(t),M(Yt.$$.fragment,t),Al=r(t),St=T(t,"P",{"data-svelte-h":!0}),U(St)!=="svelte-5fxjef"&&(St.textContent=gs),ql=r(t),At=T(t,"P",{"data-svelte-h":!0}),U(At)!=="svelte-1uf262q"&&(At.innerHTML=js),Ll=r(t),M(qt.$$.fragment,t),Dl=r(t),M(Lt.$$.fragment,t),Pl=r(t),Dt=T(t,"P",{"data-svelte-h":!0}),U(Dt)!=="svelte-18x7z5d"&&(Dt.innerHTML=ks),Kl=r(t),Pt=T(t,"P",{"data-svelte-h":!0}),U(Pt)!=="svelte-1opqzxx"&&(Pt.textContent=Is),Ol=r(t),M(Kt.$$.fragment,t),te=r(t),M(Ot.$$.fragment,t),ne=r(t),tn=T(t,"P",{"data-svelte-h":!0}),U(tn)!=="svelte-uya1e8"&&(tn.innerHTML=vs),le=r(t),M(nn.$$.fragment,t),ee=r(t),M(ln.$$.fragment,t),se=r(t),en=T(t,"P",{"data-svelte-h":!0}),U(en)!=="svelte-m3vijj"&&(en.textContent=_s),ae=r(t),M(sn.$$.fragment,t),ie=r(t),an=T(t,"P",{"data-svelte-h":!0}),U(an)!=="svelte-1lpkcws"&&(an.textContent=Bs),ce=r(t),M(cn.$$.fragment,t),re=r(t),rn=T(t,"P",{"data-svelte-h":!0}),U(rn)!=="svelte-1gz6xtn"&&(rn.textContent=Cs),me=r(t),mn=T(t,"P",{"data-svelte-h":!0}),U(mn)!=="svelte-55erzg"&&(mn.innerHTML=$s),oe=r(t),M(on.$$.fragment,t),pe=r(t),pn=T(t,"P",{"data-svelte-h":!0}),U(pn)!=="svelte-1ep0q9j"&&(pn.innerHTML=Zs),he=r(t),F.l(t),Ln=r(t),hn=T(t,"P",{"data-svelte-h":!0}),U(hn)!=="svelte-hfdr9q"&&(hn.textContent=xs),Me=r(t),M(Mn.$$.fragment,t),Je=r(t),S.l(t),Dn=r(t),Jn=T(t,"P",{"data-svelte-h":!0}),U(Jn)!=="svelte-1tvxzle"&&(Jn.textContent=Gs),ue=r(t),q.l(t),Pn=r(t),un=T(t,"P",{"data-svelte-h":!0}),U(un)!=="svelte-glqw3l"&&(un.textContent=Vs),ye=r(t),D.l(t),Kn=r(t),yn=T(t,"P",{"data-svelte-h":!0}),U(yn)!=="svelte-10lv4ty"&&(yn.textContent=Ns),de=r(t),K.l(t),On=r(t),M(dn.$$.fragment,t),be=r(t),bn=T(t,"P",{"data-svelte-h":!0}),U(bn)!=="svelte-t47wam"&&(bn.textContent=Rs),Te=r(t),M(st.$$.fragment,t),we=r(t),Tn=T(t,"P",{"data-svelte-h":!0}),U(Tn)!=="svelte-57me3a"&&(Tn.innerHTML=Ws),Ue=r(t),M(wn.$$.fragment,t),fe=r(t),M(Un.$$.fragment,t),ge=r(t),fn=T(t,"P",{"data-svelte-h":!0}),U(fn)!=="svelte-1xx830h"&&(fn.textContent=Xs),je=r(t),M(at.$$.fragment,t),ke=r(t),gn=T(t,"P",{"data-svelte-h":!0}),U(gn)!=="svelte-5dm25f"&&(gn.textContent=zs),Ie=r(t),M(jn.$$.fragment,t),ve=r(t),tl=T(t,"P",{}),Be(tl).forEach(s),this.h()},h(){Pe(l,"name","hf:doc:metadata"),Pe(l,"content",si),Pe(nt,"class","flex justify-center"),fl.a=null,jl.a=kl},m(t,e){I(document.head,l),a(t,i,e),a(t,n,e),a(t,p,e),J(d,t,e),a(t,f,e),J(g,t,e),a(t,nl,e),J(rt,t,e),a(t,ll,e),kn[B].m(t,e),a(t,Rn,e),a(t,mt,e),a(t,el,e),In[$].m(t,e),a(t,Wn,e),J(ot,t,e),a(t,sl,e),a(t,pt,e),a(t,al,e),J(ht,t,e),a(t,il,e),J(Mt,t,e),a(t,cl,e),a(t,Jt,e),a(t,rl,e),J(ut,t,e),a(t,ml,e),J(yt,t,e),a(t,ol,e),a(t,dt,e),a(t,pl,e),J(bt,t,e),a(t,hl,e),a(t,Tt,e),a(t,Ml,e),vn[x].m(t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,e),a(t,ie,e),a(t,an,e),a(t,ce,e),J(cn,t,e),a(t,re,e),a(t,rn,e),a(t,me,e),a(t,mn,e),a(t,oe,e),J(on,t,e),a(t,pe,e),a(t,pn,e),a(t,he,e),Zn[H].m(t,e),a(t,Ln,e),a(t,hn,e),a(t,Me,e),J(Mn,t,e),a(t,Je,e),xn[Y].m(t,e),a(t,Dn,e),a(t,Jn,e),a(t,ue,e),Gn[A].m(t,e),a(t,Pn,e),a(t,un,e),a(t,ye,e),Vn[L].m(t,e),a(t,Kn,e),a(t,yn,e),a(t,de,e),Nn[P].m(t,e),a(t,On,e),J(dn,t,e),a(t,be,e),a(t,bn,e),a(t,Te,e),J(st,t,e),a(t,we,e),a(t,Tn,e),a(t,Ue,e),J(wn,t,e),a(t,fe,e),J(Un,t,e),a(t,ge,e),a(t,fn,e),a(t,je,e),J(at,t,e),a(t,ke,e),a(t,gn,e),a(t,Ie,e),J(jn,t,e),a(t,ve,e),a(t,tl,e),_e=!0},p(t,[e]){const k={};e&1&&(k.fw=t[0]),d.$set(k);let tt=B;B=Es(t),B!==tt&&(_(),m(kn[tt],1,1,()=>{kn[tt]=null}),v(),C=kn[B],C||(C=kn[B]=Qs[B](t),C.c()),o(C,1),C.m(Rn.parentNode,Rn));let ze=$;$=Fs(t),$!==ze&&(_(),m(In[ze],1,1,()=>{In[ze]=null}),v(),Z=In[$],Z||(Z=In[$]=Hs[$](t),Z.c()),o(Z,1),Z.m(Wn.parentNode,Wn));let Qe=x;x=Ss(t),x!==Qe&&(_(),m(vn[Qe],1,1,()=>{vn[Qe]=null}),v(),G=vn[x],G||(G=vn[x]=Ys[x](t),G.c()),o(G,1),G.m(Xn.parentNode,Xn));let Ee=V;V=qs(t),V!==Ee&&(_(),m(_n[Ee],1,1,()=>{_n[Ee]=null}),v(),N=_n[V],N||(N=_n[V]=As[V](t),N.c()),o(N,1),N.m(zn.parentNode,zn));let He=R;R=Ds(t),R!==He&&(_(),m(Bn[He],1,1,()=>{Bn[He]=null}),v(),W=Bn[R],W||(W=Bn[R]=Ls[R](t),W.c()),o(W,1),W.m(Qn.parentNode,Qn));let Fe=X;X=Ks(t),X!==Fe&&(_(),m(Cn[Fe],1,1,()=>{Cn[Fe]=null}),v(),z=Cn[X],z||(z=Cn[X]=Ps[X](t),z.c()),o(z,1),z.m(En.parentNode,En));let Ye=Q;Q=ta(t),Q!==Ye&&(_(),m($n[Ye],1,1,()=>{$n[Ye]=null}),v(),E=$n[Q],E||(E=$n[Q]=Os[Q](t),E.c()),o(E,1),E.m(qn.parentNode,qn));const pa={};e&2&&(pa.$$scope={dirty:e,ctx:t}),lt.$set(pa);const ha={};e&2&&(ha.$$scope={dirty:e,ctx:t}),et.$set(ha);let Se=H;H=la(t),H!==Se&&(_(),m(Zn[Se],1,1,()=>{Zn[Se]=null}),v(),F=Zn[H],F||(F=Zn[H]=na[H](t),F.c()),o(F,1),F.m(Ln.parentNode,Ln));let Ae=Y;Y=sa(t),Y!==Ae&&(_(),m(xn[Ae],1,1,()=>{xn[Ae]=null}),v(),S=xn[Y],S||(S=xn[Y]=ea[Y](t),S.c()),o(S,1),S.m(Dn.parentNode,Dn));let qe=A;A=ia(t),A!==qe&&(_(),m(Gn[qe],1,1,()=>{Gn[qe]=null}),v(),q=Gn[A],q||(q=Gn[A]=aa[A](t),q.c()),o(q,1),q.m(Pn.parentNode,Pn));let Le=L;L=ra(t),L!==Le&&(_(),m(Vn[Le],1,1,()=>{Vn[Le]=null}),v(),D=Vn[L],D||(D=Vn[L]=ca[L](t),D.c()),o(D,1),D.m(Kn.parentNode,Kn));let De=P;P=oa(t),P!==De&&(_(),m(Nn[De],1,1,()=>{Nn[De]=null}),v(),K=Nn[P],K||(K=Nn[P]=ma[P](t),K.c()),o(K,1),K.m(On.parentNode,On));const Ma={};e&2&&(Ma.$$scope={dirty:e,ctx:t}),st.$set(Ma);const Ja={};e&2&&(Ja.$$scope={dirty:e,ctx:t}),at.$set(Ja)},i(t){_e||(o(d.$$.fragment,t),o(g.$$.fragment,t),o(rt.$$.fragment,t),o(C),o(Z),o(ot.$$.fragment,t),o(ht.$$.fragment,t),o(Mt.$$.fragment,t),o(ut.$$.fragment,t),o(yt.$$.fragment,t),o(bt.$$.fragment,t),o(G),o(ft.$$.fragment,t),o(N),o(W),o(z),o(_t.$$.fragment,t),o(E),o(Ct.$$.fragment,t),o(Zt.$$.fragment,t),o(lt.$$.fragment,t),o(Gt.$$.fragment,t),o(Nt.$$.fragment,t),o(Rt.$$.fragment,t),o(et.$$.fragment,t),o(Xt.$$.fragment,t),o(Qt.$$.fragment,t),o(Et.$$.fragment,t),o(Ft.$$.fragment,t),o(Yt.$$.fragment,t),o(qt.$$.fragment,t),o(Lt.$$.fragment,t),o(Kt.$$.fragment,t),o(Ot.$$.fragment,t),o(nn.$$.fragment,t),o(ln.$$.fragment,t),o(sn.$$.fragment,t),o(cn.$$.fragment,t),o(on.$$.fragment,t),o(F),o(Mn.$$.fragment,t),o(S),o(q),o(D),o(K),o(dn.$$.fragment,t),o(st.$$.fragment,t),o(wn.$$.fragment,t),o(Un.$$.fragment,t),o(at.$$.fragment,t),o(jn.$$.fragment,t),_e=!0)},o(t){m(d.$$.fragment,t),m(g.$$.fragment,t),m(rt.$$.fragment,t),m(C),m(Z),m(ot.$$.fragment,t),m(ht.$$.fragment,t),m(Mt.$$.fragment,t),m(ut.$$.fragment,t),m(yt.$$.fragment,t),m(bt.$$.fragment,t),m(G),m(ft.$$.fragment,t),m(N),m(W),m(z),m(_t.$$.fragment,t),m(E),m(Ct.$$.fragment,t),m(Zt.$$.fragment,t),m(lt.$$.fragment,t),m(Gt.$$.fragment,t),m(Nt.$$.fragment,t),m(Rt.$$.fragment,t),m(et.$$.fragment,t),m(Xt.$$.fragment,t),m(Qt.$$.fragment,t),m(Et.$$.fragment,t),m(Ft.$$.fragment,t),m(Yt.$$.fragment,t),m(qt.$$.fragment,t),m(Lt.$$.fragment,t),m(Kt.$$.fragment,t),m(Ot.$$.fragment,t),m(nn.$$.fragment,t),m(ln.$$.fragment,t),m(sn.$$.fragment,t),m(cn.$$.fragment,t),m(on.$$.fragment,t),m(F),m(Mn.$$.fragment,t),m(S),m(q),m(D),m(K),m(dn.$$.fragment,t),m(st.$$.fragment,t),m(wn.$$.fragment,t),m(Un.$$.fragment,t),m(at.$$.fragment,t),m(jn.$$.fragment,t),_e=!1},d(t){t&&(s(i),s(n),s(p),s(f),s(nl),s(ll),s(Rn),s(mt),s(el),s(Wn),s(sl),s(pt),s(al),s(il),s(cl),s(Jt),s(rl),s(ml),s(ol),s(dt),s(pl),s(hl),s(Tt),s(Ml),s(Xn),s(wt),s(Jl),s(nt),s(ul),s(Ut),s(yl),s(dl),s(zn),s(gt),s(bl),s(jt),s(Tl),s(Qn),s(kt),s(wl),s(En),s(It),s(Ul),s(j),s(gl),s(O),s(Il),s(vt),s(vl),s(_l),s(qn),s(Bt),s(Bl),s(Cl),s($t),s($l),s(Zl),s(xl),s(xt),s(Gl),s(Vl),s(Vt),s(Nl),s(Rl),s(Wl),s(Wt),s(Xl),s(zl),s(Ql),s(zt),s(El),s(Hl),s(Fl),s(Ht),s(Yl),s(Sl),s(Al),s(St),s(ql),s(At),s(Ll),s(Dl),s(Pl),s(Dt),s(Kl),s(Pt),s(Ol),s(te),s(ne),s(tn),s(le),s(ee),s(se),s(en),s(ae),s(ie),s(an),s(ce),s(re),s(rn),s(me),s(mn),s(oe),s(pe),s(pn),s(he),s(Ln),s(hn),s(Me),s(Je),s(Dn),s(Jn),s(ue),s(Pn),s(un),s(ye),s(Kn),s(yn),s(de),s(On),s(be),s(bn),s(Te),s(we),s(Tn),s(Ue),s(fe),s(ge),s(fn),s(je),s(ke),s(gn),s(Ie),s(ve),s(tl)),s(l),u(d,t),u(g,t),u(rt,t),kn[B].d(t),In[$].d(t),u(ot,t),u(ht,t),u(Mt,t),u(ut,t),u(yt,t),u(bt,t),vn[x].d(t),u(ft,t),_n[V].d(t),Bn[R].d(t),Cn[X].d(t),u(_t,t),$n[Q].d(t),u(Ct,t),u(Zt,t),u(lt,t),u(Gt,t),u(Nt,t),u(Rt,t),u(et,t),u(Xt,t),u(Qt,t),u(Et,t),u(Ft,t),u(Yt,t),u(qt,t),u(Lt,t),u(Kt,t),u(Ot,t),u(nn,t),u(ln,t),u(sn,t),u(cn,t),u(on,t),Zn[H].d(t),u(Mn,t),xn[Y].d(t),Gn[A].d(t),Vn[L].d(t),Nn[P].d(t),u(dn,t),u(st,t),u(wn,t),u(Un,t),u(at,t),u(jn,t)}}}const si='{"title":"Fast tokenizers in the QA pipeline","local":"fast-tokenizers-in-the-qa-pipeline","sections":[{"title":"Sử dụng pipeline question-answering","local":"sử-dụng-pipeline-question-answering","sections":[],"depth":2},{"title":"Sử dụng mô hình cho tác vụ hỏi đáp","local":"sử-dụng-mô-hình-cho-tác-vụ-hỏi-đáp","sections":[],"depth":2},{"title":"Xử lý các ngữ cảnh dài","local":"xử-lý-các-ngữ-cảnh-dài","sections":[],"depth":2}],"depth":1}';function ai(y,l,i){let n="pt";return fa(()=>{const p=new URLSearchParams(window.location.search);i(0,n=p.get("fw")||"pt")}),[n]}class Ji extends ga{constructor(l){super(),ja(this,l,ai,ei,Ua,{})}}export{Ji as component};
