import{s as $s,o as Is,n as ks}from"../chunks/scheduler.37c15a92.js";import{S as zs,i as As,g as h,s as o,r as d,A as Cs,h as U,f as i,c as u,j as Js,u as b,x as J,k as ws,y as Zs,a as p,v as j,t as c,b as X,d as M,w as f,p as B}from"../chunks/index.2bf4358c.js";import{T as Ts}from"../chunks/Tip.363c041f.js";import{Y as gs}from"../chunks/Youtube.1e50a667.js";import{C as w}from"../chunks/CodeBlock.4e987730.js";import{C as _s}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Qs}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Re,E as Ns}from"../chunks/getInferenceSnippets.648f38f6.js";function vs(m){let s,a;return s=new _s({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"}]}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Vs(m){let s,a;return s=new _s({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"}]}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Es(m){let s,a;return s=new gs({props:{id:"ROxrFOEbsQE"}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Ws(m){let s,a;return s=new gs({props:{id:"M6adb1j2jPI"}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Gs(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Rs(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Xs(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Bs(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Ds(m){let s,a;return s=new w({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(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Fs(m){let s,a;return s=new w({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(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Hs(m){let s,a;return s=new w({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(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Ss(m){let s,a;return s=new w({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(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,r){j(s,l,r),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){c(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function xs(m){let s,a="✏️ <strong>Try it out!</strong> Convert this <code>batched_ids</code> list into a tensor and pass it through your model. Check that you obtain the same logits as before (but twice)!";return{c(){s=h("p"),s.innerHTML=a},l(l){s=U(l,"P",{"data-svelte-h":!0}),J(s)!=="svelte-14nl6tk"&&(s.innerHTML=a)},m(l,r){p(l,s,r)},p:ks,d(l){l&&i(s)}}}function qs(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Ys(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Ls(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Ks(m){let s,a,l,r;return s=new w({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}}),l=new w({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(s.$$.fragment),a=o(),d(l.$$.fragment)},l(n){b(s.$$.fragment,n),a=u(n),b(l.$$.fragment,n)},m(n,y){j(s,n,y),p(n,a,y),j(l,n,y),r=!0},i(n){r||(M(s.$$.fragment,n),M(l.$$.fragment,n),r=!0)},o(n){c(s.$$.fragment,n),c(l.$$.fragment,n),r=!1},d(n){n&&i(a),f(s,n),f(l,n)}}}function Ps(m){let s,a="✏️ <strong>Provaci anche tu</strong> Applicate manualmente la tokenizzazione alle due frasi utilizzate nella sezione 2 (“I’ve been waiting for a HuggingFace course my whole life.” e “I hate this so much!”). Passatele attraverso il modello e verificate che si ottengano gli stessi logits della sezione 2. A questo punto, batchateli insieme utilizzando il token di padding e successivamente create la maschera di attenzione appropriata. Verificate di ottenere gli stessi risultati passando attraverso il modello!";return{c(){s=h("p"),s.innerHTML=a},l(l){s=U(l,"P",{"data-svelte-h":!0}),J(s)!=="svelte-13j4tiq"&&(s.innerHTML=a)},m(l,r){p(l,s,r)},p:ks,d(l){l&&i(s)}}}function Os(m){let s,a,l,r,n,y,D,Xe,T,k,Ce,g,_,Ze,F,Zl="Nella sezione precedente abbiamo esplorato il più semplice dei casi d’uso: fare inferenza su una singola sequenza di lunghezza ridotta. Tuttavia, emergono già alcune domande:",Be,H,Ql="<li>Come si gestiscono le sequenze multiple?</li> <li>Come gestiamo sequenze multiple <em>di lunghezza diversa</em>?</li> <li>Gli indici del vocabolario sono gli unici input che permettono a un modello di funzionare bene?</li> <li>Esiste una sequenza troppo lunga?</li>",De,S,Nl="Vediamo quali tipi di problemi pongono queste domande e come possiamo risolverli utilizzando l’API 🤗 Transformers.",Fe,x,He,q,vl="Nell’esercizio precedente abbiamo visto come le sequenze vengono tradotte in liste di numeri. Convertiamo questo elenco di numeri in un tensore e inviamolo al modello:",Se,$,I,Qe,Y,Vl="Oh no! Perché non ha funzionato?",xe,L,El="Il problema è che abbiamo inviato una singola sequenza al modello, mentre i modelli 🤗 Transformers si aspettano frasi multiple per impostazione predefinita. Qui abbiamo cercato di fare tutto ciò che il tokenizer ha fatto dietro le quinte, quando lo abbiamo applicato a una <code>sequenza</code>. Ma se si osserva attentamente, si noterà che il tokenizer non si è limitato a convertire l’elenco degli ID in ingresso in un tensore, ma ha aggiunto una dimensione:",qe,z,A,Ne,K,Wl="Proviamo di nuovo e aggiungiamo una nuova dimensione:",Ye,C,Z,ve,P,Gl="Stampiamo gli ID di input e i logit risultanti —  ecco l’output:",Le,Q,N,Ve,O,Rl="<em>Il batch</em> è la procedura di invio di più frasi nel modello, tutte in una volta. Se si ha una sola frase, si può creare un batch con una sola sequenza:",Ke,ee,Pe,le,Xl="Si tratta di un batch di due sequenze identiche!",Oe,G,el,se,Bl="Il batching consente al modello di funzionare quando si inseriscono più frasi. Utilizzare più sequenze è altrettanto semplice che creare un batch con una singola sequenza. C’è però un secondo problema. Quando si cerca di raggruppare due (o più) frasi, queste potrebbero essere di lunghezza diversa. Se si è già lavorato con i tensori, si sa che devono essere di forma rettangolare, quindi non è possibile convertire direttamente l’elenco degli ID in ingresso in un tensore. Per ovviare a questo problema, di solito, utilizziamo la tecnica del <em>padding</em> sugli input.",ll,ne,sl,te,Dl="Il seguente elenco di liste non può essere convertito in un tensore:",nl,ae,tl,ie,Fl="Per ovviare a questo problema, useremo il <em>padding</em> per dare ai nostri tensori una forma rettangolare. Il padding assicura che tutte le frasi abbiano la stessa lunghezza, aggiungendo una parola speciale chiamata <em>padding token</em> alle frasi con meno valori. Ad esempio, se si hanno 10 frasi con 10 parole e 1 frase con 20 parole, il padding assicura che tutte le frasi abbiano 20 parole. Nel nostro esempio, il tensore risultante ha il seguente aspetto:",al,pe,il,re,Hl="L’ID del token di padding si trova in <code>tokenizer.pad_token_id</code>. Utilizziamolo e inviamo le nostre due frasi attraverso il modello singolarmente e insieme:",pl,v,V,Ee,oe,Sl="C’è qualcosa che non va con i logit nelle nostre previsioni raggruppate: la seconda riga dovrebbe essere uguale ai logit della seconda frase, ma abbiamo valori completamente diversi!",rl,ue,xl="Questo perché la caratteristica principale dei modelli Transformer sono i livelli di attenzione che <em>contestualizzano</em> ogni token. Questi terranno conto dei token del padding, poiché si occupano di tutti i token di una sequenza. Per ottenere lo stesso risultato quando si passano nel modello singole frasi di lunghezza diversa o quando si passa un gruppo con le stesse frasi e l’applicazione di un padding, occorre dire a questi livelli di attenzione di ignorare i token del padding. Questo si ottiene utilizzando una maschera di attenzione.",ol,ce,ul,Me,ql="Le <em>maschere di attenzione</em> sono tensori con la stessa forma del tensore degli ID in ingresso, riempiti con 0 e 1: 1 indica che i token corrispondenti devono essere presi in considerazione, mentre 0 indica che i token corrispondenti non devono essere presi in considerazione (cioè, devono essere ignorati dagli strati di attenzione del modello).",cl,me,Yl="Completiamo l’esempio precedente con una maschera di attenzione:",Ml,E,W,We,de,Ll="Ora otteniamo gli stessi logits per la seconda frase del batch.",ml,be,Kl="Si noti che l’ultimo valore della seconda sequenza è un ID di riempimento, che è un valore 0 nella maschera di attenzione.",dl,R,bl,je,jl,fe,Pl="Con i modelli Transformer, c’è un limite alla lunghezza delle sequenze che possiamo passare ai modelli. La maggior parte dei modelli gestisce sequenze fino a 512 o 1024 token e si blocca quando viene chiesto di elaborare sequenze più lunghe. Esistono due soluzioni a questo problema:",fl,ye,Ol="<li>Utilizzare un modello con una lunghezza di sequenza supportata maggiore.</li> <li>Troncare le sequenze.</li>",yl,he,es='I modelli hanno diverse lunghezze di sequenza supportate e alcuni sono specializzati nella gestione di sequenze molto lunghe. <a href="https://huggingface.co/transformers/model_doc/longformer.html" rel="nofollow">Longformer</a> è un esempio, un altro è <a href="https://huggingface.co/transformers/model_doc/led.html" rel="nofollow">LED</a>.  Se state lavorando a un’attività che richiede sequenze molto lunghe, vi consigliamo di dare un’occhiata a questi modelli.',hl,Ue,ls="Altrimenti, si consiglia di troncare le sequenze specificando il parametro <code>max_sequence_length</code>:",Ul,Je,Jl,we,wl,Ge,Tl;n=new Qs({props:{fw:m[0]}}),D=new Re({props:{title:"Gestione di sequenze multiple",local:"gestione-di-sequenze-multiple",headingTag:"h1"}});const ss=[Vs,vs],Te=[];function ns(e,t){return e[0]==="pt"?0:1}T=ns(m),k=Te[T]=ss[T](m);const ts=[Ws,Es],ke=[];function as(e,t){return e[0]==="pt"?0:1}g=as(m),_=ke[g]=ts[g](m),x=new Re({props:{title:"I modelli si aspettano un gruppo di input",local:"i-modelli-si-aspettano-un-gruppo-di-input",headingTag:"h2"}});const is=[Rs,Gs],ge=[];function ps(e,t){return e[0]==="pt"?0:1}$=ps(m),I=ge[$]=is[$](m);const rs=[Bs,Xs],_e=[];function os(e,t){return e[0]==="pt"?0:1}z=os(m),A=_e[z]=rs[z](m);const us=[Fs,Ds],$e=[];function cs(e,t){return e[0]==="pt"?0:1}C=cs(m),Z=$e[C]=us[C](m);const Ms=[Ss,Hs],Ie=[];function ms(e,t){return e[0]==="pt"?0:1}Q=ms(m),N=Ie[Q]=Ms[Q](m),ee=new w({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new Ts({props:{$$slots:{default:[xs]},$$scope:{ctx:m}}}),ne=new Re({props:{title:"Aggiungere il padding all’input",local:"aggiungere-il-padding-allinput",headingTag:"h2"}}),ae=new w({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 w({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 ds=[Ys,qs],ze=[];function bs(e,t){return e[0]==="pt"?0:1}v=bs(m),V=ze[v]=ds[v](m),ce=new Re({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const js=[Ks,Ls],Ae=[];function fs(e,t){return e[0]==="pt"?0:1}return E=fs(m),W=Ae[E]=js[E](m),R=new Ts({props:{$$slots:{default:[Ps]},$$scope:{ctx:m}}}),je=new Re({props:{title:"Sequenze più lunghe",local:"sequenze-più-lunghe",headingTag:"h2"}}),Je=new w({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),we=new Ns({props:{source:"https://github.com/huggingface/course/blob/main/chapters/it/chapter2/5.mdx"}}),{c(){s=h("meta"),a=o(),l=h("p"),r=o(),d(n.$$.fragment),y=o(),d(D.$$.fragment),Xe=o(),k.c(),Ce=o(),_.c(),Ze=o(),F=h("p"),F.textContent=Zl,Be=o(),H=h("ul"),H.innerHTML=Ql,De=o(),S=h("p"),S.textContent=Nl,Fe=o(),d(x.$$.fragment),He=o(),q=h("p"),q.textContent=vl,Se=o(),I.c(),Qe=o(),Y=h("p"),Y.textContent=Vl,xe=o(),L=h("p"),L.innerHTML=El,qe=o(),A.c(),Ne=o(),K=h("p"),K.textContent=Wl,Ye=o(),Z.c(),ve=o(),P=h("p"),P.textContent=Gl,Le=o(),N.c(),Ve=o(),O=h("p"),O.innerHTML=Rl,Ke=o(),d(ee.$$.fragment),Pe=o(),le=h("p"),le.textContent=Xl,Oe=o(),d(G.$$.fragment),el=o(),se=h("p"),se.innerHTML=Bl,ll=o(),d(ne.$$.fragment),sl=o(),te=h("p"),te.textContent=Dl,nl=o(),d(ae.$$.fragment),tl=o(),ie=h("p"),ie.innerHTML=Fl,al=o(),d(pe.$$.fragment),il=o(),re=h("p"),re.innerHTML=Hl,pl=o(),V.c(),Ee=o(),oe=h("p"),oe.textContent=Sl,rl=o(),ue=h("p"),ue.innerHTML=xl,ol=o(),d(ce.$$.fragment),ul=o(),Me=h("p"),Me.innerHTML=ql,cl=o(),me=h("p"),me.textContent=Yl,Ml=o(),W.c(),We=o(),de=h("p"),de.textContent=Ll,ml=o(),be=h("p"),be.textContent=Kl,dl=o(),d(R.$$.fragment),bl=o(),d(je.$$.fragment),jl=o(),fe=h("p"),fe.textContent=Pl,fl=o(),ye=h("ul"),ye.innerHTML=Ol,yl=o(),he=h("p"),he.innerHTML=es,hl=o(),Ue=h("p"),Ue.innerHTML=ls,Ul=o(),d(Je.$$.fragment),Jl=o(),d(we.$$.fragment),wl=o(),Ge=h("p"),this.h()},l(e){const t=Cs("svelte-u9bgzb",document.head);s=U(t,"META",{name:!0,content:!0}),t.forEach(i),a=u(e),l=U(e,"P",{}),Js(l).forEach(i),r=u(e),b(n.$$.fragment,e),y=u(e),b(D.$$.fragment,e),Xe=u(e),k.l(e),Ce=u(e),_.l(e),Ze=u(e),F=U(e,"P",{"data-svelte-h":!0}),J(F)!=="svelte-wld0ra"&&(F.textContent=Zl),Be=u(e),H=U(e,"UL",{"data-svelte-h":!0}),J(H)!=="svelte-v9pceg"&&(H.innerHTML=Ql),De=u(e),S=U(e,"P",{"data-svelte-h":!0}),J(S)!=="svelte-s1s2kj"&&(S.textContent=Nl),Fe=u(e),b(x.$$.fragment,e),He=u(e),q=U(e,"P",{"data-svelte-h":!0}),J(q)!=="svelte-1lfbu0s"&&(q.textContent=vl),Se=u(e),I.l(e),Qe=u(e),Y=U(e,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-o1wb4g"&&(Y.textContent=Vl),xe=u(e),L=U(e,"P",{"data-svelte-h":!0}),J(L)!=="svelte-u7e21y"&&(L.innerHTML=El),qe=u(e),A.l(e),Ne=u(e),K=U(e,"P",{"data-svelte-h":!0}),J(K)!=="svelte-s8mqje"&&(K.textContent=Wl),Ye=u(e),Z.l(e),ve=u(e),P=U(e,"P",{"data-svelte-h":!0}),J(P)!=="svelte-1vqddp1"&&(P.textContent=Gl),Le=u(e),N.l(e),Ve=u(e),O=U(e,"P",{"data-svelte-h":!0}),J(O)!=="svelte-rnqgoo"&&(O.innerHTML=Rl),Ke=u(e),b(ee.$$.fragment,e),Pe=u(e),le=U(e,"P",{"data-svelte-h":!0}),J(le)!=="svelte-xfwh39"&&(le.textContent=Xl),Oe=u(e),b(G.$$.fragment,e),el=u(e),se=U(e,"P",{"data-svelte-h":!0}),J(se)!=="svelte-1vspqws"&&(se.innerHTML=Bl),ll=u(e),b(ne.$$.fragment,e),sl=u(e),te=U(e,"P",{"data-svelte-h":!0}),J(te)!=="svelte-rzsiqj"&&(te.textContent=Dl),nl=u(e),b(ae.$$.fragment,e),tl=u(e),ie=U(e,"P",{"data-svelte-h":!0}),J(ie)!=="svelte-1jrcj4i"&&(ie.innerHTML=Fl),al=u(e),b(pe.$$.fragment,e),il=u(e),re=U(e,"P",{"data-svelte-h":!0}),J(re)!=="svelte-19ch9mg"&&(re.innerHTML=Hl),pl=u(e),V.l(e),Ee=u(e),oe=U(e,"P",{"data-svelte-h":!0}),J(oe)!=="svelte-alib0i"&&(oe.textContent=Sl),rl=u(e),ue=U(e,"P",{"data-svelte-h":!0}),J(ue)!=="svelte-om47da"&&(ue.innerHTML=xl),ol=u(e),b(ce.$$.fragment,e),ul=u(e),Me=U(e,"P",{"data-svelte-h":!0}),J(Me)!=="svelte-cv6zws"&&(Me.innerHTML=ql),cl=u(e),me=U(e,"P",{"data-svelte-h":!0}),J(me)!=="svelte-1kavan4"&&(me.textContent=Yl),Ml=u(e),W.l(e),We=u(e),de=U(e,"P",{"data-svelte-h":!0}),J(de)!=="svelte-dj6crw"&&(de.textContent=Ll),ml=u(e),be=U(e,"P",{"data-svelte-h":!0}),J(be)!=="svelte-15r56fn"&&(be.textContent=Kl),dl=u(e),b(R.$$.fragment,e),bl=u(e),b(je.$$.fragment,e),jl=u(e),fe=U(e,"P",{"data-svelte-h":!0}),J(fe)!=="svelte-iljzqz"&&(fe.textContent=Pl),fl=u(e),ye=U(e,"UL",{"data-svelte-h":!0}),J(ye)!=="svelte-1h1ihuu"&&(ye.innerHTML=Ol),yl=u(e),he=U(e,"P",{"data-svelte-h":!0}),J(he)!=="svelte-10cy53r"&&(he.innerHTML=es),hl=u(e),Ue=U(e,"P",{"data-svelte-h":!0}),J(Ue)!=="svelte-dyydg6"&&(Ue.innerHTML=ls),Ul=u(e),b(Je.$$.fragment,e),Jl=u(e),b(we.$$.fragment,e),wl=u(e),Ge=U(e,"P",{}),Js(Ge).forEach(i),this.h()},h(){ws(s,"name","hf:doc:metadata"),ws(s,"content",en)},m(e,t){Zs(document.head,s),p(e,a,t),p(e,l,t),p(e,r,t),j(n,e,t),p(e,y,t),j(D,e,t),p(e,Xe,t),Te[T].m(e,t),p(e,Ce,t),ke[g].m(e,t),p(e,Ze,t),p(e,F,t),p(e,Be,t),p(e,H,t),p(e,De,t),p(e,S,t),p(e,Fe,t),j(x,e,t),p(e,He,t),p(e,q,t),p(e,Se,t),ge[$].m(e,t),p(e,Qe,t),p(e,Y,t),p(e,xe,t),p(e,L,t),p(e,qe,t),_e[z].m(e,t),p(e,Ne,t),p(e,K,t),p(e,Ye,t),$e[C].m(e,t),p(e,ve,t),p(e,P,t),p(e,Le,t),Ie[Q].m(e,t),p(e,Ve,t),p(e,O,t),p(e,Ke,t),j(ee,e,t),p(e,Pe,t),p(e,le,t),p(e,Oe,t),j(G,e,t),p(e,el,t),p(e,se,t),p(e,ll,t),j(ne,e,t),p(e,sl,t),p(e,te,t),p(e,nl,t),j(ae,e,t),p(e,tl,t),p(e,ie,t),p(e,al,t),j(pe,e,t),p(e,il,t),p(e,re,t),p(e,pl,t),ze[v].m(e,t),p(e,Ee,t),p(e,oe,t),p(e,rl,t),p(e,ue,t),p(e,ol,t),j(ce,e,t),p(e,ul,t),p(e,Me,t),p(e,cl,t),p(e,me,t),p(e,Ml,t),Ae[E].m(e,t),p(e,We,t),p(e,de,t),p(e,ml,t),p(e,be,t),p(e,dl,t),j(R,e,t),p(e,bl,t),j(je,e,t),p(e,jl,t),p(e,fe,t),p(e,fl,t),p(e,ye,t),p(e,yl,t),p(e,he,t),p(e,hl,t),p(e,Ue,t),p(e,Ul,t),j(Je,e,t),p(e,Jl,t),j(we,e,t),p(e,wl,t),p(e,Ge,t),Tl=!0},p(e,[t]){const ys={};t&1&&(ys.fw=e[0]),n.$set(ys);let kl=T;T=ns(e),T!==kl&&(B(),c(Te[kl],1,1,()=>{Te[kl]=null}),X(),k=Te[T],k||(k=Te[T]=ss[T](e),k.c()),M(k,1),k.m(Ce.parentNode,Ce));let gl=g;g=as(e),g!==gl&&(B(),c(ke[gl],1,1,()=>{ke[gl]=null}),X(),_=ke[g],_||(_=ke[g]=ts[g](e),_.c()),M(_,1),_.m(Ze.parentNode,Ze));let _l=$;$=ps(e),$!==_l&&(B(),c(ge[_l],1,1,()=>{ge[_l]=null}),X(),I=ge[$],I||(I=ge[$]=is[$](e),I.c()),M(I,1),I.m(Qe.parentNode,Qe));let $l=z;z=os(e),z!==$l&&(B(),c(_e[$l],1,1,()=>{_e[$l]=null}),X(),A=_e[z],A||(A=_e[z]=rs[z](e),A.c()),M(A,1),A.m(Ne.parentNode,Ne));let Il=C;C=cs(e),C!==Il&&(B(),c($e[Il],1,1,()=>{$e[Il]=null}),X(),Z=$e[C],Z||(Z=$e[C]=us[C](e),Z.c()),M(Z,1),Z.m(ve.parentNode,ve));let zl=Q;Q=ms(e),Q!==zl&&(B(),c(Ie[zl],1,1,()=>{Ie[zl]=null}),X(),N=Ie[Q],N||(N=Ie[Q]=Ms[Q](e),N.c()),M(N,1),N.m(Ve.parentNode,Ve));const hs={};t&2&&(hs.$$scope={dirty:t,ctx:e}),G.$set(hs);let Al=v;v=bs(e),v!==Al&&(B(),c(ze[Al],1,1,()=>{ze[Al]=null}),X(),V=ze[v],V||(V=ze[v]=ds[v](e),V.c()),M(V,1),V.m(Ee.parentNode,Ee));let Cl=E;E=fs(e),E!==Cl&&(B(),c(Ae[Cl],1,1,()=>{Ae[Cl]=null}),X(),W=Ae[E],W||(W=Ae[E]=js[E](e),W.c()),M(W,1),W.m(We.parentNode,We));const Us={};t&2&&(Us.$$scope={dirty:t,ctx:e}),R.$set(Us)},i(e){Tl||(M(n.$$.fragment,e),M(D.$$.fragment,e),M(k),M(_),M(x.$$.fragment,e),M(I),M(A),M(Z),M(N),M(ee.$$.fragment,e),M(G.$$.fragment,e),M(ne.$$.fragment,e),M(ae.$$.fragment,e),M(pe.$$.fragment,e),M(V),M(ce.$$.fragment,e),M(W),M(R.$$.fragment,e),M(je.$$.fragment,e),M(Je.$$.fragment,e),M(we.$$.fragment,e),Tl=!0)},o(e){c(n.$$.fragment,e),c(D.$$.fragment,e),c(k),c(_),c(x.$$.fragment,e),c(I),c(A),c(Z),c(N),c(ee.$$.fragment,e),c(G.$$.fragment,e),c(ne.$$.fragment,e),c(ae.$$.fragment,e),c(pe.$$.fragment,e),c(V),c(ce.$$.fragment,e),c(W),c(R.$$.fragment,e),c(je.$$.fragment,e),c(Je.$$.fragment,e),c(we.$$.fragment,e),Tl=!1},d(e){e&&(i(a),i(l),i(r),i(y),i(Xe),i(Ce),i(Ze),i(F),i(Be),i(H),i(De),i(S),i(Fe),i(He),i(q),i(Se),i(Qe),i(Y),i(xe),i(L),i(qe),i(Ne),i(K),i(Ye),i(ve),i(P),i(Le),i(Ve),i(O),i(Ke),i(Pe),i(le),i(Oe),i(el),i(se),i(ll),i(sl),i(te),i(nl),i(tl),i(ie),i(al),i(il),i(re),i(pl),i(Ee),i(oe),i(rl),i(ue),i(ol),i(ul),i(Me),i(cl),i(me),i(Ml),i(We),i(de),i(ml),i(be),i(dl),i(bl),i(jl),i(fe),i(fl),i(ye),i(yl),i(he),i(hl),i(Ue),i(Ul),i(Jl),i(wl),i(Ge)),i(s),f(n,e),f(D,e),Te[T].d(e),ke[g].d(e),f(x,e),ge[$].d(e),_e[z].d(e),$e[C].d(e),Ie[Q].d(e),f(ee,e),f(G,e),f(ne,e),f(ae,e),f(pe,e),ze[v].d(e),f(ce,e),Ae[E].d(e),f(R,e),f(je,e),f(Je,e),f(we,e)}}}const en='{"title":"Gestione di sequenze multiple","local":"gestione-di-sequenze-multiple","sections":[{"title":"I modelli si aspettano un gruppo di input","local":"i-modelli-si-aspettano-un-gruppo-di-input","sections":[],"depth":2},{"title":"Aggiungere il padding all’input","local":"aggiungere-il-padding-allinput","sections":[],"depth":2},{"title":"Attention masks","local":"attention-masks","sections":[],"depth":2},{"title":"Sequenze più lunghe","local":"sequenze-più-lunghe","sections":[],"depth":2}],"depth":1}';function ln(m,s,a){let l="pt";return Is(()=>{const r=new URLSearchParams(window.location.search);a(0,l=r.get("fw")||"pt")}),[l]}class cn extends zs{constructor(s){super(),As(this,s,ln,Os,$s,{})}}export{cn as component};
