import{s as ze,o as Re,n as Ve}from"../chunks/scheduler.37c15a92.js";import{S as Ge,i as Xe,g as d,s as i,r as j,A as ve,h as J,f as a,c as u,j as Ne,u as y,x as w,k as Qe,y as Be,a as M,v as f,t as c,b as v,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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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){y(e.$$.fragment,s)},m(s,r){f(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-xoxzsp"&&(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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){y(e.$$.fragment,t),p=u(t),y(s.$$.fragment,t)},m(t,b){f(e,t,b),M(t,p,b),f(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-bfmzzf"&&(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,Xs="<li>我们如何处理多个序列不同长度?</li>",Sl,S,vs="<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模型默认情况下需要多个句子。在这里，当我们将分词器应用于一个应用程序时，我们尝试在幕后完成分词器所做的一切，但如果仔细观察，您会发现tokenizer不仅将输入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,Xl,ml,se="我们批处理预测中的logits有点问题：第二行应该与第二句的logits相同，但我们得到了完全不同的值！",bs,ol,ee="这是因为Transformer模型的关键特性是关注层，它将每个标记上下文化。这些将考虑填充标记，因为它们涉及序列中的所有标记。为了在通过模型传递不同长度的单个句子时，或者在传递一批应用了相同句子和填充的句子时获得相同的结果，我们需要告诉这些注意层忽略填充标记。这是通过使用 attention mask来实现的。",js,bl,ys,jl,te="<em>Attention masks</em>是与输入ID张量形状完全相同的张量，用0和1填充：1s表示应注意相应的标记，0s表示不应注意相应的标记（即，模型的注意力层应忽略它们）。",fs,yl,ne="让我们用attention mask完成上一个示例：",Us,z,R,vl,fl,ae="现在我们得到了该批中第二个句子的相同登录。",ds,Ul,pe="请注意，第二个序列的最后一个值是一个填充ID，它在attention mask中是一个0值。",Js,X,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 ye=[qe,Ye],Cl=[];function fe(l,n){return l[0]==="pt"?0:1}I=fe(o),C=Cl[I]=ye[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:"注意力面具",local:"注意力面具",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),X=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=Xs,Sl=i(),S=d("ul"),S.innerHTML=vs,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(),Xl=i(),ml=d("p"),ml.textContent=se,bs=i(),ol=d("p"),ol.textContent=ee,js=i(),j(bl.$$.fragment),ys=i(),jl=d("p"),jl.innerHTML=te,fs=i(),yl=d("p"),yl.textContent=ne,Us=i(),R.c(),vl=i(),fl=d("p"),fl.textContent=ae,ds=i(),Ul=d("p"),Ul.textContent=pe,Js=i(),j(X.$$.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=ve("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),y(t.$$.fragment,l),b=u(l),y(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-17kk704"&&(x.textContent=Rs),Fl=u(l),F=J(l,"UL",{"data-svelte-h":!0}),w(F)!=="svelte-kor70g"&&(F.innerHTML=Gs),Hl=u(l),H=J(l,"UL",{"data-svelte-h":!0}),w(H)!=="svelte-ndqf10"&&(H.innerHTML=Xs),Sl=u(l),S=J(l,"UL",{"data-svelte-h":!0}),w(S)!=="svelte-io9mod"&&(S.innerHTML=vs),Yl=u(l),Y=J(l,"UL",{"data-svelte-h":!0}),w(Y)!=="svelte-1bzppce"&&(Y.innerHTML=Bs),ql=u(l),q=J(l,"P",{"data-svelte-h":!0}),w(q)!=="svelte-ks56ml"&&(q.textContent=Ds),Ll=u(l),y(L.$$.fragment,l),Kl=u(l),K=J(l,"P",{"data-svelte-h":!0}),w(K)!=="svelte-1depma5"&&(K.textContent=xs),Pl=u(l),C.l(l),El=u(l),P=J(l,"P",{"data-svelte-h":!0}),w(P)!=="svelte-17qbs1t"&&(P.textContent=Fs),Ol=u(l),O=J(l,"P",{"data-svelte-h":!0}),w(O)!=="svelte-10p50ha"&&(O.textContent=Hs),ls=u(l),Z.l(l),zl=u(l),ll=J(l,"P",{"data-svelte-h":!0}),w(ll)!=="svelte-yanjb1"&&(ll.textContent=Ss),ss=u(l),Q.l(l),Rl=u(l),sl=J(l,"P",{"data-svelte-h":!0}),w(sl)!=="svelte-1obdezm"&&(sl.textContent=Ys),es=u(l),V.l(l),Gl=u(l),el=J(l,"P",{"data-svelte-h":!0}),w(el)!=="svelte-nn0yte"&&(el.innerHTML=qs),ts=u(l),y(tl.$$.fragment,l),ns=u(l),nl=J(l,"P",{"data-svelte-h":!0}),w(nl)!=="svelte-17r4p8c"&&(nl.textContent=Ls),as=u(l),y(G.$$.fragment,l),ps=u(l),al=J(l,"P",{"data-svelte-h":!0}),w(al)!=="svelte-aj98y7"&&(al.textContent=Ks),Ms=u(l),y(pl.$$.fragment,l),rs=u(l),Ml=J(l,"P",{"data-svelte-h":!0}),w(Ml)!=="svelte-1ui0yhg"&&(Ml.textContent=Ps),is=u(l),y(rl.$$.fragment,l),us=u(l),il=J(l,"P",{"data-svelte-h":!0}),w(il)!=="svelte-1595zcg"&&(il.textContent=Os),cs=u(l),y(ul.$$.fragment,l),ms=u(l),cl=J(l,"P",{"data-svelte-h":!0}),w(cl)!=="svelte-1i6cw81"&&(cl.textContent=le),os=u(l),E.l(l),Xl=u(l),ml=J(l,"P",{"data-svelte-h":!0}),w(ml)!=="svelte-13edtgo"&&(ml.textContent=se),bs=u(l),ol=J(l,"P",{"data-svelte-h":!0}),w(ol)!=="svelte-1xsand5"&&(ol.textContent=ee),js=u(l),y(bl.$$.fragment,l),ys=u(l),jl=J(l,"P",{"data-svelte-h":!0}),w(jl)!=="svelte-nsy9ro"&&(jl.innerHTML=te),fs=u(l),yl=J(l,"P",{"data-svelte-h":!0}),w(yl)!=="svelte-1ismkgt"&&(yl.textContent=ne),Us=u(l),R.l(l),vl=u(l),fl=J(l,"P",{"data-svelte-h":!0}),w(fl)!=="svelte-xv4p52"&&(fl.textContent=ae),ds=u(l),Ul=J(l,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-1ua5puj"&&(Ul.textContent=pe),Js=u(l),y(X.$$.fragment,l),ws=u(l),y(dl.$$.fragment,l),Ts=u(l),Jl=J(l,"P",{"data-svelte-h":!0}),w(Jl)!=="svelte-1cflabc"&&(Jl.textContent=Me),hs=u(l),wl=J(l,"UL",{"data-svelte-h":!0}),w(wl)!=="svelte-sobs8j"&&(wl.innerHTML=re),ks=u(l),Tl=J(l,"UL",{"data-svelte-h":!0}),w(Tl)!=="svelte-183b0lq"&&(Tl.innerHTML=ie),_s=u(l),hl=J(l,"P",{"data-svelte-h":!0}),w(hl)!=="svelte-1e1bbgw"&&(hl.innerHTML=ue),$s=u(l),kl=J(l,"P",{"data-svelte-h":!0}),w(kl)!=="svelte-kolhfv"&&(kl.textContent=ce),Is=u(l),y(_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),f(t,l,n),M(l,b,n),f(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),f(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),f(tl,l,n),M(l,ns,n),M(l,nl,n),M(l,as,n),f(G,l,n),M(l,ps,n),M(l,al,n),M(l,Ms,n),f(pl,l,n),M(l,rs,n),M(l,Ml,n),M(l,is,n),f(rl,l,n),M(l,us,n),M(l,il,n),M(l,cs,n),f(ul,l,n),M(l,ms,n),M(l,cl,n),M(l,os,n),Ql[W].m(l,n),M(l,Xl,n),M(l,ml,n),M(l,bs,n),M(l,ol,n),M(l,js,n),f(bl,l,n),M(l,ys,n),M(l,jl,n),M(l,fs,n),M(l,yl,n),M(l,Us,n),gl[z].m(l,n),M(l,vl,n),M(l,fl,n),M(l,ds,n),M(l,Ul,n),M(l,Js,n),f(X,l,n),M(l,ws,n),f(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),f(_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}),v(),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}),v(),$=Il[_],$||($=Il[_]=be[_](l),$.c()),m($,1),$.m(Wl.parentNode,Wl));let Qs=I;I=fe(l),I!==Qs&&(B(),c(Cl[Qs],1,1,()=>{Cl[Qs]=null}),v(),C=Cl[I],C||(C=Cl[I]=ye[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}),v(),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}),v(),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}),v(),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}),v(),E=Ql[W],E||(E=Ql[W]=ke[W](l),E.c()),m(E,1),E.m(Xl.parentNode,Xl));let zs=z;z=Ie(l),z!==zs&&(B(),c(gl[zs],1,1,()=>{gl[zs]=null}),v(),R=gl[z],R||(R=gl[z]=$e[z](l),R.c()),m(R,1),R.m(vl.parentNode,vl));const Ze={};n&2&&(Ze.$$scope={dirty:n,ctx:l}),X.$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(X.$$.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(X.$$.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(Xl),a(ml),a(bs),a(ol),a(js),a(ys),a(jl),a(fs),a(yl),a(Us),a(vl),a(fl),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(X,l),U(dl,l),U(_l,l)}}}const it='{"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 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(),Xe(this,e,ut,rt,ze,{})}}export{dt as component};
