import{s as Te,o as ke}from"../chunks/scheduler.37c15a92.js";import{S as je,i as Ue,g as h,s as p,r as j,A as xe,h as g,f as n,c as m,j as ye,u as U,x as w,k as te,y as $e,a as r,v as x,t as M,b as he,d as f,w as $,m as we,n as Ce,p as ge}from"../chunks/index.2bf4358c.js";import{T as _e}from"../chunks/Tip.363c041f.js";import{C as G}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Je}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Ze}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as We}from"../chunks/Heading.8ada512a.js";function ve(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/it/chapter4/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/it/chapter4/section2_tf.ipynb"}]}}),{c(){j(s.$$.fragment)},l(l){U(s.$$.fragment,l)},m(l,b){x(s,l,b),i=!0},i(l){i||(f(s.$$.fragment,l),i=!0)},o(l){M(s.$$.fragment,l),i=!1},d(l){$(s,l)}}}function Ve(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/it/chapter4/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/it/chapter4/section2_pt.ipynb"}]}}),{c(){j(s.$$.fragment)},l(l){U(s.$$.fragment,l)},m(l,b){x(s,l,b),i=!0},i(l){i||(f(s.$$.fragment,l),i=!0)},o(l){M(s.$$.fragment,l),i=!1},d(l){$(s,l)}}}function ze(y){let s,i,l,b='Tuttavia, noi consigliamo di usare le <a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow">classi <code>TFAuto*</code></a> quando possibile, poiché sono progettate per essere agnostiche rispetto al tipo di architettura del modello. Mentre il codice di esempio precedente limita gli utenti a caricare i checkpoint supportati dall’architettura CamemBERT, usare le classi <code>TFAuto*</code> rende facile il passaggio da un checkpoint ad un altro:',u,c,d;return s=new G({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 G({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=p(),l=h("p"),l.innerHTML=b,u=p(),j(c.$$.fragment)},l(t){U(s.$$.fragment,t),i=m(t),l=g(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1azn7ht"&&(l.innerHTML=b),u=m(t),U(c.$$.fragment,t)},m(t,o){x(s,t,o),r(t,i,o),r(t,l,o),r(t,u,o),x(c,t,o),d=!0},i(t){d||(f(s.$$.fragment,t),f(c.$$.fragment,t),d=!0)},o(t){M(s.$$.fragment,t),M(c.$$.fragment,t),d=!1},d(t){t&&(n(i),n(l),n(u)),$(s,t),$(c,t)}}}function Ne(y){let s,i,l,b='Tuttavia, noi consigliamo di usare le <a href="https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes" rel="nofollow">classi <code>Auto*</code></a> quando possibile, poiché sono progettate per essere agnostiche rispetto al tipo di architettura del modello. Mentre il codice di esempio precedente limita gli utenti a caricare i checkpoint supportati dall’architettura CamemBERT, usare le classi <code>Auto*</code> rende facile il passaggio da un checkpoint ad un altro:',u,c,d;return s=new G({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 G({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=p(),l=h("p"),l.innerHTML=b,u=p(),j(c.$$.fragment)},l(t){U(s.$$.fragment,t),i=m(t),l=g(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-x8u4jp"&&(l.innerHTML=b),u=m(t),U(c.$$.fragment,t)},m(t,o){x(s,t,o),r(t,i,o),r(t,l,o),r(t,u,o),x(c,t,o),d=!0},i(t){d||(f(s.$$.fragment,t),f(c.$$.fragment,t),d=!0)},o(t){M(s.$$.fragment,t),M(c.$$.fragment,t),d=!1},d(t){t&&(n(i),n(l),n(u)),$(s,t),$(c,t)}}}function Qe(y){let s;return{c(){s=we("Quando usate un modello pre-addestrato, assicuratevi di controllare come è stato addestrato, su quali dataset, i suoi limiti e i suoi bias. Tutte queste informazioni dovrebbero essere indicate sul cartellino del modello.")},l(i){s=Ce(i,"Quando usate un modello pre-addestrato, assicuratevi di controllare come è stato addestrato, su quali dataset, i suoi limiti e i suoi bias. Tutte queste informazioni dovrebbero essere indicate sul cartellino del modello.")},m(i,l){r(i,s,l)},d(i){i&&n(s)}}}function Ee(y){let s,i,l,b,u,c,d,t,o,J,I,W,ae="Usando l’Hub diventa molto facile selzionare il modello appropriato, così da poterlo usare in qualsiasi altro framework con solo poche righe di codice. Vediamo ora come usare un di questi modelli, e come contribuire allo sviluppo della comunità.",X,v,ne="Ad esempio assumiamo di stare cercando un modello francese sviluppato per ricostruire token mancanti (mask filling).",S,C,ie='<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,re="Selezioniamo il checkpoint <code>camembert-base</code> per provarlo. L’identificatore <code>camembert-base</code> è tutto quello che serve per inizializzarlo! Come si è visto in precedenti capitoli, è possibile istanziare il modello usando la funzione <code>pipeline()</code>:",R,z,L,N,H,Q,oe="Come potete vedere, caricare un modello all’interno di una pipeline è molto semplice. L’unico elemento da tenere in considerazione è che il checkpoint scelto sia adatto all’utilizzo che intendete farne. Ad esempio, noi abbiamo caricato il checkpoint <code>camembert-base</code> all’interno del pipeline <code>fill-mask</code>, che è corretto. Ma se dovessimo caricare questo checkpoint in un pipeline di classificazione del testo (<code>text-classification</code>), i risultati non avrebbero senso perché l’head di <code>camembert-base</code> non è adatto per questo obiettivo! Si consiglia di usare il filtro per obiettivi nell’interfaccia dell’Hub di Hugging Face per selezionare il checkpoint appropriato:",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,E,pe="Potete anche istanziare il checkpoint usando direttamente l’architettura del modello:",K,T,k,Y,Z,O,A,ee;u=new Ze({props:{fw:y[0]}}),d=new We({props:{title:"Usare modelli pre-addestrati",local:"usare-modelli-pre-addestrati",headingTag:"h1"}});const me=[Ve,ve],B=[];function ue(e,a){return e[0]==="pt"?0:1}o=ue(y),J=B[o]=me[o](y),z=new G({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}}),N=new G({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=[Ne,ze],F=[];function be(e,a){return e[0]==="pt"?0:1}return T=be(y),k=F[T]=de[T](y),Z=new _e({props:{$$slots:{default:[Qe]},$$scope:{ctx:y}}}),{c(){s=h("meta"),i=p(),l=h("p"),b=p(),j(u.$$.fragment),c=p(),j(d.$$.fragment),t=p(),J.c(),I=p(),W=h("p"),W.textContent=ae,X=p(),v=h("p"),v.textContent=ne,S=p(),C=h("div"),C.innerHTML=ie,q=p(),V=h("p"),V.innerHTML=re,R=p(),j(z.$$.fragment),L=p(),j(N.$$.fragment),H=p(),Q=h("p"),Q.innerHTML=oe,D=p(),_=h("div"),_.innerHTML=ce,P=p(),E=h("p"),E.textContent=pe,K=p(),k.c(),Y=p(),j(Z.$$.fragment),O=p(),A=h("p"),this.h()},l(e){const a=xe("svelte-u9bgzb",document.head);s=g(a,"META",{name:!0,content:!0}),a.forEach(n),i=m(e),l=g(e,"P",{}),ye(l).forEach(n),b=m(e),U(u.$$.fragment,e),c=m(e),U(d.$$.fragment,e),t=m(e),J.l(e),I=m(e),W=g(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-7tp54b"&&(W.textContent=ae),X=m(e),v=g(e,"P",{"data-svelte-h":!0}),w(v)!=="svelte-oliy4s"&&(v.textContent=ne),S=m(e),C=g(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=ie),q=m(e),V=g(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-xki06v"&&(V.innerHTML=re),R=m(e),U(z.$$.fragment,e),L=m(e),U(N.$$.fragment,e),H=m(e),Q=g(e,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-1v9xid5"&&(Q.innerHTML=oe),D=m(e),_=g(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=ce),P=m(e),E=g(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-14oriir"&&(E.textContent=pe),K=m(e),k.l(e),Y=m(e),U(Z.$$.fragment,e),O=m(e),A=g(e,"P",{}),ye(A).forEach(n),this.h()},h(){te(s,"name","hf:doc:metadata"),te(s,"content",Be),te(C,"class","flex justify-center"),te(_,"class","flex justify-center")},m(e,a){$e(document.head,s),r(e,i,a),r(e,l,a),r(e,b,a),x(u,e,a),r(e,c,a),x(d,e,a),r(e,t,a),B[o].m(e,a),r(e,I,a),r(e,W,a),r(e,X,a),r(e,v,a),r(e,S,a),r(e,C,a),r(e,q,a),r(e,V,a),r(e,R,a),x(z,e,a),r(e,L,a),x(N,e,a),r(e,H,a),r(e,Q,a),r(e,D,a),r(e,_,a),r(e,P,a),r(e,E,a),r(e,K,a),F[T].m(e,a),r(e,Y,a),x(Z,e,a),r(e,O,a),r(e,A,a),ee=!0},p(e,[a]){const Me={};a&1&&(Me.fw=e[0]),u.$set(Me);let se=o;o=ue(e),o!==se&&(ge(),M(B[se],1,1,()=>{B[se]=null}),he(),J=B[o],J||(J=B[o]=me[o](e),J.c()),f(J,1),J.m(I.parentNode,I));let le=T;T=be(e),T!==le&&(ge(),M(F[le],1,1,()=>{F[le]=null}),he(),k=F[T],k||(k=F[T]=de[T](e),k.c()),f(k,1),k.m(Y.parentNode,Y));const fe={};a&2&&(fe.$$scope={dirty:a,ctx:e}),Z.$set(fe)},i(e){ee||(f(u.$$.fragment,e),f(d.$$.fragment,e),f(J),f(z.$$.fragment,e),f(N.$$.fragment,e),f(k),f(Z.$$.fragment,e),ee=!0)},o(e){M(u.$$.fragment,e),M(d.$$.fragment,e),M(J),M(z.$$.fragment,e),M(N.$$.fragment,e),M(k),M(Z.$$.fragment,e),ee=!1},d(e){e&&(n(i),n(l),n(b),n(c),n(t),n(I),n(W),n(X),n(v),n(S),n(C),n(q),n(V),n(R),n(L),n(H),n(Q),n(D),n(_),n(P),n(E),n(K),n(Y),n(O),n(A)),n(s),$(u,e),$(d,e),B[o].d(e),$(z,e),$(N,e),F[T].d(e),$(Z,e)}}}const Be='{"title":"Usare modelli pre-addestrati","local":"usare-modelli-pre-addestrati","sections":[],"depth":1}';function Fe(y,s,i){let l="pt";return ke(()=>{const b=new URLSearchParams(window.location.search);i(0,l=b.get("fw")||"pt")}),[l]}class Re extends je{constructor(s){super(),Ue(this,s,Fe,Ee,Te,{})}}export{Re as component};
