import{s as ke,o as Te}from"../chunks/scheduler.37c15a92.js";import{S as je,i as we,g as M,s as m,r as j,A as Ue,h as g,f as n,c as p,j as fe,u as w,x as $,k as te,y as xe,a as i,v as U,t as d,b as Me,d as y,w as x,m as $e,n as We,p as ge}from"../chunks/index.2bf4358c.js";import{T as _e}from"../chunks/Tip.363c041f.js";import{C as I}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Je}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as Ce}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ze}from"../chunks/Heading.8ada512a.js";function Ve(f){let s,r;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/en/chapter4/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_tf.ipynb"}]}}),{c(){j(s.$$.fragment)},l(l){w(s.$$.fragment,l)},m(l,b){U(s,l,b),r=!0},i(l){r||(y(s.$$.fragment,l),r=!0)},o(l){d(s.$$.fragment,l),r=!1},d(l){x(s,l)}}}function Ne(f){let s,r;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/en/chapter4/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_pt.ipynb"}]}}),{c(){j(s.$$.fragment)},l(l){w(s.$$.fragment,l)},m(l,b){U(s,l,b),r=!0},i(l){r||(y(s.$$.fragment,l),r=!0)},o(l){d(s.$$.fragment,l),r=!1},d(l){x(s,l)}}}function ve(f){let s,r,l,b='However, we recommend using the <a href="https://huggingface.co/transformers/model_doc/auto?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:',u,c,h;return s=new I({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}}),c=new I({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(){j(s.$$.fragment),r=m(),l=M("p"),l.innerHTML=b,u=m(),j(c.$$.fragment)},l(t){w(s.$$.fragment,t),r=p(t),l=g(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-u8g767"&&(l.innerHTML=b),u=p(t),w(c.$$.fragment,t)},m(t,o){U(s,t,o),i(t,r,o),i(t,l,o),i(t,u,o),U(c,t,o),h=!0},i(t){h||(y(s.$$.fragment,t),y(c.$$.fragment,t),h=!0)},o(t){d(s.$$.fragment,t),d(c.$$.fragment,t),h=!1},d(t){t&&(n(r),n(l),n(u)),x(s,t),x(c,t)}}}function ze(f){let s,r,l,b='However, we recommend using the <a href="https://huggingface.co/transformers/model_doc/auto?highlight=auto#auto-classes" rel="nofollow"><code>Auto*</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>Auto*</code> classes makes switching checkpoints simple:',u,c,h;return s=new I({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}}),c=new I({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(){j(s.$$.fragment),r=m(),l=M("p"),l.innerHTML=b,u=m(),j(c.$$.fragment)},l(t){w(s.$$.fragment,t),r=p(t),l=g(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-uubxqf"&&(l.innerHTML=b),u=p(t),w(c.$$.fragment,t)},m(t,o){U(s,t,o),i(t,r,o),i(t,l,o),i(t,u,o),U(c,t,o),h=!0},i(t){h||(y(s.$$.fragment,t),y(c.$$.fragment,t),h=!0)},o(t){d(s.$$.fragment,t),d(c.$$.fragment,t),h=!1},d(t){t&&(n(r),n(l),n(u)),x(s,t),x(c,t)}}}function Ee(f){let s;return{c(){s=$e("When using a pretrained model, make sure to check how it was trained, on which datasets, its limits, and its biases. All of this information should be indicated on its model card.")},l(r){s=We(r,"When using a pretrained model, make sure to check how it was trained, on which datasets, its limits, and its biases. All of this information should be indicated on its model card.")},m(r,l){i(r,s,l)},d(r){r&&n(s)}}}function Fe(f){let s,r,l,b,u,c,h,t,o,J,Y,Z,ae="The Model Hub makes selecting the appropriate model simple, so that using it in any downstream library can be done in a few lines of code. Let’s take a look at how to actually use one of these models, and how to contribute back to the community.",X,V,ne="Let’s say we’re looking for a French-based model that can perform mask filling.",S,W,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,ie="We select the <code>camembert-base</code> checkpoint to try it out. The identifier <code>camembert-base</code> is all we need to start using it! As you’ve seen in previous chapters, we can instantiate it using the <code>pipeline()</code> function:",L,v,H,z,q,E,oe="As you can see, loading a model within a pipeline is extremely simple. The only thing you need to watch out for is that the chosen checkpoint is suitable for the task it’s going to be used for. For example, here we are loading the <code>camembert-base</code> checkpoint in the <code>fill-mask</code> pipeline, which is completely fine. But if we were to load this checkpoint in the <code>text-classification</code> pipeline, the results would not make any sense because the head of <code>camembert-base</code> is not suitable for this task! We recommend using the task selector in the Hugging Face Hub interface in order to select the appropriate checkpoints:",D,_,ce='<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,me="You can also instantiate the checkpoint using the model architecture directly:",K,k,T,A,C,O,G,ee;u=new Ce({props:{fw:f[0]}}),h=new Ze({props:{title:"Using pretrained models",local:"using-pretrained-models",headingTag:"h1"}});const pe=[Ne,Ve],Q=[];function ue(e,a){return e[0]==="pt"?0:1}o=ue(f),J=Q[o]=pe[o](f),v=new I({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}}),z=new I({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=[ze,ve],B=[];function be(e,a){return e[0]==="pt"?0:1}return k=be(f),T=B[k]=he[k](f),C=new _e({props:{$$slots:{default:[Ee]},$$scope:{ctx:f}}}),{c(){s=M("meta"),r=m(),l=M("p"),b=m(),j(u.$$.fragment),c=m(),j(h.$$.fragment),t=m(),J.c(),Y=m(),Z=M("p"),Z.textContent=ae,X=m(),V=M("p"),V.textContent=ne,S=m(),W=M("div"),W.innerHTML=re,R=m(),N=M("p"),N.innerHTML=ie,L=m(),j(v.$$.fragment),H=m(),j(z.$$.fragment),q=m(),E=M("p"),E.innerHTML=oe,D=m(),_=M("div"),_.innerHTML=ce,P=m(),F=M("p"),F.textContent=me,K=m(),T.c(),A=m(),j(C.$$.fragment),O=m(),G=M("p"),this.h()},l(e){const a=Ue("svelte-u9bgzb",document.head);s=g(a,"META",{name:!0,content:!0}),a.forEach(n),r=p(e),l=g(e,"P",{}),fe(l).forEach(n),b=p(e),w(u.$$.fragment,e),c=p(e),w(h.$$.fragment,e),t=p(e),J.l(e),Y=p(e),Z=g(e,"P",{"data-svelte-h":!0}),$(Z)!=="svelte-bbm0bq"&&(Z.textContent=ae),X=p(e),V=g(e,"P",{"data-svelte-h":!0}),$(V)!=="svelte-eky70l"&&(V.textContent=ne),S=p(e),W=g(e,"DIV",{class:!0,"data-svelte-h":!0}),$(W)!=="svelte-4k6hvy"&&(W.innerHTML=re),R=p(e),N=g(e,"P",{"data-svelte-h":!0}),$(N)!=="svelte-k56284"&&(N.innerHTML=ie),L=p(e),w(v.$$.fragment,e),H=p(e),w(z.$$.fragment,e),q=p(e),E=g(e,"P",{"data-svelte-h":!0}),$(E)!=="svelte-1senv06"&&(E.innerHTML=oe),D=p(e),_=g(e,"DIV",{class:!0,"data-svelte-h":!0}),$(_)!=="svelte-1cl7xbt"&&(_.innerHTML=ce),P=p(e),F=g(e,"P",{"data-svelte-h":!0}),$(F)!=="svelte-oo27s0"&&(F.textContent=me),K=p(e),T.l(e),A=p(e),w(C.$$.fragment,e),O=p(e),G=g(e,"P",{}),fe(G).forEach(n),this.h()},h(){te(s,"name","hf:doc:metadata"),te(s,"content",Qe),te(W,"class","flex justify-center"),te(_,"class","flex justify-center")},m(e,a){xe(document.head,s),i(e,r,a),i(e,l,a),i(e,b,a),U(u,e,a),i(e,c,a),U(h,e,a),i(e,t,a),Q[o].m(e,a),i(e,Y,a),i(e,Z,a),i(e,X,a),i(e,V,a),i(e,S,a),i(e,W,a),i(e,R,a),i(e,N,a),i(e,L,a),U(v,e,a),i(e,H,a),U(z,e,a),i(e,q,a),i(e,E,a),i(e,D,a),i(e,_,a),i(e,P,a),i(e,F,a),i(e,K,a),B[k].m(e,a),i(e,A,a),U(C,e,a),i(e,O,a),i(e,G,a),ee=!0},p(e,[a]){const de={};a&1&&(de.fw=e[0]),u.$set(de);let se=o;o=ue(e),o!==se&&(ge(),d(Q[se],1,1,()=>{Q[se]=null}),Me(),J=Q[o],J||(J=Q[o]=pe[o](e),J.c()),y(J,1),J.m(Y.parentNode,Y));let le=k;k=be(e),k!==le&&(ge(),d(B[le],1,1,()=>{B[le]=null}),Me(),T=B[k],T||(T=B[k]=he[k](e),T.c()),y(T,1),T.m(A.parentNode,A));const ye={};a&2&&(ye.$$scope={dirty:a,ctx:e}),C.$set(ye)},i(e){ee||(y(u.$$.fragment,e),y(h.$$.fragment,e),y(J),y(v.$$.fragment,e),y(z.$$.fragment,e),y(T),y(C.$$.fragment,e),ee=!0)},o(e){d(u.$$.fragment,e),d(h.$$.fragment,e),d(J),d(v.$$.fragment,e),d(z.$$.fragment,e),d(T),d(C.$$.fragment,e),ee=!1},d(e){e&&(n(r),n(l),n(b),n(c),n(t),n(Y),n(Z),n(X),n(V),n(S),n(W),n(R),n(N),n(L),n(H),n(q),n(E),n(D),n(_),n(P),n(F),n(K),n(A),n(O),n(G)),n(s),x(u,e),x(h,e),Q[o].d(e),x(v,e),x(z,e),B[k].d(e),x(C,e)}}}const Qe='{"title":"Using pretrained models","local":"using-pretrained-models","sections":[],"depth":1}';function Be(f,s,r){let l="pt";return Te(()=>{const b=new URLSearchParams(window.location.search);r(0,l=b.get("fw")||"pt")}),[l]}class Le extends je{constructor(s){super(),we(this,s,Be,Fe,ke,{})}}export{Le as component};
