import{s as _l,o as gl,n as Jl}from"../chunks/scheduler.37c15a92.js";import{S as $l,i as Il,g as j,s as o,r as h,A as Al,h as w,f as p,c as u,j as jl,u as b,x as U,k as wl,y as Zl,a as i,v as y,t as M,b as X,d as c,w as f,p as B}from"../chunks/index.2bf4358c.js";import{T as Ul}from"../chunks/Tip.363c041f.js";import{Y as Tl}from"../chunks/Youtube.1e50a667.js";import{C as J}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as kl}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Cl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Re}from"../chunks/Heading.8ada512a.js";function Nl(m){let l,a;return l=new kl({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/en/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"}]}}),{c(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Ql(m){let l,a;return l=new kl({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/en/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"}]}}),{c(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Vl(m){let l,a;return l=new Tl({props:{id:"ROxrFOEbsQE"}}),{c(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Wl(m){let l,a;return l=new Tl({props:{id:"M6adb1j2jPI"}}),{c(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function vl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function El(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function zl(m){let l,a,s,r;return l=new J({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 J({props:{code:"JTNDdGYuVGVuc29yJTNBJTIwc2hhcGUlM0QoMSUyQyUyMDE2KSUyQyUyMGR0eXBlJTNEaW50MzIlMkMlMjBudW1weSUzRCUwQWFycmF5KCU1QiU1QiUyMCUyMDEwMSUyQyUyMCUyMDEwNDUlMkMlMjAlMjAxMDA1JTJDJTIwJTIwMjMxMCUyQyUyMCUyMDIwNDIlMkMlMjAlMjAzNDAzJTJDJTIwJTIwMjAwNSUyQyUyMCUyMDEwMzclMkMlMjAxNzY2MiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDEyMTcyJTJDJTIwJTIwMjYwNyUyQyUyMCUyMDIwMjYlMkMlMjAlMjAyODc4JTJDJTIwJTIwMjE2NiUyQyUyMCUyMDEwMTIlMkMlMjAlMjAlMjAxMDIlNUQlNUQlMkMlMjBkdHlwZSUzRGludDMyKSUzRQ==",highlighted:`&lt;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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function Rl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function Gl(m){let l,a;return l=new J({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(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Xl(m){let l,a;return l=new J({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(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Bl(m){let l,a;return l=new J({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(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Dl(m){let l,a;return l=new J({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(){h(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(c(l.$$.fragment,s),a=!0)},o(s){M(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Hl(m){let l,a="✏️ <strong>Try it out!</strong> Convert this <code>batched_ids</code> list into a tensor and pass it through your model. Check that you obtain the same logits as before (but twice)!";return{c(){l=j("p"),l.innerHTML=a},l(s){l=w(s,"P",{"data-svelte-h":!0}),U(l)!=="svelte-14nl6tk"&&(l.innerHTML=a)},m(s,r){i(s,l,r)},p:Jl,d(s){s&&p(l)}}}function xl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function Fl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function Sl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function Yl(m){let l,a,s,r;return l=new J({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 J({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(){h(l.$$.fragment),a=o(),h(s.$$.fragment)},l(t){b(l.$$.fragment,t),a=u(t),b(s.$$.fragment,t)},m(t,d){y(l,t,d),i(t,a,d),y(s,t,d),r=!0},i(t){r||(c(l.$$.fragment,t),c(s.$$.fragment,t),r=!0)},o(t){M(l.$$.fragment,t),M(s.$$.fragment,t),r=!1},d(t){t&&p(a),f(l,t),f(s,t)}}}function ql(m){let l,a="✏️ <strong>Try it out!</strong> Apply the tokenization manually on the two sentences used in section 2 (“I’ve been waiting for a HuggingFace course my whole life.” and “I hate this so much!”). Pass them through the model and check that you get the same logits as in section 2. Now batch them together using the padding token, then create the proper attention mask. Check that you obtain the same results when going through the model!";return{c(){l=j("p"),l.innerHTML=a},l(s){l=w(s,"P",{"data-svelte-h":!0}),U(l)!=="svelte-bymv7q"&&(l.innerHTML=a)},m(s,r){i(s,l,r)},p:Jl,d(s){s&&p(l)}}}function Ll(m){let l,a,s,r,t,d,D,Ge,T,k,Ze,_,g,Ce,H,Zs="In the previous section, we explored the simplest of use cases: doing inference on a single sequence of a small length. However, some questions emerge already:",Xe,x,Cs="<li>How do we handle multiple sequences?</li> <li>How do we handle multiple sequences <em>of different lengths</em>?</li> <li>Are vocabulary indices the only inputs that allow a model to work well?</li> <li>Is there such a thing as too long a sequence?</li>",Be,F,Ns="Let’s see what kinds of problems these questions pose, and how we can solve them using the 🤗 Transformers API.",De,S,He,Y,Qs="In the previous exercise you saw how sequences get translated into lists of numbers. Let’s convert this list of numbers to a tensor and send it to the model:",xe,$,I,Ne,q,Vs="Oh no! Why did this fail? “We followed the steps from the pipeline in section 2.",Fe,L,Ws="The problem is that we sent a single sequence to the model, whereas 🤗 Transformers models expect multiple sentences by default. Here we tried to do everything the tokenizer did behind the scenes when we applied it to a <code>sequence</code>. But if you look closely, you’ll see that the tokenizer didn’t just convert the list of input IDs into a tensor, it added a dimension on top of it:",Se,A,Z,Qe,K,vs="Let’s try again and add a new dimension:",Ye,C,N,Ve,P,Es="We print the input IDs as well as the resulting logits — here’s the output:",qe,Q,V,We,O,zs="<em>Batching</em> is the act of sending multiple sentences through the model, all at once. If you only have one sentence, you can just build a batch with a single sequence:",Le,ee,Ke,se,Rs="This is a batch of two identical sequences!",Pe,R,Oe,le,Gs="Batching allows the model to work when you feed it multiple sentences. Using multiple sequences is just as simple as building a batch with a single sequence. There’s a second issue, though. When you’re trying to batch together two (or more) sentences, they might be of different lengths. If you’ve ever worked with tensors before, you know that they need to be of rectangular shape, so you won’t be able to convert the list of input IDs into a tensor directly. To work around this problem, we usually <em>pad</em> the inputs.",es,te,ss,ne,Xs="The following list of lists cannot be converted to a tensor:",ls,ae,ts,pe,Bs="In order to work around this, we’ll use <em>padding</em> to make our tensors have a rectangular shape. Padding makes sure all our sentences have the same length by adding a special word called the <em>padding token</em> to the sentences with fewer values. For example, if you have 10 sentences with 10 words and 1 sentence with 20 words, padding will ensure all the sentences have 20 words. In our example, the resulting tensor looks like this:",ns,ie,as,re,Ds="The padding token ID can be found in <code>tokenizer.pad_token_id</code>. Let’s use it and send our two sentences through the model individually and batched together:",ps,W,v,ve,oe,Hs="There’s something wrong with the logits in our batched predictions: the second row should be the same as the logits for the second sentence, but we’ve got completely different values!",is,ue,xs="This is because the key feature of Transformer models is attention layers that <em>contextualize</em> each token. These will take into account the padding tokens since they attend to all of the tokens of a sequence. To get the same result when passing individual sentences of different lengths through the model or when passing a batch with the same sentences and padding applied, we need to tell those attention layers to ignore the padding tokens. This is done by using an attention mask.",rs,Me,os,ce,Fs="<em>Attention masks</em> are tensors with the exact same shape as the input IDs tensor, filled with 0s and 1s: 1s indicate the corresponding tokens should be attended to, and 0s indicate the corresponding tokens should not be attended to (i.e., they should be ignored by the attention layers of the model).",us,me,Ss="Let’s complete the previous example with an attention mask:",Ms,E,z,Ee,de,Ys="Now we get the same logits for the second sentence in the batch.",cs,he,qs="Notice how the last value of the second sequence is a padding ID, which is a 0 value in the attention mask.",ms,G,ds,be,hs,ye,Ls="With Transformer models, there is a limit to the lengths of the sequences we can pass the models. Most models handle sequences of up to 512 or 1024 tokens, and will crash when asked to process longer sequences. There are two solutions to this problem:",bs,fe,Ks="<li>Use a model with a longer supported sequence length.</li> <li>Truncate your sequences.</li>",ys,je,Ps='Models have different supported sequence lengths, and some specialize in handling very long sequences. <a href="https://huggingface.co/docs/transformers/model_doc/longformer" rel="nofollow">Longformer</a> is one example, and another is <a href="https://huggingface.co/docs/transformers/model_doc/led" rel="nofollow">LED</a>. If you’re working on a task that requires very long sequences, we recommend you take a look at those models.',fs,we,Os="Otherwise, we recommend you truncate your sequences by specifying the <code>max_sequence_length</code> parameter:",js,Ue,ws,ze,Us;t=new Cl({props:{fw:m[0]}}),D=new Re({props:{title:"Handling multiple sequences",local:"handling-multiple-sequences",headingTag:"h1"}});const el=[Ql,Nl],Je=[];function sl(e,n){return e[0]==="pt"?0:1}T=sl(m),k=Je[T]=el[T](m);const ll=[Wl,Vl],Te=[];function tl(e,n){return e[0]==="pt"?0:1}_=tl(m),g=Te[_]=ll[_](m),S=new Re({props:{title:"Models expect a batch of inputs",local:"models-expect-a-batch-of-inputs",headingTag:"h2"}});const nl=[El,vl],ke=[];function al(e,n){return e[0]==="pt"?0:1}$=al(m),I=ke[$]=nl[$](m);const pl=[Rl,zl],_e=[];function il(e,n){return e[0]==="pt"?0:1}A=il(m),Z=_e[A]=pl[A](m);const rl=[Xl,Gl],ge=[];function ol(e,n){return e[0]==="pt"?0:1}C=ol(m),N=ge[C]=rl[C](m);const ul=[Dl,Bl],$e=[];function Ml(e,n){return e[0]==="pt"?0:1}Q=Ml(m),V=$e[Q]=ul[Q](m),ee=new J({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),R=new Ul({props:{$$slots:{default:[Hl]},$$scope:{ctx:m}}}),te=new Re({props:{title:"Padding the inputs",local:"padding-the-inputs",headingTag:"h2"}}),ae=new J({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}}),ie=new J({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 cl=[Fl,xl],Ie=[];function ml(e,n){return e[0]==="pt"?0:1}W=ml(m),v=Ie[W]=cl[W](m),Me=new Re({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const dl=[Yl,Sl],Ae=[];function hl(e,n){return e[0]==="pt"?0:1}return E=hl(m),z=Ae[E]=dl[E](m),G=new Ul({props:{$$slots:{default:[ql]},$$scope:{ctx:m}}}),be=new Re({props:{title:"Longer sequences",local:"longer-sequences",headingTag:"h2"}}),Ue=new J({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),{c(){l=j("meta"),a=o(),s=j("p"),r=o(),h(t.$$.fragment),d=o(),h(D.$$.fragment),Ge=o(),k.c(),Ze=o(),g.c(),Ce=o(),H=j("p"),H.textContent=Zs,Xe=o(),x=j("ul"),x.innerHTML=Cs,Be=o(),F=j("p"),F.textContent=Ns,De=o(),h(S.$$.fragment),He=o(),Y=j("p"),Y.textContent=Qs,xe=o(),I.c(),Ne=o(),q=j("p"),q.textContent=Vs,Fe=o(),L=j("p"),L.innerHTML=Ws,Se=o(),Z.c(),Qe=o(),K=j("p"),K.textContent=vs,Ye=o(),N.c(),Ve=o(),P=j("p"),P.textContent=Es,qe=o(),V.c(),We=o(),O=j("p"),O.innerHTML=zs,Le=o(),h(ee.$$.fragment),Ke=o(),se=j("p"),se.textContent=Rs,Pe=o(),h(R.$$.fragment),Oe=o(),le=j("p"),le.innerHTML=Gs,es=o(),h(te.$$.fragment),ss=o(),ne=j("p"),ne.textContent=Xs,ls=o(),h(ae.$$.fragment),ts=o(),pe=j("p"),pe.innerHTML=Bs,ns=o(),h(ie.$$.fragment),as=o(),re=j("p"),re.innerHTML=Ds,ps=o(),v.c(),ve=o(),oe=j("p"),oe.textContent=Hs,is=o(),ue=j("p"),ue.innerHTML=xs,rs=o(),h(Me.$$.fragment),os=o(),ce=j("p"),ce.innerHTML=Fs,us=o(),me=j("p"),me.textContent=Ss,Ms=o(),z.c(),Ee=o(),de=j("p"),de.textContent=Ys,cs=o(),he=j("p"),he.textContent=qs,ms=o(),h(G.$$.fragment),ds=o(),h(be.$$.fragment),hs=o(),ye=j("p"),ye.textContent=Ls,bs=o(),fe=j("ul"),fe.innerHTML=Ks,ys=o(),je=j("p"),je.innerHTML=Ps,fs=o(),we=j("p"),we.innerHTML=Os,js=o(),h(Ue.$$.fragment),ws=o(),ze=j("p"),this.h()},l(e){const n=Al("svelte-u9bgzb",document.head);l=w(n,"META",{name:!0,content:!0}),n.forEach(p),a=u(e),s=w(e,"P",{}),jl(s).forEach(p),r=u(e),b(t.$$.fragment,e),d=u(e),b(D.$$.fragment,e),Ge=u(e),k.l(e),Ze=u(e),g.l(e),Ce=u(e),H=w(e,"P",{"data-svelte-h":!0}),U(H)!=="svelte-11tri8y"&&(H.textContent=Zs),Xe=u(e),x=w(e,"UL",{"data-svelte-h":!0}),U(x)!=="svelte-10g4d7v"&&(x.innerHTML=Cs),Be=u(e),F=w(e,"P",{"data-svelte-h":!0}),U(F)!=="svelte-1m7g6xt"&&(F.textContent=Ns),De=u(e),b(S.$$.fragment,e),He=u(e),Y=w(e,"P",{"data-svelte-h":!0}),U(Y)!=="svelte-13avqtg"&&(Y.textContent=Qs),xe=u(e),I.l(e),Ne=u(e),q=w(e,"P",{"data-svelte-h":!0}),U(q)!=="svelte-c7c0he"&&(q.textContent=Vs),Fe=u(e),L=w(e,"P",{"data-svelte-h":!0}),U(L)!=="svelte-1qp650b"&&(L.innerHTML=Ws),Se=u(e),Z.l(e),Qe=u(e),K=w(e,"P",{"data-svelte-h":!0}),U(K)!=="svelte-140p9gl"&&(K.textContent=vs),Ye=u(e),N.l(e),Ve=u(e),P=w(e,"P",{"data-svelte-h":!0}),U(P)!=="svelte-1tdkgla"&&(P.textContent=Es),qe=u(e),V.l(e),We=u(e),O=w(e,"P",{"data-svelte-h":!0}),U(O)!=="svelte-1qemevg"&&(O.innerHTML=zs),Le=u(e),b(ee.$$.fragment,e),Ke=u(e),se=w(e,"P",{"data-svelte-h":!0}),U(se)!=="svelte-y799te"&&(se.textContent=Rs),Pe=u(e),b(R.$$.fragment,e),Oe=u(e),le=w(e,"P",{"data-svelte-h":!0}),U(le)!=="svelte-cbff1h"&&(le.innerHTML=Gs),es=u(e),b(te.$$.fragment,e),ss=u(e),ne=w(e,"P",{"data-svelte-h":!0}),U(ne)!=="svelte-1vhszdz"&&(ne.textContent=Xs),ls=u(e),b(ae.$$.fragment,e),ts=u(e),pe=w(e,"P",{"data-svelte-h":!0}),U(pe)!=="svelte-tabns3"&&(pe.innerHTML=Bs),ns=u(e),b(ie.$$.fragment,e),as=u(e),re=w(e,"P",{"data-svelte-h":!0}),U(re)!=="svelte-1tifusi"&&(re.innerHTML=Ds),ps=u(e),v.l(e),ve=u(e),oe=w(e,"P",{"data-svelte-h":!0}),U(oe)!=="svelte-wwgzh3"&&(oe.textContent=Hs),is=u(e),ue=w(e,"P",{"data-svelte-h":!0}),U(ue)!=="svelte-tjy5dt"&&(ue.innerHTML=xs),rs=u(e),b(Me.$$.fragment,e),os=u(e),ce=w(e,"P",{"data-svelte-h":!0}),U(ce)!=="svelte-102hkoc"&&(ce.innerHTML=Fs),us=u(e),me=w(e,"P",{"data-svelte-h":!0}),U(me)!=="svelte-1pxdg9d"&&(me.textContent=Ss),Ms=u(e),z.l(e),Ee=u(e),de=w(e,"P",{"data-svelte-h":!0}),U(de)!=="svelte-1r7a38q"&&(de.textContent=Ys),cs=u(e),he=w(e,"P",{"data-svelte-h":!0}),U(he)!=="svelte-le11td"&&(he.textContent=qs),ms=u(e),b(G.$$.fragment,e),ds=u(e),b(be.$$.fragment,e),hs=u(e),ye=w(e,"P",{"data-svelte-h":!0}),U(ye)!=="svelte-j7vz7j"&&(ye.textContent=Ls),bs=u(e),fe=w(e,"UL",{"data-svelte-h":!0}),U(fe)!=="svelte-fx4oon"&&(fe.innerHTML=Ks),ys=u(e),je=w(e,"P",{"data-svelte-h":!0}),U(je)!=="svelte-o1zbju"&&(je.innerHTML=Ps),fs=u(e),we=w(e,"P",{"data-svelte-h":!0}),U(we)!=="svelte-mh7f9s"&&(we.innerHTML=Os),js=u(e),b(Ue.$$.fragment,e),ws=u(e),ze=w(e,"P",{}),jl(ze).forEach(p),this.h()},h(){wl(l,"name","hf:doc:metadata"),wl(l,"content",Kl)},m(e,n){Zl(document.head,l),i(e,a,n),i(e,s,n),i(e,r,n),y(t,e,n),i(e,d,n),y(D,e,n),i(e,Ge,n),Je[T].m(e,n),i(e,Ze,n),Te[_].m(e,n),i(e,Ce,n),i(e,H,n),i(e,Xe,n),i(e,x,n),i(e,Be,n),i(e,F,n),i(e,De,n),y(S,e,n),i(e,He,n),i(e,Y,n),i(e,xe,n),ke[$].m(e,n),i(e,Ne,n),i(e,q,n),i(e,Fe,n),i(e,L,n),i(e,Se,n),_e[A].m(e,n),i(e,Qe,n),i(e,K,n),i(e,Ye,n),ge[C].m(e,n),i(e,Ve,n),i(e,P,n),i(e,qe,n),$e[Q].m(e,n),i(e,We,n),i(e,O,n),i(e,Le,n),y(ee,e,n),i(e,Ke,n),i(e,se,n),i(e,Pe,n),y(R,e,n),i(e,Oe,n),i(e,le,n),i(e,es,n),y(te,e,n),i(e,ss,n),i(e,ne,n),i(e,ls,n),y(ae,e,n),i(e,ts,n),i(e,pe,n),i(e,ns,n),y(ie,e,n),i(e,as,n),i(e,re,n),i(e,ps,n),Ie[W].m(e,n),i(e,ve,n),i(e,oe,n),i(e,is,n),i(e,ue,n),i(e,rs,n),y(Me,e,n),i(e,os,n),i(e,ce,n),i(e,us,n),i(e,me,n),i(e,Ms,n),Ae[E].m(e,n),i(e,Ee,n),i(e,de,n),i(e,cs,n),i(e,he,n),i(e,ms,n),y(G,e,n),i(e,ds,n),y(be,e,n),i(e,hs,n),i(e,ye,n),i(e,bs,n),i(e,fe,n),i(e,ys,n),i(e,je,n),i(e,fs,n),i(e,we,n),i(e,js,n),y(Ue,e,n),i(e,ws,n),i(e,ze,n),Us=!0},p(e,[n]){const bl={};n&1&&(bl.fw=e[0]),t.$set(bl);let Js=T;T=sl(e),T!==Js&&(B(),M(Je[Js],1,1,()=>{Je[Js]=null}),X(),k=Je[T],k||(k=Je[T]=el[T](e),k.c()),c(k,1),k.m(Ze.parentNode,Ze));let Ts=_;_=tl(e),_!==Ts&&(B(),M(Te[Ts],1,1,()=>{Te[Ts]=null}),X(),g=Te[_],g||(g=Te[_]=ll[_](e),g.c()),c(g,1),g.m(Ce.parentNode,Ce));let ks=$;$=al(e),$!==ks&&(B(),M(ke[ks],1,1,()=>{ke[ks]=null}),X(),I=ke[$],I||(I=ke[$]=nl[$](e),I.c()),c(I,1),I.m(Ne.parentNode,Ne));let _s=A;A=il(e),A!==_s&&(B(),M(_e[_s],1,1,()=>{_e[_s]=null}),X(),Z=_e[A],Z||(Z=_e[A]=pl[A](e),Z.c()),c(Z,1),Z.m(Qe.parentNode,Qe));let gs=C;C=ol(e),C!==gs&&(B(),M(ge[gs],1,1,()=>{ge[gs]=null}),X(),N=ge[C],N||(N=ge[C]=rl[C](e),N.c()),c(N,1),N.m(Ve.parentNode,Ve));let $s=Q;Q=Ml(e),Q!==$s&&(B(),M($e[$s],1,1,()=>{$e[$s]=null}),X(),V=$e[Q],V||(V=$e[Q]=ul[Q](e),V.c()),c(V,1),V.m(We.parentNode,We));const yl={};n&2&&(yl.$$scope={dirty:n,ctx:e}),R.$set(yl);let Is=W;W=ml(e),W!==Is&&(B(),M(Ie[Is],1,1,()=>{Ie[Is]=null}),X(),v=Ie[W],v||(v=Ie[W]=cl[W](e),v.c()),c(v,1),v.m(ve.parentNode,ve));let As=E;E=hl(e),E!==As&&(B(),M(Ae[As],1,1,()=>{Ae[As]=null}),X(),z=Ae[E],z||(z=Ae[E]=dl[E](e),z.c()),c(z,1),z.m(Ee.parentNode,Ee));const fl={};n&2&&(fl.$$scope={dirty:n,ctx:e}),G.$set(fl)},i(e){Us||(c(t.$$.fragment,e),c(D.$$.fragment,e),c(k),c(g),c(S.$$.fragment,e),c(I),c(Z),c(N),c(V),c(ee.$$.fragment,e),c(R.$$.fragment,e),c(te.$$.fragment,e),c(ae.$$.fragment,e),c(ie.$$.fragment,e),c(v),c(Me.$$.fragment,e),c(z),c(G.$$.fragment,e),c(be.$$.fragment,e),c(Ue.$$.fragment,e),Us=!0)},o(e){M(t.$$.fragment,e),M(D.$$.fragment,e),M(k),M(g),M(S.$$.fragment,e),M(I),M(Z),M(N),M(V),M(ee.$$.fragment,e),M(R.$$.fragment,e),M(te.$$.fragment,e),M(ae.$$.fragment,e),M(ie.$$.fragment,e),M(v),M(Me.$$.fragment,e),M(z),M(G.$$.fragment,e),M(be.$$.fragment,e),M(Ue.$$.fragment,e),Us=!1},d(e){e&&(p(a),p(s),p(r),p(d),p(Ge),p(Ze),p(Ce),p(H),p(Xe),p(x),p(Be),p(F),p(De),p(He),p(Y),p(xe),p(Ne),p(q),p(Fe),p(L),p(Se),p(Qe),p(K),p(Ye),p(Ve),p(P),p(qe),p(We),p(O),p(Le),p(Ke),p(se),p(Pe),p(Oe),p(le),p(es),p(ss),p(ne),p(ls),p(ts),p(pe),p(ns),p(as),p(re),p(ps),p(ve),p(oe),p(is),p(ue),p(rs),p(os),p(ce),p(us),p(me),p(Ms),p(Ee),p(de),p(cs),p(he),p(ms),p(ds),p(hs),p(ye),p(bs),p(fe),p(ys),p(je),p(fs),p(we),p(js),p(ws),p(ze)),p(l),f(t,e),f(D,e),Je[T].d(e),Te[_].d(e),f(S,e),ke[$].d(e),_e[A].d(e),ge[C].d(e),$e[Q].d(e),f(ee,e),f(R,e),f(te,e),f(ae,e),f(ie,e),Ie[W].d(e),f(Me,e),Ae[E].d(e),f(G,e),f(be,e),f(Ue,e)}}}const Kl='{"title":"Handling multiple sequences","local":"handling-multiple-sequences","sections":[{"title":"Models expect a batch of inputs","local":"models-expect-a-batch-of-inputs","sections":[],"depth":2},{"title":"Padding the inputs","local":"padding-the-inputs","sections":[],"depth":2},{"title":"Attention masks","local":"attention-masks","sections":[],"depth":2},{"title":"Longer sequences","local":"longer-sequences","sections":[],"depth":2}],"depth":1}';function Pl(m,l,a){let s="pt";return gl(()=>{const r=new URLSearchParams(window.location.search);a(0,s=r.get("fw")||"pt")}),[s]}class it extends $l{constructor(l){super(),Il(this,l,Pl,Ll,_l,{})}}export{it as component};
