import{s as $l,o as Il,n as kl}from"../chunks/scheduler.37c15a92.js";import{S as Al,i as Zl,g as j,s as o,r as b,A as Cl,h as w,f as p,c as u,j as Ul,u as h,x as U,k as Jl,y as Nl,a as i,v as d,t as M,b as X,d as c,w as f,p as B}from"../chunks/index.7cb9c9b8.js";import{T as Tl}from"../chunks/Tip.d10b3fc9.js";import{Y as _l}from"../chunks/Youtube.8666c400.js";import{C as J}from"../chunks/CodeBlock.abae2786.js";import{C as gl}from"../chunks/CourseFloatingBanner.df82c153.js";import{F as Ql}from"../chunks/FrameworkSwitchCourse.97630871.js";import{H as Ge,E as Vl}from"../chunks/index.c99deea2.js";function Wl(m){let l,a;return l=new gl({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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 El(m){let l,a;return l=new gl({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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 _l({props:{id:"ROxrFOEbsQE"}}),{c(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 zl(m){let l,a;return l=new _l({props:{id:"M6adb1j2jPI"}}),{c(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 Rl(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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,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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Xl(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Bl(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Dl(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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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;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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 Fl(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(){b(l.$$.fragment)},l(s){h(l.$$.fragment,s)},m(s,r){d(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 Sl(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:kl,d(s){s&&p(l)}}}function Yl(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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,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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Ll(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Kl(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(){b(l.$$.fragment),a=o(),b(s.$$.fragment)},l(t){h(l.$$.fragment,t),a=u(t),h(s.$$.fragment,t)},m(t,y){d(l,t,y),i(t,a,y),d(s,t,y),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 Pl(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:kl,d(s){s&&p(l)}}}function Ol(m){let l,a,s,r,t,y,D,Xe,T,k,Ce,_,g,Ne,x,Ns="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:",Be,H,Qs="<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>",De,F,Vs="Let’s see what kinds of problems these questions pose, and how we can solve them using the 🤗 Transformers API.",xe,S,He,Y,Ws="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:",Fe,$,I,Qe,q,Es="Oh no! Why did this fail? We followed the steps from the pipeline in section 2.",Se,L,vs="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:",Ye,A,Z,Ve,K,zs="Let’s try again and add a new dimension:",qe,C,N,We,P,Rs="We print the input IDs as well as the resulting logits — here’s the output:",Le,Q,V,Ee,O,Gs="<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:",Ke,ee,Pe,se,Xs="This is a batch of two identical sequences!",Oe,R,es,le,Bs="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.",ss,te,ls,ne,Ds="The following list of lists cannot be converted to a tensor:",ts,ae,ns,pe,xs="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:",as,ie,ps,re,Hs="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:",is,W,E,ve,oe,Fs="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!",rs,ue,Ss="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.",os,Me,us,ce,Ys="<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).",Ms,me,qs="Let’s complete the previous example with an attention mask:",cs,v,z,ze,be,Ls="Now we get the same logits for the second sentence in the batch.",ms,he,Ks="Notice how the last value of the second sequence is a padding ID, which is a 0 value in the attention mask.",bs,G,hs,de,ds,fe,Ps="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:",fs,ye,Os="<li>Use a model with a longer supported sequence length.</li> <li>Truncate your sequences.</li>",ys,je,el='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.',js,we,sl="Otherwise, we recommend you truncate your sequences by specifying the <code>max_sequence_length</code> parameter:",ws,Ue,Us,Je,Js,Re,Ts;t=new Ql({props:{fw:m[0]}}),D=new Ge({props:{title:"Handling multiple sequences",local:"handling-multiple-sequences",headingTag:"h1"}});const ll=[El,Wl],Te=[];function tl(e,n){return e[0]==="pt"?0:1}T=tl(m),k=Te[T]=ll[T](m);const nl=[zl,vl],ke=[];function al(e,n){return e[0]==="pt"?0:1}_=al(m),g=ke[_]=nl[_](m),S=new Ge({props:{title:"Models expect a batch of inputs",local:"models-expect-a-batch-of-inputs",headingTag:"h2"}});const pl=[Gl,Rl],_e=[];function il(e,n){return e[0]==="pt"?0:1}$=il(m),I=_e[$]=pl[$](m);const rl=[Bl,Xl],ge=[];function ol(e,n){return e[0]==="pt"?0:1}A=ol(m),Z=ge[A]=rl[A](m);const ul=[xl,Dl],$e=[];function Ml(e,n){return e[0]==="pt"?0:1}C=Ml(m),N=$e[C]=ul[C](m);const cl=[Fl,Hl],Ie=[];function ml(e,n){return e[0]==="pt"?0:1}Q=ml(m),V=Ie[Q]=cl[Q](m),ee=new J({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),R=new Tl({props:{$$slots:{default:[Sl]},$$scope:{ctx:m}}}),te=new Ge({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 bl=[ql,Yl],Ae=[];function hl(e,n){return e[0]==="pt"?0:1}W=hl(m),E=Ae[W]=bl[W](m),Me=new Ge({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const dl=[Kl,Ll],Ze=[];function fl(e,n){return e[0]==="pt"?0:1}return v=fl(m),z=Ze[v]=dl[v](m),G=new Tl({props:{$$slots:{default:[Pl]},$$scope:{ctx:m}}}),de=new Ge({props:{title:"Longer sequences",local:"longer-sequences",headingTag:"h2"}}),Ue=new J({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),Je=new Vl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter2/5.mdx"}}),{c(){l=j("meta"),a=o(),s=j("p"),r=o(),b(t.$$.fragment),y=o(),b(D.$$.fragment),Xe=o(),k.c(),Ce=o(),g.c(),Ne=o(),x=j("p"),x.textContent=Ns,Be=o(),H=j("ul"),H.innerHTML=Qs,De=o(),F=j("p"),F.textContent=Vs,xe=o(),b(S.$$.fragment),He=o(),Y=j("p"),Y.textContent=Ws,Fe=o(),I.c(),Qe=o(),q=j("p"),q.textContent=Es,Se=o(),L=j("p"),L.innerHTML=vs,Ye=o(),Z.c(),Ve=o(),K=j("p"),K.textContent=zs,qe=o(),N.c(),We=o(),P=j("p"),P.textContent=Rs,Le=o(),V.c(),Ee=o(),O=j("p"),O.innerHTML=Gs,Ke=o(),b(ee.$$.fragment),Pe=o(),se=j("p"),se.textContent=Xs,Oe=o(),b(R.$$.fragment),es=o(),le=j("p"),le.innerHTML=Bs,ss=o(),b(te.$$.fragment),ls=o(),ne=j("p"),ne.textContent=Ds,ts=o(),b(ae.$$.fragment),ns=o(),pe=j("p"),pe.innerHTML=xs,as=o(),b(ie.$$.fragment),ps=o(),re=j("p"),re.innerHTML=Hs,is=o(),E.c(),ve=o(),oe=j("p"),oe.textContent=Fs,rs=o(),ue=j("p"),ue.innerHTML=Ss,os=o(),b(Me.$$.fragment),us=o(),ce=j("p"),ce.innerHTML=Ys,Ms=o(),me=j("p"),me.textContent=qs,cs=o(),z.c(),ze=o(),be=j("p"),be.textContent=Ls,ms=o(),he=j("p"),he.textContent=Ks,bs=o(),b(G.$$.fragment),hs=o(),b(de.$$.fragment),ds=o(),fe=j("p"),fe.textContent=Ps,fs=o(),ye=j("ul"),ye.innerHTML=Os,ys=o(),je=j("p"),je.innerHTML=el,js=o(),we=j("p"),we.innerHTML=sl,ws=o(),b(Ue.$$.fragment),Us=o(),b(Je.$$.fragment),Js=o(),Re=j("p"),this.h()},l(e){const n=Cl("svelte-u9bgzb",document.head);l=w(n,"META",{name:!0,content:!0}),n.forEach(p),a=u(e),s=w(e,"P",{}),Ul(s).forEach(p),r=u(e),h(t.$$.fragment,e),y=u(e),h(D.$$.fragment,e),Xe=u(e),k.l(e),Ce=u(e),g.l(e),Ne=u(e),x=w(e,"P",{"data-svelte-h":!0}),U(x)!=="svelte-11tri8y"&&(x.textContent=Ns),Be=u(e),H=w(e,"UL",{"data-svelte-h":!0}),U(H)!=="svelte-10g4d7v"&&(H.innerHTML=Qs),De=u(e),F=w(e,"P",{"data-svelte-h":!0}),U(F)!=="svelte-1m7g6xt"&&(F.textContent=Vs),xe=u(e),h(S.$$.fragment,e),He=u(e),Y=w(e,"P",{"data-svelte-h":!0}),U(Y)!=="svelte-13avqtg"&&(Y.textContent=Ws),Fe=u(e),I.l(e),Qe=u(e),q=w(e,"P",{"data-svelte-h":!0}),U(q)!=="svelte-qckt4g"&&(q.textContent=Es),Se=u(e),L=w(e,"P",{"data-svelte-h":!0}),U(L)!=="svelte-1qp650b"&&(L.innerHTML=vs),Ye=u(e),Z.l(e),Ve=u(e),K=w(e,"P",{"data-svelte-h":!0}),U(K)!=="svelte-140p9gl"&&(K.textContent=zs),qe=u(e),N.l(e),We=u(e),P=w(e,"P",{"data-svelte-h":!0}),U(P)!=="svelte-1tdkgla"&&(P.textContent=Rs),Le=u(e),V.l(e),Ee=u(e),O=w(e,"P",{"data-svelte-h":!0}),U(O)!=="svelte-1qemevg"&&(O.innerHTML=Gs),Ke=u(e),h(ee.$$.fragment,e),Pe=u(e),se=w(e,"P",{"data-svelte-h":!0}),U(se)!=="svelte-y799te"&&(se.textContent=Xs),Oe=u(e),h(R.$$.fragment,e),es=u(e),le=w(e,"P",{"data-svelte-h":!0}),U(le)!=="svelte-cbff1h"&&(le.innerHTML=Bs),ss=u(e),h(te.$$.fragment,e),ls=u(e),ne=w(e,"P",{"data-svelte-h":!0}),U(ne)!=="svelte-1vhszdz"&&(ne.textContent=Ds),ts=u(e),h(ae.$$.fragment,e),ns=u(e),pe=w(e,"P",{"data-svelte-h":!0}),U(pe)!=="svelte-tabns3"&&(pe.innerHTML=xs),as=u(e),h(ie.$$.fragment,e),ps=u(e),re=w(e,"P",{"data-svelte-h":!0}),U(re)!=="svelte-1tifusi"&&(re.innerHTML=Hs),is=u(e),E.l(e),ve=u(e),oe=w(e,"P",{"data-svelte-h":!0}),U(oe)!=="svelte-wwgzh3"&&(oe.textContent=Fs),rs=u(e),ue=w(e,"P",{"data-svelte-h":!0}),U(ue)!=="svelte-tjy5dt"&&(ue.innerHTML=Ss),os=u(e),h(Me.$$.fragment,e),us=u(e),ce=w(e,"P",{"data-svelte-h":!0}),U(ce)!=="svelte-102hkoc"&&(ce.innerHTML=Ys),Ms=u(e),me=w(e,"P",{"data-svelte-h":!0}),U(me)!=="svelte-1pxdg9d"&&(me.textContent=qs),cs=u(e),z.l(e),ze=u(e),be=w(e,"P",{"data-svelte-h":!0}),U(be)!=="svelte-1r7a38q"&&(be.textContent=Ls),ms=u(e),he=w(e,"P",{"data-svelte-h":!0}),U(he)!=="svelte-le11td"&&(he.textContent=Ks),bs=u(e),h(G.$$.fragment,e),hs=u(e),h(de.$$.fragment,e),ds=u(e),fe=w(e,"P",{"data-svelte-h":!0}),U(fe)!=="svelte-j7vz7j"&&(fe.textContent=Ps),fs=u(e),ye=w(e,"UL",{"data-svelte-h":!0}),U(ye)!=="svelte-fx4oon"&&(ye.innerHTML=Os),ys=u(e),je=w(e,"P",{"data-svelte-h":!0}),U(je)!=="svelte-o1zbju"&&(je.innerHTML=el),js=u(e),we=w(e,"P",{"data-svelte-h":!0}),U(we)!=="svelte-mh7f9s"&&(we.innerHTML=sl),ws=u(e),h(Ue.$$.fragment,e),Us=u(e),h(Je.$$.fragment,e),Js=u(e),Re=w(e,"P",{}),Ul(Re).forEach(p),this.h()},h(){Jl(l,"name","hf:doc:metadata"),Jl(l,"content",et)},m(e,n){Nl(document.head,l),i(e,a,n),i(e,s,n),i(e,r,n),d(t,e,n),i(e,y,n),d(D,e,n),i(e,Xe,n),Te[T].m(e,n),i(e,Ce,n),ke[_].m(e,n),i(e,Ne,n),i(e,x,n),i(e,Be,n),i(e,H,n),i(e,De,n),i(e,F,n),i(e,xe,n),d(S,e,n),i(e,He,n),i(e,Y,n),i(e,Fe,n),_e[$].m(e,n),i(e,Qe,n),i(e,q,n),i(e,Se,n),i(e,L,n),i(e,Ye,n),ge[A].m(e,n),i(e,Ve,n),i(e,K,n),i(e,qe,n),$e[C].m(e,n),i(e,We,n),i(e,P,n),i(e,Le,n),Ie[Q].m(e,n),i(e,Ee,n),i(e,O,n),i(e,Ke,n),d(ee,e,n),i(e,Pe,n),i(e,se,n),i(e,Oe,n),d(R,e,n),i(e,es,n),i(e,le,n),i(e,ss,n),d(te,e,n),i(e,ls,n),i(e,ne,n),i(e,ts,n),d(ae,e,n),i(e,ns,n),i(e,pe,n),i(e,as,n),d(ie,e,n),i(e,ps,n),i(e,re,n),i(e,is,n),Ae[W].m(e,n),i(e,ve,n),i(e,oe,n),i(e,rs,n),i(e,ue,n),i(e,os,n),d(Me,e,n),i(e,us,n),i(e,ce,n),i(e,Ms,n),i(e,me,n),i(e,cs,n),Ze[v].m(e,n),i(e,ze,n),i(e,be,n),i(e,ms,n),i(e,he,n),i(e,bs,n),d(G,e,n),i(e,hs,n),d(de,e,n),i(e,ds,n),i(e,fe,n),i(e,fs,n),i(e,ye,n),i(e,ys,n),i(e,je,n),i(e,js,n),i(e,we,n),i(e,ws,n),d(Ue,e,n),i(e,Us,n),d(Je,e,n),i(e,Js,n),i(e,Re,n),Ts=!0},p(e,[n]){const yl={};n&1&&(yl.fw=e[0]),t.$set(yl);let ks=T;T=tl(e),T!==ks&&(B(),M(Te[ks],1,1,()=>{Te[ks]=null}),X(),k=Te[T],k||(k=Te[T]=ll[T](e),k.c()),c(k,1),k.m(Ce.parentNode,Ce));let _s=_;_=al(e),_!==_s&&(B(),M(ke[_s],1,1,()=>{ke[_s]=null}),X(),g=ke[_],g||(g=ke[_]=nl[_](e),g.c()),c(g,1),g.m(Ne.parentNode,Ne));let gs=$;$=il(e),$!==gs&&(B(),M(_e[gs],1,1,()=>{_e[gs]=null}),X(),I=_e[$],I||(I=_e[$]=pl[$](e),I.c()),c(I,1),I.m(Qe.parentNode,Qe));let $s=A;A=ol(e),A!==$s&&(B(),M(ge[$s],1,1,()=>{ge[$s]=null}),X(),Z=ge[A],Z||(Z=ge[A]=rl[A](e),Z.c()),c(Z,1),Z.m(Ve.parentNode,Ve));let Is=C;C=Ml(e),C!==Is&&(B(),M($e[Is],1,1,()=>{$e[Is]=null}),X(),N=$e[C],N||(N=$e[C]=ul[C](e),N.c()),c(N,1),N.m(We.parentNode,We));let As=Q;Q=ml(e),Q!==As&&(B(),M(Ie[As],1,1,()=>{Ie[As]=null}),X(),V=Ie[Q],V||(V=Ie[Q]=cl[Q](e),V.c()),c(V,1),V.m(Ee.parentNode,Ee));const jl={};n&2&&(jl.$$scope={dirty:n,ctx:e}),R.$set(jl);let Zs=W;W=hl(e),W!==Zs&&(B(),M(Ae[Zs],1,1,()=>{Ae[Zs]=null}),X(),E=Ae[W],E||(E=Ae[W]=bl[W](e),E.c()),c(E,1),E.m(ve.parentNode,ve));let Cs=v;v=fl(e),v!==Cs&&(B(),M(Ze[Cs],1,1,()=>{Ze[Cs]=null}),X(),z=Ze[v],z||(z=Ze[v]=dl[v](e),z.c()),c(z,1),z.m(ze.parentNode,ze));const wl={};n&2&&(wl.$$scope={dirty:n,ctx:e}),G.$set(wl)},i(e){Ts||(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(E),c(Me.$$.fragment,e),c(z),c(G.$$.fragment,e),c(de.$$.fragment,e),c(Ue.$$.fragment,e),c(Je.$$.fragment,e),Ts=!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(E),M(Me.$$.fragment,e),M(z),M(G.$$.fragment,e),M(de.$$.fragment,e),M(Ue.$$.fragment,e),M(Je.$$.fragment,e),Ts=!1},d(e){e&&(p(a),p(s),p(r),p(y),p(Xe),p(Ce),p(Ne),p(x),p(Be),p(H),p(De),p(F),p(xe),p(He),p(Y),p(Fe),p(Qe),p(q),p(Se),p(L),p(Ye),p(Ve),p(K),p(qe),p(We),p(P),p(Le),p(Ee),p(O),p(Ke),p(Pe),p(se),p(Oe),p(es),p(le),p(ss),p(ls),p(ne),p(ts),p(ns),p(pe),p(as),p(ps),p(re),p(is),p(ve),p(oe),p(rs),p(ue),p(os),p(us),p(ce),p(Ms),p(me),p(cs),p(ze),p(be),p(ms),p(he),p(bs),p(hs),p(ds),p(fe),p(fs),p(ye),p(ys),p(je),p(js),p(we),p(ws),p(Us),p(Js),p(Re)),p(l),f(t,e),f(D,e),Te[T].d(e),ke[_].d(e),f(S,e),_e[$].d(e),ge[A].d(e),$e[C].d(e),Ie[Q].d(e),f(ee,e),f(R,e),f(te,e),f(ae,e),f(ie,e),Ae[W].d(e),f(Me,e),Ze[v].d(e),f(G,e),f(de,e),f(Ue,e),f(Je,e)}}}const et='{"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 st(m,l,a){let s="pt";return Il(()=>{const r=new URLSearchParams(window.location.search);a(0,s=r.get("fw")||"pt")}),[s]}class ut extends Al{constructor(l){super(),Zl(this,l,st,Ol,$l,{})}}export{ut as component};
