P air CFR : Enhancing Model Training on Paired Counterfactually Augmented Data through Contrastive Learning (2024)

Abstract: Counterfactually Augmented Data (CAD) involves creating new data samples by applying minimal yet sufficient modifications to flip the label of existing data samples to other classes. Training with CAD enhances model robustness against spurious features that happen to correlate with labels by spreading the casual relationships across different classes. Yet, recent research reveals that training with CAD may lead models to overly focus on modified features while ignoring other important contextual information, inadvertently introducing biases that may impair performance on out-of-distribution (OOD) datasets. To mitigate this issue, we employ contrastive learning to promote global feature alignment in addition to learning counterfactual clues. We theoretically prove that contrastive loss can encourage models to leverage a broader range of features beyond those modified ones. Comprehensive experiments on two human-edited CAD datasets demonstrate that our proposed method outperforms the state-of-the-art on OOD datasets.

## introduction in the field of natural language processing (nlp), a significant body of research @xcite @xcite has raised the concern that deep learning models can overfit spurious correlations, such as dataset-specific artifacts and biases, rather than focusing on the more complex, generalizable task-related features. for example, @xcite and @xcite demonstrate that classifiers trained exclusively on hypotheses can still achieve decent results on some natural language inference (nli) datasets, which ideally requires comparing hypotheses with premises to determine the labels. the existence of biases or shortcuts in training datasets can severely degrade the performance of deep learning models on outof-distribution (ood) datasets. counterfactually augmented data (cad) has emerged as a promising approach to mitigate this issue by making minimal modifications to existing data samples such that the corresponding labels are switched to other classes @xcite @xcite . this technique aims to establish direct causal relationships for models to learn more effectively and enhance generalization across different datasets @xcite . however, the effectiveness of cad is not always guaranteed, particularly when both contexts and the modified information should be considered together to make predictions @xcite . for instance, in sentiment analysis, simply replacing positive adjectives such as "good" or "excellent" with negative counterparts like "terrible" or "bad" will potentially risk models to overemphasize these changes and even assign zero weights to the broader unmodified context @xcite . consequently, the trained models may fail to understand more nuanced expressions like irony or negation, exemplified by sentences such as "is it a good movie ????" or "this movie is not that good." to solve the above risks of cad training, an intuitive solution is to increase the diversity of counterfactual samples @xcite , thereby disentangling the suspicious correlations between edited features and labels. nonetheless, this kind of method often relies on human knowledge to steer the diversification, bearing high expenditure and time consumption @xcite . others try to design additional constraints to align the model gradient with the straight line between the counterfactual example and the original input @xcite , or to minimize the invariant risk @xcite , but these attempts fail to exploit the complex effects of augmented feature components. in this paper, we introduce a simple yet effective learning strategy to mitigate the overfitting problem associated with cad. inspired by the recent success of contrastive learning (cl) in feature alignment @xcite @xcite and its strengths in capturing global relationships @xcite , we propose to employ a contrastive learning objective to complement the standard cross-entropy (ce) loss. while cl compels the model to extract complementary effects among counterfactually augmented data to alleviate the feature degeneration, ce ensures the induced feature representations are effectively used for classification. our mathematical proof further corroborates the advantage of combining the two losses in training models on cad, resulting in enhanced generation capability. in summary, our contributions are as follows: counterfactually augmented data. counterfactual examples (cfes) suggest the minimal modifications required in an input instance to elicit a different outcome @xcite . this property has inspired researchers @xcite to adopt cfes as a meaningful data augmentation in nlp, aiming to mitigate spurious correlations and improve causal learning. early efforts @xcite involved creating cad datasets with manual sentence edits for label reversal. to ease the high cost of manual annotation, subsequent works adopt large language models (llms) for cost-effective generation of cad @xcite @xcite @xcite . however, findings from various investigations have indicated that training on cad does not always ensure improved generalization on ood tasks @xcite @xcite . consequently, our emphasis in this work is not on generating cad, but rather on the exploration of methodologies to effectively utilize the inherent prior knowledge within cad. contrastive learning. contrastive learning is initially proposed to learn a better embedding space by clustering similar samples closely while pushing dissimilar ones far apart @xcite @xcite . for example, the triplet loss @xcite minimizes the distance between an anchor point and its positive sample while maximizing the distance from a negative sample. the n-pair loss @xcite maximizes the distance between an anchor point with multiple negative points. @xcite separates positive samples from multiple noise samples with crossentropy loss. enhanced by other efficient techniques, e.g., data augmentation @xcite , hard negative sampling @xcite , and memory bank @xcite , cl has propelled significant advancements in various domains, under both supervised and unsupervised settings. in this section, we explore the untapped potential of cl to enhance the ood generalization of models trained on cad. training with cad. the task of effectively training a robust model with cad has received relatively limited attention. the simple approach is to directly use the cross-entropy loss @xcite @xcite . teney et al. (2020) have introduced gradient supervision over pairs of original data and their counterfactual examples, ensuring the model gradient aligns with the straight line between the original and counterfactual points. meanwhile, fan et al. (2024) considers original and counterfactual distribution as two different environments and proposes a dataset-level constraint using invariant risk minimization. following these works, we introduce a learning framework employing contrastive loss as a regularizer to enhance the generalization of fine-tuned models notably. ## experimental setup in the following, we introduce experimental settings, which include benchmark tasks, evaluation metrics, competitive baselines and implementation details. our code is released on github foot_0 . ## conclusion counterfactually augmented data (cad) can enhance model robustness by explicitly identifying causal features. however, recent research found that cad may fall behind non-cad methods on generality. in this work, we introduce paircfr to overcome this challenge. paircfr pairs original and counterfactual data during training and includes both contrastive and cross-entropy losses for learning discriminative representations. we prove that contrastive loss aids models in capturing sufficient relationships not represented in cad, thus improving generality. extensive experiments demonstrate that our paircfr achieves superior accuracy and robustness in various scenarios. our findings emphasize the potential of carefully designed training paradigms in utilization of cad.