import{S as wl,i as bl,s as ql,e as n,k as c,w as h,t,M as yl,c as o,d as a,m as f,a as r,x as m,h as l,b as u,N as Pl,G as s,g as p,y as g,q as v,o as $,B as j,v as Al}from"../chunks/vendor-hf-doc-builder.js";import{T as Sl}from"../chunks/Tip-hf-doc-builder.js";import{I as rs}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as y}from"../chunks/CodeBlock-hf-doc-builder.js";function Dl(ps){let d,T,k,z,C;return{c(){d=n("p"),T=t("Dai un\u2019occhiata alla documentazione di "),k=n("code"),z=t("pipeline()"),C=t(" per una lista completa dei compiti supportati.")},l(x){d=o(x,"P",{});var P=r(d);T=l(P,"Dai un\u2019occhiata alla documentazione di "),k=o(P,"CODE",{});var N=r(k);z=l(N,"pipeline()"),N.forEach(a),C=l(P," per una lista completa dei compiti supportati."),P.forEach(a)},m(x,P){p(x,d,P),s(d,T),s(d,k),s(k,z),s(d,C)},d(x){x&&a(d)}}}function Cl(ps){let d,T,k,z,C,x,P,N,ta,cs,w,la,Ae,ia,na,Y,oa,ra,Se,pa,ca,fs,A,Z,fa,De,ua,da,ha,Ce,ma,ga,ee,va,Le,$a,ja,us,H,ds,L,U,Me,se,_a,Oe,ka,hs,b,Ea,Ie,xa,za,Te,wa,ba,Ne,qa,ya,ms,Ee,ae,Pa,He,Aa,Sa,gs,te,vs,le,ie,Da,Ue,Ca,La,$s,ne,js,xe,Ma,_s,oe,ks,E,Oa,Re,Ia,Ta,Fe,Na,Ha,Ke,Ua,Ra,Qe,Fa,Ka,Es,re,xs,M,R,Ve,pe,Qa,Be,Va,zs,_,Ba,Ge,Ga,Ja,ce,Wa,Xa,Je,Ya,Za,We,et,st,Xe,at,tt,ws,fe,bs,F,lt,Ye,it,nt,qs,ue,ys,K,ot,Ze,rt,pt,Ps,de,As,O,Q,es,he,ct,ss,ft,Ss,V,ut,as,dt,ht,Ds,ze,mt,Cs,me,Ls,S,gt,ge,vt,$t,ts,jt,_t,Ms,ve,Os,B,kt,ls,Et,xt,Is,$e,Ts,I,G,is,je,zt,ns,wt,Ns,J,bt,os,qt,yt,Hs,we,Pt,Us,be,qe,At,Rs,_e,Fs;return x=new rs({}),H=new Sl({props:{$$slots:{default:[Dl]},$$scope:{ctx:ps}}}),se=new rs({}),te=new y({props:{code:`from transformers import pipeline

generator = pipeline(task="text-generation")`,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 y({props:{code:`generator(
    "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone"
)  # doctest: +SKIP`,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 y({props:{code:`generator(
    [
        "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone",
        "Nine for Mortal Men, doomed to die, One for the Dark Lord on his dark throne",
    ]
)  # doctest: +SKIP`,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>`}}),re=new y({props:{code:`generator(
    "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone",
    num_return_sequences=2,
)  # doctest: +SKIP`,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>`}}),pe=new rs({}),fe=new y({props:{code:`from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("distilgpt2")
model = AutoModelForCausalLM.from_pretrained("distilgpt2")`,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>)`}}),ue=new y({props:{code:`from transformers import pipeline

generator = pipeline(task="text-generation", model=model, tokenizer=tokenizer)`,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 y({props:{code:`generator(
    "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone"
)  # doctest: +SKIP`,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 rs({}),me=new y({props:{code:`from datasets import load_dataset
import torch

torch.manual_seed(42)
ds = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
audio_file = ds[0]["audio"]["path"]`,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>]`}}),ve=new y({props:{code:`from transformers import pipeline

audio_classifier = pipeline(
    task="audio-classification", model="ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
)`,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>)`}}),$e=new y({props:{code:`preds = audio_classifier(audio_file)
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
preds`,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>}]`}}),je=new rs({}),_e=new y({props:{code:`from transformers import pipeline

vision_classifier = pipeline(task="image-classification")
preds = vision_classifier(
    images="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
)
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
preds`,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"),T=c(),k=n("h1"),z=n("a"),C=n("span"),h(x.$$.fragment),P=c(),N=n("span"),ta=t("Pipeline per l'inferenza"),cs=c(),w=n("p"),la=t("La "),Ae=n("code"),ia=t("pipeline()"),na=t(" rende semplice usare qualsiasi modello dal "),Y=n("a"),oa=t("Model Hub"),ra=t(" 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 "),Se=n("code"),pa=t("pipeline()"),ca=t("! Questa esercitazione ti insegner\xE0 a:"),fs=c(),A=n("ul"),Z=n("li"),fa=t("Usare una "),De=n("code"),ua=t("pipeline()"),da=t(" per fare inferenza."),ha=c(),Ce=n("li"),ma=t("Usare uno specifico tokenizer o modello."),ga=c(),ee=n("li"),va=t("Usare una "),Le=n("code"),$a=t("pipeline()"),ja=t(" per compiti che riguardano audio e video."),us=c(),h(H.$$.fragment),ds=c(),L=n("h2"),U=n("a"),Me=n("span"),h(se.$$.fragment),_a=c(),Oe=n("span"),ka=t("Utilizzo della Pipeline"),hs=c(),b=n("p"),Ea=t("Nonostante ogni compito abbia una "),Ie=n("code"),xa=t("pipeline()"),za=t(" associata, \xE8 pi\xF9 semplice utilizzare l\u2019astrazione generica della "),Te=n("code"),wa=t("pipeline()"),ba=t(" che contiene tutte quelle specifiche per ogni mansione. La "),Ne=n("code"),qa=t("pipeline()"),ya=t(" carica automaticamente un modello predefinito e un tokenizer in grado di fare inferenza per il tuo compito."),ms=c(),Ee=n("ol"),ae=n("li"),Pa=t("Inizia creando una "),He=n("code"),Aa=t("pipeline()"),Sa=t(" e specificando il compito su cui fare inferenza:"),gs=c(),h(te.$$.fragment),vs=c(),le=n("ol"),ie=n("li"),Da=t("Inserisci il testo in input nella "),Ue=n("code"),Ca=t("pipeline()"),La=t(":"),$s=c(),h(ne.$$.fragment),js=c(),xe=n("p"),Ma=t("Se hai pi\xF9 di un input, inseriscilo in una lista:"),_s=c(),h(oe.$$.fragment),ks=c(),E=n("p"),Oa=t("Qualsiasi parametro addizionale per il tuo compito pu\xF2 essere incluso nella "),Re=n("code"),Ia=t("pipeline()"),Ta=t(". La mansione "),Fe=n("code"),Na=t("text-generation"),Ha=t(" ha un metodo "),Ke=n("code"),Ua=t("generate()"),Ra=t(" con diversi parametri per controllare l\u2019output. Ad esempio, se desideri generare pi\xF9 di un output, utilizza il parametro "),Qe=n("code"),Fa=t("num_return_sequences"),Ka=t(":"),Es=c(),h(re.$$.fragment),xs=c(),M=n("h3"),R=n("a"),Ve=n("span"),h(pe.$$.fragment),Qa=c(),Be=n("span"),Va=t("Scegliere modello e tokenizer"),zs=c(),_=n("p"),Ba=t("La "),Ge=n("code"),Ga=t("pipeline()"),Ja=t(" accetta qualsiasi modello dal "),ce=n("a"),Wa=t("Model Hub"),Xa=t(". 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 "),Je=n("code"),Ya=t("AutoModelFor"),Za=t(" e "),We=n("code"),et=t("AutoTokenizer"),st=t(". Ad esempio, carica la classe "),Xe=n("code"),at=t("AutoModelForCausalLM"),tt=t(" per un compito di causal language modeling:"),ws=c(),h(fe.$$.fragment),bs=c(),F=n("p"),lt=t("Crea una "),Ye=n("code"),it=t("pipeline()"),nt=t(" per il tuo compito, specificando il modello e il tokenizer che hai caricato:"),qs=c(),h(ue.$$.fragment),ys=c(),K=n("p"),ot=t("Inserisci il testo di input nella "),Ze=n("code"),rt=t("pipeline()"),pt=t(" per generare del testo:"),Ps=c(),h(de.$$.fragment),As=c(),O=n("h2"),Q=n("a"),es=n("span"),h(he.$$.fragment),ct=c(),ss=n("span"),ft=t("Audio pipeline"),Ss=c(),V=n("p"),ut=t("La flessibilit\xE0 della "),as=n("code"),dt=t("pipeline()"),ht=t(" fa si che possa essere estesa ad attivit\xE0 sugli audio."),Ds=c(),ze=n("p"),mt=t("Per esempio, classifichiamo le emozioni in questo clip audio:"),Cs=c(),h(me.$$.fragment),Ls=c(),S=n("p"),gt=t("Trova un modello per la "),ge=n("a"),vt=t("classificazione audio"),$t=t(" sul Model Hub per eseguire un compito di riconoscimento automatico delle emozioni e caricalo nella "),ts=n("code"),jt=t("pipeline()"),_t=t(":"),Ms=c(),h(ve.$$.fragment),Os=c(),B=n("p"),kt=t("Inserisci il file audio nella "),ls=n("code"),Et=t("pipeline()"),xt=t(":"),Is=c(),h($e.$$.fragment),Ts=c(),I=n("h2"),G=n("a"),is=n("span"),h(je.$$.fragment),zt=c(),ns=n("span"),wt=t("Vision pipeline"),Ns=c(),J=n("p"),bt=t("Infine, usare la "),os=n("code"),qt=t("pipeline()"),yt=t(" per le attivit\xE0 sulle immagini \xE8 praticamente la stessa cosa."),Hs=c(),we=n("p"),Pt=t("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?"),Us=c(),be=n("p"),qe=n("img"),Rs=c(),h(_e.$$.fragment),this.h()},l(e){const i=yl('[data-svelte="svelte-1phssyn"]',document.head);d=o(i,"META",{name:!0,content:!0}),i.forEach(a),T=f(e),k=o(e,"H1",{class:!0});var ke=r(k);z=o(ke,"A",{id:!0,class:!0,href:!0});var St=r(z);C=o(St,"SPAN",{});var Dt=r(C);m(x.$$.fragment,Dt),Dt.forEach(a),St.forEach(a),P=f(ke),N=o(ke,"SPAN",{});var Ct=r(N);ta=l(Ct,"Pipeline per l'inferenza"),Ct.forEach(a),ke.forEach(a),cs=f(e),w=o(e,"P",{});var W=r(w);la=l(W,"La "),Ae=o(W,"CODE",{});var Lt=r(Ae);ia=l(Lt,"pipeline()"),Lt.forEach(a),na=l(W," rende semplice usare qualsiasi modello dal "),Y=o(W,"A",{href:!0,rel:!0});var Mt=r(Y);oa=l(Mt,"Model Hub"),Mt.forEach(a),ra=l(W," 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 "),Se=o(W,"CODE",{});var Ot=r(Se);pa=l(Ot,"pipeline()"),Ot.forEach(a),ca=l(W,"! Questa esercitazione ti insegner\xE0 a:"),W.forEach(a),fs=f(e),A=o(e,"UL",{});var ye=r(A);Z=o(ye,"LI",{});var Ks=r(Z);fa=l(Ks,"Usare una "),De=o(Ks,"CODE",{});var It=r(De);ua=l(It,"pipeline()"),It.forEach(a),da=l(Ks," per fare inferenza."),Ks.forEach(a),ha=f(ye),Ce=o(ye,"LI",{});var Tt=r(Ce);ma=l(Tt,"Usare uno specifico tokenizer o modello."),Tt.forEach(a),ga=f(ye),ee=o(ye,"LI",{});var Qs=r(ee);va=l(Qs,"Usare una "),Le=o(Qs,"CODE",{});var Nt=r(Le);$a=l(Nt,"pipeline()"),Nt.forEach(a),ja=l(Qs," per compiti che riguardano audio e video."),Qs.forEach(a),ye.forEach(a),us=f(e),m(H.$$.fragment,e),ds=f(e),L=o(e,"H2",{class:!0});var Vs=r(L);U=o(Vs,"A",{id:!0,class:!0,href:!0});var Ht=r(U);Me=o(Ht,"SPAN",{});var Ut=r(Me);m(se.$$.fragment,Ut),Ut.forEach(a),Ht.forEach(a),_a=f(Vs),Oe=o(Vs,"SPAN",{});var Rt=r(Oe);ka=l(Rt,"Utilizzo della Pipeline"),Rt.forEach(a),Vs.forEach(a),hs=f(e),b=o(e,"P",{});var X=r(b);Ea=l(X,"Nonostante ogni compito abbia una "),Ie=o(X,"CODE",{});var Ft=r(Ie);xa=l(Ft,"pipeline()"),Ft.forEach(a),za=l(X," associata, \xE8 pi\xF9 semplice utilizzare l\u2019astrazione generica della "),Te=o(X,"CODE",{});var Kt=r(Te);wa=l(Kt,"pipeline()"),Kt.forEach(a),ba=l(X," che contiene tutte quelle specifiche per ogni mansione. La "),Ne=o(X,"CODE",{});var Qt=r(Ne);qa=l(Qt,"pipeline()"),Qt.forEach(a),ya=l(X," carica automaticamente un modello predefinito e un tokenizer in grado di fare inferenza per il tuo compito."),X.forEach(a),ms=f(e),Ee=o(e,"OL",{});var Vt=r(Ee);ae=o(Vt,"LI",{});var Bs=r(ae);Pa=l(Bs,"Inizia creando una "),He=o(Bs,"CODE",{});var Bt=r(He);Aa=l(Bt,"pipeline()"),Bt.forEach(a),Sa=l(Bs," e specificando il compito su cui fare inferenza:"),Bs.forEach(a),Vt.forEach(a),gs=f(e),m(te.$$.fragment,e),vs=f(e),le=o(e,"OL",{start:!0});var Gt=r(le);ie=o(Gt,"LI",{});var Gs=r(ie);Da=l(Gs,"Inserisci il testo in input nella "),Ue=o(Gs,"CODE",{});var Jt=r(Ue);Ca=l(Jt,"pipeline()"),Jt.forEach(a),La=l(Gs,":"),Gs.forEach(a),Gt.forEach(a),$s=f(e),m(ne.$$.fragment,e),js=f(e),xe=o(e,"P",{});var Wt=r(xe);Ma=l(Wt,"Se hai pi\xF9 di un input, inseriscilo in una lista:"),Wt.forEach(a),_s=f(e),m(oe.$$.fragment,e),ks=f(e),E=o(e,"P",{});var D=r(E);Oa=l(D,"Qualsiasi parametro addizionale per il tuo compito pu\xF2 essere incluso nella "),Re=o(D,"CODE",{});var Xt=r(Re);Ia=l(Xt,"pipeline()"),Xt.forEach(a),Ta=l(D,". La mansione "),Fe=o(D,"CODE",{});var Yt=r(Fe);Na=l(Yt,"text-generation"),Yt.forEach(a),Ha=l(D," ha un metodo "),Ke=o(D,"CODE",{});var Zt=r(Ke);Ua=l(Zt,"generate()"),Zt.forEach(a),Ra=l(D," con diversi parametri per controllare l\u2019output. Ad esempio, se desideri generare pi\xF9 di un output, utilizza il parametro "),Qe=o(D,"CODE",{});var el=r(Qe);Fa=l(el,"num_return_sequences"),el.forEach(a),Ka=l(D,":"),D.forEach(a),Es=f(e),m(re.$$.fragment,e),xs=f(e),M=o(e,"H3",{class:!0});var Js=r(M);R=o(Js,"A",{id:!0,class:!0,href:!0});var sl=r(R);Ve=o(sl,"SPAN",{});var al=r(Ve);m(pe.$$.fragment,al),al.forEach(a),sl.forEach(a),Qa=f(Js),Be=o(Js,"SPAN",{});var tl=r(Be);Va=l(tl,"Scegliere modello e tokenizer"),tl.forEach(a),Js.forEach(a),zs=f(e),_=o(e,"P",{});var q=r(_);Ba=l(q,"La "),Ge=o(q,"CODE",{});var ll=r(Ge);Ga=l(ll,"pipeline()"),ll.forEach(a),Ja=l(q," accetta qualsiasi modello dal "),ce=o(q,"A",{href:!0,rel:!0});var il=r(ce);Wa=l(il,"Model Hub"),il.forEach(a),Xa=l(q,". 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 "),Je=o(q,"CODE",{});var nl=r(Je);Ya=l(nl,"AutoModelFor"),nl.forEach(a),Za=l(q," e "),We=o(q,"CODE",{});var ol=r(We);et=l(ol,"AutoTokenizer"),ol.forEach(a),st=l(q,". Ad esempio, carica la classe "),Xe=o(q,"CODE",{});var rl=r(Xe);at=l(rl,"AutoModelForCausalLM"),rl.forEach(a),tt=l(q," per un compito di causal language modeling:"),q.forEach(a),ws=f(e),m(fe.$$.fragment,e),bs=f(e),F=o(e,"P",{});var Ws=r(F);lt=l(Ws,"Crea una "),Ye=o(Ws,"CODE",{});var pl=r(Ye);it=l(pl,"pipeline()"),pl.forEach(a),nt=l(Ws," per il tuo compito, specificando il modello e il tokenizer che hai caricato:"),Ws.forEach(a),qs=f(e),m(ue.$$.fragment,e),ys=f(e),K=o(e,"P",{});var Xs=r(K);ot=l(Xs,"Inserisci il testo di input nella "),Ze=o(Xs,"CODE",{});var cl=r(Ze);rt=l(cl,"pipeline()"),cl.forEach(a),pt=l(Xs," per generare del testo:"),Xs.forEach(a),Ps=f(e),m(de.$$.fragment,e),As=f(e),O=o(e,"H2",{class:!0});var Ys=r(O);Q=o(Ys,"A",{id:!0,class:!0,href:!0});var fl=r(Q);es=o(fl,"SPAN",{});var ul=r(es);m(he.$$.fragment,ul),ul.forEach(a),fl.forEach(a),ct=f(Ys),ss=o(Ys,"SPAN",{});var dl=r(ss);ft=l(dl,"Audio pipeline"),dl.forEach(a),Ys.forEach(a),Ss=f(e),V=o(e,"P",{});var Zs=r(V);ut=l(Zs,"La flessibilit\xE0 della "),as=o(Zs,"CODE",{});var hl=r(as);dt=l(hl,"pipeline()"),hl.forEach(a),ht=l(Zs," fa si che possa essere estesa ad attivit\xE0 sugli audio."),Zs.forEach(a),Ds=f(e),ze=o(e,"P",{});var ml=r(ze);mt=l(ml,"Per esempio, classifichiamo le emozioni in questo clip audio:"),ml.forEach(a),Cs=f(e),m(me.$$.fragment,e),Ls=f(e),S=o(e,"P",{});var Pe=r(S);gt=l(Pe,"Trova un modello per la "),ge=o(Pe,"A",{href:!0,rel:!0});var gl=r(ge);vt=l(gl,"classificazione audio"),gl.forEach(a),$t=l(Pe," sul Model Hub per eseguire un compito di riconoscimento automatico delle emozioni e caricalo nella "),ts=o(Pe,"CODE",{});var vl=r(ts);jt=l(vl,"pipeline()"),vl.forEach(a),_t=l(Pe,":"),Pe.forEach(a),Ms=f(e),m(ve.$$.fragment,e),Os=f(e),B=o(e,"P",{});var ea=r(B);kt=l(ea,"Inserisci il file audio nella "),ls=o(ea,"CODE",{});var $l=r(ls);Et=l($l,"pipeline()"),$l.forEach(a),xt=l(ea,":"),ea.forEach(a),Is=f(e),m($e.$$.fragment,e),Ts=f(e),I=o(e,"H2",{class:!0});var sa=r(I);G=o(sa,"A",{id:!0,class:!0,href:!0});var jl=r(G);is=o(jl,"SPAN",{});var _l=r(is);m(je.$$.fragment,_l),_l.forEach(a),jl.forEach(a),zt=f(sa),ns=o(sa,"SPAN",{});var kl=r(ns);wt=l(kl,"Vision pipeline"),kl.forEach(a),sa.forEach(a),Ns=f(e),J=o(e,"P",{});var aa=r(J);bt=l(aa,"Infine, usare la "),os=o(aa,"CODE",{});var El=r(os);qt=l(El,"pipeline()"),El.forEach(a),yt=l(aa," per le attivit\xE0 sulle immagini \xE8 praticamente la stessa cosa."),aa.forEach(a),Hs=f(e),we=o(e,"P",{});var xl=r(we);Pt=l(xl,"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?"),xl.forEach(a),Us=f(e),be=o(e,"P",{});var zl=r(be);qe=o(zl,"IMG",{src:!0,alt:!0}),zl.forEach(a),Rs=f(e),m(_e.$$.fragment,e),this.h()},h(){u(d,"name","hf:doc:metadata"),u(d,"content",JSON.stringify(Ll)),u(z,"id","pipeline-per-linferenza"),u(z,"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"),u(z,"href","#pipeline-per-linferenza"),u(k,"class","relative group"),u(Y,"href","https://huggingface.co/models"),u(Y,"rel","nofollow"),u(U,"id","utilizzo-della-pipeline"),u(U,"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"),u(U,"href","#utilizzo-della-pipeline"),u(L,"class","relative group"),u(le,"start","2"),u(R,"id","scegliere-modello-e-tokenizer"),u(R,"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"),u(R,"href","#scegliere-modello-e-tokenizer"),u(M,"class","relative group"),u(ce,"href","https://huggingface.co/models"),u(ce,"rel","nofollow"),u(Q,"id","audio-pipeline"),u(Q,"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"),u(Q,"href","#audio-pipeline"),u(O,"class","relative group"),u(ge,"href","https://huggingface.co/models?pipeline_tag=audio-classification"),u(ge,"rel","nofollow"),u(G,"id","vision-pipeline"),u(G,"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"),u(G,"href","#vision-pipeline"),u(I,"class","relative group"),Pl(qe.src,At="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")||u(qe,"src",At),u(qe,"alt","pipeline-cat-chonk")},m(e,i){s(document.head,d),p(e,T,i),p(e,k,i),s(k,z),s(z,C),g(x,C,null),s(k,P),s(k,N),s(N,ta),p(e,cs,i),p(e,w,i),s(w,la),s(w,Ae),s(Ae,ia),s(w,na),s(w,Y),s(Y,oa),s(w,ra),s(w,Se),s(Se,pa),s(w,ca),p(e,fs,i),p(e,A,i),s(A,Z),s(Z,fa),s(Z,De),s(De,ua),s(Z,da),s(A,ha),s(A,Ce),s(Ce,ma),s(A,ga),s(A,ee),s(ee,va),s(ee,Le),s(Le,$a),s(ee,ja),p(e,us,i),g(H,e,i),p(e,ds,i),p(e,L,i),s(L,U),s(U,Me),g(se,Me,null),s(L,_a),s(L,Oe),s(Oe,ka),p(e,hs,i),p(e,b,i),s(b,Ea),s(b,Ie),s(Ie,xa),s(b,za),s(b,Te),s(Te,wa),s(b,ba),s(b,Ne),s(Ne,qa),s(b,ya),p(e,ms,i),p(e,Ee,i),s(Ee,ae),s(ae,Pa),s(ae,He),s(He,Aa),s(ae,Sa),p(e,gs,i),g(te,e,i),p(e,vs,i),p(e,le,i),s(le,ie),s(ie,Da),s(ie,Ue),s(Ue,Ca),s(ie,La),p(e,$s,i),g(ne,e,i),p(e,js,i),p(e,xe,i),s(xe,Ma),p(e,_s,i),g(oe,e,i),p(e,ks,i),p(e,E,i),s(E,Oa),s(E,Re),s(Re,Ia),s(E,Ta),s(E,Fe),s(Fe,Na),s(E,Ha),s(E,Ke),s(Ke,Ua),s(E,Ra),s(E,Qe),s(Qe,Fa),s(E,Ka),p(e,Es,i),g(re,e,i),p(e,xs,i),p(e,M,i),s(M,R),s(R,Ve),g(pe,Ve,null),s(M,Qa),s(M,Be),s(Be,Va),p(e,zs,i),p(e,_,i),s(_,Ba),s(_,Ge),s(Ge,Ga),s(_,Ja),s(_,ce),s(ce,Wa),s(_,Xa),s(_,Je),s(Je,Ya),s(_,Za),s(_,We),s(We,et),s(_,st),s(_,Xe),s(Xe,at),s(_,tt),p(e,ws,i),g(fe,e,i),p(e,bs,i),p(e,F,i),s(F,lt),s(F,Ye),s(Ye,it),s(F,nt),p(e,qs,i),g(ue,e,i),p(e,ys,i),p(e,K,i),s(K,ot),s(K,Ze),s(Ze,rt),s(K,pt),p(e,Ps,i),g(de,e,i),p(e,As,i),p(e,O,i),s(O,Q),s(Q,es),g(he,es,null),s(O,ct),s(O,ss),s(ss,ft),p(e,Ss,i),p(e,V,i),s(V,ut),s(V,as),s(as,dt),s(V,ht),p(e,Ds,i),p(e,ze,i),s(ze,mt),p(e,Cs,i),g(me,e,i),p(e,Ls,i),p(e,S,i),s(S,gt),s(S,ge),s(ge,vt),s(S,$t),s(S,ts),s(ts,jt),s(S,_t),p(e,Ms,i),g(ve,e,i),p(e,Os,i),p(e,B,i),s(B,kt),s(B,ls),s(ls,Et),s(B,xt),p(e,Is,i),g($e,e,i),p(e,Ts,i),p(e,I,i),s(I,G),s(G,is),g(je,is,null),s(I,zt),s(I,ns),s(ns,wt),p(e,Ns,i),p(e,J,i),s(J,bt),s(J,os),s(os,qt),s(J,yt),p(e,Hs,i),p(e,we,i),s(we,Pt),p(e,Us,i),p(e,be,i),s(be,qe),p(e,Rs,i),g(_e,e,i),Fs=!0},p(e,[i]){const ke={};i&2&&(ke.$$scope={dirty:i,ctx:e}),H.$set(ke)},i(e){Fs||(v(x.$$.fragment,e),v(H.$$.fragment,e),v(se.$$.fragment,e),v(te.$$.fragment,e),v(ne.$$.fragment,e),v(oe.$$.fragment,e),v(re.$$.fragment,e),v(pe.$$.fragment,e),v(fe.$$.fragment,e),v(ue.$$.fragment,e),v(de.$$.fragment,e),v(he.$$.fragment,e),v(me.$$.fragment,e),v(ve.$$.fragment,e),v($e.$$.fragment,e),v(je.$$.fragment,e),v(_e.$$.fragment,e),Fs=!0)},o(e){$(x.$$.fragment,e),$(H.$$.fragment,e),$(se.$$.fragment,e),$(te.$$.fragment,e),$(ne.$$.fragment,e),$(oe.$$.fragment,e),$(re.$$.fragment,e),$(pe.$$.fragment,e),$(fe.$$.fragment,e),$(ue.$$.fragment,e),$(de.$$.fragment,e),$(he.$$.fragment,e),$(me.$$.fragment,e),$(ve.$$.fragment,e),$($e.$$.fragment,e),$(je.$$.fragment,e),$(_e.$$.fragment,e),Fs=!1},d(e){a(d),e&&a(T),e&&a(k),j(x),e&&a(cs),e&&a(w),e&&a(fs),e&&a(A),e&&a(us),j(H,e),e&&a(ds),e&&a(L),j(se),e&&a(hs),e&&a(b),e&&a(ms),e&&a(Ee),e&&a(gs),j(te,e),e&&a(vs),e&&a(le),e&&a($s),j(ne,e),e&&a(js),e&&a(xe),e&&a(_s),j(oe,e),e&&a(ks),e&&a(E),e&&a(Es),j(re,e),e&&a(xs),e&&a(M),j(pe),e&&a(zs),e&&a(_),e&&a(ws),j(fe,e),e&&a(bs),e&&a(F),e&&a(qs),j(ue,e),e&&a(ys),e&&a(K),e&&a(Ps),j(de,e),e&&a(As),e&&a(O),j(he),e&&a(Ss),e&&a(V),e&&a(Ds),e&&a(ze),e&&a(Cs),j(me,e),e&&a(Ls),e&&a(S),e&&a(Ms),j(ve,e),e&&a(Os),e&&a(B),e&&a(Is),j($e,e),e&&a(Ts),e&&a(I),j(je),e&&a(Ns),e&&a(J),e&&a(Hs),e&&a(we),e&&a(Us),e&&a(be),e&&a(Rs),j(_e,e)}}}const Ll={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 Ml(ps){return Al(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Hl extends wl{constructor(d){super();bl(this,d,Ml,Cl,ql,{})}}export{Hl as default,Ll as metadata};
