import{s as X,n as F,o as Y}from"../chunks/scheduler.37c15a92.js";import{S as K,i as L,g as M,s as l,r as j,A as D,h as g,f as e,c as n,j as R,u as w,x as G,k as Z,y as O,a,v as J,d as $,t as x,w as T}from"../chunks/index.2bf4358c.js";import{C as P}from"../chunks/CodeBlock.4e987730.js";import{C as ss}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{H as ts,E as es}from"../chunks/getInferenceSnippets.97e75ee2.js";function as(Q){let r,k,b,C,p,U,i,B,o,q="如果你打算在正式的项目中使用经过预训练或经过微调的模型。请注意：虽然这些模型是很强大，但它们也有局限性。其中最大的一个问题是，为了对大量数据进行预训练，研究人员通常会搜集所有他们能找到的所有文字内容，中间可能夹带一些意识形态或者价值观的刻板印象。",_,c,S="为了快速解释清楚这个问题，让我们回到一个使用 BERT 模型的 pipeline 的例子：",I,m,V,u,N,h,A='当要求模型填写这两句话中缺少的单词时，模型给出的答案中，只有一个与性别无关（服务员/女服务员）。其他职业通常与某一特定性别相关，妓女最终进入了模型中与“女人”和“工作”相关的前五位。尽管 BERT 是少数使用经过筛选和清洗后，并且看似中立的数据集上建立的的 Transformer 模型，而不是通过从互联网上搜集数据（它使用的是 <a href="https://huggingface.co/datasets/wikipedia" rel="nofollow">Wikipedia 英文</a> 和 <a href="https://huggingface.co/datasets/bookcorpus" rel="nofollow">BookCorpus</a> 数据集），但是这种情况还是发生了。',W,f,H="因此，当你使用这些工具时，你需要记住，使用的原始模型的时候，很容易生成性别歧视、种族主义或恐同内容。这种固有偏见不会随着微调模型而消失。",v,y,z,d,E;return p=new ts({props:{title:"偏见和局限性",local:"偏见和局限性",headingTag:"h1"}}),i=new ss({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/zh-CN/chapter1/section8.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter1/section8.ipynb"}]}}),m=new P({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}}),u=new P({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}}),y=new es({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter1/8.mdx"}}),{c(){r=M("meta"),k=l(),b=M("p"),C=l(),j(p.$$.fragment),U=l(),j(i.$$.fragment),B=l(),o=M("p"),o.textContent=q,_=l(),c=M("p"),c.textContent=S,I=l(),j(m.$$.fragment),V=l(),j(u.$$.fragment),N=l(),h=M("p"),h.innerHTML=A,W=l(),f=M("p"),f.textContent=H,v=l(),j(y.$$.fragment),z=l(),d=M("p"),this.h()},l(s){const t=D("svelte-u9bgzb",document.head);r=g(t,"META",{name:!0,content:!0}),t.forEach(e),k=n(s),b=g(s,"P",{}),R(b).forEach(e),C=n(s),w(p.$$.fragment,s),U=n(s),w(i.$$.fragment,s),B=n(s),o=g(s,"P",{"data-svelte-h":!0}),G(o)!=="svelte-14d8mf7"&&(o.textContent=q),_=n(s),c=g(s,"P",{"data-svelte-h":!0}),G(c)!=="svelte-27d4wy"&&(c.textContent=S),I=n(s),w(m.$$.fragment,s),V=n(s),w(u.$$.fragment,s),N=n(s),h=g(s,"P",{"data-svelte-h":!0}),G(h)!=="svelte-1j5rfw5"&&(h.innerHTML=A),W=n(s),f=g(s,"P",{"data-svelte-h":!0}),G(f)!=="svelte-11rtbii"&&(f.textContent=H),v=n(s),w(y.$$.fragment,s),z=n(s),d=g(s,"P",{}),R(d).forEach(e),this.h()},h(){Z(r,"name","hf:doc:metadata"),Z(r,"content",ls)},m(s,t){O(document.head,r),a(s,k,t),a(s,b,t),a(s,C,t),J(p,s,t),a(s,U,t),J(i,s,t),a(s,B,t),a(s,o,t),a(s,_,t),a(s,c,t),a(s,I,t),J(m,s,t),a(s,V,t),J(u,s,t),a(s,N,t),a(s,h,t),a(s,W,t),a(s,f,t),a(s,v,t),J(y,s,t),a(s,z,t),a(s,d,t),E=!0},p:F,i(s){E||($(p.$$.fragment,s),$(i.$$.fragment,s),$(m.$$.fragment,s),$(u.$$.fragment,s),$(y.$$.fragment,s),E=!0)},o(s){x(p.$$.fragment,s),x(i.$$.fragment,s),x(m.$$.fragment,s),x(u.$$.fragment,s),x(y.$$.fragment,s),E=!1},d(s){s&&(e(k),e(b),e(C),e(U),e(B),e(o),e(_),e(c),e(I),e(V),e(N),e(h),e(W),e(f),e(v),e(z),e(d)),e(r),T(p,s),T(i,s),T(m,s),T(u,s),T(y,s)}}}const ls='{"title":"偏见和局限性","local":"偏见和局限性","sections":[],"depth":1}';function ns(Q){return Y(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ms extends K{constructor(r){super(),L(this,r,ns,as,X,{})}}export{ms as component};
