import{s as vl,o as Al,n as gl}from"../chunks/scheduler.37c15a92.js";import{S as Cl,i as Nl,g as U,s as i,r as d,A as Ql,h,f as p,c as o,j as kl,u as b,x as J,k as _l,y as Vl,a as u,v as j,t as c,b as G,d as M,w as y,p as H}from"../chunks/index.2bf4358c.js";import{T as $l}from"../chunks/Tip.363c041f.js";import{Y as Il}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4e987730.js";import{C as Zl}from"../chunks/CourseFloatingBanner.6add7356.js";import{F as El}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ge,E as zl}from"../chunks/getInferenceSnippets.97e75ee2.js";function Wl(m){let l,a;return l=new Zl({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"English",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"},{label:"Français",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/fr/chapter2/section5_tf.ipynb"},{label:"English",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"},{label:"Français",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/fr/chapter2/section5_tf.ipynb"}]}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Bl(m){let l,a;return l=new Zl({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"English",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"},{label:"Français",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/fr/chapter2/section5_pt.ipynb"},{label:"English",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"},{label:"Français",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/fr/chapter2/section5_pt.ipynb"}]}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Rl(m){let l,a;return l=new Il({props:{id:"ROxrFOEbsQE"}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Gl(m){let l,a;return l=new Il({props:{id:"M6adb1j2jPI"}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Hl(m){let l,a,s,r;return l=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMjMlMjBKJ2FpJTIwYXR0ZW5kdSUyMHVuJTIwY291cnMlMjBkJUUyJTgwJTk5SHVnZ2luZ0ZhY2UlMjB0b3V0ZSUyMG1hJTIwdmllLiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEFpbnB1dF9pZHMlMjAlM0QlMjB0Zi5jb25zdGFudChpZHMpJTBBJTIzJTIwVGhpcyUyMGxpbmUlMjB3aWxsJTIwZmFpbC4lMEFtb2RlbChpbnB1dF9pZHMp",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>
<span class="hljs-comment"># J&#x27;ai attendu un cours d’HuggingFace toute ma vie.</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = tf.constant(ids)
<span class="hljs-comment"># This line will fail.</span>
model(input_ids)`,wrap:!1}}),s=new T({props:{code:"SW52YWxpZEFyZ3VtZW50RXJyb3IlM0ElMjBJbnB1dCUyMHRvJTIwcmVzaGFwZSUyMGlzJTIwYSUyMHRlbnNvciUyMHdpdGglMjAxNCUyMHZhbHVlcyUyQyUyMGJ1dCUyMHRoZSUyMHJlcXVlc3RlZCUyMHNoYXBlJTIwaGFzJTIwMTk2JTIwJTVCT3AlM0FSZXNoYXBlJTVE",highlighted:'InvalidArgumentError: Input to reshape <span class="hljs-keyword">is</span> a tensor <span class="hljs-keyword">with</span> <span class="hljs-number">14</span> values, but the requested shape has <span class="hljs-number">196</span> [Op:Reshape]',wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function Xl(m){let l,a,s,r;return l=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUyMyUyMEonYWklMjBhdHRlbmR1JTIwdW4lMjBjb3VycyUyMGQlRTIlODAlOTlIdWdnaW5nRmFjZSUyMHRvdXRlJTIwbWElMjB2aWUuJTBBJTBBdG9rZW5zJTIwJTNEJTIwdG9rZW5pemVyLnRva2VuaXplKHNlcXVlbmNlKSUwQWlkcyUyMCUzRCUyMHRva2VuaXplci5jb252ZXJ0X3Rva2Vuc190b19pZHModG9rZW5zKSUwQWlucHV0X2lkcyUyMCUzRCUyMHRvcmNoLnRlbnNvcihpZHMpJTBBJTIzJTIwQ2V0dGUlMjBsaWduZSUyMHZhJTIwJUMzJUE5Y2hvdWVyLiUwQW1vZGVsKGlucHV0X2lkcyk=",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>
<span class="hljs-comment"># J&#x27;ai attendu un cours d’HuggingFace toute ma vie.</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = torch.tensor(ids)
<span class="hljs-comment"># Cette ligne va échouer.</span>
model(input_ids)`,wrap:!1}}),s=new T({props:{code:"SW5kZXhFcnJvciUzQSUyMERpbWVuc2lvbiUyMG91dCUyMG9mJTIwcmFuZ2UlMjAoZXhwZWN0ZWQlMjB0byUyMGJlJTIwaW4lMjByYW5nZSUyMG9mJTIwJTVCLTElMkMlMjAwJTVEJTJDJTIwYnV0JTIwZ290JTIwMSk=",highlighted:'IndexError: Dimension out of <span class="hljs-built_in">range</span> (expected to be <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span> of [-<span class="hljs-number">1</span>, <span class="hljs-number">0</span>], but got <span class="hljs-number">1</span>)',wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function ql(m){let l,a,s,r;return l=new T({props:{code:"dG9rZW5pemVkX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIpJTBBcHJpbnQodG9rZW5pemVkX2lucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:`tokenized_inputs = tokenizer(sequence, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-built_in">print</span>(tokenized_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`,wrap:!1}}),s=new T({props:{code:"JTNDdGYuVGVuc29yJTNBJTIwc2hhcGUlM0QoMSUyQyUyMDE2KSUyQyUyMGR0eXBlJTNEaW50MzIlMkMlMjBudW1weSUzRCUwQWFycmF5KCU1QiU1QiUyMCUyMDEwMSUyQyUyMCUyMDEwNDUlMkMlMjAlMjAxMDA1JTJDJTIwJTIwMjMxMCUyQyUyMCUyMDIwNDIlMkMlMjAlMjAzNDAzJTJDJTIwJTIwMjAwNSUyQyUyMCUyMDEwMzclMkMlMjAxNzY2MiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDEyMTcyJTJDJTIwJTIwMjYwNyUyQyUyMCUyMDIwMjYlMkMlMjAlMjAyODc4JTJDJTIwJTIwMjE2NiUyQyUyMCUyMDEwMTIlMkMlMjAlMjAlMjAxMDIlNUQlNUQlMkMlMjBkdHlwZSUzRGludDMyKSUzRQ==",highlighted:`&lt;tf.Tensor: shape=(<span class="hljs-number">1</span>, <span class="hljs-number">16</span>), dtype=int32, numpy=
array([[  <span class="hljs-number">101</span>,  <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>,
        <span class="hljs-number">12172</span>,  <span class="hljs-number">2607</span>,  <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>,   <span class="hljs-number">102</span>]], dtype=int32)&gt;`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function Dl(m){let l,a,s,r;return l=new T({props:{code:"dG9rZW5pemVkX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBcHJpbnQodG9rZW5pemVkX2lucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:`tokenized_inputs = tokenizer(sequence, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(tokenized_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`,wrap:!1}}),s=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMCUyMDEwMSUyQyUyMCUyMDEwNDUlMkMlMjAlMjAxMDA1JTJDJTIwJTIwMjMxMCUyQyUyMCUyMDIwNDIlMkMlMjAlMjAzNDAzJTJDJTIwJTIwMjAwNSUyQyUyMCUyMDEwMzclMkMlMjAxNzY2MiUyQyUyMDEyMTcyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMjYwNyUyQyUyMCUyMDIwMjYlMkMlMjAlMjAyODc4JTJDJTIwJTIwMjE2NiUyQyUyMCUyMDEwMTIlMkMlMjAlMjAlMjAxMDIlNUQlNUQp",highlighted:`tensor([[  <span class="hljs-number">101</span>,  <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>, <span class="hljs-number">12172</span>,
          <span class="hljs-number">2607</span>,  <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>,   <span class="hljs-number">102</span>]])`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function xl(m){let l,a;return l=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMjMlMjBKJ2FpJTIwYXR0ZW5kdSUyMHVuJTIwY291cnMlMjBkJUUyJTgwJTk5SHVnZ2luZ0ZhY2UlMjB0b3V0ZSUyMG1hJTIwdmllLiUwQSUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEElMEFpbnB1dF9pZHMlMjAlM0QlMjB0Zi5jb25zdGFudCglNUJpZHMlNUQpJTBBcHJpbnQoJTIySW5wdXQlMjBJRHMlM0ElMjIlMkMlMjBpbnB1dF9pZHMpJTBBJTBBb3V0cHV0JTIwJTNEJTIwbW9kZWwoaW5wdXRfaWRzKSUwQXByaW50KCUyMkxvZ2l0cyUzQSUyMiUyQyUyMG91dHB1dC5sb2dpdHMp",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>
<span class="hljs-comment"># J&#x27;ai attendu un cours d’HuggingFace toute ma vie.</span>


tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)

input_ids = tf.constant([ids])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Input IDs:&quot;</span>, input_ids)

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Fl(m){let l,a;return l=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUyMyUyMEonYWklMjBhdHRlbmR1JTIwdW4lMjBjb3VycyUyMGQlRTIlODAlOTlIdWdnaW5nRmFjZSUyMHRvdXRlJTIwbWElMjB2aWUuJTBBJTBBJTBBdG9rZW5zJTIwJTNEJTIwdG9rZW5pemVyLnRva2VuaXplKHNlcXVlbmNlKSUwQWlkcyUyMCUzRCUyMHRva2VuaXplci5jb252ZXJ0X3Rva2Vuc190b19pZHModG9rZW5zKSUwQSUwQWlucHV0X2lkcyUyMCUzRCUyMHRvcmNoLnRlbnNvciglNUJpZHMlNUQpJTBBcHJpbnQoJTIySW5wdXQlMjBJRHMlM0ElMjIlMkMlMjBpbnB1dF9pZHMpJTBBJTBBb3V0cHV0JTIwJTNEJTIwbW9kZWwoaW5wdXRfaWRzKSUwQXByaW50KCUyMkxvZ2l0cyUzQSUyMiUyQyUyMG91dHB1dC5sb2dpdHMp",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>
<span class="hljs-comment"># J&#x27;ai attendu un cours d’HuggingFace toute ma vie.</span>


tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)

input_ids = torch.tensor([ids])
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Input IDs:&quot;</span>, input_ids)

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Sl(m){let l,a;return l=new T({props:{code:"SW5wdXQlMjBJRHMlM0ElMjB0Zi5UZW5zb3IoJTBBJTVCJTVCJTIwMTA0NSUyMCUyMDEwMDUlMjAlMjAyMzEwJTIwJTIwMjA0MiUyMCUyMDM0MDMlMjAlMjAyMDA1JTIwJTIwMTAzNyUyMDE3NjYyJTIwMTIxNzIlMjAlMjAyNjA3JTIwJTIwMjAyNiUyMCUyMDI4NzglMEElMjAlMjAlMjAyMTY2JTIwJTIwMTAxMiU1RCU1RCUyQyUyMHNoYXBlJTNEKDElMkMlMjAxNCklMkMlMjBkdHlwZSUzRGludDMyKSUwQUxvZ2l0cyUzQSUyMHRmLlRlbnNvciglNUIlNUItMi43Mjc2MjA4JTIwJTIwMi44Nzg5Mzc3JTVEJTVEJTJDJTIwc2hhcGUlM0QoMSUyQyUyMDIpJTJDJTIwZHR5cGUlM0RmbG9hdDMyKQ==",highlighted:`Input IDs: tf.Tensor(
[[ <span class="hljs-number">1045</span>  <span class="hljs-number">1005</span>  <span class="hljs-number">2310</span>  <span class="hljs-number">2042</span>  <span class="hljs-number">3403</span>  <span class="hljs-number">2005</span>  <span class="hljs-number">1037</span> <span class="hljs-number">17662</span> <span class="hljs-number">12172</span>  <span class="hljs-number">2607</span>  <span class="hljs-number">2026</span>  <span class="hljs-number">2878</span>
   <span class="hljs-number">2166</span>  <span class="hljs-number">1012</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">14</span>), dtype=int32)
Logits: tf.Tensor([[-<span class="hljs-number">2.7276208</span>  <span class="hljs-number">2.8789377</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Yl(m){let l,a;return l=new T({props:{code:"SW5wdXQlMjBJRHMlM0ElMjAlNUIlNUIlMjAxMDQ1JTJDJTIwJTIwMTAwNSUyQyUyMCUyMDIzMTAlMkMlMjAlMjAyMDQyJTJDJTIwJTIwMzQwMyUyQyUyMCUyMDIwMDUlMkMlMjAlMjAxMDM3JTJDJTIwMTc2NjIlMkMlMjAxMjE3MiUyQyUyMCUyMDI2MDclMkMlMjAyMDI2JTJDJTIwJTIwMjg3OCUyQyUyMCUyMDIxNjYlMkMlMjAlMjAxMDEyJTVEJTVEJTBBTG9naXRzJTNBJTIwJTVCJTVCLTIuNzI3NiUyQyUyMCUyMDIuODc4OSU1RCU1RA==",highlighted:`Input IDs: [[ <span class="hljs-number">1045</span>,  <span class="hljs-number">1005</span>,  <span class="hljs-number">2310</span>,  <span class="hljs-number">2042</span>,  <span class="hljs-number">3403</span>,  <span class="hljs-number">2005</span>,  <span class="hljs-number">1037</span>, <span class="hljs-number">17662</span>, <span class="hljs-number">12172</span>,  <span class="hljs-number">2607</span>, <span class="hljs-number">2026</span>,  <span class="hljs-number">2878</span>,  <span class="hljs-number">2166</span>,  <span class="hljs-number">1012</span>]]
Logits: [[-<span class="hljs-number">2.7276</span>,  <span class="hljs-number">2.8789</span>]]`,wrap:!1}}),{c(){d(l.$$.fragment)},l(s){b(l.$$.fragment,s)},m(s,r){j(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){y(l,s)}}}function Ll(m){let l,a="✏️ <strong>Essayez !</strong> Convertissez cette liste <code>batched_ids</code> en un tenseur et passez-la dans votre modèle. Vérifiez que vous obtenez les mêmes logits que précédemment (mais deux fois) !";return{c(){l=U("p"),l.innerHTML=a},l(s){l=h(s,"P",{"data-svelte-h":!0}),J(l)!=="svelte-u1wvi8"&&(l.innerHTML=a)},m(s,r){u(s,l,r)},p:gl,d(s){s&&p(l)}}}function Kl(m){let l,a,s,r;return l=new T({props:{code:"bW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UxX2lkcyUyMCUzRCUyMCU1QiU1QjIwMCUyQyUyMDIwMCUyQyUyMDIwMCU1RCU1RCUwQXNlcXVlbmNlMl9pZHMlMjAlM0QlMjAlNUIlNUIyMDAlMkMlMjAyMDAlNUQlNUQlMEFiYXRjaGVkX2lkcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU1QjIwMCUyQyUyMDIwMCUyQyUyMDIwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCU1QjIwMCUyQyUyMDIwMCUyQyUyMHRva2VuaXplci5wYWRfdG9rZW5faWQlNUQlMkMlMEElNUQlMEElMEFwcmludChtb2RlbCh0Zi5jb25zdGFudChzZXF1ZW5jZTFfaWRzKSkubG9naXRzKSUwQXByaW50KG1vZGVsKHRmLmNvbnN0YW50KHNlcXVlbmNlMl9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodGYuY29uc3RhbnQoYmF0Y2hlZF9pZHMpKS5sb2dpdHMp",highlighted:`model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence1_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
sequence2_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

<span class="hljs-built_in">print</span>(model(tf.constant(sequence1_ids)).logits)
<span class="hljs-built_in">print</span>(model(tf.constant(sequence2_ids)).logits)
<span class="hljs-built_in">print</span>(model(tf.constant(batched_ids)).logits)`,wrap:!1}}),s=new T({props:{code:"dGYuVGVuc29yKCU1QiU1QiUyMDEuNTY5MzY3OCUyMC0xLjM4OTQ1ODElNUQlNUQlMkMlMjBzaGFwZSUzRCgxJTJDJTIwMiklMkMlMjBkdHlwZSUzRGZsb2F0MzIpJTBBdGYuVGVuc29yKCU1QiU1QiUyMDAuNTgwMzAwNSUyMCUyMC0wLjQxMjUyNDI4JTVEJTVEJTJDJTIwc2hhcGUlM0QoMSUyQyUyMDIpJTJDJTIwZHR5cGUlM0RmbG9hdDMyKSUwQXRmLlRlbnNvciglMEElNUIlNUIlMjAxLjU2OTM2ODElMjAtMS4zODk0NTgyJTVEJTBBJTIwJTVCJTIwMS4zMzczNDg2JTIwLTEuMjE2MzE5MyU1RCU1RCUyQyUyMHNoYXBlJTNEKDIlMkMlMjAyKSUyQyUyMGR0eXBlJTNEZmxvYXQzMik=",highlighted:`tf.Tensor([[ <span class="hljs-number">1.5693678</span> -<span class="hljs-number">1.3894581</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)
tf.Tensor([[ <span class="hljs-number">0.5803005</span>  -<span class="hljs-number">0.41252428</span>]], shape=(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), dtype=float32)
tf.Tensor(
[[ <span class="hljs-number">1.5693681</span> -<span class="hljs-number">1.3894582</span>]
 [ <span class="hljs-number">1.3373486</span> -<span class="hljs-number">1.2163193</span>]], shape=(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function Pl(m){let l,a,s,r;return l=new T({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQXNlcXVlbmNlMV9pZHMlMjAlM0QlMjAlNUIlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlNUQlMEFzZXF1ZW5jZTJfaWRzJTIwJTNEJTIwJTVCJTVCMjAwJTJDJTIwMjAwJTVEJTVEJTBBYmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKHNlcXVlbmNlMV9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKHNlcXVlbmNlMl9pZHMpKS5sb2dpdHMpJTBBcHJpbnQobW9kZWwodG9yY2gudGVuc29yKGJhdGNoZWRfaWRzKSkubG9naXRzKQ==",highlighted:`model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence1_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
sequence2_ids = [[<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]]
batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

<span class="hljs-built_in">print</span>(model(torch.tensor(sequence1_ids)).logits)
<span class="hljs-built_in">print</span>(model(torch.tensor(sequence2_ids)).logits)
<span class="hljs-built_in">print</span>(model(torch.tensor(batched_ids)).logits)`,wrap:!1}}),s=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMDEuNTY5NCUyQyUyMC0xLjM4OTUlNUQlNUQlMkMlMjBncmFkX2ZuJTNEJTNDQWRkbW1CYWNrd2FyZCUzRSklMEF0ZW5zb3IoJTVCJTVCJTIwMC41ODAzJTJDJTIwLTAuNDEyNSU1RCU1RCUyQyUyMGdyYWRfZm4lM0QlM0NBZGRtbUJhY2t3YXJkJTNFKSUwQXRlbnNvciglNUIlNUIlMjAxLjU2OTQlMkMlMjAtMS4zODk1JTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCJTIwMS4zMzczJTJDJTIwLTEuMjE2MyU1RCU1RCUyQyUyMGdyYWRfZm4lM0QlM0NBZGRtbUJhY2t3YXJkJTNFKQ==",highlighted:`tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>]], grad_fn=&lt;AddmmBackward&gt;)
tensor([[ <span class="hljs-number">0.5803</span>, -<span class="hljs-number">0.4125</span>]], grad_fn=&lt;AddmmBackward&gt;)
tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>],
        [ <span class="hljs-number">1.3373</span>, -<span class="hljs-number">1.2163</span>]], grad_fn=&lt;AddmmBackward&gt;)`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function Ol(m){let l,a,s,r;return l=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBYXR0ZW50aW9uX21hc2slMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDElNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDAlNUQlMkMlMEElNUQlMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwodGYuY29uc3RhbnQoYmF0Y2hlZF9pZHMpJTJDJTIwYXR0ZW50aW9uX21hc2slM0R0Zi5jb25zdGFudChhdHRlbnRpb25fbWFzaykpJTBBcHJpbnQob3V0cHV0cy5sb2dpdHMp",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

attention_mask = [
    [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
    [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>],
]

outputs = model(tf.constant(batched_ids), attention_mask=tf.constant(attention_mask))
<span class="hljs-built_in">print</span>(outputs.logits)`,wrap:!1}}),s=new T({props:{code:"dGYuVGVuc29yKCUwQSU1QiU1QiUyMDEuNTY5MzY4MSUyMCUyMC0xLjM4OTQ1ODIlMjAlNUQlMEElMjAlNUIlMjAwLjU4MDMwMjElMjAlMjAtMC40MTI1MjU4NiU1RCU1RCUyQyUyMHNoYXBlJTNEKDIlMkMlMjAyKSUyQyUyMGR0eXBlJTNEZmxvYXQzMik=",highlighted:`tf.Tensor(
[[ <span class="hljs-number">1.5693681</span>  -<span class="hljs-number">1.3894582</span> ]
 [ <span class="hljs-number">0.5803021</span>  -<span class="hljs-number">0.41252586</span>]], shape=(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>), dtype=float32)`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function en(m){let l,a,s,r;return l=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkJTVEJTJDJTBBJTVEJTBBJTBBYXR0ZW50aW9uX21hc2slMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDElNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIxJTJDJTIwMSUyQyUyMDAlNUQlMkMlMEElNUQlMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwodG9yY2gudGVuc29yKGJhdGNoZWRfaWRzKSUyQyUyMGF0dGVudGlvbl9tYXNrJTNEdG9yY2gudGVuc29yKGF0dGVudGlvbl9tYXNrKSklMEFwcmludChvdXRwdXRzLmxvZ2l0cyk=",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, tokenizer.pad_token_id],
]

attention_mask = [
    [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
    [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>],
]

outputs = model(torch.tensor(batched_ids), attention_mask=torch.tensor(attention_mask))
<span class="hljs-built_in">print</span>(outputs.logits)`,wrap:!1}}),s=new T({props:{code:"dGVuc29yKCU1QiU1QiUyMDEuNTY5NCUyQyUyMC0xLjM4OTUlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUIlMjAwLjU4MDMlMkMlMjAtMC40MTI1JTVEJTVEJTJDJTIwZ3JhZF9mbiUzRCUzQ0FkZG1tQmFja3dhcmQlM0Up",highlighted:`tensor([[ <span class="hljs-number">1.5694</span>, -<span class="hljs-number">1.3895</span>],
        [ <span class="hljs-number">0.5803</span>, -<span class="hljs-number">0.4125</span>]], grad_fn=&lt;AddmmBackward&gt;)`,wrap:!1}}),{c(){d(l.$$.fragment),a=i(),d(s.$$.fragment)},l(n){b(l.$$.fragment,n),a=o(n),b(s.$$.fragment,n)},m(n,f){j(l,n,f),u(n,a,f),j(s,n,f),r=!0},i(n){r||(M(l.$$.fragment,n),M(s.$$.fragment,n),r=!0)},o(n){c(l.$$.fragment,n),c(s.$$.fragment,n),r=!1},d(n){n&&p(a),y(l,n),y(s,n)}}}function sn(m){let l,a="✏️ <strong>Essayez !</strong> Appliquez la tokenisation manuellement sur les deux phrases utilisées dans la section 2 (« <i>I’ve been waiting for a HuggingFace course my whole life.</i> » et « <i>I hate this so much!</i> »). Passez-les dans le modèle et vérifiez que vous obtenez les mêmes logits que dans la section 2. Ensuite regroupez-les en utilisant le jeton de <em>padding</em> et créez le masque d’attention approprié. Vérifiez que vous obtenez les mêmes résultats qu’en passant par le modèle !";return{c(){l=U("p"),l.innerHTML=a},l(s){l=h(s,"P",{"data-svelte-h":!0}),J(l)!=="svelte-14lslok"&&(l.innerHTML=a)},m(s,r){u(s,l,r)},p:gl,d(s){s&&p(l)}}}function ln(m){let l,a,s,r,n,f,X,He,w,k,Ce,_,$,Ne,q,Qs="Dans la section précédente, nous avons exploré le cas d’utilisation le plus simple : faire une inférence sur une seule séquence de petite longueur. Cependant, certaines questions émergent déjà :",Xe,D,Vs="<li>comment gérer de plusieurs séquences ?</li> <li>comment gérer de plusieurs séquences <em>de longueurs différentes</em> ?</li> <li>les indices du vocabulaire sont-ils les seules entrées qui permettent à un modèle de bien fonctionner ?</li> <li>existe-t-il une séquence trop longue ?</li>",qe,x,Es="Voyons quels types de problèmes ces questions posent et comment nous pouvons les résoudre en utilisant l’API 🤗 <em>Transformers</em>.",De,F,xe,S,zs=`Dans l’exercice précédent, vous avez vu comment les séquences sont traduites en listes de nombres.
Convertissons cette liste de nombres en un tenseur et envoyons-le au modèle :`,Fe,g,I,Qe,Y,Ws="Pourquoi cela a échoué ? Nous avons suivi les étapes du pipeline de la section 2.",Se,L,Bs="Le problème est que nous avons envoyé une seule séquence au modèle, alors que les modèles de l’API 🤗 <em>Transformers</em> attendent plusieurs phrases par défaut. Ici, nous avons essayé de faire ce que le <em>tokenizer</em> fait en coulisses lorsque nous l’avons appliqué à une <code>séquence</code>. Cependant si vous regardez de près, vous verrez qu’il n’a pas seulement converti la liste des identifiants d’entrée en un tenseur mais aussi ajouté une dimension par-dessus :",Ye,Z,v,Ve,K,Rs="Essayons à nouveau en ajoutant une nouvelle dimension :",Le,A,C,Ee,P,Gs="Nous affichons les identifiants d’entrée ainsi que les logits résultants. Voici la sortie :",Ke,N,Q,ze,O,Hs="Le « <em>batching</em> » est l’acte d’envoyer plusieurs phrases à travers le modèle, toutes en même temps. Si vous n’avez qu’une seule phrase, vous pouvez simplement construire un batch avec une seule séquence :",Pe,ee,Oe,se,Xs="Il s’agit d’un batch de deux séquences identiques !",es,B,ss,le,qs="Utiliser des <em>batchs</em> permet au modèle de fonctionner lorsque vous lui donnez plusieurs séquences. Utiliser plusieurs séquences est aussi simple que de construire un batch avec une seule séquence. Il y a cependant un deuxième problème. Lorsque vous essayez de regrouper deux phrases (ou plus), elles peuvent être de longueurs différentes. Si vous avez déjà travaillé avec des tenseurs, vous savez qu’ils doivent être de forme rectangulaire. Vous ne pourrez donc pas convertir directement la liste des identifiants d’entrée en un tenseur. Pour contourner ce problème, nous avons l’habitude de <em>rembourrer</em>/<em>remplir</em> (le <em>padding</em> en anglais) les entrées.",ls,ne,ns,te,Ds="La liste de listes suivante ne peut pas être convertie en un tenseur :",ts,ae,as,pe,xs="Afin de contourner ce problème, nous utilisons le <em>padding</em> pour que nos tenseurs aient une forme rectangulaire. Le <em>padding</em> permet de s’assurer que toutes nos phrases ont la même longueur en ajoutant un mot spécial appelé <em>padding token</em> aux phrases ayant moins de valeurs. Par exemple, si vous avez 10 phrases de 10 mots et 1 phrase de 20 mots, le <em>padding</em> fait en sorte que toutes les phrases aient 20 mots. Dans notre exemple, le tenseur résultant ressemble à ceci :",ps,ue,us,re,Fs="L’identifiant du jeton de <em>padding</em> peut être trouvé dans <code>tokenizer.pad_token_id</code>. Utilisons-le et envoyons nos deux phrases à travers le modèle premièrement individuellement puis en étant mises dans un même batch :",rs,V,E,We,ie,Ss="Il y a quelque chose qui ne va pas avec les logits de notre prédiction avec les séquences mises dans un même batch. La deuxième ligne devrait être la même que les logits pour la deuxième phrase, mais nous avons des valeurs complètement différentes !",is,oe,Ys="C’est parce que dans un <em>transformer</em> les couches d’attention <em>contextualisent</em> chaque <em>token</em>. Celles-ci prennent en compte les <em>tokens</em> de <em>padding</em> puisqu’elles analysent tous les <em>tokens</em> d’une séquence. Pour obtenir le même résultat lorsque l’on passe dans notre modèle des phrases individuelles de différentes longueurs ou un batch composé de mêmes phrases avec <em>padding</em>, nous devons dire à ces couches d’attention d’ignorer les jetons de <em>padding</em>. Ceci est fait en utilisant un masque d’attention.",os,ce,cs,Me,Ls="Les masques d’attention sont des tenseurs ayant exactement la même forme que le tenseur d’identifiants d’entrée, remplis de 0 et de 1 :",Ms,me,Ks="<li>1 indique que les <em>tokens</em> correspondants doivent être analysés</li> <li>0 indique que les <em>tokens</em> correspondants ne doivent pas être analysés (c’est-à-dire qu’ils doivent être ignorés par les couches d’attention du modèle).</li>",ms,de,Ps="Complétons l’exemple précédent avec un masque d’attention :",ds,z,W,Be,be,Os="Nous obtenons maintenant les mêmes logits pour la deuxième phrase du batch.",bs,je,el="Remarquez comment la dernière valeur de la deuxième séquence est un identifiant de <em>padding</em> valant 0 dans le masque d’attention.",js,R,ys,ye,fs,fe,sl="Les <em>transformers</em> acceptent en entrée que des séquences d’une longueur limitée. La plupart des modèles traitent des séquences allant jusqu’à 512 ou 1024 <em>tokens</em> et plantent lorsqu’on leur demande de traiter des séquences plus longues. Il existe deux solutions à ce problème :",Us,Ue,ll="<li>utiliser un modèle avec une longueur de séquence supportée plus longue,</li> <li>tronquer les séquences.</li>",hs,he,nl='Certains modèles sont spécialisés dans le traitement de très longues séquences comme par exemple le <a href="https://huggingface.co/transformers/model_doc/longformer.html" rel="nofollow">Longformer</a> ou le <a href="https://huggingface.co/transformers/model_doc/led.html" rel="nofollow">LED</a>. Si vous travaillez sur une tâche qui nécessite de très longues séquences, nous vous recommandons de jeter un coup d’œil à ces modèles.',Js,Je,tl="Sinon, nous vous recommandons de tronquer vos séquences en spécifiant le paramètre <code>max_sequence_length</code> :",Ts,Te,ws,we,ks,Re,_s;n=new El({props:{fw:m[0]}}),X=new Ge({props:{title:"Manipulation de plusieurs séquences",local:"manipulation-de-plusieurs-séquences",headingTag:"h1"}});const al=[Bl,Wl],ke=[];function pl(e,t){return e[0]==="pt"?0:1}w=pl(m),k=ke[w]=al[w](m);const ul=[Gl,Rl],_e=[];function rl(e,t){return e[0]==="pt"?0:1}_=rl(m),$=_e[_]=ul[_](m),F=new Ge({props:{title:"Les modèles attendent un batch d’entrées",local:"les-modèles-attendent-un-batch-dentrées",headingTag:"h2"}});const il=[Xl,Hl],$e=[];function ol(e,t){return e[0]==="pt"?0:1}g=ol(m),I=$e[g]=il[g](m);const cl=[Dl,ql],ge=[];function Ml(e,t){return e[0]==="pt"?0:1}Z=Ml(m),v=ge[Z]=cl[Z](m);const ml=[Fl,xl],Ie=[];function dl(e,t){return e[0]==="pt"?0:1}A=dl(m),C=Ie[A]=ml[A](m);const bl=[Yl,Sl],Ze=[];function jl(e,t){return e[0]==="pt"?0:1}N=jl(m),Q=Ze[N]=bl[N](m),ee=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),B=new $l({props:{$$slots:{default:[Ll]},$$scope:{ctx:m}}}),ne=new Ge({props:{title:"<i> Padding </i> des entrées",local:"i-padding-i-des-entrées",headingTag:"h2"}}),ae=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlMkMlMjAyMDAlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIyMDAlMkMlMjAyMDAlNUQlMEElNUQ=",highlighted:`batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>]
]`,wrap:!1}}),ue=new T({props:{code:"cGFkZGluZ19pZCUyMCUzRCUyMDEwMCUwQSUwQWJhdGNoZWRfaWRzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTVCMjAwJTJDJTIwMjAwJTJDJTIwMjAwJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTVCMjAwJTJDJTIwMjAwJTJDJTIwcGFkZGluZ19pZCU1RCUyQyUwQSU1RA==",highlighted:`padding_id = <span class="hljs-number">100</span>

batched_ids = [
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">200</span>],
    [<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, padding_id],
]`,wrap:!1}});const yl=[Pl,Kl],ve=[];function fl(e,t){return e[0]==="pt"?0:1}V=fl(m),E=ve[V]=yl[V](m),ce=new Ge({props:{title:"Masques d’attention",local:"masques-dattention",headingTag:"h2"}});const Ul=[en,Ol],Ae=[];function hl(e,t){return e[0]==="pt"?0:1}return z=hl(m),W=Ae[z]=Ul[z](m),R=new $l({props:{$$slots:{default:[sn]},$$scope:{ctx:m}}}),ye=new Ge({props:{title:"Séquences plus longues",local:"séquences-plus-longues",headingTag:"h2"}}),Te=new T({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),we=new zl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/fr/chapter2/5.mdx"}}),{c(){l=U("meta"),a=i(),s=U("p"),r=i(),d(n.$$.fragment),f=i(),d(X.$$.fragment),He=i(),k.c(),Ce=i(),$.c(),Ne=i(),q=U("p"),q.textContent=Qs,Xe=i(),D=U("ul"),D.innerHTML=Vs,qe=i(),x=U("p"),x.innerHTML=Es,De=i(),d(F.$$.fragment),xe=i(),S=U("p"),S.textContent=zs,Fe=i(),I.c(),Qe=i(),Y=U("p"),Y.textContent=Ws,Se=i(),L=U("p"),L.innerHTML=Bs,Ye=i(),v.c(),Ve=i(),K=U("p"),K.textContent=Rs,Le=i(),C.c(),Ee=i(),P=U("p"),P.textContent=Gs,Ke=i(),Q.c(),ze=i(),O=U("p"),O.innerHTML=Hs,Pe=i(),d(ee.$$.fragment),Oe=i(),se=U("p"),se.textContent=Xs,es=i(),d(B.$$.fragment),ss=i(),le=U("p"),le.innerHTML=qs,ls=i(),d(ne.$$.fragment),ns=i(),te=U("p"),te.textContent=Ds,ts=i(),d(ae.$$.fragment),as=i(),pe=U("p"),pe.innerHTML=xs,ps=i(),d(ue.$$.fragment),us=i(),re=U("p"),re.innerHTML=Fs,rs=i(),E.c(),We=i(),ie=U("p"),ie.textContent=Ss,is=i(),oe=U("p"),oe.innerHTML=Ys,os=i(),d(ce.$$.fragment),cs=i(),Me=U("p"),Me.textContent=Ls,Ms=i(),me=U("ul"),me.innerHTML=Ks,ms=i(),de=U("p"),de.textContent=Ps,ds=i(),W.c(),Be=i(),be=U("p"),be.textContent=Os,bs=i(),je=U("p"),je.innerHTML=el,js=i(),d(R.$$.fragment),ys=i(),d(ye.$$.fragment),fs=i(),fe=U("p"),fe.innerHTML=sl,Us=i(),Ue=U("ul"),Ue.innerHTML=ll,hs=i(),he=U("p"),he.innerHTML=nl,Js=i(),Je=U("p"),Je.innerHTML=tl,Ts=i(),d(Te.$$.fragment),ws=i(),d(we.$$.fragment),ks=i(),Re=U("p"),this.h()},l(e){const t=Ql("svelte-u9bgzb",document.head);l=h(t,"META",{name:!0,content:!0}),t.forEach(p),a=o(e),s=h(e,"P",{}),kl(s).forEach(p),r=o(e),b(n.$$.fragment,e),f=o(e),b(X.$$.fragment,e),He=o(e),k.l(e),Ce=o(e),$.l(e),Ne=o(e),q=h(e,"P",{"data-svelte-h":!0}),J(q)!=="svelte-13pdcpq"&&(q.textContent=Qs),Xe=o(e),D=h(e,"UL",{"data-svelte-h":!0}),J(D)!=="svelte-1htqdau"&&(D.innerHTML=Vs),qe=o(e),x=h(e,"P",{"data-svelte-h":!0}),J(x)!=="svelte-1cqzeo2"&&(x.innerHTML=Es),De=o(e),b(F.$$.fragment,e),xe=o(e),S=h(e,"P",{"data-svelte-h":!0}),J(S)!=="svelte-ziencv"&&(S.textContent=zs),Fe=o(e),I.l(e),Qe=o(e),Y=h(e,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-1dc7q6m"&&(Y.textContent=Ws),Se=o(e),L=h(e,"P",{"data-svelte-h":!0}),J(L)!=="svelte-vs1vxt"&&(L.innerHTML=Bs),Ye=o(e),v.l(e),Ve=o(e),K=h(e,"P",{"data-svelte-h":!0}),J(K)!=="svelte-c3gb2l"&&(K.textContent=Rs),Le=o(e),C.l(e),Ee=o(e),P=h(e,"P",{"data-svelte-h":!0}),J(P)!=="svelte-9n4sm7"&&(P.textContent=Gs),Ke=o(e),Q.l(e),ze=o(e),O=h(e,"P",{"data-svelte-h":!0}),J(O)!=="svelte-1n722ay"&&(O.innerHTML=Hs),Pe=o(e),b(ee.$$.fragment,e),Oe=o(e),se=h(e,"P",{"data-svelte-h":!0}),J(se)!=="svelte-y8149p"&&(se.textContent=Xs),es=o(e),b(B.$$.fragment,e),ss=o(e),le=h(e,"P",{"data-svelte-h":!0}),J(le)!=="svelte-1y1e589"&&(le.innerHTML=qs),ls=o(e),b(ne.$$.fragment,e),ns=o(e),te=h(e,"P",{"data-svelte-h":!0}),J(te)!=="svelte-arsqyj"&&(te.textContent=Ds),ts=o(e),b(ae.$$.fragment,e),as=o(e),pe=h(e,"P",{"data-svelte-h":!0}),J(pe)!=="svelte-agnh4j"&&(pe.innerHTML=xs),ps=o(e),b(ue.$$.fragment,e),us=o(e),re=h(e,"P",{"data-svelte-h":!0}),J(re)!=="svelte-1afsobr"&&(re.innerHTML=Fs),rs=o(e),E.l(e),We=o(e),ie=h(e,"P",{"data-svelte-h":!0}),J(ie)!=="svelte-12j75sg"&&(ie.textContent=Ss),is=o(e),oe=h(e,"P",{"data-svelte-h":!0}),J(oe)!=="svelte-cqhnrg"&&(oe.innerHTML=Ys),os=o(e),b(ce.$$.fragment,e),cs=o(e),Me=h(e,"P",{"data-svelte-h":!0}),J(Me)!=="svelte-1itz9ww"&&(Me.textContent=Ls),Ms=o(e),me=h(e,"UL",{"data-svelte-h":!0}),J(me)!=="svelte-12tc3tz"&&(me.innerHTML=Ks),ms=o(e),de=h(e,"P",{"data-svelte-h":!0}),J(de)!=="svelte-5cirng"&&(de.textContent=Ps),ds=o(e),W.l(e),Be=o(e),be=h(e,"P",{"data-svelte-h":!0}),J(be)!=="svelte-9gsnfq"&&(be.textContent=Os),bs=o(e),je=h(e,"P",{"data-svelte-h":!0}),J(je)!=="svelte-gbywhd"&&(je.innerHTML=el),js=o(e),b(R.$$.fragment,e),ys=o(e),b(ye.$$.fragment,e),fs=o(e),fe=h(e,"P",{"data-svelte-h":!0}),J(fe)!=="svelte-1oimxg5"&&(fe.innerHTML=sl),Us=o(e),Ue=h(e,"UL",{"data-svelte-h":!0}),J(Ue)!=="svelte-sv9tfg"&&(Ue.innerHTML=ll),hs=o(e),he=h(e,"P",{"data-svelte-h":!0}),J(he)!=="svelte-xc8uee"&&(he.innerHTML=nl),Js=o(e),Je=h(e,"P",{"data-svelte-h":!0}),J(Je)!=="svelte-1fyxyso"&&(Je.innerHTML=tl),Ts=o(e),b(Te.$$.fragment,e),ws=o(e),b(we.$$.fragment,e),ks=o(e),Re=h(e,"P",{}),kl(Re).forEach(p),this.h()},h(){_l(l,"name","hf:doc:metadata"),_l(l,"content",nn)},m(e,t){Vl(document.head,l),u(e,a,t),u(e,s,t),u(e,r,t),j(n,e,t),u(e,f,t),j(X,e,t),u(e,He,t),ke[w].m(e,t),u(e,Ce,t),_e[_].m(e,t),u(e,Ne,t),u(e,q,t),u(e,Xe,t),u(e,D,t),u(e,qe,t),u(e,x,t),u(e,De,t),j(F,e,t),u(e,xe,t),u(e,S,t),u(e,Fe,t),$e[g].m(e,t),u(e,Qe,t),u(e,Y,t),u(e,Se,t),u(e,L,t),u(e,Ye,t),ge[Z].m(e,t),u(e,Ve,t),u(e,K,t),u(e,Le,t),Ie[A].m(e,t),u(e,Ee,t),u(e,P,t),u(e,Ke,t),Ze[N].m(e,t),u(e,ze,t),u(e,O,t),u(e,Pe,t),j(ee,e,t),u(e,Oe,t),u(e,se,t),u(e,es,t),j(B,e,t),u(e,ss,t),u(e,le,t),u(e,ls,t),j(ne,e,t),u(e,ns,t),u(e,te,t),u(e,ts,t),j(ae,e,t),u(e,as,t),u(e,pe,t),u(e,ps,t),j(ue,e,t),u(e,us,t),u(e,re,t),u(e,rs,t),ve[V].m(e,t),u(e,We,t),u(e,ie,t),u(e,is,t),u(e,oe,t),u(e,os,t),j(ce,e,t),u(e,cs,t),u(e,Me,t),u(e,Ms,t),u(e,me,t),u(e,ms,t),u(e,de,t),u(e,ds,t),Ae[z].m(e,t),u(e,Be,t),u(e,be,t),u(e,bs,t),u(e,je,t),u(e,js,t),j(R,e,t),u(e,ys,t),j(ye,e,t),u(e,fs,t),u(e,fe,t),u(e,Us,t),u(e,Ue,t),u(e,hs,t),u(e,he,t),u(e,Js,t),u(e,Je,t),u(e,Ts,t),j(Te,e,t),u(e,ws,t),j(we,e,t),u(e,ks,t),u(e,Re,t),_s=!0},p(e,[t]){const Jl={};t&1&&(Jl.fw=e[0]),n.$set(Jl);let $s=w;w=pl(e),w!==$s&&(H(),c(ke[$s],1,1,()=>{ke[$s]=null}),G(),k=ke[w],k||(k=ke[w]=al[w](e),k.c()),M(k,1),k.m(Ce.parentNode,Ce));let gs=_;_=rl(e),_!==gs&&(H(),c(_e[gs],1,1,()=>{_e[gs]=null}),G(),$=_e[_],$||($=_e[_]=ul[_](e),$.c()),M($,1),$.m(Ne.parentNode,Ne));let Is=g;g=ol(e),g!==Is&&(H(),c($e[Is],1,1,()=>{$e[Is]=null}),G(),I=$e[g],I||(I=$e[g]=il[g](e),I.c()),M(I,1),I.m(Qe.parentNode,Qe));let Zs=Z;Z=Ml(e),Z!==Zs&&(H(),c(ge[Zs],1,1,()=>{ge[Zs]=null}),G(),v=ge[Z],v||(v=ge[Z]=cl[Z](e),v.c()),M(v,1),v.m(Ve.parentNode,Ve));let vs=A;A=dl(e),A!==vs&&(H(),c(Ie[vs],1,1,()=>{Ie[vs]=null}),G(),C=Ie[A],C||(C=Ie[A]=ml[A](e),C.c()),M(C,1),C.m(Ee.parentNode,Ee));let As=N;N=jl(e),N!==As&&(H(),c(Ze[As],1,1,()=>{Ze[As]=null}),G(),Q=Ze[N],Q||(Q=Ze[N]=bl[N](e),Q.c()),M(Q,1),Q.m(ze.parentNode,ze));const Tl={};t&2&&(Tl.$$scope={dirty:t,ctx:e}),B.$set(Tl);let Cs=V;V=fl(e),V!==Cs&&(H(),c(ve[Cs],1,1,()=>{ve[Cs]=null}),G(),E=ve[V],E||(E=ve[V]=yl[V](e),E.c()),M(E,1),E.m(We.parentNode,We));let Ns=z;z=hl(e),z!==Ns&&(H(),c(Ae[Ns],1,1,()=>{Ae[Ns]=null}),G(),W=Ae[z],W||(W=Ae[z]=Ul[z](e),W.c()),M(W,1),W.m(Be.parentNode,Be));const wl={};t&2&&(wl.$$scope={dirty:t,ctx:e}),R.$set(wl)},i(e){_s||(M(n.$$.fragment,e),M(X.$$.fragment,e),M(k),M($),M(F.$$.fragment,e),M(I),M(v),M(C),M(Q),M(ee.$$.fragment,e),M(B.$$.fragment,e),M(ne.$$.fragment,e),M(ae.$$.fragment,e),M(ue.$$.fragment,e),M(E),M(ce.$$.fragment,e),M(W),M(R.$$.fragment,e),M(ye.$$.fragment,e),M(Te.$$.fragment,e),M(we.$$.fragment,e),_s=!0)},o(e){c(n.$$.fragment,e),c(X.$$.fragment,e),c(k),c($),c(F.$$.fragment,e),c(I),c(v),c(C),c(Q),c(ee.$$.fragment,e),c(B.$$.fragment,e),c(ne.$$.fragment,e),c(ae.$$.fragment,e),c(ue.$$.fragment,e),c(E),c(ce.$$.fragment,e),c(W),c(R.$$.fragment,e),c(ye.$$.fragment,e),c(Te.$$.fragment,e),c(we.$$.fragment,e),_s=!1},d(e){e&&(p(a),p(s),p(r),p(f),p(He),p(Ce),p(Ne),p(q),p(Xe),p(D),p(qe),p(x),p(De),p(xe),p(S),p(Fe),p(Qe),p(Y),p(Se),p(L),p(Ye),p(Ve),p(K),p(Le),p(Ee),p(P),p(Ke),p(ze),p(O),p(Pe),p(Oe),p(se),p(es),p(ss),p(le),p(ls),p(ns),p(te),p(ts),p(as),p(pe),p(ps),p(us),p(re),p(rs),p(We),p(ie),p(is),p(oe),p(os),p(cs),p(Me),p(Ms),p(me),p(ms),p(de),p(ds),p(Be),p(be),p(bs),p(je),p(js),p(ys),p(fs),p(fe),p(Us),p(Ue),p(hs),p(he),p(Js),p(Je),p(Ts),p(ws),p(ks),p(Re)),p(l),y(n,e),y(X,e),ke[w].d(e),_e[_].d(e),y(F,e),$e[g].d(e),ge[Z].d(e),Ie[A].d(e),Ze[N].d(e),y(ee,e),y(B,e),y(ne,e),y(ae,e),y(ue,e),ve[V].d(e),y(ce,e),Ae[z].d(e),y(R,e),y(ye,e),y(Te,e),y(we,e)}}}const nn='{"title":"Manipulation de plusieurs séquences","local":"manipulation-de-plusieurs-séquences","sections":[{"title":"Les modèles attendent un batch d’entrées","local":"les-modèles-attendent-un-batch-dentrées","sections":[],"depth":2},{"title":"<i> Padding </i> des entrées","local":"i-padding-i-des-entrées","sections":[],"depth":2},{"title":"Masques d’attention","local":"masques-dattention","sections":[],"depth":2},{"title":"Séquences plus longues","local":"séquences-plus-longues","sections":[],"depth":2}],"depth":1}';function tn(m,l,a){let s="pt";return Al(()=>{const r=new URLSearchParams(window.location.search);a(0,s=r.get("fw")||"pt")}),[s]}class dn extends Cl{constructor(l){super(),Nl(this,l,tn,ln,vl,{})}}export{dn as component};
