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