import{s as $e,o as xe}from"../chunks/scheduler.cc52f4b9.js";import{S as Ue,i as We,e as T,s as o,c as M,h as Ce,a as w,d as a,b as c,f as ke,g,j as W,k as ae,l as _e,m as r,n as J,o as h,E as Te,t as f,p as k,q as Ze,r as Ve,F as we}from"../chunks/index.5b747fde.js";import{T as Ne}from"../chunks/Tip.f0925d57.js";import{C as ve,H as ze,E as Ee}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d38ac5a9.js";import{C as X}from"../chunks/CodeBlock.665bfc37.js";import{C as je}from"../chunks/CourseFloatingBanner.b33fcd79.js";import{F as Fe}from"../chunks/FrameworkSwitchCourse.b3b657b3.js";function Qe(y){let s,i;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(){M(s.$$.fragment)},l(l){g(s.$$.fragment,l)},m(l,d){J(s,l,d),i=!0},i(l){i||(f(s.$$.fragment,l),i=!0)},o(l){h(s.$$.fragment,l),i=!1},d(l){k(s,l)}}}function Be(y){let s,i;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(){M(s.$$.fragment)},l(l){g(s.$$.fragment,l)},m(l,d){J(s,l,d),i=!0},i(l){i||(f(s.$$.fragment,l),i=!0)},o(l){h(s.$$.fragment,l),i=!1},d(l){k(s,l)}}}function Ye(y){let s,i,l,d='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,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(){M(s.$$.fragment),i=o(),l=T("p"),l.innerHTML=d,u=o(),M(m.$$.fragment)},l(t){g(s.$$.fragment,t),i=c(t),l=w(t,"P",{"data-svelte-h":!0}),W(l)!=="svelte-u8g767"&&(l.innerHTML=d),u=c(t),g(m.$$.fragment,t)},m(t,p){J(s,t,p),r(t,i,p),r(t,l,p),r(t,u,p),J(m,t,p),b=!0},i(t){b||(f(s.$$.fragment,t),f(m.$$.fragment,t),b=!0)},o(t){h(s.$$.fragment,t),h(m.$$.fragment,t),b=!1},d(t){t&&(a(i),a(l),a(u)),k(s,t),k(m,t)}}}function Ge(y){let s,i,l,d='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,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(){M(s.$$.fragment),i=o(),l=T("p"),l.innerHTML=d,u=o(),M(m.$$.fragment)},l(t){g(s.$$.fragment,t),i=c(t),l=w(t,"P",{"data-svelte-h":!0}),W(l)!=="svelte-uubxqf"&&(l.innerHTML=d),u=c(t),g(m.$$.fragment,t)},m(t,p){J(s,t,p),r(t,i,p),r(t,l,p),r(t,u,p),J(m,t,p),b=!0},i(t){b||(f(s.$$.fragment,t),f(m.$$.fragment,t),b=!0)},o(t){h(s.$$.fragment,t),h(m.$$.fragment,t),b=!1},d(t){t&&(a(i),a(l),a(u)),k(s,t),k(m,t)}}}function Ie(y){let s;return{c(){s=Ze("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(i){s=Ve(i,"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(i,l){r(i,s,l)},d(i){i&&a(s)}}}function Ae(y){let s,i,l,d,u,m,b,t,p,L,j,$,I,V,oe="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.",R,N,ce="Let’s say we’re looking for a French-based model that can perform mask filling.",H,C,me='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/camembert.gif" alt="Selecting the Camembert model." width="80%"/>',q,v,pe="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:",D,z,P,E,K,F,ue="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:",O,_,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,he="You can also instantiate the checkpoint using the model architecture directly:",te,x,U,A,Z,se,B,le,S,ne;u=new Fe({props:{fw:y[0]}}),b=new ve({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),p=new ze({props:{title:"Using pretrained models",local:"using-pretrained-models",headingTag:"h1"}});const fe=[Be,Qe],Y=[];function de(e,n){return e[0]==="pt"?0:1}j=de(y),$=Y[j]=fe[j](y),z=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 ye=[Ge,Ye],G=[];function Me(e,n){return e[0]==="pt"?0:1}return x=Me(y),U=G[x]=ye[x](y),Z=new Ne({props:{$$slots:{default:[Ie]},$$scope:{ctx:y}}}),B=new Ee({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter4/2.mdx"}}),{c(){s=T("meta"),i=o(),l=T("p"),d=o(),M(u.$$.fragment),m=o(),M(b.$$.fragment),t=o(),M(p.$$.fragment),L=o(),$.c(),I=o(),V=T("p"),V.textContent=oe,R=o(),N=T("p"),N.textContent=ce,H=o(),C=T("div"),C.innerHTML=me,q=o(),v=T("p"),v.innerHTML=pe,D=o(),M(z.$$.fragment),P=o(),M(E.$$.fragment),K=o(),F=T("p"),F.innerHTML=ue,O=o(),_=T("div"),_.innerHTML=be,ee=o(),Q=T("p"),Q.textContent=he,te=o(),U.c(),A=o(),M(Z.$$.fragment),se=o(),M(B.$$.fragment),le=o(),S=T("p"),this.h()},l(e){const n=Ce("svelte-u9bgzb",document.head);s=w(n,"META",{name:!0,content:!0}),n.forEach(a),i=c(e),l=w(e,"P",{}),ke(l).forEach(a),d=c(e),g(u.$$.fragment,e),m=c(e),g(b.$$.fragment,e),t=c(e),g(p.$$.fragment,e),L=c(e),$.l(e),I=c(e),V=w(e,"P",{"data-svelte-h":!0}),W(V)!=="svelte-bbm0bq"&&(V.textContent=oe),R=c(e),N=w(e,"P",{"data-svelte-h":!0}),W(N)!=="svelte-eky70l"&&(N.textContent=ce),H=c(e),C=w(e,"DIV",{class:!0,"data-svelte-h":!0}),W(C)!=="svelte-4k6hvy"&&(C.innerHTML=me),q=c(e),v=w(e,"P",{"data-svelte-h":!0}),W(v)!=="svelte-k56284"&&(v.innerHTML=pe),D=c(e),g(z.$$.fragment,e),P=c(e),g(E.$$.fragment,e),K=c(e),F=w(e,"P",{"data-svelte-h":!0}),W(F)!=="svelte-1senv06"&&(F.innerHTML=ue),O=c(e),_=w(e,"DIV",{class:!0,"data-svelte-h":!0}),W(_)!=="svelte-1cl7xbt"&&(_.innerHTML=be),ee=c(e),Q=w(e,"P",{"data-svelte-h":!0}),W(Q)!=="svelte-oo27s0"&&(Q.textContent=he),te=c(e),U.l(e),A=c(e),g(Z.$$.fragment,e),se=c(e),g(B.$$.fragment,e),le=c(e),S=w(e,"P",{}),ke(S).forEach(a),this.h()},h(){ae(s,"name","hf:doc:metadata"),ae(s,"content",Xe),ae(C,"class","flex justify-center"),ae(_,"class","flex justify-center")},m(e,n){_e(document.head,s),r(e,i,n),r(e,l,n),r(e,d,n),J(u,e,n),r(e,m,n),J(b,e,n),r(e,t,n),J(p,e,n),r(e,L,n),Y[j].m(e,n),r(e,I,n),r(e,V,n),r(e,R,n),r(e,N,n),r(e,H,n),r(e,C,n),r(e,q,n),r(e,v,n),r(e,D,n),J(z,e,n),r(e,P,n),J(E,e,n),r(e,K,n),r(e,F,n),r(e,O,n),r(e,_,n),r(e,ee,n),r(e,Q,n),r(e,te,n),G[x].m(e,n),r(e,A,n),J(Z,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=j;j=de(e),j!==re&&(we(),h(Y[re],1,1,()=>{Y[re]=null}),Te(),$=Y[j],$||($=Y[j]=fe[j](e),$.c()),f($,1),$.m(I.parentNode,I));let ie=x;x=Me(e),x!==ie&&(we(),h(G[ie],1,1,()=>{G[ie]=null}),Te(),U=G[x],U||(U=G[x]=ye[x](e),U.c()),f(U,1),U.m(A.parentNode,A));const Je={};n&2&&(Je.$$scope={dirty:n,ctx:e}),Z.$set(Je)},i(e){ne||(f(u.$$.fragment,e),f(b.$$.fragment,e),f(p.$$.fragment,e),f($),f(z.$$.fragment,e),f(E.$$.fragment,e),f(U),f(Z.$$.fragment,e),f(B.$$.fragment,e),ne=!0)},o(e){h(u.$$.fragment,e),h(b.$$.fragment,e),h(p.$$.fragment,e),h($),h(z.$$.fragment,e),h(E.$$.fragment,e),h(U),h(Z.$$.fragment,e),h(B.$$.fragment,e),ne=!1},d(e){e&&(a(i),a(l),a(d),a(m),a(t),a(L),a(I),a(V),a(R),a(N),a(H),a(C),a(q),a(v),a(D),a(P),a(K),a(F),a(O),a(_),a(ee),a(Q),a(te),a(A),a(se),a(le),a(S)),a(s),k(u,e),k(b,e),k(p,e),Y[j].d(e),k(z,e),k(E,e),G[x].d(e),k(Z,e),k(B,e)}}}const Xe='{"title":"Using pretrained models","local":"using-pretrained-models","sections":[],"depth":1}';function Se(y,s,i){let l="pt";return xe(()=>{const d=new URLSearchParams(window.location.search);i(0,l=d.get("fw")||"pt")}),[l]}class Oe extends Ue{constructor(s){super(),We(this,s,Se,Ae,$e,{})}}export{Oe as component};
