import{s as lt,o as tt}from"../chunks/scheduler.37c15a92.js";import{S as et,i as nt,g as h,s as c,r as u,A as st,h as T,f as n,c as i,j as Al,u as r,x as y,k as Ol,y as at,a as s,v as m,t as M,b as Pl,d as p,w as J,p as Ll}from"../chunks/index.2bf4358c.js";import{C as U}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Kl}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as ct}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Cl}from"../chunks/Heading.8ada512a.js";function it(j){let a,o;return a=new Kl({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(e){r(a.$$.fragment,e)},m(e,b){m(a,e,b),o=!0},i(e){o||(p(a.$$.fragment,e),o=!0)},o(e){M(a.$$.fragment,e),o=!1},d(e){J(a,e)}}}function ot(j){let a,o;return a=new Kl({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(e){r(a.$$.fragment,e)},m(e,b){m(a,e,b),o=!0},i(e){o||(p(a.$$.fragment,e),o=!0)},o(e){M(a.$$.fragment,e),o=!1},d(e){J(a,e)}}}function Mt(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(e){r(a.$$.fragment,e)},m(e,b){m(a,e,b),o=!0},i(e){o||(p(a.$$.fragment,e),o=!0)},o(e){M(a.$$.fragment,e),o=!1},d(e){J(a,e)}}}function pt(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(e){r(a.$$.fragment,e)},m(e,b){m(a,e,b),o=!0},i(e){o||(p(a.$$.fragment,e),o=!0)},o(e){M(a.$$.fragment,e),o=!1},d(e){J(a,e)}}}function ut(j){let a,o,e,b,k,el,V,nl,w,d,K,f,Sl="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.",sl,Q,El="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:",al,Z,cl,B,$l="Ở đâ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>.",il,C,zl="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:",ol,S,Ml,E,Wl="Nó cũng xử lý nhiều chuỗi cùng một lúc mà không cần thay đổi trong API:",pl,$,ul,z,vl="Nó có thể đệm thêm tuỳ theo một số mục tiêu như sau:",rl,W,ml,v,Nl="Nó cũng có thể cắt bớt các chuỗi:",Jl,N,hl,G,Gl="Đố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:",Tl,x,bl,R,yl,_,xl="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 đó:",Ul,F,jl,q,wl,Y,Rl="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ì:",dl,X,gl,H,Il,D,_l="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.",kl,A,Vl,O,Fl="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ó:",fl,g,I,ll,tl,Ql;k=new ct({props:{fw:j[0]}}),V=new Cl({props:{title:"Kết hợp lại",local:"kết-hợp-lại",headingTag:"h1"}});const ql=[ot,it],P=[];function Yl(l,t){return l[0]==="pt"?0:1}w=Yl(j),d=P[w]=ql[w](j),Z=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}}),$=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}}),W=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}}),N=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}}),x=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}}),R=new Cl({props:{title:"Các token đặc biệt",local:"các-token-đặc-biệt",headingTag:"h2"}}),F=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}}),q=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}}),X=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}}),H=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}}),A=new Cl({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 Xl=[pt,Mt],L=[];function Hl(l,t){return l[0]==="pt"?0:1}return g=Hl(j),I=L[g]=Xl[g](j),{c(){a=h("meta"),o=c(),e=h("p"),b=c(),u(k.$$.fragment),el=c(),u(V.$$.fragment),nl=c(),d.c(),K=c(),f=h("p"),f.textContent=Sl,sl=c(),Q=h("p"),Q.innerHTML=El,al=c(),u(Z.$$.fragment),cl=c(),B=h("p"),B.innerHTML=$l,il=c(),C=h("p"),C.textContent=zl,ol=c(),u(S.$$.fragment),Ml=c(),E=h("p"),E.textContent=Wl,pl=c(),u($.$$.fragment),ul=c(),z=h("p"),z.textContent=vl,rl=c(),u(W.$$.fragment),ml=c(),v=h("p"),v.textContent=Nl,Jl=c(),u(N.$$.fragment),hl=c(),G=h("p"),G.innerHTML=Gl,Tl=c(),u(x.$$.fragment),bl=c(),u(R.$$.fragment),yl=c(),_=h("p"),_.textContent=xl,Ul=c(),u(F.$$.fragment),jl=c(),u(q.$$.fragment),wl=c(),Y=h("p"),Y.textContent=Rl,dl=c(),u(X.$$.fragment),gl=c(),u(H.$$.fragment),Il=c(),D=h("p"),D.innerHTML=_l,kl=c(),u(A.$$.fragment),Vl=c(),O=h("p"),O.innerHTML=Fl,fl=c(),I.c(),ll=c(),tl=h("p"),this.h()},l(l){const t=st("svelte-u9bgzb",document.head);a=T(t,"META",{name:!0,content:!0}),t.forEach(n),o=i(l),e=T(l,"P",{}),Al(e).forEach(n),b=i(l),r(k.$$.fragment,l),el=i(l),r(V.$$.fragment,l),nl=i(l),d.l(l),K=i(l),f=T(l,"P",{"data-svelte-h":!0}),y(f)!=="svelte-1u8130m"&&(f.textContent=Sl),sl=i(l),Q=T(l,"P",{"data-svelte-h":!0}),y(Q)!=="svelte-1h8wj95"&&(Q.innerHTML=El),al=i(l),r(Z.$$.fragment,l),cl=i(l),B=T(l,"P",{"data-svelte-h":!0}),y(B)!=="svelte-2oyymw"&&(B.innerHTML=$l),il=i(l),C=T(l,"P",{"data-svelte-h":!0}),y(C)!=="svelte-5zlfre"&&(C.textContent=zl),ol=i(l),r(S.$$.fragment,l),Ml=i(l),E=T(l,"P",{"data-svelte-h":!0}),y(E)!=="svelte-mvqlrn"&&(E.textContent=Wl),pl=i(l),r($.$$.fragment,l),ul=i(l),z=T(l,"P",{"data-svelte-h":!0}),y(z)!=="svelte-ulchx8"&&(z.textContent=vl),rl=i(l),r(W.$$.fragment,l),ml=i(l),v=T(l,"P",{"data-svelte-h":!0}),y(v)!=="svelte-19xof0h"&&(v.textContent=Nl),Jl=i(l),r(N.$$.fragment,l),hl=i(l),G=T(l,"P",{"data-svelte-h":!0}),y(G)!=="svelte-2u7qwj"&&(G.innerHTML=Gl),Tl=i(l),r(x.$$.fragment,l),bl=i(l),r(R.$$.fragment,l),yl=i(l),_=T(l,"P",{"data-svelte-h":!0}),y(_)!=="svelte-zhuz9l"&&(_.textContent=xl),Ul=i(l),r(F.$$.fragment,l),jl=i(l),r(q.$$.fragment,l),wl=i(l),Y=T(l,"P",{"data-svelte-h":!0}),y(Y)!=="svelte-d3k5ao"&&(Y.textContent=Rl),dl=i(l),r(X.$$.fragment,l),gl=i(l),r(H.$$.fragment,l),Il=i(l),D=T(l,"P",{"data-svelte-h":!0}),y(D)!=="svelte-m99wg0"&&(D.innerHTML=_l),kl=i(l),r(A.$$.fragment,l),Vl=i(l),O=T(l,"P",{"data-svelte-h":!0}),y(O)!=="svelte-nuly3r"&&(O.innerHTML=Fl),fl=i(l),I.l(l),ll=i(l),tl=T(l,"P",{}),Al(tl).forEach(n),this.h()},h(){Ol(a,"name","hf:doc:metadata"),Ol(a,"content",rt)},m(l,t){at(document.head,a),s(l,o,t),s(l,e,t),s(l,b,t),m(k,l,t),s(l,el,t),m(V,l,t),s(l,nl,t),P[w].m(l,t),s(l,K,t),s(l,f,t),s(l,sl,t),s(l,Q,t),s(l,al,t),m(Z,l,t),s(l,cl,t),s(l,B,t),s(l,il,t),s(l,C,t),s(l,ol,t),m(S,l,t),s(l,Ml,t),s(l,E,t),s(l,pl,t),m($,l,t),s(l,ul,t),s(l,z,t),s(l,rl,t),m(W,l,t),s(l,ml,t),s(l,v,t),s(l,Jl,t),m(N,l,t),s(l,hl,t),s(l,G,t),s(l,Tl,t),m(x,l,t),s(l,bl,t),m(R,l,t),s(l,yl,t),s(l,_,t),s(l,Ul,t),m(F,l,t),s(l,jl,t),m(q,l,t),s(l,wl,t),s(l,Y,t),s(l,dl,t),m(X,l,t),s(l,gl,t),m(H,l,t),s(l,Il,t),s(l,D,t),s(l,kl,t),m(A,l,t),s(l,Vl,t),s(l,O,t),s(l,fl,t),L[g].m(l,t),s(l,ll,t),s(l,tl,t),Ql=!0},p(l,[t]){const Dl={};t&1&&(Dl.fw=l[0]),k.$set(Dl);let Zl=w;w=Yl(l),w!==Zl&&(Ll(),M(P[Zl],1,1,()=>{P[Zl]=null}),Pl(),d=P[w],d||(d=P[w]=ql[w](l),d.c()),p(d,1),d.m(K.parentNode,K));let Bl=g;g=Hl(l),g!==Bl&&(Ll(),M(L[Bl],1,1,()=>{L[Bl]=null}),Pl(),I=L[g],I||(I=L[g]=Xl[g](l),I.c()),p(I,1),I.m(ll.parentNode,ll))},i(l){Ql||(p(k.$$.fragment,l),p(V.$$.fragment,l),p(d),p(Z.$$.fragment,l),p(S.$$.fragment,l),p($.$$.fragment,l),p(W.$$.fragment,l),p(N.$$.fragment,l),p(x.$$.fragment,l),p(R.$$.fragment,l),p(F.$$.fragment,l),p(q.$$.fragment,l),p(X.$$.fragment,l),p(H.$$.fragment,l),p(A.$$.fragment,l),p(I),Ql=!0)},o(l){M(k.$$.fragment,l),M(V.$$.fragment,l),M(d),M(Z.$$.fragment,l),M(S.$$.fragment,l),M($.$$.fragment,l),M(W.$$.fragment,l),M(N.$$.fragment,l),M(x.$$.fragment,l),M(R.$$.fragment,l),M(F.$$.fragment,l),M(q.$$.fragment,l),M(X.$$.fragment,l),M(H.$$.fragment,l),M(A.$$.fragment,l),M(I),Ql=!1},d(l){l&&(n(o),n(e),n(b),n(el),n(nl),n(K),n(f),n(sl),n(Q),n(al),n(cl),n(B),n(il),n(C),n(ol),n(Ml),n(E),n(pl),n(ul),n(z),n(rl),n(ml),n(v),n(Jl),n(hl),n(G),n(Tl),n(bl),n(yl),n(_),n(Ul),n(jl),n(wl),n(Y),n(dl),n(gl),n(Il),n(D),n(kl),n(Vl),n(O),n(fl),n(ll),n(tl)),n(a),J(k,l),J(V,l),P[w].d(l),J(Z,l),J(S,l),J($,l),J(W,l),J(N,l),J(x,l),J(R,l),J(F,l),J(q,l),J(X,l),J(H,l),J(A,l),L[g].d(l)}}}const rt='{"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 mt(j,a,o){let e="pt";return tt(()=>{const b=new URLSearchParams(window.location.search);o(0,e=b.get("fw")||"pt")}),[e]}class jt extends et{constructor(a){super(),nt(this,a,mt,ut,lt,{})}}export{jt as component};
