import{s as je,o as Ue}from"../chunks/scheduler.37c15a92.js";import{S as xe,i as $e,g as h,s as c,r as J,A as we,h as g,f as n,c as p,j as ge,u as T,x as w,k as le,y as Ce,a as i,v as k,t as f,b as Je,d as M,w as j,m as _e,n as Ze,p as Te}from"../chunks/index.2bf4358c.js";import{T as We}from"../chunks/Tip.363c041f.js";import{C as A}from"../chunks/CodeBlock.4e987730.js";import{C as ke}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as ve}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ve,E as ze}from"../chunks/getInferenceSnippets.24b50994.js";function Ne(y){let s,r;return s=new ke({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){T(s.$$.fragment,l)},m(l,b){k(s,l,b),r=!0},i(l){r||(M(s.$$.fragment,l),r=!0)},o(l){f(s.$$.fragment,l),r=!1},d(l){j(s,l)}}}function Ee(y){let s,r;return s=new ke({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){T(s.$$.fragment,l)},m(l,b){k(s,l,b),r=!0},i(l){r||(M(s.$$.fragment,l),r=!0)},o(l){f(s.$$.fragment,l),r=!1},d(l){j(s,l)}}}function Qe(y){let s,r,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,m,d;return s=new A({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 A({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=c(),l=h("p"),l.innerHTML=b,u=c(),J(m.$$.fragment)},l(t){T(s.$$.fragment,t),r=p(t),l=g(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-1azn7ht"&&(l.innerHTML=b),u=p(t),T(m.$$.fragment,t)},m(t,o){k(s,t,o),i(t,r,o),i(t,l,o),i(t,u,o),k(m,t,o),d=!0},i(t){d||(M(s.$$.fragment,t),M(m.$$.fragment,t),d=!0)},o(t){f(s.$$.fragment,t),f(m.$$.fragment,t),d=!1},d(t){t&&(n(r),n(l),n(u)),j(s,t),j(m,t)}}}function Be(y){let s,r,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,m,d;return s=new A({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 A({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=c(),l=h("p"),l.innerHTML=b,u=c(),J(m.$$.fragment)},l(t){T(s.$$.fragment,t),r=p(t),l=g(t,"P",{"data-svelte-h":!0}),w(l)!=="svelte-x8u4jp"&&(l.innerHTML=b),u=p(t),T(m.$$.fragment,t)},m(t,o){k(s,t,o),i(t,r,o),i(t,l,o),i(t,u,o),k(m,t,o),d=!0},i(t){d||(M(s.$$.fragment,t),M(m.$$.fragment,t),d=!0)},o(t){f(s.$$.fragment,t),f(m.$$.fragment,t),d=!1},d(t){t&&(n(r),n(l),n(u)),j(s,t),j(m,t)}}}function Fe(y){let s;return{c(){s=_e("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(r){s=Ze(r,"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(r,l){i(r,s,l)},d(r){r&&n(s)}}}function Ge(y){let s,r,l,b,u,m,d,t,o,U,I,W,ie="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à.",S,v,re="Ad esempio assumiamo di stare cercando un modello francese sviluppato per ricostruire token mancanti (mask filling).",q,C,oe='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/camembert.gif" alt="Selecting the Camembert model." width="80%"/>',R,V,ce="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>:",L,z,H,N,D,E,pe="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:",P,_,me='<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,Q,ue="Potete anche istanziare il checkpoint usando direttamente l’architettura del modello:",O,x,$,Y,Z,ee,B,te,X,se;u=new ve({props:{fw:y[0]}}),d=new Ve({props:{title:"Usare modelli pre-addestrati",local:"usare-modelli-pre-addestrati",headingTag:"h1"}});const de=[Ee,Ne],F=[];function be(e,a){return e[0]==="pt"?0:1}o=be(y),U=F[o]=de[o](y),z=new A({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 A({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 fe=[Be,Qe],G=[];function Me(e,a){return e[0]==="pt"?0:1}return x=Me(y),$=G[x]=fe[x](y),Z=new We({props:{$$slots:{default:[Fe]},$$scope:{ctx:y}}}),B=new ze({props:{source:"https://github.com/huggingface/course/blob/main/chapters/it/chapter4/2.mdx"}}),{c(){s=h("meta"),r=c(),l=h("p"),b=c(),J(u.$$.fragment),m=c(),J(d.$$.fragment),t=c(),U.c(),I=c(),W=h("p"),W.textContent=ie,S=c(),v=h("p"),v.textContent=re,q=c(),C=h("div"),C.innerHTML=oe,R=c(),V=h("p"),V.innerHTML=ce,L=c(),J(z.$$.fragment),H=c(),J(N.$$.fragment),D=c(),E=h("p"),E.innerHTML=pe,P=c(),_=h("div"),_.innerHTML=me,K=c(),Q=h("p"),Q.textContent=ue,O=c(),$.c(),Y=c(),J(Z.$$.fragment),ee=c(),J(B.$$.fragment),te=c(),X=h("p"),this.h()},l(e){const a=we("svelte-u9bgzb",document.head);s=g(a,"META",{name:!0,content:!0}),a.forEach(n),r=p(e),l=g(e,"P",{}),ge(l).forEach(n),b=p(e),T(u.$$.fragment,e),m=p(e),T(d.$$.fragment,e),t=p(e),U.l(e),I=p(e),W=g(e,"P",{"data-svelte-h":!0}),w(W)!=="svelte-7tp54b"&&(W.textContent=ie),S=p(e),v=g(e,"P",{"data-svelte-h":!0}),w(v)!=="svelte-oliy4s"&&(v.textContent=re),q=p(e),C=g(e,"DIV",{class:!0,"data-svelte-h":!0}),w(C)!=="svelte-4k6hvy"&&(C.innerHTML=oe),R=p(e),V=g(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-xki06v"&&(V.innerHTML=ce),L=p(e),T(z.$$.fragment,e),H=p(e),T(N.$$.fragment,e),D=p(e),E=g(e,"P",{"data-svelte-h":!0}),w(E)!=="svelte-1v9xid5"&&(E.innerHTML=pe),P=p(e),_=g(e,"DIV",{class:!0,"data-svelte-h":!0}),w(_)!=="svelte-1cl7xbt"&&(_.innerHTML=me),K=p(e),Q=g(e,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-14oriir"&&(Q.textContent=ue),O=p(e),$.l(e),Y=p(e),T(Z.$$.fragment,e),ee=p(e),T(B.$$.fragment,e),te=p(e),X=g(e,"P",{}),ge(X).forEach(n),this.h()},h(){le(s,"name","hf:doc:metadata"),le(s,"content",Ie),le(C,"class","flex justify-center"),le(_,"class","flex justify-center")},m(e,a){Ce(document.head,s),i(e,r,a),i(e,l,a),i(e,b,a),k(u,e,a),i(e,m,a),k(d,e,a),i(e,t,a),F[o].m(e,a),i(e,I,a),i(e,W,a),i(e,S,a),i(e,v,a),i(e,q,a),i(e,C,a),i(e,R,a),i(e,V,a),i(e,L,a),k(z,e,a),i(e,H,a),k(N,e,a),i(e,D,a),i(e,E,a),i(e,P,a),i(e,_,a),i(e,K,a),i(e,Q,a),i(e,O,a),G[x].m(e,a),i(e,Y,a),k(Z,e,a),i(e,ee,a),k(B,e,a),i(e,te,a),i(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&&(Te(),f(F[ae],1,1,()=>{F[ae]=null}),Je(),U=F[o],U||(U=F[o]=de[o](e),U.c()),M(U,1),U.m(I.parentNode,I));let ne=x;x=Me(e),x!==ne&&(Te(),f(G[ne],1,1,()=>{G[ne]=null}),Je(),$=G[x],$||($=G[x]=fe[x](e),$.c()),M($,1),$.m(Y.parentNode,Y));const he={};a&2&&(he.$$scope={dirty:a,ctx:e}),Z.$set(he)},i(e){se||(M(u.$$.fragment,e),M(d.$$.fragment,e),M(U),M(z.$$.fragment,e),M(N.$$.fragment,e),M($),M(Z.$$.fragment,e),M(B.$$.fragment,e),se=!0)},o(e){f(u.$$.fragment,e),f(d.$$.fragment,e),f(U),f(z.$$.fragment,e),f(N.$$.fragment,e),f($),f(Z.$$.fragment,e),f(B.$$.fragment,e),se=!1},d(e){e&&(n(r),n(l),n(b),n(m),n(t),n(I),n(W),n(S),n(v),n(q),n(C),n(R),n(V),n(L),n(H),n(D),n(E),n(P),n(_),n(K),n(Q),n(O),n(Y),n(ee),n(te),n(X)),n(s),j(u,e),j(d,e),F[o].d(e),j(z,e),j(N,e),G[x].d(e),j(Z,e),j(B,e)}}}const Ie='{"title":"Usare modelli pre-addestrati","local":"usare-modelli-pre-addestrati","sections":[],"depth":1}';function Ye(y,s,r){let l="pt";return Ue(()=>{const b=new URLSearchParams(window.location.search);r(0,l=b.get("fw")||"pt")}),[l]}class De extends xe{constructor(s){super(),$e(this,s,Ye,Ge,je,{})}}export{De as component};
