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