import{s as gs,o as _s,n as ws}from"../chunks/scheduler.37c15a92.js";import{S as $s,i as Is,g as h,s as o,r as b,A as zs,h as U,f as i,c as u,j as hs,u as j,x as J,k as Us,y as As,a as p,v as f,t as M,b as X,d as c,w as y,p as B}from"../chunks/index.2bf4358c.js";import{T as Js}from"../chunks/Tip.363c041f.js";import{Y as Ts}from"../chunks/Youtube.1e50a667.js";import{C as w}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as ks}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Cs}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ge}from"../chunks/Heading.8ada512a.js";function Zs(m){let s,a;return s=new ks({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"}]}}),{c(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Qs(m){let s,a;return s=new ks({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"}]}}),{c(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Ns(m){let s,a;return s=new Ts({props:{id:"ROxrFOEbsQE"}}),{c(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function vs(m){let s,a;return s=new Ts({props:{id:"M6adb1j2jPI"}}),{c(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Vs(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Ws(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Es(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Gs(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Rs(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(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Xs(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(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Bs(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(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Ds(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(){b(s.$$.fragment)},l(l){j(s.$$.fragment,l)},m(l,r){f(s,l,r),a=!0},i(l){a||(c(s.$$.fragment,l),a=!0)},o(l){M(s.$$.fragment,l),a=!1},d(l){y(s,l)}}}function Fs(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:ws,d(l){l&&i(s)}}}function Hs(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Ss(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function xs(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function qs(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(){b(s.$$.fragment),a=o(),b(l.$$.fragment)},l(n){j(s.$$.fragment,n),a=u(n),j(l.$$.fragment,n)},m(n,d){f(s,n,d),p(n,a,d),f(l,n,d),r=!0},i(n){r||(c(s.$$.fragment,n),c(l.$$.fragment,n),r=!0)},o(n){M(s.$$.fragment,n),M(l.$$.fragment,n),r=!1},d(n){n&&i(a),y(s,n),y(l,n)}}}function Ys(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:ws,d(l){l&&i(s)}}}function Ls(m){let s,a,l,r,n,d,D,Re,T,k,Ae,g,_,Ce,F,Al="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:",Xe,H,Cl="<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>",Be,S,Zl="Vediamo quali tipi di problemi pongono queste domande e come possiamo risolverli utilizzando l’API 🤗 Transformers.",De,x,Fe,q,Ql="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:",He,$,I,Ze,Y,Nl="Oh no! Perché non ha funzionato?",Se,L,vl="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:",xe,z,A,Qe,K,Vl="Proviamo di nuovo e aggiungiamo una nuova dimensione:",qe,C,Z,Ne,P,Wl="Stampiamo gli ID di input e i logit risultanti —  ecco l’output:",Ye,Q,N,ve,O,El="<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:",Le,ee,Ke,le,Gl="Si tratta di un batch di due sequenze identiche!",Pe,G,Oe,se,Rl="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.",el,ne,ll,te,Xl="Il seguente elenco di liste non può essere convertito in un tensore:",sl,ae,nl,ie,Bl="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:",tl,pe,al,re,Dl="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:",il,v,V,Ve,oe,Fl="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!",pl,ue,Hl="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.",rl,Me,ol,ce,Sl="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).",ul,me,xl="Completiamo l’esempio precedente con una maschera di attenzione:",Ml,W,E,We,de,ql="Ora otteniamo gli stessi logits per la seconda frase del batch.",cl,be,Yl="Si noti che l’ultimo valore della seconda sequenza è un ID di riempimento, che è un valore 0 nella maschera di attenzione.",ml,R,dl,je,bl,fe,Ll="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:",jl,ye,Kl="<li>Utilizzare un modello con una lunghezza di sequenza supportata maggiore.</li> <li>Troncare le sequenze.</li>",fl,he,Pl='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.',yl,Ue,Ol="Altrimenti, si consiglia di troncare le sequenze specificando il parametro <code>max_sequence_length</code>:",hl,Je,Ul,Ee,Jl;n=new Cs({props:{fw:m[0]}}),D=new Ge({props:{title:"Gestione di sequenze multiple",local:"gestione-di-sequenze-multiple",headingTag:"h1"}});const es=[Qs,Zs],we=[];function ls(e,t){return e[0]==="pt"?0:1}T=ls(m),k=we[T]=es[T](m);const ss=[vs,Ns],Te=[];function ns(e,t){return e[0]==="pt"?0:1}g=ns(m),_=Te[g]=ss[g](m),x=new Ge({props:{title:"I modelli si aspettano un gruppo di input",local:"i-modelli-si-aspettano-un-gruppo-di-input",headingTag:"h2"}});const ts=[Ws,Vs],ke=[];function as(e,t){return e[0]==="pt"?0:1}$=as(m),I=ke[$]=ts[$](m);const is=[Gs,Es],ge=[];function ps(e,t){return e[0]==="pt"?0:1}z=ps(m),A=ge[z]=is[z](m);const rs=[Xs,Rs],_e=[];function os(e,t){return e[0]==="pt"?0:1}C=os(m),Z=_e[C]=rs[C](m);const us=[Ds,Bs],$e=[];function Ms(e,t){return e[0]==="pt"?0:1}Q=Ms(m),N=$e[Q]=us[Q](m),ee=new w({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new Js({props:{$$slots:{default:[Fs]},$$scope:{ctx:m}}}),ne=new Ge({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 cs=[Ss,Hs],Ie=[];function ms(e,t){return e[0]==="pt"?0:1}v=ms(m),V=Ie[v]=cs[v](m),Me=new Ge({props:{title:"Attention masks",local:"attention-masks",headingTag:"h2"}});const ds=[qs,xs],ze=[];function bs(e,t){return e[0]==="pt"?0:1}return W=bs(m),E=ze[W]=ds[W](m),R=new Js({props:{$$slots:{default:[Ys]},$$scope:{ctx:m}}}),je=new Ge({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}}),{c(){s=h("meta"),a=o(),l=h("p"),r=o(),b(n.$$.fragment),d=o(),b(D.$$.fragment),Re=o(),k.c(),Ae=o(),_.c(),Ce=o(),F=h("p"),F.textContent=Al,Xe=o(),H=h("ul"),H.innerHTML=Cl,Be=o(),S=h("p"),S.textContent=Zl,De=o(),b(x.$$.fragment),Fe=o(),q=h("p"),q.textContent=Ql,He=o(),I.c(),Ze=o(),Y=h("p"),Y.textContent=Nl,Se=o(),L=h("p"),L.innerHTML=vl,xe=o(),A.c(),Qe=o(),K=h("p"),K.textContent=Vl,qe=o(),Z.c(),Ne=o(),P=h("p"),P.textContent=Wl,Ye=o(),N.c(),ve=o(),O=h("p"),O.innerHTML=El,Le=o(),b(ee.$$.fragment),Ke=o(),le=h("p"),le.textContent=Gl,Pe=o(),b(G.$$.fragment),Oe=o(),se=h("p"),se.innerHTML=Rl,el=o(),b(ne.$$.fragment),ll=o(),te=h("p"),te.textContent=Xl,sl=o(),b(ae.$$.fragment),nl=o(),ie=h("p"),ie.innerHTML=Bl,tl=o(),b(pe.$$.fragment),al=o(),re=h("p"),re.innerHTML=Dl,il=o(),V.c(),Ve=o(),oe=h("p"),oe.textContent=Fl,pl=o(),ue=h("p"),ue.innerHTML=Hl,rl=o(),b(Me.$$.fragment),ol=o(),ce=h("p"),ce.innerHTML=Sl,ul=o(),me=h("p"),me.textContent=xl,Ml=o(),E.c(),We=o(),de=h("p"),de.textContent=ql,cl=o(),be=h("p"),be.textContent=Yl,ml=o(),b(R.$$.fragment),dl=o(),b(je.$$.fragment),bl=o(),fe=h("p"),fe.textContent=Ll,jl=o(),ye=h("ul"),ye.innerHTML=Kl,fl=o(),he=h("p"),he.innerHTML=Pl,yl=o(),Ue=h("p"),Ue.innerHTML=Ol,hl=o(),b(Je.$$.fragment),Ul=o(),Ee=h("p"),this.h()},l(e){const t=zs("svelte-u9bgzb",document.head);s=U(t,"META",{name:!0,content:!0}),t.forEach(i),a=u(e),l=U(e,"P",{}),hs(l).forEach(i),r=u(e),j(n.$$.fragment,e),d=u(e),j(D.$$.fragment,e),Re=u(e),k.l(e),Ae=u(e),_.l(e),Ce=u(e),F=U(e,"P",{"data-svelte-h":!0}),J(F)!=="svelte-wld0ra"&&(F.textContent=Al),Xe=u(e),H=U(e,"UL",{"data-svelte-h":!0}),J(H)!=="svelte-v9pceg"&&(H.innerHTML=Cl),Be=u(e),S=U(e,"P",{"data-svelte-h":!0}),J(S)!=="svelte-s1s2kj"&&(S.textContent=Zl),De=u(e),j(x.$$.fragment,e),Fe=u(e),q=U(e,"P",{"data-svelte-h":!0}),J(q)!=="svelte-1lfbu0s"&&(q.textContent=Ql),He=u(e),I.l(e),Ze=u(e),Y=U(e,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-o1wb4g"&&(Y.textContent=Nl),Se=u(e),L=U(e,"P",{"data-svelte-h":!0}),J(L)!=="svelte-u7e21y"&&(L.innerHTML=vl),xe=u(e),A.l(e),Qe=u(e),K=U(e,"P",{"data-svelte-h":!0}),J(K)!=="svelte-s8mqje"&&(K.textContent=Vl),qe=u(e),Z.l(e),Ne=u(e),P=U(e,"P",{"data-svelte-h":!0}),J(P)!=="svelte-1vqddp1"&&(P.textContent=Wl),Ye=u(e),N.l(e),ve=u(e),O=U(e,"P",{"data-svelte-h":!0}),J(O)!=="svelte-rnqgoo"&&(O.innerHTML=El),Le=u(e),j(ee.$$.fragment,e),Ke=u(e),le=U(e,"P",{"data-svelte-h":!0}),J(le)!=="svelte-xfwh39"&&(le.textContent=Gl),Pe=u(e),j(G.$$.fragment,e),Oe=u(e),se=U(e,"P",{"data-svelte-h":!0}),J(se)!=="svelte-1vspqws"&&(se.innerHTML=Rl),el=u(e),j(ne.$$.fragment,e),ll=u(e),te=U(e,"P",{"data-svelte-h":!0}),J(te)!=="svelte-rzsiqj"&&(te.textContent=Xl),sl=u(e),j(ae.$$.fragment,e),nl=u(e),ie=U(e,"P",{"data-svelte-h":!0}),J(ie)!=="svelte-1jrcj4i"&&(ie.innerHTML=Bl),tl=u(e),j(pe.$$.fragment,e),al=u(e),re=U(e,"P",{"data-svelte-h":!0}),J(re)!=="svelte-19ch9mg"&&(re.innerHTML=Dl),il=u(e),V.l(e),Ve=u(e),oe=U(e,"P",{"data-svelte-h":!0}),J(oe)!=="svelte-alib0i"&&(oe.textContent=Fl),pl=u(e),ue=U(e,"P",{"data-svelte-h":!0}),J(ue)!=="svelte-om47da"&&(ue.innerHTML=Hl),rl=u(e),j(Me.$$.fragment,e),ol=u(e),ce=U(e,"P",{"data-svelte-h":!0}),J(ce)!=="svelte-cv6zws"&&(ce.innerHTML=Sl),ul=u(e),me=U(e,"P",{"data-svelte-h":!0}),J(me)!=="svelte-1kavan4"&&(me.textContent=xl),Ml=u(e),E.l(e),We=u(e),de=U(e,"P",{"data-svelte-h":!0}),J(de)!=="svelte-dj6crw"&&(de.textContent=ql),cl=u(e),be=U(e,"P",{"data-svelte-h":!0}),J(be)!=="svelte-15r56fn"&&(be.textContent=Yl),ml=u(e),j(R.$$.fragment,e),dl=u(e),j(je.$$.fragment,e),bl=u(e),fe=U(e,"P",{"data-svelte-h":!0}),J(fe)!=="svelte-iljzqz"&&(fe.textContent=Ll),jl=u(e),ye=U(e,"UL",{"data-svelte-h":!0}),J(ye)!=="svelte-1h1ihuu"&&(ye.innerHTML=Kl),fl=u(e),he=U(e,"P",{"data-svelte-h":!0}),J(he)!=="svelte-10cy53r"&&(he.innerHTML=Pl),yl=u(e),Ue=U(e,"P",{"data-svelte-h":!0}),J(Ue)!=="svelte-dyydg6"&&(Ue.innerHTML=Ol),hl=u(e),j(Je.$$.fragment,e),Ul=u(e),Ee=U(e,"P",{}),hs(Ee).forEach(i),this.h()},h(){Us(s,"name","hf:doc:metadata"),Us(s,"content",Ks)},m(e,t){As(document.head,s),p(e,a,t),p(e,l,t),p(e,r,t),f(n,e,t),p(e,d,t),f(D,e,t),p(e,Re,t),we[T].m(e,t),p(e,Ae,t),Te[g].m(e,t),p(e,Ce,t),p(e,F,t),p(e,Xe,t),p(e,H,t),p(e,Be,t),p(e,S,t),p(e,De,t),f(x,e,t),p(e,Fe,t),p(e,q,t),p(e,He,t),ke[$].m(e,t),p(e,Ze,t),p(e,Y,t),p(e,Se,t),p(e,L,t),p(e,xe,t),ge[z].m(e,t),p(e,Qe,t),p(e,K,t),p(e,qe,t),_e[C].m(e,t),p(e,Ne,t),p(e,P,t),p(e,Ye,t),$e[Q].m(e,t),p(e,ve,t),p(e,O,t),p(e,Le,t),f(ee,e,t),p(e,Ke,t),p(e,le,t),p(e,Pe,t),f(G,e,t),p(e,Oe,t),p(e,se,t),p(e,el,t),f(ne,e,t),p(e,ll,t),p(e,te,t),p(e,sl,t),f(ae,e,t),p(e,nl,t),p(e,ie,t),p(e,tl,t),f(pe,e,t),p(e,al,t),p(e,re,t),p(e,il,t),Ie[v].m(e,t),p(e,Ve,t),p(e,oe,t),p(e,pl,t),p(e,ue,t),p(e,rl,t),f(Me,e,t),p(e,ol,t),p(e,ce,t),p(e,ul,t),p(e,me,t),p(e,Ml,t),ze[W].m(e,t),p(e,We,t),p(e,de,t),p(e,cl,t),p(e,be,t),p(e,ml,t),f(R,e,t),p(e,dl,t),f(je,e,t),p(e,bl,t),p(e,fe,t),p(e,jl,t),p(e,ye,t),p(e,fl,t),p(e,he,t),p(e,yl,t),p(e,Ue,t),p(e,hl,t),f(Je,e,t),p(e,Ul,t),p(e,Ee,t),Jl=!0},p(e,[t]){const js={};t&1&&(js.fw=e[0]),n.$set(js);let wl=T;T=ls(e),T!==wl&&(B(),M(we[wl],1,1,()=>{we[wl]=null}),X(),k=we[T],k||(k=we[T]=es[T](e),k.c()),c(k,1),k.m(Ae.parentNode,Ae));let Tl=g;g=ns(e),g!==Tl&&(B(),M(Te[Tl],1,1,()=>{Te[Tl]=null}),X(),_=Te[g],_||(_=Te[g]=ss[g](e),_.c()),c(_,1),_.m(Ce.parentNode,Ce));let kl=$;$=as(e),$!==kl&&(B(),M(ke[kl],1,1,()=>{ke[kl]=null}),X(),I=ke[$],I||(I=ke[$]=ts[$](e),I.c()),c(I,1),I.m(Ze.parentNode,Ze));let gl=z;z=ps(e),z!==gl&&(B(),M(ge[gl],1,1,()=>{ge[gl]=null}),X(),A=ge[z],A||(A=ge[z]=is[z](e),A.c()),c(A,1),A.m(Qe.parentNode,Qe));let _l=C;C=os(e),C!==_l&&(B(),M(_e[_l],1,1,()=>{_e[_l]=null}),X(),Z=_e[C],Z||(Z=_e[C]=rs[C](e),Z.c()),c(Z,1),Z.m(Ne.parentNode,Ne));let $l=Q;Q=Ms(e),Q!==$l&&(B(),M($e[$l],1,1,()=>{$e[$l]=null}),X(),N=$e[Q],N||(N=$e[Q]=us[Q](e),N.c()),c(N,1),N.m(ve.parentNode,ve));const fs={};t&2&&(fs.$$scope={dirty:t,ctx:e}),G.$set(fs);let Il=v;v=ms(e),v!==Il&&(B(),M(Ie[Il],1,1,()=>{Ie[Il]=null}),X(),V=Ie[v],V||(V=Ie[v]=cs[v](e),V.c()),c(V,1),V.m(Ve.parentNode,Ve));let zl=W;W=bs(e),W!==zl&&(B(),M(ze[zl],1,1,()=>{ze[zl]=null}),X(),E=ze[W],E||(E=ze[W]=ds[W](e),E.c()),c(E,1),E.m(We.parentNode,We));const ys={};t&2&&(ys.$$scope={dirty:t,ctx:e}),R.$set(ys)},i(e){Jl||(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(Me.$$.fragment,e),c(E),c(R.$$.fragment,e),c(je.$$.fragment,e),c(Je.$$.fragment,e),Jl=!0)},o(e){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(Me.$$.fragment,e),M(E),M(R.$$.fragment,e),M(je.$$.fragment,e),M(Je.$$.fragment,e),Jl=!1},d(e){e&&(i(a),i(l),i(r),i(d),i(Re),i(Ae),i(Ce),i(F),i(Xe),i(H),i(Be),i(S),i(De),i(Fe),i(q),i(He),i(Ze),i(Y),i(Se),i(L),i(xe),i(Qe),i(K),i(qe),i(Ne),i(P),i(Ye),i(ve),i(O),i(Le),i(Ke),i(le),i(Pe),i(Oe),i(se),i(el),i(ll),i(te),i(sl),i(nl),i(ie),i(tl),i(al),i(re),i(il),i(Ve),i(oe),i(pl),i(ue),i(rl),i(ol),i(ce),i(ul),i(me),i(Ml),i(We),i(de),i(cl),i(be),i(ml),i(dl),i(bl),i(fe),i(jl),i(ye),i(fl),i(he),i(yl),i(Ue),i(hl),i(Ul),i(Ee)),i(s),y(n,e),y(D,e),we[T].d(e),Te[g].d(e),y(x,e),ke[$].d(e),ge[z].d(e),_e[C].d(e),$e[Q].d(e),y(ee,e),y(G,e),y(ne,e),y(ae,e),y(pe,e),Ie[v].d(e),y(Me,e),ze[W].d(e),y(R,e),y(je,e),y(Je,e)}}}const Ks='{"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 Ps(m,s,a){let l="pt";return _s(()=>{const r=new URLSearchParams(window.location.search);a(0,l=r.get("fw")||"pt")}),[l]}class rn extends $s{constructor(s){super(),Is(this,s,Ps,Ls,gs,{})}}export{rn as component};
