1
|
|
|
""" |
2
|
|
|
Metrics and debiasing for bias (such as gender and race) in word embedding. |
3
|
|
|
|
4
|
|
|
.. important:: |
5
|
|
|
The following paper suggests that the current methods |
6
|
|
|
have an only superficial effect on the bias in word embeddings: |
7
|
|
|
|
8
|
|
|
Gonen, H., & Goldberg, Y. (2019). |
9
|
|
|
`Lipstick on a Pig: |
10
|
|
|
Debiasing Methods Cover up Systematic Gender Biases |
11
|
|
|
in Word Embeddings But do not Remove Them <https://arxiv.org/abs/1903.03862>`_. |
12
|
|
|
arXiv preprint arXiv:1903.03862. |
13
|
|
|
|
14
|
|
|
.. important:: |
15
|
|
|
The following paper criticize using |
16
|
|
|
:func:`~responsibly.we.utils.most_similar` |
17
|
|
|
function from `gensim <https://radimrehurek.com/gensim/>`_ in the context |
18
|
|
|
of word embedding bias and the generating analogies process: |
19
|
|
|
|
20
|
|
|
Nissim, M., van Noord, R., van der Goot, R. (2019). |
21
|
|
|
`Fair is Better than Sensational: Man is to Doctor |
22
|
|
|
as Woman is to Doctor <https://arxiv.org/abs/1905.09866>`_. |
23
|
|
|
|
24
|
|
|
Therefore, in *responsibly* there is an implementation of |
25
|
|
|
:func:`~responsibly.we.utils.most_similar` with the argument |
26
|
|
|
`unrestricted` that doesn't filter the results. |
27
|
|
|
Similar argument exist for |
28
|
|
|
:meth:`~responsibly.we.bias.BiasWordEmbedding.generate_analogies`. |
29
|
|
|
|
30
|
|
|
Currently, three methods are supported: |
31
|
|
|
|
32
|
|
|
1. Bolukbasi et al. (2016) bias measure and debiasing |
33
|
|
|
- :mod:`responsibly.we.bias` |
34
|
|
|
|
35
|
|
|
2. WEAT measure |
36
|
|
|
- :mod:`responsibly.we.weat` |
37
|
|
|
|
38
|
|
|
3. Gonen et al. (2019) clustering as classification |
39
|
|
|
of biased neutral words |
40
|
|
|
- :meth:`responsibly.we.bias.BiasWordEmbedding.plot_most_biased_clustering` |
41
|
|
|
|
42
|
|
|
Besides, some of the standard benchmarks for |
43
|
|
|
word embeddings are also available, primarily to check |
44
|
|
|
the impact of debiasing performance. |
45
|
|
|
|
46
|
|
|
""" |
47
|
|
|
|
48
|
|
|
from responsibly.we.bias import BiasWordEmbedding, GenderBiasWE |
49
|
|
|
from responsibly.we.data import load_w2v_small |
50
|
|
|
from responsibly.we.utils import most_similar |
51
|
|
|
from responsibly.we.weat import ( |
52
|
|
|
calc_all_weat, calc_single_weat, calc_weat_pleasant_unpleasant_attribute, |
53
|
|
|
) |
54
|
|
|
|