import{s as Il,o as Zl,n as _l}from"../chunks/scheduler.37c15a92.js";import{S as vl,i as Al,g as U,s as i,r as b,A as Cl,h,f as p,c as o,j as Tl,u as j,x as J,k as wl,y as Nl,a as u,v as y,t as c,b as G,d as M,w as f,p as H}from"../chunks/index.2bf4358c.js";import{T as kl}from"../chunks/Tip.363c041f.js";import{Y as gl}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as $l}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Ql}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Re}from"../chunks/Heading.8ada512a.js";function Vl(m){let l,a;return l=new $l({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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function zl(m){let l,a;return l=new $l({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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function El(m){let l,a;return l=new gl({props:{id:"ROxrFOEbsQE"}}),{c(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Wl(m){let l,a;return l=new gl({props:{id:"M6adb1j2jPI"}}),{c(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Bl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Rl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Gl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Hl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function ql(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Dl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function xl(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(){b(l.$$.fragment)},l(s){j(l.$$.fragment,s)},m(s,r){y(l,s,r),a=!0},i(s){a||(M(l.$$.fragment,s),a=!0)},o(s){c(l.$$.fragment,s),a=!1},d(s){f(l,s)}}}function Fl(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:_l,d(s){s&&p(l)}}}function Sl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Yl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Ll(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Kl(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(){b(l.$$.fragment),a=i(),b(s.$$.fragment)},l(n){j(l.$$.fragment,n),a=o(n),j(s.$$.fragment,n)},m(n,d){y(l,n,d),u(n,a,d),y(s,n,d),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),f(l,n),f(s,n)}}}function Pl(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:_l,d(s){s&&p(l)}}}function Ol(m){let l,a,s,r,n,d,X,Ge,w,k,Ae,_,g,Ce,q,Cs="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à :",He,D,Ns="<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>",Xe,x,Qs="Voyons quels types de problèmes ces questions posent et comment nous pouvons les résoudre en utilisant l’API 🤗 <em>Transformers</em>.",qe,F,De,S,Vs=`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 :`,xe,$,I,Ne,Y,zs="Pourquoi cela a échoué ? Nous avons suivi les étapes du pipeline de la section 2.",Fe,L,Es="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 :",Se,Z,v,Qe,K,Ws="Essayons à nouveau en ajoutant une nouvelle dimension :",Ye,A,C,Ve,P,Bs="Nous affichons les identifiants d’entrée ainsi que les logits résultants. Voici la sortie :",Le,N,Q,ze,O,Rs="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 :",Ke,ee,Pe,se,Gs="Il s’agit d’un batch de deux séquences identiques !",Oe,B,es,le,Hs="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.",ss,ne,ls,te,Xs="La liste de listes suivante ne peut pas être convertie en un tenseur :",ns,ae,ts,pe,qs="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 :",as,ue,ps,re,Ds="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 :",us,V,z,Ee,ie,xs="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 !",rs,oe,Fs="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.",is,ce,os,Me,Ss="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 :",cs,me,Ys="<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,Ls="Complétons l’exemple précédent avec un masque d’attention :",ms,E,W,We,be,Ks="Nous obtenons maintenant les mêmes logits pour la deuxième phrase du batch.",ds,je,Ps="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.",bs,R,js,ye,ys,fe,Os="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 :",fs,Ue,el="<li>utiliser un modèle avec une longueur de séquence supportée plus longue,</li> <li>tronquer les séquences.</li>",Us,he,sl='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.',hs,Je,ll="Sinon, nous vous recommandons de tronquer vos séquences en spécifiant le paramètre <code>max_sequence_length</code> :",Js,Te,Ts,Be,ws;n=new Ql({props:{fw:m[0]}}),X=new Re({props:{title:"Manipulation de plusieurs séquences",local:"manipulation-de-plusieurs-séquences",headingTag:"h1"}});const nl=[zl,Vl],we=[];function tl(e,t){return e[0]==="pt"?0:1}w=tl(m),k=we[w]=nl[w](m);const al=[Wl,El],ke=[];function pl(e,t){return e[0]==="pt"?0:1}_=pl(m),g=ke[_]=al[_](m),F=new Re({props:{title:"Les modèles attendent un batch d’entrées",local:"les-modèles-attendent-un-batch-dentrées",headingTag:"h2"}});const ul=[Rl,Bl],_e=[];function rl(e,t){return e[0]==="pt"?0:1}$=rl(m),I=_e[$]=ul[$](m);const il=[Hl,Gl],ge=[];function ol(e,t){return e[0]==="pt"?0:1}Z=ol(m),v=ge[Z]=il[Z](m);const cl=[ql,Xl],$e=[];function Ml(e,t){return e[0]==="pt"?0:1}A=Ml(m),C=$e[A]=cl[A](m);const ml=[xl,Dl],Ie=[];function dl(e,t){return e[0]==="pt"?0:1}N=dl(m),Q=Ie[N]=ml[N](m),ee=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),B=new kl({props:{$$slots:{default:[Fl]},$$scope:{ctx:m}}}),ne=new Re({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 bl=[Yl,Sl],Ze=[];function jl(e,t){return e[0]==="pt"?0:1}V=jl(m),z=Ze[V]=bl[V](m),ce=new Re({props:{title:"Masques d’attention",local:"masques-dattention",headingTag:"h2"}});const yl=[Kl,Ll],ve=[];function fl(e,t){return e[0]==="pt"?0:1}return E=fl(m),W=ve[E]=yl[E](m),R=new kl({props:{$$slots:{default:[Pl]},$$scope:{ctx:m}}}),ye=new Re({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}}),{c(){l=U("meta"),a=i(),s=U("p"),r=i(),b(n.$$.fragment),d=i(),b(X.$$.fragment),Ge=i(),k.c(),Ae=i(),g.c(),Ce=i(),q=U("p"),q.textContent=Cs,He=i(),D=U("ul"),D.innerHTML=Ns,Xe=i(),x=U("p"),x.innerHTML=Qs,qe=i(),b(F.$$.fragment),De=i(),S=U("p"),S.textContent=Vs,xe=i(),I.c(),Ne=i(),Y=U("p"),Y.textContent=zs,Fe=i(),L=U("p"),L.innerHTML=Es,Se=i(),v.c(),Qe=i(),K=U("p"),K.textContent=Ws,Ye=i(),C.c(),Ve=i(),P=U("p"),P.textContent=Bs,Le=i(),Q.c(),ze=i(),O=U("p"),O.innerHTML=Rs,Ke=i(),b(ee.$$.fragment),Pe=i(),se=U("p"),se.textContent=Gs,Oe=i(),b(B.$$.fragment),es=i(),le=U("p"),le.innerHTML=Hs,ss=i(),b(ne.$$.fragment),ls=i(),te=U("p"),te.textContent=Xs,ns=i(),b(ae.$$.fragment),ts=i(),pe=U("p"),pe.innerHTML=qs,as=i(),b(ue.$$.fragment),ps=i(),re=U("p"),re.innerHTML=Ds,us=i(),z.c(),Ee=i(),ie=U("p"),ie.textContent=xs,rs=i(),oe=U("p"),oe.innerHTML=Fs,is=i(),b(ce.$$.fragment),os=i(),Me=U("p"),Me.textContent=Ss,cs=i(),me=U("ul"),me.innerHTML=Ys,Ms=i(),de=U("p"),de.textContent=Ls,ms=i(),W.c(),We=i(),be=U("p"),be.textContent=Ks,ds=i(),je=U("p"),je.innerHTML=Ps,bs=i(),b(R.$$.fragment),js=i(),b(ye.$$.fragment),ys=i(),fe=U("p"),fe.innerHTML=Os,fs=i(),Ue=U("ul"),Ue.innerHTML=el,Us=i(),he=U("p"),he.innerHTML=sl,hs=i(),Je=U("p"),Je.innerHTML=ll,Js=i(),b(Te.$$.fragment),Ts=i(),Be=U("p"),this.h()},l(e){const t=Cl("svelte-u9bgzb",document.head);l=h(t,"META",{name:!0,content:!0}),t.forEach(p),a=o(e),s=h(e,"P",{}),Tl(s).forEach(p),r=o(e),j(n.$$.fragment,e),d=o(e),j(X.$$.fragment,e),Ge=o(e),k.l(e),Ae=o(e),g.l(e),Ce=o(e),q=h(e,"P",{"data-svelte-h":!0}),J(q)!=="svelte-13pdcpq"&&(q.textContent=Cs),He=o(e),D=h(e,"UL",{"data-svelte-h":!0}),J(D)!=="svelte-1htqdau"&&(D.innerHTML=Ns),Xe=o(e),x=h(e,"P",{"data-svelte-h":!0}),J(x)!=="svelte-1cqzeo2"&&(x.innerHTML=Qs),qe=o(e),j(F.$$.fragment,e),De=o(e),S=h(e,"P",{"data-svelte-h":!0}),J(S)!=="svelte-ziencv"&&(S.textContent=Vs),xe=o(e),I.l(e),Ne=o(e),Y=h(e,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-1dc7q6m"&&(Y.textContent=zs),Fe=o(e),L=h(e,"P",{"data-svelte-h":!0}),J(L)!=="svelte-vs1vxt"&&(L.innerHTML=Es),Se=o(e),v.l(e),Qe=o(e),K=h(e,"P",{"data-svelte-h":!0}),J(K)!=="svelte-c3gb2l"&&(K.textContent=Ws),Ye=o(e),C.l(e),Ve=o(e),P=h(e,"P",{"data-svelte-h":!0}),J(P)!=="svelte-9n4sm7"&&(P.textContent=Bs),Le=o(e),Q.l(e),ze=o(e),O=h(e,"P",{"data-svelte-h":!0}),J(O)!=="svelte-1n722ay"&&(O.innerHTML=Rs),Ke=o(e),j(ee.$$.fragment,e),Pe=o(e),se=h(e,"P",{"data-svelte-h":!0}),J(se)!=="svelte-y8149p"&&(se.textContent=Gs),Oe=o(e),j(B.$$.fragment,e),es=o(e),le=h(e,"P",{"data-svelte-h":!0}),J(le)!=="svelte-1y1e589"&&(le.innerHTML=Hs),ss=o(e),j(ne.$$.fragment,e),ls=o(e),te=h(e,"P",{"data-svelte-h":!0}),J(te)!=="svelte-arsqyj"&&(te.textContent=Xs),ns=o(e),j(ae.$$.fragment,e),ts=o(e),pe=h(e,"P",{"data-svelte-h":!0}),J(pe)!=="svelte-agnh4j"&&(pe.innerHTML=qs),as=o(e),j(ue.$$.fragment,e),ps=o(e),re=h(e,"P",{"data-svelte-h":!0}),J(re)!=="svelte-1afsobr"&&(re.innerHTML=Ds),us=o(e),z.l(e),Ee=o(e),ie=h(e,"P",{"data-svelte-h":!0}),J(ie)!=="svelte-12j75sg"&&(ie.textContent=xs),rs=o(e),oe=h(e,"P",{"data-svelte-h":!0}),J(oe)!=="svelte-cqhnrg"&&(oe.innerHTML=Fs),is=o(e),j(ce.$$.fragment,e),os=o(e),Me=h(e,"P",{"data-svelte-h":!0}),J(Me)!=="svelte-1itz9ww"&&(Me.textContent=Ss),cs=o(e),me=h(e,"UL",{"data-svelte-h":!0}),J(me)!=="svelte-12tc3tz"&&(me.innerHTML=Ys),Ms=o(e),de=h(e,"P",{"data-svelte-h":!0}),J(de)!=="svelte-5cirng"&&(de.textContent=Ls),ms=o(e),W.l(e),We=o(e),be=h(e,"P",{"data-svelte-h":!0}),J(be)!=="svelte-9gsnfq"&&(be.textContent=Ks),ds=o(e),je=h(e,"P",{"data-svelte-h":!0}),J(je)!=="svelte-gbywhd"&&(je.innerHTML=Ps),bs=o(e),j(R.$$.fragment,e),js=o(e),j(ye.$$.fragment,e),ys=o(e),fe=h(e,"P",{"data-svelte-h":!0}),J(fe)!=="svelte-1oimxg5"&&(fe.innerHTML=Os),fs=o(e),Ue=h(e,"UL",{"data-svelte-h":!0}),J(Ue)!=="svelte-sv9tfg"&&(Ue.innerHTML=el),Us=o(e),he=h(e,"P",{"data-svelte-h":!0}),J(he)!=="svelte-xc8uee"&&(he.innerHTML=sl),hs=o(e),Je=h(e,"P",{"data-svelte-h":!0}),J(Je)!=="svelte-1fyxyso"&&(Je.innerHTML=ll),Js=o(e),j(Te.$$.fragment,e),Ts=o(e),Be=h(e,"P",{}),Tl(Be).forEach(p),this.h()},h(){wl(l,"name","hf:doc:metadata"),wl(l,"content",en)},m(e,t){Nl(document.head,l),u(e,a,t),u(e,s,t),u(e,r,t),y(n,e,t),u(e,d,t),y(X,e,t),u(e,Ge,t),we[w].m(e,t),u(e,Ae,t),ke[_].m(e,t),u(e,Ce,t),u(e,q,t),u(e,He,t),u(e,D,t),u(e,Xe,t),u(e,x,t),u(e,qe,t),y(F,e,t),u(e,De,t),u(e,S,t),u(e,xe,t),_e[$].m(e,t),u(e,Ne,t),u(e,Y,t),u(e,Fe,t),u(e,L,t),u(e,Se,t),ge[Z].m(e,t),u(e,Qe,t),u(e,K,t),u(e,Ye,t),$e[A].m(e,t),u(e,Ve,t),u(e,P,t),u(e,Le,t),Ie[N].m(e,t),u(e,ze,t),u(e,O,t),u(e,Ke,t),y(ee,e,t),u(e,Pe,t),u(e,se,t),u(e,Oe,t),y(B,e,t),u(e,es,t),u(e,le,t),u(e,ss,t),y(ne,e,t),u(e,ls,t),u(e,te,t),u(e,ns,t),y(ae,e,t),u(e,ts,t),u(e,pe,t),u(e,as,t),y(ue,e,t),u(e,ps,t),u(e,re,t),u(e,us,t),Ze[V].m(e,t),u(e,Ee,t),u(e,ie,t),u(e,rs,t),u(e,oe,t),u(e,is,t),y(ce,e,t),u(e,os,t),u(e,Me,t),u(e,cs,t),u(e,me,t),u(e,Ms,t),u(e,de,t),u(e,ms,t),ve[E].m(e,t),u(e,We,t),u(e,be,t),u(e,ds,t),u(e,je,t),u(e,bs,t),y(R,e,t),u(e,js,t),y(ye,e,t),u(e,ys,t),u(e,fe,t),u(e,fs,t),u(e,Ue,t),u(e,Us,t),u(e,he,t),u(e,hs,t),u(e,Je,t),u(e,Js,t),y(Te,e,t),u(e,Ts,t),u(e,Be,t),ws=!0},p(e,[t]){const Ul={};t&1&&(Ul.fw=e[0]),n.$set(Ul);let ks=w;w=tl(e),w!==ks&&(H(),c(we[ks],1,1,()=>{we[ks]=null}),G(),k=we[w],k||(k=we[w]=nl[w](e),k.c()),M(k,1),k.m(Ae.parentNode,Ae));let _s=_;_=pl(e),_!==_s&&(H(),c(ke[_s],1,1,()=>{ke[_s]=null}),G(),g=ke[_],g||(g=ke[_]=al[_](e),g.c()),M(g,1),g.m(Ce.parentNode,Ce));let gs=$;$=rl(e),$!==gs&&(H(),c(_e[gs],1,1,()=>{_e[gs]=null}),G(),I=_e[$],I||(I=_e[$]=ul[$](e),I.c()),M(I,1),I.m(Ne.parentNode,Ne));let $s=Z;Z=ol(e),Z!==$s&&(H(),c(ge[$s],1,1,()=>{ge[$s]=null}),G(),v=ge[Z],v||(v=ge[Z]=il[Z](e),v.c()),M(v,1),v.m(Qe.parentNode,Qe));let Is=A;A=Ml(e),A!==Is&&(H(),c($e[Is],1,1,()=>{$e[Is]=null}),G(),C=$e[A],C||(C=$e[A]=cl[A](e),C.c()),M(C,1),C.m(Ve.parentNode,Ve));let Zs=N;N=dl(e),N!==Zs&&(H(),c(Ie[Zs],1,1,()=>{Ie[Zs]=null}),G(),Q=Ie[N],Q||(Q=Ie[N]=ml[N](e),Q.c()),M(Q,1),Q.m(ze.parentNode,ze));const hl={};t&2&&(hl.$$scope={dirty:t,ctx:e}),B.$set(hl);let vs=V;V=jl(e),V!==vs&&(H(),c(Ze[vs],1,1,()=>{Ze[vs]=null}),G(),z=Ze[V],z||(z=Ze[V]=bl[V](e),z.c()),M(z,1),z.m(Ee.parentNode,Ee));let As=E;E=fl(e),E!==As&&(H(),c(ve[As],1,1,()=>{ve[As]=null}),G(),W=ve[E],W||(W=ve[E]=yl[E](e),W.c()),M(W,1),W.m(We.parentNode,We));const Jl={};t&2&&(Jl.$$scope={dirty:t,ctx:e}),R.$set(Jl)},i(e){ws||(M(n.$$.fragment,e),M(X.$$.fragment,e),M(k),M(g),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(z),M(ce.$$.fragment,e),M(W),M(R.$$.fragment,e),M(ye.$$.fragment,e),M(Te.$$.fragment,e),ws=!0)},o(e){c(n.$$.fragment,e),c(X.$$.fragment,e),c(k),c(g),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(z),c(ce.$$.fragment,e),c(W),c(R.$$.fragment,e),c(ye.$$.fragment,e),c(Te.$$.fragment,e),ws=!1},d(e){e&&(p(a),p(s),p(r),p(d),p(Ge),p(Ae),p(Ce),p(q),p(He),p(D),p(Xe),p(x),p(qe),p(De),p(S),p(xe),p(Ne),p(Y),p(Fe),p(L),p(Se),p(Qe),p(K),p(Ye),p(Ve),p(P),p(Le),p(ze),p(O),p(Ke),p(Pe),p(se),p(Oe),p(es),p(le),p(ss),p(ls),p(te),p(ns),p(ts),p(pe),p(as),p(ps),p(re),p(us),p(Ee),p(ie),p(rs),p(oe),p(is),p(os),p(Me),p(cs),p(me),p(Ms),p(de),p(ms),p(We),p(be),p(ds),p(je),p(bs),p(js),p(ys),p(fe),p(fs),p(Ue),p(Us),p(he),p(hs),p(Je),p(Js),p(Ts),p(Be)),p(l),f(n,e),f(X,e),we[w].d(e),ke[_].d(e),f(F,e),_e[$].d(e),ge[Z].d(e),$e[A].d(e),Ie[N].d(e),f(ee,e),f(B,e),f(ne,e),f(ae,e),f(ue,e),Ze[V].d(e),f(ce,e),ve[E].d(e),f(R,e),f(ye,e),f(Te,e)}}}const en='{"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 sn(m,l,a){let s="pt";return Zl(()=>{const r=new URLSearchParams(window.location.search);a(0,s=r.get("fw")||"pt")}),[s]}class cn extends vl{constructor(l){super(),Al(this,l,sn,Ol,Il,{})}}export{cn as component};
