import{s as me,n as fe,o as ce}from"../chunks/scheduler.9bc65507.js";import{S as Me,i as ke,g as r,s as n,r as U,A as de,h as i,f as s,c as a,j as oe,u as Z,x as p,k as pe,y as je,a as l,v as w,d as J,t as V,w as _}from"../chunks/index.707bf1b6.js";import{C as K}from"../chunks/CodeBlock.54a9f38d.js";import{H as O}from"../chunks/Heading.342b1fa6.js";function ge(D){let o,F,v,C,m,I,f,ee='<a href="/docs/transformers/v4.39.1/ja/main_classes/tokenizer#transformers.PreTrainedTokenizerFast">PreTrainedTokenizerFast</a>は<a href="https://huggingface.co/docs/tokenizers" rel="nofollow">🤗 Tokenizers</a>ライブラリに依存しています。🤗 Tokenizersライブラリから取得したトークナイザーは、非常に簡単に🤗 Transformersにロードできます。',P,c,te="具体的な内容に入る前に、まずはいくつかの行でダミーのトークナイザーを作成することから始めましょう：",N,M,Q,k,se=`私たちは今、定義したファイルにトレーニングされたトークナイザーを持っています。これをランタイムで引き続き使用するか、
将来の再利用のためにJSONファイルに保存することができます。`,W,d,X,j,le=`🤗 Transformersライブラリでこのトークナイザーオブジェクトをどのように活用できるかを見てみましょう。<a href="/docs/transformers/v4.39.1/ja/main_classes/tokenizer#transformers.PreTrainedTokenizerFast">PreTrainedTokenizerFast</a>クラスは、
<em>tokenizer</em>オブジェクトを引数として受け入れ、簡単にインスタンス化できるようにします。`,q,g,G,y,ne='このオブジェクトは、🤗 Transformers トークナイザーが共有するすべてのメソッドと一緒に使用できます！詳細については、<a href="main_classes/tokenizer">トークナイザーページ</a>をご覧ください。',E,h,R,T,ae="JSONファイルからトークナイザーを読み込むには、まずトークナイザーを保存することから始めましょう：",L,u,x,z,re="このファイルを保存したパスは、<code>PreTrainedTokenizerFast</code> の初期化メソッドに <code>tokenizer_file</code> パラメータを使用して渡すことができます：",H,$,S,b,ie='このオブジェクトは、🤗 Transformers トークナイザーが共有するすべてのメソッドと一緒に使用できるようになりました！詳細については、<a href="main_classes/tokenizer">トークナイザーページ</a>をご覧ください。',A,B,Y;return m=new O({props:{title:"Use tokenizers from 🤗 Tokenizers",local:"use-tokenizers-from--tokenizers",headingTag:"h1"}}),M=new K({props:{code:"ZnJvbSUyMHRva2VuaXplcnMlMjBpbXBvcnQlMjBUb2tlbml6ZXIlMEFmcm9tJTIwdG9rZW5pemVycy5tb2RlbHMlMjBpbXBvcnQlMjBCUEUlMEFmcm9tJTIwdG9rZW5pemVycy50cmFpbmVycyUyMGltcG9ydCUyMEJwZVRyYWluZXIlMEFmcm9tJTIwdG9rZW5pemVycy5wcmVfdG9rZW5pemVycyUyMGltcG9ydCUyMFdoaXRlc3BhY2UlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBUb2tlbml6ZXIoQlBFKHVua190b2tlbiUzRCUyMiU1QlVOSyU1RCUyMikpJTBBdHJhaW5lciUyMCUzRCUyMEJwZVRyYWluZXIoc3BlY2lhbF90b2tlbnMlM0QlNUIlMjIlNUJVTkslNUQlMjIlMkMlMjAlMjIlNUJDTFMlNUQlMjIlMkMlMjAlMjIlNUJTRVAlNUQlMjIlMkMlMjAlMjIlNUJQQUQlNUQlMjIlMkMlMjAlMjIlNUJNQVNLJTVEJTIyJTVEKSUwQSUwQXRva2VuaXplci5wcmVfdG9rZW5pemVyJTIwJTNEJTIwV2hpdGVzcGFjZSgpJTBBZmlsZXMlMjAlM0QlMjAlNUIuLi4lNUQlMEF0b2tlbml6ZXIudHJhaW4oZmlsZXMlMkMlMjB0cmFpbmVyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tokenizers <span class="hljs-keyword">import</span> Tokenizer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tokenizers.models <span class="hljs-keyword">import</span> BPE
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tokenizers.trainers <span class="hljs-keyword">import</span> BpeTrainer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tokenizers.pre_tokenizers <span class="hljs-keyword">import</span> Whitespace

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = Tokenizer(BPE(unk_token=<span class="hljs-string">&quot;[UNK]&quot;</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = BpeTrainer(special_tokens=[<span class="hljs-string">&quot;[UNK]&quot;</span>, <span class="hljs-string">&quot;[CLS]&quot;</span>, <span class="hljs-string">&quot;[SEP]&quot;</span>, <span class="hljs-string">&quot;[PAD]&quot;</span>, <span class="hljs-string">&quot;[MASK]&quot;</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.pre_tokenizer = Whitespace()
<span class="hljs-meta">&gt;&gt;&gt; </span>files = [...]
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.train(files, trainer)`,wrap:!1}}),d=new O({props:{title:"Loading directly from the tokenizer object",local:"loading-directly-from-the-tokenizer-object",headingTag:"h2"}}),g=new K({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFByZVRyYWluZWRUb2tlbml6ZXJGYXN0JTBBJTBBZmFzdF90b2tlbml6ZXIlMjAlM0QlMjBQcmVUcmFpbmVkVG9rZW5pemVyRmFzdCh0b2tlbml6ZXJfb2JqZWN0JTNEdG9rZW5pemVyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> PreTrainedTokenizerFast

<span class="hljs-meta">&gt;&gt;&gt; </span>fast_tokenizer = PreTrainedTokenizerFast(tokenizer_object=tokenizer)`,wrap:!1}}),h=new O({props:{title:"Loading from a JSON file",local:"loading-from-a-json-file",headingTag:"h2"}}),u=new K({props:{code:"dG9rZW5pemVyLnNhdmUoJTIydG9rZW5pemVyLmpzb24lMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.save(<span class="hljs-string">&quot;tokenizer.json&quot;</span>)',wrap:!1}}),$=new K({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFByZVRyYWluZWRUb2tlbml6ZXJGYXN0JTBBJTBBZmFzdF90b2tlbml6ZXIlMjAlM0QlMjBQcmVUcmFpbmVkVG9rZW5pemVyRmFzdCh0b2tlbml6ZXJfZmlsZSUzRCUyMnRva2VuaXplci5qc29uJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> PreTrainedTokenizerFast

<span class="hljs-meta">&gt;&gt;&gt; </span>fast_tokenizer = PreTrainedTokenizerFast(tokenizer_file=<span class="hljs-string">&quot;tokenizer.json&quot;</span>)`,wrap:!1}}),{c(){o=r("meta"),F=n(),v=r("p"),C=n(),U(m.$$.fragment),I=n(),f=r("p"),f.innerHTML=ee,P=n(),c=r("p"),c.textContent=te,N=n(),U(M.$$.fragment),Q=n(),k=r("p"),k.textContent=se,W=n(),U(d.$$.fragment),X=n(),j=r("p"),j.innerHTML=le,q=n(),U(g.$$.fragment),G=n(),y=r("p"),y.innerHTML=ne,E=n(),U(h.$$.fragment),R=n(),T=r("p"),T.textContent=ae,L=n(),U(u.$$.fragment),x=n(),z=r("p"),z.innerHTML=re,H=n(),U($.$$.fragment),S=n(),b=r("p"),b.innerHTML=ie,A=n(),B=r("p"),this.h()},l(e){const t=de("svelte-u9bgzb",document.head);o=i(t,"META",{name:!0,content:!0}),t.forEach(s),F=a(e),v=i(e,"P",{}),oe(v).forEach(s),C=a(e),Z(m.$$.fragment,e),I=a(e),f=i(e,"P",{"data-svelte-h":!0}),p(f)!=="svelte-prdc2q"&&(f.innerHTML=ee),P=a(e),c=i(e,"P",{"data-svelte-h":!0}),p(c)!=="svelte-ut5c9x"&&(c.textContent=te),N=a(e),Z(M.$$.fragment,e),Q=a(e),k=i(e,"P",{"data-svelte-h":!0}),p(k)!=="svelte-invdsu"&&(k.textContent=se),W=a(e),Z(d.$$.fragment,e),X=a(e),j=i(e,"P",{"data-svelte-h":!0}),p(j)!=="svelte-1hn01v"&&(j.innerHTML=le),q=a(e),Z(g.$$.fragment,e),G=a(e),y=i(e,"P",{"data-svelte-h":!0}),p(y)!=="svelte-3q8kj6"&&(y.innerHTML=ne),E=a(e),Z(h.$$.fragment,e),R=a(e),T=i(e,"P",{"data-svelte-h":!0}),p(T)!=="svelte-132sdzq"&&(T.textContent=ae),L=a(e),Z(u.$$.fragment,e),x=a(e),z=i(e,"P",{"data-svelte-h":!0}),p(z)!=="svelte-1djco1p"&&(z.innerHTML=re),H=a(e),Z($.$$.fragment,e),S=a(e),b=i(e,"P",{"data-svelte-h":!0}),p(b)!=="svelte-1ipwbgd"&&(b.innerHTML=ie),A=a(e),B=i(e,"P",{}),oe(B).forEach(s),this.h()},h(){pe(o,"name","hf:doc:metadata"),pe(o,"content",ye)},m(e,t){je(document.head,o),l(e,F,t),l(e,v,t),l(e,C,t),w(m,e,t),l(e,I,t),l(e,f,t),l(e,P,t),l(e,c,t),l(e,N,t),w(M,e,t),l(e,Q,t),l(e,k,t),l(e,W,t),w(d,e,t),l(e,X,t),l(e,j,t),l(e,q,t),w(g,e,t),l(e,G,t),l(e,y,t),l(e,E,t),w(h,e,t),l(e,R,t),l(e,T,t),l(e,L,t),w(u,e,t),l(e,x,t),l(e,z,t),l(e,H,t),w($,e,t),l(e,S,t),l(e,b,t),l(e,A,t),l(e,B,t),Y=!0},p:fe,i(e){Y||(J(m.$$.fragment,e),J(M.$$.fragment,e),J(d.$$.fragment,e),J(g.$$.fragment,e),J(h.$$.fragment,e),J(u.$$.fragment,e),J($.$$.fragment,e),Y=!0)},o(e){V(m.$$.fragment,e),V(M.$$.fragment,e),V(d.$$.fragment,e),V(g.$$.fragment,e),V(h.$$.fragment,e),V(u.$$.fragment,e),V($.$$.fragment,e),Y=!1},d(e){e&&(s(F),s(v),s(C),s(I),s(f),s(P),s(c),s(N),s(Q),s(k),s(W),s(X),s(j),s(q),s(G),s(y),s(E),s(R),s(T),s(L),s(x),s(z),s(H),s(S),s(b),s(A),s(B)),s(o),_(m,e),_(M,e),_(d,e),_(g,e),_(h,e),_(u,e),_($,e)}}}const ye='{"title":"Use tokenizers from 🤗 Tokenizers","local":"use-tokenizers-from--tokenizers","sections":[{"title":"Loading directly from the tokenizer object","local":"loading-directly-from-the-tokenizer-object","sections":[],"depth":2},{"title":"Loading from a JSON file","local":"loading-from-a-json-file","sections":[],"depth":2}],"depth":1}';function he(D){return ce(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class be extends Me{constructor(o){super(),ke(this,o,he,ge,me,{})}}export{be as component};
