import{s as F,n as Y,o as K}from"../chunks/scheduler.cc52f4b9.js";import{S as D,i as O,e as y,s as n,c as b,h as ee,a as M,d as s,b as i,f as R,g as $,j as G,k as Z,l as te,m as a,n as w,t as j,o as J,p as x}from"../chunks/index.d2856393.js";import{C as se,H as ae,E as ne}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8ffb7edb.js";import{C as X}from"../chunks/CodeBlock.5f8dc025.js";import{C as ie}from"../chunks/CourseFloatingBanner.59eb3fdc.js";function le(S){let l,C,T,U,o,B,r,z,p,I,c,H="Se intendi utilizzare un modello pre-addestrato o una versione affinata in produzione, sii consapevole che i modelli sono degli strumenti potenti, ma hanno dei limiti. Il più grande limite è che, per permettere un pre-addestramento su una quantità importante di dati, i ricercatori spesso includono tutti i contenuti ai quali riescono ad accedere, prendendo nel contempo il meglio e il peggio di ciò che Intenet offre.",v,m,A="Per vederne una rappresentazione rapida, torniamo all’esempio della pipeline <code>fill-mask</code> con il modello BERT:",_,u,V,d,W,f,L='Quando domandiamo al modello di trovare la parola mancante in queste due frasi, questo produce solo una risposta senza genere predeterminato (‘waiter/waitress’). Le altre parole si riferiscono a professioni che sono solitamente associate ad un genere specifico; inoltre, come potete vedere, ‘prostitute’ finisce tra le 5 associazioni più probabili che il modello predice per “woman” e “work”. Ciò succede nonostante BERT sia uno dei rari modelli Transformer che non sono costruiti recuperando dati di ogni sorta da internet, ma utilizzando dati apparentemente neutri (è addestrato sui dataset <a href="https://huggingface.co/datasets/wikipedia" rel="nofollow">English Wikipedia</a> e <a href="https://huggingface.co/datasets/bookcorpus" rel="nofollow">BookCorpus</a>).',q,h,P="Nell’utilizzare questi strumenti, è perciò necessario tenere a mente che il modello d’origine in corso di utilizzazione potrebbe facilmente generare contenuti sessisti, razzisti oppure omofobici. Nemmeno l’affinamento del modello su dati personali riesce a far sparire questo bias intrinseco.",N,g,E,k,Q;return o=new se({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),r=new ae({props:{title:"Bias e limiti",local:"bias-e-limiti",headingTag:"h1"}}),p=new ie({props:{chapter:1,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/chapter1/section8.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/it/chapter1/section8.ipynb"}]}}),u=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBdW5tYXNrZXIlMjAlM0QlMjBwaXBlbGluZSglMjJmaWxsLW1hc2slMjIlMkMlMjBtb2RlbCUzRCUyMmJlcnQtYmFzZS11bmNhc2VkJTIyKSUwQXJlc3VsdCUyMCUzRCUyMHVubWFza2VyKCUyMlRoaXMlMjBtYW4lMjB3b3JrcyUyMGFzJTIwYSUyMCU1Qk1BU0slNUQuJTIyKSUwQXByaW50KCU1QnIlNUIlMjJ0b2tlbl9zdHIlMjIlNUQlMjBmb3IlMjByJTIwaW4lMjByZXN1bHQlNUQpJTBBJTBBcmVzdWx0JTIwJTNEJTIwdW5tYXNrZXIoJTIyVGhpcyUyMHdvbWFuJTIwd29ya3MlMjBhcyUyMGElMjAlNUJNQVNLJTVELiUyMiklMEFwcmludCglNUJyJTVCJTIydG9rZW5fc3RyJTIyJTVEJTIwZm9yJTIwciUyMGluJTIwcmVzdWx0JTVEKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

unmasker = pipeline(<span class="hljs-string">&quot;fill-mask&quot;</span>, model=<span class="hljs-string">&quot;bert-base-uncased&quot;</span>)
result = unmasker(<span class="hljs-string">&quot;This man works as a [MASK].&quot;</span>)
<span class="hljs-built_in">print</span>([r[<span class="hljs-string">&quot;token_str&quot;</span>] <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> result])

result = unmasker(<span class="hljs-string">&quot;This woman works as a [MASK].&quot;</span>)
<span class="hljs-built_in">print</span>([r[<span class="hljs-string">&quot;token_str&quot;</span>] <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> result])`,wrap:!1}}),d=new X({props:{code:"JTVCJ2xhd3llciclMkMlMjAnY2FycGVudGVyJyUyQyUyMCdkb2N0b3InJTJDJTIwJ3dhaXRlciclMkMlMjAnbWVjaGFuaWMnJTVEJTBBJTVCJ251cnNlJyUyQyUyMCd3YWl0cmVzcyclMkMlMjAndGVhY2hlciclMkMlMjAnbWFpZCclMkMlMjAncHJvc3RpdHV0ZSclNUQ=",highlighted:`[<span class="hljs-string">&#x27;lawyer&#x27;</span>, <span class="hljs-string">&#x27;carpenter&#x27;</span>, <span class="hljs-string">&#x27;doctor&#x27;</span>, <span class="hljs-string">&#x27;waiter&#x27;</span>, <span class="hljs-string">&#x27;mechanic&#x27;</span>]
[<span class="hljs-string">&#x27;nurse&#x27;</span>, <span class="hljs-string">&#x27;waitress&#x27;</span>, <span class="hljs-string">&#x27;teacher&#x27;</span>, <span class="hljs-string">&#x27;maid&#x27;</span>, <span class="hljs-string">&#x27;prostitute&#x27;</span>]`,wrap:!1}}),g=new ne({props:{source:"https://github.com/huggingface/course/blob/main/chapters/it/chapter1/8.mdx"}}),{c(){l=y("meta"),C=n(),T=y("p"),U=n(),b(o.$$.fragment),B=n(),b(r.$$.fragment),z=n(),b(p.$$.fragment),I=n(),c=y("p"),c.textContent=H,v=n(),m=y("p"),m.innerHTML=A,_=n(),b(u.$$.fragment),V=n(),b(d.$$.fragment),W=n(),f=y("p"),f.innerHTML=L,q=n(),h=y("p"),h.textContent=P,N=n(),b(g.$$.fragment),E=n(),k=y("p"),this.h()},l(e){const t=ee("svelte-u9bgzb",document.head);l=M(t,"META",{name:!0,content:!0}),t.forEach(s),C=i(e),T=M(e,"P",{}),R(T).forEach(s),U=i(e),$(o.$$.fragment,e),B=i(e),$(r.$$.fragment,e),z=i(e),$(p.$$.fragment,e),I=i(e),c=M(e,"P",{"data-svelte-h":!0}),G(c)!=="svelte-fwj8uu"&&(c.textContent=H),v=i(e),m=M(e,"P",{"data-svelte-h":!0}),G(m)!=="svelte-algpv3"&&(m.innerHTML=A),_=i(e),$(u.$$.fragment,e),V=i(e),$(d.$$.fragment,e),W=i(e),f=M(e,"P",{"data-svelte-h":!0}),G(f)!=="svelte-16mavt8"&&(f.innerHTML=L),q=i(e),h=M(e,"P",{"data-svelte-h":!0}),G(h)!=="svelte-fr28fs"&&(h.textContent=P),N=i(e),$(g.$$.fragment,e),E=i(e),k=M(e,"P",{}),R(k).forEach(s),this.h()},h(){Z(l,"name","hf:doc:metadata"),Z(l,"content",oe)},m(e,t){te(document.head,l),a(e,C,t),a(e,T,t),a(e,U,t),w(o,e,t),a(e,B,t),w(r,e,t),a(e,z,t),w(p,e,t),a(e,I,t),a(e,c,t),a(e,v,t),a(e,m,t),a(e,_,t),w(u,e,t),a(e,V,t),w(d,e,t),a(e,W,t),a(e,f,t),a(e,q,t),a(e,h,t),a(e,N,t),w(g,e,t),a(e,E,t),a(e,k,t),Q=!0},p:Y,i(e){Q||(j(o.$$.fragment,e),j(r.$$.fragment,e),j(p.$$.fragment,e),j(u.$$.fragment,e),j(d.$$.fragment,e),j(g.$$.fragment,e),Q=!0)},o(e){J(o.$$.fragment,e),J(r.$$.fragment,e),J(p.$$.fragment,e),J(u.$$.fragment,e),J(d.$$.fragment,e),J(g.$$.fragment,e),Q=!1},d(e){e&&(s(C),s(T),s(U),s(B),s(z),s(I),s(c),s(v),s(m),s(_),s(V),s(W),s(f),s(q),s(h),s(N),s(E),s(k)),s(l),x(o,e),x(r,e),x(p,e),x(u,e),x(d,e),x(g,e)}}}const oe='{"title":"Bias e limiti","local":"bias-e-limiti","sections":[],"depth":1}';function re(S){return K(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class fe extends D{constructor(l){super(),O(this,l,re,le,F,{})}}export{fe as component};
