import{S as $t,i as Et,s as It,e as n,k as c,w as h,t as a,M as Tt,c as o,d as l,m as u,a as p,x as f,h as t,b as m,N as kt,G as s,g as r,y as M,q as y,o as j,B as g,v as zt}from"../chunks/vendor-hf-doc-builder.js";import{T as Zt}from"../chunks/Tip-hf-doc-builder.js";import{I as ps}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as T}from"../chunks/CodeBlock-hf-doc-builder.js";function _t(rs){let d,V,v,w,C;return{c(){d=n("p"),V=a("Dai un\u2019occhiata alla documentazione di "),v=n("code"),w=a("pipeline()"),C=a(" per una lista completa dei compiti supportati.")},l(J){d=o(J,"P",{});var k=p(d);V=t(k,"Dai un\u2019occhiata alla documentazione di "),v=o(k,"CODE",{});var q=p(v);w=t(q,"pipeline()"),q.forEach(l),C=t(k," per una lista completa dei compiti supportati."),k.forEach(l)},m(J,k){r(J,d,k),s(d,V),s(d,v),s(v,w),s(d,C)},d(J){J&&l(d)}}}function Ct(rs){let d,V,v,w,C,J,k,q,al,cs,$,tl,ze,il,nl,O,ol,pl,Ze,rl,cl,us,z,K,ul,_e,ml,dl,hl,Ce,fl,Ml,ee,yl,Ge,jl,gl,ms,R,ds,G,S,xe,se,Ul,Be,vl,hs,E,bl,We,Jl,wl,Ve,$l,El,qe,Il,Tl,fs,be,le,kl,Re,zl,Zl,Ms,ae,ys,te,ie,_l,Se,Cl,Gl,js,ne,gs,Je,xl,Us,oe,vs,b,Bl,Ae,Wl,Vl,Ne,ql,Rl,Xe,Sl,Al,He,Nl,Xl,bs,pe,Js,x,A,Qe,re,Hl,De,Ql,ws,U,Dl,Pe,Pl,Yl,ce,Fl,Ll,Ye,Ol,Kl,Fe,ea,sa,Le,la,aa,$s,ue,Es,N,ta,Oe,ia,na,Is,me,Ts,X,oa,Ke,pa,ra,ks,de,zs,B,H,es,he,ca,ss,ua,Zs,Q,ma,ls,da,ha,_s,we,fa,Cs,fe,Gs,Z,Ma,Me,ya,ja,as,ga,Ua,xs,ye,Bs,D,va,ts,ba,Ja,Ws,je,Vs,W,P,is,ge,wa,ns,$a,qs,Y,Ea,os,Ia,Ta,Rs,$e,ka,Ss,Ee,Ie,za,As,Ue,Ns;return J=new ps({}),R=new Zt({props:{$$slots:{default:[_t]},$$scope:{ctx:rs}}}),se=new ps({}),ae=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBZ2VuZXJhdG9yJTIwJTNEJTIwcGlwZWxpbmUodGFzayUzRCUyMnRleHQtZ2VuZXJhdGlvbiUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>generator = pipeline(task=<span class="hljs-string">&quot;text-generation&quot;</span>)`}}),ne=new T({props:{code:"Z2VuZXJhdG9yKCUwQSUyMCUyMCUyMCUyMCUyMlRocmVlJTIwUmluZ3MlMjBmb3IlMjB0aGUlMjBFbHZlbi1raW5ncyUyMHVuZGVyJTIwdGhlJTIwc2t5JTJDJTIwU2V2ZW4lMjBmb3IlMjB0aGUlMjBEd2FyZi1sb3JkcyUyMGluJTIwdGhlaXIlMjBoYWxscyUyMG9mJTIwc3RvbmUlMjIlMEEpJTIwJTIwJTIzJTIwZG9jdGVzdCUzQSUyMCUyQlNLSVA=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>generator(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone&quot;</span>
<span class="hljs-meta">... </span>)  <span class="hljs-comment"># doctest: +SKIP</span>
[{<span class="hljs-string">&#x27;generated_text&#x27;</span>: <span class="hljs-string">&#x27;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Seven for the Iron-priests at the door to the east, and thirteen for the Lord Kings at the end of the mountain&#x27;</span>}]`}}),oe=new T({props:{code:"Z2VuZXJhdG9yKCUwQSUyMCUyMCUyMCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMlRocmVlJTIwUmluZ3MlMjBmb3IlMjB0aGUlMjBFbHZlbi1raW5ncyUyMHVuZGVyJTIwdGhlJTIwc2t5JTJDJTIwU2V2ZW4lMjBmb3IlMjB0aGUlMjBEd2FyZi1sb3JkcyUyMGluJTIwdGhlaXIlMjBoYWxscyUyMG9mJTIwc3RvbmUlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJOaW5lJTIwZm9yJTIwTW9ydGFsJTIwTWVuJTJDJTIwZG9vbWVkJTIwdG8lMjBkaWUlMkMlMjBPbmUlMjBmb3IlMjB0aGUlMjBEYXJrJTIwTG9yZCUyMG9uJTIwaGlzJTIwZGFyayUyMHRocm9uZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCU1RCUwQSklMjAlMjAlMjMlMjBkb2N0ZXN0JTNBJTIwJTJCU0tJUA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>generator(
<span class="hljs-meta">... </span>    [
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;Nine for Mortal Men, doomed to die, One for the Dark Lord on his dark throne&quot;</span>,
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)  <span class="hljs-comment"># doctest: +SKIP</span>`}}),pe=new T({props:{code:"Z2VuZXJhdG9yKCUwQSUyMCUyMCUyMCUyMCUyMlRocmVlJTIwUmluZ3MlMjBmb3IlMjB0aGUlMjBFbHZlbi1raW5ncyUyMHVuZGVyJTIwdGhlJTIwc2t5JTJDJTIwU2V2ZW4lMjBmb3IlMjB0aGUlMjBEd2FyZi1sb3JkcyUyMGluJTIwdGhlaXIlMjBoYWxscyUyMG9mJTIwc3RvbmUlMjIlMkMlMEElMjAlMjAlMjAlMjBudW1fcmV0dXJuX3NlcXVlbmNlcyUzRDIlMkMlMEEpJTIwJTIwJTIzJTIwZG9jdGVzdCUzQSUyMCUyQlNLSVA=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>generator(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone&quot;</span>,
<span class="hljs-meta">... </span>    num_return_sequences=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>)  <span class="hljs-comment"># doctest: +SKIP</span>`}}),re=new ps({}),ue=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmRpc3RpbGdwdDIlMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyZGlzdGlsZ3B0MiUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilgpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;distilgpt2&quot;</span>)`}}),me=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBZ2VuZXJhdG9yJTIwJTNEJTIwcGlwZWxpbmUodGFzayUzRCUyMnRleHQtZ2VuZXJhdGlvbiUyMiUyQyUyMG1vZGVsJTNEbW9kZWwlMkMlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>generator = pipeline(task=<span class="hljs-string">&quot;text-generation&quot;</span>, model=model, tokenizer=tokenizer)`}}),de=new T({props:{code:"Z2VuZXJhdG9yKCUwQSUyMCUyMCUyMCUyMCUyMlRocmVlJTIwUmluZ3MlMjBmb3IlMjB0aGUlMjBFbHZlbi1raW5ncyUyMHVuZGVyJTIwdGhlJTIwc2t5JTJDJTIwU2V2ZW4lMjBmb3IlMjB0aGUlMjBEd2FyZi1sb3JkcyUyMGluJTIwdGhlaXIlMjBoYWxscyUyMG9mJTIwc3RvbmUlMjIlMEEpJTIwJTIwJTIzJTIwZG9jdGVzdCUzQSUyMCUyQlNLSVA=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>generator(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone&quot;</span>
<span class="hljs-meta">... </span>)  <span class="hljs-comment"># doctest: +SKIP</span>
[{<span class="hljs-string">&#x27;generated_text&#x27;</span>: <span class="hljs-string">&#x27;Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Seven for the Dragon-lords (for them to rule in a world ruled by their rulers, and all who live within the realm&#x27;</span>}]`}}),he=new ps({}),fe=new T({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBaW1wb3J0JTIwdG9yY2glMEElMEF0b3JjaC5tYW51YWxfc2VlZCg0MiklMEFkcyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJoZi1pbnRlcm5hbC10ZXN0aW5nJTJGbGlicmlzcGVlY2hfYXNyX2RlbW8lMjIlMkMlMjAlMjJjbGVhbiUyMiUyQyUyMHNwbGl0JTNEJTIydmFsaWRhdGlvbiUyMiklMEFhdWRpb19maWxlJTIwJTNEJTIwZHMlNUIwJTVEJTVCJTIyYXVkaW8lMjIlNUQlNUIlMjJwYXRoJTIyJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>torch.manual_seed(<span class="hljs-number">42</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>ds = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/librispeech_asr_demo&quot;</span>, <span class="hljs-string">&quot;clean&quot;</span>, split=<span class="hljs-string">&quot;validation&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>audio_file = ds[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;path&quot;</span>]`}}),ye=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBYXVkaW9fY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMHRhc2slM0QlMjJhdWRpby1jbGFzc2lmaWNhdGlvbiUyMiUyQyUyMG1vZGVsJTNEJTIyZWhjYWxhYnJlcyUyRndhdjJ2ZWMyLWxnLXhsc3ItZW4tc3BlZWNoLWVtb3Rpb24tcmVjb2duaXRpb24lMjIlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>audio_classifier = pipeline(
<span class="hljs-meta">... </span>    task=<span class="hljs-string">&quot;audio-classification&quot;</span>, model=<span class="hljs-string">&quot;ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition&quot;</span>
<span class="hljs-meta">... </span>)`}}),je=new T({props:{code:"cHJlZHMlMjAlM0QlMjBhdWRpb19jbGFzc2lmaWVyKGF1ZGlvX2ZpbGUpJTBBcHJlZHMlMjAlM0QlMjAlNUIlN0IlMjJzY29yZSUyMiUzQSUyMHJvdW5kKHByZWQlNUIlMjJzY29yZSUyMiU1RCUyQyUyMDQpJTJDJTIwJTIybGFiZWwlMjIlM0ElMjBwcmVkJTVCJTIybGFiZWwlMjIlNUQlN0QlMjBmb3IlMjBwcmVkJTIwaW4lMjBwcmVkcyU1RCUwQXByZWRz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>preds = audio_classifier(audio_file)
<span class="hljs-meta">&gt;&gt;&gt; </span>preds = [{<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-built_in">round</span>(pred[<span class="hljs-string">&quot;score&quot;</span>], <span class="hljs-number">4</span>), <span class="hljs-string">&quot;label&quot;</span>: pred[<span class="hljs-string">&quot;label&quot;</span>]} <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
<span class="hljs-meta">&gt;&gt;&gt; </span>preds
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1315</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;calm&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1307</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;neutral&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1274</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;sad&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1261</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;fearful&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.1242</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;happy&#x27;</span>}]`}}),ge=new ps({}),Ue=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBdmlzaW9uX2NsYXNzaWZpZXIlMjAlM0QlMjBwaXBlbGluZSh0YXNrJTNEJTIyaW1hZ2UtY2xhc3NpZmljYXRpb24lMjIpJTBBcHJlZHMlMjAlM0QlMjB2aXNpb25fY2xhc3NpZmllciglMEElMjAlMjAlMjAlMjBpbWFnZXMlM0QlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZodWdnaW5nZmFjZSUyRmRvY3VtZW50YXRpb24taW1hZ2VzJTJGcmVzb2x2ZSUyRm1haW4lMkZwaXBlbGluZS1jYXQtY2hvbmsuanBlZyUyMiUwQSklMEFwcmVkcyUyMCUzRCUyMCU1QiU3QiUyMnNjb3JlJTIyJTNBJTIwcm91bmQocHJlZCU1QiUyMnNjb3JlJTIyJTVEJTJDJTIwNCklMkMlMjAlMjJsYWJlbCUyMiUzQSUyMHByZWQlNUIlMjJsYWJlbCUyMiU1RCU3RCUyMGZvciUyMHByZWQlMjBpbiUyMHByZWRzJTVEJTBBcHJlZHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>vision_classifier = pipeline(task=<span class="hljs-string">&quot;image-classification&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>preds = vision_classifier(
<span class="hljs-meta">... </span>    images=<span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>preds = [{<span class="hljs-string">&quot;score&quot;</span>: <span class="hljs-built_in">round</span>(pred[<span class="hljs-string">&quot;score&quot;</span>], <span class="hljs-number">4</span>), <span class="hljs-string">&quot;label&quot;</span>: pred[<span class="hljs-string">&quot;label&quot;</span>]} <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
<span class="hljs-meta">&gt;&gt;&gt; </span>preds
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.4335</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;lynx, catamount&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0348</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;cougar, puma, catamount, mountain lion, painter, panther, Felis concolor&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0324</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;snow leopard, ounce, Panthera uncia&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0239</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;Egyptian cat&#x27;</span>}, {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.0229</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;tiger cat&#x27;</span>}]`}}),{c(){d=n("meta"),V=c(),v=n("h1"),w=n("a"),C=n("span"),h(J.$$.fragment),k=c(),q=n("span"),al=a("Pipeline per l'inferenza"),cs=c(),$=n("p"),tl=a("La "),ze=n("code"),il=a("pipeline()"),nl=a(" rende semplice usare qualsiasi modello dal "),O=n("a"),ol=a("Model Hub"),pl=a(" per fare inferenza su diversi compiti come generazione del testo, segmentazione di immagini e classificazione di audio. Anche se non hai esperienza con una modalit\xE0 specifica o non comprendi bene il codice che alimenta i modelli, \xE8 comunque possibile utilizzarli con l\u2019opzione "),Ze=n("code"),rl=a("pipeline()"),cl=a("! Questa esercitazione ti insegner\xE0 a:"),us=c(),z=n("ul"),K=n("li"),ul=a("Usare una "),_e=n("code"),ml=a("pipeline()"),dl=a(" per fare inferenza."),hl=c(),Ce=n("li"),fl=a("Usare uno specifico tokenizer o modello."),Ml=c(),ee=n("li"),yl=a("Usare una "),Ge=n("code"),jl=a("pipeline()"),gl=a(" per compiti che riguardano audio e video."),ms=c(),h(R.$$.fragment),ds=c(),G=n("h2"),S=n("a"),xe=n("span"),h(se.$$.fragment),Ul=c(),Be=n("span"),vl=a("Utilizzo della Pipeline"),hs=c(),E=n("p"),bl=a("Nonostante ogni compito abbia una "),We=n("code"),Jl=a("pipeline()"),wl=a(" associata, \xE8 pi\xF9 semplice utilizzare l\u2019astrazione generica della "),Ve=n("code"),$l=a("pipeline()"),El=a(" che contiene tutte quelle specifiche per ogni mansione. La "),qe=n("code"),Il=a("pipeline()"),Tl=a(" carica automaticamente un modello predefinito e un tokenizer in grado di fare inferenza per il tuo compito."),fs=c(),be=n("ol"),le=n("li"),kl=a("Inizia creando una "),Re=n("code"),zl=a("pipeline()"),Zl=a(" e specificando il compito su cui fare inferenza:"),Ms=c(),h(ae.$$.fragment),ys=c(),te=n("ol"),ie=n("li"),_l=a("Inserisci il testo in input nella "),Se=n("code"),Cl=a("pipeline()"),Gl=a(":"),js=c(),h(ne.$$.fragment),gs=c(),Je=n("p"),xl=a("Se hai pi\xF9 di un input, inseriscilo in una lista:"),Us=c(),h(oe.$$.fragment),vs=c(),b=n("p"),Bl=a("Qualsiasi parametro addizionale per il tuo compito pu\xF2 essere incluso nella "),Ae=n("code"),Wl=a("pipeline()"),Vl=a(". La mansione "),Ne=n("code"),ql=a("text-generation"),Rl=a(" ha un metodo "),Xe=n("code"),Sl=a("generate()"),Al=a(" con diversi parametri per controllare l\u2019output. Ad esempio, se desideri generare pi\xF9 di un output, utilizza il parametro "),He=n("code"),Nl=a("num_return_sequences"),Xl=a(":"),bs=c(),h(pe.$$.fragment),Js=c(),x=n("h3"),A=n("a"),Qe=n("span"),h(re.$$.fragment),Hl=c(),De=n("span"),Ql=a("Scegliere modello e tokenizer"),ws=c(),U=n("p"),Dl=a("La "),Pe=n("code"),Pl=a("pipeline()"),Yl=a(" accetta qualsiasi modello dal "),ce=n("a"),Fl=a("Model Hub"),Ll=a(". Ci sono tag nel Model Hub che consentono di filtrare i modelli per attivit\xE0. Una volta che avrai scelto il modello appropriato, caricalo usando la corrispondente classe "),Ye=n("code"),Ol=a("AutoModelFor"),Kl=a(" e "),Fe=n("code"),ea=a("AutoTokenizer"),sa=a(". Ad esempio, carica la classe "),Le=n("code"),la=a("AutoModelForCausalLM"),aa=a(" per un compito di causal language modeling:"),$s=c(),h(ue.$$.fragment),Es=c(),N=n("p"),ta=a("Crea una "),Oe=n("code"),ia=a("pipeline()"),na=a(" per il tuo compito, specificando il modello e il tokenizer che hai caricato:"),Is=c(),h(me.$$.fragment),Ts=c(),X=n("p"),oa=a("Inserisci il testo di input nella "),Ke=n("code"),pa=a("pipeline()"),ra=a(" per generare del testo:"),ks=c(),h(de.$$.fragment),zs=c(),B=n("h2"),H=n("a"),es=n("span"),h(he.$$.fragment),ca=c(),ss=n("span"),ua=a("Audio pipeline"),Zs=c(),Q=n("p"),ma=a("La flessibilit\xE0 della "),ls=n("code"),da=a("pipeline()"),ha=a(" fa si che possa essere estesa ad attivit\xE0 sugli audio."),_s=c(),we=n("p"),fa=a("Per esempio, classifichiamo le emozioni in questo clip audio:"),Cs=c(),h(fe.$$.fragment),Gs=c(),Z=n("p"),Ma=a("Trova un modello per la "),Me=n("a"),ya=a("classificazione audio"),ja=a(" sul Model Hub per eseguire un compito di riconoscimento automatico delle emozioni e caricalo nella "),as=n("code"),ga=a("pipeline()"),Ua=a(":"),xs=c(),h(ye.$$.fragment),Bs=c(),D=n("p"),va=a("Inserisci il file audio nella "),ts=n("code"),ba=a("pipeline()"),Ja=a(":"),Ws=c(),h(je.$$.fragment),Vs=c(),W=n("h2"),P=n("a"),is=n("span"),h(ge.$$.fragment),wa=c(),ns=n("span"),$a=a("Vision pipeline"),qs=c(),Y=n("p"),Ea=a("Infine, usare la "),os=n("code"),Ia=a("pipeline()"),Ta=a(" per le attivit\xE0 sulle immagini \xE8 praticamente la stessa cosa."),Rs=c(),$e=n("p"),ka=a("Specifica la tua attivit\xE0 e inserisci l\u2019immagine nel classificatore. L\u2019immagine pu\xF2 essere sia un link che un percorso sul tuo pc in locale. Per esempio, quale specie di gatto \xE8 raffigurata qui sotto?"),Ss=c(),Ee=n("p"),Ie=n("img"),As=c(),h(Ue.$$.fragment),this.h()},l(e){const i=Tt('[data-svelte="svelte-1phssyn"]',document.head);d=o(i,"META",{name:!0,content:!0}),i.forEach(l),V=u(e),v=o(e,"H1",{class:!0});var ve=p(v);w=o(ve,"A",{id:!0,class:!0,href:!0});var Za=p(w);C=o(Za,"SPAN",{});var _a=p(C);f(J.$$.fragment,_a),_a.forEach(l),Za.forEach(l),k=u(ve),q=o(ve,"SPAN",{});var Ca=p(q);al=t(Ca,"Pipeline per l'inferenza"),Ca.forEach(l),ve.forEach(l),cs=u(e),$=o(e,"P",{});var F=p($);tl=t(F,"La "),ze=o(F,"CODE",{});var Ga=p(ze);il=t(Ga,"pipeline()"),Ga.forEach(l),nl=t(F," rende semplice usare qualsiasi modello dal "),O=o(F,"A",{href:!0,rel:!0});var xa=p(O);ol=t(xa,"Model Hub"),xa.forEach(l),pl=t(F," per fare inferenza su diversi compiti come generazione del testo, segmentazione di immagini e classificazione di audio. Anche se non hai esperienza con una modalit\xE0 specifica o non comprendi bene il codice che alimenta i modelli, \xE8 comunque possibile utilizzarli con l\u2019opzione "),Ze=o(F,"CODE",{});var Ba=p(Ze);rl=t(Ba,"pipeline()"),Ba.forEach(l),cl=t(F,"! Questa esercitazione ti insegner\xE0 a:"),F.forEach(l),us=u(e),z=o(e,"UL",{});var Te=p(z);K=o(Te,"LI",{});var Xs=p(K);ul=t(Xs,"Usare una "),_e=o(Xs,"CODE",{});var Wa=p(_e);ml=t(Wa,"pipeline()"),Wa.forEach(l),dl=t(Xs," per fare inferenza."),Xs.forEach(l),hl=u(Te),Ce=o(Te,"LI",{});var Va=p(Ce);fl=t(Va,"Usare uno specifico tokenizer o modello."),Va.forEach(l),Ml=u(Te),ee=o(Te,"LI",{});var Hs=p(ee);yl=t(Hs,"Usare una "),Ge=o(Hs,"CODE",{});var qa=p(Ge);jl=t(qa,"pipeline()"),qa.forEach(l),gl=t(Hs," per compiti che riguardano audio e video."),Hs.forEach(l),Te.forEach(l),ms=u(e),f(R.$$.fragment,e),ds=u(e),G=o(e,"H2",{class:!0});var Qs=p(G);S=o(Qs,"A",{id:!0,class:!0,href:!0});var Ra=p(S);xe=o(Ra,"SPAN",{});var Sa=p(xe);f(se.$$.fragment,Sa),Sa.forEach(l),Ra.forEach(l),Ul=u(Qs),Be=o(Qs,"SPAN",{});var Aa=p(Be);vl=t(Aa,"Utilizzo della Pipeline"),Aa.forEach(l),Qs.forEach(l),hs=u(e),E=o(e,"P",{});var L=p(E);bl=t(L,"Nonostante ogni compito abbia una "),We=o(L,"CODE",{});var Na=p(We);Jl=t(Na,"pipeline()"),Na.forEach(l),wl=t(L," associata, \xE8 pi\xF9 semplice utilizzare l\u2019astrazione generica della "),Ve=o(L,"CODE",{});var Xa=p(Ve);$l=t(Xa,"pipeline()"),Xa.forEach(l),El=t(L," che contiene tutte quelle specifiche per ogni mansione. La "),qe=o(L,"CODE",{});var Ha=p(qe);Il=t(Ha,"pipeline()"),Ha.forEach(l),Tl=t(L," carica automaticamente un modello predefinito e un tokenizer in grado di fare inferenza per il tuo compito."),L.forEach(l),fs=u(e),be=o(e,"OL",{});var Qa=p(be);le=o(Qa,"LI",{});var Ds=p(le);kl=t(Ds,"Inizia creando una "),Re=o(Ds,"CODE",{});var Da=p(Re);zl=t(Da,"pipeline()"),Da.forEach(l),Zl=t(Ds," e specificando il compito su cui fare inferenza:"),Ds.forEach(l),Qa.forEach(l),Ms=u(e),f(ae.$$.fragment,e),ys=u(e),te=o(e,"OL",{start:!0});var Pa=p(te);ie=o(Pa,"LI",{});var Ps=p(ie);_l=t(Ps,"Inserisci il testo in input nella "),Se=o(Ps,"CODE",{});var Ya=p(Se);Cl=t(Ya,"pipeline()"),Ya.forEach(l),Gl=t(Ps,":"),Ps.forEach(l),Pa.forEach(l),js=u(e),f(ne.$$.fragment,e),gs=u(e),Je=o(e,"P",{});var Fa=p(Je);xl=t(Fa,"Se hai pi\xF9 di un input, inseriscilo in una lista:"),Fa.forEach(l),Us=u(e),f(oe.$$.fragment,e),vs=u(e),b=o(e,"P",{});var _=p(b);Bl=t(_,"Qualsiasi parametro addizionale per il tuo compito pu\xF2 essere incluso nella "),Ae=o(_,"CODE",{});var La=p(Ae);Wl=t(La,"pipeline()"),La.forEach(l),Vl=t(_,". La mansione "),Ne=o(_,"CODE",{});var Oa=p(Ne);ql=t(Oa,"text-generation"),Oa.forEach(l),Rl=t(_," ha un metodo "),Xe=o(_,"CODE",{});var Ka=p(Xe);Sl=t(Ka,"generate()"),Ka.forEach(l),Al=t(_," con diversi parametri per controllare l\u2019output. Ad esempio, se desideri generare pi\xF9 di un output, utilizza il parametro "),He=o(_,"CODE",{});var et=p(He);Nl=t(et,"num_return_sequences"),et.forEach(l),Xl=t(_,":"),_.forEach(l),bs=u(e),f(pe.$$.fragment,e),Js=u(e),x=o(e,"H3",{class:!0});var Ys=p(x);A=o(Ys,"A",{id:!0,class:!0,href:!0});var st=p(A);Qe=o(st,"SPAN",{});var lt=p(Qe);f(re.$$.fragment,lt),lt.forEach(l),st.forEach(l),Hl=u(Ys),De=o(Ys,"SPAN",{});var at=p(De);Ql=t(at,"Scegliere modello e tokenizer"),at.forEach(l),Ys.forEach(l),ws=u(e),U=o(e,"P",{});var I=p(U);Dl=t(I,"La "),Pe=o(I,"CODE",{});var tt=p(Pe);Pl=t(tt,"pipeline()"),tt.forEach(l),Yl=t(I," accetta qualsiasi modello dal "),ce=o(I,"A",{href:!0,rel:!0});var it=p(ce);Fl=t(it,"Model Hub"),it.forEach(l),Ll=t(I,". Ci sono tag nel Model Hub che consentono di filtrare i modelli per attivit\xE0. Una volta che avrai scelto il modello appropriato, caricalo usando la corrispondente classe "),Ye=o(I,"CODE",{});var nt=p(Ye);Ol=t(nt,"AutoModelFor"),nt.forEach(l),Kl=t(I," e "),Fe=o(I,"CODE",{});var ot=p(Fe);ea=t(ot,"AutoTokenizer"),ot.forEach(l),sa=t(I,". Ad esempio, carica la classe "),Le=o(I,"CODE",{});var pt=p(Le);la=t(pt,"AutoModelForCausalLM"),pt.forEach(l),aa=t(I," per un compito di causal language modeling:"),I.forEach(l),$s=u(e),f(ue.$$.fragment,e),Es=u(e),N=o(e,"P",{});var Fs=p(N);ta=t(Fs,"Crea una "),Oe=o(Fs,"CODE",{});var rt=p(Oe);ia=t(rt,"pipeline()"),rt.forEach(l),na=t(Fs," per il tuo compito, specificando il modello e il tokenizer che hai caricato:"),Fs.forEach(l),Is=u(e),f(me.$$.fragment,e),Ts=u(e),X=o(e,"P",{});var Ls=p(X);oa=t(Ls,"Inserisci il testo di input nella "),Ke=o(Ls,"CODE",{});var ct=p(Ke);pa=t(ct,"pipeline()"),ct.forEach(l),ra=t(Ls," per generare del testo:"),Ls.forEach(l),ks=u(e),f(de.$$.fragment,e),zs=u(e),B=o(e,"H2",{class:!0});var Os=p(B);H=o(Os,"A",{id:!0,class:!0,href:!0});var ut=p(H);es=o(ut,"SPAN",{});var mt=p(es);f(he.$$.fragment,mt),mt.forEach(l),ut.forEach(l),ca=u(Os),ss=o(Os,"SPAN",{});var dt=p(ss);ua=t(dt,"Audio pipeline"),dt.forEach(l),Os.forEach(l),Zs=u(e),Q=o(e,"P",{});var Ks=p(Q);ma=t(Ks,"La flessibilit\xE0 della "),ls=o(Ks,"CODE",{});var ht=p(ls);da=t(ht,"pipeline()"),ht.forEach(l),ha=t(Ks," fa si che possa essere estesa ad attivit\xE0 sugli audio."),Ks.forEach(l),_s=u(e),we=o(e,"P",{});var ft=p(we);fa=t(ft,"Per esempio, classifichiamo le emozioni in questo clip audio:"),ft.forEach(l),Cs=u(e),f(fe.$$.fragment,e),Gs=u(e),Z=o(e,"P",{});var ke=p(Z);Ma=t(ke,"Trova un modello per la "),Me=o(ke,"A",{href:!0,rel:!0});var Mt=p(Me);ya=t(Mt,"classificazione audio"),Mt.forEach(l),ja=t(ke," sul Model Hub per eseguire un compito di riconoscimento automatico delle emozioni e caricalo nella "),as=o(ke,"CODE",{});var yt=p(as);ga=t(yt,"pipeline()"),yt.forEach(l),Ua=t(ke,":"),ke.forEach(l),xs=u(e),f(ye.$$.fragment,e),Bs=u(e),D=o(e,"P",{});var el=p(D);va=t(el,"Inserisci il file audio nella "),ts=o(el,"CODE",{});var jt=p(ts);ba=t(jt,"pipeline()"),jt.forEach(l),Ja=t(el,":"),el.forEach(l),Ws=u(e),f(je.$$.fragment,e),Vs=u(e),W=o(e,"H2",{class:!0});var sl=p(W);P=o(sl,"A",{id:!0,class:!0,href:!0});var gt=p(P);is=o(gt,"SPAN",{});var Ut=p(is);f(ge.$$.fragment,Ut),Ut.forEach(l),gt.forEach(l),wa=u(sl),ns=o(sl,"SPAN",{});var vt=p(ns);$a=t(vt,"Vision pipeline"),vt.forEach(l),sl.forEach(l),qs=u(e),Y=o(e,"P",{});var ll=p(Y);Ea=t(ll,"Infine, usare la "),os=o(ll,"CODE",{});var bt=p(os);Ia=t(bt,"pipeline()"),bt.forEach(l),Ta=t(ll," per le attivit\xE0 sulle immagini \xE8 praticamente la stessa cosa."),ll.forEach(l),Rs=u(e),$e=o(e,"P",{});var Jt=p($e);ka=t(Jt,"Specifica la tua attivit\xE0 e inserisci l\u2019immagine nel classificatore. L\u2019immagine pu\xF2 essere sia un link che un percorso sul tuo pc in locale. Per esempio, quale specie di gatto \xE8 raffigurata qui sotto?"),Jt.forEach(l),Ss=u(e),Ee=o(e,"P",{});var wt=p(Ee);Ie=o(wt,"IMG",{src:!0,alt:!0}),wt.forEach(l),As=u(e),f(Ue.$$.fragment,e),this.h()},h(){m(d,"name","hf:doc:metadata"),m(d,"content",JSON.stringify(Gt)),m(w,"id","pipeline-per-linferenza"),m(w,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(w,"href","#pipeline-per-linferenza"),m(v,"class","relative group"),m(O,"href","https://huggingface.co/models"),m(O,"rel","nofollow"),m(S,"id","utilizzo-della-pipeline"),m(S,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(S,"href","#utilizzo-della-pipeline"),m(G,"class","relative group"),m(te,"start","2"),m(A,"id","scegliere-modello-e-tokenizer"),m(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(A,"href","#scegliere-modello-e-tokenizer"),m(x,"class","relative group"),m(ce,"href","https://huggingface.co/models"),m(ce,"rel","nofollow"),m(H,"id","audio-pipeline"),m(H,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(H,"href","#audio-pipeline"),m(B,"class","relative group"),m(Me,"href","https://huggingface.co/models?pipeline_tag=audio-classification"),m(Me,"rel","nofollow"),m(P,"id","vision-pipeline"),m(P,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(P,"href","#vision-pipeline"),m(W,"class","relative group"),kt(Ie.src,za="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")||m(Ie,"src",za),m(Ie,"alt","pipeline-cat-chonk")},m(e,i){s(document.head,d),r(e,V,i),r(e,v,i),s(v,w),s(w,C),M(J,C,null),s(v,k),s(v,q),s(q,al),r(e,cs,i),r(e,$,i),s($,tl),s($,ze),s(ze,il),s($,nl),s($,O),s(O,ol),s($,pl),s($,Ze),s(Ze,rl),s($,cl),r(e,us,i),r(e,z,i),s(z,K),s(K,ul),s(K,_e),s(_e,ml),s(K,dl),s(z,hl),s(z,Ce),s(Ce,fl),s(z,Ml),s(z,ee),s(ee,yl),s(ee,Ge),s(Ge,jl),s(ee,gl),r(e,ms,i),M(R,e,i),r(e,ds,i),r(e,G,i),s(G,S),s(S,xe),M(se,xe,null),s(G,Ul),s(G,Be),s(Be,vl),r(e,hs,i),r(e,E,i),s(E,bl),s(E,We),s(We,Jl),s(E,wl),s(E,Ve),s(Ve,$l),s(E,El),s(E,qe),s(qe,Il),s(E,Tl),r(e,fs,i),r(e,be,i),s(be,le),s(le,kl),s(le,Re),s(Re,zl),s(le,Zl),r(e,Ms,i),M(ae,e,i),r(e,ys,i),r(e,te,i),s(te,ie),s(ie,_l),s(ie,Se),s(Se,Cl),s(ie,Gl),r(e,js,i),M(ne,e,i),r(e,gs,i),r(e,Je,i),s(Je,xl),r(e,Us,i),M(oe,e,i),r(e,vs,i),r(e,b,i),s(b,Bl),s(b,Ae),s(Ae,Wl),s(b,Vl),s(b,Ne),s(Ne,ql),s(b,Rl),s(b,Xe),s(Xe,Sl),s(b,Al),s(b,He),s(He,Nl),s(b,Xl),r(e,bs,i),M(pe,e,i),r(e,Js,i),r(e,x,i),s(x,A),s(A,Qe),M(re,Qe,null),s(x,Hl),s(x,De),s(De,Ql),r(e,ws,i),r(e,U,i),s(U,Dl),s(U,Pe),s(Pe,Pl),s(U,Yl),s(U,ce),s(ce,Fl),s(U,Ll),s(U,Ye),s(Ye,Ol),s(U,Kl),s(U,Fe),s(Fe,ea),s(U,sa),s(U,Le),s(Le,la),s(U,aa),r(e,$s,i),M(ue,e,i),r(e,Es,i),r(e,N,i),s(N,ta),s(N,Oe),s(Oe,ia),s(N,na),r(e,Is,i),M(me,e,i),r(e,Ts,i),r(e,X,i),s(X,oa),s(X,Ke),s(Ke,pa),s(X,ra),r(e,ks,i),M(de,e,i),r(e,zs,i),r(e,B,i),s(B,H),s(H,es),M(he,es,null),s(B,ca),s(B,ss),s(ss,ua),r(e,Zs,i),r(e,Q,i),s(Q,ma),s(Q,ls),s(ls,da),s(Q,ha),r(e,_s,i),r(e,we,i),s(we,fa),r(e,Cs,i),M(fe,e,i),r(e,Gs,i),r(e,Z,i),s(Z,Ma),s(Z,Me),s(Me,ya),s(Z,ja),s(Z,as),s(as,ga),s(Z,Ua),r(e,xs,i),M(ye,e,i),r(e,Bs,i),r(e,D,i),s(D,va),s(D,ts),s(ts,ba),s(D,Ja),r(e,Ws,i),M(je,e,i),r(e,Vs,i),r(e,W,i),s(W,P),s(P,is),M(ge,is,null),s(W,wa),s(W,ns),s(ns,$a),r(e,qs,i),r(e,Y,i),s(Y,Ea),s(Y,os),s(os,Ia),s(Y,Ta),r(e,Rs,i),r(e,$e,i),s($e,ka),r(e,Ss,i),r(e,Ee,i),s(Ee,Ie),r(e,As,i),M(Ue,e,i),Ns=!0},p(e,[i]){const ve={};i&2&&(ve.$$scope={dirty:i,ctx:e}),R.$set(ve)},i(e){Ns||(y(J.$$.fragment,e),y(R.$$.fragment,e),y(se.$$.fragment,e),y(ae.$$.fragment,e),y(ne.$$.fragment,e),y(oe.$$.fragment,e),y(pe.$$.fragment,e),y(re.$$.fragment,e),y(ue.$$.fragment,e),y(me.$$.fragment,e),y(de.$$.fragment,e),y(he.$$.fragment,e),y(fe.$$.fragment,e),y(ye.$$.fragment,e),y(je.$$.fragment,e),y(ge.$$.fragment,e),y(Ue.$$.fragment,e),Ns=!0)},o(e){j(J.$$.fragment,e),j(R.$$.fragment,e),j(se.$$.fragment,e),j(ae.$$.fragment,e),j(ne.$$.fragment,e),j(oe.$$.fragment,e),j(pe.$$.fragment,e),j(re.$$.fragment,e),j(ue.$$.fragment,e),j(me.$$.fragment,e),j(de.$$.fragment,e),j(he.$$.fragment,e),j(fe.$$.fragment,e),j(ye.$$.fragment,e),j(je.$$.fragment,e),j(ge.$$.fragment,e),j(Ue.$$.fragment,e),Ns=!1},d(e){l(d),e&&l(V),e&&l(v),g(J),e&&l(cs),e&&l($),e&&l(us),e&&l(z),e&&l(ms),g(R,e),e&&l(ds),e&&l(G),g(se),e&&l(hs),e&&l(E),e&&l(fs),e&&l(be),e&&l(Ms),g(ae,e),e&&l(ys),e&&l(te),e&&l(js),g(ne,e),e&&l(gs),e&&l(Je),e&&l(Us),g(oe,e),e&&l(vs),e&&l(b),e&&l(bs),g(pe,e),e&&l(Js),e&&l(x),g(re),e&&l(ws),e&&l(U),e&&l($s),g(ue,e),e&&l(Es),e&&l(N),e&&l(Is),g(me,e),e&&l(Ts),e&&l(X),e&&l(ks),g(de,e),e&&l(zs),e&&l(B),g(he),e&&l(Zs),e&&l(Q),e&&l(_s),e&&l(we),e&&l(Cs),g(fe,e),e&&l(Gs),e&&l(Z),e&&l(xs),g(ye,e),e&&l(Bs),e&&l(D),e&&l(Ws),g(je,e),e&&l(Vs),e&&l(W),g(ge),e&&l(qs),e&&l(Y),e&&l(Rs),e&&l($e),e&&l(Ss),e&&l(Ee),e&&l(As),g(Ue,e)}}}const Gt={local:"pipeline-per-linferenza",sections:[{local:"utilizzo-della-pipeline",sections:[{local:"scegliere-modello-e-tokenizer",title:"Scegliere modello e tokenizer"}],title:"Utilizzo della Pipeline"},{local:"audio-pipeline",title:"Audio pipeline"},{local:"vision-pipeline",title:"Vision pipeline"}],title:"Pipeline per l'inferenza"};function xt(rs){return zt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Rt extends $t{constructor(d){super();Et(this,d,xt,Ct,It,{})}}export{Rt as default,Gt as metadata};
