import{s as Gs,o as vs,n as Es}from"../chunks/scheduler.37c15a92.js";import{S as Xs,i as Bs,g as d,s as i,r as b,A as Ds,h as J,f as a,c as u,j as gs,u as j,x as w,k as Vs,y as xs,a as M,v as f,t as c,b as X,d as m,w as y,p as B}from"../chunks/index.2bf4358c.js";import{T as Ws}from"../chunks/Tip.363c041f.js";import{Y as zs}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Rs}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Fs}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as xl,E as Hs}from"../chunks/EditOnGithub.8916dc7c.js";function Ss(o){let s,p;return s=new Rs({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 Ys(o){let s,p;return s=new Rs({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 qs(o){let s,p;return s=new zs({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 Ls(o){let s,p;return s=new zs({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 Ks(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 Ps(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 Os(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 lt(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 et(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 st(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 tt(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 nt(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 at(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:Es,d(e){e&&a(s)}}}function pt(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 Mt(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 rt(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 it(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 ut(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:Es,d(e){e&&a(s)}}}function ct(o){let s,p,e,r,t,U,D,Fl,h,k,Wl,_,$,El,x,ve="在上一節中，我們探討了最簡單的用例：對一個小長度的序列進行推理。然而，一些問題已經出現：",Hl,F,Xe="<li>我們如何處理多個序列？</li>",Sl,H,Be="<li>我們如何處理多個序列不同長度?</li>",Yl,S,De="<li>詞彙索引是讓模型正常工作的唯一輸入嗎？</li>",ql,Y,xe="<li>是否存在序列太長的問題？</li>",Ll,q,Fe="讓我們看看這些問題會帶來什麼樣的問題，以及如何使用🤗 Transformers API解決它們",Kl,L,Pl,K,He="在上一個練習中，您看到了序列如何轉換為數字列表。讓我們將此數字列表轉換為張量，並將其發送到模型：",Ol,I,C,zl,P,Se="哦不！為什麼失敗了？我們遵循了第2節中管道的步驟。",le,O,Ye="問題是我們向模型發送了一個序列，而 🤗Transformers 模型默認情況下需要多個句子。在這裡，當我們將分詞器應用於一個應用程序時，我們嘗試在幕後完成分詞器所做的一切，但如果仔細觀察，您會發現它不僅將輸入ID列表轉換為張量，還在其頂部添加了一個維度：",ee,A,Z,Rl,ll,qe="讓我們重試並添加一個新維度：",se,N,Q,Gl,el,Le="我們打印輸入ID以及生成的logits-以下是輸出：",te,g,V,vl,sl,Ke="<em>Batching</em> 是一次通過模型發送多個句子的行為。如果你只有一句話，你可以用一個序列構建一個批次：",ne,tl,ae,nl,Pe="這是一批兩個相同的序列！",pe,G,Me,al,Oe="批處理允許模型在輸入多個句子時工作。使用多個序列就像使用單個序列構建批一樣簡單。不過，還有第二個問題。當你試圖將兩個（或更多）句子組合在一起時，它們的長度可能不同。如果您以前使用過張量，那麼您知道它們必須是矩形，因此無法將輸入ID列表直接轉換為張量。為了解決這個問題，我們通常填充輸入。",re,pl,ie,Ml,ls="以下列表不能轉換為張量：",ue,rl,ce,il,es="為了解決這個問題，我們將使用填充使張量具有矩形。Padding通過在值較少的句子中添加一個名為Padding token的特殊單詞來確保我們所有的句子長度相同。例如，如果你有10個包含10個單詞的句子和1個包含20個單詞的句子，填充將確保所有句子都包含20個單詞。在我們的示例中，生成的張量如下所示：",me,ul,oe,cl,ss="可以在tokenizer.pad_token_id中找到填充令牌ID. 讓我們使用它，將我們的兩句話分別發送到模型中，並分批發送到一起：",be,W,E,Xl,ml,ts="我們批處理預測中的logits有點問題：第二行應該與第二句的logits相同，但我們得到了完全不同的值！",je,ol,ns="這是因為Transformer模型的關鍵特性是關注層，它將每個標記上下文化。這些將考慮填充標記，因為它們涉及序列中的所有標記。為了在通過模型傳遞不同長度的單個句子時，或者在傳遞一批應用了相同句子和填充的句子時獲得相同的結果，我們需要告訴這些注意層忽略填充標記。這是通過使用 attention mask來實現的。",fe,bl,ye,jl,as="<em>Attention masks</em> 是與輸入 ID 張量形狀完全相同的張量，用0和1填充：1s表示應注意相應的標記，0s表示不應注意相應的標記（即，模型的注意力層應忽略它們）。",Ue,fl,ps="讓我們用 attention mask 完成上一個示例：",de,z,R,Bl,yl,Ms="現在我們得到了該批中第二個句子的相同登錄。",Je,Ul,rs="請注意，第二個序列的最後一個值是一個填充ID，它在attention mask中是一個0值。",we,v,Te,dl,he,Jl,is="對於Transformers模型，我們可以通過模型的序列長度是有限的。大多數模型處理多達512或1024個令牌的序列，當要求處理更長的序列時，會崩潰。此問題有兩種解決方案：",ke,wl,us="<li>使用支持的序列長度較長的模型。</li>",_e,Tl,cs="<li>截斷序列。</li>",$e,hl,ms=`模型有不同的支持序列長度，有些模型專門處理很長的序列。
<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>
. 如果您正在處理一項需要很長序列的任務，我們建議您查看這些模型。`,Ie,kl,os="否則，我們建議您通過指定max_sequence_length參數：",Ce,_l,Ae,$l,Ze,Dl,Ne;t=new Fs({props:{fw:o[0]}}),D=new xl({props:{title:"處理多個序列",local:"處理多個序列",headingTag:"h1"}});const bs=[Ys,Ss],Il=[];function js(l,n){return l[0]==="pt"?0:1}h=js(o),k=Il[h]=bs[h](o);const fs=[Ls,qs],Cl=[];function ys(l,n){return l[0]==="pt"?0:1}_=ys(o),$=Cl[_]=fs[_](o),L=new xl({props:{title:"模型需要一批輸入",local:"模型需要一批輸入",headingTag:"h2"}});const Us=[Ps,Ks],Al=[];function ds(l,n){return l[0]==="pt"?0:1}I=ds(o),C=Al[I]=Us[I](o);const Js=[lt,Os],Zl=[];function ws(l,n){return l[0]==="pt"?0:1}A=ws(o),Z=Zl[A]=Js[A](o);const Ts=[st,et],Nl=[];function hs(l,n){return l[0]==="pt"?0:1}N=hs(o),Q=Nl[N]=Ts[N](o);const ks=[nt,tt],Ql=[];function _s(l,n){return l[0]==="pt"?0:1}g=_s(o),V=Ql[g]=ks[g](o),tl=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new Ws({props:{$$slots:{default:[at]},$$scope:{ctx:o}}}),pl=new xl({props:{title:"填充輸入",local:"填充輸入",headingTag:"h2"}}),rl=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}}),ul=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 $s=[Mt,pt],gl=[];function Is(l,n){return l[0]==="pt"?0:1}W=Is(o),E=gl[W]=$s[W](o),bl=new xl({props:{title:"注意力遮罩（Attention masks）",local:"注意力遮罩attention-masks",headingTag:"h2"}});const Cs=[it,rt],Vl=[];function As(l,n){return l[0]==="pt"?0:1}return z=As(o),R=Vl[z]=Cs[z](o),v=new Ws({props:{$$slots:{default:[ut]},$$scope:{ctx:o}}}),dl=new xl({props:{title:"長序列",local:"長序列",headingTag:"h2"}}),_l=new T({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),$l=new Hs({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),Fl=i(),k.c(),Wl=i(),$.c(),El=i(),x=d("p"),x.textContent=ve,Hl=i(),F=d("ul"),F.innerHTML=Xe,Sl=i(),H=d("ul"),H.innerHTML=Be,Yl=i(),S=d("ul"),S.innerHTML=De,ql=i(),Y=d("ul"),Y.innerHTML=xe,Ll=i(),q=d("p"),q.textContent=Fe,Kl=i(),b(L.$$.fragment),Pl=i(),K=d("p"),K.textContent=He,Ol=i(),C.c(),zl=i(),P=d("p"),P.textContent=Se,le=i(),O=d("p"),O.textContent=Ye,ee=i(),Z.c(),Rl=i(),ll=d("p"),ll.textContent=qe,se=i(),Q.c(),Gl=i(),el=d("p"),el.textContent=Le,te=i(),V.c(),vl=i(),sl=d("p"),sl.innerHTML=Ke,ne=i(),b(tl.$$.fragment),ae=i(),nl=d("p"),nl.textContent=Pe,pe=i(),b(G.$$.fragment),Me=i(),al=d("p"),al.textContent=Oe,re=i(),b(pl.$$.fragment),ie=i(),Ml=d("p"),Ml.textContent=ls,ue=i(),b(rl.$$.fragment),ce=i(),il=d("p"),il.textContent=es,me=i(),b(ul.$$.fragment),oe=i(),cl=d("p"),cl.textContent=ss,be=i(),E.c(),Xl=i(),ml=d("p"),ml.textContent=ts,je=i(),ol=d("p"),ol.textContent=ns,fe=i(),b(bl.$$.fragment),ye=i(),jl=d("p"),jl.innerHTML=as,Ue=i(),fl=d("p"),fl.textContent=ps,de=i(),R.c(),Bl=i(),yl=d("p"),yl.textContent=Ms,Je=i(),Ul=d("p"),Ul.textContent=rs,we=i(),b(v.$$.fragment),Te=i(),b(dl.$$.fragment),he=i(),Jl=d("p"),Jl.textContent=is,ke=i(),wl=d("ul"),wl.innerHTML=us,_e=i(),Tl=d("ul"),Tl.innerHTML=cs,$e=i(),hl=d("p"),hl.innerHTML=ms,Ie=i(),kl=d("p"),kl.textContent=os,Ce=i(),b(_l.$$.fragment),Ae=i(),b($l.$$.fragment),Ze=i(),Dl=d("p"),this.h()},l(l){const n=Ds("svelte-u9bgzb",document.head);s=J(n,"META",{name:!0,content:!0}),n.forEach(a),p=u(l),e=J(l,"P",{}),gs(e).forEach(a),r=u(l),j(t.$$.fragment,l),U=u(l),j(D.$$.fragment,l),Fl=u(l),k.l(l),Wl=u(l),$.l(l),El=u(l),x=J(l,"P",{"data-svelte-h":!0}),w(x)!=="svelte-6dkml4"&&(x.textContent=ve),Hl=u(l),F=J(l,"UL",{"data-svelte-h":!0}),w(F)!=="svelte-9tzwkr"&&(F.innerHTML=Xe),Sl=u(l),H=J(l,"UL",{"data-svelte-h":!0}),w(H)!=="svelte-1w7fwlb"&&(H.innerHTML=Be),Yl=u(l),S=J(l,"UL",{"data-svelte-h":!0}),w(S)!=="svelte-x0w2fa"&&(S.innerHTML=De),ql=u(l),Y=J(l,"UL",{"data-svelte-h":!0}),w(Y)!=="svelte-18odgmb"&&(Y.innerHTML=xe),Ll=u(l),q=J(l,"P",{"data-svelte-h":!0}),w(q)!=="svelte-1kwjoxo"&&(q.textContent=Fe),Kl=u(l),j(L.$$.fragment,l),Pl=u(l),K=J(l,"P",{"data-svelte-h":!0}),w(K)!=="svelte-1fptg5k"&&(K.textContent=He),Ol=u(l),C.l(l),zl=u(l),P=J(l,"P",{"data-svelte-h":!0}),w(P)!=="svelte-1u75gf9"&&(P.textContent=Se),le=u(l),O=J(l,"P",{"data-svelte-h":!0}),w(O)!=="svelte-18zv6do"&&(O.textContent=Ye),ee=u(l),Z.l(l),Rl=u(l),ll=J(l,"P",{"data-svelte-h":!0}),w(ll)!=="svelte-eu2vvx"&&(ll.textContent=qe),se=u(l),Q.l(l),Gl=u(l),el=J(l,"P",{"data-svelte-h":!0}),w(el)!=="svelte-1ne29e1"&&(el.textContent=Le),te=u(l),V.l(l),vl=u(l),sl=J(l,"P",{"data-svelte-h":!0}),w(sl)!=="svelte-1refguu"&&(sl.innerHTML=Ke),ne=u(l),j(tl.$$.fragment,l),ae=u(l),nl=J(l,"P",{"data-svelte-h":!0}),w(nl)!=="svelte-w6io46"&&(nl.textContent=Pe),pe=u(l),j(G.$$.fragment,l),Me=u(l),al=J(l,"P",{"data-svelte-h":!0}),w(al)!=="svelte-1606dt"&&(al.textContent=Oe),re=u(l),j(pl.$$.fragment,l),ie=u(l),Ml=J(l,"P",{"data-svelte-h":!0}),w(Ml)!=="svelte-vwy5iv"&&(Ml.textContent=ls),ue=u(l),j(rl.$$.fragment,l),ce=u(l),il=J(l,"P",{"data-svelte-h":!0}),w(il)!=="svelte-19s4rp0"&&(il.textContent=es),me=u(l),j(ul.$$.fragment,l),oe=u(l),cl=J(l,"P",{"data-svelte-h":!0}),w(cl)!=="svelte-3vhdkf"&&(cl.textContent=ss),be=u(l),E.l(l),Xl=u(l),ml=J(l,"P",{"data-svelte-h":!0}),w(ml)!=="svelte-an7a6l"&&(ml.textContent=ts),je=u(l),ol=J(l,"P",{"data-svelte-h":!0}),w(ol)!=="svelte-1c9g1sd"&&(ol.textContent=ns),fe=u(l),j(bl.$$.fragment,l),ye=u(l),jl=J(l,"P",{"data-svelte-h":!0}),w(jl)!=="svelte-zvdsz0"&&(jl.innerHTML=as),Ue=u(l),fl=J(l,"P",{"data-svelte-h":!0}),w(fl)!=="svelte-tkwp7j"&&(fl.textContent=ps),de=u(l),R.l(l),Bl=u(l),yl=J(l,"P",{"data-svelte-h":!0}),w(yl)!=="svelte-tiex34"&&(yl.textContent=Ms),Je=u(l),Ul=J(l,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-cb07p9"&&(Ul.textContent=rs),we=u(l),j(v.$$.fragment,l),Te=u(l),j(dl.$$.fragment,l),he=u(l),Jl=J(l,"P",{"data-svelte-h":!0}),w(Jl)!=="svelte-6rcea8"&&(Jl.textContent=is),ke=u(l),wl=J(l,"UL",{"data-svelte-h":!0}),w(wl)!=="svelte-1g3lvzn"&&(wl.innerHTML=us),_e=u(l),Tl=J(l,"UL",{"data-svelte-h":!0}),w(Tl)!=="svelte-j7jtjo"&&(Tl.innerHTML=cs),$e=u(l),hl=J(l,"P",{"data-svelte-h":!0}),w(hl)!=="svelte-14805wq"&&(hl.innerHTML=ms),Ie=u(l),kl=J(l,"P",{"data-svelte-h":!0}),w(kl)!=="svelte-qrd9ew"&&(kl.textContent=os),Ce=u(l),j(_l.$$.fragment,l),Ae=u(l),j($l.$$.fragment,l),Ze=u(l),Dl=J(l,"P",{}),gs(Dl).forEach(a),this.h()},h(){Vs(s,"name","hf:doc:metadata"),Vs(s,"content",mt)},m(l,n){xs(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,Fl,n),Il[h].m(l,n),M(l,Wl,n),Cl[_].m(l,n),M(l,El,n),M(l,x,n),M(l,Hl,n),M(l,F,n),M(l,Sl,n),M(l,H,n),M(l,Yl,n),M(l,S,n),M(l,ql,n),M(l,Y,n),M(l,Ll,n),M(l,q,n),M(l,Kl,n),f(L,l,n),M(l,Pl,n),M(l,K,n),M(l,Ol,n),Al[I].m(l,n),M(l,zl,n),M(l,P,n),M(l,le,n),M(l,O,n),M(l,ee,n),Zl[A].m(l,n),M(l,Rl,n),M(l,ll,n),M(l,se,n),Nl[N].m(l,n),M(l,Gl,n),M(l,el,n),M(l,te,n),Ql[g].m(l,n),M(l,vl,n),M(l,sl,n),M(l,ne,n),f(tl,l,n),M(l,ae,n),M(l,nl,n),M(l,pe,n),f(G,l,n),M(l,Me,n),M(l,al,n),M(l,re,n),f(pl,l,n),M(l,ie,n),M(l,Ml,n),M(l,ue,n),f(rl,l,n),M(l,ce,n),M(l,il,n),M(l,me,n),f(ul,l,n),M(l,oe,n),M(l,cl,n),M(l,be,n),gl[W].m(l,n),M(l,Xl,n),M(l,ml,n),M(l,je,n),M(l,ol,n),M(l,fe,n),f(bl,l,n),M(l,ye,n),M(l,jl,n),M(l,Ue,n),M(l,fl,n),M(l,de,n),Vl[z].m(l,n),M(l,Bl,n),M(l,yl,n),M(l,Je,n),M(l,Ul,n),M(l,we,n),f(v,l,n),M(l,Te,n),f(dl,l,n),M(l,he,n),M(l,Jl,n),M(l,ke,n),M(l,wl,n),M(l,_e,n),M(l,Tl,n),M(l,$e,n),M(l,hl,n),M(l,Ie,n),M(l,kl,n),M(l,Ce,n),f(_l,l,n),M(l,Ae,n),f($l,l,n),M(l,Ze,n),M(l,Dl,n),Ne=!0},p(l,[n]){const Zs={};n&1&&(Zs.fw=l[0]),t.$set(Zs);let Qe=h;h=js(l),h!==Qe&&(B(),c(Il[Qe],1,1,()=>{Il[Qe]=null}),X(),k=Il[h],k||(k=Il[h]=bs[h](l),k.c()),m(k,1),k.m(Wl.parentNode,Wl));let ge=_;_=ys(l),_!==ge&&(B(),c(Cl[ge],1,1,()=>{Cl[ge]=null}),X(),$=Cl[_],$||($=Cl[_]=fs[_](l),$.c()),m($,1),$.m(El.parentNode,El));let Ve=I;I=ds(l),I!==Ve&&(B(),c(Al[Ve],1,1,()=>{Al[Ve]=null}),X(),C=Al[I],C||(C=Al[I]=Us[I](l),C.c()),m(C,1),C.m(zl.parentNode,zl));let We=A;A=ws(l),A!==We&&(B(),c(Zl[We],1,1,()=>{Zl[We]=null}),X(),Z=Zl[A],Z||(Z=Zl[A]=Js[A](l),Z.c()),m(Z,1),Z.m(Rl.parentNode,Rl));let Ee=N;N=hs(l),N!==Ee&&(B(),c(Nl[Ee],1,1,()=>{Nl[Ee]=null}),X(),Q=Nl[N],Q||(Q=Nl[N]=Ts[N](l),Q.c()),m(Q,1),Q.m(Gl.parentNode,Gl));let ze=g;g=_s(l),g!==ze&&(B(),c(Ql[ze],1,1,()=>{Ql[ze]=null}),X(),V=Ql[g],V||(V=Ql[g]=ks[g](l),V.c()),m(V,1),V.m(vl.parentNode,vl));const Ns={};n&2&&(Ns.$$scope={dirty:n,ctx:l}),G.$set(Ns);let Re=W;W=Is(l),W!==Re&&(B(),c(gl[Re],1,1,()=>{gl[Re]=null}),X(),E=gl[W],E||(E=gl[W]=$s[W](l),E.c()),m(E,1),E.m(Xl.parentNode,Xl));let Ge=z;z=As(l),z!==Ge&&(B(),c(Vl[Ge],1,1,()=>{Vl[Ge]=null}),X(),R=Vl[z],R||(R=Vl[z]=Cs[z](l),R.c()),m(R,1),R.m(Bl.parentNode,Bl));const Qs={};n&2&&(Qs.$$scope={dirty:n,ctx:l}),v.$set(Qs)},i(l){Ne||(m(t.$$.fragment,l),m(D.$$.fragment,l),m(k),m($),m(L.$$.fragment,l),m(C),m(Z),m(Q),m(V),m(tl.$$.fragment,l),m(G.$$.fragment,l),m(pl.$$.fragment,l),m(rl.$$.fragment,l),m(ul.$$.fragment,l),m(E),m(bl.$$.fragment,l),m(R),m(v.$$.fragment,l),m(dl.$$.fragment,l),m(_l.$$.fragment,l),m($l.$$.fragment,l),Ne=!0)},o(l){c(t.$$.fragment,l),c(D.$$.fragment,l),c(k),c($),c(L.$$.fragment,l),c(C),c(Z),c(Q),c(V),c(tl.$$.fragment,l),c(G.$$.fragment,l),c(pl.$$.fragment,l),c(rl.$$.fragment,l),c(ul.$$.fragment,l),c(E),c(bl.$$.fragment,l),c(R),c(v.$$.fragment,l),c(dl.$$.fragment,l),c(_l.$$.fragment,l),c($l.$$.fragment,l),Ne=!1},d(l){l&&(a(p),a(e),a(r),a(U),a(Fl),a(Wl),a(El),a(x),a(Hl),a(F),a(Sl),a(H),a(Yl),a(S),a(ql),a(Y),a(Ll),a(q),a(Kl),a(Pl),a(K),a(Ol),a(zl),a(P),a(le),a(O),a(ee),a(Rl),a(ll),a(se),a(Gl),a(el),a(te),a(vl),a(sl),a(ne),a(ae),a(nl),a(pe),a(Me),a(al),a(re),a(ie),a(Ml),a(ue),a(ce),a(il),a(me),a(oe),a(cl),a(be),a(Xl),a(ml),a(je),a(ol),a(fe),a(ye),a(jl),a(Ue),a(fl),a(de),a(Bl),a(yl),a(Je),a(Ul),a(we),a(Te),a(he),a(Jl),a(ke),a(wl),a(_e),a(Tl),a($e),a(hl),a(Ie),a(kl),a(Ce),a(Ae),a(Ze),a(Dl)),a(s),y(t,l),y(D,l),Il[h].d(l),Cl[_].d(l),y(L,l),Al[I].d(l),Zl[A].d(l),Nl[N].d(l),Ql[g].d(l),y(tl,l),y(G,l),y(pl,l),y(rl,l),y(ul,l),gl[W].d(l),y(bl,l),Vl[z].d(l),y(v,l),y(dl,l),y(_l,l),y($l,l)}}}const mt='{"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 ot(o,s,p){let e="pt";return vs(()=>{const r=new URLSearchParams(window.location.search);p(0,e=r.get("fw")||"pt")}),[e]}class Tt extends Xs{constructor(s){super(),Bs(this,s,ot,ct,Gs,{})}}export{Tt as component};
