Finspector: A Human-Centered Visual Inspection Tool for Exploring and Comparing Biases among Foundation Models (2023)

Abstract: Pre-trained transformer-based language models are becoming increasingly popular due to their exceptional performance on various benchmarks. However, concerns persist regarding the presence of hidden biases within these models, which can lead to discriminatory outcomes and reinforce harmful stereotypes. To address this issue, we propose Finspector, a human-centered visual inspection tool designed to detect biases in different categories through log-likelihood scores generated by language models. The goal of the tool is to enable researchers to easily identify potential biases using visual analytics, ultimately contributing to a fairer and more just deployment of these models in both academic and industrial settings. Finspector is available at https://github.com/IBM/finspector .

## introduction recently, pre-trained large language models (llms), including 'foundation models,' that are trained on large amounts of data have shown striking performances in a variety of natural language processing (nlp) tasks such as language translation, text classification, and summarization. such models can also be fine-tuned and adapted to analyze and understand text generated in specific fields, such as law and medicine. despite their usefulness, there is a growing concern that the foundation models inherently reflect human biases, which might have originated from their large training corpora @xcite @xcite . these social biases include stereotyping and negative generalizations of different social groups and communities, which could have been present in their training corpora @xcite . a cognitive bias, stereotyping, is defined as the assumption of some characteristics are applied to communities on the basis of their @xcite . relatedly, fairness ("zero-bias"), in the context of nlp and machine learning is defined as being not discriminatory according to such characteristics @xcite . given this context, there is a significant demand for methodologies and tools aimed at inspecting, detecting, and mitigating bias within ai models, particularly large-scale language models @xcite . a previous work @xcite demonstrated that computing the pseudo-log-likelihood scores of paraphrased sentences using different foundation models can be used to test the consistency and robustness of the models, which can lead to a better understanding of the fairness of llms. pseudo-log-likelihood masked language models (mlm) scoring or log probability of auto-regressive language models can be used to measure how likely a language model is to produce a given sentence @xcite . it can also be used to measure the likelihood of multiple variants of a sentence, such as stereotypical and non-stereotypical ones, in order to determine which one the model prefers or predicts as more likely. consequently, this measure can be used to show whether a model consistently prefers stereotypical sentences over non-stereotypical ones. we believe that experts in respective fields need to inspect the fairness and biases through a systematic, human-in-the-loop approach, including the lens of log-likelihood scores, before adapting them for any downstream tasks. such humancentered data analysis approaches can help users to assess foundation models' inner workings. furthermore, interactive data visualization techniques can help users to form and test their hypotheses about underlying models and effectively communicate the results of these models to a wider audience, enabling better collaboration and understanding among stakeholders. many techniques were developed and applied to inspect the fairness of different machine learning models, as discussed in section 2. in this work, we propose a visual analytics application called finspector, a short name for foundation model inspector. finspector is designed to help users to test the robustness of foundation models and identify biases of various foundation models using interactive visualizations. the system is built as a python package so that it can be used in the jupyter environment, which is familiar to our target users-data scientists. the tool consists of multiple, coordinated visualizations, each of which supports a variety of analytic tasks. with foundation models available from repositories such as hugging face, users can use finspector to generate and visually compare the log probability scores on user-provided sentences. in this paper, we introduce the design of finspector and present a case study of how the tool can be used to inspect the fairness of large language models. ## background bias in nlp including large language models has been studied extensively. garrido-muñoz et al. provide a survey @xcite of existing work on the topic. benchmarks for detecting bias in models is a key element of this research; stereoset @xcite , crows-pairs @xcite , winogender @xcite , winobias @xcite are examples of such benchmarks. tenny et al. presented language interpretability tool (lit) @xcite as a visualization tool for understanding nlp models which includes analyzing gender bias among others. there are several other visualization tools that are focused on analyzing different aspects of transformer-based llms such as attention or hidden states such as t 3 -vis @xcite , interpert @xcite , exbert @xcite , allennlp interpret @xcite , sanvis @xcite , and bertviz @xcite . similarly, biascope @xcite , is a visualization tool for unfairness diagnosis in graph embeddings by comparing models. the visualizations in these tools are mainly focused on understanding how the attention mechanism works and the impact of different tokens in the input to the model output. there are several other visualization tools that help users investigate the fairness of machine learning models, primarily focusing on aspects such as prediction discrepancy among different subgroups, group fairness, individual fairness, and counterfactual fairness. these include tools such as what-if tool @xcite , fairvis @xcite , fairsight @xcite , @xcite , dash @xcite , conceptexplainer @xcite and @xcite . despite their usefulness, they are mainly designed to explore the fairness of predictive models (e.g., image classification), not for pre-trained foundation models. in contrast to these tools above, finspector aims to inspect the fairness and bias of foundational models by exploring the log-likelihood scores generated by the models. such scores and their difference are presented with interactive visualizations. ## design of finspector in this section, we describe the design of finspector. there are three main views of finspector, 1) distribution of log likelihoods, 2) table of sentences, and 3) sentence embeddings, and a customization panel on top to set highlights or split distributions by selected categorical variables. readers can access the code of finspector at https: //github.com/ibm/finspector . the system requires users to provide three items: 1) text data with paired samples and bias category labels; 2) pre-trained foundation models; 3) 2d sentence embeddings. by default, the system expects text data with labels indicating paired samples (e.g., sample id) and bias categories, similar to the crows-pairs dataset @xcite . without bias categories provided, users can still use finspector but without options to color-code or sliceand-dice the samples by the variables. any other metadata associated with each sentence can be viewed in the table view. in the current implementation, the system accepts any models trained in selfsupervised, masked language modeling approaches using pytorch. for instance, users can download models like bert, albert, and roberta from hugging face and use them to run finspector. users can optionally provide the 2d representation vectors of sentences. users can freely choose any dimensionality reduction method to derive meaningful representations that can be visualized for explorative analysis. ## use cases: inspecting foundation models using the paraphrased crows-pairs dataset in this section, we demonstrate how finspector can be used to discover informative insights about foundation models and datasets. note that the insights reported here are preliminary hypotheses so should not be taken as proven facts. this section aims to describe how interactive visualizations of finspector help users to explore the fairness of large language models. in this use case, we used the crows-pairs dataset for the analysis @xcite . to increase the sample size, we generated 10 paraphrased sentences per each given sentence using pegasus @xcite and ensured that there are no duplicates. then, we generated the pseudo-loglikelihood measure using each of the three foundation models, bert, albert, and roberta, per sentence. then, for the sentence embedding view, we used a dimensionality reduction algorithm, t-sne (van der @xcite , to project the log-likelihood score vector into two dimensions. as figure 1 shows, we plugged in the model checkpoints downloaded from hugging face, the paraphrased crows-pairs dataset, and the 2d representation vectors generated from t-sne to launch finspector. initially, the three foundation models show similar distributions of log probabilities, but the score of albert is slightly lower than those of the two other models as shown in figure 1 (b ). in particular, a small bump between -4 and -5 indicates there are a considerable amount of sentences that deem unlikely from albert. overall, the sentence embedding view shows that there are several groups that share the distribution across three models. we set a filter by drawing a rectangular box between the values of -5 and -4 on albert. figure 3 (a ) shows parallel coordinates of sentences satisfying the requirement. notably, the sentences that had lower than -4 in log probabilities on al-bert tended to have higher values around -3.5 and -2.5 on bert or roberta. the sentences embedding view shows that the selected sentences are clustered at the bottom part. we decided to select the bottom region by hovering sentences near the cluster and found sentences that show similar patterns with wider differences in scores. in the case of one sentence, "i know the whites are correct, i said warmly.", scores were -3.3, -3.4, and -.6.6, for bert, roberta, and albert, respectively. we decided to explore differences in the log probabilities among bias categories using the split and highlight features of finspector. the distribution view shows differences in the score of al-bert between a pair of base and stereotype sentences of the disability category, as figure 3 (b) shows. the stereotypical sentences appear more likely than the base sentences. for instance, the log probability of "a person with mental illness laughed at a bird" by albert is -2.4. on the other hand, "a person laughed at a bird" by albert is -3.8. however, the other models did not show similar trends: -2.7 (bert), -2.3 (roberta) for the stereotypical sentence, and -2.4 (bert), -2.2 (roberta) for the base sentence. we switched the gear to see general differences among categories. the parallel band view shows that the log probabilities of sentences in the age category tend to be higher than those in the race-color category. lastly, we decided to generate some customized sentences. we wrote a gender-stereotype sentence, "housekeeping and childcare are women's responsibility.", and its counterpart, "housekeeping and childcare are men's responsibility." the log probability score by roberta shows some differences as the score of the stereotypical sentence is -1.5, which is higher than that of the counterpart, -2.0. we also wrote another gender-stereotype sentence, "jane is the most probable candidate for the ceo position because of her leadership, credibility, and humility.", and compared it to its counterpart, "john is the most probable candidate for the ceo position because of his leadership, credibility, and humility." as figure 3 (c ) & (d) show, the log probabilities of the sentence including the gender stereotype appear to show higher log probabilities than the counterpart, across all three foundation models. ## discussion in this paper, we introduce an interactive visualization system called finspector, which helps users to explore pre-trained large language models by evaluating the pseudo-log-likelihood measures computed on text data. adopting the workflow from our previous approach @xcite , the system allows users to inspect biases and fairnesses of given models applied to sentences that manifest signs of stereotypes. finspector is developed for interactive computing environments like jupyter to help users constantly evaluate models while improving their effectiveness and fairness before deploying them for practice. this paper describes the views and features of finspector to accomplish the goals, which can be useful for future researchers and designers to develop similar systems in the future. our work of a human-centered approach for fairness inspection of llms opens new research av-enues for interdisciplinary research between ai, visualization, and other fields. one future research area is to build interactive visualization systems that help users evaluate the impact of biases in foundation models on various downstream tasks. numerous large language models undergo fine-tuning or prompt-tuning processes, such as text classification, entity recognition, and language translation. latent fairness and bias issues in language models can propagate through the pipeline so that fine-tuning or prompt-tuning the foundation models may generate undesirable outcomes. therefore, researchers need to examine the relationship between bias and fairness in base models and the performance outcomes of fine-tuning or prompttuning these models on specific tasks. interactive visualizations can be developed for researchers to conduct systematic evaluations of the associations between bias and performance. another future work can investigate the robustness of pseudo-log-likelihood scoring as a bias measure for foundation models adapted to various tasks. we consistently discover some cases where foundation models generate some problematic issues in sentences that contain stereotypical characteristics with one category (e.g., black) versus another (e.g., white). one key area to measure the robustness is to identify new ways to improve the robustness of loglikelihood scoring as a bias measure for foundation models. it is also important to collect a benchmark dataset containing the stereotype sentence pairs in a systematic manner. ultimately, such investigation will help us develop an evaluation metric that can be widely used before fine-tuning and deploying it for downstream tasks. in this work, we focused on language models pre-trained using masked-language modeling objectives, i.e., mainly encoder-only models such as bert, roberta, and albert, which can be used to generate conditional pseudo-log-likelihood measures. there are two other families of language models. first, decoder-only autoregressive models, such as gpt, are pre-trained by predicting the subsequent word in a sequence based on the preceding words or employing the next-sentence-prediction approach @xcite . second, there are encoder-decoder or sequence-to-sequence models such as bart @xcite or t5 @xcite . finspector is generalizable to these different types of architectures given that a metric can be formulated to measure the likelihood of a given sentence in the language model. for instance, for gpt-like language models, @xcite use log probability score. in the future, we plan to incorporate foundation models from other families, including decoder-only and encoder-decoder models, into finspector. to inspect such models in the current finspector framework, users need to develop ways to generate a log-likelihood-equivalent measure per sentence or we can adapt the visualization framework to fit the next-sentence-prediction models and evaluate their biases in different ways. as part of our future research, we plan to investigate various visual analytics approaches for inspecting the fairness and biases in models pre-trained using various modeling objectives and architecture. ## impact statement our tool is designed to help users evaluate the fairness and biases of foundation models or large language models. such a tool can help researchers and practitioners visually investigate biases in large language models for further discussion and remedy. presentation of finspector can facilitate discussion of human-centered approaches to detecting and resolving fairness issues in various large language models. however, readers should also note that there is no guarantee to discover all biases or fairness issues by using the tool. we hope that the design of the tool described in the paper can inspire future technologies that can help evaluate the bias and fairness of foundation models.