import{S as de,i as we,s as ge,e as o,k as f,w as L,t as i,M as ke,c as r,d as t,m as d,a as l,x as G,h as p,b as u,G as a,g as n,y as O,L as be,q as z,o as D,B as H,v as ye}from"../../chunks/vendor-hf-doc-builder.js";import{I as ve}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as fe}from"../../chunks/CodeBlock-hf-doc-builder.js";import{C as _e}from"../../chunks/CourseFloatingBanner-hf-doc-builder.js";function $e(oe){let c,A,m,w,T,k,J,q,U,S,b,C,x,Q,P,g,V,B,X,Y,M,y,W,v,R,h,Z,_,ee,te,$,se,ae,I,j,ne,K;return k=new ve({}),b=new _e({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/en/chapter1/section8.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter1/section8.ipynb"}]}}),y=new fe({props:{code:`from transformers import pipeline

unmasker = pipeline("fill-mask", model="bert-base-uncased")
result = unmasker("This man works as a [MASK].")
print([r["token_str"] for r in result])

result = unmasker("This woman works as a [MASK].")
print([r["token_str"] for r in result])`,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])`}}),v=new fe({props:{code:`['lawyer', 'carpenter', 'doctor', 'waiter', 'mechanic']
['nurse', 'waitress', 'teacher', 'maid', 'prostitute']`,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>]`}}),{c(){c=o("meta"),A=f(),m=o("h1"),w=o("a"),T=o("span"),L(k.$$.fragment),J=f(),q=o("span"),U=i("Bias and limitations"),S=f(),L(b.$$.fragment),C=f(),x=o("p"),Q=i("If your intent is to use a pretrained model or a fine-tuned version in production, please be aware that, while these models are powerful tools, they come with limitations. The biggest of these is that, to enable pretraining on large amounts of data, researchers often scrape all the content they can find, taking the best as well as the worst of what is available on the internet."),P=f(),g=o("p"),V=i("To give a quick illustration, let\u2019s go back the example of a "),B=o("code"),X=i("fill-mask"),Y=i(" pipeline with the BERT model:"),M=f(),L(y.$$.fragment),W=f(),L(v.$$.fragment),R=f(),h=o("p"),Z=i("When asked to fill in the missing word in these two sentences, the model gives only one gender-free answer (waiter/waitress). The others are work occupations usually associated with one specific gender \u2014 and yes, prostitute ended up in the top 5 possibilities the model associates with \u201Cwoman\u201D and \u201Cwork.\u201D This happens even though BERT is one of the rare Transformer models not built by scraping data from all over the internet, but rather using apparently neutral data (it\u2019s trained on the "),_=o("a"),ee=i("English Wikipedia"),te=i(" and "),$=o("a"),se=i("BookCorpus"),ae=i(" datasets)."),I=f(),j=o("p"),ne=i("When you use these tools, you therefore need to keep in the back of your mind that the original model you are using could very easily generate sexist, racist, or homophobic content. Fine-tuning the model on your data won\u2019t make this intrinsic bias disappear."),this.h()},l(e){const s=ke('[data-svelte="svelte-1phssyn"]',document.head);c=r(s,"META",{name:!0,content:!0}),s.forEach(t),A=d(e),m=r(e,"H1",{class:!0});var N=l(m);w=r(N,"A",{id:!0,class:!0,href:!0});var re=l(w);T=r(re,"SPAN",{});var ie=l(T);G(k.$$.fragment,ie),ie.forEach(t),re.forEach(t),J=d(N),q=r(N,"SPAN",{});var le=l(q);U=p(le,"Bias and limitations"),le.forEach(t),N.forEach(t),S=d(e),G(b.$$.fragment,e),C=d(e),x=r(e,"P",{});var pe=l(x);Q=p(pe,"If your intent is to use a pretrained model or a fine-tuned version in production, please be aware that, while these models are powerful tools, they come with limitations. The biggest of these is that, to enable pretraining on large amounts of data, researchers often scrape all the content they can find, taking the best as well as the worst of what is available on the internet."),pe.forEach(t),P=d(e),g=r(e,"P",{});var F=l(g);V=p(F,"To give a quick illustration, let\u2019s go back the example of a "),B=r(F,"CODE",{});var he=l(B);X=p(he,"fill-mask"),he.forEach(t),Y=p(F," pipeline with the BERT model:"),F.forEach(t),M=d(e),G(y.$$.fragment,e),W=d(e),G(v.$$.fragment,e),R=d(e),h=r(e,"P",{});var E=l(h);Z=p(E,"When asked to fill in the missing word in these two sentences, the model gives only one gender-free answer (waiter/waitress). The others are work occupations usually associated with one specific gender \u2014 and yes, prostitute ended up in the top 5 possibilities the model associates with \u201Cwoman\u201D and \u201Cwork.\u201D This happens even though BERT is one of the rare Transformer models not built by scraping data from all over the internet, but rather using apparently neutral data (it\u2019s trained on the "),_=r(E,"A",{href:!0,rel:!0});var ue=l(_);ee=p(ue,"English Wikipedia"),ue.forEach(t),te=p(E," and "),$=r(E,"A",{href:!0,rel:!0});var ce=l($);se=p(ce,"BookCorpus"),ce.forEach(t),ae=p(E," datasets)."),E.forEach(t),I=d(e),j=r(e,"P",{});var me=l(j);ne=p(me,"When you use these tools, you therefore need to keep in the back of your mind that the original model you are using could very easily generate sexist, racist, or homophobic content. Fine-tuning the model on your data won\u2019t make this intrinsic bias disappear."),me.forEach(t),this.h()},h(){u(c,"name","hf:doc:metadata"),u(c,"content",JSON.stringify(xe)),u(w,"id","bias-and-limitations"),u(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"),u(w,"href","#bias-and-limitations"),u(m,"class","relative group"),u(_,"href","https://huggingface.co/datasets/wikipedia"),u(_,"rel","nofollow"),u($,"href","https://huggingface.co/datasets/bookcorpus"),u($,"rel","nofollow")},m(e,s){a(document.head,c),n(e,A,s),n(e,m,s),a(m,w),a(w,T),O(k,T,null),a(m,J),a(m,q),a(q,U),n(e,S,s),O(b,e,s),n(e,C,s),n(e,x,s),a(x,Q),n(e,P,s),n(e,g,s),a(g,V),a(g,B),a(B,X),a(g,Y),n(e,M,s),O(y,e,s),n(e,W,s),O(v,e,s),n(e,R,s),n(e,h,s),a(h,Z),a(h,_),a(_,ee),a(h,te),a(h,$),a($,se),a(h,ae),n(e,I,s),n(e,j,s),a(j,ne),K=!0},p:be,i(e){K||(z(k.$$.fragment,e),z(b.$$.fragment,e),z(y.$$.fragment,e),z(v.$$.fragment,e),K=!0)},o(e){D(k.$$.fragment,e),D(b.$$.fragment,e),D(y.$$.fragment,e),D(v.$$.fragment,e),K=!1},d(e){t(c),e&&t(A),e&&t(m),H(k),e&&t(S),H(b,e),e&&t(C),e&&t(x),e&&t(P),e&&t(g),e&&t(M),H(y,e),e&&t(W),H(v,e),e&&t(R),e&&t(h),e&&t(I),e&&t(j)}}}const xe={local:"bias-and-limitations",title:"Bias and limitations"};function je(oe){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ae extends de{constructor(c){super();we(this,c,je,$e,ge,{})}}export{Ae as default,xe as metadata};
