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