import{s as Te,o as je}from"../chunks/scheduler.37c15a92.js";import{S as ke,i as Ue,g as h,s as i,r as k,A as xe,h as J,f as n,c as p,j as de,u as U,x as w,k as se,y as $e,a as c,v as x,t as y,b as he,d as f,w as $,m as we,n as Ce,p as Je}from"../chunks/index.2bf4358c.js";import{T as _e}from"../chunks/Tip.363c041f.js";import{C as G}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as ge}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(d){let t,r;return t=new ge({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(d){let t,r;return t=new ge({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 ze(d){let t,r,l,M='然而，我们建议使用 <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 t=new G({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 G({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=i(),l=h("p"),l.innerHTML=M,u=i(),k(m.$$.fragment)},l(s){U(t.$$.fragment,s),r=p(s),l=J(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-11ohs9u"&&(l.innerHTML=M),u=p(s),U(m.$$.fragment,s)},m(s,o){x(t,s,o),c(s,r,o),c(s,l,o),c(s,u,o),x(m,s,o),b=!0},i(s){b||(f(t.$$.fragment,s),f(m.$$.fragment,s),b=!0)},o(s){y(t.$$.fragment,s),y(m.$$.fragment,s),b=!1},d(s){s&&(n(r),n(l),n(u)),$(t,s),$(m,s)}}}function ve(d){let t,r,l,M='然而，我们建议使用 <a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow"><code>Auto*</code> 类</a>，因为 <code>Auto*</code> 类设计与架构无关。前面的代码示例将只能在 CamemBERT 架构中加载可用的检查点，但使用 <code>Auto*</code> 类使切换不同的检查点变得简单：',u,m,b;return t=new G({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 G({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=i(),l=h("p"),l.innerHTML=M,u=i(),k(m.$$.fragment)},l(s){U(t.$$.fragment,s),r=p(s),l=J(s,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1ugw688"&&(l.innerHTML=M),u=p(s),U(m.$$.fragment,s)},m(s,o){x(t,s,o),c(s,r,o),c(s,l,o),c(s,u,o),x(m,s,o),b=!0},i(s){b||(f(t.$$.fragment,s),f(m.$$.fragment,s),b=!0)},o(s){y(t.$$.fragment,s),y(m.$$.fragment,s),b=!1},d(s){s&&(n(r),n(l),n(u)),$(t,s),$(m,s)}}}function Ee(d){let t;return{c(){t=we("使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏差。所有这些信息都应在其模型卡片上注明。")},l(r){t=Ce(r,"使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏差。所有这些信息都应在其模型卡片上注明。")},m(r,l){c(r,t,l)},d(r){r&&n(t)}}}function Fe(d){let t,r,l,M,u,m,b,s,o,g,I,W,ae="模型中心使选择合适的模型变得简单，因此只需几行代码即可在任何下游库中使用它。让我们来看看如何使用这些模型，以及如何将模型贡献到社区。",X,V,ne="假设我们正在寻找一种可以执行 mask 填充的 French-based 模型。",S,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%"/>',R,N,ce="我们选择 <code>camembert-base</code> 检查点来尝试一下。我们需要做的仅仅是输入 <code>camembert-base</code> 标识符！正如你在前几章中看到的，我们可以使用 <code>pipeline()</code> 功能：",L,z,q,v,H,E,oe="如你所见，在管道中加载模型非常简单。你唯一需要注意的是所选检查点是否适合它将用于的任务。例如，这里我们正在将 <code>camembert-base</code> 检查点加载在 <code>fill-mask</code> 管道，这完全没问题。但是如果我们在 <code>text-classification</code> 管道加载检查点，结果没有任何意义，因为 <code>camembert-base</code> 不适合这个任务！我们建议使用 Hugging Face Hub 界面中的任务选择器来选择合适的检查点：",D,_,me='<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,F,ie="你还可以直接使用模型架构实例化检查点：",K,T,j,Y,Z,O,A,ee;u=new Ze({props:{fw:d[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(d),g=Q[o]=pe[o](d),z=new G({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}}),v=new G({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=[ve,ze],B=[];function Me(e,a){return e[0]==="pt"?0:1}return T=Me(d),j=B[T]=be[T](d),Z=new _e({props:{$$slots:{default:[Ee]},$$scope:{ctx:d}}}),{c(){t=h("meta"),r=i(),l=h("p"),M=i(),k(u.$$.fragment),m=i(),k(b.$$.fragment),s=i(),g.c(),I=i(),W=h("p"),W.textContent=ae,X=i(),V=h("p"),V.textContent=ne,S=i(),C=h("div"),C.innerHTML=re,R=i(),N=h("p"),N.innerHTML=ce,L=i(),k(z.$$.fragment),q=i(),k(v.$$.fragment),H=i(),E=h("p"),E.innerHTML=oe,D=i(),_=h("div"),_.innerHTML=me,P=i(),F=h("p"),F.textContent=ie,K=i(),j.c(),Y=i(),k(Z.$$.fragment),O=i(),A=h("p"),this.h()},l(e){const a=xe("svelte-u9bgzb",document.head);t=J(a,"META",{name:!0,content:!0}),a.forEach(n),r=p(e),l=J(e,"P",{}),de(l).forEach(n),M=p(e),U(u.$$.fragment,e),m=p(e),U(b.$$.fragment,e),s=p(e),g.l(e),I=p(e),W=J(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-5jl04w"&&(W.textContent=ae),X=p(e),V=J(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-1bxwioq"&&(V.textContent=ne),S=p(e),C=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=re),R=p(e),N=J(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-uvqxl6"&&(N.innerHTML=ce),L=p(e),U(z.$$.fragment,e),q=p(e),U(v.$$.fragment,e),H=p(e),E=J(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-jiucns"&&(E.innerHTML=oe),D=p(e),_=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=me),P=p(e),F=J(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-oyh0fx"&&(F.textContent=ie),K=p(e),j.l(e),Y=p(e),U(Z.$$.fragment,e),O=p(e),A=J(e,"P",{}),de(A).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,m,a),x(b,e,a),c(e,s,a),Q[o].m(e,a),c(e,I,a),c(e,W,a),c(e,X,a),c(e,V,a),c(e,S,a),c(e,C,a),c(e,R,a),c(e,N,a),c(e,L,a),x(z,e,a),c(e,q,a),x(v,e,a),c(e,H,a),c(e,E,a),c(e,D,a),c(e,_,a),c(e,P,a),c(e,F,a),c(e,K,a),B[T].m(e,a),c(e,Y,a),x(Z,e,a),c(e,O,a),c(e,A,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&&(Je(),y(Q[te],1,1,()=>{Q[te]=null}),he(),g=Q[o],g||(g=Q[o]=pe[o](e),g.c()),f(g,1),g.m(I.parentNode,I));let le=T;T=Me(e),T!==le&&(Je(),y(B[le],1,1,()=>{B[le]=null}),he(),j=B[T],j||(j=B[T]=be[T](e),j.c()),f(j,1),j.m(Y.parentNode,Y));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(g),f(z.$$.fragment,e),f(v.$$.fragment,e),f(j),f(Z.$$.fragment,e),ee=!0)},o(e){y(u.$$.fragment,e),y(b.$$.fragment,e),y(g),y(z.$$.fragment,e),y(v.$$.fragment,e),y(j),y(Z.$$.fragment,e),ee=!1},d(e){e&&(n(r),n(l),n(M),n(m),n(s),n(I),n(W),n(X),n(V),n(S),n(C),n(R),n(N),n(L),n(q),n(H),n(E),n(D),n(_),n(P),n(F),n(K),n(Y),n(O),n(A)),n(t),$(u,e),$(b,e),Q[o].d(e),$(z,e),$(v,e),B[T].d(e),$(Z,e)}}}const Qe='{"title":"使用预训练模型","local":"使用预训练模型","sections":[],"depth":1}';function Be(d,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,Fe,Te,{})}}export{Le as component};
