import{s as As,o as Cs,n as $s}from"../chunks/scheduler.893fe8c9.js";import{S as Zs,i as vs,e as U,s as u,c as d,h as Ns,a as J,d as i,b as c,f as hs,g as b,j as T,k as ks,l as Qs,m as r,n as j,o,D,t as M,p as f,E as X}from"../chunks/index.6ee278c6.js";import{T as _s}from"../chunks/Tip.eab0255c.js";import{C as zs,H as De,E as Vs}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.ea3ad860.js";import{Y as Is}from"../chunks/Youtube.59d04f41.js";import{C as w}from"../chunks/CodeBlock.8bdd5f33.js";import{C as gs}from"../chunks/CourseFloatingBanner.c25cfa5e.js";import{F as Es}from"../chunks/FrameworkSwitchCourse.77a18d50.js";function Ws(m){let s,a;return s=new gs({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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Gs(m){let s,a;return s=new gs({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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Rs(m){let s,a;return s=new Is({props:{id:"ROxrFOEbsQE"}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Ds(m){let s,a;return s=new Is({props:{id:"M6adb1j2jPI"}}),{c(){d(s.$$.fragment)},l(l){b(s.$$.fragment,l)},m(l,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Xs(m){let s,a,l,p;return s=new w({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIudG9rZW5pemUoc2VxdWVuY2UpJTBBaWRzJTIwJTNEJTIwdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyh0b2tlbnMpJTBBaW5wdXRfaWRzJTIwJTNEJTIwdGYuY29uc3RhbnQoaWRzKSUwQSUyMyUyMEFjZWFzdCVDNCU4MyUyMGxpbmllJTIwdmElMjBlJUM4JTk5dWEuJTBBbW9kZWwoaW5wdXRfaWRzKQ==",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"># Această linie va eșua.</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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function Bs(m){let s,a,l,p;return s=new w({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEFpbnB1dF9pZHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoaWRzKSUwQSUyMyUyMEFjZWFzdCVDNCU4MyUyMGxpbmllJTIwdmElMjBlJUM4JTk5dWEuJTBBbW9kZWwoaW5wdXRfaWRzKQ==",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"># Această linie va eșua.</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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function xs(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function Fs(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function Hs(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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Ys(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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function qs(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,p){j(s,l,p),a=!0},i(l){a||(M(s.$$.fragment,l),a=!0)},o(l){o(s.$$.fragment,l),a=!1},d(l){f(s,l)}}}function Ls(m){let s,a="✏️ <strong>Încercați!</strong> Convertiți această listă <code>batched_ids</code> într-un tensor și treceți-o prin modelul dumneavoastră. Verificați dacă obțineți aceleași logits ca înainte (dar de două ori)!";return{c(){s=U("p"),s.innerHTML=a},l(l){s=J(l,"P",{"data-svelte-h":!0}),T(s)!=="svelte-3tzcvk"&&(s.innerHTML=a)},m(l,p){r(l,s,p)},p:$s,d(l){l&&i(s)}}}function Ks(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function Ps(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function Os(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function et(m){let s,a,l,p;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=u(),d(l.$$.fragment)},l(t){b(s.$$.fragment,t),a=c(t),b(l.$$.fragment,t)},m(t,y){j(s,t,y),r(t,a,y),j(l,t,y),p=!0},i(t){p||(M(s.$$.fragment,t),M(l.$$.fragment,t),p=!0)},o(t){o(s.$$.fragment,t),o(l.$$.fragment,t),p=!1},d(t){t&&i(a),f(s,t),f(l,t)}}}function lt(m){let s,a="✏️ <strong>Încercați!</strong> Aplicați manual tokenizarea pe cele două propoziții utilizate în secțiunea 2 (“I’ve been waiting for a HuggingFace course my whole life.” și “I hate this so much!”). Treceți-le prin model și verificați dacă obțineți aceeași logiți ca în secțiunea 2. Acum grupați-le împreună folosind token-ul de padding, apoi creați masca de atenție corespunzătoare. Verificați dacă obțineți aceleași rezultate atunci când parcurgeți modelul!";return{c(){s=U("p"),s.innerHTML=a},l(l){s=J(l,"P",{"data-svelte-h":!0}),T(s)!=="svelte-16ntdo2"&&(s.innerHTML=a)},m(l,p){r(l,s,p)},p:$s,d(l){l&&i(s)}}}function st(m){let s,a,l,p,t,y,B,Xe,x,Be,h,k,ve,_,$,Ne,F,Ql="În secțiunea anterioară, am explorat cel mai simplu caz de utilizare: realizarea de inferențe pe o singură secvență scurtă. Cu toate acestea, apar deja unele întrebări:",xe,H,zl="<li>Cum gestionăm secvențe multiple?</li> <li>Cum gestionăm secvențe multiple <em>de lungimi diferite</em>?</li> <li>Indicii vocabularului sunt singurele intrări care permit unui model să funcționeze bine?</li> <li>Există o secvență prea lungă?</li>",Fe,S,Vl="Să vedem ce tipuri de probleme prezintă aceste întrebări și cum le putem rezolva folosind API-ul 🤗 Transformers.",He,Y,Se,q,El="În exercițiul anterior ați văzut cum secvențele sunt transformate în liste de numere. Să convertim această listă de numere într-un tensor și să o transmitem modelului:",Ye,I,g,Qe,L,Wl="Oh, nu! De ce a eșuat? Am urmat pașii din pipeline-ul din secțiunea 2.",qe,K,Gl="Problema este că am trimis o singură secvență către model, în timp ce modelele 🤗 Transformers așteaptă în mod implicit mai multe propoziții. Aici am încercat să facem tot ce a făcut tokenizatorul în fundal atunci când l-am aplicat unei <code>secvențe</code>. Dar, dacă vă uitați cu atenție, veți vedea că tokenizatorul nu a convertit doar lista de ID-uri de intrare într-un tensor, ci a adăugat și o dimensiune peste aceasta:",Le,A,C,ze,P,Rl="Să încercăm din nou și să adăugăm o nouă dimensiune:",Ke,Z,v,Ve,O,Dl="Imprimăm ID-urile de intrare, precum și logit-urile rezultate - iată rezultatul:",Pe,N,Q,Ee,ee,Xl="Batching-ul este acțiunea de a trimite mai multe propoziții prin model, toate odată. Dacă aveți o singură propoziție, puteți crea un lot cu o singură secvență:",Oe,le,el,se,Bl="Acesta este un batch de două secvențe identice!",ll,G,sl,te,xl="Batching-ul permite modelului să funcționeze atunci când îi furnizați mai multe secvențe. Utilizarea mai multor secvențe este la fel de simplă ca și crearea unui lot cu o singură secvență. Există însă o a doua problemă. Atunci când încercați să combinați două (sau mai multe) propoziții, acestea pot avea lungimi diferite. Dacă ați mai lucrat vreodată cu tensori, știți că aceștia trebuie să aibă o formă dreptunghiulară, deci nu veți putea converti direct lista de ID-uri de intrare într-un tensor. Pentru a rezolva această problemă, de obicei <em>umplem</em> datele de intrare.",tl,ne,nl,ae,Fl="Următoarea serie de liste nu poate fi convertită într-un tensor:",al,ie,il,re,Hl="Pentru a ocoli acest lucru, vom folosi <em>padding-ul</em> pentru ca tensorii noștri să aibă o formă dreptunghiulară. Padding-ul (umplerea datelor) asigură că toate propozițiile noastre au aceeași lungime prin adăugarea unui cuvânt special numit <em>padding token</em> la propozițiile cu mai puține valori. De exemplu, dacă aveți 10 propoziții cu 10 cuvinte și 1 propoziție cu 20 de cuvinte, padding-ul va asigura că toate propozițiile au 20 de cuvinte. În exemplul nostru, tensorul rezultat arată astfel:",rl,pe,pl,ue,Sl="ID-ul token-ului de padding poate fi găsit în <code>tokenizer.pad_token_id</code>. Să-l folosim și să trimitem cele două propoziții prin model în mod separat și grupate împreună:",ul,z,V,We,ce,Yl="Este ceva în neregulă cu logit-urile din predicțiile noastre grupate: al doilea rând ar trebui să fie identic cu logit-urile pentru a doua propoziție, dar avem valori complet diferite!",cl,oe,ql="Acest lucru se datorează faptului că principala caracteristică a modelelor Transformer sunt straturile de atenție care <em>contextualizează</em> fiecare token. Acestea vor lua în considerare token-urile de umplutură, deoarece se ocupă de toate token-urile unei secvențe. Pentru a obține același rezultat atunci când trecem propoziții individuale de diferite lungimi prin model sau atunci când trecem un batch cu aceleași propoziții și același umplutură aplicată, trebuie să spunem acelor straturi de atenție să ignore token-urile de umplutură. Acest lucru se realizează prin utilizarea unei măști de atenție (attention mask).",ol,Me,Ml,me,Ll="<em>Măștile de atenție</em> sunt tensori cu exact aceeași formă ca tensorul ID-urilor de intrare, completate cu 0 și 1: valorile 1 indică faptul că ar trebui să se acorde atenție token-urilor corespunzătoare, iar valorile 0 indică faptul că nu ar trebui să se acorde atenție token-urilor corespunzătoare (adică acestea ar trebui ignorate de straturile de atenție ale modelului).",ml,de,Kl="Să completăm exemplul anterior cu o mască de atenție:",dl,E,W,Ge,be,Pl="Acum obținem aceeași logits pentru a doua propoziție din batch.",bl,je,Ol="Observăm cum ultima valoare a celei de-a doua secvențe este un ID de padding, care este o valoare 0 în masca de atenție.",jl,R,fl,fe,yl,ye,es="Cu modelele Transformer, există o limită a lungimii secvențelor pe care le putem transmite modelelor. Majoritatea modelelor gestionează secvențe de până la 512 sau 1024 de token-uri și se vor bloca atunci când li se cere să proceseze secvențe mai lungi. Există două soluții la această problemă:",Ul,Ue,ls="<li>Utilizați un model cu o lungime de secvență acceptată mai mare.</li> <li>Trunchiați secvențele.</li>",Jl,Je,ss='Modelele au diferite lungimi de secvență acceptate, iar unele sunt specializate în tratarea secvențelor foarte lungi. <a href="https://huggingface.co/docs/transformers/model_doc/longformer" rel="nofollow">Longformer</a> este un exemplu, iar altul este <a href="https://huggingface.co/docs/transformers/model_doc/led" rel="nofollow">LED</a>. Dacă lucrați la o sarcină care necesită secvențe foarte lungi, vă recomandăm să aruncați o privire la aceste modele.',Tl,Te,ts="În caz contrar, vă recomandăm să vă trunchiați secvențele prin specificarea parametrului <code>max_sequence_length</code>:",wl,we,hl,he,kl,Re,_l;t=new Es({props:{fw:m[0]}}),B=new zs({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),x=new De({props:{title:"Gestionarea secvențelor multiple",local:"gestionarea-secvențelor-multiple",headingTag:"h1"}});const ns=[Gs,Ws],ke=[];function as(e,n){return e[0]==="pt"?0:1}h=as(m),k=ke[h]=ns[h](m);const is=[Ds,Rs],_e=[];function rs(e,n){return e[0]==="pt"?0:1}_=rs(m),$=_e[_]=is[_](m),Y=new De({props:{title:"Modelele așteaptă un batch de intrări",local:"modelele-așteaptă-un-batch-de-intrări",headingTag:"h2"}});const ps=[Bs,Xs],$e=[];function us(e,n){return e[0]==="pt"?0:1}I=us(m),g=$e[I]=ps[I](m);const cs=[Fs,xs],Ie=[];function os(e,n){return e[0]==="pt"?0:1}A=os(m),C=Ie[A]=cs[A](m);const Ms=[Ss,Hs],ge=[];function ms(e,n){return e[0]==="pt"?0:1}Z=ms(m),v=ge[Z]=Ms[Z](m);const ds=[qs,Ys],Ae=[];function bs(e,n){return e[0]==="pt"?0:1}N=bs(m),Q=Ae[N]=ds[N](m),le=new w({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new _s({props:{$$slots:{default:[Ls]},$$scope:{ctx:m}}}),ne=new De({props:{title:"Padding-ul datelor de intrare",local:"padding-ul-datelor-de-intrare",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}}),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 js=[Ps,Ks],Ce=[];function fs(e,n){return e[0]==="pt"?0:1}z=fs(m),V=Ce[z]=js[z](m),Me=new De({props:{title:"Attention masks(măști de atenție)",local:"attention-masks",headingTag:"h2"}});const ys=[et,Os],Ze=[];function Us(e,n){return e[0]==="pt"?0:1}return E=Us(m),W=Ze[E]=ys[E](m),R=new _s({props:{$$slots:{default:[lt]},$$scope:{ctx:m}}}),fe=new De({props:{title:"Secvențe mai lungi",local:"secvențe-mai-lungi",headingTag:"h2"}}),we=new w({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),he=new Vs({props:{source:"https://github.com/huggingface/course/blob/main/chapters/ro/chapter2/5.mdx"}}),{c(){s=U("meta"),a=u(),l=U("p"),p=u(),d(t.$$.fragment),y=u(),d(B.$$.fragment),Xe=u(),d(x.$$.fragment),Be=u(),k.c(),ve=u(),$.c(),Ne=u(),F=U("p"),F.textContent=Ql,xe=u(),H=U("ul"),H.innerHTML=zl,Fe=u(),S=U("p"),S.textContent=Vl,He=u(),d(Y.$$.fragment),Se=u(),q=U("p"),q.textContent=El,Ye=u(),g.c(),Qe=u(),L=U("p"),L.textContent=Wl,qe=u(),K=U("p"),K.innerHTML=Gl,Le=u(),C.c(),ze=u(),P=U("p"),P.textContent=Rl,Ke=u(),v.c(),Ve=u(),O=U("p"),O.textContent=Dl,Pe=u(),Q.c(),Ee=u(),ee=U("p"),ee.textContent=Xl,Oe=u(),d(le.$$.fragment),el=u(),se=U("p"),se.textContent=Bl,ll=u(),d(G.$$.fragment),sl=u(),te=U("p"),te.innerHTML=xl,tl=u(),d(ne.$$.fragment),nl=u(),ae=U("p"),ae.textContent=Fl,al=u(),d(ie.$$.fragment),il=u(),re=U("p"),re.innerHTML=Hl,rl=u(),d(pe.$$.fragment),pl=u(),ue=U("p"),ue.innerHTML=Sl,ul=u(),V.c(),We=u(),ce=U("p"),ce.textContent=Yl,cl=u(),oe=U("p"),oe.innerHTML=ql,ol=u(),d(Me.$$.fragment),Ml=u(),me=U("p"),me.innerHTML=Ll,ml=u(),de=U("p"),de.textContent=Kl,dl=u(),W.c(),Ge=u(),be=U("p"),be.textContent=Pl,bl=u(),je=U("p"),je.textContent=Ol,jl=u(),d(R.$$.fragment),fl=u(),d(fe.$$.fragment),yl=u(),ye=U("p"),ye.textContent=es,Ul=u(),Ue=U("ul"),Ue.innerHTML=ls,Jl=u(),Je=U("p"),Je.innerHTML=ss,Tl=u(),Te=U("p"),Te.innerHTML=ts,wl=u(),d(we.$$.fragment),hl=u(),d(he.$$.fragment),kl=u(),Re=U("p"),this.h()},l(e){const n=Ns("svelte-u9bgzb",document.head);s=J(n,"META",{name:!0,content:!0}),n.forEach(i),a=c(e),l=J(e,"P",{}),hs(l).forEach(i),p=c(e),b(t.$$.fragment,e),y=c(e),b(B.$$.fragment,e),Xe=c(e),b(x.$$.fragment,e),Be=c(e),k.l(e),ve=c(e),$.l(e),Ne=c(e),F=J(e,"P",{"data-svelte-h":!0}),T(F)!=="svelte-4ill58"&&(F.textContent=Ql),xe=c(e),H=J(e,"UL",{"data-svelte-h":!0}),T(H)!=="svelte-hvd40"&&(H.innerHTML=zl),Fe=c(e),S=J(e,"P",{"data-svelte-h":!0}),T(S)!=="svelte-v1se4v"&&(S.textContent=Vl),He=c(e),b(Y.$$.fragment,e),Se=c(e),q=J(e,"P",{"data-svelte-h":!0}),T(q)!=="svelte-aln8pl"&&(q.textContent=El),Ye=c(e),g.l(e),Qe=c(e),L=J(e,"P",{"data-svelte-h":!0}),T(L)!=="svelte-12dxwu1"&&(L.textContent=Wl),qe=c(e),K=J(e,"P",{"data-svelte-h":!0}),T(K)!=="svelte-yekvch"&&(K.innerHTML=Gl),Le=c(e),C.l(e),ze=c(e),P=J(e,"P",{"data-svelte-h":!0}),T(P)!=="svelte-wbsm1t"&&(P.textContent=Rl),Ke=c(e),v.l(e),Ve=c(e),O=J(e,"P",{"data-svelte-h":!0}),T(O)!=="svelte-1xr9u3w"&&(O.textContent=Dl),Pe=c(e),Q.l(e),Ee=c(e),ee=J(e,"P",{"data-svelte-h":!0}),T(ee)!=="svelte-i79i9q"&&(ee.textContent=Xl),Oe=c(e),b(le.$$.fragment,e),el=c(e),se=J(e,"P",{"data-svelte-h":!0}),T(se)!=="svelte-psj20t"&&(se.textContent=Bl),ll=c(e),b(G.$$.fragment,e),sl=c(e),te=J(e,"P",{"data-svelte-h":!0}),T(te)!=="svelte-mkjens"&&(te.innerHTML=xl),tl=c(e),b(ne.$$.fragment,e),nl=c(e),ae=J(e,"P",{"data-svelte-h":!0}),T(ae)!=="svelte-nyd9xy"&&(ae.textContent=Fl),al=c(e),b(ie.$$.fragment,e),il=c(e),re=J(e,"P",{"data-svelte-h":!0}),T(re)!=="svelte-7ltdaf"&&(re.innerHTML=Hl),rl=c(e),b(pe.$$.fragment,e),pl=c(e),ue=J(e,"P",{"data-svelte-h":!0}),T(ue)!=="svelte-qx46ym"&&(ue.innerHTML=Sl),ul=c(e),V.l(e),We=c(e),ce=J(e,"P",{"data-svelte-h":!0}),T(ce)!=="svelte-7q00i2"&&(ce.textContent=Yl),cl=c(e),oe=J(e,"P",{"data-svelte-h":!0}),T(oe)!=="svelte-1wm1min"&&(oe.innerHTML=ql),ol=c(e),b(Me.$$.fragment,e),Ml=c(e),me=J(e,"P",{"data-svelte-h":!0}),T(me)!=="svelte-1pqiu7n"&&(me.innerHTML=Ll),ml=c(e),de=J(e,"P",{"data-svelte-h":!0}),T(de)!=="svelte-1cpev44"&&(de.textContent=Kl),dl=c(e),W.l(e),Ge=c(e),be=J(e,"P",{"data-svelte-h":!0}),T(be)!=="svelte-14al49h"&&(be.textContent=Pl),bl=c(e),je=J(e,"P",{"data-svelte-h":!0}),T(je)!=="svelte-1w97x9s"&&(je.textContent=Ol),jl=c(e),b(R.$$.fragment,e),fl=c(e),b(fe.$$.fragment,e),yl=c(e),ye=J(e,"P",{"data-svelte-h":!0}),T(ye)!=="svelte-106z6ta"&&(ye.textContent=es),Ul=c(e),Ue=J(e,"UL",{"data-svelte-h":!0}),T(Ue)!=="svelte-kfcj30"&&(Ue.innerHTML=ls),Jl=c(e),Je=J(e,"P",{"data-svelte-h":!0}),T(Je)!=="svelte-1tld82w"&&(Je.innerHTML=ss),Tl=c(e),Te=J(e,"P",{"data-svelte-h":!0}),T(Te)!=="svelte-1p4ewle"&&(Te.innerHTML=ts),wl=c(e),b(we.$$.fragment,e),hl=c(e),b(he.$$.fragment,e),kl=c(e),Re=J(e,"P",{}),hs(Re).forEach(i),this.h()},h(){ks(s,"name","hf:doc:metadata"),ks(s,"content",tt)},m(e,n){Qs(document.head,s),r(e,a,n),r(e,l,n),r(e,p,n),j(t,e,n),r(e,y,n),j(B,e,n),r(e,Xe,n),j(x,e,n),r(e,Be,n),ke[h].m(e,n),r(e,ve,n),_e[_].m(e,n),r(e,Ne,n),r(e,F,n),r(e,xe,n),r(e,H,n),r(e,Fe,n),r(e,S,n),r(e,He,n),j(Y,e,n),r(e,Se,n),r(e,q,n),r(e,Ye,n),$e[I].m(e,n),r(e,Qe,n),r(e,L,n),r(e,qe,n),r(e,K,n),r(e,Le,n),Ie[A].m(e,n),r(e,ze,n),r(e,P,n),r(e,Ke,n),ge[Z].m(e,n),r(e,Ve,n),r(e,O,n),r(e,Pe,n),Ae[N].m(e,n),r(e,Ee,n),r(e,ee,n),r(e,Oe,n),j(le,e,n),r(e,el,n),r(e,se,n),r(e,ll,n),j(G,e,n),r(e,sl,n),r(e,te,n),r(e,tl,n),j(ne,e,n),r(e,nl,n),r(e,ae,n),r(e,al,n),j(ie,e,n),r(e,il,n),r(e,re,n),r(e,rl,n),j(pe,e,n),r(e,pl,n),r(e,ue,n),r(e,ul,n),Ce[z].m(e,n),r(e,We,n),r(e,ce,n),r(e,cl,n),r(e,oe,n),r(e,ol,n),j(Me,e,n),r(e,Ml,n),r(e,me,n),r(e,ml,n),r(e,de,n),r(e,dl,n),Ze[E].m(e,n),r(e,Ge,n),r(e,be,n),r(e,bl,n),r(e,je,n),r(e,jl,n),j(R,e,n),r(e,fl,n),j(fe,e,n),r(e,yl,n),r(e,ye,n),r(e,Ul,n),r(e,Ue,n),r(e,Jl,n),r(e,Je,n),r(e,Tl,n),r(e,Te,n),r(e,wl,n),j(we,e,n),r(e,hl,n),j(he,e,n),r(e,kl,n),r(e,Re,n),_l=!0},p(e,[n]){const Js={};n&1&&(Js.fw=e[0]),t.$set(Js);let $l=h;h=as(e),h!==$l&&(X(),o(ke[$l],1,1,()=>{ke[$l]=null}),D(),k=ke[h],k||(k=ke[h]=ns[h](e),k.c()),M(k,1),k.m(ve.parentNode,ve));let Il=_;_=rs(e),_!==Il&&(X(),o(_e[Il],1,1,()=>{_e[Il]=null}),D(),$=_e[_],$||($=_e[_]=is[_](e),$.c()),M($,1),$.m(Ne.parentNode,Ne));let gl=I;I=us(e),I!==gl&&(X(),o($e[gl],1,1,()=>{$e[gl]=null}),D(),g=$e[I],g||(g=$e[I]=ps[I](e),g.c()),M(g,1),g.m(Qe.parentNode,Qe));let Al=A;A=os(e),A!==Al&&(X(),o(Ie[Al],1,1,()=>{Ie[Al]=null}),D(),C=Ie[A],C||(C=Ie[A]=cs[A](e),C.c()),M(C,1),C.m(ze.parentNode,ze));let Cl=Z;Z=ms(e),Z!==Cl&&(X(),o(ge[Cl],1,1,()=>{ge[Cl]=null}),D(),v=ge[Z],v||(v=ge[Z]=Ms[Z](e),v.c()),M(v,1),v.m(Ve.parentNode,Ve));let Zl=N;N=bs(e),N!==Zl&&(X(),o(Ae[Zl],1,1,()=>{Ae[Zl]=null}),D(),Q=Ae[N],Q||(Q=Ae[N]=ds[N](e),Q.c()),M(Q,1),Q.m(Ee.parentNode,Ee));const Ts={};n&2&&(Ts.$$scope={dirty:n,ctx:e}),G.$set(Ts);let vl=z;z=fs(e),z!==vl&&(X(),o(Ce[vl],1,1,()=>{Ce[vl]=null}),D(),V=Ce[z],V||(V=Ce[z]=js[z](e),V.c()),M(V,1),V.m(We.parentNode,We));let Nl=E;E=Us(e),E!==Nl&&(X(),o(Ze[Nl],1,1,()=>{Ze[Nl]=null}),D(),W=Ze[E],W||(W=Ze[E]=ys[E](e),W.c()),M(W,1),W.m(Ge.parentNode,Ge));const ws={};n&2&&(ws.$$scope={dirty:n,ctx:e}),R.$set(ws)},i(e){_l||(M(t.$$.fragment,e),M(B.$$.fragment,e),M(x.$$.fragment,e),M(k),M($),M(Y.$$.fragment,e),M(g),M(C),M(v),M(Q),M(le.$$.fragment,e),M(G.$$.fragment,e),M(ne.$$.fragment,e),M(ie.$$.fragment,e),M(pe.$$.fragment,e),M(V),M(Me.$$.fragment,e),M(W),M(R.$$.fragment,e),M(fe.$$.fragment,e),M(we.$$.fragment,e),M(he.$$.fragment,e),_l=!0)},o(e){o(t.$$.fragment,e),o(B.$$.fragment,e),o(x.$$.fragment,e),o(k),o($),o(Y.$$.fragment,e),o(g),o(C),o(v),o(Q),o(le.$$.fragment,e),o(G.$$.fragment,e),o(ne.$$.fragment,e),o(ie.$$.fragment,e),o(pe.$$.fragment,e),o(V),o(Me.$$.fragment,e),o(W),o(R.$$.fragment,e),o(fe.$$.fragment,e),o(we.$$.fragment,e),o(he.$$.fragment,e),_l=!1},d(e){e&&(i(a),i(l),i(p),i(y),i(Xe),i(Be),i(ve),i(Ne),i(F),i(xe),i(H),i(Fe),i(S),i(He),i(Se),i(q),i(Ye),i(Qe),i(L),i(qe),i(K),i(Le),i(ze),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(te),i(tl),i(nl),i(ae),i(al),i(il),i(re),i(rl),i(pl),i(ue),i(ul),i(We),i(ce),i(cl),i(oe),i(ol),i(Ml),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(Ul),i(Ue),i(Jl),i(Je),i(Tl),i(Te),i(wl),i(hl),i(kl),i(Re)),i(s),f(t,e),f(B,e),f(x,e),ke[h].d(e),_e[_].d(e),f(Y,e),$e[I].d(e),Ie[A].d(e),ge[Z].d(e),Ae[N].d(e),f(le,e),f(G,e),f(ne,e),f(ie,e),f(pe,e),Ce[z].d(e),f(Me,e),Ze[E].d(e),f(R,e),f(fe,e),f(we,e),f(he,e)}}}const tt='{"title":"Gestionarea secvențelor multiple","local":"gestionarea-secvențelor-multiple","sections":[{"title":"Modelele așteaptă un batch de intrări","local":"modelele-așteaptă-un-batch-de-intrări","sections":[],"depth":2},{"title":"Padding-ul datelor de intrare","local":"padding-ul-datelor-de-intrare","sections":[],"depth":2},{"title":"Attention masks(măști de atenție)","local":"attention-masks","sections":[],"depth":2},{"title":"Secvențe mai lungi","local":"secvențe-mai-lungi","sections":[],"depth":2}],"depth":1}';function nt(m,s,a){let l="pt";return Cs(()=>{const p=new URLSearchParams(window.location.search);a(0,l=p.get("fw")||"pt")}),[l]}class mt extends Zs{constructor(s){super(),vs(this,s,nt,st,As,{})}}export{mt as component};
