import{s as je,o as Ue}from"../chunks/scheduler.37c15a92.js";import{S as xe,i as $e,g as d,s as i,r as g,A as we,h as J,f as n,c as m,j as Je,u as T,x as w,k as le,y as Ce,a as r,v as k,t as y,b as ge,d as f,w as j,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.4e987730.js";import{C as ke}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Ve}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ne,E as ze}from"../chunks/getInferenceSnippets.24b50994.js";function ve(h){let s,c;return s=new ke({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){k(s,l,M),c=!0},i(l){c||(f(s.$$.fragment,l),c=!0)},o(l){y(s.$$.fragment,l),c=!1},d(l){j(s,l)}}}function Ee(h){let s,c;return s=new ke({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){k(s,l,M),c=!0},i(l){c||(f(s.$$.fragment,l),c=!0)},o(l){y(s.$$.fragment,l),c=!1},d(l){j(s,l)}}}function Fe(h){let s,c,l,M='然而，我们建议使用 <a href="https://huggingface.co/transformers/model_doc/auto?highlight=auto#auto-classes" rel="nofollow"><code>TFAuto*</code> 类</a> ，因为 <code>TFAuto*</code> 类在设计时不依赖模型架构。前面的代码示例将只能在 CamemBERT 架构中加载可用的 checkpoint，但使用 <code>TFAuto*</code> 类使切换不同的 checkpoint 变得简单：',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=i(),l=d("p"),l.innerHTML=M,u=i(),g(p.$$.fragment)},l(t){T(s.$$.fragment,t),c=m(t),l=J(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1ug935i"&&(l.innerHTML=M),u=m(t),T(p.$$.fragment,t)},m(t,o){k(s,t,o),r(t,c,o),r(t,l,o),r(t,u,o),k(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)),j(s,t),j(p,t)}}}function Qe(h){let s,c,l,M='然而，我们建议使用 <a href="https://huggingface.co/transformers/model_doc/auto?highlight=auto#auto-classes" rel="nofollow"><code>Auto*</code> 类</a> ，因为 <code>Auto*</code> 类在设计时不依赖模型架构。前面的代码示例将只能在 CamemBERT 架构中加载可用的 checkpoint，但使用 <code>Auto*</code> 类使切换不同的 checkpoint 变得简单：',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=i(),l=d("p"),l.innerHTML=M,u=i(),g(p.$$.fragment)},l(t){T(s.$$.fragment,t),c=m(t),l=J(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-9a9kjk"&&(l.innerHTML=M),u=m(t),T(p.$$.fragment,t)},m(t,o){k(s,t,o),r(t,c,o),r(t,l,o),r(t,u,o),k(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)),j(s,t),j(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 filling 又称完形填空）的 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,ie="我们选择 <code>camembert-base</code> checkpoint 来尝试一下。我们需要做的仅仅是输入 <code>camembert-base</code> 标签！正如你在前几章中学习的，我们可以使用 <code>pipeline()</code> 功能：",q,z,H,v,D,E,me="如你所见，在管道中加载模型非常简单。你唯一需要注意的是所选 checkpoint 是否适合它将用于的任务。例如，这里我们正在将 <code>camembert-base</code> checkpoint 加载在 <code>fill-mask</code> 管道，这完全没问题。但是如果我们在 <code>text-classification</code> 管道中加载该 checkpoint 结果没有任何意义，因为 <code>camembert-base</code> 不适合这个任务！我们建议使用 Hugging Face Hub 中的任务选择器来选择合适的 checkpoint 。",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="你还可以直接使用模型架构实例化 checkpoint：",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=i(),l=d("p"),M=i(),g(u.$$.fragment),p=i(),g(b.$$.fragment),t=i(),U.c(),I=i(),W=d("p"),W.textContent=re,S=i(),V=d("p"),V.textContent=ce,R=i(),C=d("div"),C.innerHTML=oe,L=i(),N=d("p"),N.innerHTML=ie,q=i(),g(z.$$.fragment),H=i(),g(v.$$.fragment),D=i(),E=d("p"),E.innerHTML=me,P=i(),_=d("div"),_.innerHTML=pe,K=i(),F=d("p"),F.textContent=ue,O=i(),$.c(),Y=i(),g(Z.$$.fragment),ee=i(),g(Q.$$.fragment),te=i(),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=m(e),l=J(e,"P",{}),Je(l).forEach(n),M=m(e),T(u.$$.fragment,e),p=m(e),T(b.$$.fragment,e),t=m(e),U.l(e),I=m(e),W=J(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-xsypcs"&&(W.textContent=re),S=m(e),V=J(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-dsqyqs"&&(V.textContent=ce),R=m(e),C=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=oe),L=m(e),N=J(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-1fbgnfn"&&(N.innerHTML=ie),q=m(e),T(z.$$.fragment,e),H=m(e),T(v.$$.fragment,e),D=m(e),E=J(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-1ctlltg"&&(E.innerHTML=me),P=m(e),_=J(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=pe),K=m(e),F=J(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-f1tf1d"&&(F.textContent=ue),O=m(e),$.l(e),Y=m(e),T(Z.$$.fragment,e),ee=m(e),T(Q.$$.fragment,e),te=m(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),k(u,e,a),r(e,p,a),k(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),k(z,e,a),r(e,H,a),k(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),k(Z,e,a),r(e,ee,a),k(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),j(u,e),j(b,e),B[o].d(e),j(z,e),j(v,e),G[x].d(e),j(Z,e),j(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,je,{})}}export{De as component};
