import{s as Xs,o as Bs,n as Rs}from"../chunks/scheduler.cc52f4b9.js";import{S as Ds,i as xs,e as d,s as i,c as b,h as Fs,a as J,d as a,b as u,f as Ws,g as j,j as w,k as Es,l as Hs,m as M,n as f,o as c,u as X,t as m,p as y,v as B}from"../chunks/index.9480bb2b.js";import{T as zs}from"../chunks/Tip.f7b80743.js";import{C as Ss,H as Fl,E as Ys}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.52103c90.js";import{Y as Gs}from"../chunks/Youtube.7b12d9e8.js";import{C as T}from"../chunks/CodeBlock.c5404643.js";import{C as vs}from"../chunks/CourseFloatingBanner.78fb31df.js";import{F as Ls}from"../chunks/FrameworkSwitchCourse.42d12053.js";function qs(o){let s,p;return s=new vs({props:{chapter:2,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/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section5_tf.ipynb"}]}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function Ks(o){let s,p;return s=new vs({props:{chapter:2,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/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section5_pt.ipynb"}]}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function Ps(o){let s,p;return s=new Gs({props:{id:"ROxrFOEbsQE"}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function Os(o){let s,p;return s=new Gs({props:{id:"M6adb1j2jPI"}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function lt(o){let s,p,e,r;return s=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIudG9rZW5pemUoc2VxdWVuY2UpJTBBaWRzJTIwJTNEJTIwdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyh0b2tlbnMpJTBBaW5wdXRfaWRzJTIwJTNEJTIwdGYuY29uc3RhbnQoaWRzKSUwQSUyMyUyMFRoaXMlMjBsaW5lJTIwd2lsbCUyMGZhaWwuJTBBbW9kZWwoaW5wdXRfaWRzKQ==",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = tf.constant(ids)
<span class="hljs-comment"># This line will fail.</span>
model(input_ids)`,wrap:!1}}),e=new T({props:{code:"SW52YWxpZEFyZ3VtZW50RXJyb3IlM0ElMjBJbnB1dCUyMHRvJTIwcmVzaGFwZSUyMGlzJTIwYSUyMHRlbnNvciUyMHdpdGglMjAxNCUyMHZhbHVlcyUyQyUyMGJ1dCUyMHRoZSUyMHJlcXVlc3RlZCUyMHNoYXBlJTIwaGFzJTIwMTk2JTIwJTVCT3AlM0FSZXNoYXBlJTVE",highlighted:'InvalidArgumentError: Input to reshape <span class="hljs-keyword">is</span> a tensor <span class="hljs-keyword">with</span> <span class="hljs-number">14</span> values, but the requested shape has <span class="hljs-number">196</span> [Op:Reshape]',wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function et(o){let s,p,e,r;return s=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEFpbnB1dF9pZHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoaWRzKSUwQSUyMyUyMFRoaXMlMjBsaW5lJTIwd2lsbCUyMGZhaWwuJTBBbW9kZWwoaW5wdXRfaWRzKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = torch.tensor(ids)
<span class="hljs-comment"># This line will fail.</span>
model(input_ids)`,wrap:!1}}),e=new T({props:{code:"SW5kZXhFcnJvciUzQSUyMERpbWVuc2lvbiUyMG91dCUyMG9mJTIwcmFuZ2UlMjAoZXhwZWN0ZWQlMjB0byUyMGJlJTIwaW4lMjByYW5nZSUyMG9mJTIwJTVCLTElMkMlMjAwJTVEJTJDJTIwYnV0JTIwZ290JTIwMSk=",highlighted:'IndexError: Dimension out of <span class="hljs-built_in">range</span> (expected to be <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span> of [-<span class="hljs-number">1</span>, <span class="hljs-number">0</span>], but got <span class="hljs-number">1</span>)',wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function st(o){let s,p,e,r;return s=new T({props:{code:"dG9rZW5pemVkX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIpJTBBcHJpbnQodG9rZW5pemVkX2lucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:`tokenized_inputs = tokenizer(sequence, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-built_in">print</span>(tokenized_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`,wrap:!1}}),e=new T({props:{code:"dGYuVGVuc29yJTNBJTIwc2hhcGUlM0QoMSUyQyUyMDE2KSUyQyUyMGR0eXBlJTNEaW50MzIlMkMlMjBudW1weSUzRCUwQWFycmF5KCU1QiU1QiUyMCUyMDEwMSUyQyUyMCUyMDEwNDUlMkMlMjAlMjAxMDA1JTJDJTIwJTIwMjMxMCUyQyUyMCUyMDIwNDIlMkMlMjAlMjAzNDAzJTJDJTIwJTIwMjAwNSUyQyUyMCUyMDEwMzclMkMlMjAxNzY2MiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDEyMTcyJTJDJTIwJTIwMjYwNyUyQyUyMCUyMDIwMjYlMkMlMjAlMjAyODc4JTJDJTIwJTIwMjE2NiUyQyUyMCUyMDEwMTIlMkMlMjAlMjAlMjAxMDIlNUQlNUQlMkMlMjBkdHlwZSUzRGludDMyKSUzRQ==",highlighted:`tf.Tensor: shape=(<span class="hljs-number">1</span>, <span class="hljs-number">16</span>), dtype=int32, numpy=
array([[  <span class="hljs-number">101</span>,  <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>,
        <span class="hljs-number">12172</span>,  <span class="hljs-number">2607</span>,  <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>,   <span class="hljs-number">102</span>]], dtype=int32)&gt;`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function tt(o){let s,p,e,r;return s=new T({props:{code:"dG9rZW5pemVkX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBcHJpbnQodG9rZW5pemVkX2lucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:`tokenized_inputs = tokenizer(sequence, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(tokenized_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`,wrap:!1}}),e=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMCUyMDEwMSUyQyUyMCUyMDEwNDUlMkMlMjAlMjAxMDA1JTJDJTIwJTIwMjMxMCUyQyUyMCUyMDIwNDIlMkMlMjAlMjAzNDAzJTJDJTIwJTIwMjAwNSUyQyUyMCUyMDEwMzclMkMlMjAxNzY2MiUyQyUyMDEyMTcyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMjYwNyUyQyUyMCUyMDIwMjYlMkMlMjAlMjAyODc4JTJDJTIwJTIwMjE2NiUyQyUyMCUyMDEwMTIlMkMlMjAlMjAlMjAxMDIlNUQlNUQp",highlighted:`tensor([[  <span class="hljs-number">101</span>,  <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>, <span class="hljs-number">12172</span>,
          <span class="hljs-number">2607</span>,  <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>,   <span class="hljs-number">102</span>]])`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function nt(o){let s,p;return s=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIudG9rZW5pemUoc2VxdWVuY2UpJTBBaWRzJTIwJTNEJTIwdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyh0b2tlbnMpJTBBJTBBaW5wdXRfaWRzJTIwJTNEJTIwdGYuY29uc3RhbnQoJTVCaWRzJTVEKSUwQXByaW50KCUyMklucHV0JTIwSURzJTNBJTIyJTJDJTIwaW5wdXRfaWRzKSUwQSUwQW91dHB1dCUyMCUzRCUyMG1vZGVsKGlucHV0X2lkcyklMEFwcmludCglMjJMb2dpdHMlM0ElMjIlMkMlMjBvdXRwdXQubG9naXRzKQ==",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)

input_ids = tf.constant([ids])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Input IDs:&quot;</span>, input_ids)

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function at(o){let s,p;return s=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEElMEFpbnB1dF9pZHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCaWRzJTVEKSUwQXByaW50KCUyMklucHV0JTIwSURzJTNBJTIyJTJDJTIwaW5wdXRfaWRzKSUwQSUwQW91dHB1dCUyMCUzRCUyMG1vZGVsKGlucHV0X2lkcyklMEFwcmludCglMjJMb2dpdHMlM0ElMjIlMkMlMjBvdXRwdXQubG9naXRzKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)

input_ids = torch.tensor([ids])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Input IDs:&quot;</span>, input_ids)

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function pt(o){let s,p;return s=new T({props:{code:"SW5wdXQlMjBJRHMlM0ElMjB0Zi5UZW5zb3IoJTBBJTVCJTVCJTIwMTA0NSUyMCUyMDEwMDUlMjAlMjAyMzEwJTIwJTIwMjA0MiUyMCUyMDM0MDMlMjAlMjAyMDA1JTIwJTIwMTAzNyUyMDE3NjYyJTIwMTIxNzIlMjAlMjAyNjA3JTIwJTIwMjAyNiUyMCUyMDI4NzglMEElMjAlMjAlMjAyMTY2JTIwJTIwMTAxMiU1RCU1RCUyQyUyMHNoYXBlJTNEKDElMkMlMjAxNCklMkMlMjBkdHlwZSUzRGludDMyKSUwQUxvZ2l0cyUzQSUyMHRmLlRlbnNvciglNUIlNUItMi43Mjc2MjA4JTIwJTIwMi44Nzg5Mzc3JTVEJTVEJTJDJTIwc2hhcGUlM0QoMSUyQyUyMDIpJTJDJTIwZHR5cGUlM0RmbG9hdDMyKQ==",highlighted:`Input IDs: tf.Tensor(
[[ <span class="hljs-number">1045</span>  <span class="hljs-number">1005</span>  <span class="hljs-number">2310</span>  <span class="hljs-number">2042</span>  <span class="hljs-number">3403</span>  <span class="hljs-number">2005</span>  <span class="hljs-number">1037</span> <span class="hljs-number">17662</span> <span class="hljs-number">12172</span>  <span class="hljs-number">2607</span>  <span class="hljs-number">2026</span>  <span class="hljs-number">2878</span>
   <span class="hljs-number">2166</span>  <span class="hljs-number">1012</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">14</span>), dtype=int32)
Logits: tf.Tensor([[-<span class="hljs-number">2.7276208</span>  <span class="hljs-number">2.8789377</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function Mt(o){let s,p;return s=new T({props:{code:"SW5wdXQlMjBJRHMlM0ElMjAlNUIlNUIlMjAxMDQ1JTJDJTIwJTIwMTAwNSUyQyUyMCUyMDIzMTAlMkMlMjAlMjAyMDQyJTJDJTIwJTIwMzQwMyUyQyUyMCUyMDIwMDUlMkMlMjAlMjAxMDM3JTJDJTIwMTc2NjIlMkMlMjAxMjE3MiUyQyUyMCUyMDI2MDclMkMlMjAyMDI2JTJDJTIwJTIwMjg3OCUyQyUyMCUyMDIxNjYlMkMlMjAlMjAxMDEyJTVEJTVEJTBBTG9naXRzJTNBJTIwJTVCJTVCLTIuNzI3NiUyQyUyMCUyMDIuODc4OSU1RCU1RA==",highlighted:`Input IDs: [[ <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>, <span class="hljs-number">12172</span>,  <span class="hljs-number">2607</span>, <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>]]
Logits: [[-<span class="hljs-number">2.7276</span>,  <span class="hljs-number">2.8789</span>]]`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){f(s,e,r),p=!0},i(e){p||(m(s.$$.fragment,e),p=!0)},o(e){c(s.$$.fragment,e),p=!1},d(e){y(s,e)}}}function rt(o){let s,p="✏️ <strong>試試看！</strong> 將此列表轉換為張量並通過模型傳遞。檢查您是否獲得與之前相同的登錄（但是隻有兩次）";return{c(){s=d("p"),s.innerHTML=p},l(e){s=J(e,"P",{"data-svelte-h":!0}),w(s)!=="svelte-1waoogr"&&(s.innerHTML=p)},m(e,r){M(e,s,r)},p:Rs,d(e){e&&a(s)}}}function it(o){let s,p,e,r;return s=new T({props:{code:"bW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UxX2lkcyUyMCUzRCUyMCU1QiU1QjIwMCUyQyUyMDIwMCUyQyUyMDIwMCU1RCU1RCUwQXNlcXVlbmNlMl9pZHMlMjAlM0QlMjAlNUIlNUIyMDAlMkMlMjAyMDAlNUQlNUQlMEFiYXRjaGVkX2lkcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU1QjIwMCUyQyUyMDIwMCUyQyUyMDIwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCU1QjIwMCUyQyUyMDIwMCUyQyUyMHRva2VuaXplci5wYWRfdG9rZW5faWQlNUQlMkMlMEElNUQlMEElMEFwcmludChtb2RlbCh0Zi5jb25zdGFudChzZXF1ZW5jZTFfaWRzKSkubG9naXRzKSUwQXByaW50KG1vZGVsKHRmLmNvbnN0YW50KHNlcXVlbmNlMl9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodGYuY29uc3RhbnQoYmF0Y2hlZF9pZHMpKS5sb2dpdHMp",highlighted:`model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence1_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
sequence2_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

<span class="hljs-built_in">print</span>(model(tf.constant(sequence1_ids)).logits)
<span class="hljs-built_in">print</span>(model(tf.constant(sequence2_ids)).logits)
<span class="hljs-built_in">print</span>(model(tf.constant(batched_ids)).logits)`,wrap:!1}}),e=new T({props:{code:"dGYuVGVuc29yKCU1QiU1QiUyMDEuNTY5MzY3OCUyMC0xLjM4OTQ1ODElNUQlNUQlMkMlMjBzaGFwZSUzRCgxJTJDJTIwMiklMkMlMjBkdHlwZSUzRGZsb2F0MzIpJTBBdGYuVGVuc29yKCU1QiU1QiUyMDAuNTgwMzAwNSUyMCUyMC0wLjQxMjUyNDI4JTVEJTVEJTJDJTIwc2hhcGUlM0QoMSUyQyUyMDIpJTJDJTIwZHR5cGUlM0RmbG9hdDMyKSUwQXRmLlRlbnNvciglMEElNUIlNUIlMjAxLjU2OTM2ODElMjAtMS4zODk0NTgyJTVEJTBBJTIwJTVCJTIwMS4zMzczNDg2JTIwLTEuMjE2MzE5MyU1RCU1RCUyQyUyMHNoYXBlJTNEKDIlMkMlMjAyKSUyQyUyMGR0eXBlJTNEZmxvYXQzMik=",highlighted:`tf.Tensor([[ <span class="hljs-number">1.5693678</span> -<span class="hljs-number">1.3894581</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)
tf.Tensor([[ <span class="hljs-number">0.5803005</span>  -<span class="hljs-number">0.41252428</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)
tf.Tensor(
[[ <span class="hljs-number">1.5693681</span> -<span class="hljs-number">1.3894582</span>]
 [ <span class="hljs-number">1.3373486</span> -<span class="hljs-number">1.2163193</span>]], shape=(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function ut(o){let s,p,e,r;return s=new T({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQXNlcXVlbmNlMV9pZHMlMjAlM0QlMjAlNUIlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlNUQlMEFzZXF1ZW5jZTJfaWRzJTIwJTNEJTIwJTVCJTVCMjAwJTJDJTIwMjAwJTVEJTVEJTBBYmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKHNlcXVlbmNlMV9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKHNlcXVlbmNlMl9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKGJhdGNoZWRfaWRzKSkubG9naXRzKQ==",highlighted:`model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence1_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
sequence2_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

<span class="hljs-built_in">print</span>(model(torch.tensor(sequence1_ids)).logits)
<span class="hljs-built_in">print</span>(model(torch.tensor(sequence2_ids)).logits)
<span class="hljs-built_in">print</span>(model(torch.tensor(batched_ids)).logits)`,wrap:!1}}),e=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMDEuNTY5NCUyQyUyMC0xLjM4OTUlNUQlNUQlMkMlMjBncmFkX2ZuJTNEJTNDQWRkbW1CYWNrd2FyZCUzRSklMEF0ZW5zb3IoJTVCJTVCJTIwMC41ODAzJTJDJTIwLTAuNDEyNSU1RCU1RCUyQyUyMGdyYWRfZm4lM0QlM0NBZGRtbUJhY2t3YXJkJTNFKSUwQXRlbnNvciglNUIlNUIlMjAxLjU2OTQlMkMlMjAtMS4zODk1JTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCJTIwMS4zMzczJTJDJTIwLTEuMjE2MyU1RCU1RCUyQyUyMGdyYWRfZm4lM0QlM0NBZGRtbUJhY2t3YXJkJTNFKQ==",highlighted:`tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>]], grad_fn=&lt;AddmmBackward&gt;)
tensor([[ <span class="hljs-number">0.5803</span>, -<span class="hljs-number">0.4125</span>]], grad_fn=&lt;AddmmBackward&gt;)
tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>],
        [ <span class="hljs-number">1.3373</span>, -<span class="hljs-number">1.2163</span>]], grad_fn=&lt;AddmmBackward&gt;)`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function ct(o){let s,p,e,r;return s=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBYXR0ZW50aW9uX21hc2slMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDElNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDAlNUQlMkMlMEElNUQlMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwodGYuY29uc3RhbnQoYmF0Y2hlZF9pZHMpJTJDJTIwYXR0ZW50aW9uX21hc2slM0R0Zi5jb25zdGFudChhdHRlbnRpb25fbWFzaykpJTBBcHJpbnQob3V0cHV0cy5sb2dpdHMp",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

attention_mask = [
    [<span class="hljs-number">1</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>, <span class="hljs-number">0</span>],
]

outputs = model(tf.constant(batched_ids), attention_mask=tf.constant(attention_mask))
<span class="hljs-built_in">print</span>(outputs.logits)`,wrap:!1}}),e=new T({props:{code:"dGYuVGVuc29yKCUwQSU1QiU1QiUyMDEuNTY5MzY4MSUyMCUyMC0xLjM4OTQ1ODIlMjAlNUQlMEElMjAlNUIlMjAwLjU4MDMwMjElMjAlMjAtMC40MTI1MjU4NiU1RCU1RCUyQyUyMHNoYXBlJTNEKDIlMkMlMjAyKSUyQyUyMGR0eXBlJTNEZmxvYXQzMik=",highlighted:`tf.Tensor(
[[ <span class="hljs-number">1.5693681</span>  -<span class="hljs-number">1.3894582</span> ]
 [ <span class="hljs-number">0.5803021</span>  -<span class="hljs-number">0.41252586</span>]], shape=(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function mt(o){let s,p,e,r;return s=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBYXR0ZW50aW9uX21hc2slMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDElNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDAlNUQlMkMlMEElNUQlMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwodG9yY2gudGVuc29yKGJhdGNoZWRfaWRzKSUyQyUyMGF0dGVudGlvbl9tYXNrJTNEdG9yY2gudGVuc29yKGF0dGVudGlvbl9tYXNrKSklMEFwcmludChvdXRwdXRzLmxvZ2l0cyk=",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

attention_mask = [
    [<span class="hljs-number">1</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>, <span class="hljs-number">0</span>],
]

outputs = model(torch.tensor(batched_ids), attention_mask=torch.tensor(attention_mask))
<span class="hljs-built_in">print</span>(outputs.logits)`,wrap:!1}}),e=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMDEuNTY5NCUyQyUyMC0xLjM4OTUlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUIlMjAwLjU4MDMlMkMlMjAtMC40MTI1JTVEJTVEJTJDJTIwZ3JhZF9mbiUzRCUzQ0FkZG1tQmFja3dhcmQlM0Up",highlighted:`tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>],
        [ <span class="hljs-number">0.5803</span>, -<span class="hljs-number">0.4125</span>]], grad_fn=&lt;AddmmBackward&gt;)`,wrap:!1}}),{c(){b(s.$$.fragment),p=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),p=u(t),j(e.$$.fragment,t)},m(t,U){f(s,t,U),M(t,p,U),f(e,t,U),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&a(p),y(s,t),y(e,t)}}}function ot(o){let s,p="✏️ 試試看！在第2節中使用的兩個句子上手動應用標記化（“我一生都在等待Hugging Face課程。”和“我非常討厭這個！”）。通過模型傳遞它們，並檢查您是否獲得與第2節中相同的登錄。現在使用填充標記將它們批處理在一起，然後創建適當的注意掩碼。檢查通過模型時是否獲得相同的結果！";return{c(){s=d("p"),s.textContent=p},l(e){s=J(e,"P",{"data-svelte-h":!0}),w(s)!=="svelte-1tpl6z6"&&(s.textContent=p)},m(e,r){M(e,s,r)},p:Rs,d(e){e&&a(s)}}}function bt(o){let s,p,e,r,t,U,D,Hl,x,Sl,h,k,El,_,$,zl,F,Be="在上一節中，我們探討了最簡單的用例：對一個小長度的序列進行推理。然而，一些問題已經出現：",Yl,H,De="<li>我們如何處理多個序列？</li>",Ll,S,xe="<li>我們如何處理多個序列不同長度?</li>",ql,Y,Fe="<li>詞彙索引是讓模型正常工作的唯一輸入嗎？</li>",Kl,L,He="<li>是否存在序列太長的問題？</li>",Pl,q,Se="讓我們看看這些問題會帶來什麼樣的問題，以及如何使用🤗 Transformers API解決它們",Ol,K,le,P,Ye="在上一個練習中，您看到了序列如何轉換為數字列表。讓我們將此數字列表轉換為張量，並將其發送到模型：",ee,I,C,Rl,O,Le="哦不！為什麼失敗了？我們遵循了第2節中管道的步驟。",se,ll,qe="問題是我們向模型發送了一個序列，而 🤗Transformers 模型默認情況下需要多個句子。在這裡，當我們將分詞器應用於一個應用程序時，我們嘗試在幕後完成分詞器所做的一切，但如果仔細觀察，您會發現它不僅將輸入ID列表轉換為張量，還在其頂部添加了一個維度：",te,A,Z,Gl,el,Ke="讓我們重試並添加一個新維度：",ne,N,Q,vl,sl,Pe="我們打印輸入ID以及生成的logits-以下是輸出：",ae,g,V,Xl,tl,Oe="<em>Batching</em> 是一次通過模型發送多個句子的行為。如果你只有一句話，你可以用一個序列構建一個批次：",pe,nl,Me,al,ls="這是一批兩個相同的序列！",re,G,ie,pl,es="批處理允許模型在輸入多個句子時工作。使用多個序列就像使用單個序列構建批一樣簡單。不過，還有第二個問題。當你試圖將兩個（或更多）句子組合在一起時，它們的長度可能不同。如果您以前使用過張量，那麼您知道它們必須是矩形，因此無法將輸入ID列表直接轉換為張量。為了解決這個問題，我們通常填充輸入。",ue,Ml,ce,rl,ss="以下列表不能轉換為張量：",me,il,oe,ul,ts="為了解決這個問題，我們將使用填充使張量具有矩形。Padding通過在值較少的句子中添加一個名為Padding token的特殊單詞來確保我們所有的句子長度相同。例如，如果你有10個包含10個單詞的句子和1個包含20個單詞的句子，填充將確保所有句子都包含20個單詞。在我們的示例中，生成的張量如下所示：",be,cl,je,ml,ns="可以在tokenizer.pad_token_id中找到填充令牌ID. 讓我們使用它，將我們的兩句話分別發送到模型中，並分批發送到一起：",fe,W,E,Bl,ol,as="我們批處理預測中的logits有點問題：第二行應該與第二句的logits相同，但我們得到了完全不同的值！",ye,bl,ps="這是因為Transformer模型的關鍵特性是關注層，它將每個標記上下文化。這些將考慮填充標記，因為它們涉及序列中的所有標記。為了在通過模型傳遞不同長度的單個句子時，或者在傳遞一批應用了相同句子和填充的句子時獲得相同的結果，我們需要告訴這些注意層忽略填充標記。這是通過使用 attention mask來實現的。",Ue,jl,de,fl,Ms="<em>Attention masks</em> 是與輸入 ID 張量形狀完全相同的張量，用0和1填充：1s表示應注意相應的標記，0s表示不應注意相應的標記（即，模型的注意力層應忽略它們）。",Je,yl,rs="讓我們用 attention mask 完成上一個示例：",we,z,R,Dl,Ul,is="現在我們得到了該批中第二個句子的相同登錄。",Te,dl,us="請注意，第二個序列的最後一個值是一個填充ID，它在attention mask中是一個0值。",he,v,ke,Jl,_e,wl,cs="對於Transformers模型，我們可以通過模型的序列長度是有限的。大多數模型處理多達512或1024個令牌的序列，當要求處理更長的序列時，會崩潰。此問題有兩種解決方案：",$e,Tl,ms="<li>使用支持的序列長度較長的模型。</li>",Ie,hl,os="<li>截斷序列。</li>",Ce,kl,bs=`模型有不同的支持序列長度，有些模型專門處理很長的序列。
<a href="https://huggingface.co/transformers/model_doc/longformer.html" rel="nofollow">Longformer</a>
這是一個例子，另一個是
<a href="https://huggingface.co/transformers/model_doc/led.html" rel="nofollow">LED</a>
. 如果您正在處理一項需要很長序列的任務，我們建議您查看這些模型。`,Ae,_l,js="否則，我們建議您通過指定max_sequence_length參數：",Ze,$l,Ne,Il,Qe,xl,ge;t=new Ls({props:{fw:o[0]}}),D=new Ss({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),x=new Fl({props:{title:"處理多個序列",local:"處理多個序列",headingTag:"h1"}});const fs=[Ks,qs],Cl=[];function ys(l,n){return l[0]==="pt"?0:1}h=ys(o),k=Cl[h]=fs[h](o);const Us=[Os,Ps],Al=[];function ds(l,n){return l[0]==="pt"?0:1}_=ds(o),$=Al[_]=Us[_](o),K=new Fl({props:{title:"模型需要一批輸入",local:"模型需要一批輸入",headingTag:"h2"}});const Js=[et,lt],Zl=[];function ws(l,n){return l[0]==="pt"?0:1}I=ws(o),C=Zl[I]=Js[I](o);const Ts=[tt,st],Nl=[];function hs(l,n){return l[0]==="pt"?0:1}A=hs(o),Z=Nl[A]=Ts[A](o);const ks=[at,nt],Ql=[];function _s(l,n){return l[0]==="pt"?0:1}N=_s(o),Q=Ql[N]=ks[N](o);const $s=[Mt,pt],gl=[];function Is(l,n){return l[0]==="pt"?0:1}g=Is(o),V=gl[g]=$s[g](o),nl=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new zs({props:{$$slots:{default:[rt]},$$scope:{ctx:o}}}),Ml=new Fl({props:{title:"填充輸入",local:"填充輸入",headingTag:"h2"}}),il=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlNUQlMEElNUQ=",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]
]`,wrap:!1}}),cl=new T({props:{code:"cGFkZGluZ19pZCUyMCUzRCUyMDEwMCUwQSUwQWJhdGNoZWRfaWRzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTVCMjAwJTJDJTIwMjAwJTJDJTIwMjAwJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTVCMjAwJTJDJTIwMjAwJTJDJTIwcGFkZGluZ19pZCU1RCUyQyUwQSU1RA==",highlighted:`padding_id = <span class="hljs-number">100</span>

batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, padding_id],
]`,wrap:!1}});const Cs=[ut,it],Vl=[];function As(l,n){return l[0]==="pt"?0:1}W=As(o),E=Vl[W]=Cs[W](o),jl=new Fl({props:{title:"注意力遮罩（Attention masks）",local:"注意力遮罩attention-masks",headingTag:"h2"}});const Zs=[mt,ct],Wl=[];function Ns(l,n){return l[0]==="pt"?0:1}return z=Ns(o),R=Wl[z]=Zs[z](o),v=new zs({props:{$$slots:{default:[ot]},$$scope:{ctx:o}}}),Jl=new Fl({props:{title:"長序列",local:"長序列",headingTag:"h2"}}),$l=new T({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),Il=new Ys({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter2/5.mdx"}}),{c(){s=d("meta"),p=i(),e=d("p"),r=i(),b(t.$$.fragment),U=i(),b(D.$$.fragment),Hl=i(),b(x.$$.fragment),Sl=i(),k.c(),El=i(),$.c(),zl=i(),F=d("p"),F.textContent=Be,Yl=i(),H=d("ul"),H.innerHTML=De,Ll=i(),S=d("ul"),S.innerHTML=xe,ql=i(),Y=d("ul"),Y.innerHTML=Fe,Kl=i(),L=d("ul"),L.innerHTML=He,Pl=i(),q=d("p"),q.textContent=Se,Ol=i(),b(K.$$.fragment),le=i(),P=d("p"),P.textContent=Ye,ee=i(),C.c(),Rl=i(),O=d("p"),O.textContent=Le,se=i(),ll=d("p"),ll.textContent=qe,te=i(),Z.c(),Gl=i(),el=d("p"),el.textContent=Ke,ne=i(),Q.c(),vl=i(),sl=d("p"),sl.textContent=Pe,ae=i(),V.c(),Xl=i(),tl=d("p"),tl.innerHTML=Oe,pe=i(),b(nl.$$.fragment),Me=i(),al=d("p"),al.textContent=ls,re=i(),b(G.$$.fragment),ie=i(),pl=d("p"),pl.textContent=es,ue=i(),b(Ml.$$.fragment),ce=i(),rl=d("p"),rl.textContent=ss,me=i(),b(il.$$.fragment),oe=i(),ul=d("p"),ul.textContent=ts,be=i(),b(cl.$$.fragment),je=i(),ml=d("p"),ml.textContent=ns,fe=i(),E.c(),Bl=i(),ol=d("p"),ol.textContent=as,ye=i(),bl=d("p"),bl.textContent=ps,Ue=i(),b(jl.$$.fragment),de=i(),fl=d("p"),fl.innerHTML=Ms,Je=i(),yl=d("p"),yl.textContent=rs,we=i(),R.c(),Dl=i(),Ul=d("p"),Ul.textContent=is,Te=i(),dl=d("p"),dl.textContent=us,he=i(),b(v.$$.fragment),ke=i(),b(Jl.$$.fragment),_e=i(),wl=d("p"),wl.textContent=cs,$e=i(),Tl=d("ul"),Tl.innerHTML=ms,Ie=i(),hl=d("ul"),hl.innerHTML=os,Ce=i(),kl=d("p"),kl.innerHTML=bs,Ae=i(),_l=d("p"),_l.textContent=js,Ze=i(),b($l.$$.fragment),Ne=i(),b(Il.$$.fragment),Qe=i(),xl=d("p"),this.h()},l(l){const n=Fs("svelte-u9bgzb",document.head);s=J(n,"META",{name:!0,content:!0}),n.forEach(a),p=u(l),e=J(l,"P",{}),Ws(e).forEach(a),r=u(l),j(t.$$.fragment,l),U=u(l),j(D.$$.fragment,l),Hl=u(l),j(x.$$.fragment,l),Sl=u(l),k.l(l),El=u(l),$.l(l),zl=u(l),F=J(l,"P",{"data-svelte-h":!0}),w(F)!=="svelte-6dkml4"&&(F.textContent=Be),Yl=u(l),H=J(l,"UL",{"data-svelte-h":!0}),w(H)!=="svelte-9tzwkr"&&(H.innerHTML=De),Ll=u(l),S=J(l,"UL",{"data-svelte-h":!0}),w(S)!=="svelte-1w7fwlb"&&(S.innerHTML=xe),ql=u(l),Y=J(l,"UL",{"data-svelte-h":!0}),w(Y)!=="svelte-x0w2fa"&&(Y.innerHTML=Fe),Kl=u(l),L=J(l,"UL",{"data-svelte-h":!0}),w(L)!=="svelte-18odgmb"&&(L.innerHTML=He),Pl=u(l),q=J(l,"P",{"data-svelte-h":!0}),w(q)!=="svelte-1kwjoxo"&&(q.textContent=Se),Ol=u(l),j(K.$$.fragment,l),le=u(l),P=J(l,"P",{"data-svelte-h":!0}),w(P)!=="svelte-1fptg5k"&&(P.textContent=Ye),ee=u(l),C.l(l),Rl=u(l),O=J(l,"P",{"data-svelte-h":!0}),w(O)!=="svelte-1u75gf9"&&(O.textContent=Le),se=u(l),ll=J(l,"P",{"data-svelte-h":!0}),w(ll)!=="svelte-18zv6do"&&(ll.textContent=qe),te=u(l),Z.l(l),Gl=u(l),el=J(l,"P",{"data-svelte-h":!0}),w(el)!=="svelte-eu2vvx"&&(el.textContent=Ke),ne=u(l),Q.l(l),vl=u(l),sl=J(l,"P",{"data-svelte-h":!0}),w(sl)!=="svelte-1ne29e1"&&(sl.textContent=Pe),ae=u(l),V.l(l),Xl=u(l),tl=J(l,"P",{"data-svelte-h":!0}),w(tl)!=="svelte-1refguu"&&(tl.innerHTML=Oe),pe=u(l),j(nl.$$.fragment,l),Me=u(l),al=J(l,"P",{"data-svelte-h":!0}),w(al)!=="svelte-w6io46"&&(al.textContent=ls),re=u(l),j(G.$$.fragment,l),ie=u(l),pl=J(l,"P",{"data-svelte-h":!0}),w(pl)!=="svelte-1606dt"&&(pl.textContent=es),ue=u(l),j(Ml.$$.fragment,l),ce=u(l),rl=J(l,"P",{"data-svelte-h":!0}),w(rl)!=="svelte-vwy5iv"&&(rl.textContent=ss),me=u(l),j(il.$$.fragment,l),oe=u(l),ul=J(l,"P",{"data-svelte-h":!0}),w(ul)!=="svelte-19s4rp0"&&(ul.textContent=ts),be=u(l),j(cl.$$.fragment,l),je=u(l),ml=J(l,"P",{"data-svelte-h":!0}),w(ml)!=="svelte-3vhdkf"&&(ml.textContent=ns),fe=u(l),E.l(l),Bl=u(l),ol=J(l,"P",{"data-svelte-h":!0}),w(ol)!=="svelte-an7a6l"&&(ol.textContent=as),ye=u(l),bl=J(l,"P",{"data-svelte-h":!0}),w(bl)!=="svelte-1c9g1sd"&&(bl.textContent=ps),Ue=u(l),j(jl.$$.fragment,l),de=u(l),fl=J(l,"P",{"data-svelte-h":!0}),w(fl)!=="svelte-zvdsz0"&&(fl.innerHTML=Ms),Je=u(l),yl=J(l,"P",{"data-svelte-h":!0}),w(yl)!=="svelte-tkwp7j"&&(yl.textContent=rs),we=u(l),R.l(l),Dl=u(l),Ul=J(l,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-tiex34"&&(Ul.textContent=is),Te=u(l),dl=J(l,"P",{"data-svelte-h":!0}),w(dl)!=="svelte-cb07p9"&&(dl.textContent=us),he=u(l),j(v.$$.fragment,l),ke=u(l),j(Jl.$$.fragment,l),_e=u(l),wl=J(l,"P",{"data-svelte-h":!0}),w(wl)!=="svelte-6rcea8"&&(wl.textContent=cs),$e=u(l),Tl=J(l,"UL",{"data-svelte-h":!0}),w(Tl)!=="svelte-1g3lvzn"&&(Tl.innerHTML=ms),Ie=u(l),hl=J(l,"UL",{"data-svelte-h":!0}),w(hl)!=="svelte-j7jtjo"&&(hl.innerHTML=os),Ce=u(l),kl=J(l,"P",{"data-svelte-h":!0}),w(kl)!=="svelte-14805wq"&&(kl.innerHTML=bs),Ae=u(l),_l=J(l,"P",{"data-svelte-h":!0}),w(_l)!=="svelte-qrd9ew"&&(_l.textContent=js),Ze=u(l),j($l.$$.fragment,l),Ne=u(l),j(Il.$$.fragment,l),Qe=u(l),xl=J(l,"P",{}),Ws(xl).forEach(a),this.h()},h(){Es(s,"name","hf:doc:metadata"),Es(s,"content",jt)},m(l,n){Hs(document.head,s),M(l,p,n),M(l,e,n),M(l,r,n),f(t,l,n),M(l,U,n),f(D,l,n),M(l,Hl,n),f(x,l,n),M(l,Sl,n),Cl[h].m(l,n),M(l,El,n),Al[_].m(l,n),M(l,zl,n),M(l,F,n),M(l,Yl,n),M(l,H,n),M(l,Ll,n),M(l,S,n),M(l,ql,n),M(l,Y,n),M(l,Kl,n),M(l,L,n),M(l,Pl,n),M(l,q,n),M(l,Ol,n),f(K,l,n),M(l,le,n),M(l,P,n),M(l,ee,n),Zl[I].m(l,n),M(l,Rl,n),M(l,O,n),M(l,se,n),M(l,ll,n),M(l,te,n),Nl[A].m(l,n),M(l,Gl,n),M(l,el,n),M(l,ne,n),Ql[N].m(l,n),M(l,vl,n),M(l,sl,n),M(l,ae,n),gl[g].m(l,n),M(l,Xl,n),M(l,tl,n),M(l,pe,n),f(nl,l,n),M(l,Me,n),M(l,al,n),M(l,re,n),f(G,l,n),M(l,ie,n),M(l,pl,n),M(l,ue,n),f(Ml,l,n),M(l,ce,n),M(l,rl,n),M(l,me,n),f(il,l,n),M(l,oe,n),M(l,ul,n),M(l,be,n),f(cl,l,n),M(l,je,n),M(l,ml,n),M(l,fe,n),Vl[W].m(l,n),M(l,Bl,n),M(l,ol,n),M(l,ye,n),M(l,bl,n),M(l,Ue,n),f(jl,l,n),M(l,de,n),M(l,fl,n),M(l,Je,n),M(l,yl,n),M(l,we,n),Wl[z].m(l,n),M(l,Dl,n),M(l,Ul,n),M(l,Te,n),M(l,dl,n),M(l,he,n),f(v,l,n),M(l,ke,n),f(Jl,l,n),M(l,_e,n),M(l,wl,n),M(l,$e,n),M(l,Tl,n),M(l,Ie,n),M(l,hl,n),M(l,Ce,n),M(l,kl,n),M(l,Ae,n),M(l,_l,n),M(l,Ze,n),f($l,l,n),M(l,Ne,n),f(Il,l,n),M(l,Qe,n),M(l,xl,n),ge=!0},p(l,[n]){const Qs={};n&1&&(Qs.fw=l[0]),t.$set(Qs);let Ve=h;h=ys(l),h!==Ve&&(B(),c(Cl[Ve],1,1,()=>{Cl[Ve]=null}),X(),k=Cl[h],k||(k=Cl[h]=fs[h](l),k.c()),m(k,1),k.m(El.parentNode,El));let We=_;_=ds(l),_!==We&&(B(),c(Al[We],1,1,()=>{Al[We]=null}),X(),$=Al[_],$||($=Al[_]=Us[_](l),$.c()),m($,1),$.m(zl.parentNode,zl));let Ee=I;I=ws(l),I!==Ee&&(B(),c(Zl[Ee],1,1,()=>{Zl[Ee]=null}),X(),C=Zl[I],C||(C=Zl[I]=Js[I](l),C.c()),m(C,1),C.m(Rl.parentNode,Rl));let ze=A;A=hs(l),A!==ze&&(B(),c(Nl[ze],1,1,()=>{Nl[ze]=null}),X(),Z=Nl[A],Z||(Z=Nl[A]=Ts[A](l),Z.c()),m(Z,1),Z.m(Gl.parentNode,Gl));let Re=N;N=_s(l),N!==Re&&(B(),c(Ql[Re],1,1,()=>{Ql[Re]=null}),X(),Q=Ql[N],Q||(Q=Ql[N]=ks[N](l),Q.c()),m(Q,1),Q.m(vl.parentNode,vl));let Ge=g;g=Is(l),g!==Ge&&(B(),c(gl[Ge],1,1,()=>{gl[Ge]=null}),X(),V=gl[g],V||(V=gl[g]=$s[g](l),V.c()),m(V,1),V.m(Xl.parentNode,Xl));const gs={};n&2&&(gs.$$scope={dirty:n,ctx:l}),G.$set(gs);let ve=W;W=As(l),W!==ve&&(B(),c(Vl[ve],1,1,()=>{Vl[ve]=null}),X(),E=Vl[W],E||(E=Vl[W]=Cs[W](l),E.c()),m(E,1),E.m(Bl.parentNode,Bl));let Xe=z;z=Ns(l),z!==Xe&&(B(),c(Wl[Xe],1,1,()=>{Wl[Xe]=null}),X(),R=Wl[z],R||(R=Wl[z]=Zs[z](l),R.c()),m(R,1),R.m(Dl.parentNode,Dl));const Vs={};n&2&&(Vs.$$scope={dirty:n,ctx:l}),v.$set(Vs)},i(l){ge||(m(t.$$.fragment,l),m(D.$$.fragment,l),m(x.$$.fragment,l),m(k),m($),m(K.$$.fragment,l),m(C),m(Z),m(Q),m(V),m(nl.$$.fragment,l),m(G.$$.fragment,l),m(Ml.$$.fragment,l),m(il.$$.fragment,l),m(cl.$$.fragment,l),m(E),m(jl.$$.fragment,l),m(R),m(v.$$.fragment,l),m(Jl.$$.fragment,l),m($l.$$.fragment,l),m(Il.$$.fragment,l),ge=!0)},o(l){c(t.$$.fragment,l),c(D.$$.fragment,l),c(x.$$.fragment,l),c(k),c($),c(K.$$.fragment,l),c(C),c(Z),c(Q),c(V),c(nl.$$.fragment,l),c(G.$$.fragment,l),c(Ml.$$.fragment,l),c(il.$$.fragment,l),c(cl.$$.fragment,l),c(E),c(jl.$$.fragment,l),c(R),c(v.$$.fragment,l),c(Jl.$$.fragment,l),c($l.$$.fragment,l),c(Il.$$.fragment,l),ge=!1},d(l){l&&(a(p),a(e),a(r),a(U),a(Hl),a(Sl),a(El),a(zl),a(F),a(Yl),a(H),a(Ll),a(S),a(ql),a(Y),a(Kl),a(L),a(Pl),a(q),a(Ol),a(le),a(P),a(ee),a(Rl),a(O),a(se),a(ll),a(te),a(Gl),a(el),a(ne),a(vl),a(sl),a(ae),a(Xl),a(tl),a(pe),a(Me),a(al),a(re),a(ie),a(pl),a(ue),a(ce),a(rl),a(me),a(oe),a(ul),a(be),a(je),a(ml),a(fe),a(Bl),a(ol),a(ye),a(bl),a(Ue),a(de),a(fl),a(Je),a(yl),a(we),a(Dl),a(Ul),a(Te),a(dl),a(he),a(ke),a(_e),a(wl),a($e),a(Tl),a(Ie),a(hl),a(Ce),a(kl),a(Ae),a(_l),a(Ze),a(Ne),a(Qe),a(xl)),a(s),y(t,l),y(D,l),y(x,l),Cl[h].d(l),Al[_].d(l),y(K,l),Zl[I].d(l),Nl[A].d(l),Ql[N].d(l),gl[g].d(l),y(nl,l),y(G,l),y(Ml,l),y(il,l),y(cl,l),Vl[W].d(l),y(jl,l),Wl[z].d(l),y(v,l),y(Jl,l),y($l,l),y(Il,l)}}}const jt='{"title":"處理多個序列","local":"處理多個序列","sections":[{"title":"模型需要一批輸入","local":"模型需要一批輸入","sections":[],"depth":2},{"title":"填充輸入","local":"填充輸入","sections":[],"depth":2},{"title":"注意力遮罩（Attention masks）","local":"注意力遮罩attention-masks","sections":[],"depth":2},{"title":"長序列","local":"長序列","sections":[],"depth":2}],"depth":1}';function ft(o,s,p){let e="pt";return Bs(()=>{const r=new URLSearchParams(window.location.search);p(0,e=r.get("fw")||"pt")}),[e]}class _t extends Ds{constructor(s){super(),xs(this,s,ft,bt,Xs,{})}}export{_t as component};
