import{s as Qs,o as Ns,n as $s}from"../chunks/scheduler.cc52f4b9.js";import{S as As,i as Zs,e as d,s as i,c as b,h as Vs,a as J,d as p,b as u,f as ws,g as j,j as h,k as ks,l as gs,m as M,n as y,o as c,u as v,t as m,p as U,v as B}from"../chunks/index.ccfa71ad.js";import{T as _s}from"../chunks/Tip.b150ffa7.js";import{C as Es,H as vl,E as Rs}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.bf6e17b3.js";import{Y as Cs}from"../chunks/Youtube.6232240b.js";import{C as T}from"../chunks/CodeBlock.d683ceb4.js";import{C as Is}from"../chunks/CourseFloatingBanner.23e5afab.js";import{F as Ws}from"../chunks/FrameworkSwitchCourse.4d190e14.js";function zs(o){let s,a;return s=new Is({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_tf.ipynb"}]}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Gs(o){let s,a;return s=new Is({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter2/section5_pt.ipynb"}]}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Fs(o){let s,a;return s=new Cs({props:{id:"ROxrFOEbsQE"}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function vs(o){let s,a;return s=new Cs({props:{id:"M6adb1j2jPI"}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Bs(o){let s,a,e,r;return s=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIudG9rZW5pemUoc2VxdWVuY2UpJTBBaWRzJTIwJTNEJTIwdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyh0b2tlbnMpJTBBaW5wdXRfaWRzJTIwJTNEJTIwdGYuY29uc3RhbnQoaWRzKSUwQSUyMyUyMCVFQyU5RCVCNCUyMCVFQyVCRCU5NCVFQiU5MyU5QyVFQiU4QSU5NCUyMCVFQyU4QiVBNCVFRCU5NiU4OSVFQiU5MCU5OCVFQyVBNyU4MCUyMCVFQyU5NSU4QSVFQyU5RCU4NCUyMCVFQSVCMiU4MyVFQyU5RSU4NSVFQiU4QiU4OCVFQiU4QiVBNC4lMEFtb2RlbChpbnB1dF9pZHMp",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = tf.constant(ids)
<span class="hljs-comment"># 이 코드는 실행되지 않을 것입니다.</span>
model(input_ids)`,wrap:!1}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function Xs(o){let s,a,e,r;return s=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEFpbnB1dF9pZHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoaWRzKSUwQSUyMyUyMCVFQyU5RCVCNCUyMCVFQyVCRCU5NCVFQiU5MyU5QyVFQiU4QSU5NCUyMCVFQyU4QiVBNCVFRCU5NiU4OSVFQiU5MCU5OCVFQyVBNyU4MCUyMCVFQyU5NSU4QSVFQyU5RCU4NCUyMCVFQSVCMiU4MyVFQyU5RSU4NSVFQiU4QiU4OCVFQiU4QiVBNC4lMEFtb2RlbChpbnB1dF9pZHMp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = torch.tensor(ids)
<span class="hljs-comment"># 이 코드는 실행되지 않을 것입니다.</span>
model(input_ids)`,wrap:!1}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function Ds(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function Hs(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function xs(o){let s,a;return s=new T({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBJTBBc2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIudG9rZW5pemUoc2VxdWVuY2UpJTBBaWRzJTIwJTNEJTIwdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyh0b2tlbnMpJTBBJTBBaW5wdXRfaWRzJTIwJTNEJTIwdGYuY29uc3RhbnQoJTVCaWRzJTVEKSUwQXByaW50KCUyMklucHV0JTIwSURzJTNBJTIyJTJDJTIwaW5wdXRfaWRzKSUwQSUwQW91dHB1dCUyMCUzRCUyMG1vZGVsKGlucHV0X2lkcyklMEFwcmludCglMjJMb2dpdHMlM0ElMjIlMkMlMjBvdXRwdXQubG9naXRzKQ==",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

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

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

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Ss(o){let s,a;return s=new T({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFzZXF1ZW5jZSUyMCUzRCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEElMEFpbnB1dF9pZHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCaWRzJTVEKSUwQXByaW50KCUyMklucHV0JTIwSURzJTNBJTIyJTJDJTIwaW5wdXRfaWRzKSUwQSUwQW91dHB1dCUyMCUzRCUyMG1vZGVsKGlucHV0X2lkcyklMEFwcmludCglMjJMb2dpdHMlM0ElMjIlMkMlMjBvdXRwdXQubG9naXRzKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)

sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

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

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

output = model(input_ids)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Logits:&quot;</span>, output.logits)`,wrap:!1}}),{c(){b(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Ys(o){let s,a;return s=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(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function qs(o){let s,a;return s=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(s.$$.fragment)},l(e){j(s.$$.fragment,e)},m(e,r){y(s,e,r),a=!0},i(e){a||(m(s.$$.fragment,e),a=!0)},o(e){c(s.$$.fragment,e),a=!1},d(e){U(s,e)}}}function Ls(o){let s,a="✏️ <strong>직접 해보세요!</strong> 이 <code>batched_ids</code> 리스트를 텐서로 변환하고 모델로 전달해보세요. 이전에 얻은 로짓과 동일한 결과를 얻는지 확인해보세요. (개수는 두 개여야 합니다!)";return{c(){s=d("p"),s.innerHTML=a},l(e){s=J(e,"P",{"data-svelte-h":!0}),h(s)!=="svelte-a98m1d"&&(s.innerHTML=a)},m(e,r){M(e,s,r)},p:$s,d(e){e&&p(s)}}}function Ks(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function Ps(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function Os(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function lt(o){let s,a,e,r;return s=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}}),e=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(s.$$.fragment),a=i(),b(e.$$.fragment)},l(t){j(s.$$.fragment,t),a=u(t),j(e.$$.fragment,t)},m(t,f){y(s,t,f),M(t,a,f),y(e,t,f),r=!0},i(t){r||(m(s.$$.fragment,t),m(e.$$.fragment,t),r=!0)},o(t){c(s.$$.fragment,t),c(e.$$.fragment,t),r=!1},d(t){t&&p(a),U(s,t),U(e,t)}}}function et(o){let s,a="✏️ <strong>직접 해보세요!</strong> 2장에서 사용한 두 개의 문장(“I’ve been waiting for a HuggingFace course my whole life.” and “I hate this so much!“)을 이용해 직접 토큰화를 적용해보세요. 토큰화 결과를 모델에 넘기고 2장에서 얻은 것과 동일한 로짓을 얻었는지 확인해보세요. 이제 Now batch them together using the padding token, then create the proper attention mask. Check that you obtain the same results when going through the model!";return{c(){s=d("p"),s.innerHTML=a},l(e){s=J(e,"P",{"data-svelte-h":!0}),h(s)!=="svelte-1lj13kq"&&(s.innerHTML=a)},m(e,r){M(e,s,r)},p:$s,d(e){e&&p(s)}}}function st(o){let s,a,e,r,t,f,X,Bl,D,Xl,w,k,Zl,_,$,Vl,H,ge="이전 섹션에서, 우리는 가장 간단한 사용 예시를 확인했습니다. 길이가 짧은 단일 시퀀스에 대한 추론을 수행했습니다. 그러나 이미 몇 가지 궁금증이 생깁니다.",Dl,x,Ee="<li>여러 개의 시퀀스는 어떻게 처리하나요?</li> <li><em>서로 다른 길이</em>를 갖는 다중 시퀀스를 어떻게 처리하나요?</li> <li>단어 사전의 인덱스가 모델이 잘 작동하게 하는 유일한 입력인가요?</li> <li>엄청 긴 시퀀스를 처리하는 방법이 있나요?</li>",Hl,S,Re="이러한 질문들이 제기하는 문제에 대해 알아보고, 🤗 Transformers API를 이용해 이 문제들을 어떻게 해결할 수 있는지 살펴봅시다.",xl,Y,Sl,q,We="우리는 이전 실습에서 시퀀스가 숫자 리스트로 어떻게 바뀌는지 확인했습니다. 이 숫자 리스트를 텐서로 바꾸고 모델로 보내봅시다.:",Yl,C,I,gl,L,ze="이런! 2장의 파이프라인을 순서대로 따라했는데 왜 실행되지 않는 걸까요?",ql,K,Ge="🤗 Transformers 모델은 기본적으로 여러 개의 문장을 입력으로 받는데 하나의 시퀀스만을 모델에 넘겨줬기 때문에 발생하는 문제입니다. 여기서 우리는 토크나이저를 <code>시퀀스</code>에 적용했을 때 뒤에서 일어나고 있는 모든 일을 수행하려고 했습니다. 하지만 자세히 보면, 토크나이저가 입력 ID 리스트를 텐서로 바꿨을 뿐만 아니라 차원도 추가한 것을 알 수 있습니다.",Ll,Q,N,El,P,Fe="새로운 차원을 추가해서 다시 시도해봅시다.",Kl,A,Z,Rl,O,ve="입력 ID와 결과 로짓을 출력한 결과입니다.",Pl,V,g,Wl,ll,Be="<em>배치</em>는 한 번에 여러 개의 문장을 모델로 보내는 방법입니다. 만약 단 한 개의 문장을 가지고 있다면 한 문장을 위한 배치를 만들 수 있습니다.",Ol,el,le,sl,Xe="동일한 문장 2개로 만든 배치입니다!",ee,G,se,tl,De="배치는 여러 개의 문장을 모델로 넘겼을 때도 모델이 작동하게 합니다. 다중 시퀀스를 사용하는 것은 단일 시퀀스로 배치를 만드는 것만큼 간단합니다. 하지만 두 번째 문제가 있습니다. 두 개 이상의 문장을 배치로 만드려고 할 때, 그 문장들은 아마 다른 길이를 가지고 있을 것입니다. 이전에 텐서를 다뤄본 사람이라면, 텐서의 형태가 직사각형이어야 한다는 것을 알고 있습니다. 문장 길이가 다르면 입력 ID 리스트를 텐서로 바로 변환할 수 없습니다. 이 문제를 해결하기 위해, 일반적으로 입력에 <em>패드</em>를 추가합니다.",te,nl,ne,al,He="아래 보이는 리스트는 텐서로 변환될 수 없습니다.",ae,pl,pe,Ml,xe="<em>패딩</em>을 이용해 텐서가 직사각형 형태를 가질 수 있게 하면 이 문제를 해결할 수 있습니다. 패딩은 길이가 짧은 문장에 <em>패딩 토큰</em>이라고 불리는 특별한 토큰을 추가함으로써 모든 문장이 같은 길이를 갖게 합니다. 10개의 단어로 이루어진 문장 10개와 20개의 단어로 이루어진 문장 1개를 가지고 있다고 가정한다면, 패딩은 모든 문장이 20개의 단어를 갖게 하는 역할을 합니다. 우리가 사용하는 예시에서 결과 텐서는 다음과 같습니다.",Me,rl,re,il,Se="패딩 토큰의 ID는 <code>tokenizer.pad_token_id</code> 를 통해 확인할 수 있습니다. 이걸 사용해서 두 문장을 각각 모델로 보내고 하나의 배치로 만들어 봅시다.",ie,E,R,zl,ul,Ye="배치되어 있는 예측 결과의 로짓이 뭔가 잘못된 것 같습니다. 두 번째 행은 두 번째 문장의 로짓과 값이 같아야 하는데 완전히 다른 값을 얻었습니다!",ue,cl,qe="이것은 Transformer 모델의 핵심 기능이 각 토큰을 <em>문맥화</em>하는 어텐션 레이어이기 때문입니다. 어텐션 레이어는 시퀀스 내 모든 토큰을 처리하기 때문에 패딩 토큰도 고려합니다. 서로 다른 길이를 가지는 문장 각각을 모델로 전달했을 때와 패딩이 추가되어 길이가 같아진 문장들을 배치로 전달했을 때의 결과가 같기 위해서는 이 어텐션 레이어들에게 패딩 토큰을 무시하라고 알려주어야 합니다. 이 역할을 어텐션 마스크가 수행합니다.",ce,ml,me,ol,Le="<em>어텐션 마스크</em>는 입력 ID 텐서와 같은 크기를 같는 텐서로, 0과 1로 이루어져 있습니다. 1은 해당 토큰을 주의 깊게 봐야한다는 것을 의미하고 0은 해당 토큰을 신경 쓰지 않아도 된다는 의미입니다. (다시 말해, 0에 해당하는 토큰은 모델의 어텐션 레이어에서 무시되어야 한다는 뜻입니다.)",oe,bl,Ke="어텐션 마스크와 함께 이전 예시를 완성해봅시다.",be,W,z,Gl,jl,Pe="이제 배치 내 두 번째 문장과 동일한 로짓을 얻었습니다.",je,yl,Oe="두 번째 문장의 어텐션 마스크에서 마지막 값인 0은 패딩 ID라는 것을 잊지 마세요.",ye,F,Ue,Ul,fe,fl,ls="Transformer 모델을 사용할 때, 모델에 넘겨줄 수 있는 시퀀스 길이에 제한이 있습니다. 대부분의 모델은 최대 512개나 1024개의 토큰으로 이루어진 시퀀스를 처리할 수 있으며 더 긴 길이의 시퀀스를 처리해달라는 요청을 받으면 작동하지 않습니다. 이 문제에 대한 해결 방법은 2가지가 있습니다.",de,dl,es="<li>긴 시퀀스를 처리할 수 있는 모델을 사용하세요.</li> <li>시퀀스 길이를 최대 길이에 맞게 잘라내세요.</li>",Je,Jl,ss='모델별로 지원하는 시퀀스 길이는 다르고 몇 개의 특별한 모델은 엄청나게 긴 시퀀스를 처리할 수 있습니다. <a href="https://huggingface.co/transformers/model_doc/longformer.html" rel="nofollow">Longformer</a> 가 그 중 하나이며, <a href="https://huggingface.co/transformers/model_doc/led.html" rel="nofollow">LED</a>도 해당합니다. 만약 매우 긴 길이의 시퀀스를 다뤄야 하는 태스크를 진행하고 있다면, 두 모델을 살펴보세요.',he,hl,ts="그렇지 않으면 <code>max_sequence_length</code> 파라미터를 이용해 시퀀스 길이를 잘라내는 것이 좋습니다.",Te,Tl,we,wl,ke,Fl,_e;t=new Ws({props:{fw:o[0]}}),X=new Es({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),D=new vl({props:{title:"다중 시퀀스 처리",local:"handling-multiple-sequences",headingTag:"h1"}});const ns=[Gs,zs],kl=[];function as(l,n){return l[0]==="pt"?0:1}w=as(o),k=kl[w]=ns[w](o);const ps=[vs,Fs],_l=[];function Ms(l,n){return l[0]==="pt"?0:1}_=Ms(o),$=_l[_]=ps[_](o),Y=new vl({props:{title:"모델은 배치 입력을 기대합니다",local:"models-expect-a-batch-of-inputs",headingTag:"h2"}});const rs=[Xs,Bs],$l=[];function is(l,n){return l[0]==="pt"?0:1}C=is(o),I=$l[C]=rs[C](o);const us=[Hs,Ds],Cl=[];function cs(l,n){return l[0]==="pt"?0:1}Q=cs(o),N=Cl[Q]=us[Q](o);const ms=[Ss,xs],Il=[];function os(l,n){return l[0]==="pt"?0:1}A=os(o),Z=Il[A]=ms[A](o);const bs=[qs,Ys],Ql=[];function js(l,n){return l[0]==="pt"?0:1}V=js(o),g=Ql[V]=bs[V](o),el=new T({props:{code:"YmF0Y2hlZF9pZHMlMjAlM0QlMjAlNUJpZHMlMkMlMjBpZHMlNUQ=",highlighted:'<span class="hljs-attr">batched_ids</span> = [ids, ids]',wrap:!1}}),G=new _s({props:{$$slots:{default:[Ls]},$$scope:{ctx:o}}}),nl=new vl({props:{title:"입력에 패딩 추가하기",local:"padding-the-inputs",headingTag:"h2"}}),pl=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}}),rl=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 ys=[Ps,Ks],Nl=[];function Us(l,n){return l[0]==="pt"?0:1}E=Us(o),R=Nl[E]=ys[E](o),ml=new vl({props:{title:"어텐션 마스크",local:"attention-masks",headingTag:"h2"}});const fs=[lt,Os],Al=[];function ds(l,n){return l[0]==="pt"?0:1}return W=ds(o),z=Al[W]=fs[W](o),F=new _s({props:{$$slots:{default:[et]},$$scope:{ctx:o}}}),Ul=new vl({props:{title:"길이가 긴 시퀀스",local:"longer-sequences",headingTag:"h2"}}),Tl=new T({props:{code:"c2VxdWVuY2UlMjAlM0QlMjBzZXF1ZW5jZSU1QiUzQW1heF9zZXF1ZW5jZV9sZW5ndGglNUQ=",highlighted:"sequence = sequence[:max_sequence_length]",wrap:!1}}),wl=new Rs({props:{source:"https://github.com/huggingface/course/blob/main/chapters/ko/chapter2/5.mdx"}}),{c(){s=d("meta"),a=i(),e=d("p"),r=i(),b(t.$$.fragment),f=i(),b(X.$$.fragment),Bl=i(),b(D.$$.fragment),Xl=i(),k.c(),Zl=i(),$.c(),Vl=i(),H=d("p"),H.textContent=ge,Dl=i(),x=d("ul"),x.innerHTML=Ee,Hl=i(),S=d("p"),S.textContent=Re,xl=i(),b(Y.$$.fragment),Sl=i(),q=d("p"),q.textContent=We,Yl=i(),I.c(),gl=i(),L=d("p"),L.textContent=ze,ql=i(),K=d("p"),K.innerHTML=Ge,Ll=i(),N.c(),El=i(),P=d("p"),P.textContent=Fe,Kl=i(),Z.c(),Rl=i(),O=d("p"),O.textContent=ve,Pl=i(),g.c(),Wl=i(),ll=d("p"),ll.innerHTML=Be,Ol=i(),b(el.$$.fragment),le=i(),sl=d("p"),sl.textContent=Xe,ee=i(),b(G.$$.fragment),se=i(),tl=d("p"),tl.innerHTML=De,te=i(),b(nl.$$.fragment),ne=i(),al=d("p"),al.textContent=He,ae=i(),b(pl.$$.fragment),pe=i(),Ml=d("p"),Ml.innerHTML=xe,Me=i(),b(rl.$$.fragment),re=i(),il=d("p"),il.innerHTML=Se,ie=i(),R.c(),zl=i(),ul=d("p"),ul.textContent=Ye,ue=i(),cl=d("p"),cl.innerHTML=qe,ce=i(),b(ml.$$.fragment),me=i(),ol=d("p"),ol.innerHTML=Le,oe=i(),bl=d("p"),bl.textContent=Ke,be=i(),z.c(),Gl=i(),jl=d("p"),jl.textContent=Pe,je=i(),yl=d("p"),yl.textContent=Oe,ye=i(),b(F.$$.fragment),Ue=i(),b(Ul.$$.fragment),fe=i(),fl=d("p"),fl.textContent=ls,de=i(),dl=d("ul"),dl.innerHTML=es,Je=i(),Jl=d("p"),Jl.innerHTML=ss,he=i(),hl=d("p"),hl.innerHTML=ts,Te=i(),b(Tl.$$.fragment),we=i(),b(wl.$$.fragment),ke=i(),Fl=d("p"),this.h()},l(l){const n=Vs("svelte-u9bgzb",document.head);s=J(n,"META",{name:!0,content:!0}),n.forEach(p),a=u(l),e=J(l,"P",{}),ws(e).forEach(p),r=u(l),j(t.$$.fragment,l),f=u(l),j(X.$$.fragment,l),Bl=u(l),j(D.$$.fragment,l),Xl=u(l),k.l(l),Zl=u(l),$.l(l),Vl=u(l),H=J(l,"P",{"data-svelte-h":!0}),h(H)!=="svelte-1qjehab"&&(H.textContent=ge),Dl=u(l),x=J(l,"UL",{"data-svelte-h":!0}),h(x)!=="svelte-1p6inoo"&&(x.innerHTML=Ee),Hl=u(l),S=J(l,"P",{"data-svelte-h":!0}),h(S)!=="svelte-1hv1ziw"&&(S.textContent=Re),xl=u(l),j(Y.$$.fragment,l),Sl=u(l),q=J(l,"P",{"data-svelte-h":!0}),h(q)!=="svelte-1n6xx2z"&&(q.textContent=We),Yl=u(l),I.l(l),gl=u(l),L=J(l,"P",{"data-svelte-h":!0}),h(L)!=="svelte-ky609g"&&(L.textContent=ze),ql=u(l),K=J(l,"P",{"data-svelte-h":!0}),h(K)!=="svelte-1v3wueu"&&(K.innerHTML=Ge),Ll=u(l),N.l(l),El=u(l),P=J(l,"P",{"data-svelte-h":!0}),h(P)!=="svelte-duirzf"&&(P.textContent=Fe),Kl=u(l),Z.l(l),Rl=u(l),O=J(l,"P",{"data-svelte-h":!0}),h(O)!=="svelte-19o28sc"&&(O.textContent=ve),Pl=u(l),g.l(l),Wl=u(l),ll=J(l,"P",{"data-svelte-h":!0}),h(ll)!=="svelte-19eet6z"&&(ll.innerHTML=Be),Ol=u(l),j(el.$$.fragment,l),le=u(l),sl=J(l,"P",{"data-svelte-h":!0}),h(sl)!=="svelte-16dtipq"&&(sl.textContent=Xe),ee=u(l),j(G.$$.fragment,l),se=u(l),tl=J(l,"P",{"data-svelte-h":!0}),h(tl)!=="svelte-evtzq5"&&(tl.innerHTML=De),te=u(l),j(nl.$$.fragment,l),ne=u(l),al=J(l,"P",{"data-svelte-h":!0}),h(al)!=="svelte-1lmfvft"&&(al.textContent=He),ae=u(l),j(pl.$$.fragment,l),pe=u(l),Ml=J(l,"P",{"data-svelte-h":!0}),h(Ml)!=="svelte-ed90xc"&&(Ml.innerHTML=xe),Me=u(l),j(rl.$$.fragment,l),re=u(l),il=J(l,"P",{"data-svelte-h":!0}),h(il)!=="svelte-ni868t"&&(il.innerHTML=Se),ie=u(l),R.l(l),zl=u(l),ul=J(l,"P",{"data-svelte-h":!0}),h(ul)!=="svelte-10cs0bp"&&(ul.textContent=Ye),ue=u(l),cl=J(l,"P",{"data-svelte-h":!0}),h(cl)!=="svelte-ie9byc"&&(cl.innerHTML=qe),ce=u(l),j(ml.$$.fragment,l),me=u(l),ol=J(l,"P",{"data-svelte-h":!0}),h(ol)!=="svelte-11ozs9i"&&(ol.innerHTML=Le),oe=u(l),bl=J(l,"P",{"data-svelte-h":!0}),h(bl)!=="svelte-1ybgid6"&&(bl.textContent=Ke),be=u(l),z.l(l),Gl=u(l),jl=J(l,"P",{"data-svelte-h":!0}),h(jl)!=="svelte-nq8e4n"&&(jl.textContent=Pe),je=u(l),yl=J(l,"P",{"data-svelte-h":!0}),h(yl)!=="svelte-3f1cen"&&(yl.textContent=Oe),ye=u(l),j(F.$$.fragment,l),Ue=u(l),j(Ul.$$.fragment,l),fe=u(l),fl=J(l,"P",{"data-svelte-h":!0}),h(fl)!=="svelte-rg7wre"&&(fl.textContent=ls),de=u(l),dl=J(l,"UL",{"data-svelte-h":!0}),h(dl)!=="svelte-2ezxij"&&(dl.innerHTML=es),Je=u(l),Jl=J(l,"P",{"data-svelte-h":!0}),h(Jl)!=="svelte-jn88al"&&(Jl.innerHTML=ss),he=u(l),hl=J(l,"P",{"data-svelte-h":!0}),h(hl)!=="svelte-1ds2vx3"&&(hl.innerHTML=ts),Te=u(l),j(Tl.$$.fragment,l),we=u(l),j(wl.$$.fragment,l),ke=u(l),Fl=J(l,"P",{}),ws(Fl).forEach(p),this.h()},h(){ks(s,"name","hf:doc:metadata"),ks(s,"content",tt)},m(l,n){gs(document.head,s),M(l,a,n),M(l,e,n),M(l,r,n),y(t,l,n),M(l,f,n),y(X,l,n),M(l,Bl,n),y(D,l,n),M(l,Xl,n),kl[w].m(l,n),M(l,Zl,n),_l[_].m(l,n),M(l,Vl,n),M(l,H,n),M(l,Dl,n),M(l,x,n),M(l,Hl,n),M(l,S,n),M(l,xl,n),y(Y,l,n),M(l,Sl,n),M(l,q,n),M(l,Yl,n),$l[C].m(l,n),M(l,gl,n),M(l,L,n),M(l,ql,n),M(l,K,n),M(l,Ll,n),Cl[Q].m(l,n),M(l,El,n),M(l,P,n),M(l,Kl,n),Il[A].m(l,n),M(l,Rl,n),M(l,O,n),M(l,Pl,n),Ql[V].m(l,n),M(l,Wl,n),M(l,ll,n),M(l,Ol,n),y(el,l,n),M(l,le,n),M(l,sl,n),M(l,ee,n),y(G,l,n),M(l,se,n),M(l,tl,n),M(l,te,n),y(nl,l,n),M(l,ne,n),M(l,al,n),M(l,ae,n),y(pl,l,n),M(l,pe,n),M(l,Ml,n),M(l,Me,n),y(rl,l,n),M(l,re,n),M(l,il,n),M(l,ie,n),Nl[E].m(l,n),M(l,zl,n),M(l,ul,n),M(l,ue,n),M(l,cl,n),M(l,ce,n),y(ml,l,n),M(l,me,n),M(l,ol,n),M(l,oe,n),M(l,bl,n),M(l,be,n),Al[W].m(l,n),M(l,Gl,n),M(l,jl,n),M(l,je,n),M(l,yl,n),M(l,ye,n),y(F,l,n),M(l,Ue,n),y(Ul,l,n),M(l,fe,n),M(l,fl,n),M(l,de,n),M(l,dl,n),M(l,Je,n),M(l,Jl,n),M(l,he,n),M(l,hl,n),M(l,Te,n),y(Tl,l,n),M(l,we,n),y(wl,l,n),M(l,ke,n),M(l,Fl,n),_e=!0},p(l,[n]){const Js={};n&1&&(Js.fw=l[0]),t.$set(Js);let $e=w;w=as(l),w!==$e&&(B(),c(kl[$e],1,1,()=>{kl[$e]=null}),v(),k=kl[w],k||(k=kl[w]=ns[w](l),k.c()),m(k,1),k.m(Zl.parentNode,Zl));let Ce=_;_=Ms(l),_!==Ce&&(B(),c(_l[Ce],1,1,()=>{_l[Ce]=null}),v(),$=_l[_],$||($=_l[_]=ps[_](l),$.c()),m($,1),$.m(Vl.parentNode,Vl));let Ie=C;C=is(l),C!==Ie&&(B(),c($l[Ie],1,1,()=>{$l[Ie]=null}),v(),I=$l[C],I||(I=$l[C]=rs[C](l),I.c()),m(I,1),I.m(gl.parentNode,gl));let Qe=Q;Q=cs(l),Q!==Qe&&(B(),c(Cl[Qe],1,1,()=>{Cl[Qe]=null}),v(),N=Cl[Q],N||(N=Cl[Q]=us[Q](l),N.c()),m(N,1),N.m(El.parentNode,El));let Ne=A;A=os(l),A!==Ne&&(B(),c(Il[Ne],1,1,()=>{Il[Ne]=null}),v(),Z=Il[A],Z||(Z=Il[A]=ms[A](l),Z.c()),m(Z,1),Z.m(Rl.parentNode,Rl));let Ae=V;V=js(l),V!==Ae&&(B(),c(Ql[Ae],1,1,()=>{Ql[Ae]=null}),v(),g=Ql[V],g||(g=Ql[V]=bs[V](l),g.c()),m(g,1),g.m(Wl.parentNode,Wl));const hs={};n&2&&(hs.$$scope={dirty:n,ctx:l}),G.$set(hs);let Ze=E;E=Us(l),E!==Ze&&(B(),c(Nl[Ze],1,1,()=>{Nl[Ze]=null}),v(),R=Nl[E],R||(R=Nl[E]=ys[E](l),R.c()),m(R,1),R.m(zl.parentNode,zl));let Ve=W;W=ds(l),W!==Ve&&(B(),c(Al[Ve],1,1,()=>{Al[Ve]=null}),v(),z=Al[W],z||(z=Al[W]=fs[W](l),z.c()),m(z,1),z.m(Gl.parentNode,Gl));const Ts={};n&2&&(Ts.$$scope={dirty:n,ctx:l}),F.$set(Ts)},i(l){_e||(m(t.$$.fragment,l),m(X.$$.fragment,l),m(D.$$.fragment,l),m(k),m($),m(Y.$$.fragment,l),m(I),m(N),m(Z),m(g),m(el.$$.fragment,l),m(G.$$.fragment,l),m(nl.$$.fragment,l),m(pl.$$.fragment,l),m(rl.$$.fragment,l),m(R),m(ml.$$.fragment,l),m(z),m(F.$$.fragment,l),m(Ul.$$.fragment,l),m(Tl.$$.fragment,l),m(wl.$$.fragment,l),_e=!0)},o(l){c(t.$$.fragment,l),c(X.$$.fragment,l),c(D.$$.fragment,l),c(k),c($),c(Y.$$.fragment,l),c(I),c(N),c(Z),c(g),c(el.$$.fragment,l),c(G.$$.fragment,l),c(nl.$$.fragment,l),c(pl.$$.fragment,l),c(rl.$$.fragment,l),c(R),c(ml.$$.fragment,l),c(z),c(F.$$.fragment,l),c(Ul.$$.fragment,l),c(Tl.$$.fragment,l),c(wl.$$.fragment,l),_e=!1},d(l){l&&(p(a),p(e),p(r),p(f),p(Bl),p(Xl),p(Zl),p(Vl),p(H),p(Dl),p(x),p(Hl),p(S),p(xl),p(Sl),p(q),p(Yl),p(gl),p(L),p(ql),p(K),p(Ll),p(El),p(P),p(Kl),p(Rl),p(O),p(Pl),p(Wl),p(ll),p(Ol),p(le),p(sl),p(ee),p(se),p(tl),p(te),p(ne),p(al),p(ae),p(pe),p(Ml),p(Me),p(re),p(il),p(ie),p(zl),p(ul),p(ue),p(cl),p(ce),p(me),p(ol),p(oe),p(bl),p(be),p(Gl),p(jl),p(je),p(yl),p(ye),p(Ue),p(fe),p(fl),p(de),p(dl),p(Je),p(Jl),p(he),p(hl),p(Te),p(we),p(ke),p(Fl)),p(s),U(t,l),U(X,l),U(D,l),kl[w].d(l),_l[_].d(l),U(Y,l),$l[C].d(l),Cl[Q].d(l),Il[A].d(l),Ql[V].d(l),U(el,l),U(G,l),U(nl,l),U(pl,l),U(rl,l),Nl[E].d(l),U(ml,l),Al[W].d(l),U(F,l),U(Ul,l),U(Tl,l),U(wl,l)}}}const tt='{"title":"다중 시퀀스 처리","local":"handling-multiple-sequences","sections":[{"title":"모델은 배치 입력을 기대합니다","local":"models-expect-a-batch-of-inputs","sections":[],"depth":2},{"title":"입력에 패딩 추가하기","local":"padding-the-inputs","sections":[],"depth":2},{"title":"어텐션 마스크","local":"attention-masks","sections":[],"depth":2},{"title":"길이가 긴 시퀀스","local":"longer-sequences","sections":[],"depth":2}],"depth":1}';function nt(o,s,a){let e="pt";return Ns(()=>{const r=new URLSearchParams(window.location.search);a(0,e=r.get("fw")||"pt")}),[e]}class ot extends As{constructor(s){super(),Zs(this,s,nt,st,Qs,{})}}export{ot as component};
