import{s as ke,o as Ue}from"../chunks/scheduler.37c15a92.js";import{S as xe,i as $e,g as d,s as m,r as g,A as we,h as J,f as n,c as i,j as Je,u as T,x as w,k as le,y as Ce,a as r,v as j,t as y,b as ge,d as f,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 A}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as je}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Ve}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ne,E as ze}from"../chunks/EditOnGithub.8916dc7c.js";function ve(h){let s,c;return s=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(){g(s.$$.fragment)},l(l){T(s.$$.fragment,l)},m(l,M){j(s,l,M),c=!0},i(l){c||(f(s.$$.fragment,l),c=!0)},o(l){y(s.$$.fragment,l),c=!1},d(l){k(s,l)}}}function Ee(h){let s,c;return s=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(){g(s.$$.fragment)},l(l){T(s.$$.fragment,l)},m(l,M){j(s,l,M),c=!0},i(l){c||(f(s.$$.fragment,l),c=!0)},o(l){y(s.$$.fragment,l),c=!1},d(l){k(s,l)}}}function Fe(h){let s,c,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,p,b;return s=new A({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 A({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),c=m(),l=d("p"),l.innerHTML=M,u=m(),g(p.$$.fragment)},l(t){T(s.$$.fragment,t),c=i(t),l=J(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-11ohs9u"&&(l.innerHTML=M),u=i(t),T(p.$$.fragment,t)},m(t,o){j(s,t,o),r(t,c,o),r(t,l,o),r(t,u,o),j(p,t,o),b=!0},i(t){b||(f(s.$$.fragment,t),f(p.$$.fragment,t),b=!0)},o(t){y(s.$$.fragment,t),y(p.$$.fragment,t),b=!1},d(t){t&&(n(c),n(l),n(u)),k(s,t),k(p,t)}}}function Qe(h){let s,c,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,p,b;return s=new A({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 A({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),c=m(),l=d("p"),l.innerHTML=M,u=m(),g(p.$$.fragment)},l(t){T(s.$$.fragment,t),c=i(t),l=J(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1ugw688"&&(l.innerHTML=M),u=i(t),T(p.$$.fragment,t)},m(t,o){j(s,t,o),r(t,c,o),r(t,l,o),r(t,u,o),j(p,t,o),b=!0},i(t){b||(f(s.$$.fragment,t),f(p.$$.fragment,t),b=!0)},o(t){y(s.$$.fragment,t),y(p.$$.fragment,t),b=!1},d(t){t&&(n(c),n(l),n(u)),k(s,t),k(p,t)}}}function Be(h){let s;return{c(){s=_e("使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏差。所有这些信息都应在其模型卡片上注明。")},l(c){s=Ze(c,"使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏差。所有这些信息都应在其模型卡片上注明。")},m(c,l){r(c,s,l)},d(c){c&&n(s)}}}function Ge(h){let s,c,l,M,u,p,b,t,o,U,I,W,re="模型中心使选择合适的模型变得简单，因此只需几行代码即可在任何下游库中使用它。让我们来看看如何使用这些模型，以及如何将模型贡献到社区。",S,V,ce="假设我们正在寻找一种可以执行 mask 填充的 French-based 模型。",R,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,me="我们选择 <code>camembert-base</code> 检查点来尝试一下。我们需要做的仅仅是输入 <code>camembert-base</code> 标识符！正如你在前几章中看到的，我们可以使用 <code>pipeline()</code> 功能：",q,z,H,v,D,E,ie="如你所见，在管道中加载模型非常简单。你唯一需要注意的是所选检查点是否适合它将用于的任务。例如，这里我们正在将 <code>camembert-base</code> 检查点加载在 <code>fill-mask</code> 管道，这完全没问题。但是如果我们在 <code>text-classification</code> 管道加载检查点，结果没有任何意义，因为 <code>camembert-base</code> 不适合这个任务！我们建议使用 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,$,Y,Z,ee,Q,te,X,se;u=new Ve({props:{fw:h[0]}}),b=new Ne({props:{title:"使用预训练模型",local:"使用预训练模型",headingTag:"h1"}});const be=[Ee,ve],B=[];function Me(e,a){return e[0]==="pt"?0:1}o=Me(h),U=B[o]=be[o](h),z=new A({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 A({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 ye=[Qe,Fe],G=[];function fe(e,a){return e[0]==="pt"?0:1}return x=fe(h),$=G[x]=ye[x](h),Z=new We({props:{$$slots:{default:[Be]},$$scope:{ctx:h}}}),Q=new ze({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter4/2.mdx"}}),{c(){s=d("meta"),c=m(),l=d("p"),M=m(),g(u.$$.fragment),p=m(),g(b.$$.fragment),t=m(),U.c(),I=m(),W=d("p"),W.textContent=re,S=m(),V=d("p"),V.textContent=ce,R=m(),C=d("div"),C.innerHTML=oe,L=m(),N=d("p"),N.innerHTML=me,q=m(),g(z.$$.fragment),H=m(),g(v.$$.fragment),D=m(),E=d("p"),E.innerHTML=ie,P=m(),_=d("div"),_.innerHTML=pe,K=m(),F=d("p"),F.textContent=ue,O=m(),$.c(),Y=m(),g(Z.$$.fragment),ee=m(),g(Q.$$.fragment),te=m(),X=d("p"),this.h()},l(e){const a=we("svelte-u9bgzb",document.head);s=J(a,"META",{name:!0,content:!0}),a.forEach(n),c=i(e),l=J(e,"P",{}),Je(l).forEach(n),M=i(e),T(u.$$.fragment,e),p=i(e),T(b.$$.fragment,e),t=i(e),U.l(e),I=i(e),W=J(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-5jl04w"&&(W.textContent=re),S=i(e),V=J(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-1bxwioq"&&(V.textContent=ce),R=i(e),C=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=oe),L=i(e),N=J(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-uvqxl6"&&(N.innerHTML=me),q=i(e),T(z.$$.fragment,e),H=i(e),T(v.$$.fragment,e),D=i(e),E=J(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-jiucns"&&(E.innerHTML=ie),P=i(e),_=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=pe),K=i(e),F=J(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-oyh0fx"&&(F.textContent=ue),O=i(e),$.l(e),Y=i(e),T(Z.$$.fragment,e),ee=i(e),T(Q.$$.fragment,e),te=i(e),X=J(e,"P",{}),Je(X).forEach(n),this.h()},h(){le(s,"name","hf:doc:metadata"),le(s,"content",Ie),le(C,"class","flex justify-center"),le(_,"class","flex justify-center")},m(e,a){Ce(document.head,s),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,t,a),B[o].m(e,a),r(e,I,a),r(e,W,a),r(e,S,a),r(e,V,a),r(e,R,a),r(e,C,a),r(e,L,a),r(e,N,a),r(e,q,a),j(z,e,a),r(e,H,a),j(v,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),G[x].m(e,a),r(e,Y,a),j(Z,e,a),r(e,ee,a),j(Q,e,a),r(e,te,a),r(e,X,a),se=!0},p(e,[a]){const he={};a&1&&(he.fw=e[0]),u.$set(he);let ae=o;o=Me(e),o!==ae&&(Te(),y(B[ae],1,1,()=>{B[ae]=null}),ge(),U=B[o],U||(U=B[o]=be[o](e),U.c()),f(U,1),U.m(I.parentNode,I));let ne=x;x=fe(e),x!==ne&&(Te(),y(G[ne],1,1,()=>{G[ne]=null}),ge(),$=G[x],$||($=G[x]=ye[x](e),$.c()),f($,1),$.m(Y.parentNode,Y));const de={};a&2&&(de.$$scope={dirty:a,ctx:e}),Z.$set(de)},i(e){se||(f(u.$$.fragment,e),f(b.$$.fragment,e),f(U),f(z.$$.fragment,e),f(v.$$.fragment,e),f($),f(Z.$$.fragment,e),f(Q.$$.fragment,e),se=!0)},o(e){y(u.$$.fragment,e),y(b.$$.fragment,e),y(U),y(z.$$.fragment,e),y(v.$$.fragment,e),y($),y(Z.$$.fragment,e),y(Q.$$.fragment,e),se=!1},d(e){e&&(n(c),n(l),n(M),n(p),n(t),n(I),n(W),n(S),n(V),n(R),n(C),n(L),n(N),n(q),n(H),n(D),n(E),n(P),n(_),n(K),n(F),n(O),n(Y),n(ee),n(te),n(X)),n(s),k(u,e),k(b,e),B[o].d(e),k(z,e),k(v,e),G[x].d(e),k(Z,e),k(Q,e)}}}const Ie='{"title":"使用预训练模型","local":"使用预训练模型","sections":[],"depth":1}';function Ye(h,s,c){let l="pt";return Ue(()=>{const M=new URLSearchParams(window.location.search);c(0,l=M.get("fw")||"pt")}),[l]}class De extends xe{constructor(s){super(),$e(this,s,Ye,Ge,ke,{})}}export{De as component};
