import{s as Gs,o as Xs,n as Es}from"../chunks/scheduler.37c15a92.js";import{S as vs,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 v,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-xanjkg"&&(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-f3kll9"&&(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,Xe="在上一节中，我们探讨了最简单的用例：对一个小长度的序列进行推理。然而，一些问题已经出现：",Hl,F,ve="<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模型默认情况下需要多个句子。在这里，当我们将分词器应用于一个应用程序时，我们尝试在幕后完成分词器所做的一切，但如果仔细观察，您会发现tokenizer不仅将输入ID列表转换为张量，还在其顶部添加了一个维度：",ee,A,Z,Rl,ll,qe="让我们重试并添加一个新维度：",se,N,Q,Gl,el,Le="我们打印输入ID以及生成的logits-以下是输出：",te,g,V,Xl,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,vl,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,X,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:"注意力面具",local:"注意力面具",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),X=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-CN/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=Xe,Hl=i(),F=d("ul"),F.innerHTML=ve,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(),Xl=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(),vl=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(X.$$.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-17kk704"&&(x.textContent=Xe),Hl=u(l),F=J(l,"UL",{"data-svelte-h":!0}),w(F)!=="svelte-kor70g"&&(F.innerHTML=ve),Sl=u(l),H=J(l,"UL",{"data-svelte-h":!0}),w(H)!=="svelte-ndqf10"&&(H.innerHTML=Be),Yl=u(l),S=J(l,"UL",{"data-svelte-h":!0}),w(S)!=="svelte-io9mod"&&(S.innerHTML=De),ql=u(l),Y=J(l,"UL",{"data-svelte-h":!0}),w(Y)!=="svelte-1bzppce"&&(Y.innerHTML=xe),Ll=u(l),q=J(l,"P",{"data-svelte-h":!0}),w(q)!=="svelte-ks56ml"&&(q.textContent=Fe),Kl=u(l),j(L.$$.fragment,l),Pl=u(l),K=J(l,"P",{"data-svelte-h":!0}),w(K)!=="svelte-1depma5"&&(K.textContent=He),Ol=u(l),C.l(l),zl=u(l),P=J(l,"P",{"data-svelte-h":!0}),w(P)!=="svelte-17qbs1t"&&(P.textContent=Se),le=u(l),O=J(l,"P",{"data-svelte-h":!0}),w(O)!=="svelte-10p50ha"&&(O.textContent=Ye),ee=u(l),Z.l(l),Rl=u(l),ll=J(l,"P",{"data-svelte-h":!0}),w(ll)!=="svelte-yanjb1"&&(ll.textContent=qe),se=u(l),Q.l(l),Gl=u(l),el=J(l,"P",{"data-svelte-h":!0}),w(el)!=="svelte-1obdezm"&&(el.textContent=Le),te=u(l),V.l(l),Xl=u(l),sl=J(l,"P",{"data-svelte-h":!0}),w(sl)!=="svelte-nn0yte"&&(sl.innerHTML=Ke),ne=u(l),j(tl.$$.fragment,l),ae=u(l),nl=J(l,"P",{"data-svelte-h":!0}),w(nl)!=="svelte-17r4p8c"&&(nl.textContent=Pe),pe=u(l),j(G.$$.fragment,l),Me=u(l),al=J(l,"P",{"data-svelte-h":!0}),w(al)!=="svelte-aj98y7"&&(al.textContent=Oe),re=u(l),j(pl.$$.fragment,l),ie=u(l),Ml=J(l,"P",{"data-svelte-h":!0}),w(Ml)!=="svelte-1ui0yhg"&&(Ml.textContent=ls),ue=u(l),j(rl.$$.fragment,l),ce=u(l),il=J(l,"P",{"data-svelte-h":!0}),w(il)!=="svelte-1595zcg"&&(il.textContent=es),me=u(l),j(ul.$$.fragment,l),oe=u(l),cl=J(l,"P",{"data-svelte-h":!0}),w(cl)!=="svelte-1i6cw81"&&(cl.textContent=ss),be=u(l),E.l(l),vl=u(l),ml=J(l,"P",{"data-svelte-h":!0}),w(ml)!=="svelte-13edtgo"&&(ml.textContent=ts),je=u(l),ol=J(l,"P",{"data-svelte-h":!0}),w(ol)!=="svelte-1xsand5"&&(ol.textContent=ns),fe=u(l),j(bl.$$.fragment,l),ye=u(l),jl=J(l,"P",{"data-svelte-h":!0}),w(jl)!=="svelte-nsy9ro"&&(jl.innerHTML=as),Ue=u(l),fl=J(l,"P",{"data-svelte-h":!0}),w(fl)!=="svelte-1ismkgt"&&(fl.textContent=ps),de=u(l),R.l(l),Bl=u(l),yl=J(l,"P",{"data-svelte-h":!0}),w(yl)!=="svelte-xv4p52"&&(yl.textContent=Ms),Je=u(l),Ul=J(l,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-1ua5puj"&&(Ul.textContent=rs),we=u(l),j(X.$$.fragment,l),Te=u(l),j(dl.$$.fragment,l),he=u(l),Jl=J(l,"P",{"data-svelte-h":!0}),w(Jl)!=="svelte-1cflabc"&&(Jl.textContent=is),ke=u(l),wl=J(l,"UL",{"data-svelte-h":!0}),w(wl)!=="svelte-sobs8j"&&(wl.innerHTML=us),_e=u(l),Tl=J(l,"UL",{"data-svelte-h":!0}),w(Tl)!=="svelte-183b0lq"&&(Tl.innerHTML=cs),$e=u(l),hl=J(l,"P",{"data-svelte-h":!0}),w(hl)!=="svelte-1e1bbgw"&&(hl.innerHTML=ms),Ie=u(l),kl=J(l,"P",{"data-svelte-h":!0}),w(kl)!=="svelte-kolhfv"&&(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,Xl,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,vl,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(X,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}),v(),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}),v(),$=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}),v(),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}),v(),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}),v(),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}),v(),V=Ql[g],V||(V=Ql[g]=ks[g](l),V.c()),m(V,1),V.m(Xl.parentNode,Xl));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}),v(),E=gl[W],E||(E=gl[W]=$s[W](l),E.c()),m(E,1),E.m(vl.parentNode,vl));let Ge=z;z=As(l),z!==Ge&&(B(),c(Vl[Ge],1,1,()=>{Vl[Ge]=null}),v(),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}),X.$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(X.$$.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(X.$$.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(Xl),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(vl),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(X,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":"注意力面具","local":"注意力面具","sections":[],"depth":2},{"title":"长序列","local":"长序列","sections":[],"depth":2}],"depth":1}';function ot(o,s,p){let e="pt";return Xs(()=>{const r=new URLSearchParams(window.location.search);p(0,e=r.get("fw")||"pt")}),[e]}class Tt extends vs{constructor(s){super(),Bs(this,s,ot,ct,Gs,{})}}export{Tt as component};
