import{s as ke,o as Ue}from"../chunks/scheduler.37c15a92.js";import{S as $e,i as xe,g,s as i,r as J,A as we,h as d,f as n,c as m,j as de,u as T,x as w,k as le,y as Ce,a as r,v as j,t as f,b as Je,d as y,w as k,m as _e,n as Ze,p as Te}from"../chunks/index.2bf4358c.js";import{T as We}from"../chunks/Tip.363c041f.js";import{C as Y}from"../chunks/CodeBlock.4e987730.js";import{C as je}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Ve}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ne,E as ve}from"../chunks/getInferenceSnippets.1837c472.js";function ze(h){let t,c;return t=new je({props:{chapter:4,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter4/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter4/section2_tf.ipynb"}]}}),{c(){J(t.$$.fragment)},l(l){T(t.$$.fragment,l)},m(l,M){j(t,l,M),c=!0},i(l){c||(y(t.$$.fragment,l),c=!0)},o(l){f(t.$$.fragment,l),c=!1},d(l){k(t,l)}}}function Ee(h){let t,c;return t=new je({props:{chapter:4,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter4/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter4/section2_pt.ipynb"}]}}),{c(){J(t.$$.fragment)},l(l){T(t.$$.fragment,l)},m(l,M){j(t,l,M),c=!0},i(l){c||(y(t.$$.fragment,l),c=!0)},o(l){f(t.$$.fragment,l),c=!1},d(l){k(t,l)}}}function Fe(h){let t,c,l,M=`However, we recommend using the <a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow"><code>TFAuto*</code> classes</a> instead, as these are by design architecture-agnostic. While the previous code sample limits users to checkpoints loadable in the CamemBERT architecture, using the <code>TFAuto*</code> classes makes switching checkpoints simple:
然而，我們建議使用<a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow"><code>TFAuto*</code> 類</a>，因為<code>TFAuto*</code>類設計與架構無關。前面的代碼示例將只能在 CamemBERT 架構中加載可用的檢查點，但使用 <code>TFAuto*</code>  類使切換檢查點變得簡單：`,u,p,b;return t=new Y({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMENhbWVtYmVydFRva2VuaXplciUyQyUyMFRGQ2FtZW1iZXJ0Rm9yTWFza2VkTE0lMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBDYW1lbWJlcnRUb2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmNhbWVtYmVydC1iYXNlJTIyKSUwQW1vZGVsJTIwJTNEJTIwVEZDYW1lbWJlcnRGb3JNYXNrZWRMTS5mcm9tX3ByZXRyYWluZWQoJTIyY2FtZW1iZXJ0LWJhc2UlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CamembertTokenizer, TFCamembertForMaskedLM

tokenizer = CamembertTokenizer.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)
model = TFCamembertForMaskedLM.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)`,wrap:!1}}),p=new Y({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbEZvck1hc2tlZExNJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIyY2FtZW1iZXJ0LWJhc2UlMjIpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvck1hc2tlZExNLmZyb21fcHJldHJhaW5lZCglMjJjYW1lbWJlcnQtYmFzZSUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForMaskedLM

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)
model = TFAutoModelForMaskedLM.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)`,wrap:!1}}),{c(){J(t.$$.fragment),c=i(),l=g("p"),l.innerHTML=M,u=i(),J(p.$$.fragment)},l(s){T(t.$$.fragment,s),c=m(s),l=d(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-33gguv"&&(l.innerHTML=M),u=m(s),T(p.$$.fragment,s)},m(s,o){j(t,s,o),r(s,c,o),r(s,l,o),r(s,u,o),j(p,s,o),b=!0},i(s){b||(y(t.$$.fragment,s),y(p.$$.fragment,s),b=!0)},o(s){f(t.$$.fragment,s),f(p.$$.fragment,s),b=!1},d(s){s&&(n(c),n(l),n(u)),k(t,s),k(p,s)}}}function Qe(h){let t,c,l,M='然而，我們建議使用<a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow">Auto* 類</a>，因為Auto* 類設計與架構無關。前面的代碼示例將只能在 CamemBERT 架構中加載可用的檢查點，但使用 <strong>Auto*</strong> 類使切換檢查點變得簡單：',u,p,b;return t=new Y({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMENhbWVtYmVydFRva2VuaXplciUyQyUyMENhbWVtYmVydEZvck1hc2tlZExNJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQ2FtZW1iZXJ0VG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJjYW1lbWJlcnQtYmFzZSUyMiklMEFtb2RlbCUyMCUzRCUyMENhbWVtYmVydEZvck1hc2tlZExNLmZyb21fcHJldHJhaW5lZCglMjJjYW1lbWJlcnQtYmFzZSUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CamembertTokenizer, CamembertForMaskedLM

tokenizer = CamembertTokenizer.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)
model = CamembertForMaskedLM.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)`,wrap:!1}}),p=new Y({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JNYXNrZWRMTSUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmNhbWVtYmVydC1iYXNlJTIyKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yTWFza2VkTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmNhbWVtYmVydC1iYXNlJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForMaskedLM

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)
model = AutoModelForMaskedLM.from_pretrained(<span class="hljs-string">&quot;camembert-base&quot;</span>)`,wrap:!1}}),{c(){J(t.$$.fragment),c=i(),l=g("p"),l.innerHTML=M,u=i(),J(p.$$.fragment)},l(s){T(t.$$.fragment,s),c=m(s),l=d(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1jkf2fj"&&(l.innerHTML=M),u=m(s),T(p.$$.fragment,s)},m(s,o){j(t,s,o),r(s,c,o),r(s,l,o),r(s,u,o),j(p,s,o),b=!0},i(s){b||(y(t.$$.fragment,s),y(p.$$.fragment,s),b=!0)},o(s){f(t.$$.fragment,s),f(p.$$.fragment,s),b=!1},d(s){s&&(n(c),n(l),n(u)),k(t,s),k(p,s)}}}function Be(h){let t;return{c(){t=_e("使用預訓練模型時，一定要檢查它是如何訓練的，在哪些數據集上，它的限制和它的偏差。所有這些信息都應在其模型卡片上註明。")},l(c){t=Ze(c,"使用預訓練模型時，一定要檢查它是如何訓練的，在哪些數據集上，它的限制和它的偏差。所有這些信息都應在其模型卡片上註明。")},m(c,l){r(c,t,l)},d(c){c&&n(t)}}}function Ae(h){let t,c,l,M,u,p,b,s,o,U,G,W,re="模型中心使選擇合適的模型變得簡單，因此只需幾行代碼即可在任何下游庫中使用它。讓我們來看看如何實際使用這些模型之一，以及如何回饋社區。",R,V,ce="假設我們正在尋找一種可以執行<strong>mask</strong>填充的French-based模型。",S,C,oe='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/camembert.gif" alt="Selecting the Camembert model." width="80%"/>',L,N,ie="我們選擇 <strong>camembert-base</strong> 檢查點來嘗試一下。我們需要做的僅僅是輸入 <code>camembert-base</code>標識符！正如您在前幾章中看到的，我們可以使用 <strong>pipeline()</strong> 功能：",H,v,q,z,D,E,me="如您所見，在管道中加載模型非常簡單。您唯一需要注意的是所選檢查點是否適合它將用於的任務。例如，這裡我們正在加載 <strong>camembert-base</strong> 檢查點在 <strong>fill-mask</strong> 管道，這完全沒問題。但是如果我們要在 <strong>text-classification</strong> 管道，結果沒有任何意義，因為 <strong>camembert-base</strong> 不適合這個任務！我們建議使用 Hugging Face Hub 界面中的任務選擇器來選擇合適的檢查點：",P,_,pe='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/tasks.png" alt="The task selector on the web interface." width="80%"/>',K,F,ue="您還可以直接使用模型架構實例化檢查點：",O,$,x,I,Z,ee,Q,se,X,te;u=new Ve({props:{fw:h[0]}}),b=new Ne({props:{title:"使用預訓練的模型",local:"使用預訓練的模型",headingTag:"h1"}});const be=[Ee,ze],B=[];function Me(e,a){return e[0]==="pt"?0:1}o=Me(h),U=B[o]=be[o](h),v=new Y({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBY2FtZW1iZXJ0X2ZpbGxfbWFzayUyMCUzRCUyMHBpcGVsaW5lKCUyMmZpbGwtbWFzayUyMiUyQyUyMG1vZGVsJTNEJTIyY2FtZW1iZXJ0LWJhc2UlMjIpJTBBcmVzdWx0cyUyMCUzRCUyMGNhbWVtYmVydF9maWxsX21hc2soJTIyTGUlMjBjYW1lbWJlcnQlMjBlc3QlMjAlM0NtYXNrJTNFJTIwJTNBKSUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

camembert_fill_mask = pipeline(<span class="hljs-string">&quot;fill-mask&quot;</span>, model=<span class="hljs-string">&quot;camembert-base&quot;</span>)
results = camembert_fill_mask(<span class="hljs-string">&quot;Le camembert est &lt;mask&gt; :)&quot;</span>)`,wrap:!1}}),z=new Y({props:{code:"JTVCJTBBJTIwJTIwJTdCJ3NlcXVlbmNlJyUzQSUyMCdMZSUyMGNhbWVtYmVydCUyMGVzdCUyMGQlQzMlQTlsaWNpZXV4JTIwJTNBKSclMkMlMjAnc2NvcmUnJTNBJTIwMC40OTA5MTAwNTMyNTMxNzM4MyUyQyUyMCd0b2tlbiclM0ElMjA3MjAwJTJDJTIwJ3Rva2VuX3N0ciclM0ElMjAnZCVDMyVBOWxpY2lldXgnJTdEJTJDJTIwJTBBJTIwJTIwJTdCJ3NlcXVlbmNlJyUzQSUyMCdMZSUyMGNhbWVtYmVydCUyMGVzdCUyMGV4Y2VsbGVudCUyMCUzQSknJTJDJTIwJ3Njb3JlJyUzQSUyMDAuMTA1NTY5NzQyNjE5OTkxMyUyQyUyMCd0b2tlbiclM0ElMjAyMTgzJTJDJTIwJ3Rva2VuX3N0ciclM0ElMjAnZXhjZWxsZW50JyU3RCUyQyUyMCUwQSUyMCUyMCU3QidzZXF1ZW5jZSclM0ElMjAnTGUlMjBjYW1lbWJlcnQlMjBlc3QlMjBzdWNjdWxlbnQlMjAlM0EpJyUyQyUyMCdzY29yZSclM0ElMjAwLjAzNDUzMzEzMTg2NzY0NzE3JTJDJTIwJ3Rva2VuJyUzQSUyMDI2MjAyJTJDJTIwJ3Rva2VuX3N0ciclM0ElMjAnc3VjY3VsZW50JyU3RCUyQyUyMCUwQSUyMCUyMCU3QidzZXF1ZW5jZSclM0ElMjAnTGUlMjBjYW1lbWJlcnQlMjBlc3QlMjBtZWlsbGV1ciUyMCUzQSknJTJDJTIwJ3Njb3JlJyUzQSUyMDAuMDMzMDMxNDExNDY4OTgyNyUyQyUyMCd0b2tlbiclM0ElMjA1MjglMkMlMjAndG9rZW5fc3RyJyUzQSUyMCdtZWlsbGV1ciclN0QlMkMlMjAlMEElMjAlMjAlN0Inc2VxdWVuY2UnJTNBJTIwJ0xlJTIwY2FtZW1iZXJ0JTIwZXN0JTIwcGFyZmFpdCUyMCUzQSknJTJDJTIwJ3Njb3JlJyUzQSUyMDAuMDMwMDc2NTAxODkxMDE2OTYlMkMlMjAndG9rZW4nJTNBJTIwMTY1NCUyQyUyMCd0b2tlbl9zdHInJTNBJTIwJ3BhcmZhaXQnJTdEJTBBJTVE",highlighted:`[
  {<span class="hljs-string">&#x27;sequence&#x27;</span>: <span class="hljs-string">&#x27;Le camembert est délicieux :)&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.49091005325317383</span>, <span class="hljs-string">&#x27;token&#x27;</span>: <span class="hljs-number">7200</span>, <span class="hljs-string">&#x27;token_str&#x27;</span>: <span class="hljs-string">&#x27;délicieux&#x27;</span>}, 
  {<span class="hljs-string">&#x27;sequence&#x27;</span>: <span class="hljs-string">&#x27;Le camembert est excellent :)&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1055697426199913</span>, <span class="hljs-string">&#x27;token&#x27;</span>: <span class="hljs-number">2183</span>, <span class="hljs-string">&#x27;token_str&#x27;</span>: <span class="hljs-string">&#x27;excellent&#x27;</span>}, 
  {<span class="hljs-string">&#x27;sequence&#x27;</span>: <span class="hljs-string">&#x27;Le camembert est succulent :)&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.03453313186764717</span>, <span class="hljs-string">&#x27;token&#x27;</span>: <span class="hljs-number">26202</span>, <span class="hljs-string">&#x27;token_str&#x27;</span>: <span class="hljs-string">&#x27;succulent&#x27;</span>}, 
  {<span class="hljs-string">&#x27;sequence&#x27;</span>: <span class="hljs-string">&#x27;Le camembert est meilleur :)&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0330314114689827</span>, <span class="hljs-string">&#x27;token&#x27;</span>: <span class="hljs-number">528</span>, <span class="hljs-string">&#x27;token_str&#x27;</span>: <span class="hljs-string">&#x27;meilleur&#x27;</span>}, 
  {<span class="hljs-string">&#x27;sequence&#x27;</span>: <span class="hljs-string">&#x27;Le camembert est parfait :)&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.03007650189101696</span>, <span class="hljs-string">&#x27;token&#x27;</span>: <span class="hljs-number">1654</span>, <span class="hljs-string">&#x27;token_str&#x27;</span>: <span class="hljs-string">&#x27;parfait&#x27;</span>}
]`,wrap:!1}});const fe=[Qe,Fe],A=[];function ye(e,a){return e[0]==="pt"?0:1}return $=ye(h),x=A[$]=fe[$](h),Z=new We({props:{$$slots:{default:[Be]},$$scope:{ctx:h}}}),Q=new ve({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter4/2.mdx"}}),{c(){t=g("meta"),c=i(),l=g("p"),M=i(),J(u.$$.fragment),p=i(),J(b.$$.fragment),s=i(),U.c(),G=i(),W=g("p"),W.textContent=re,R=i(),V=g("p"),V.innerHTML=ce,S=i(),C=g("div"),C.innerHTML=oe,L=i(),N=g("p"),N.innerHTML=ie,H=i(),J(v.$$.fragment),q=i(),J(z.$$.fragment),D=i(),E=g("p"),E.innerHTML=me,P=i(),_=g("div"),_.innerHTML=pe,K=i(),F=g("p"),F.textContent=ue,O=i(),x.c(),I=i(),J(Z.$$.fragment),ee=i(),J(Q.$$.fragment),se=i(),X=g("p"),this.h()},l(e){const a=we("svelte-u9bgzb",document.head);t=d(a,"META",{name:!0,content:!0}),a.forEach(n),c=m(e),l=d(e,"P",{}),de(l).forEach(n),M=m(e),T(u.$$.fragment,e),p=m(e),T(b.$$.fragment,e),s=m(e),U.l(e),G=m(e),W=d(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-v2lrld"&&(W.textContent=re),R=m(e),V=d(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-57fjr6"&&(V.innerHTML=ce),S=m(e),C=d(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=oe),L=m(e),N=d(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-18vwy7e"&&(N.innerHTML=ie),H=m(e),T(v.$$.fragment,e),q=m(e),T(z.$$.fragment,e),D=m(e),E=d(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-1lkl1fi"&&(E.innerHTML=me),P=m(e),_=d(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=pe),K=m(e),F=d(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-1ouqidj"&&(F.textContent=ue),O=m(e),x.l(e),I=m(e),T(Z.$$.fragment,e),ee=m(e),T(Q.$$.fragment,e),se=m(e),X=d(e,"P",{}),de(X).forEach(n),this.h()},h(){le(t,"name","hf:doc:metadata"),le(t,"content",Ge),le(C,"class","flex justify-center"),le(_,"class","flex justify-center")},m(e,a){Ce(document.head,t),r(e,c,a),r(e,l,a),r(e,M,a),j(u,e,a),r(e,p,a),j(b,e,a),r(e,s,a),B[o].m(e,a),r(e,G,a),r(e,W,a),r(e,R,a),r(e,V,a),r(e,S,a),r(e,C,a),r(e,L,a),r(e,N,a),r(e,H,a),j(v,e,a),r(e,q,a),j(z,e,a),r(e,D,a),r(e,E,a),r(e,P,a),r(e,_,a),r(e,K,a),r(e,F,a),r(e,O,a),A[$].m(e,a),r(e,I,a),j(Z,e,a),r(e,ee,a),j(Q,e,a),r(e,se,a),r(e,X,a),te=!0},p(e,[a]){const he={};a&1&&(he.fw=e[0]),u.$set(he);let ae=o;o=Me(e),o!==ae&&(Te(),f(B[ae],1,1,()=>{B[ae]=null}),Je(),U=B[o],U||(U=B[o]=be[o](e),U.c()),y(U,1),U.m(G.parentNode,G));let ne=$;$=ye(e),$!==ne&&(Te(),f(A[ne],1,1,()=>{A[ne]=null}),Je(),x=A[$],x||(x=A[$]=fe[$](e),x.c()),y(x,1),x.m(I.parentNode,I));const ge={};a&2&&(ge.$$scope={dirty:a,ctx:e}),Z.$set(ge)},i(e){te||(y(u.$$.fragment,e),y(b.$$.fragment,e),y(U),y(v.$$.fragment,e),y(z.$$.fragment,e),y(x),y(Z.$$.fragment,e),y(Q.$$.fragment,e),te=!0)},o(e){f(u.$$.fragment,e),f(b.$$.fragment,e),f(U),f(v.$$.fragment,e),f(z.$$.fragment,e),f(x),f(Z.$$.fragment,e),f(Q.$$.fragment,e),te=!1},d(e){e&&(n(c),n(l),n(M),n(p),n(s),n(G),n(W),n(R),n(V),n(S),n(C),n(L),n(N),n(H),n(q),n(D),n(E),n(P),n(_),n(K),n(F),n(O),n(I),n(ee),n(se),n(X)),n(t),k(u,e),k(b,e),B[o].d(e),k(v,e),k(z,e),A[$].d(e),k(Z,e),k(Q,e)}}}const Ge='{"title":"使用預訓練的模型","local":"使用預訓練的模型","sections":[],"depth":1}';function Ie(h,t,c){let l="pt";return Ue(()=>{const M=new URLSearchParams(window.location.search);c(0,l=M.get("fw")||"pt")}),[l]}class De extends $e{constructor(t){super(),xe(this,t,Ie,Ae,ke,{})}}export{De as component};
