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