Exploring Multifaceted Variation and Bias in Written Language Data (2024)

Abstract: Exploring and understanding language data is a fundamental stage in all areas dealing with human language. It allows NLP practitioners to uncover quality concerns and harmful biases in data before training, and helps linguists and social scientists to gain insight into language use and human behavior. Yet, there is currently a lack of a unified, customizable tool to seamlessly inspect and visualize language variation and bias across multiple variables, language units, and diverse metrics that go beyond descriptive statistics. In this paper, we introduce VARIATIONIST, a highly-modular, extensible, and task-agnostic tool that fills this gap. VARIATIONIST handles at once a potentially unlimited combination of variable types and semantics across diversity and association metrics with regards to the language unit of choice, and orchestrates the creation of up to five-dimensional interactive charts for over 30 variable type– semantics combinations. Through our case studies on computational dialectology, human label variation, and text generation, we show how VARIATIONIST enables researchers from different disciplines to effortlessly answer specific research questions or unveil undesired associations in language data. A Python library, code, documentation, and tutorials are made publicly available to the research community.

heading: 1 Introduction
text: Language data is at the core of a large body of work in many research fields and at their intersections. Language data is used to train large language models (LLMs) by natural language processing (NLP) practitioners, but also by linguists and social scientists to analyze human language and behavior.
With a tendency in the NLP community to overlook what actually is in the training data of models (Bender et al., 2021), especially at the level of
*These authors contributed equally to this work.
textual information, and how different characteristics of the data can be intertwined, we propose a tool that can help in inspecting language data in a straightforward and highly customizable manner.
While some language data exploration tools already exist, especially English-centric corpus linguistics tools (Anthony, 2013), these cannot typically handle different types of textual units (e.g., tokens, bigrams, characters, and more) and multiple variables or combinations thereof, only offering surface-level metrics that are not easily customizable, and providing low-dimensional visualization. On the other hand, modern analysis tools in NLP mainly focus on interpreting model outputs (Sarti et al., 2023; Attanasio et al., 2023, inter alia) rather than exploring the language data in itself.
VARIATIONIST aims to fill this gap, offering the chance to researchers from diverse disciplines to easily explore the intersections between variables in textual corpora in a plethora of different configurations in a unified manner (cf. Figure 1). Addition-
346
ally, VARIATIONIST allows users to plug in their own custom tokenization functions and metrics in a seamless way, opening up an unlimited number of analysis configurations in just a few lines of code, and going beyond English-centric assumptions on what the definition of a unit in language actually is.
We demonstrate the flexibility of VARIATIONIST through a set of case studies spanning research questions pertaining to diverse areas of research: computational dialectology, human-label variation (Plank, 2022), and text generation.
Contributions We propose VARIATIONIST, a highly flexible and customizable tool for allowing researchers from many fields to seamlessly explore and visualize language variation and bias in textual corpora across many dimensions. We release our code,1 a Python library,2 a detailed documentation,3 a video presentation,4 and a set of tutorials.5

heading: 2 Tool Design
text: In this section, we present the overall design and aim of VARIATIONIST. In Section 2.1 we detail the guiding design principles, whereas in Section 2.2 we summarize the core elements and functionalities around which VARIATIONIST is designed.

heading: 2.1 Design Principles
text: The guiding design principles of VARIATIONIST are summarized in the following:
• Ease of use: VARIATIONIST is crafted to be as accessible and customizable as possible, to serve researchers from a wide range of fields who are interested in exploring textual data;
• Modularity: VARIATIONIST is built out of small building blocks, allowing users to pick and choose their desired features and metrics without running unnecessary calculations;
• Extensibility: VARIATIONIST is designed to be easily extended. By virtue of its intrinsic modularity, it is conceived to let users select their preferred features, and import their own custom tokenizers and metrics into the tool.
1§ : https://github.com/dhfbk/variationist. 23 : https://pypi.org/project/variationist. 3[ : https://variationist.readthedocs.io. 4Y : The video is available in our GitHub repository. 5e : https://github.com/dhfbk/variationist/
tree/main/examples.

heading: 2.2 Core Elements and Functionalities
text: VARIATIONIST is designed around a set of core elements useful for computation and visualization. We provide details on each of them in the following.
DATASETS The main input for the analysis. Datasets can be provided in the form of i) tabseparated (tsv) or ii) comma-separated (csv) files, or iii) pre-computed pandas dataframes. Moreover, iv) any dataset from the Hugging Face Datasets (Lhoest et al., 2021) repository can be directly imported for analysis and visualization, too.
TEXTS The subset of the input data, in the form of column names or indices, containing textual data. While in most scenarios only a single text column is needed, VARIATIONIST handles up to two columns at once in the analysis. This is especially useful for exploring similarities and differences between texts associated to the same labels and/or metadata.
UNITS The language unit of interest, which can be anything from characters to “words” (whatever their definition may be) and longer sequences. VARIATIONIST seamlessly supports n-grams (i.e., n contiguous language units) and co-occurrences of n units (not necessarily contiguous) that fall within a user-defined window size, with optional duplicate handling. For creating units, we rely on either builtin, publicly available, or user-defined tokenizers (see below). Units may optionally undergo preprocessing with lowercasing and stopword removal. In the latter case, the user can rely on off-the-shelf stopword lists across multiple languages from the stopwords-iso6 package, provide their own lists directly or as files, or combine them.
TOKENIZERS Since the driver for the computation is a language unit, we need ways to segment texts into desired units. VARIATIONIST allows the user to leverage i) a default whitespace tokenizer that goes beyond Latin characters, ii) any tokenizer from Hugging Face Tokenizers (Wolf et al., 2020), or iii) a custom tokenizer. This way we avoid any assumptions on what actually is a language unit, also broaden the applicability of VARIATIONIST to a wide range of language varieties.
VARIABLES Variables are essential components for computing association metrics with language units. While variables in NLP typically translate
6https://github.com/stopwords-iso.
to human-annotated “labels”, those may be naturally generalized to any kind of meta-information associated to textual data (e.g., genres, dates, spatial information, sociodemographic characteristics of annotators or authors). VARIATIONIST natively supports a potentially unlimited number of variable combinations during analysis. Due to the variety of data types and semantic meanings that variables may take, each variable (i.e., column name) is defined through the following two attributes:
• Variable types: the type of the variable for representation purposes. It can be either nominal (i.e., categorical variable without an intrinsic ordering/ranking), ordinal (variable that can be ordered/ranked), quantitative (numerical variable – either discrete or continuous – which may take any value), or coordinate (position of a point on the Earth’s surface, i.e., latitude or longitude);
• Variable semantics: how the variable must be interpreted for visualization purposes. It may be either temporal (e.g., variables such as date or time), spatial (e.g., coordinate variables or nominal variables with spatial semantics such as countries, states, or provinces), or general (any variable that does not fall in the aforementioned categories).
METRICS The methods used for measuring associations between language units and a potentially unlimited combination of variables. VARIATIONIST includes metrics such as pointwise mutual information (PMI; Fano, 1961), its positive, normalized, and weighted variants, as well as their combinations, for a total of 8 different PMI flavors. It also includes a normalized class relevance metric based on Ramponi and Tonelli (2022) in its positive, weighted, and positive weighted versions. Besides unit–variables association metrics, VARIATIONIST also includes lexical diversity measures such as type-token ratio (TTR; Johnson, 1944), root TTR (Guiraud, 1960), log TTR (Herdan, 1960), and Maas’ index (Maas, 1972). Basic statistics such as frequencies, number of texts, number of language units, duplicate instances, average text length, and vocabulary size are also provided. Finally, custom metrics can be easily defined by the user and used for subsequent analysis, therefore extending VARIATIONIST’s capabilities to specific use cases.
CHARTS The visual components of the tool. VARIATIONIST orchestrates the automatic creation
of interactive charts for each metric based on the combination of variable types and semantics from a previous analysis. It defines the optimal dimension or channel (e.g., x, y, color, size, lat, lon, or a dropdown component) for each variable, creating charts with up to five dimensions (of which one is reserved for the quantitative metric score, and the other to the nominal language unit). Possible charts currently include temporal line charts, choropleth maps, geographic and standard scatter plots, heatmaps, binned maps, and bar charts. For each metric, one or more charts are created (e.g., in the case of nominal variable types with spatial semantics, both a bar chart and a geographic scatter plot are created). Charts can be interactively filtered by language unit through a search input field supporting regular expressions or a dropdown menu7 to smoothly explore associations between units and the variables of interest.

heading: 3 Implementation and Usage
text: In this section, we present implementation details (Section 3.1 and Section 3.2) and an example usage of our Python library (Section 3.3).

heading: 3.1 User-facing Classes
text: There are two main elements a typical user interacts with: Inspector and Visualizer, as well as their respective InspectorArgs and VisualizerArgs, which store all of the parameters they work with.
Inspector The Inspector class takes care of orchestrating the analysis, from importing and tokenizing the data to handling variable combinations and importing and calculating the metrics. It returns a dictionary (or a .json file, cf. Section 3.2) with all the calculated metrics for each unit of language, variable, and combination thereof, according to a set of parameters that are set by the user through the InspectorArgs.
InspectorArgs Through the InspectorArgs class we tell Inspector how to carry out the analysis. While we refer the reader to our library and related resources for the full documentation (Appendix A), some of the analysis details that can be set using InspectorArgs include what texts and variable(s) of the data to focus on, whether to use n-grams or n co-occurrences (and if so, for what
7The choice depends on the chart type and its number of dimensions, with the goal of keeping the overall user experience and filtering time as smooth as possible.
values of n), what tokenizer to use, including any custom ones, the selection of metrics we want to calculate, whether and how to bin the variables, and more. In short, any preference regarding the analysis will have to go through InspectorArgs.
Visualizer The Visualizer class takes care of orchestrating the creation of a variety of interactive charts for each metric and variable combination associated to the language units of interest. It leverages the results and metadata from the dictionary (or .json file) resulting from a prior analysis using Inspector, creating charts up to five dimensions using the altair library (VanderPlas et al., 2018).8 It relies on VisualizerArgs, a class storing specific user-defined arguments for visualization.
VisualizerArgs The VisualizerArgs class provides ways to customize the creation of charts and their serialization. In particular, it allows the user to specify whether to pre-filter the visualization based on selected language units (provided as lists) or top-scoring ones (by specifying a maximum per-variable amount), provide a shapefile for setting the background of spatial charts, and decide whether the charts have to be saved as files and in which format, among others.

heading: 3.2 Data Interchange
text: The results of an Inspector analysis are either i) stored in a variable as a dictionary, or ii) serialized in a .json file. While the first case comes handy for direct use by the Visualizer in most cases, the second option is especially useful when dealing with large datasets and a high number of variable combinations (and possible values). Indeed, serialization will enable the results to be easily used for
8Due to the modular design of VARIATIONIST, we aim to integrate additional visualization libraries in future releases.
visualization in a later stage. Details on the structure of the interchange file are in our repository.

heading: 3.3 Example Usage
text: Figure 2 shows a basic usage example of VARIATIONIST, which consists of four steps: i) defining the InspectorArgs, ii) instantiating and running the computation with Inspector, iii) defining the VisualizerArgs, and finally iv) creating interactive charts for the previously specified metrics through the Visualizer. For details on all the available parameters and hands-on tutorials, we refer the reader to our resources (Appendix A).

heading: 4 Case Studies
text: In the following, we scratch the surface of VARIATIONIST’s capabilities by presenting case studies on diverse topics, from computational dialectology (Section 4.1) to human label variation (Section 4.2) and text generation (Section 4.3). Three personas with different backgrounds and aims exemplify our case studies: Alice, Bob, and Carol. We then provide ideas for further applications (Section 4.4). Code for case studies is available in our repository.

heading: 4.1 Exploring Language Variation Across Space
text: Computational dialectology
Alice is a linguist interested in how language varies across space. Specifically, her research focuses on language varieties of Italy and their use in social media. Her goal is to understand in which areas selected lexical items are predominantly used.
Alice uses DIATOPIT (Ramponi and Casula, 2023), a corpus of geolocated social media posts in Italy
focused on local language varieties, and provides it as input to VARIATIONIST. She specifies the text column of the dataset as the textual data and the region column as the variable of interest (setting it with nominal type and spatial semantics). She selects the normalized, positive, and weighted variant of PMI (npw_pmi) as the metric, and chooses unigrams, derived via the default whitespace tokenizer, as the language unit. Lastly, she sets all text characters to lowercase and specifies stopword removal using a default lexicon in Italian, and extends it by providing extra unigrams to remove (i.e., the “user” and “url” placeholders). She then interactively explores the results to understand where the lexical item “ghe” is predominantly used.
As shown in the choropleth map in Figure 3a, the lexical item appears to be mostly used in specific regions in northern Italy, especially those where Venetian, Ligurian, and Lombard varieties are spoken. This is due to its role as an adverb and pronoun in these Romance varieties. However, language varieties of Italy cross administrative borders and multiple varieties are spoken within each region (Ramponi, 2024). By running VARIATIONIST again and specifying the latitude and longitude variables instead (both with coordinate type and spatial semantics), Alice gets a fine-grained picture of the actual use of the word (Figure 3b). Moreover, by defining 30 equally-sized intervals for the latitude and longitude variables, she obtains a binned map (Figure 3c) that allows her to explore the use of “ghe” at an intermediate granularity.
In the future, Alice would like to investigate if the use of certain lexical items underwent change
over time, as a mean to assess the vitality of language varieties. By providing an additional temporal variable, she may answer her question.

heading: 4.2 Investigating Human Subjectivity in Hate Speech Annotation
text: Human label variation
Bob is a computational social scientist interested in how people perceive hateful language online. Specifically, he is interested in understanding whether annotators with different sociodemographic characteristics place greater importance to certain lexical items in determining if a message is hateful.
Bob employs the Measuring Hate Speech (MHS; Sachdeva et al., 2022) corpus for answering his questions. Each post in the dataset is labeled as hate speech or not and includes the demographic attributes of annotators. Bob loads the dataset from Hugging Face Datasets9 and filters it to keep hateful messages only (i.e., hatespeech=2). For facilitating the analysis, he combines boolean columns pertaining to the same variables (e.g., annotator_race_{asian|black|...}) into single string columns (e.g., annotator_race with possible values among {asian|black|...}). Then, he uses VARIATIONIST and specifies text as the column containing the textual data and npw_relevance as the metric for the analysis, he sets the conversion of texts to lowercase to reduce data sparsity and the
9https://huggingface.co/datasets/ ucberkeley-dlab/measuring-hate-speech.
removal of stopwords in English. Bob leaves the remaining parameters with default values (e.g., unigrams as units, whitespace tokenizer). As the variables of interest, he specifies hatespeech and either annotator_sexuality or annotator_race (all with nominal type and general semantics).
When exploring the relationship between annotators’ sexual orientation and the labels they assign to posts, Bob discovers that the lexical item “gay” is more indicative of the hateful class for annotators who identify as straight compared to those who identify as bisexual, gay, or other (Figure 4a). This may indicate that non-straight annotators are more sensible to the nuances in the use of the term and that straight annotators may instead occasionally use it as shortcut for hate speech annotation. Bob gets a similar finding when investigating the association of reclaimed words such as “n*ggas” to hateful posts across self-reported annotators’ race (Figure 4b). The term is less associated to posts labeled as hateful by annotators who identify themselves as black people (in-group members) compared to those annotated as hateful by most out-group members (e.g., asian, native american, white people).
In summary, different lexical items may be (more or less) informative for certain labels (e.g., hate speech) depending on the sociodemographics of annotators. VARIATIONIST can aid in speeding up the exploration of undesired associations across a combination of attributes in language data.
4.3 Analyzing Features of Human versus Generated Texts
Text generation
Carol is an NLP practitioner working on generative large language models (LLMs). She is interested in exploring the differences between texts written by humans and those generated by LLMs in terms of length, lexical diversity, and word use.
Carol uses the Human ChatGPT Comparison Corpus (HC3; Guo et al., 2023), loading it from the
Hugging Face hub.10 HC3 comprises answers written by humans and ChatGPT-generated responses given the same questions across five domains. Through VARIATIONIST, Carol specifies two text columns of interest: human_answers and chatgpt_answers. She sets bigrams as units with lowercase normalization, and specifies stopword removal in English, further adding “url” and numbers from 0 to 9 as extra unigrams to remove. She defines stats, root_ttr, and npw_pmi as metrics in order to analyze different aspects of the texts. The other parameters are left with default values.
By looking at the summary stats, Carol finds that human answers are on average much longer than ChatGPT-generated ones (i.e., 98.26 vs 73.66 units) and that the vocabulary size of human answers is almost two times that of synthetic responses (i.e., 1.60M vs 0.87M). Moreover, humanproduced answers are more varied in terms of root_ttr, also exhibiting a larger standard deviation compared to ChatGPT-generated ones (cf. Figure 5a). Finally, by looking at the top-k (k=20) bigrams associated to human and ChatGPT texts (Figure 5b), Carol finds that human answers appear to include terms that are more commonly used in everyday situations (e.g., “lot people”, “lot money”), while ChatGPT answers tend to include language that is more formal and less conversational, such as “healthcare provider” or “variety factors”. In addition to this, it is clear from the npw_pmi scores that the distribution of bigrams is a bit more balanced for human-authored texts, while ChatGPT appears to produce texts that include very specific bigrams with a much higher frequency. This might be a consequence of the different lexical variety between ChatGPT and human-authored texts.
10https://huggingface.co/datasets/ Hello-SimpleAI/HC3.
As a future exploration, Carol aims to investigate which n co-occurrences of language units appear to be strongly associated to synthetic responses within specific domains (e.g., finance). This can be done by providing the source column of the HC3 dataset as an additional variable to VARIATIONIST.

heading: 4.4 Food for Thought
text: The potential applications of VARIATIONIST are many. For instance, it can be used for advancing research on sociolects such as African-American English (Blodgett et al., 2016), to study linguistic reclamation and more generally investigate semantic change over time, or to conduct qualitative error analyses for model predictions (i.e., to unveil which language units are more informative of a wrong class). Moreover, it can be used to compare tokenizers and their effect on specific language varieties. We leave those areas to the reader as potential avenues for future applications of VARIATIONIST.

heading: 5 Related Work
text: There exist many tools for data exploration in literature, especially in the field of corpus linguistics (see Anthony (2013) for an overview). However, there is currently a lack of a unified tool to serve diverse research communities that goes beyond descriptive statistics and basic charts, and that handles many variables at once in a simple fashion. The closest work to VARIATIONIST is Hugging Face’s Data Measurements Tool (DMT; Luccioni et al., 2021). However, it does not consider multiple texts and variables in the analysis, and it does not provide customization and flexibility in terms of units, metrics, tokenizers, and charts. VARIATIONIST serves to fill this gap in literature.

heading: 6 Conclusion
text: We introduced VARIATIONIST, a modular, customizable, and easy-to-use analysis and visualization tool that aims at helping researchers in understanding language variation and unveiling potential biases in written language corpora across many dimensions. Through the case studies of Alice, Bob, and Carol, we showed the potential of our tool in answering different research questions across disciplines. We hope that our work will also be useful to Dave, a fourth fictional character who unfortunately looks at the data very rarely before using it, to begin to reconsider the pivotal role of exploring data before using it for training language models.
Ethics and Broader Impact Statement
VARIATIONIST serves as a tool to support the research community in better understanding the diversity in language use and unveiling quality issues and harmful biases in textual data. As a result, we do not foresee specific ethical concerns related to our work and, on the contrary, we hope that VARIATIONIST will give additional means to explore datasets and raise awareness among researchers on the paramount importance of looking at the data.
VARIATIONIST has been designed following an inclusion-first approach, i.e., by avoiding common language-specific assumptions to better support its application across many language varieties. As a limitation, we acknowledge that VARIATIONIST is currently limited to the lexical level on written data. We aim to extend its functionalities to also cover other linguistic aspects such as grammar as well as the speech modality in the next releases.

heading: Acknowledgments
text: This work has been funded within the European Union’s ISF program under grant agreement No. 101100539 (PRECRISIS) and by the European Union’s Horizon Europe research and innovation program under grant agreement No. 101070190 (AI4Trust).

heading: B Credits
text: Emojis are from the Google Noto Emoji set (https: //github.com/googlefonts/noto-emoji).

heading: Future Work
text: We leave those areas to the reader as potential avenues for future applications of VARIATIONIST