import{s as st,o as at}from"../chunks/scheduler.cc52f4b9.js";import{S as ct,i as it,e as h,s as c,c as u,h as ot,a as T,d as e,b as i,f as Kl,g as r,j as y,k as lt,l as pt,m as s,n as m,o as p,u as tt,t as M,p as J,v as et}from"../chunks/index.9480bb2b.js";import{C as Mt,H as zl,E as ut}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.7aac1ff7.js";import{C as U}from"../chunks/CodeBlock.ca838256.js";import{C as nt}from"../chunks/CourseFloatingBanner.d5461535.js";import{F as rt}from"../chunks/FrameworkSwitchCourse.42d12053.js";function mt(j){let a,o;return a=new nt({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/vi/chapter2/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/vi/chapter2/section6_tf.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){r(a.$$.fragment,n)},m(n,b){m(a,n,b),o=!0},i(n){o||(M(a.$$.fragment,n),o=!0)},o(n){p(a.$$.fragment,n),o=!1},d(n){J(a,n)}}}function Jt(j){let a,o;return a=new nt({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/vi/chapter2/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/vi/chapter2/section6_pt.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){r(a.$$.fragment,n)},m(n,b){m(a,n,b),o=!0},i(n){o||(M(a.$$.fragment,n),o=!0)},o(n){p(a.$$.fragment,n),o=!1},d(n){J(a,n)}}}function ht(j){let a,o;return a=new U({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtc3N0LTItZW5nbGlzaCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBc2VxdWVuY2VzJTIwJTNEJTIwJTVCJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTJDJTIwJTIyU28lMjBoYXZlJTIwSSElMjIlNUQlMEElMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIpJTBBb3V0cHV0JTIwJTNEJTIwbW9kZWwoKip0b2tlbnMp",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)
sequences = [<span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>, <span class="hljs-string">&quot;So have I!&quot;</span>]

tokens = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
output = model(**tokens)`,wrap:!1}}),{c(){u(a.$$.fragment)},l(n){r(a.$$.fragment,n)},m(n,b){m(a,n,b),o=!0},i(n){o||(M(a.$$.fragment,n),o=!0)},o(n){p(a.$$.fragment,n),o=!1},d(n){J(a,n)}}}function Tt(j){let a,o;return a=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFzZXF1ZW5jZXMlMjAlM0QlMjAlNUIlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMkMlMjAlMjJTbyUyMGhhdmUlMjBJISUyMiU1RCUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZXMlMkMlMjBwYWRkaW5nJTNEVHJ1ZSUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEFvdXRwdXQlMjAlM0QlMjBtb2RlbCgqKnRva2Vucyk=",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)
sequences = [<span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>, <span class="hljs-string">&quot;So have I!&quot;</span>]

tokens = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
output = model(**tokens)`,wrap:!1}}),{c(){u(a.$$.fragment)},l(n){r(a.$$.fragment,n)},m(n,b){m(a,n,b),o=!0},i(n){o||(M(a.$$.fragment,n),o=!0)},o(n){p(a.$$.fragment,n),o=!1},d(n){J(a,n)}}}function bt(j){let a,o,n,b,k,sl,f,al,V,cl,w,d,tl,Q,Wl="Trong vài phần trước, chúng ta đã cố gắng hết sức để làm hầu hết các tác vụ bằng tay. Chúng ta đã khám phá cách thức hoạt động của các công cụ tokenize và xem xét quá trình tokenize, chuyển đổi dữ liệu sang ID đầu vào, đệm, cắt bớt và các lớp che attention.",il,Z,vl="Tuy nhiên, như chúng ta đã thấy trong phần 2, API 🤗 Transformers có thể xử lý tất cả những điều này cho chúng ta bằng một chức năng cấp cao mà chúng ta sẽ đi sâu vào đây. Khi bạn gọi trực tiếp <code>tokenizer</code> trên câu, bạn sẽ nhận lại được các thông tin đầu vào sẵn sàng chuyển qua mô hình của bạn:",ol,$,pl,B,Nl="Ở đây, biến <code>model_inputs</code> chứa mọi thứ cần thiết để một mô hình hoạt động tốt. Đối với DistilBERT, điều đó bao gồm các ID đầu vào cũng như lớp che attention. Các mô hình khác chấp nhận đầu vào bổ sung cũng sẽ có đầu ra đó từ đối tượng <code>tokenizer</code>.",Ml,C,xl="Như chúng ta sẽ thấy trong một số ví dụ bên dưới, phương pháp này rất mạnh mẽ. Đầu tiên, nó có thể mã hóa một chuỗi duy nhất:",ul,S,rl,E,Gl="Nó cũng xử lý nhiều chuỗi cùng một lúc mà không cần thay đổi trong API:",ml,z,Jl,W,Rl="Nó có thể đệm thêm tuỳ theo một số mục tiêu như sau:",hl,v,Tl,N,_l="Nó cũng có thể cắt bớt các chuỗi:",bl,x,yl,G,Fl="Đối tượng <code>tokenizer</code> có thể xử lý việc chuyển đổi sang các tensor cụ thể, sau đó có thể được gửi trực tiếp đến mô hình. Ví dụ: trong đoạn mã sau, chúng tôi đang nhắc tokenizer trả về tensors từ các khung khác nhau - <code>&quot;pt&quot;</code> trả về tensors PyTorch, <code>&quot;tf&quot;</code> trả về tensors TensorFlow và <code>&quot;np&quot;</code> trả về mảng NumPy:",Ul,R,jl,_,wl,F,ql="Nếu chúng ta xem xét các ID đầu vào được trả về bởi tokenizer, chúng ta sẽ thấy chúng hơi khác một chút so với những gì chúng ta đã có trước đó:",dl,q,gl,Y,Il,X,Yl="Một token ID đã được thêm vào vị trí đầu và cuối. Hãy giải mã hai chuỗi ID ở trên để xem nó là gì:",kl,H,fl,D,Vl,A,Xl="Tokenizer đã thêm từ đặc biệt <code>[CLS]</code> vào đầu và từ đặc biệt <code>[SEP]</code> ở cuối. Điều này là do mô hình đã được huấn luyện trước với chúng, vì vậy để có được kết quả tương tự để luận suy, chúng ta cũng cần thêm chúng vào. Lưu ý rằng một số mô hình không thêm các từ đặc biệt hoặc thêm các từ khác; mô hình cũng có thể chỉ thêm những từ đặc biệt này vào đầu hoặc chỉ ở cuối. Trong mọi trường hợp, tokenizer biết cái nào được mong đợi và sẽ giải quyết việc này cho bạn.",Ql,O,Zl,L,Hl="Giờ chúng ta đã thấy tất cả các bước riêng lẻ mà <code>tokenizer</code> sử dụng khi áp dụng lên văn bản, chúng ta hãy xem lần cuối cách nó có thể xử lý nhiều chuỗi (đệm thêm!), chuỗi rất dài (cắt ngắn!) Và nhiều kiểu tensor với API chính của nó:",$l,g,I,el,P,Bl,nl,Cl;k=new rt({props:{fw:j[0]}}),f=new Mt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),V=new zl({props:{title:"Kết hợp lại",local:"kết-hợp-lại",headingTag:"h1"}});const Dl=[Jt,mt],K=[];function Al(l,t){return l[0]==="pt"?0:1}w=Al(j),d=K[w]=Dl[w](j),$=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQtZmluZXR1bmVkLXNzdC0yLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQXNlcXVlbmNlJTIwJTNEJTIwJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTBBJTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHNlcXVlbmNlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

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

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

model_inputs = tokenizer(sequence)`,wrap:!1}}),S=new U({props:{code:"c2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2Up",highlighted:`sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

model_inputs = tokenizer(sequence)`,wrap:!1}}),z=new U({props:{code:"c2VxdWVuY2VzJTIwJTNEJTIwJTVCJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTJDJTIwJTIyU28lMjBoYXZlJTIwSSElMjIlNUQlMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzKQ==",highlighted:`sequences = [<span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>, <span class="hljs-string">&quot;So have I!&quot;</span>]

model_inputs = tokenizer(sequences)`,wrap:!1}}),v=new U({props:{code:"JTIzJTIwUyVFMSVCQSVCRCUyMCVDNCU5MSVFMSVCQiU4N20lMjB0aCVDMyVBQW0lMjB2JUMzJUEwbyUyMGNodSVFMSVCQiU5N2klMjBzYW8lMjBjaG8lMjAlQzQlOTElRTElQkIlOTklMjBkJUMzJUEwaSUyMGIlRTElQkElQjFuZyUyMCVDNCU5MSVFMSVCQiU5OSUyMGQlQzMlQTBpJTIwdCVFMSVCQiU5MWklMjAlQzQlOTFhJTIwYyVFMSVCQiVBN2ElMjBjaHUlRTElQkIlOTdpJTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHNlcXVlbmNlcyUyQyUyMHBhZGRpbmclM0QlMjJsb25nZXN0JTIyKSUwQSUwQSUyMyUyMFMlRTElQkElQkQlMjAlQzQlOTElRTElQkIlODdtJTIwdGglQzMlQUFtJTIwdiVDMyVBMG8lMjBjaHUlRTElQkIlOTdpJTIwc2FvJTIwY2hvJTIwJUM0JTkxJUUxJUJCJTk5JTIwZCVDMyVBMGklMjBiJUUxJUJBJUIxbmclMjAlQzQlOTElRTElQkIlOTklMjBkJUMzJUEwaSUyMHQlRTElQkIlOTFpJTIwJUM0JTkxYSUyMGMlRTElQkIlQTdhJTIwbSVDMyVCNCUyMGglQzMlQUNuaCUwQSUyMyUyMCg1MTIlMjBjaG8lMjBCRVJUJTIwaG8lRTElQkElQjdjJTIwRGlzdGlsQkVSVCklMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwcGFkZGluZyUzRCUyMm1heF9sZW5ndGglMjIpJTBBJTBBJTIzJTIwUyVFMSVCQSVCRCUyMCVDNCU5MSVFMSVCQiU4N20lMjB0aCVDMyVBQW0lMjB2JUMzJUEwbyUyMGNodSVFMSVCQiU5N2klMjBzYW8lMjBjaG8lMjAlQzQlOTElRTElQkIlOTklMjBkJUMzJUEwaSUyMGIlRTElQkElQjFuZyUyMCVDNCU5MSVFMSVCQiU5OSUyMGQlQzMlQTBpJTIwdCVFMSVCQiU5MWklMjAlQzQlOTFhJTIwJUM0JTkxJUM2JUIwJUUxJUJCJUEzYyUyMGNoJUUxJUJCJTg5JTIwJUM0JTkxJUUxJUJCJThCbmglMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwcGFkZGluZyUzRCUyMm1heF9sZW5ndGglMjIlMkMlMjBtYXhfbGVuZ3RoJTNEOCk=",highlighted:`<span class="hljs-comment"># Sẽ đệm thêm vào chuỗi sao cho độ dài bằng độ dài tối đa của chuỗi</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-string">&quot;longest&quot;</span>)

<span class="hljs-comment"># Sẽ đệm thêm vào chuỗi sao cho độ dài bằng độ dài tối đa của mô hình</span>
<span class="hljs-comment"># (512 cho BERT hoặc DistilBERT)</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-string">&quot;max_length&quot;</span>)

<span class="hljs-comment"># Sẽ đệm thêm vào chuỗi sao cho độ dài bằng độ dài tối đa được chỉ định</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-string">&quot;max_length&quot;</span>, max_length=<span class="hljs-number">8</span>)`,wrap:!1}}),x=new U({props:{code:"c2VxdWVuY2VzJTIwJTNEJTIwJTVCJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTJDJTIwJTIyU28lMjBoYXZlJTIwSSElMjIlNUQlMEElMEElMjMlMjBTJUUxJUJBJUJEJTIwYyVFMSVCQSVBRnQlMjBiJUUxJUJCJTlCdCUyMGNodSVFMSVCQiU5N2klMjBjaG8lMjBiJUUxJUJBJUIxbmclMjAlQzQlOTElRTElQkIlOTklMjBkJUMzJUEwaSUyMHQlRTElQkIlOTFpJTIwJUM0JTkxYSUyMGMlRTElQkIlQTdhJTIwbSVDMyVCNCUyMGglQzMlQUNuaCUwQSUyMyUyMCg1MTIlMjBjaG8lMjBCRVJUJTIwaG8lRTElQkElQjdjJTIwRGlzdGlsQkVSVCklMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUpJTBBJTBBJTIzJTIwUyVFMSVCQSVCRCUyMGMlRTElQkElQUZ0JTIwYiVFMSVCQiU5QnQlMjBjaHUlRTElQkIlOTdpJTIwYyVDMyVCMyUyMCVDNCU5MSVFMSVCQiU5OSUyMGQlQzMlQTBpJTIwZCVDMyVBMGklMjBoJUM2JUExbiUyMCVDNCU5MSVFMSVCQiU5OSUyMGQlQzMlQTBpJTIwdCVFMSVCQiU5MWklMjAlQzQlOTFhJTIwJUM0JTkxJUM2JUIwJUUxJUJCJUEzYyUyMGNoJUUxJUJCJTg5JTIwJUM0JTkxJUUxJUJCJThCbmglMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwbWF4X2xlbmd0aCUzRDglMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSk=",highlighted:`sequences = [<span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>, <span class="hljs-string">&quot;So have I!&quot;</span>]

<span class="hljs-comment"># Sẽ cắt bớt chuỗi cho bằng độ dài tối đa của mô hình</span>
<span class="hljs-comment"># (512 cho BERT hoặc DistilBERT)</span>
model_inputs = tokenizer(sequences, truncation=<span class="hljs-literal">True</span>)

<span class="hljs-comment"># Sẽ cắt bớt chuỗi có độ dài dài hơn độ dài tối đa được chỉ định</span>
model_inputs = tokenizer(sequences, max_length=<span class="hljs-number">8</span>, truncation=<span class="hljs-literal">True</span>)`,wrap:!1}}),R=new U({props:{code:"c2VxdWVuY2VzJTIwJTNEJTIwJTVCJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTJDJTIwJTIyU28lMjBoYXZlJTIwSSElMjIlNUQlMEElMEElMjMlMjBUciVFMSVCQSVBMyUyMHYlRTElQkIlODElMjB0ZW5zb3IlMjBQeVRvcmNoJTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHNlcXVlbmNlcyUyQyUyMHBhZGRpbmclM0RUcnVlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEElMjMlMjBUciVFMSVCQSVBMyUyMHYlRTElQkIlODElMjB0ZW5zb3IlMjBUZW5zb3JGbG93JTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHNlcXVlbmNlcyUyQyUyMHBhZGRpbmclM0RUcnVlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiklMEElMEElMjMlMjBUciVFMSVCQSVBMyUyMHYlRTElQkIlODElMjBtJUUxJUJBJUEzbmclMjBOdW1QeSUwQW1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihzZXF1ZW5jZXMlMkMlMjBwYWRkaW5nJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIybnAlMjIp",highlighted:`sequences = [<span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>, <span class="hljs-string">&quot;So have I!&quot;</span>]

<span class="hljs-comment"># Trả về tensor PyTorch</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-comment"># Trả về tensor TensorFlow</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)

<span class="hljs-comment"># Trả về mảng NumPy</span>
model_inputs = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;np&quot;</span>)`,wrap:!1}}),_=new zl({props:{title:"Các token đặc biệt",local:"các-token-đặc-biệt",headingTag:"h2"}}),q=new U({props:{code:"c2VxdWVuY2UlMjAlM0QlMjAlMjJJJ3ZlJTIwYmVlbiUyMHdhaXRpbmclMjBmb3IlMjBhJTIwSHVnZ2luZ0ZhY2UlMjBjb3Vyc2UlMjBteSUyMHdob2xlJTIwbGlmZS4lMjIlMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2UpJTBBcHJpbnQobW9kZWxfaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVEKSUwQSUwQXRva2VucyUyMCUzRCUyMHRva2VuaXplci50b2tlbml6ZShzZXF1ZW5jZSklMEFpZHMlMjAlM0QlMjB0b2tlbml6ZXIuY29udmVydF90b2tlbnNfdG9faWRzKHRva2VucyklMEFwcmludChpZHMp",highlighted:`sequence = <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>

model_inputs = tokenizer(sequence)
<span class="hljs-built_in">print</span>(model_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])

tokens = tokenizer.tokenize(sequence)
ids = tokenizer.convert_tokens_to_ids(tokens)
<span class="hljs-built_in">print</span>(ids)`,wrap:!1}}),Y=new U({props:{code:"JTVCMTAxJTJDJTIwMTA0NSUyQyUyMDEwMDUlMkMlMjAyMzEwJTJDJTIwMjA0MiUyQyUyMDM0MDMlMkMlMjAyMDA1JTJDJTIwMTAzNyUyQyUyMDE3NjYyJTJDJTIwMTIxNzIlMkMlMjAyNjA3JTJDJTIwMjAyNiUyQyUyMDI4NzglMkMlMjAyMTY2JTJDJTIwMTAxMiUyQyUyMDEwMiU1RCUwQSU1QjEwNDUlMkMlMjAxMDA1JTJDJTIwMjMxMCUyQyUyMDIwNDIlMkMlMjAzNDAzJTJDJTIwMjAwNSUyQyUyMDEwMzclMkMlMjAxNzY2MiUyQyUyMDEyMTcyJTJDJTIwMjYwNyUyQyUyMDIwMjYlMkMlMjAyODc4JTJDJTIwMjE2NiUyQyUyMDEwMTIlNUQ=",highlighted:`[<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>]
[<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>]`,wrap:!1}}),H=new U({props:{code:"cHJpbnQodG9rZW5pemVyLmRlY29kZShtb2RlbF9pbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQpKSUwQXByaW50KHRva2VuaXplci5kZWNvZGUoaWRzKSk=",highlighted:`<span class="hljs-built_in">print</span>(tokenizer.decode(model_inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]))
<span class="hljs-built_in">print</span>(tokenizer.decode(ids))`,wrap:!1}}),D=new U({props:{code:"JTIyJTVCQ0xTJTVEJTIwaSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMGh1Z2dpbmdmYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIwJTVCU0VQJTVEJTIyJTBBJTIyaSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMGh1Z2dpbmdmYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIy",highlighted:`<span class="hljs-string">&quot;[CLS] i&#x27;ve been waiting for a huggingface course my whole life. [SEP]&quot;</span>
<span class="hljs-string">&quot;i&#x27;ve been waiting for a huggingface course my whole life.&quot;</span>`,wrap:!1}}),O=new zl({props:{title:"Tổng kết: Từ tokenizer đến mô hình",local:"tổng-kết-từ-tokenizer-đến-mô-hình",headingTag:"h2"}});const Ol=[Tt,ht],ll=[];function Ll(l,t){return l[0]==="pt"?0:1}return g=Ll(j),I=ll[g]=Ol[g](j),P=new ut({props:{source:"https://github.com/huggingface/course/blob/main/chapters/vi/chapter2/6.mdx"}}),{c(){a=h("meta"),o=c(),n=h("p"),b=c(),u(k.$$.fragment),sl=c(),u(f.$$.fragment),al=c(),u(V.$$.fragment),cl=c(),d.c(),tl=c(),Q=h("p"),Q.textContent=Wl,il=c(),Z=h("p"),Z.innerHTML=vl,ol=c(),u($.$$.fragment),pl=c(),B=h("p"),B.innerHTML=Nl,Ml=c(),C=h("p"),C.textContent=xl,ul=c(),u(S.$$.fragment),rl=c(),E=h("p"),E.textContent=Gl,ml=c(),u(z.$$.fragment),Jl=c(),W=h("p"),W.textContent=Rl,hl=c(),u(v.$$.fragment),Tl=c(),N=h("p"),N.textContent=_l,bl=c(),u(x.$$.fragment),yl=c(),G=h("p"),G.innerHTML=Fl,Ul=c(),u(R.$$.fragment),jl=c(),u(_.$$.fragment),wl=c(),F=h("p"),F.textContent=ql,dl=c(),u(q.$$.fragment),gl=c(),u(Y.$$.fragment),Il=c(),X=h("p"),X.textContent=Yl,kl=c(),u(H.$$.fragment),fl=c(),u(D.$$.fragment),Vl=c(),A=h("p"),A.innerHTML=Xl,Ql=c(),u(O.$$.fragment),Zl=c(),L=h("p"),L.innerHTML=Hl,$l=c(),I.c(),el=c(),u(P.$$.fragment),Bl=c(),nl=h("p"),this.h()},l(l){const t=ot("svelte-u9bgzb",document.head);a=T(t,"META",{name:!0,content:!0}),t.forEach(e),o=i(l),n=T(l,"P",{}),Kl(n).forEach(e),b=i(l),r(k.$$.fragment,l),sl=i(l),r(f.$$.fragment,l),al=i(l),r(V.$$.fragment,l),cl=i(l),d.l(l),tl=i(l),Q=T(l,"P",{"data-svelte-h":!0}),y(Q)!=="svelte-1u8130m"&&(Q.textContent=Wl),il=i(l),Z=T(l,"P",{"data-svelte-h":!0}),y(Z)!=="svelte-1h8wj95"&&(Z.innerHTML=vl),ol=i(l),r($.$$.fragment,l),pl=i(l),B=T(l,"P",{"data-svelte-h":!0}),y(B)!=="svelte-2oyymw"&&(B.innerHTML=Nl),Ml=i(l),C=T(l,"P",{"data-svelte-h":!0}),y(C)!=="svelte-5zlfre"&&(C.textContent=xl),ul=i(l),r(S.$$.fragment,l),rl=i(l),E=T(l,"P",{"data-svelte-h":!0}),y(E)!=="svelte-mvqlrn"&&(E.textContent=Gl),ml=i(l),r(z.$$.fragment,l),Jl=i(l),W=T(l,"P",{"data-svelte-h":!0}),y(W)!=="svelte-ulchx8"&&(W.textContent=Rl),hl=i(l),r(v.$$.fragment,l),Tl=i(l),N=T(l,"P",{"data-svelte-h":!0}),y(N)!=="svelte-19xof0h"&&(N.textContent=_l),bl=i(l),r(x.$$.fragment,l),yl=i(l),G=T(l,"P",{"data-svelte-h":!0}),y(G)!=="svelte-2u7qwj"&&(G.innerHTML=Fl),Ul=i(l),r(R.$$.fragment,l),jl=i(l),r(_.$$.fragment,l),wl=i(l),F=T(l,"P",{"data-svelte-h":!0}),y(F)!=="svelte-zhuz9l"&&(F.textContent=ql),dl=i(l),r(q.$$.fragment,l),gl=i(l),r(Y.$$.fragment,l),Il=i(l),X=T(l,"P",{"data-svelte-h":!0}),y(X)!=="svelte-d3k5ao"&&(X.textContent=Yl),kl=i(l),r(H.$$.fragment,l),fl=i(l),r(D.$$.fragment,l),Vl=i(l),A=T(l,"P",{"data-svelte-h":!0}),y(A)!=="svelte-m99wg0"&&(A.innerHTML=Xl),Ql=i(l),r(O.$$.fragment,l),Zl=i(l),L=T(l,"P",{"data-svelte-h":!0}),y(L)!=="svelte-nuly3r"&&(L.innerHTML=Hl),$l=i(l),I.l(l),el=i(l),r(P.$$.fragment,l),Bl=i(l),nl=T(l,"P",{}),Kl(nl).forEach(e),this.h()},h(){lt(a,"name","hf:doc:metadata"),lt(a,"content",yt)},m(l,t){pt(document.head,a),s(l,o,t),s(l,n,t),s(l,b,t),m(k,l,t),s(l,sl,t),m(f,l,t),s(l,al,t),m(V,l,t),s(l,cl,t),K[w].m(l,t),s(l,tl,t),s(l,Q,t),s(l,il,t),s(l,Z,t),s(l,ol,t),m($,l,t),s(l,pl,t),s(l,B,t),s(l,Ml,t),s(l,C,t),s(l,ul,t),m(S,l,t),s(l,rl,t),s(l,E,t),s(l,ml,t),m(z,l,t),s(l,Jl,t),s(l,W,t),s(l,hl,t),m(v,l,t),s(l,Tl,t),s(l,N,t),s(l,bl,t),m(x,l,t),s(l,yl,t),s(l,G,t),s(l,Ul,t),m(R,l,t),s(l,jl,t),m(_,l,t),s(l,wl,t),s(l,F,t),s(l,dl,t),m(q,l,t),s(l,gl,t),m(Y,l,t),s(l,Il,t),s(l,X,t),s(l,kl,t),m(H,l,t),s(l,fl,t),m(D,l,t),s(l,Vl,t),s(l,A,t),s(l,Ql,t),m(O,l,t),s(l,Zl,t),s(l,L,t),s(l,$l,t),ll[g].m(l,t),s(l,el,t),m(P,l,t),s(l,Bl,t),s(l,nl,t),Cl=!0},p(l,[t]){const Pl={};t&1&&(Pl.fw=l[0]),k.$set(Pl);let Sl=w;w=Al(l),w!==Sl&&(et(),p(K[Sl],1,1,()=>{K[Sl]=null}),tt(),d=K[w],d||(d=K[w]=Dl[w](l),d.c()),M(d,1),d.m(tl.parentNode,tl));let El=g;g=Ll(l),g!==El&&(et(),p(ll[El],1,1,()=>{ll[El]=null}),tt(),I=ll[g],I||(I=ll[g]=Ol[g](l),I.c()),M(I,1),I.m(el.parentNode,el))},i(l){Cl||(M(k.$$.fragment,l),M(f.$$.fragment,l),M(V.$$.fragment,l),M(d),M($.$$.fragment,l),M(S.$$.fragment,l),M(z.$$.fragment,l),M(v.$$.fragment,l),M(x.$$.fragment,l),M(R.$$.fragment,l),M(_.$$.fragment,l),M(q.$$.fragment,l),M(Y.$$.fragment,l),M(H.$$.fragment,l),M(D.$$.fragment,l),M(O.$$.fragment,l),M(I),M(P.$$.fragment,l),Cl=!0)},o(l){p(k.$$.fragment,l),p(f.$$.fragment,l),p(V.$$.fragment,l),p(d),p($.$$.fragment,l),p(S.$$.fragment,l),p(z.$$.fragment,l),p(v.$$.fragment,l),p(x.$$.fragment,l),p(R.$$.fragment,l),p(_.$$.fragment,l),p(q.$$.fragment,l),p(Y.$$.fragment,l),p(H.$$.fragment,l),p(D.$$.fragment,l),p(O.$$.fragment,l),p(I),p(P.$$.fragment,l),Cl=!1},d(l){l&&(e(o),e(n),e(b),e(sl),e(al),e(cl),e(tl),e(Q),e(il),e(Z),e(ol),e(pl),e(B),e(Ml),e(C),e(ul),e(rl),e(E),e(ml),e(Jl),e(W),e(hl),e(Tl),e(N),e(bl),e(yl),e(G),e(Ul),e(jl),e(wl),e(F),e(dl),e(gl),e(Il),e(X),e(kl),e(fl),e(Vl),e(A),e(Ql),e(Zl),e(L),e($l),e(el),e(Bl),e(nl)),e(a),J(k,l),J(f,l),J(V,l),K[w].d(l),J($,l),J(S,l),J(z,l),J(v,l),J(x,l),J(R,l),J(_,l),J(q,l),J(Y,l),J(H,l),J(D,l),J(O,l),ll[g].d(l),J(P,l)}}}const yt='{"title":"Kết hợp lại","local":"kết-hợp-lại","sections":[{"title":"Các token đặc biệt","local":"các-token-đặc-biệt","sections":[],"depth":2},{"title":"Tổng kết: Từ tokenizer đến mô hình","local":"tổng-kết-từ-tokenizer-đến-mô-hình","sections":[],"depth":2}],"depth":1}';function Ut(j,a,o){let n="pt";return at(()=>{const b=new URLSearchParams(window.location.search);o(0,n=b.get("fw")||"pt")}),[n]}class ft extends ct{constructor(a){super(),it(this,a,Ut,bt,st,{})}}export{ft as component};
