import{s as Te,o as je}from"../chunks/scheduler.37c15a92.js";import{S as ke,i as Ue,g,s as m,r as k,A as xe,h as d,f as n,c as p,j as he,u as U,x as w,k as se,y as $e,a as c,v as x,t as y,b as ge,d as f,w as $,m as we,n as Ce,p as de}from"../chunks/index.2bf4358c.js";import{T as _e}from"../chunks/Tip.363c041f.js";import{C as Y}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Je}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Ze}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as We}from"../chunks/Heading.8ada512a.js";function Ve(h){let t,r;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(){k(t.$$.fragment)},l(l){U(t.$$.fragment,l)},m(l,M){x(t,l,M),r=!0},i(l){r||(f(t.$$.fragment,l),r=!0)},o(l){y(t.$$.fragment,l),r=!1},d(l){$(t,l)}}}function Ne(h){let t,r;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(){k(t.$$.fragment)},l(l){U(t.$$.fragment,l)},m(l,M){x(t,l,M),r=!0},i(l){r||(f(t.$$.fragment,l),r=!0)},o(l){y(t.$$.fragment,l),r=!1},d(l){$(t,l)}}}function ve(h){let t,r,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,i,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}}),i=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(){k(t.$$.fragment),r=m(),l=g("p"),l.innerHTML=M,u=m(),k(i.$$.fragment)},l(s){U(t.$$.fragment,s),r=p(s),l=d(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-33gguv"&&(l.innerHTML=M),u=p(s),U(i.$$.fragment,s)},m(s,o){x(t,s,o),c(s,r,o),c(s,l,o),c(s,u,o),x(i,s,o),b=!0},i(s){b||(f(t.$$.fragment,s),f(i.$$.fragment,s),b=!0)},o(s){y(t.$$.fragment,s),y(i.$$.fragment,s),b=!1},d(s){s&&(n(r),n(l),n(u)),$(t,s),$(i,s)}}}function ze(h){let t,r,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,i,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}}),i=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(){k(t.$$.fragment),r=m(),l=g("p"),l.innerHTML=M,u=m(),k(i.$$.fragment)},l(s){U(t.$$.fragment,s),r=p(s),l=d(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1jkf2fj"&&(l.innerHTML=M),u=p(s),U(i.$$.fragment,s)},m(s,o){x(t,s,o),c(s,r,o),c(s,l,o),c(s,u,o),x(i,s,o),b=!0},i(s){b||(f(t.$$.fragment,s),f(i.$$.fragment,s),b=!0)},o(s){y(t.$$.fragment,s),y(i.$$.fragment,s),b=!1},d(s){s&&(n(r),n(l),n(u)),$(t,s),$(i,s)}}}function Fe(h){let t;return{c(){t=we("使用預訓練模型時，一定要檢查它是如何訓練的，在哪些數據集上，它的限制和它的偏差。所有這些信息都應在其模型卡片上註明。")},l(r){t=Ce(r,"使用預訓練模型時，一定要檢查它是如何訓練的，在哪些數據集上，它的限制和它的偏差。所有這些信息都應在其模型卡片上註明。")},m(r,l){c(r,t,l)},d(r){r&&n(t)}}}function Ee(h){let t,r,l,M,u,i,b,s,o,J,A,W,ae="模型中心使選擇合適的模型變得簡單，因此只需幾行代碼即可在任何下游庫中使用它。讓我們來看看如何實際使用這些模型之一，以及如何回饋社區。",X,V,ne="假設我們正在尋找一種可以執行<strong>mask</strong>填充的French-based模型。",R,C,re='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/camembert.gif" alt="Selecting the Camembert model." width="80%"/>',S,N,ce="我們選擇 <strong>camembert-base</strong> 檢查點來嘗試一下。我們需要做的僅僅是輸入 <code>camembert-base</code>標識符！正如您在前幾章中看到的，我們可以使用 <strong>pipeline()</strong> 功能：",L,v,H,z,q,F,oe="如您所見，在管道中加載模型非常簡單。您唯一需要注意的是所選檢查點是否適合它將用於的任務。例如，這裡我們正在加載 <strong>camembert-base</strong> 檢查點在 <strong>fill-mask</strong> 管道，這完全沒問題。但是如果我們要在 <strong>text-classification</strong> 管道，結果沒有任何意義，因為 <strong>camembert-base</strong> 不適合這個任務！我們建議使用 Hugging Face Hub 界面中的任務選擇器來選擇合適的檢查點：",D,_,ie='<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%"/>',P,E,me="您還可以直接使用模型架構實例化檢查點：",K,T,j,I,Z,O,G,ee;u=new Ze({props:{fw:h[0]}}),b=new We({props:{title:"使用預訓練的模型",local:"使用預訓練的模型",headingTag:"h1"}});const pe=[Ne,Ve],Q=[];function ue(e,a){return e[0]==="pt"?0:1}o=ue(h),J=Q[o]=pe[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 be=[ze,ve],B=[];function Me(e,a){return e[0]==="pt"?0:1}return T=Me(h),j=B[T]=be[T](h),Z=new _e({props:{$$slots:{default:[Fe]},$$scope:{ctx:h}}}),{c(){t=g("meta"),r=m(),l=g("p"),M=m(),k(u.$$.fragment),i=m(),k(b.$$.fragment),s=m(),J.c(),A=m(),W=g("p"),W.textContent=ae,X=m(),V=g("p"),V.innerHTML=ne,R=m(),C=g("div"),C.innerHTML=re,S=m(),N=g("p"),N.innerHTML=ce,L=m(),k(v.$$.fragment),H=m(),k(z.$$.fragment),q=m(),F=g("p"),F.innerHTML=oe,D=m(),_=g("div"),_.innerHTML=ie,P=m(),E=g("p"),E.textContent=me,K=m(),j.c(),I=m(),k(Z.$$.fragment),O=m(),G=g("p"),this.h()},l(e){const a=xe("svelte-u9bgzb",document.head);t=d(a,"META",{name:!0,content:!0}),a.forEach(n),r=p(e),l=d(e,"P",{}),he(l).forEach(n),M=p(e),U(u.$$.fragment,e),i=p(e),U(b.$$.fragment,e),s=p(e),J.l(e),A=p(e),W=d(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-v2lrld"&&(W.textContent=ae),X=p(e),V=d(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-57fjr6"&&(V.innerHTML=ne),R=p(e),C=d(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=re),S=p(e),N=d(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-18vwy7e"&&(N.innerHTML=ce),L=p(e),U(v.$$.fragment,e),H=p(e),U(z.$$.fragment,e),q=p(e),F=d(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-1lkl1fi"&&(F.innerHTML=oe),D=p(e),_=d(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=ie),P=p(e),E=d(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-1ouqidj"&&(E.textContent=me),K=p(e),j.l(e),I=p(e),U(Z.$$.fragment,e),O=p(e),G=d(e,"P",{}),he(G).forEach(n),this.h()},h(){se(t,"name","hf:doc:metadata"),se(t,"content",Qe),se(C,"class","flex justify-center"),se(_,"class","flex justify-center")},m(e,a){$e(document.head,t),c(e,r,a),c(e,l,a),c(e,M,a),x(u,e,a),c(e,i,a),x(b,e,a),c(e,s,a),Q[o].m(e,a),c(e,A,a),c(e,W,a),c(e,X,a),c(e,V,a),c(e,R,a),c(e,C,a),c(e,S,a),c(e,N,a),c(e,L,a),x(v,e,a),c(e,H,a),x(z,e,a),c(e,q,a),c(e,F,a),c(e,D,a),c(e,_,a),c(e,P,a),c(e,E,a),c(e,K,a),B[T].m(e,a),c(e,I,a),x(Z,e,a),c(e,O,a),c(e,G,a),ee=!0},p(e,[a]){const ye={};a&1&&(ye.fw=e[0]),u.$set(ye);let te=o;o=ue(e),o!==te&&(de(),y(Q[te],1,1,()=>{Q[te]=null}),ge(),J=Q[o],J||(J=Q[o]=pe[o](e),J.c()),f(J,1),J.m(A.parentNode,A));let le=T;T=Me(e),T!==le&&(de(),y(B[le],1,1,()=>{B[le]=null}),ge(),j=B[T],j||(j=B[T]=be[T](e),j.c()),f(j,1),j.m(I.parentNode,I));const fe={};a&2&&(fe.$$scope={dirty:a,ctx:e}),Z.$set(fe)},i(e){ee||(f(u.$$.fragment,e),f(b.$$.fragment,e),f(J),f(v.$$.fragment,e),f(z.$$.fragment,e),f(j),f(Z.$$.fragment,e),ee=!0)},o(e){y(u.$$.fragment,e),y(b.$$.fragment,e),y(J),y(v.$$.fragment,e),y(z.$$.fragment,e),y(j),y(Z.$$.fragment,e),ee=!1},d(e){e&&(n(r),n(l),n(M),n(i),n(s),n(A),n(W),n(X),n(V),n(R),n(C),n(S),n(N),n(L),n(H),n(q),n(F),n(D),n(_),n(P),n(E),n(K),n(I),n(O),n(G)),n(t),$(u,e),$(b,e),Q[o].d(e),$(v,e),$(z,e),B[T].d(e),$(Z,e)}}}const Qe='{"title":"使用預訓練的模型","local":"使用預訓練的模型","sections":[],"depth":1}';function Be(h,t,r){let l="pt";return je(()=>{const M=new URLSearchParams(window.location.search);r(0,l=M.get("fw")||"pt")}),[l]}class Le extends ke{constructor(t){super(),Ue(this,t,Be,Ee,Te,{})}}export{Le as component};
