<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Doctoral Consortium of AIxIA</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Supervised Bias Detection in Transformers-based Language Models</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Michele Dusi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alfonso Emilio Gerevini</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Luca Putelli</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Ivan Serina</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Sapienza University of Rome</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Brescia (UniBS)</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2023</year>
      </pub-date>
      <volume>22</volume>
      <fpage>6</fpage>
      <lpage>9</lpage>
      <abstract>
        <p>Training Large Language Models on biased datasets tends to teach a discriminatory behavior to the systems themselves, as it has been proven by the last years literature on fairness in AI and Machine Learning algorithms. The developed bias-detection strategies often ignores the inner body of the model, making it easy to generalize the methodology, but harder to understand the underlying motivations. In this paper, we present a general approach for detecting unwanted prejudices in Language Models, requiring only a small set of input data. Our strategy works on the embedding representation of languages, without any constraint on model architecture, but it is able to detect which parts of the representation is the most prejudice-afected.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Natural Language Processing</kwd>
        <kwd>Large Language Models</kwd>
        <kwd>AI Fairness</kwd>
        <kwd>Bias Detection</kwd>
        <kwd>Word Embeddings</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>In recent years, there has been significant growth in the utilization of pre-trained models for
Natural Language Processing across various sectors, including chatbots, sentiment analysis
systems, and applications in fields such as medicine, marketing, and education. Naturally, the
primary concern of the Machine Learning community for these applications is their performance.
New, intricate architectures like BERT and other Transformer-based models have proven to
deliver a notably high level of accuracy. However, it’s crucial to note that these models are
trained using extensive datasets directly sourced from the internet. Consequently, they may
inadvertently incorporate biases, prejudices, and stereotypes related to demographic minorities,
such as gender, race, religion, sexual orientation, disability, and more. These unintended
characteristics can emerge in the algorithms, potentially leading to discriminatory behavior.</p>
      <p>
        Numerous studies have been dedicated to this topic, revealing that both word embedding
representations and pre-trained language models encompass gender bias [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], showing a deep
relationship between the gender stereotypes and the use of language. Further studies have also
highlighted the presence of other types of biases (ethnicity bias, religion bias, sexual orientation
bias, . . . ) in monolingual and bilingual models [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Works following a geometric approach try to
measure bias according to concepts representation in word embeddings; this idea follows directly
the distributional hypothesis from linguistics [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], stating that nearby embeddings corresponds
to similar words in meaning. Statistical analysis of the spatial relationships between sets of
concepts has also led to bias-quantification tests [
        <xref ref-type="bibr" rid="ref4 ref5">4, 5, 6, 7</xref>
        ].
      </p>
      <p>One of the key limitations in these studies lies in their treatment of the model as an opaque
entity, a black-box. Primarily, their focus is on confirming the presence or absence of bias
without delving deeper into how it is encoded within the model. Instead, this work presents an
alternative methodology for studying the presence of bias in a generic model of contextual word
embeddings. Furthermore, this approach could pinpoint the specific components of the word
vectors that are responsible of conveying the bias. This insight aids in visualization, ofering an
immediate grasp of bias within a language model, and helps the development of more targeted
strategies for bias reduction.</p>
      <p>In the following, we apply our methodology to three diferent protected attributes: gender,
ethnicity and religion; we thus consider diferent stereotypes involving perceived criminality,
positive and negative terms and jobs salary. The experiments have been conducted on the BERT
architecture [8] (in particular, the base English version), but our approach can be generalized
considering other Transformer-based models [9].</p>
    </sec>
    <sec id="sec-2">
      <title>2. Materials and Methods</title>
      <p>Applying our method requires two diferent sets of word vectors: a set of protected words,
characterising the protected attribute, and a second set of stereotyped words,
characterising the values in which the stereotype expresses. For instance, we could have a first set of
words identifying religions (christian, muslim, church, mosque, priest, imam, etc.), and a second
identifying positive and negative adjectives (good, faithful, innocent, bad, treacherous, guilty,
etc.). Each word is associated with a value of the corresponding attribute; in the previous
example, protected words refer to values christian or muslim, whereas stereotyped words can
be positive or negative. Lastly, each word has a reciprocal word vector obtained through BERT.
In conclusion, items of the two sets can be seen as tuples with a word, a value for the property,
and a vector with the size of the model embedding space.</p>
      <p>The words datasets have been crafted from scratch to precisely identify the chosen attributes,
taking word samples from internet services like WordReference1. The construction of the word
embeddings by BERT, instead, required the usage of contextual sentences in which the words
appeared. Each sentence was processed by the Language Model and converted into a series of
embeddings, one for each token2. Next, only the embedding referring to the inquired word was
retained, obtaining a single word vector.</p>
      <p>The core procedure of bias detection is composed by two steps: in a first phase, the protected
attribute is characterised in terms of relevant embedding features, meaning that we identify
which components of the word vectors encode the analysed attribute. The idea of this
preliminary step is to understand how the protected property is represented within the model
1https://www.wordreference.com/it/
2A token is a part of text in which Large Language Models like BERT split the input sentences. For the sake of
simplicity, we could think of a token as a single word.</p>
      <p>n = 235
Actual values
(stereotyped)
positive
negative</p>
      <p>Predicted values</p>
      <p>(protected)
christian muslim
80 40
39 81
119 121
∑︀
embedding space and which features best describe it. The second phase compares the
stereotyped words to the previously-described protected features, efectively performing operations of
bias detection and quantification. The second step provides the desired outcome of quantifying
a prejudice; however, it builds upon the previous procedure and cannot be performed by itself.</p>
      <p>More specifically, in the first phase we train a classifier on the protected words, teaching it to
discern diferent values of the protected attribute by their embeddings. This way, the classifier
learns which features are relevant for encoding the inquired property (gender, ethnicity or
religion). After experimenting with multiple classifiers, we opted for the one that gave the best
results, a Linear Support Vector Machine (LSVM). This choice can be explained by looking at
the dimension of the learning dataset, around 100 samples, which is not enough for training a
neural network architecture.</p>
      <p>The LSVM learns one scalar weight for each one of the embedding dimensions; in our case,
BERT works in a 768-dimensional space. Among these 768, we selected the n highest weights by
their absolute value, where n is a hyperparameter chosen based on the protected and stereotyped
attributes; its exact value, typically around 100, will be discussed later. The n highest weights
identify the n most relevant features of the embedding space; for this, we project all the word
vectors to those n dimensions, i.e. we shorten the vectors by discarding the 768 − n non-relevant
features. This operation is applied both to protected and stereotyped word embeddings.</p>
      <p>The outcome at the end of the first phase consists in two sets of reduced word vectors with
size n, corresponding to the original word vectors whose only the most relevant dimensions
have been retained. This enhance the encoding of the protected attribute within the embeddings,
if present, and removes the unwanted noise in the vector.</p>
      <p>The second phase works on the enhanced sets to detect whether a bias is present. A bias
in word embedding is a distortion of how concepts are represented; in simpler words, if the
terrorist word vector is more similar to vectors of value muslim than vectors of value christian,
the representation is not balanced and, thus, not fair.</p>
      <p>To measure similarity of stereotyped vectors with respect to protected ones, we train another
classifier on the reduced n-dimensional protected word vector, which learns to discern among
genders, religions or ethnicities. Thence, we provide to it the stereotyped embeddings as a test
set and look at the predicted classes. In the ideal situation, the classifier shouldn’t be able to
predict anything, because the test samples (the stereotyped embeddings) are not related to the
training samples (the protected embeddings). As a consequence, the outcomes for the test set
should be random, with equal probabilities for each predicted class; this is our null hypothesis.</p>
      <p>On the contrary, if the predictions are unbalanced and the protected values show some sort of
gender× salary
religion× adjective
ethnicity× criminality
500
600
700
768
correlation with the stereotyped values (for example, if the low-salary jobs vectors are classified
as female, or if the negative adjectives are classifies as muslim, etc.), the null hypothesis should
be rejected and we assess the presence of a prejudice.</p>
    </sec>
    <sec id="sec-3">
      <title>3. Results and Discussion</title>
      <p>In Table 1, we report the observed frequency for the classification of positive and negative
adjectives in the religion classes. As it can be observed, the distribution is not balanced for the
protected attribute: the tendency to classify the positive adjectives as christian is contrasted by
the opposite tendency to classify negative terms as muslim.</p>
      <p>We can measure how the distribution shifts from a random classification via the  2 test. The
resulting p-value for the example in Table 1 is 1.1 · 10− 7, meaning that such distribution is not
random, and thus the protected and stereotyped attributes are perceived as correlated with
probability higher than 0.999999.</p>
      <p>Other domains give similar outcomes: the p-value for jobs word vectors grouped by salary
(stereotyped attribute) and classified by gender (protected attribute) is 6.4 · 10− 3 for n = 42;
the p-value for the ethnicity protected attribute compared with criminality words is 1.8 · 10− 3
for n = 10.</p>
      <p>Finally, in Figure 1 we address the problem of choosing the right value for the hyperparameter
n. The plots show the trend of the p-value for diferent n going from 2 to 768, representing
diferent percentages of retained dimensions of the original embedding space. As we can see,
higher values of n includes noise in the representation, obfuscating the underlying bias which
would not be detected by our method. Lower values of n, instead, give a clean representation
of the protected attribute in the stereotyped words, enhancing their unwanted distortion.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Conclusion</title>
      <p>In this document we briefly presented a geometric approach to assess bias detection in Large
Language Models. We considered BERT in the English base implementation, evaluating common
prejudices for gender, ethnic and religious groups of people. The method requires very few
input resources to grasp and assess the stereotypes, making it easy to implement and use.</p>
      <p>The hyperparameter n controls the amount of information retained from the original word
embeddings; choosing the right value is crucial to detect the distortions. The plots in Figure
1 indicate that diferent attributes are characterised by and encoded with diferent amount of
dimensions. Further analysis are required to understand how the best value of n can be chosen
in advance, without testing all the possible values.</p>
      <p>In the future, many other domains could be tested with this methodology, discovering
connotations not only related to biases and prejudices, but also to the conception of the word
embedding space. This could improve our comprehension of Large Language Models, allowing to
operate on word vectors and language representation with increased precision and knowledge.</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments</title>
      <p>This work was carried out while the author, Michele Dusi, was enrolled in the Italian National
Doctorate on Artificial Intelligence run by Sapienza University of Rome in collaboration with the
University of Brescia.
tics, *SEM@NAACL-HLT 2019, Minneapolis, MN, USA, June 6-7, 2019, Association for
Computational Linguistics, 2019, pp. 85–91.
[6] C. May, A. Wang, S. Bordia, S. R. Bowman, R. Rudinger, On measuring social biases in
sentence encoders, in: J. Burstein, C. Doran, T. Solorio (Eds.), Proceedings of the 2019
Conference of the North American Chapter of the Association for Computational Linguistics:
Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN, USA, June 2-7, 2019,
Volume 1 (Long and Short Papers), Association for Computational Linguistics, 2019, pp.
622–628.
[7] W. Guo, A. Caliskan, Detecting emergent intersectional biases: Contextualized word
embeddings contain a distribution of human-like biases, in: Proceedings of the 2021
AAAI/ACM Conference on AI, Ethics, and Society, ACM, 2021.
[8] J. Devlin, M. Chang, K. Lee, K. Toutanova, BERT: pre-training of deep bidirectional
transformers for language understanding, in: J. Burstein, C. Doran, T. Solorio (Eds.), Proceedings
of the 2019 Conference of the North American Chapter of the Association for
Computational Linguistics: Human Language Technologies, NAACL-HLT 2019, Minneapolis, MN,
USA, June 2-7, 2019, Volume 1 (Long and Short Papers), Association for Computational
Linguistics, 2019, pp. 4171–4186.
[9] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, L. Kaiser, I. Polosukhin,
Attention is all you need, in: I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus,
S. Vishwanathan, R. Garnett (Eds.), Advances in Neural Information Processing Systems,
volume 30, Curran Associates, Inc., 2017.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>T.</given-names>
            <surname>Bolukbasi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Chang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. Y.</given-names>
            <surname>Zou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Saligrama</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. T.</given-names>
            <surname>Kalai</surname>
          </string-name>
          ,
          <article-title>Man is to computer programmer as woman is to homemaker? debiasing word embeddings</article-title>
          , in: D. D.
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Sugiyama</surname>
            , U. von Luxburg,
            <given-names>I. Guyon</given-names>
          </string-name>
          , R. Garnett (Eds.),
          <source>Advances in Neural Information Processing Systems 29: Annual Conference on Neural Information Processing Systems</source>
          <year>2016</year>
          , December 5-
          <issue>10</issue>
          ,
          <year>2016</year>
          , Barcelona, Spain,
          <year>2016</year>
          , pp.
          <fpage>4349</fpage>
          -
          <lpage>4357</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>P.</given-names>
            <surname>Zhou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Shi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Zhao</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Huang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Cotterell</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Chang</surname>
          </string-name>
          ,
          <article-title>Examining gender bias in languages with grammatical gender</article-title>
          , in: K. Inui,
          <string-name>
            <given-names>J.</given-names>
            <surname>Jiang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Ng</surname>
          </string-name>
          ,
          <string-name>
            <surname>X.</surname>
          </string-name>
          Wan (Eds.),
          <source>Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing, EMNLP-IJCNLP</source>
          <year>2019</year>
          ,
          <string-name>
            <given-names>Hong</given-names>
            <surname>Kong</surname>
          </string-name>
          , China, November 3-
          <issue>7</issue>
          ,
          <year>2019</year>
          , Association for Computational Linguistics,
          <year>2019</year>
          , pp.
          <fpage>5275</fpage>
          -
          <lpage>5283</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Z. S.</given-names>
            <surname>Harris</surname>
          </string-name>
          , Distributional structure,
          <source>WORD</source>
          <volume>10</volume>
          (
          <year>1954</year>
          )
          <fpage>146</fpage>
          -
          <lpage>162</lpage>
          . URL: https: //doi.org/10.1080/00437956.
          <year>1954</year>
          .
          <volume>11659520</volume>
          . doi:
          <volume>10</volume>
          .1080/00437956.
          <year>1954</year>
          .
          <volume>11659520</volume>
          . arXiv:https://doi.org/10.1080/00437956.
          <year>1954</year>
          .
          <volume>11659520</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Caliskan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. J.</given-names>
            <surname>Bryson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Narayanan</surname>
          </string-name>
          ,
          <article-title>Semantics derived automatically from language corpora contain human-like biases</article-title>
          ,
          <source>Science</source>
          <volume>356</volume>
          (
          <year>2017</year>
          )
          <fpage>183</fpage>
          -
          <lpage>186</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>A.</given-names>
            <surname>Lauscher</surname>
          </string-name>
          , G. Glavas,
          <article-title>Are we consistently biased? multidimensional analysis of biases in distributional word vectors</article-title>
          , in: R.
          <string-name>
            <surname>Mihalcea</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          <string-name>
            <surname>Shutova</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <string-name>
            <surname>Ku</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          <string-name>
            <surname>Evang</surname>
          </string-name>
          , S. Poria (Eds.),
          <source>Proceedings of the Eighth Joint Conference on Lexical and Computational</source>
          Seman-
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>