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