import{s as _l,o as $l,n as Tl}from"../chunks/scheduler.37c15a92.js";import{S as Il,i as gl,g as U,s as i,r as b,A as Al,h as J,f as o,c as m,j as Ul,u as j,x as h,k as Jl,y as Cl,a as r,v as f,t as u,b as X,d as c,w as y,p as B}from"../chunks/index.2bf4358c.js";import{T as hl}from"../chunks/Tip.363c041f.js";import{Y as wl}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as kl}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Zl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Re}from"../chunks/Heading.8ada512a.js";function Nl(M){let l,t;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/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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function Ql(M){let l,t;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/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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function vl(M){let l,t;return l=new wl({props:{id:"ROxrFOEbsQE"}}),{c(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function Vl(M){let l,t;return l=new wl({props:{id:"M6adb1j2jPI"}}),{c(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function zl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function El(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Wl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Rl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Gl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function Xl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function Bl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function Dl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,p){f(l,s,p),t=!0},i(s){t||(c(l.$$.fragment,s),t=!0)},o(s){u(l.$$.fragment,s),t=!1},d(s){y(l,s)}}}function ql(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:Tl,d(s){s&&o(l)}}}function xl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Fl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Hl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Sl(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(){b(l.$$.fragment),t=i(),b(s.$$.fragment)},l(a){j(l.$$.fragment,a),t=m(a),j(s.$$.fragment,a)},m(a,d){f(l,a,d),r(a,t,d),f(s,a,d),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),y(l,a),y(s,a)}}}function Yl(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:Tl,d(s){s&&o(l)}}}function Ll(M){let l,t,s,p,a,d,D,Ge,w,k,Ce,_,$,Ze,q,Cs="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:",Xe,x,Zs="<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>",Be,F,Ns="Vamos ver que tipos de problemas estas questões colocam, e como podemos resolvê-los usando a API do 🤗 Transformers.",De,H,qe,S,Qs="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:",xe,I,g,Ne,Y,vs="Oh não! Por que isso falhou? “Seguimos os passos do pipeline na seção 2.",Fe,L,Vs="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:",He,A,C,Qe,K,zs="Vamos tentar novamente e acrescentar uma nova dimensão:",Se,Z,N,ve,P,Es="Printamos os IDs de entrada assim como os logits resultantes - aqui está a saída:",Ye,Q,v,Ve,O,Ws="<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:",Le,ee,Ke,se,Rs="Este é um lote de duas sequências idênticas!",Pe,R,Oe,le,Gs="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.",es,ae,ss,ne,Xs="A seguinte lista de listas não pode ser convertida em um tensor:",ls,te,as,oe,Bs="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:",ns,re,ts,pe,Ds="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:",os,V,z,ze,ie,qs="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!",rs,me,xs="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>).",ps,ue,is,ce,Fs="<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).",ms,Me,Hs="Vamos completar o exemplo anterior com uma máscara de atenção:",us,E,W,Ee,de,Ss="Agora obtemos os mesmos logits para a segunda frase do batch.",cs,be,Ys="Observe como o último valor da segunda sequência é um ID de padding, que é um valor 0 na máscara de atenção.",Ms,G,ds,je,bs,fe,Ls="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:",js,ye,Ks="<li>Use um modelo com suporte a um comprimento mais longo de sequência.</li> <li>Trunque suas sequências.</li>",fs,Ue,Ps='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.',ys,Je,Os="Caso contrário, recomendamos que você trunque suas sequências, especificando o parâmetro <code>max_sequence_length</code>:",Us,he,Js,We,hs;a=new Zl({props:{fw:M[0]}}),D=new Re({props:{title:"Tratando sequências múltiplas",local:"tratando-sequências-múltiplas",headingTag:"h1"}});const el=[Ql,Nl],Te=[];function sl(e,n){return e[0]==="pt"?0:1}w=sl(M),k=Te[w]=el[w](M);const ll=[Vl,vl],we=[];function al(e,n){return e[0]==="pt"?0:1}_=al(M),$=we[_]=ll[_](M),H=new Re({props:{title:"Modelos esperam um batch de entradas",local:"modelos-esperam-um-batch-de-entradas",headingTag:"h2"}});const nl=[El,zl],ke=[];function tl(e,n){return e[0]==="pt"?0:1}I=tl(M),g=ke[I]=nl[I](M);const ol=[Rl,Wl],_e=[];function rl(e,n){return e[0]==="pt"?0:1}A=rl(M),C=_e[A]=ol[A](M);const pl=[Xl,Gl],$e=[];function il(e,n){return e[0]==="pt"?0:1}Z=il(M),N=$e[Z]=pl[Z](M);const ml=[Dl,Bl],Ie=[];function ul(e,n){return e[0]==="pt"?0:1}Q=ul(M),v=Ie[Q]=ml[Q](M),ee=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),R=new hl({props:{$$slots:{default:[ql]},$$scope:{ctx:M}}}),ae=new Re({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 cl=[Fl,xl],ge=[];function Ml(e,n){return e[0]==="pt"?0:1}V=Ml(M),z=ge[V]=cl[V](M),ue=new Re({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const dl=[Sl,Hl],Ae=[];function bl(e,n){return e[0]==="pt"?0:1}return E=bl(M),W=Ae[E]=dl[E](M),G=new hl({props:{$$slots:{default:[Yl]},$$scope:{ctx:M}}}),je=new Re({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}}),{c(){l=U("meta"),t=i(),s=U("p"),p=i(),b(a.$$.fragment),d=i(),b(D.$$.fragment),Ge=i(),k.c(),Ce=i(),$.c(),Ze=i(),q=U("p"),q.textContent=Cs,Xe=i(),x=U("ul"),x.innerHTML=Zs,Be=i(),F=U("p"),F.textContent=Ns,De=i(),b(H.$$.fragment),qe=i(),S=U("p"),S.textContent=Qs,xe=i(),g.c(),Ne=i(),Y=U("p"),Y.textContent=vs,Fe=i(),L=U("p"),L.innerHTML=Vs,He=i(),C.c(),Qe=i(),K=U("p"),K.textContent=zs,Se=i(),N.c(),ve=i(),P=U("p"),P.textContent=Es,Ye=i(),v.c(),Ve=i(),O=U("p"),O.innerHTML=Ws,Le=i(),b(ee.$$.fragment),Ke=i(),se=U("p"),se.textContent=Rs,Pe=i(),b(R.$$.fragment),Oe=i(),le=U("p"),le.innerHTML=Gs,es=i(),b(ae.$$.fragment),ss=i(),ne=U("p"),ne.textContent=Xs,ls=i(),b(te.$$.fragment),as=i(),oe=U("p"),oe.innerHTML=Bs,ns=i(),b(re.$$.fragment),ts=i(),pe=U("p"),pe.innerHTML=Ds,os=i(),z.c(),ze=i(),ie=U("p"),ie.textContent=qs,rs=i(),me=U("p"),me.innerHTML=xs,ps=i(),b(ue.$$.fragment),is=i(),ce=U("p"),ce.innerHTML=Fs,ms=i(),Me=U("p"),Me.textContent=Hs,us=i(),W.c(),Ee=i(),de=U("p"),de.textContent=Ss,cs=i(),be=U("p"),be.textContent=Ys,Ms=i(),b(G.$$.fragment),ds=i(),b(je.$$.fragment),bs=i(),fe=U("p"),fe.textContent=Ls,js=i(),ye=U("ul"),ye.innerHTML=Ks,fs=i(),Ue=U("p"),Ue.innerHTML=Ps,ys=i(),Je=U("p"),Je.innerHTML=Os,Us=i(),b(he.$$.fragment),Js=i(),We=U("p"),this.h()},l(e){const n=Al("svelte-u9bgzb",document.head);l=J(n,"META",{name:!0,content:!0}),n.forEach(o),t=m(e),s=J(e,"P",{}),Ul(s).forEach(o),p=m(e),j(a.$$.fragment,e),d=m(e),j(D.$$.fragment,e),Ge=m(e),k.l(e),Ce=m(e),$.l(e),Ze=m(e),q=J(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-1vukfd4"&&(q.textContent=Cs),Xe=m(e),x=J(e,"UL",{"data-svelte-h":!0}),h(x)!=="svelte-j7p8tt"&&(x.innerHTML=Zs),Be=m(e),F=J(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-751i5t"&&(F.textContent=Ns),De=m(e),j(H.$$.fragment,e),qe=m(e),S=J(e,"P",{"data-svelte-h":!0}),h(S)!=="svelte-1pm58du"&&(S.textContent=Qs),xe=m(e),g.l(e),Ne=m(e),Y=J(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-ml0qp4"&&(Y.textContent=vs),Fe=m(e),L=J(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-1nj62oy"&&(L.innerHTML=Vs),He=m(e),C.l(e),Qe=m(e),K=J(e,"P",{"data-svelte-h":!0}),h(K)!=="svelte-hhxxgw"&&(K.textContent=zs),Se=m(e),N.l(e),ve=m(e),P=J(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-pysvdd"&&(P.textContent=Es),Ye=m(e),v.l(e),Ve=m(e),O=J(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-cgucpz"&&(O.innerHTML=Ws),Le=m(e),j(ee.$$.fragment,e),Ke=m(e),se=J(e,"P",{"data-svelte-h":!0}),h(se)!=="svelte-fwpvl2"&&(se.textContent=Rs),Pe=m(e),j(R.$$.fragment,e),Oe=m(e),le=J(e,"P",{"data-svelte-h":!0}),h(le)!=="svelte-mb0epl"&&(le.innerHTML=Gs),es=m(e),j(ae.$$.fragment,e),ss=m(e),ne=J(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-3gjf35"&&(ne.textContent=Xs),ls=m(e),j(te.$$.fragment,e),as=m(e),oe=J(e,"P",{"data-svelte-h":!0}),h(oe)!=="svelte-1gvc7uj"&&(oe.innerHTML=Bs),ns=m(e),j(re.$$.fragment,e),ts=m(e),pe=J(e,"P",{"data-svelte-h":!0}),h(pe)!=="svelte-ql9arv"&&(pe.innerHTML=Ds),os=m(e),z.l(e),ze=m(e),ie=J(e,"P",{"data-svelte-h":!0}),h(ie)!=="svelte-1el0zle"&&(ie.textContent=qs),rs=m(e),me=J(e,"P",{"data-svelte-h":!0}),h(me)!=="svelte-s3o8ck"&&(me.innerHTML=xs),ps=m(e),j(ue.$$.fragment,e),is=m(e),ce=J(e,"P",{"data-svelte-h":!0}),h(ce)!=="svelte-4mocpk"&&(ce.innerHTML=Fs),ms=m(e),Me=J(e,"P",{"data-svelte-h":!0}),h(Me)!=="svelte-99xg22"&&(Me.textContent=Hs),us=m(e),W.l(e),Ee=m(e),de=J(e,"P",{"data-svelte-h":!0}),h(de)!=="svelte-1cxqz6z"&&(de.textContent=Ss),cs=m(e),be=J(e,"P",{"data-svelte-h":!0}),h(be)!=="svelte-1daay4i"&&(be.textContent=Ys),Ms=m(e),j(G.$$.fragment,e),ds=m(e),j(je.$$.fragment,e),bs=m(e),fe=J(e,"P",{"data-svelte-h":!0}),h(fe)!=="svelte-uv2gxb"&&(fe.textContent=Ls),js=m(e),ye=J(e,"UL",{"data-svelte-h":!0}),h(ye)!=="svelte-1gcif07"&&(ye.innerHTML=Ks),fs=m(e),Ue=J(e,"P",{"data-svelte-h":!0}),h(Ue)!=="svelte-zt63kj"&&(Ue.innerHTML=Ps),ys=m(e),Je=J(e,"P",{"data-svelte-h":!0}),h(Je)!=="svelte-1ruisxl"&&(Je.innerHTML=Os),Us=m(e),j(he.$$.fragment,e),Js=m(e),We=J(e,"P",{}),Ul(We).forEach(o),this.h()},h(){Jl(l,"name","hf:doc:metadata"),Jl(l,"content",Kl)},m(e,n){Cl(document.head,l),r(e,t,n),r(e,s,n),r(e,p,n),f(a,e,n),r(e,d,n),f(D,e,n),r(e,Ge,n),Te[w].m(e,n),r(e,Ce,n),we[_].m(e,n),r(e,Ze,n),r(e,q,n),r(e,Xe,n),r(e,x,n),r(e,Be,n),r(e,F,n),r(e,De,n),f(H,e,n),r(e,qe,n),r(e,S,n),r(e,xe,n),ke[I].m(e,n),r(e,Ne,n),r(e,Y,n),r(e,Fe,n),r(e,L,n),r(e,He,n),_e[A].m(e,n),r(e,Qe,n),r(e,K,n),r(e,Se,n),$e[Z].m(e,n),r(e,ve,n),r(e,P,n),r(e,Ye,n),Ie[Q].m(e,n),r(e,Ve,n),r(e,O,n),r(e,Le,n),f(ee,e,n),r(e,Ke,n),r(e,se,n),r(e,Pe,n),f(R,e,n),r(e,Oe,n),r(e,le,n),r(e,es,n),f(ae,e,n),r(e,ss,n),r(e,ne,n),r(e,ls,n),f(te,e,n),r(e,as,n),r(e,oe,n),r(e,ns,n),f(re,e,n),r(e,ts,n),r(e,pe,n),r(e,os,n),ge[V].m(e,n),r(e,ze,n),r(e,ie,n),r(e,rs,n),r(e,me,n),r(e,ps,n),f(ue,e,n),r(e,is,n),r(e,ce,n),r(e,ms,n),r(e,Me,n),r(e,us,n),Ae[E].m(e,n),r(e,Ee,n),r(e,de,n),r(e,cs,n),r(e,be,n),r(e,Ms,n),f(G,e,n),r(e,ds,n),f(je,e,n),r(e,bs,n),r(e,fe,n),r(e,js,n),r(e,ye,n),r(e,fs,n),r(e,Ue,n),r(e,ys,n),r(e,Je,n),r(e,Us,n),f(he,e,n),r(e,Js,n),r(e,We,n),hs=!0},p(e,[n]){const jl={};n&1&&(jl.fw=e[0]),a.$set(jl);let Ts=w;w=sl(e),w!==Ts&&(B(),u(Te[Ts],1,1,()=>{Te[Ts]=null}),X(),k=Te[w],k||(k=Te[w]=el[w](e),k.c()),c(k,1),k.m(Ce.parentNode,Ce));let ws=_;_=al(e),_!==ws&&(B(),u(we[ws],1,1,()=>{we[ws]=null}),X(),$=we[_],$||($=we[_]=ll[_](e),$.c()),c($,1),$.m(Ze.parentNode,Ze));let ks=I;I=tl(e),I!==ks&&(B(),u(ke[ks],1,1,()=>{ke[ks]=null}),X(),g=ke[I],g||(g=ke[I]=nl[I](e),g.c()),c(g,1),g.m(Ne.parentNode,Ne));let _s=A;A=rl(e),A!==_s&&(B(),u(_e[_s],1,1,()=>{_e[_s]=null}),X(),C=_e[A],C||(C=_e[A]=ol[A](e),C.c()),c(C,1),C.m(Qe.parentNode,Qe));let $s=Z;Z=il(e),Z!==$s&&(B(),u($e[$s],1,1,()=>{$e[$s]=null}),X(),N=$e[Z],N||(N=$e[Z]=pl[Z](e),N.c()),c(N,1),N.m(ve.parentNode,ve));let Is=Q;Q=ul(e),Q!==Is&&(B(),u(Ie[Is],1,1,()=>{Ie[Is]=null}),X(),v=Ie[Q],v||(v=Ie[Q]=ml[Q](e),v.c()),c(v,1),v.m(Ve.parentNode,Ve));const fl={};n&2&&(fl.$$scope={dirty:n,ctx:e}),R.$set(fl);let gs=V;V=Ml(e),V!==gs&&(B(),u(ge[gs],1,1,()=>{ge[gs]=null}),X(),z=ge[V],z||(z=ge[V]=cl[V](e),z.c()),c(z,1),z.m(ze.parentNode,ze));let As=E;E=bl(e),E!==As&&(B(),u(Ae[As],1,1,()=>{Ae[As]=null}),X(),W=Ae[E],W||(W=Ae[E]=dl[E](e),W.c()),c(W,1),W.m(Ee.parentNode,Ee));const yl={};n&2&&(yl.$$scope={dirty:n,ctx:e}),G.$set(yl)},i(e){hs||(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),hs=!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),hs=!1},d(e){e&&(o(t),o(s),o(p),o(d),o(Ge),o(Ce),o(Ze),o(q),o(Xe),o(x),o(Be),o(F),o(De),o(qe),o(S),o(xe),o(Ne),o(Y),o(Fe),o(L),o(He),o(Qe),o(K),o(Se),o(ve),o(P),o(Ye),o(Ve),o(O),o(Le),o(Ke),o(se),o(Pe),o(Oe),o(le),o(es),o(ss),o(ne),o(ls),o(as),o(oe),o(ns),o(ts),o(pe),o(os),o(ze),o(ie),o(rs),o(me),o(ps),o(is),o(ce),o(ms),o(Me),o(us),o(Ee),o(de),o(cs),o(be),o(Ms),o(ds),o(bs),o(fe),o(js),o(ye),o(fs),o(Ue),o(ys),o(Je),o(Us),o(Js),o(We)),o(l),y(a,e),y(D,e),Te[w].d(e),we[_].d(e),y(H,e),ke[I].d(e),_e[A].d(e),$e[Z].d(e),Ie[Q].d(e),y(ee,e),y(R,e),y(ae,e),y(te,e),y(re,e),ge[V].d(e),y(ue,e),Ae[E].d(e),y(G,e),y(je,e),y(he,e)}}}const Kl='{"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 Pl(M,l,t){let s="pt";return $l(()=>{const p=new URLSearchParams(window.location.search);t(0,s=p.get("fw")||"pt")}),[s]}class ra extends Il{constructor(l){super(),gl(this,l,Pl,Ll,_l,{})}}export{ra as component};
