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