import{s as xe,o as Ue}from"../chunks/scheduler.cc52f4b9.js";import{S as Ce,i as we,e as k,s as o,c as d,h as _e,a as j,d as a,b as i,f as Te,g,j as w,k as ae,l as Ze,m as r,n as J,o as f,u as ke,t as M,p as T,q as We,r as Ve,v as je}from"../chunks/index.9480bb2b.js";import{T as Ne}from"../chunks/Tip.f7b80743.js";import{C as ze,H as ve,E as Ee}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.009dc98d.js";import{C as X}from"../chunks/CodeBlock.184aadb6.js";import{C as $e}from"../chunks/CourseFloatingBanner.6488bde3.js";import{F as Fe}from"../chunks/FrameworkSwitchCourse.42d12053.js";function Qe(h){let s,c;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(){d(s.$$.fragment)},l(l){g(s.$$.fragment,l)},m(l,y){J(s,l,y),c=!0},i(l){c||(M(s.$$.fragment,l),c=!0)},o(l){f(s.$$.fragment,l),c=!1},d(l){T(s,l)}}}function Be(h){let s,c;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(){d(s.$$.fragment)},l(l){g(s.$$.fragment,l)},m(l,y){J(s,l,y),c=!0},i(l){c||(M(s.$$.fragment,l),c=!0)},o(l){f(s.$$.fragment,l),c=!1},d(l){T(s,l)}}}function Ge(h){let s,c,l,y='然而，我们建议使用 <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,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(){d(s.$$.fragment),c=o(),l=k("p"),l.innerHTML=y,u=o(),d(m.$$.fragment)},l(t){g(s.$$.fragment,t),c=i(t),l=j(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1ug935i"&&(l.innerHTML=y),u=i(t),g(m.$$.fragment,t)},m(t,p){J(s,t,p),r(t,c,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&&(a(c),a(l),a(u)),T(s,t),T(m,t)}}}function Ie(h){let s,c,l,y='然而，我们建议使用 <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,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(){d(s.$$.fragment),c=o(),l=k("p"),l.innerHTML=y,u=o(),d(m.$$.fragment)},l(t){g(s.$$.fragment,t),c=i(t),l=j(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-9a9kjk"&&(l.innerHTML=y),u=i(t),g(m.$$.fragment,t)},m(t,p){J(s,t,p),r(t,c,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&&(a(c),a(l),a(u)),T(s,t),T(m,t)}}}function Ye(h){let s;return{c(){s=We("使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏见。所有这些信息都应在其模型卡片上有所展示。")},l(c){s=Ve(c,"使用预训练模型时，一定要检查它是如何训练的、在哪些数据集上训练的、它的局限性和偏见。所有这些信息都应在其模型卡片上有所展示。")},m(c,l){r(c,s,l)},d(c){c&&a(s)}}}function Ae(h){let s,c,l,y,u,m,b,t,p,R,$,x,Y,V,oe="模型中心使选择合适的模型变得简单，只需几行代码即可在任何下游库中使用它。让我们来看看如何使用这些模型，以及如何将模型贡献到社区。",L,N,ie="假设我们正在寻找一种可以执行掩码填充（mask filling 又称完形填空）的 French-based（法语）模型。",q,_,me='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/camembert.gif" alt="Selecting the Camembert model." width="80%"/>',H,z,pe="我们选择 <code>camembert-base</code> checkpoint 来尝试一下。我们需要做的仅仅是输入 <code>camembert-base</code> 标签！正如你在前几章中学习的，我们可以使用 <code>pipeline()</code> 功能：",D,v,P,E,K,F,ue="如你所见，在管道中加载模型非常简单。你唯一需要注意的是所选 checkpoint 是否适合它将用于的任务。例如，这里我们正在将 <code>camembert-base</code> checkpoint 加载在 <code>fill-mask</code> 管道，这完全没问题。但是如果我们在 <code>text-classification</code> 管道中加载该 checkpoint 结果没有任何意义，因为 <code>camembert-base</code> 不适合这个任务！我们建议使用 Hugging Face Hub 中的任务选择器来选择合适的 checkpoint 。",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="你还可以直接使用模型架构实例化 checkpoint：",te,U,C,A,W,se,B,le,S,ne;u=new Fe({props:{fw:h[0]}}),b=new ze({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),p=new ve({props:{title:"使用预训练模型",local:"使用预训练模型",headingTag:"h1"}});const Me=[Be,Qe],G=[];function ye(e,n){return e[0]==="pt"?0:1}$=ye(h),x=G[$]=Me[$](h),v=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 de(e,n){return e[0]==="pt"?0:1}return U=de(h),C=I[U]=he[U](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-CN/chapter4/2.mdx"}}),{c(){s=k("meta"),c=o(),l=k("p"),y=o(),d(u.$$.fragment),m=o(),d(b.$$.fragment),t=o(),d(p.$$.fragment),R=o(),x.c(),Y=o(),V=k("p"),V.textContent=oe,L=o(),N=k("p"),N.textContent=ie,q=o(),_=k("div"),_.innerHTML=me,H=o(),z=k("p"),z.innerHTML=pe,D=o(),d(v.$$.fragment),P=o(),d(E.$$.fragment),K=o(),F=k("p"),F.innerHTML=ue,O=o(),Z=k("div"),Z.innerHTML=be,ee=o(),Q=k("p"),Q.textContent=fe,te=o(),C.c(),A=o(),d(W.$$.fragment),se=o(),d(B.$$.fragment),le=o(),S=k("p"),this.h()},l(e){const n=_e("svelte-u9bgzb",document.head);s=j(n,"META",{name:!0,content:!0}),n.forEach(a),c=i(e),l=j(e,"P",{}),Te(l).forEach(a),y=i(e),g(u.$$.fragment,e),m=i(e),g(b.$$.fragment,e),t=i(e),g(p.$$.fragment,e),R=i(e),x.l(e),Y=i(e),V=j(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-xsypcs"&&(V.textContent=oe),L=i(e),N=j(e,"P",{"data-svelte-h":!0}),w(N)!=="svelte-dsqyqs"&&(N.textContent=ie),q=i(e),_=j(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-4k6hvy"&&(_.innerHTML=me),H=i(e),z=j(e,"P",{"data-svelte-h":!0}),w(z)!=="svelte-1fbgnfn"&&(z.innerHTML=pe),D=i(e),g(v.$$.fragment,e),P=i(e),g(E.$$.fragment,e),K=i(e),F=j(e,"P",{"data-svelte-h":!0}),w(F)!=="svelte-1ctlltg"&&(F.innerHTML=ue),O=i(e),Z=j(e,"DIV",{class:!0,"data-svelte-h":!0}),w(Z)!=="svelte-1cl7xbt"&&(Z.innerHTML=be),ee=i(e),Q=j(e,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-f1tf1d"&&(Q.textContent=fe),te=i(e),C.l(e),A=i(e),g(W.$$.fragment,e),se=i(e),g(B.$$.fragment,e),le=i(e),S=j(e,"P",{}),Te(S).forEach(a),this.h()},h(){ae(s,"name","hf:doc:metadata"),ae(s,"content",Xe),ae(_,"class","flex justify-center"),ae(Z,"class","flex justify-center")},m(e,n){Ze(document.head,s),r(e,c,n),r(e,l,n),r(e,y,n),J(u,e,n),r(e,m,n),J(b,e,n),r(e,t,n),J(p,e,n),r(e,R,n),G[$].m(e,n),r(e,Y,n),r(e,V,n),r(e,L,n),r(e,N,n),r(e,q,n),r(e,_,n),r(e,H,n),r(e,z,n),r(e,D,n),J(v,e,n),r(e,P,n),J(E,e,n),r(e,K,n),r(e,F,n),r(e,O,n),r(e,Z,n),r(e,ee,n),r(e,Q,n),r(e,te,n),I[U].m(e,n),r(e,A,n),J(W,e,n),r(e,se,n),J(B,e,n),r(e,le,n),r(e,S,n),ne=!0},p(e,[n]){const ge={};n&1&&(ge.fw=e[0]),u.$set(ge);let re=$;$=ye(e),$!==re&&(je(),f(G[re],1,1,()=>{G[re]=null}),ke(),x=G[$],x||(x=G[$]=Me[$](e),x.c()),M(x,1),x.m(Y.parentNode,Y));let ce=U;U=de(e),U!==ce&&(je(),f(I[ce],1,1,()=>{I[ce]=null}),ke(),C=I[U],C||(C=I[U]=he[U](e),C.c()),M(C,1),C.m(A.parentNode,A));const Je={};n&2&&(Je.$$scope={dirty:n,ctx:e}),W.$set(Je)},i(e){ne||(M(u.$$.fragment,e),M(b.$$.fragment,e),M(p.$$.fragment,e),M(x),M(v.$$.fragment,e),M(E.$$.fragment,e),M(C),M(W.$$.fragment,e),M(B.$$.fragment,e),ne=!0)},o(e){f(u.$$.fragment,e),f(b.$$.fragment,e),f(p.$$.fragment,e),f(x),f(v.$$.fragment,e),f(E.$$.fragment,e),f(C),f(W.$$.fragment,e),f(B.$$.fragment,e),ne=!1},d(e){e&&(a(c),a(l),a(y),a(m),a(t),a(R),a(Y),a(V),a(L),a(N),a(q),a(_),a(H),a(z),a(D),a(P),a(K),a(F),a(O),a(Z),a(ee),a(Q),a(te),a(A),a(se),a(le),a(S)),a(s),T(u,e),T(b,e),T(p,e),G[$].d(e),T(v,e),T(E,e),I[U].d(e),T(W,e),T(B,e)}}}const Xe='{"title":"使用预训练模型","local":"使用预训练模型","sections":[],"depth":1}';function Se(h,s,c){let l="pt";return Ue(()=>{const y=new URLSearchParams(window.location.search);c(0,l=y.get("fw")||"pt")}),[l]}class Oe extends Ce{constructor(s){super(),we(this,s,Se,Ae,xe,{})}}export{Oe as component};
