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