Elamur Research

Conditional Supervised Contrastive Learning for Fair Text Classification

Paper · 2022 · Jianfeng Chi, William Shand, Yaodong Yu et al.

Summary

A classifier that flags toxic comments can make different kinds of mistakes at different rates depending on which identities the comments mention. It can flag benign comments from one group more frequently or miss toxic comments from another group more often. Jianfeng Chi and colleagues ask whether those disparities can be reduced by changing what a text encoder learns before it makes a prediction. Their criterion is equalized odds. It compares predictions across groups separately for each true label, so that a disparity in flagging benign comments can be examined independently of a disparity in catching toxic ones. The method uses protected-group labels during training. At prediction time, a classifier works from the encoded text.

The authors develop a training method called conditional supervised contrastive learning. It gives the encoder complementary instructions about which texts should be close together in its representation. The first instruction brings texts with the same task label together. The second asks the encoder to recognize an altered version of a text among other texts that share both its task label and its protected group. Group membership gives the encoder no basis for choosing among candidates in that second comparison. The authors use information theory to explain how the objectives relate to the amount of group information in a representation after the task label is known. That connection depends on an assumption about how closely the representations of original and altered texts align.

The experiments cover toxicity detection on Jigsaw and occupation prediction on Bias-in-Bios. Giving more weight to the conditional objective generally lowers the measured equalized odds gap at a cost in F1. The version that trains the encoder first and then fits a classifier with the encoder frozen offers a wider range of tradeoffs than joint training. This two-stage approach and iterative null-space projection are the strongest methods in the comparison. Their tradeoffs are similar on Bias-in-Bios, where the two-stage approach gives more consistent results across runs. On Jigsaw, the relative advantage depends on the F1 region. The authors also find that the fairness improvement persists across several choices of augmentation, temperature, and batch size.

The evidence concerns group disparities under the paper’s evaluation criteria. Both benchmarks use a binary protected attribute, and the biography benchmark assigns gender from pronouns. The study leaves open how well the training procedure would handle intersections of protected attributes, where the examples needed for its conditional comparisons may be scarce.

Deep dive: Conditional Supervised Contrastive Learning for Fair Text Classification

Conditional supervised contrastive learning reduces disparities in text classification by changing which examples an encoder learns to distinguish. · about 38 minutes to read

The problem and its context

What counts as a disparity

The paper studies a form of text classification in which the predicted label matters in different ways to different groups. In comment moderation, a false positive flags a benign comment as toxic. The authors discuss this error as a possible form of unintentional censorship. A false negative lets a toxic comment pass and can expose readers to the kinds of interactions the classifier was intended to catch. A single overall performance score can describe how well a classifier does at the task while leaving open who is more likely to experience each kind of error.

Consider the question of whether comments that mention a particular identity receive more toxicity flags. To interpret the answer, a researcher needs to know which of those comments are labeled toxic. A difference in the rate of flags can reflect unequal treatment of comments with the same true label, differences in the underlying prevalence of the label, or both. Equalized odds moves the comparison inside each true-label category. Among benign comments, the relevant question is how often the classifier raises a false alarm in each group. Among toxic comments, the question is how frequently it correctly detects toxicity in each group. The paper takes this criterion from Equality of Opportunity in Supervised Learning.

The distinction matters because another common fairness criterion, demographic parity, compares the overall rate of positive predictions across groups. Under demographic parity, the desired positive prediction rate is the same even if positive labels have different frequencies in the groups being compared. A perfect classifier reproduces the underlying label frequencies in its predictions, so different base rates can put a perfect classifier outside the demographic parity constraint. Equalized odds permits those base rates to differ. Perfect predictions satisfy its requirement because each group has the same rates within the corresponding true-label categories.

The occupation task gives the same question a different shape. The classifier chooses among professions, and each profession can be treated as the positive class for a group comparison. For a given occupation, the true positive rate concerns biographies whose subjects actually have that occupation. The false positive rate concerns biographies whose subjects have other occupations. A system can recognize members of one protected group more readily for some professions and produce more false assignments for others. The paper builds a multiclass fairness score from the gaps for individual professions, which lets the experiments ask about these differences alongside overall classification performance.

The protected attribute means different things in the two applications. In the toxicity benchmark it identifies a category of identity mention in the comment. The group label concerns what the text mentions and cannot identify who wrote it. In the occupation benchmark the attribute is a binary gender label associated with the subject of the biography. The mathematical question is the same in both settings: given the true task label, does the protected attribute help explain the prediction? The interpretation of the answer depends on what that attribute records.

Why change the representation?

The authors place the problem in a body of work on bias in natural language processing. They point to studies of social bias in word embeddings and sentence encoders, where the object of study is a numerical representation of language. They also describe research on bias in downstream applications such as coreference resolution and machine translation. Their own question concerns differences in classifier behavior across protected groups. An encoder comes into that question because it determines which features of the original text are available to the classifier.

A text encoder represents an input as a vector. A classifier reads that vector and predicts a label. If such a vector carries information about the protected group that remains useful after the true task label has been fixed, a classifier can potentially use that information. The fairness condition can therefore be imposed at the level of the representation. If, within each true label, the representation has the same distribution for the groups in question, applying a classifier to the representation preserves that equality at the output. The authors use this sufficient condition to connect the way the encoder is trained with the way its predictions are evaluated.

Other approaches in the paper interfere with group information in different places. In adversarial training, a discriminator tries to recover the protected attribute, and the encoder is trained to make that prediction harder while still representing the task. Iterative null-space projection learns which directions in an existing representation support group prediction and removes those directions through successive linear projections. Both approaches can be organized around a true task label when the target is equalized odds. They illustrate two possible ways to affect what a classifier can learn about a group: change the representations during their formation, or filter what the encoder has already produced.

Contrastive learning offers another way to direct the formation of representations. Its basic unit is a comparison. An anchor text has examples that should receive relatively high similarity scores and examples that compete with them. Two versions of the same text can form a positive pair. With task labels available, different inputs with the same label can also serve as positives. The authors locate this idea in work on both vision and text. Among the studies they cite are contrastive predictive coding, a framework for visual contrastive learning, and a contrastive approach to sentence embeddings. Representation Learning with Contrastive Predictive Coding · A Simple Framework for Contrastive Learning of Visual Representations · SimCSE

The comparison set determines which information helps solve a contrastive task. If the correct match is the only candidate from the anchor’s group, group membership may help identify it. If all the candidates share the anchor’s group and its task label, those attributes are already held constant. The encoder then needs information that distinguishes an input from other members of that same set. This dependence on the comparison set makes conditional contrastive learning relevant to fairness. It also explains why the authors examine the exact conditioning variables instead of treating contrastive learning as a fairness intervention by itself.

Earlier contrastive work that the paper discusses includes an approach that reduces associations between sentence representations and words associated with bias. Other studies use contrastive objectives to remove sensitive information from representations for classification. The authors describe those classification objectives as principally concerned with demographic parity. They also point to information-theoretic work that uses a bound on mutual information to separate kinds of information in a textual representation. Chi and colleagues bring those threads together around a different target: leakage of group information within a task label.

The training setup gives this target a practical consequence. Protected labels are available for the training examples and can determine how their representations are compared. The classifier does not receive a protected label alongside a new text. A post-processing rule that consults the group of each new input would require an input outside this setup. Learning a differently organized representation lets the authors pursue a change in group-level error rates through the encoder and classifier alone.

The method, step by step

From a labeled text to a comparison batch

Each training example brings together a text, its task label, and its protected attribute. In the biography experiment, for example, the text is a biography, the task label is an occupation, and the protected attribute comes from the benchmark’s gender annotation. The authors take a batch of original examples and add an altered view of each. The altered text inherits the labels of its original. These copies give the encoder a defined match for every source text, in addition to the matches that arise from having the same task label as somebody else in the batch.

How conditional supervised contrastive training uses a batch

The steps in order.

How conditional supervised contrastive training uses a batchStep 1: Collect texts with task labels and protected attributes1. Collect texts with task labels and protected attributesStep 2: Generate an altered view of each text2. Generate an altered view of each textStep 3: Encode the original and altered views3. Encode the original and altered viewsStep 4: Compare each anchor with examples sharing its label4. Compare each anchor with examples sharing its labelStep 5: Match paired views within each label and group5. Match paired views within each label and groupStep 6: Combine the losses to train the encoder6. Combine the losses to train the encoderStep 7: Fit the classifier jointly or with frozen representations7. Fit the classifier jointly or with frozen representations

The augmentation can modify words, insert them, or produce a new rendering through translation. Its role is to supply a different view whose connection to the original is known. The contrastive objective can then use that connection directly. The ordinary supervised objective can also treat the augmented view as another input with the same task label. Both uses rely on the decision to carry the labels across the transformation, which is an experimental design choice about the training pairs.

The experiments encode the texts with bert-base-uncased and use a multilayer perceptron with two layers as the classifier. The paper reports using the Hugging Face implementation and releasing the study’s code in the JFChi/CSCL4FTC repository. The encoder architecture supplies the representation. The method changes the training objective and, in its two-stage variant, when the representation is frozen. BERT

The variables distinguish the original text from its altered view and the task label from the protected attribute. Here is the prediction path for the original.

X —f→ Z —g→ Ŷ

X is a random input text, f is the encoder, Z is its representation, g is the classifier, and Ŷ is the predicted class. Each arrow shows which function acts on the variable before it. The true task label is Y, and the protected attribute is A. In the paper’s notation, lower-case letters such as x, y, and a refer to particular values of these variables. The primed variables X′, Z′, and Ŷ′ refer to the altered input and the results of putting it through the same encoder and classifier.

X′ = t(X),  t ∼ T

X′ is the text produced by applying the transformation t to X. The symbol ∼ means that t is sampled, and T is the set of allowable transformations, with uniform sampling assumed in the theoretical setup. The training procedure defines the match through this transformation. Even when other texts have the same labels, the positive for the conditional comparison is the other view of the same example.

Holding the label fixed

Equalized odds has a compact expression in the paper’s notation.

Ŷ ⊥ A | Y

Ŷ is the prediction, A is the protected attribute, and Y is the true task label. The symbol ⊥ means independence. The bar | indicates that the independence is assessed conditional on Y. In the binary toxicity task, holding Y fixed amounts to making one comparison for benign comments and another for toxic comments. Within either set, the group should give no additional information about the prediction if the criterion is satisfied.

The authors pursue this criterion by targeting conditional independence earlier in the pipeline.

Z ⊥ A | Y

Z is the encoder’s representation, A is the protected attribute, and the notation again requires independence after conditioning on the true label Y. This condition applies to the whole representation. A classifier might satisfy equalized odds even when its input contains unused group information, so the representation condition gives the authors a sufficient training target. When the classifier only receives Z, any equalized odds property that follows from this stronger condition carries through to its prediction.

The paper expresses the connection using conditional mutual information.

I(Ŷ; A | Y) ≤ I(Z; A | Y)

I denotes mutual information, a measure of how much knowing one variable tells us about another. The semicolon separates those variables, and | Y means that the information is considered given the true label. The left side measures remaining information about A in the predicted class Ŷ, and the right side measures remaining information about A in Z. The inequality ≤ follows from data processing in the encoder-to-classifier path. Taking the prediction from the representation cannot add information about the group after the label has been fixed. In particular, if the right side is 0, the prediction satisfies equalized odds.

Conditioning changes which information counts as leakage. Suppose an encoder did nothing beyond representing the true occupation. An observer might still infer something about the benchmark’s protected attribute from the distribution of occupations. After the occupation is given, that representation yields no further help in inferring the attribute. The paper’s target concerns this second test. It permits group information implied by the task label and focuses on what the representation supplies beyond it.

Why the altered view enters the theory

Directly controlling group information in an encoder’s output is the goal. The authors look for terms that also describe a contrastive training problem. They start by assuming that the representation of an altered text retains enough information to make the representation of the original relatively predictable once the task label is known.

H(Z | Z′, Y) ≤ ϵ

H is entropy, which here describes the uncertainty left about Z, the representation of the original. The variables after | are available when assessing that uncertainty, namely the altered representation Z′ and the task label Y. The comma means that both are given. ϵ is the paper’s small positive tolerance, and ≤ sets an upper limit on the remaining uncertainty. In concrete terms, the assumption makes the original and transformed views informative about each other within a task class. It is an assumption on the learned representations, rather than a property established by merely generating a text variant.

The next step compares how much the views tell us about each other under different conditions.

 The absolute difference between \(I(Z; A \mid Y)\) and \(I(Z′; Z \mid Y) - I(Z′; Z \mid A, Y)\) is at most \(\epsilon\).

The first mutual information term measures dependence between the altered and original representations once Y is given. The second measures their dependence once both A and Y are given. The middle term is the information the original representation Z gives about A beyond the label Y. The subtraction signs compare the view dependence under the two sets of conditions. The tolerance ϵ is added or subtracted to give the bounds indicated by ≤.

The proof expands the view-to-view information terms into entropies. The difference contains the desired group-information term and a correction involving uncertainty about Z after Z′ is known. Giving the protected attribute in addition to the augmented representation and label can reduce that uncertainty. When the paper’s alignment assumption holds, there is only a small amount of uncertainty left for the attribute to remove. The correction thus stays within the stated tolerance. This is why the two contrastive objectives can be motivated by a difference of conditional information terms.

The direction of the difference matters. The authors seek to reduce the dependence between views measured given only the task label and increase the dependence measured given both the task label and protected group. The second term is about the information one representation carries about its paired view under those conditions. A larger value there is compatible with encoding meaningful differences among texts inside the group. It does not by itself mean that group membership becomes easier to recover from the representation.

Bringing examples with the same task label together

The first information term is handled through a bound. The authors express it using the probability that a given altered representation would arise conditional on an original representation and its label. The bound asks about plausible pairings within a class, including pairings formed from separate draws.

I(Z′; Z | Y) ≤ −E_{p(y)} E_{p(z′|y)} E_{p(z|y)} [log p(z′|z,y)]

I(Z′; Z | Y) is the dependence between the two representations given the true label. E is expectation, or averaging under the distribution indicated in braces. p(y) is the task-label distribution. p(z′|y) and p(z|y) are the distributions of altered and original representations within class y. The nested expectations use these within-class marginals to draw the two representations separately. The conditional probability p(z′|z,y) evaluates the altered representation when the original representation and class are given. log takes its logarithm, the minus sign negates the average, and ≤ indicates an upper bound.

The appendix proof writes the conditional probability of an altered representation within a class as an average over original representations. Jensen’s inequality then relates the log of that average to the average of the logs. The last step in the stated argument drops an expected log-probability term. For the training interpretation, the authors assume that higher similarity between two within-class representations corresponds to a higher conditional probability of one arising from the other. Encouraging high similarities across the class then serves as a way to pursue a lower bound value on the right-hand side of the inequality, which is itself an upper bound on the information term.

The approach implements this idea with supervised contrastive learning. For a given anchor, every other item with the anchor’s task label is a positive, including the anchor’s augmented counterpart. The pool used to normalize the score contains all the other views in the batch. The membership of the protected group need not be checked for this part. Examples with a different label compete in the normalization, so the objective also favors separation between classes.

ℓᵢⱼ = exp(f(xᵢ) · f(xⱼ) / τ) / ∑ₖ₌₁²ᴺ 𝟙{i ≠ k} exp(f(xᵢ) · f(xₖ) / τ)

ℓᵢⱼ is the normalized score for candidate j when view i is the anchor. xᵢ, xⱼ, and xₖ are the texts at the indicated batch positions, and f produces each representation. The dot · is the vector dot product. The function exp exponentiates its argument. The parameter τ, called temperature, scales the dot products before exponentiation. The symbol ∑ adds the terms for candidate indices k from 1 through 2N, where N is the number of originals and 2N counts the originals and altered views together. The indicator 𝟙{i ≠ k} is active for candidates other than the anchor. The slash divides the pair’s score by the total score over those candidates.

Temperature affects the competition among candidates. With a smaller temperature, a difference in dot products creates a larger difference after scaling and exponentiation. Candidates with the highest scores can then take up more of the normalized score. Changing the temperature can therefore change the effect of a hard comparison even when the examples in the batch stay the same. The authors examine temperature experimentally because the training objective depends on these relative scores.

Lₛᵤₚ = −∑ᵢ₌₁²ᴺ [1 / (Nᵧᵢ − 1)] ∑ⱼ₌₁²ᴺ 𝟙{i ≠ j, yᵢ = yⱼ} log(ℓᵢⱼ)

Lₛᵤₚ is the supervised contrastive loss. The outer sum runs over anchor views i in the batch, and the inner sum considers candidate views j. yᵢ and yⱼ are their task labels. The indicator keeps candidates with the same label and excludes the anchor. Nᵧᵢ counts all views with the anchor’s label, including the anchor, so Nᵧᵢ − 1 is the number of eligible positives. The leading fraction averages their log normalized scores log(ℓᵢⱼ). The minus sign makes lower loss correspond to assigning higher scores to those positives.

A useful distinction is that the probability in the theoretical bound and the normalized similarity in the batch loss play different roles. The former describes how a view is distributed under the paper’s assumptions. The latter is a score computed from a finite set of encoded examples. The authors use the supervised loss because it encourages the kind of within-label similarity suggested by the bound. The loss is therefore a practical approximation to the theoretical direction of improvement.

Matching views inside a label and group

The second objective changes both the positive set and the candidates against which the positive is scored. Every candidate has the anchor’s task label and protected attribute. The goal is to select the alternate view of the anchor itself from this set. Other texts with the same labels now compete with the true paired view. Thus, for some pairs that the ordinary supervised objective draws together, the conditional objective asks the encoder to preserve the distinctions needed to recognize individual inputs.

The paper’s theoretical construction is a conditional version of InfoNCE, a contrastive objective that scores a paired sample relative to a set of candidates. In this case the construction begins with a task label and protected attribute, then draws pairs under those conditions. For a fixed scoring function, its score at an anchor can be written as follows.

C(s) = E_{p(a,y)} E_{p(zᵢ′,zᵢ|a,y)⊗ᴺ} [log(exp(s(zᵢ′,zᵢ)) / ((1/N) ∑ⱼ₌₁ᴺ exp(s(zᵢ′,zⱼ))))]

C(s) names the conditional contrastive score for the similarity function s. The expectation E_{p(a,y)} averages over protected attributes a and task labels y drawn from their joint distribution. The next expectation refers to N independent example pairs under the selected condition, with ⊗ᴺ denoting repeated independent draws as specified for the objective. The prime in zᵢ′ marks the altered representation for anchor pair i. The numerator scores that altered representation against its matched original representation zᵢ. The denominator takes the mean, indicated by 1/N, of the exponentiated scores against candidates with original representations zⱼ. The index j runs over the candidate set, and the logarithm measures the matched score relative to that mean.

supₛ C(s) ≤ I(Z′; Z | A, Y)

supₛ is the supremum, or least upper bound of the scores attainable over choices of s. The paper calls the optimized expression on the left CS-InfoNCE. The term on the right is the mutual information between the altered and original representations when the group A and label Y are both given. The symbol ≤ marks CS-InfoNCE as a lower bound on that conditional information. The idea is to reward a score that distinguishes a genuinely paired view from alternatives that share the conditioning variables.

The appendix connects this bound to Kullback–Leibler divergence, a measure of discrepancy between probability distributions. It compares a joint distribution of paired views with a distribution that retains the label and group but pairs representations from their separate conditional marginals. The divergence recovers conditional mutual information when those conditioning variables are included in both distributions.

I(Z′; Z | A, Y) = Dₖₗ(P_{Z′,Z,A,Y} ∥ P_{A,Y} P_{Z′|A,Y} P_{Z|A,Y})

Dₖₗ denotes Kullback–Leibler divergence, and ∥ separates the distribution being compared from the reference distribution. P_{Z′,Z,A,Y} is the joint probability law of both representations, the attribute, and the task label. The product on the right first draws A and Y from P_{A,Y}, then draws the views independently from their respective conditional laws, P_{Z′|A,Y} and P_{Z|A,Y}. This construction removes the pair-specific connection while retaining what the two views have in common through the conditioning variables. The appendix uses variational expressions for the divergence and a contrastive bound based on scores of matched and competing pairs.

The implemented loss uses groups and labels already present in the augmented training batch. Its candidate set is defined separately for each anchor. An anchor’s alternate view is available because every original is paired with an augmentation, and both views carry the same labels.

ℓᵢ = exp(f(xᵢ) · f(xᵢ′) / τ) / ∑ₖ₌₁²ᴺ 𝟙{i ≠ k, aᵢ = aₖ, yᵢ = yₖ} exp(f(xᵢ) · f(xₖ) / τ)

ℓᵢ is the normalized score for the correct alternate view xᵢ′ of anchor xᵢ. The same encoder f, dot product ·, and temperature τ determine similarity. The denominator sums exponentiated scores over batch positions k from 1 to 2N. The indicator checks three conditions: the candidate has an index different from i, its protected attribute aₖ matches aᵢ, and its label yₖ matches yᵢ. The matched view can contribute to the denominator as well as the numerator. The other eligible views provide the competing examples.

L꜀ₛ = −∑ᵢ₌₁²ᴺ log(ℓᵢ) / (Nₐᵢ,ᵧᵢ − 1)

L꜀ₛ denotes the paper’s conditional supervised InfoNCE loss. The sum is over the 2N anchor views, with the displayed division applied to each anchor’s term. ℓᵢ is the score of its matched view relative to its eligible candidates, and log is the logarithm. Nₐᵢ,ᵧᵢ counts all views with the anchor’s protected attribute aᵢ and its label yᵢ. Subtracting 1 leaves the number other than the anchor. The minus sign turns a higher score for the match into a lower contribution to the loss.

The pair of objectives creates a specific pressure on the geometry of the representation. The ordinary supervised term rewards similarity across the class, including across groups. The conditional term asks the encoder to distinguish different inputs that have the same class and belong to the same group. Under the combined objective, forming a compact cluster for a protected group within a class can make it harder to retrieve the correct paired view. The authors interpret this interaction as encouraging examples from different groups to mix within classes while preserving the relationships between paired views. The conditional term acts through the restricted comparisons. It does not contain a direct target for the distance between the groups’ average representations.

When the classifier learns

Both implementations use the same contrastive terms. In the two-stage implementation, the authors first train the encoder with the contrastive objective.

Lₜ𝑤ₒ = Lₛᵤₚ + λ · L꜀ₛ

Lₜ𝑤ₒ is the encoder training objective for the two-stage procedure. Lₛᵤₚ is the ordinary supervised contrastive loss, L꜀ₛ is the conditional supervised InfoNCE loss, and λ is a non-negative weight. Here · denotes scalar multiplication. Raising λ makes the conditional term more influential relative to the supervised term. After this stage, the authors freeze the encoder and fit the classifier with cross-entropy, which penalizes low predicted probability for the known task label. The frozen representation means that classifier fitting can adjust the prediction rule without reshaping the encoder’s output.

The single-stage procedure trains the classifier and the encoder together. Cross-entropy can now change the representation during the same training process as the contrastive objectives.

Lₒₙₑ = (1 − γ) · L꜀ₑ + γ · Lₛᵤₚ + λ · L꜀ₛ

Lₒₙₑ is the combined loss for joint training, and L꜀ₑ is the cross-entropy loss. The coefficient γ is in [0, 1] and governs how much weight the ordinary supervised contrastive term receives relative to cross-entropy. The factor 1 − γ gives the complementary weight to cross-entropy. The non-negative weight λ again controls the conditional term. The signs + add the contributions, and · multiplies each loss by its coefficient. Cross-entropy supplies task-prediction supervision, while the two contrastive terms constrain how the encoder arranges examples.

This distinction puts fine-tuning at different points in the procedure. In the two-stage case, there is an encoder training phase followed by classification on fixed features. In the single-stage case, the classification task participates in shaping those features throughout joint optimization. Both procedures learn a classifier that consumes the representation without requiring a protected attribute at prediction time. The experiments use the same general encoder and classifier architecture so that the comparison can focus on the consequences of changing the training scheme.

Augmentations and practical training

The experiments compare a collection of ways to produce a paired view. The first is easy data augmentation, or EDA, which applies simple word-level changes. The authors use synonym replacement, insertion, swapping, and deletion, with an augmentation ratio of 0.1. They generate four augmented examples per input for this strategy. The contrastive batch construction uses a paired altered view. The wider collection of variants supplies possible forms of that view. EDA

Back translation changes the input by translating it into another language and then back into English. The paper names wmt19-en-de for this experiment. The comparison also includes contextual word substitution and contextual word insertion. Those strategies use RoBERTa-base to select changes with information from surrounding words. Both contextual strategies use an augmentation rate of 0.1. Together these choices let the authors examine whether the fairness result survives substantially different ways of constructing the paired text. Contextual Augmentation

Batch size has a particular role under the conditional objective. When more examples are available, an anchor has more opportunities to encounter other texts with its task label and protected attribute. Which cases become useful negatives still depends on the batch’s composition. The authors use a gradient cache to accommodate large contrastive batches under memory constraints. This lets the batch-size experiment vary the size of the comparison pool while retaining the same form of loss.

Experiments and results

The two prediction tasks

Jigsaw provides online comments with annotated toxicity scores and identity labels. The authors turn the toxicity score into a binary label using a threshold of 0.5. The positive class consists of comments scored at or above the threshold. For the protected attribute they use the race or ethnicity annotations, dividing the selected comments according to Black or non-Black identity labels. The categories describe the annotation of the comment’s content. That is the population over which the reported group rates are compared.

The selected Jigsaw data contain 42,906 comments. The training split has 25,954, the validation split has 4,390, and the test split has 12,562. Within the training split, 38.1% of comments fall in the Black identity category and 61.9% in the non-Black category. The corresponding test proportions are 38.8% and 61.2%. The split-level averages of the binary task label are 0.2822 for training, 0.2897 for validation, and 0.2873 for test. These are averages across all examples in each split. The fairness comparison uses prediction rates within true-label and protected-group subsets.

Bias-in-Bios consists of biographies collected from Common Crawl and classified into 28 professions. The benchmark derives a binary gender attribute from gendered pronouns and scrubs names and pronouns from the text used in the task. The experiment asks the classifier to recover the occupation from what remains. The group labels are still available to form the comparisons used in training and to evaluate group-level errors.

The biography corpus used in the experiment has 393,423 examples. The training split has 255,710, the validation split has 39,369, and the test split has 98,344. The proportions with the female label are 46.0% in training, 47.8% in validation, and 46.5% in test. These are proportions for whole splits. Since conditional training compares biographies inside a particular occupation and group, the supply of competing examples depends on the composition of those smaller sets.

The tasks give the method different tests. Jigsaw has a binary task label, so each group contributes rates for catching toxic comments and for flagging benign ones. Bias-in-Bios has several classes from which the classifier must choose a single occupation. Its fairness score gathers disparities over those class-specific decisions. A training response that appears in both datasets is consequently observed under different definitions of the prediction task and of the group attribute.

What gets measured

The paper reports F1 for classification performance. F1 combines precision and recall, balancing the correctness of predicted positives with the ability to recover actual positives. A higher F1 indicates stronger performance on that combined measure. The fairness metric uses separate true positive and false positive rates, each evaluated relative to the overall rate.

Δₜₚᵣ = ∑ₐ |TPRₐ − TPRₒᵥₑᵣₐₗₗ|

Δₜₚᵣ is the true positive equality difference. TPRₐ is the fraction of actually positive examples in protected group a predicted to be positive, and TPRₒᵥₑᵣₐₗₗ is the corresponding rate across examples used for the overall comparison. The subtraction gives the deviation, and the absolute-value bars retain its magnitude. The sum ∑ₐ adds that magnitude over the protected groups.

Δ𝒻ₚᵣ = ∑ₐ |FPRₐ − FPRₒᵥₑᵣₐₗₗ|

Δ𝒻ₚᵣ is the false positive equality difference. FPRₐ is the fraction of actually negative examples in group a predicted to be positive. FPRₒᵥₑᵣₐₗₗ is the overall false positive rate. The absolute-value bars again retain the magnitude of the deviation, and the sum adds the deviations over groups. In Jigsaw this component concerns benign comments that the classifier marks as toxic.

Δₑₒ = Δₜₚᵣ + Δ𝒻ₚᵣ

Δₑₒ is the equalized odds gap. The plus sign adds the deviations for the two kinds of rates. A lower gap means smaller disparities as measured by this sum. When the group rates all coincide with their corresponding overall rates, both components are 0.

Δₑₒ = ∑ᵧ Δₑₒʸ

For the multiclass task, y is a profession and Δₑₒʸ is the equalized odds gap with that profession treated as the positive class. The sum ∑ᵧ adds the resulting gaps across professions to obtain the aggregate Δₑₒ. This gives a benchmark-wide score for comparing training choices under the same evaluation protocol. Its value reflects both the individual class disparities and the number of classes over which the metric is summed.

A reduced gap can accompany several changes in the underlying error rates. Two groups can become more similar because a group with better detection loses some of its advantage, because a group with poorer detection improves, or through a combination of changes. Similarly, a smaller difference in false positive rates speaks to their alignment and by itself leaves open what levels the rates reach. The study therefore reports F1 alongside the gap and compares settings by the combinations they attain. It runs each experiment with five different random seeds and summarizes the results using the mean and standard deviation of each metric.

Which training procedures are compared

Training with cross-entropy provides the reference for a system trained to predict the task labels without either contrastive term. For the adversarial baseline, the encoder also encounters a discriminator trained to recover the protected attribute from its outputs. The original form of adversarial removal aims to suppress group information without conditioning on task labels. In this evaluation the authors use conditional adversarial training so that the discriminator addresses the type of information relevant to equalized odds.

Diverse adversarial training uses an ensemble of three discriminators. A difference loss encourages the discriminators to use orthogonal representations, giving them room to respond to different directions of group information. The authors search the difference-loss weight over {0, 100, 1000, 5000} and vary a separate weight that controls the adversarial influence. The experiment uses a difference-loss weight of 100 on Jigsaw and 5000 on Bias-in-Bios. These are settings for the corresponding diverse-adversary comparisons. Ordinary adversarial training uses a single discriminator and the same general conditional approach.

Iterative null-space projection, or INLP, begins from an already trained text encoder. In the main comparison the authors train that encoder using cross-entropy and choose its checkpoint with the validation set. They take the weights from support vector machines trained to predict the protected attribute and use successive null-space projections to remove the directions those classifiers use. To align the procedure with equalized odds, a group classifier in each round is trained with data from the same task class. The authors vary the number of projection rounds to control the extent of the intervention. A classifier is then fitted over the guarded representation. Null It Out

This comparison puts encoder training and representation filtering on the same pair of evaluation measures. The contrastive methods and the adversarial baselines directly shape the encoder. INLP takes the encoder as a starting point and changes its output before classification. The availability of that starting point becomes important in the later checkpoint analysis. In the main experiment, the selected encoder gives INLP a chance to show what it can do under a favorable training choice.

For the contrastive runs, the temperature search covers {0.1, 0.5, 1.0, 2.0}, and the search over contrastive batch sizes covers {32, 64, 128, 256}. Both implementations search among EDA, back translation, contextual insertion, and contextual substitution. The one-stage implementation searches γ over {0.1, 0.3, 0.7, 0.9}. The authors first use this search to choose settings for classification performance. They then vary the conditional weight λ to trace a performance and fairness tradeoff.

For two-stage encoder training, the epoch limits are 15 for Jigsaw and 25 for Bias-in-Bios. The authors stop this phase early after three consecutive epochs without improvement on the validation set. The additional fine-tuning settings include a batch size of 32 and a learning rate of 2e-5 with Adam for both datasets. The listed epoch settings for this part of training are 10 on Jigsaw and 7 on Bias-in-Bios.

What the trade-off curves show

The first comparison asks what happens when the researchers put more weight on conditional matching. As λ rises, the equalized odds gap generally falls and F1 generally declines. The two-stage procedure moves farther along the fairness dimension over the same range of weights. Its F1 scores are generally comparable to, or better than, those of the one-stage procedure along this comparison. The flexibility the authors report thus concerns the range of attainable performance and fairness combinations. The result gives λ an empirical role beyond its definition as a coefficient in the loss.

The baseline comparison identifies two-stage contrastive learning and INLP as the strongest methods overall. On Bias-in-Bios, they reach similar tradeoffs. The two-stage method shows less variation across runs. The adversarial approaches generally perform worse and vary more, especially on this benchmark. The paper’s evidence for this ranking comes from comparing the methods across their own tradeoff settings, so the result describes the trajectories they can achieve under the experimental search.

On Jigsaw, two-stage contrastive learning reaches the highest classification performance in the authors’ comparison and covers a broad range of tradeoffs. Around an F1 of 0.58, the two-stage runs are more consistent and show a lower equalized odds gap. INLP has the better tradeoff in the F1 region the paper gives as 0.62∼0.64. The chart marks those reported operating regions on the F1 axis. Its entries are an approximate location and range endpoints, rather than exact F1 scores attached to a particular hyper-parameter or a common fairness gap.

Reported Jigsaw F1 regions for two-stage contrastive learning and INLP

The relative fairness advantage changes across the F1 range.

Reported Jigsaw F1 regions for two-stage contrastive learning and INLPTwo-stage contrastive learning, approximate region with lower gap (this paper): 0.58Two-stage contrastive learning,approximate region with lower gap (thispaper)0.58INLP, lower endpoint of favorable region: 0.62INLP, lower endpoint of favorable region0.62INLP, upper endpoint of favorable region: 0.64INLP, upper endpoint of favorable region0.64
The numbers
System or settingF1
Two-stage contrastive learning, approximate region with lower gap (this paper)0.58
INLP, lower endpoint of favorable region0.62
INLP, upper endpoint of favorable region0.64

The Jigsaw result supports a comparison at particular performance levels. Around the lower F1 region described by the authors, two-stage training combines a smaller group gap with greater consistency. In the higher range cited for INLP, the projection baseline attains a better balance. Looking at the methods at a particular operating point is therefore more informative than treating the entire tradeoff curve as a single ranking. The paper’s claim for two-stage learning rests on the range it reaches and its consistency, alongside its performance in the regions where it has a fairness advantage.

The training procedures also differ in what is attached to the encoder. Adversarial training requires discriminators while the competing objectives are being optimized. INLP introduces a projection between the encoder and classifier. The contrastive method uses pair comparisons in its loss and leaves inference with the encoder followed by the classifier. That architectural property is independent of the F1 or fairness ranking. Its relevance is that the change can be made through training in the encoder-and-classifier setup the paper studies.

What the ablations show

The contribution of the conditional term

The closest comparison to a component ablation comes from setting λ to zero and then giving the conditional term a positive weight. In the two-stage procedure, zero weight leaves ordinary supervised contrastive training for the encoder. In joint training it leaves cross-entropy and ordinary supervised contrastive learning. Accordingly, a difference observed as λ changes compares procedures that retain their task supervision and differ in how strongly they demand identification of the paired view within a label and group.

The change in the fairness gap under this comparison is evidence that the extra term contributes to the measured tradeoff. In particular, the common direction of smaller gaps as its weight grows fits the authors’ explanation that ordinary same-label alignment can leave protected-group structure inside the class. The corresponding decline in F1 also matters for interpreting the mechanism. Altering the within-class geometry affects what can be recovered for prediction. The result is a controllable shift in the two measured outcomes, with the width of that shift depending on how the encoder and classifier are trained.

Comparing the training schedules reveals that the conditional objective has a larger practical effect when the encoder is trained contrastively and then frozen. The one-stage objective has the task prediction loss updating the encoder jointly with both contrastive terms. The two-stage objective allows the contrastive losses to set up the representation before the classifier is fitted. This is a comparison of complete training schedules, including the placement of cross-entropy and the freezing decision. It establishes how those schedules behave together and leaves the individual contribution of each scheduling choice unresolved.

Temperature, batch size, and text variants

The authors focus their sensitivity analysis on two-stage learning after its stronger tradeoff in the main comparison. On Bias-in-Bios they contrast settings with λ values of 0.0 and 5.0. They vary temperature, contrastive batch size, and how the paired texts are generated. Across the tested choices, the positive conditional weight produces a smaller equalized odds gap, while F1 remains relatively high in the authors’ comparison. This result matters because every one of those settings changes the task seen by the contrastive loss. Temperature changes the emphasis on high-scoring pairs. Batch size changes which texts can compete. Augmentation changes the evidence that connects a view to its source.

The appendix gives a corresponding Jigsaw sensitivity analysis at 0.0 and 2.0 for λ. The choice of positive weight differs from the biography experiment, so these comparisons address persistence under changes to the training setup for each benchmark. They do not measure the effect of transplanting a chosen weight between the benchmarks. The authors interpret the patterns as evidence that the two-stage result is stable across the ranges tested.

A comparison across augmentations has a narrower meaning than a test of the theoretical alignment assumption. An augmentation can produce a recognizably related text, and a training objective can perform well with it, while still leaving uncertainty about the original representation given the altered representation and label. The sensitivity experiments examine predictions and fairness gaps after training. They show that the observed effect is sustained by several ways of making text pairs. They leave the conditional entropy in the theoretical argument unmeasured.

What the representation pictures contribute

The paper visualizes the biography embeddings with t-SNE. The visualization assigns a marker to each task class and a color to each protected group. Both cross-entropy training and ordinary supervised contrastive training produce clusters associated with class. In those displays, examples of the same protected group can also gather into smaller clusters within a class. A representation can thus show clear occupation structure while retaining a visible association with the protected attribute inside the occupation.

With the conditional term added, the authors observe more mixing of group colors within the class clusters. This fits the two-loss interpretation. The supervised term rewards class alignment, while the conditional term makes the paired view compete against other same-group texts. A group-specific cluster alone offers little help in solving that latter comparison. The paper uses the visualization to connect the observed behavior to the training objective. Since t-SNE depicts the embeddings in a reduced space, the figure provides qualitative evidence about the arrangement and the measured gaps supply the separate evaluation of predictions.

The display is also a way to see why ordinary supervised contrastive learning can help with one objective and leave work for the other. Markers grouping together indicate that the representations support the main task. Colors forming subclusters indicate that task alignment can coexist with remaining group structure. The conditional objective is aimed at the organization within a class. Its intended effect is therefore more specific than making classes easier to tell apart.

Why the projection baseline depends on its encoder

The authors hold the INLP tradeoff parameter fixed in comparisons that change the encoder supplied to it. They examine the cross-entropy checkpoint with the best validation loss, the final checkpoint from cross-entropy training, an encoder trained with ordinary supervised contrastive loss, and the original bert-base-uncased parameters without task-specific encoder training. The resulting performance and fairness differ substantially on both datasets even at matching settings of the projection parameter.

The final cross-entropy checkpoint provides little bias mitigation in the reported comparison, even though it comes from training with the same objective as the validation-selected checkpoint. Starting from the original BERT parameters leads to a steep decline in classification performance as more projection iterations are used. Training the encoder with supervised contrastive loss also gives an unfavorable starting point in the authors’ tests. The main baseline results use the stronger checkpoint configuration the researchers obtained.

This analysis matters because a projection can only work with the directions present in its input representation. Changing a checkpoint changes which distinctions the available directions capture and how those distinctions overlap with group prediction. The empirical sensitivity explains why the paper reports competitive INLP results in the main experiment and a wider range of outcomes in its additional tests. It also clarifies the comparison with two-stage contrastive learning. The contrastive method’s sensitivity study changes the configuration of a procedure that learns the encoder itself, while the INLP study changes the representation on which a separate procedure operates.

Limitations

Limits identified by the authors

The authors test binary protected attributes. They draw particular attention to the biography corpus, where an attribute derived from pronoun usage is mapped to female and male categories. This mapping leaves people outside those categories unrepresented in the gender analysis. The reported occupation results concern the dataset’s binary annotation and the disparities measured under it. More inclusive group definitions would require data and comparisons that the study does not supply.

Intersectional groups are an extension the authors propose. Their theoretical argument can condition on a protected attribute with more complex categories. The training procedure then faces a sampling problem. It needs different examples that share an anchor’s task label and protected group. With several attributes combined, some label-and-group combinations can occur too rarely for this comparison to supply many negatives. In a batch dominated by the paired views from a single input in such a combination, the contrastive match is trivial and yields little information about distinguishing different inputs.

The authors suggest that a memory bank might supply negative examples for sparsely represented groups. A memory bank would make additional examples available beyond the current batch. They leave this possibility for future work, so the study supplies neither a test of that approach nor evidence that it resolves the sampling difficulty. The distinction between the formal conditioning argument and the empirical supply of examples is central to this limit. A condition can be straightforward to express and difficult to populate with meaningful comparisons.

In their ethics statement, the authors acknowledge the scope of equalized odds. It concerns a pattern of errors across groups conditioned on the task labels. Individual fairness, which concerns the treatment of individual cases, falls outside that evaluation. The paper describes reducing unintended censorship and reducing exposure to toxic comments as possible benefits of mitigation. Its experiments measure task performance and group gaps on benchmarks. Those measurements establish how the tested classifiers behave against the annotations used in the experiments.

Limits visible in the evaluation

Equalized odds treats the observed task labels as the basis for separating correct classifications from mistakes. On Jigsaw, a threshold applied to the annotated toxicity rating establishes that label. Equalizing errors under this procedure gives evidence about agreement with those annotations across the identity-mention groups. The experiment does not independently establish a standard for judging toxicity, and it does not observe who is actually censored or how moderation decisions affect their participation. The use of identity mentions as the protected attribute further fixes the population to which the comparison applies.

The aggregate gap also leaves some details unresolved. It adds deviations in true positive and false positive rates, and the biography version adds class-level gaps. A decline tells us that the combined discrepancy fell. It can occur alongside different trajectories for individual groups or occupations. The overall F1 score gives a check on aggregate task performance while leaving open which classes or groups account for the change. Comparing fairer operating points in detail would require those component rates and the context in which the different errors matter.

This aggregation makes the strongest comparisons the ones made within each benchmark. The Bias-in-Bios gap sums over occupations, whereas Jigsaw uses a binary task. A comparison of the raw gap magnitudes across those datasets would mix the behavior of the classifiers with the way the scores are constructed. The experiments establish the tradeoffs among methods evaluated under the same rules for each dataset.

The use of group labels during training is another boundary of the setup. The conditional loss uses the labels to select its comparison candidates, so its training procedure depends on access to both annotations for each example. In the reported experiments the augmented copy receives the annotations of its source text as well. Alterations can affect language that contributes to an occupation or toxicity label, or language associated with an identity mention. The paper compares augmentation strategies through the results they produce under inherited labels. It does not report a separate validation of label preservation for the generated views.

The stability results are likewise tied to the tested choices. They give evidence across the selected batch sizes, temperatures, and augmentation strategies, with different positive conditional weights in the two sensitivity studies. The work uses a particular text encoder and classifier design. It does not establish that the same response holds with a different architecture, a different protected attribute, or a new distribution of texts. The reported standard deviations describe variation across the runs in the experiment. They do not measure all the forms of uncertainty that would arise when transferring the approach to a different application.

What the theory establishes about the trained system

The sufficient condition for equalized odds is exact conditional independence of the representation and the protected attribute. The information-theoretic argument relates an amount of leakage to view dependence under its alignment assumption. The experiments apply finite-batch similarity losses inspired by bounds on those quantities, then measure prediction gaps. A lower observed gap is direct evidence about the predictions on the benchmark. It does not establish a numerical value for the information the entire representation still carries about the group.

There are several steps in that distinction. The upper bound involves conditional probabilities, while the implementation uses exponentiated similarities. The lower bound is stated for a contrastive sampling construction, while the implemented loss uses the eligible views found in a batch. Optimizing a surrogate can improve the empirical behavior that motivated it even when the underlying bound is loose. The paper does not estimate the tightness of these bounds for its trained encoders or verify the small-entropy assumption directly. Its empirical claim is therefore mitigation under an evaluated group criterion, with the theory explaining why the training comparisons are plausible choices.

The experiment also evaluates a classifier fitted for each representation. Exact independence would transfer to any prediction derived only from the representation, by the data-processing argument. A smaller gap for the particular fitted classifier is a weaker observation. Another classifier could in principle use information present in the representation that the fitted classifier ignores. The gap curves and embedding visualizations show what happened in the tested pipeline. They leave open how much group information a different downstream procedure could recover.

Finally, the tradeoff itself is part of the result. Stronger conditional training generally brought the group rates closer together and lowered the classification score. A reduction in disparity is meaningful for the criterion the authors chose. The most suitable point on the curve would depend on the consequences of false positives and false negatives for the application. This paper measures the range of outcomes available from the methods it compares and does not resolve that application-specific choice.

What came after

The later citing work is rematchka at ArAIEval Shared Task. It studies prefix-tuning and prompt-tuning for detecting propaganda and disinformation in Arabic social media content. It shares the broader setting of classification for social media, while its stated task concerns different labels and its named methods concern how to adapt a system for those labels. rematchka at ArAIEval Shared Task

The citation establishes a connection between the papers. The available account of rematchka identifies its tasks and tuning methods, but gives no methodological detail about its use of Chi and colleagues’ work. Whether it adopted conditional contrastive training, used equalized odds for evaluation, or cited the paper as background remains unspecified.

Cite

Cite as Jianfeng Chi, William Shand, Yaodong Yu, Kai-Wei Chang, Han Zhao and Yuan Tian. 2022. Conditional Supervised Contrastive Learning for Fair Text Classification. Findings of the Association for Computational Linguistics: EMNLP 2022.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2022.findings-emnlp.199

@inproceedings{chi2022conditional,
  title = {{Conditional Supervised Contrastive Learning for Fair Text Classification}},
  author = {Jianfeng Chi, William Shand, Yaodong Yu, Kai-Wei Chang, Han Zhao and Yuan Tian},
  booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2022},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.199},
  url = {https://doi.org/10.18653/v1/2022.findings-emnlp.199}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/chi-2022-conditional-supervised-contrastive-learning-fair/