import{s as Il,o as gl,n as kl}from"../chunks/scheduler.37c15a92.js";import{S as Al,i as Cl,g as U,s as i,r as d,A as Zl,h as J,f as o,c as m,j as hl,u as b,x as h,k as Tl,y as Nl,a as r,v as j,t as u,b as X,d as c,w as f,p as B}from"../chunks/index.2bf4358c.js";import{T as wl}from"../chunks/Tip.363c041f.js";import{Y as _l}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4e987730.js";import{C as $l}from"../chunks/CourseFloatingBanner.6add7356.js";import{F as Ql}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ge,E as vl}from"../chunks/getInferenceSnippets.80a69898.js";function Vl(M){let l,t;return l=new $l({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/pt/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/pt/chapter2/section5_tf.ipynb"}]}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function zl(M){let l,t;return l=new $l({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/pt/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/pt/chapter2/section5_pt.ipynb"}]}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function El(M){let l,t;return l=new _l({props:{id:"ROxrFOEbsQE"}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function Wl(M){let l,t;return l=new _l({props:{id:"M6adb1j2jPI"}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function Rl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Gl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Xl(M){let l,t,s,p;return l=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:"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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Bl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Dl(M){let l,t;return l=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(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function ql(M){let l,t;return l=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(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function xl(M){let l,t;return l=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(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function Fl(M){let l,t;return l=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(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,p){j(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){f(l,s)}}}function Hl(M){let l,t="✏️ <strong>Experimente!</strong> Converta esta lista de <code>batched_ids</code> em um tensor e passe-a através de seu modelo. Verifique se você obtém os mesmos logits que antes (mas duas vezes)!";return{c(){l=U("p"),l.innerHTML=t},l(s){l=J(s,"P",{"data-svelte-h":!0}),h(l)!=="svelte-wjw746"&&(l.innerHTML=t)},m(s,p){r(s,l,p)},p:kl,d(s){s&&o(l)}}}function Sl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Yl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Ll(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Kl(M){let l,t,s,p;return l=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(){d(l.$$.fragment),t=i(),d(s.$$.fragment)},l(a){b(l.$$.fragment,a),t=m(a),b(s.$$.fragment,a)},m(a,y){j(l,a,y),r(a,t,y),j(s,a,y),p=!0},i(a){p||(c(l.$$.fragment,a),c(s.$$.fragment,a),p=!0)},o(a){u(l.$$.fragment,a),u(s.$$.fragment,a),p=!1},d(a){a&&o(t),f(l,a),f(s,a)}}}function Pl(M){let l,t="✏️ <strong>Experimente!</strong> Aplique a tokenização manualmente nas duas frases usadas na seção 2 (“I’ve been waiting for a HuggingFace course my whole life.” e “I hate this so much!”). Passe-as através do modelo e verifique se você obtém os mesmos logits que na seção 2. Agora, agrupe-os usando o token de padding e depois crie a máscara de atenção adequada. Verifique que você obtenha os mesmos resultados ao passar pelo modelo!";return{c(){l=U("p"),l.innerHTML=t},l(s){l=J(s,"P",{"data-svelte-h":!0}),h(l)!=="svelte-1s4zknu"&&(l.innerHTML=t)},m(s,p){r(s,l,p)},p:kl,d(s){s&&o(l)}}}function Ol(M){let l,t,s,p,a,y,D,Xe,w,k,Ze,_,$,Ne,q,Ns="Na seção anterior, exploramos os casos mais simples de uso: fazer inferência sobre uma única sequência de pequeno comprimento. No entanto, surgem algumas questões:",Be,x,Qs="<li>Como nós tratamos diversas sequências?</li> <li>Como nós tratamos diversas sequências <em>de diferentes tamanhos</em>?</li> <li>Os índices de vocabulário são as únicas entradas que permitem que um modelo funcione bem?</li> <li>Existe uma sequência muito longa?</li>",De,F,vs="Vamos ver que tipos de problemas estas questões colocam, e como podemos resolvê-los usando a API do 🤗 Transformers.",qe,H,xe,S,Vs="No exercício anterior, você viu como as sequências são traduzidas em listas de números. Vamos converter esta lista de números em um tensor e enviá-la para o modelo:",Fe,I,g,Qe,Y,zs="Oh não! Por que isso falhou? “Seguimos os passos do pipeline na seção 2.",He,L,Es="O problema é que enviamos uma única sequência para o modelo, enquanto que os 🤗 transformers esperam várias sentenças por padrão. Aqui tentamos fazer tudo o que o tokenizer fez nos bastidores quando o aplicamos a uma <code>sequência</code>, mas se você olhar com atenção, verá que ele não apenas converteu a lista de IDs de entrada em um tensor, mas acrescentou uma dimensão em cima dele:",Se,A,C,ve,K,Ws="Vamos tentar novamente e acrescentar uma nova dimensão:",Ye,Z,N,Ve,P,Rs="Printamos os IDs de entrada assim como os logits resultantes - aqui está a saída:",Le,Q,v,ze,O,Gs="<em>Batching</em> é o ato de enviar múltiplas sentenças através do modelo, todas de uma só vez. Se você tiver apenas uma frase, você pode apenas construir um lote com uma única sequência:",Ke,ee,Pe,se,Xs="Este é um lote de duas sequências idênticas!",Oe,R,es,le,Bs="O Batching permite que o modelo funcione quando você o alimenta com várias frases. Usar várias sequências é tão simples quanto construir um lote com uma única sequência. Há uma segunda questão, no entanto. Quando você está tentando agrupar duas (ou mais) sentenças, elas podem ser de comprimentos diferentes. Se você já trabalhou com tensores antes, você sabe que eles precisam ser de forma retangular, então você não será capaz de converter a lista de IDs de entrada em um tensor diretamente. Para contornar este problema, normalmente realizamos uma <em>padronização</em> (padding) nas entradas.",ss,ae,ls,ne,Ds="A seguinte lista de listas não pode ser convertida em um tensor:",as,te,ns,oe,qs="Para contornar isso, usaremos <em>padding</em> para fazer com que nossos tensores tenham uma forma retangular. O padding garante que todas as nossas frases tenham o mesmo comprimento, acrescentando uma palavra especial chamada <em>padding token</em> às frases com menos valores. Por exemplo, se você tiver 10 frases com 10 palavras e 1 frase com 20 palavras, o padding garantirá que todas as frases tenham 20 palavras. Em nosso exemplo, o tensor resultante se parece com isto:",ts,re,os,pe,xs="O padding do ID token pode ser encontrada em <code>tokenizer.pad_token_id</code>. Vamos utilizá-lo e enviar nossas duas frases através do modelo individualmente e agrupadas em batches:",rs,V,z,Ee,ie,Fs="Há algo errado com os logits em nossas predições em batches: a segunda fileira deveria ser a mesma que os logits para a segunda frase, mas temos valores completamente diferentes!",ps,me,Hs="Isto porque a característica chave dos Transformer são as camadas de atenção que <em>contextualizam</em> cada token. Estes levarão em conta os tokens de padding, uma vez que atendem a todos os tokens de uma sequência. Para obter o mesmo resultado ao passar frases individuais de diferentes comprimentos pelo modelo ou ao passar um batch com as mesmas frases e os paddings aplicados, precisamos dizer a essas camadas de atenção para ignorar os tokens de padding. Isto é feito com o uso de uma máscara de atenção (<em>attention mask</em>).",is,ue,ms,ce,Ss="<em>Attention masks</em> são tensores com a mesma forma exata do tensor de IDs de entrada, preenchidos com 0s e 1s: 1s indicam que os tokens correspondentes devem ser atendidas, e 0s indicam que os tokens correspondentes não devem ser atendidas (ou seja, devem ser ignoradas pelas camadas de atenção do modelo).",us,Me,Ys="Vamos completar o exemplo anterior com uma máscara de atenção:",cs,E,W,We,de,Ls="Agora obtemos os mesmos logits para a segunda frase do batch.",Ms,be,Ks="Observe como o último valor da segunda sequência é um ID de padding, que é um valor 0 na máscara de atenção.",ds,G,bs,je,js,fe,Ps="Com os Transformer, há um limite para os comprimentos das sequências, podemos passar os modelos. A maioria dos modelos manipula sequências de até 512 ou 1024 tokens, e se chocará quando solicitados a processar sequências mais longas. Há duas soluções para este problema:",fs,ye,Os="<li>Use um modelo com suporte a um comprimento mais longo de sequência.</li> <li>Trunque suas sequências.</li>",ys,Ue,el='Os modelos têm diferentes comprimentos de sequência suportados, e alguns são especializados no tratamento de sequências muito longas. O <a href="https://huggingface.co/transformers/model_doc/longformer.html" rel="nofollow">Longformer</a> é um exemplo, e outro exemplo é o <a href="https://huggingface.co/transformers/model_doc/led.html" rel="nofollow">LED</a>. Se você estiver trabalhando em uma tarefa que requer sequências muito longas, recomendamos que você dê uma olhada nesses modelos.',Us,Je,sl="Caso contrário, recomendamos que você trunque suas sequências, especificando o parâmetro <code>max_sequence_length</code>:",Js,he,hs,Te,Ts,Re,ws;a=new Ql({props:{fw:M[0]}}),D=new Ge({props:{title:"Tratando sequências múltiplas",local:"tratando-sequências-múltiplas",headingTag:"h1"}});const ll=[zl,Vl],we=[];function al(e,n){return e[0]==="pt"?0:1}w=al(M),k=we[w]=ll[w](M);const nl=[Wl,El],ke=[];function tl(e,n){return e[0]==="pt"?0:1}_=tl(M),$=ke[_]=nl[_](M),H=new Ge({props:{title:"Modelos esperam um batch de entradas",local:"modelos-esperam-um-batch-de-entradas",headingTag:"h2"}});const ol=[Gl,Rl],_e=[];function rl(e,n){return e[0]==="pt"?0:1}I=rl(M),g=_e[I]=ol[I](M);const pl=[Bl,Xl],$e=[];function il(e,n){return e[0]==="pt"?0:1}A=il(M),C=$e[A]=pl[A](M);const ml=[ql,Dl],Ie=[];function ul(e,n){return e[0]==="pt"?0:1}Z=ul(M),N=Ie[Z]=ml[Z](M);const cl=[Fl,xl],ge=[];function Ml(e,n){return e[0]==="pt"?0:1}Q=Ml(M),v=ge[Q]=cl[Q](M),ee=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),R=new wl({props:{$$slots:{default:[Hl]},$$scope:{ctx:M}}}),ae=new Ge({props:{title:"Realizando padding nas entradas",local:"realizando-padding-nas-entradas",headingTag:"h2"}}),te=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}}),re=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 dl=[Yl,Sl],Ae=[];function bl(e,n){return e[0]==="pt"?0:1}V=bl(M),z=Ae[V]=dl[V](M),ue=new Ge({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const jl=[Kl,Ll],Ce=[];function fl(e,n){return e[0]==="pt"?0:1}return E=fl(M),W=Ce[E]=jl[E](M),G=new wl({props:{$$slots:{default:[Pl]},$$scope:{ctx:M}}}),je=new Ge({props:{title:"Sequências mais longas",local:"sequências-mais-longas",headingTag:"h2"}}),he=new T({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),Te=new vl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/pt/chapter2/5.mdx"}}),{c(){l=U("meta"),t=i(),s=U("p"),p=i(),d(a.$$.fragment),y=i(),d(D.$$.fragment),Xe=i(),k.c(),Ze=i(),$.c(),Ne=i(),q=U("p"),q.textContent=Ns,Be=i(),x=U("ul"),x.innerHTML=Qs,De=i(),F=U("p"),F.textContent=vs,qe=i(),d(H.$$.fragment),xe=i(),S=U("p"),S.textContent=Vs,Fe=i(),g.c(),Qe=i(),Y=U("p"),Y.textContent=zs,He=i(),L=U("p"),L.innerHTML=Es,Se=i(),C.c(),ve=i(),K=U("p"),K.textContent=Ws,Ye=i(),N.c(),Ve=i(),P=U("p"),P.textContent=Rs,Le=i(),v.c(),ze=i(),O=U("p"),O.innerHTML=Gs,Ke=i(),d(ee.$$.fragment),Pe=i(),se=U("p"),se.textContent=Xs,Oe=i(),d(R.$$.fragment),es=i(),le=U("p"),le.innerHTML=Bs,ss=i(),d(ae.$$.fragment),ls=i(),ne=U("p"),ne.textContent=Ds,as=i(),d(te.$$.fragment),ns=i(),oe=U("p"),oe.innerHTML=qs,ts=i(),d(re.$$.fragment),os=i(),pe=U("p"),pe.innerHTML=xs,rs=i(),z.c(),Ee=i(),ie=U("p"),ie.textContent=Fs,ps=i(),me=U("p"),me.innerHTML=Hs,is=i(),d(ue.$$.fragment),ms=i(),ce=U("p"),ce.innerHTML=Ss,us=i(),Me=U("p"),Me.textContent=Ys,cs=i(),W.c(),We=i(),de=U("p"),de.textContent=Ls,Ms=i(),be=U("p"),be.textContent=Ks,ds=i(),d(G.$$.fragment),bs=i(),d(je.$$.fragment),js=i(),fe=U("p"),fe.textContent=Ps,fs=i(),ye=U("ul"),ye.innerHTML=Os,ys=i(),Ue=U("p"),Ue.innerHTML=el,Us=i(),Je=U("p"),Je.innerHTML=sl,Js=i(),d(he.$$.fragment),hs=i(),d(Te.$$.fragment),Ts=i(),Re=U("p"),this.h()},l(e){const n=Zl("svelte-u9bgzb",document.head);l=J(n,"META",{name:!0,content:!0}),n.forEach(o),t=m(e),s=J(e,"P",{}),hl(s).forEach(o),p=m(e),b(a.$$.fragment,e),y=m(e),b(D.$$.fragment,e),Xe=m(e),k.l(e),Ze=m(e),$.l(e),Ne=m(e),q=J(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-1vukfd4"&&(q.textContent=Ns),Be=m(e),x=J(e,"UL",{"data-svelte-h":!0}),h(x)!=="svelte-j7p8tt"&&(x.innerHTML=Qs),De=m(e),F=J(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-751i5t"&&(F.textContent=vs),qe=m(e),b(H.$$.fragment,e),xe=m(e),S=J(e,"P",{"data-svelte-h":!0}),h(S)!=="svelte-1pm58du"&&(S.textContent=Vs),Fe=m(e),g.l(e),Qe=m(e),Y=J(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-ml0qp4"&&(Y.textContent=zs),He=m(e),L=J(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-1nj62oy"&&(L.innerHTML=Es),Se=m(e),C.l(e),ve=m(e),K=J(e,"P",{"data-svelte-h":!0}),h(K)!=="svelte-hhxxgw"&&(K.textContent=Ws),Ye=m(e),N.l(e),Ve=m(e),P=J(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-pysvdd"&&(P.textContent=Rs),Le=m(e),v.l(e),ze=m(e),O=J(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-cgucpz"&&(O.innerHTML=Gs),Ke=m(e),b(ee.$$.fragment,e),Pe=m(e),se=J(e,"P",{"data-svelte-h":!0}),h(se)!=="svelte-fwpvl2"&&(se.textContent=Xs),Oe=m(e),b(R.$$.fragment,e),es=m(e),le=J(e,"P",{"data-svelte-h":!0}),h(le)!=="svelte-mb0epl"&&(le.innerHTML=Bs),ss=m(e),b(ae.$$.fragment,e),ls=m(e),ne=J(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-3gjf35"&&(ne.textContent=Ds),as=m(e),b(te.$$.fragment,e),ns=m(e),oe=J(e,"P",{"data-svelte-h":!0}),h(oe)!=="svelte-1gvc7uj"&&(oe.innerHTML=qs),ts=m(e),b(re.$$.fragment,e),os=m(e),pe=J(e,"P",{"data-svelte-h":!0}),h(pe)!=="svelte-ql9arv"&&(pe.innerHTML=xs),rs=m(e),z.l(e),Ee=m(e),ie=J(e,"P",{"data-svelte-h":!0}),h(ie)!=="svelte-1el0zle"&&(ie.textContent=Fs),ps=m(e),me=J(e,"P",{"data-svelte-h":!0}),h(me)!=="svelte-s3o8ck"&&(me.innerHTML=Hs),is=m(e),b(ue.$$.fragment,e),ms=m(e),ce=J(e,"P",{"data-svelte-h":!0}),h(ce)!=="svelte-4mocpk"&&(ce.innerHTML=Ss),us=m(e),Me=J(e,"P",{"data-svelte-h":!0}),h(Me)!=="svelte-99xg22"&&(Me.textContent=Ys),cs=m(e),W.l(e),We=m(e),de=J(e,"P",{"data-svelte-h":!0}),h(de)!=="svelte-1cxqz6z"&&(de.textContent=Ls),Ms=m(e),be=J(e,"P",{"data-svelte-h":!0}),h(be)!=="svelte-1daay4i"&&(be.textContent=Ks),ds=m(e),b(G.$$.fragment,e),bs=m(e),b(je.$$.fragment,e),js=m(e),fe=J(e,"P",{"data-svelte-h":!0}),h(fe)!=="svelte-uv2gxb"&&(fe.textContent=Ps),fs=m(e),ye=J(e,"UL",{"data-svelte-h":!0}),h(ye)!=="svelte-1gcif07"&&(ye.innerHTML=Os),ys=m(e),Ue=J(e,"P",{"data-svelte-h":!0}),h(Ue)!=="svelte-zt63kj"&&(Ue.innerHTML=el),Us=m(e),Je=J(e,"P",{"data-svelte-h":!0}),h(Je)!=="svelte-1ruisxl"&&(Je.innerHTML=sl),Js=m(e),b(he.$$.fragment,e),hs=m(e),b(Te.$$.fragment,e),Ts=m(e),Re=J(e,"P",{}),hl(Re).forEach(o),this.h()},h(){Tl(l,"name","hf:doc:metadata"),Tl(l,"content",ea)},m(e,n){Nl(document.head,l),r(e,t,n),r(e,s,n),r(e,p,n),j(a,e,n),r(e,y,n),j(D,e,n),r(e,Xe,n),we[w].m(e,n),r(e,Ze,n),ke[_].m(e,n),r(e,Ne,n),r(e,q,n),r(e,Be,n),r(e,x,n),r(e,De,n),r(e,F,n),r(e,qe,n),j(H,e,n),r(e,xe,n),r(e,S,n),r(e,Fe,n),_e[I].m(e,n),r(e,Qe,n),r(e,Y,n),r(e,He,n),r(e,L,n),r(e,Se,n),$e[A].m(e,n),r(e,ve,n),r(e,K,n),r(e,Ye,n),Ie[Z].m(e,n),r(e,Ve,n),r(e,P,n),r(e,Le,n),ge[Q].m(e,n),r(e,ze,n),r(e,O,n),r(e,Ke,n),j(ee,e,n),r(e,Pe,n),r(e,se,n),r(e,Oe,n),j(R,e,n),r(e,es,n),r(e,le,n),r(e,ss,n),j(ae,e,n),r(e,ls,n),r(e,ne,n),r(e,as,n),j(te,e,n),r(e,ns,n),r(e,oe,n),r(e,ts,n),j(re,e,n),r(e,os,n),r(e,pe,n),r(e,rs,n),Ae[V].m(e,n),r(e,Ee,n),r(e,ie,n),r(e,ps,n),r(e,me,n),r(e,is,n),j(ue,e,n),r(e,ms,n),r(e,ce,n),r(e,us,n),r(e,Me,n),r(e,cs,n),Ce[E].m(e,n),r(e,We,n),r(e,de,n),r(e,Ms,n),r(e,be,n),r(e,ds,n),j(G,e,n),r(e,bs,n),j(je,e,n),r(e,js,n),r(e,fe,n),r(e,fs,n),r(e,ye,n),r(e,ys,n),r(e,Ue,n),r(e,Us,n),r(e,Je,n),r(e,Js,n),j(he,e,n),r(e,hs,n),j(Te,e,n),r(e,Ts,n),r(e,Re,n),ws=!0},p(e,[n]){const yl={};n&1&&(yl.fw=e[0]),a.$set(yl);let ks=w;w=al(e),w!==ks&&(B(),u(we[ks],1,1,()=>{we[ks]=null}),X(),k=we[w],k||(k=we[w]=ll[w](e),k.c()),c(k,1),k.m(Ze.parentNode,Ze));let _s=_;_=tl(e),_!==_s&&(B(),u(ke[_s],1,1,()=>{ke[_s]=null}),X(),$=ke[_],$||($=ke[_]=nl[_](e),$.c()),c($,1),$.m(Ne.parentNode,Ne));let $s=I;I=rl(e),I!==$s&&(B(),u(_e[$s],1,1,()=>{_e[$s]=null}),X(),g=_e[I],g||(g=_e[I]=ol[I](e),g.c()),c(g,1),g.m(Qe.parentNode,Qe));let Is=A;A=il(e),A!==Is&&(B(),u($e[Is],1,1,()=>{$e[Is]=null}),X(),C=$e[A],C||(C=$e[A]=pl[A](e),C.c()),c(C,1),C.m(ve.parentNode,ve));let gs=Z;Z=ul(e),Z!==gs&&(B(),u(Ie[gs],1,1,()=>{Ie[gs]=null}),X(),N=Ie[Z],N||(N=Ie[Z]=ml[Z](e),N.c()),c(N,1),N.m(Ve.parentNode,Ve));let As=Q;Q=Ml(e),Q!==As&&(B(),u(ge[As],1,1,()=>{ge[As]=null}),X(),v=ge[Q],v||(v=ge[Q]=cl[Q](e),v.c()),c(v,1),v.m(ze.parentNode,ze));const Ul={};n&2&&(Ul.$$scope={dirty:n,ctx:e}),R.$set(Ul);let Cs=V;V=bl(e),V!==Cs&&(B(),u(Ae[Cs],1,1,()=>{Ae[Cs]=null}),X(),z=Ae[V],z||(z=Ae[V]=dl[V](e),z.c()),c(z,1),z.m(Ee.parentNode,Ee));let Zs=E;E=fl(e),E!==Zs&&(B(),u(Ce[Zs],1,1,()=>{Ce[Zs]=null}),X(),W=Ce[E],W||(W=Ce[E]=jl[E](e),W.c()),c(W,1),W.m(We.parentNode,We));const Jl={};n&2&&(Jl.$$scope={dirty:n,ctx:e}),G.$set(Jl)},i(e){ws||(c(a.$$.fragment,e),c(D.$$.fragment,e),c(k),c($),c(H.$$.fragment,e),c(g),c(C),c(N),c(v),c(ee.$$.fragment,e),c(R.$$.fragment,e),c(ae.$$.fragment,e),c(te.$$.fragment,e),c(re.$$.fragment,e),c(z),c(ue.$$.fragment,e),c(W),c(G.$$.fragment,e),c(je.$$.fragment,e),c(he.$$.fragment,e),c(Te.$$.fragment,e),ws=!0)},o(e){u(a.$$.fragment,e),u(D.$$.fragment,e),u(k),u($),u(H.$$.fragment,e),u(g),u(C),u(N),u(v),u(ee.$$.fragment,e),u(R.$$.fragment,e),u(ae.$$.fragment,e),u(te.$$.fragment,e),u(re.$$.fragment,e),u(z),u(ue.$$.fragment,e),u(W),u(G.$$.fragment,e),u(je.$$.fragment,e),u(he.$$.fragment,e),u(Te.$$.fragment,e),ws=!1},d(e){e&&(o(t),o(s),o(p),o(y),o(Xe),o(Ze),o(Ne),o(q),o(Be),o(x),o(De),o(F),o(qe),o(xe),o(S),o(Fe),o(Qe),o(Y),o(He),o(L),o(Se),o(ve),o(K),o(Ye),o(Ve),o(P),o(Le),o(ze),o(O),o(Ke),o(Pe),o(se),o(Oe),o(es),o(le),o(ss),o(ls),o(ne),o(as),o(ns),o(oe),o(ts),o(os),o(pe),o(rs),o(Ee),o(ie),o(ps),o(me),o(is),o(ms),o(ce),o(us),o(Me),o(cs),o(We),o(de),o(Ms),o(be),o(ds),o(bs),o(js),o(fe),o(fs),o(ye),o(ys),o(Ue),o(Us),o(Je),o(Js),o(hs),o(Ts),o(Re)),o(l),f(a,e),f(D,e),we[w].d(e),ke[_].d(e),f(H,e),_e[I].d(e),$e[A].d(e),Ie[Z].d(e),ge[Q].d(e),f(ee,e),f(R,e),f(ae,e),f(te,e),f(re,e),Ae[V].d(e),f(ue,e),Ce[E].d(e),f(G,e),f(je,e),f(he,e),f(Te,e)}}}const ea='{"title":"Tratando sequências múltiplas","local":"tratando-sequências-múltiplas","sections":[{"title":"Modelos esperam um batch de entradas","local":"modelos-esperam-um-batch-de-entradas","sections":[],"depth":2},{"title":"Realizando padding nas entradas","local":"realizando-padding-nas-entradas","sections":[],"depth":2},{"title":"Attention masks","local":"attention-masks","sections":[],"depth":2},{"title":"Sequências mais longas","local":"sequências-mais-longas","sections":[],"depth":2}],"depth":1}';function sa(M,l,t){let s="pt";return gl(()=>{const p=new URLSearchParams(window.location.search);t(0,s=p.get("fw")||"pt")}),[s]}class ma extends Al{constructor(l){super(),Cl(this,l,sa,Ol,Il,{})}}export{ma as component};
