Fill In The Gaps: Model Calibration and Generalization with Synthetic Data (2024)

Abstract: As machine learning models continue to swiftly advance, calibrating their performance has become a major concern prior to practical and widespread implementation. Most existing calibration methods often negatively impact model accuracy due to the lack of diversity of validation data, resulting in reduced generalizability. To address this, we propose a calibration method that incorporates synthetic data without compromising accuracy. We derive the expected calibration error (ECE) bound using the Probably Approximately Correct (PAC) learning framework. Large language models (LLMs), known for their ability to mimic real data and generate text with mixed class labels, are utilized as a synthetic data generation strategy to lower the ECE bound and improve model accuracy on real test data. Additionally, we propose data generation mechanisms for efficient calibration. Testing our method on four different natural language processing tasks, we observed an average up to 34% increase in accuracy and 33% decrease in ECE.

## introduction natural language processing (nlp) models have fundamentally advanced the syntactic and semantic analysis, information retrieval, and automated generation of textual data. state-of-the-art (sota) models (e.g., transformers @xcite , bert @xcite , and roberta @xcite ) have excelled in practical, usercentric applications such as automated customer support chatbots, personalized content curation, and real-time multilingual text translation. other nlp models, which are typically trained for a specialized use context, have also been developed and fine-tuned for numerous downstream tasks, including sentiment analysis, named entity recognition (ner), and text classification, as parts of a decision-support system (dss). powered by deep learning algorithms, these classification models have achieved remarkable levels of performance in terms of their accuracy, f1 scores, and aucs @xcite . as machine learning philosophies continue to evolve, growing attention is placed on metrics beyond simple classification accuracy. in recent years, socially responsible artificial intelligence (ai) has been strongly advocated by algorithmic regulatory frameworks (e.g., the us algorithmic accountability act @xcite ), especially in safety-critical domains, such as healthcare @xcite and law enforcement @xcite . some key pillars of socially responsible ai include accountability, transparency, and robustness @xcite . ensuring a calibrated ml model accountable for its decision means that it must provide clear justifications for any decision being made, while transparency requires that these justifications are understandable and interpretable @xcite ; additionally, robustness requires that the ml model performs consistently well under various conditions. in classification tasks, these requirements can be addressed by properly managing model output uncertainty, i.e., quantifying, calibrating, and communicating the proper confidence level associated with each prediction to the end user. among the three aspects of uncertainty management, calibration directly improves model performance by ensuring that model predictions are congruent with empirically observed outcomes. ai risk management is an emerging field that emphasizes understanding the limitations of model predictions. model calibration techniques are used to address the fact that high accuracy does not always mean high confidence in a model's predictions. for example, consider a classifier trained to recognize handwritten digits. this model might achieve high accuracy on a test set, but it also provides the predicted probability for each class, which reflects its level of uncertainty. if it classi-figure 1 : the framework of our proposed method involves initially training a downstream model using real data to identify poorly calibrated bins. data instances, x i , and their prediction probabilities, p (y i |x i ), from these bins are then fed into large language models (llms) to generate synthetic data, x syn i , along with their corresponding probabilities, p (y i |x syn i ). this synthetic data, combined with the real data, is used to retrain the downstream model, thereby improving calibration outputs without compromising model performance. modern deep learning neural networks (nn), however, have been shown to be often miscalibrated i.e., while the nn model performs well in classification, the uncertainty around predictions is also high @xcite . nlp models trained on classification tasks (such as sentiment analysis) are built on deep learning algorithms, with many hidden layers and regularization steps, and consequently, numerous hyperparameters to be tuned. recent work has shown the association between increased depth and/or width of nn layers, and miscalibrated outcomes @xcite . model calibration becomes worse in data-scarce scenarios, where the fraction of events predicted does not align with actual outcomes because the amount of data available at hand may not be sufficient enough to be representative across different classes. data augmentation approaches (e.g., the mixup approach @xcite ) and the associated model calibration problems have been discussed in literature @xcite . but, theories for understanding the association between model performance and calibration are still lacking. this work is motivated by a recently published paper @xcite , in which llms are utilized to generate synthetic data close to the decision boundary to sharpen the discrimination power of the classifier and increase model accuracy. the llm-generated synthetic data leverage the capability of llms in providing both realistic and diverse datasets, which potentially increases the ml model's generalizability on out-of-distribution data. the application of synthetic data has been explored as an augmented training set @xcite , validation set @xcite , or test set @xcite to improve ml model performance. however, applying synthetic data to address model calibration has barely been explored. we aim to use llm-generated synthetic text data to fine-tune downstream binary classification tasks to reduce expected calibration error (ece) without sacrificing the ml model's accuracy. our approach is derived from the probably approximately correct (pac) learning framework @xcite . we prove that reducing both calibration and misclassification errors can be achieved simultaneously, and we establish the necessity of generating synthetic data for enhancing model calibration. this approach is validated on real-world text datasets. the synthetic data generation process is accomplished using open-source large language models -llama 2 @xcite . figure 1 illustrates our proposed framework to improve model calibration and generalization via synthetic data for natural language classification tasks. the contributions of this work can be summarized as follows: ## calibration concept this section introduces some basic concepts related to model calibration, which would lay a foundation to derive our methodology. expected calibration error (ece). ece is a widely-used metric to evaluate how well a model's predicted probabilities (confidence) align with its actual outcomes (accuracy) @xcite . it is calculated by segmenting the full range of predicted probabilities into m equal bins and sorting predictions into these bins based on their confidence. within each bin, the model's accuracy (the fraction of correct predictions) and average predicted confidence are computed. let b m be the set of examples in the m th bin, whose accuracy and confidence are: there exist some variants of ece, like mce @xcite , ace @xcite , and other metrics to quantify calibration like brier score @xcite , however, in this paper, the calibration error refers to ece. ## methodology in this section, we utilize the probably approximately correct (pac) learning framework to derive the expected calibration error(ece) bound and discuss the benefits of using synthetic data to improve models' calibration and generalization. moreover, we use a toy sample to demonstrate our methodology. ## related work model calibration has emerged as an open challenge in machine learning as concerns arise regarding the responsible and ethical use of ml-enabled systems. several methods have been proposed, including platt scaling @xcite , isotonic regression @xcite , among others. both of them somewhat change the predicted probability, which could lower the predicted accuracy. in the computer vision field, a mixup method @xcite has been proposed to overcome the shortcomings of data scarcity. it combines two instances from the original dataset with different proportions. a follow-up paper @xcite investigates the computer vision task calibration by using the mixup approach and concludes that this approach could impair the model calibration. however, the calibration issue in the nlp field has rarely been discussed. several benefits from using synthetic data have been explored in @xcite . it is found that ml prediction accuracy can be improved significantly by adding synthetic data generated near the decision boundary. on the other hand, a recent paper @xcite investigates on potential and limitations of synthetic data generated from llm for text classification tasks and concludes that while synthetic data can be beneficial in certain scenarios, it does not consistently enhance model performance. our research is different from theirs in that we provide a strategy that enables both good generalization and uncertainty calibration. ## conclusion in the era of large models, we believe smaller models still hold tremendous values in, e.g., edge computing and specialized downstream machine learning tasks. we derive the expected calibration error bound for ml models and explore the possibility of leveraging synthetic data to mitigate calibration error. through empirical validation with text classification tasks, we demonstrate the usefulness of our method; that is, by harnessing the power of llms, purposefully generated synthetic data can be utilized to train smaller downstream nlp tasks, achieving both strong classification performance and calibration error reduction.