C orr S ynth - A Correlated Sampling Method for Diverse Dataset Generation from LLM s (2024)

Abstract: Large language models (LLMs) have demonstrated remarkable performance in diverse tasks using zero-shot and few-shot prompting. Even though their capabilities of data synthesis have been studied well in recent years, the generated data suffers from a lack of diversity, less adherence to the prompt, and potential biases that creep into the data from the generator model. In this work, we tackle the challenge of generating datasets with high diversity, upon which a student model is trained for downstream tasks. Taking the route of decoding-time guidance-based approaches, we propose CorrSynth, which generates data that is more diverse and faithful to the input prompt using a correlated sampling strategy. Further, our method overcomes the complexity drawbacks of some other guidance-based techniques like classifier-based guidance. With extensive experiments, we show the effectiveness of our approach and substantiate our claims. In particular, we perform intrinsic evaluation to show the improvements in diversity. Our experiments show that CorrSynth improves both student metrics and intrinsic metrics upon competitive baselines across four datasets, showing the innate advantage of our method.

## introduction pretrained language models (llms) @xcite have achieved strong performance on text classification with a large amount of task-specific training data. however, in real world scenarios, collecting labeled data can be challenging due to expense and need for domain expertise. recently, several works have focused on generating texts using versatile llms such as @xcite , @xcite , mistral @xcite , mixtal @xcite and subsequently distill a student model on the synthetically generated data @xcite . however, generated datasets suffer from a lack of diversity @xcite and regurgitate the biases of the teacher llms, which proliferate into the student model. although prior works have utilized retrieval augmented generation for diverse dataset synthesis @xcite , here we focus on the more fundamental challenge of improving or controlling generations given a prompt and context. in particular, we focus on synthetic data generation for supervised text classification tasks and take the route of decoding time guidance based approaches @xcite @xcite , which aim to tackle the challenge of improving diversity and faithfulness to target class in these generated datasets. motivated by recent works on classifier free guidance (cfg) @xcite , we introduce a novel guidance based strategy, corrsynth. in corrsynth, generations are kept faithful to the synthesis instruction, while introducing greater diversity and similarity to human text. corrsynth is a correlated sampling approach which generates multiple sequences in parallel with strong inter-dependence between them. the main idea is as follows: when generating an instance of a particular class and sampling the next token, we contrast its logits with logits corresponding to partially generated instances from other classes. this is a simple but crucial change compared to cfg: in corrsynth, the contrasting logits for a class/label are obtained from generations corresponding to other labels, whereas in cfg, the contrasting logits are obtained feeding back the generation for the current label into the llm with prompts corresponding to other labels. to synthesize a k-class classification dataset, this requires k-times fewer forward passes compared to cfg. furthermore, we can smoothly trade-off diversity and improve class-separability by introducing contrasts between logits from the same or different classes. in summary, our contributions are: (1) we develop a general correlated sampling approach, corrsynth, that can generate multiple correlated sequences in parallel from an llm, by explicitly introducing contrasts between parallel generations during the sampling of each token, (2) we apply this to classification dataset synthesis, with the goal of improving diversity of synthetic generations, (3) we demonstrate how our method overcomes the limitations of cfg and controllable synthesis in regards to diversity and label-separation, (4) we benchmark our approach on tasks ranging from humor detection, sentiment analysis and topic classification in regional news headlines. our intrinsic analysis find that corrsynth generates datasets with higher representation of tail entities, lexical diversity and similarity to human text, and distillation accuracy of student models, compared to four state of the art baselines. when we describe natural language domains using x , y we mean either in the sense of them containing natural language sentences or as subsets of v * , it will be clear from the context. we consider dataset generation for text classification tasks. suppose we have a multiclass text classification problem with k classes as [k] and input domain x . let @xmath0, • • • , y k } be the space of label verbalizations for the k classes i.e., y k is a textual description of label @xmath1. a natural language example input is denoted as @xmath2. so the learning problem is defined on x ×y: given a data generating distribution p xy on x × y the task is to learn a classifier h : @xmath3, y)] is minimized for a given loss function l : y × @xmath4, where the expectation is taken with respect to p xy . given the rapid advancement of llms like gpt-4, llama2, mistral etc. we are interested in utilizing the world knowledge and reasoning capabilities of these large models to generate synthetic training data for the textual k-class classification problem. similar to recent works in this domain @xcite @xcite @xcite @xcite , we consider the setup of prompting teacher llm with a prompt prompt that includes a label @xmath5, a few in-context learning (icl) examples for the label y and potentially any other instance dependent attributes, and the prompt tasks the llm to generate a synthetic instance @xmath6.e., the aim is to generate x ∼ p x|@xmath7. that is, we generate a synthetic dataset d synth . a student language model (e.g., a bert-style pre-trained encoder model @xcite ) is trained on d synth . for the icl examples, we assume that we have access to a seed set of examples d @xmath8, y 1 ), . . . , (x n , y n )}. for us, typically n is such that we have around 50 examples per class. we assume that d seed is not large enough to train an effective student, but instead a larger synthetic dataset d @xmath9, y i )} m @xmath10. a standard approach to dataset synthesis is few shot generation i.e. fewgen @xcite @xcite . for instance, consider a task of detecting a business news article. in order to synthesize a dataset for this task, we could prompt the llm appropriately, include few icl examples. the llm might generate a fairly decent article. but when we sample a large number of generations we see that the there is lack of diversity: similar entities are repeated, popular topics are highlighted and potential stylistic differences from a human written text. these could affect the performance of a student model that is trained on such dataset. a "good" synthetic dataset must ensure that the conditional distribution of instances given any label must closely approximate that of the true distribution p xy . this includes: i) correct semantic separation of labels, ii) preservation of intra-label semantic diversity and of course, iii) fluent and coherent generations. in order to achieve (i) and (ii) (without compromising on (iii)), we present a method, corrsynth, in the flavor of decoding time guidance techniques @xcite @xcite . in these works, at inference time, the token probability distribution is tilted by another distribution obtained either from a different llm, or same llm with a different prompt, or different layers of the same llm. in particular, we take inspiration from the classifier free guidance @xcite ) method applied to text based llms @xcite . corrsynth aims to control i) diversity in generations, ii) similarity to human crafted gold dataset, iii) cross label separation and at the same time iv) improve the student performance. the core idea of our approach is to perform correlated or dependent sampling from the llm i.e., multiple sequences are generated in parallel that have strong dependency between each other. figure 1 illustrates our method. more details are given in section 3. this method can be used in conjunction with other synthetic dataset generation approaches like retrieval augmented generation @xcite . ## method now we describe our novel corrsynth method of sampling from an llm. although it is a general technique, we choose to motivate it from the perspective of data synthesis for a text based super-vised learning problem. ## experimental setup datasets. we experiment on 4 datasets described in ## analysis and visualizations effect of intra-label and cross-label contrasts: given the promising results of our method corrsynth, we wanted to analyse and visualize the effect of varying intra-label and cross-label contrasts upon the generations. for this, we obtain the average label-wise cosine similarities of the generations and plot them as heatmaps (see figure 3 ). we specifically study the behavior of our approach in multi-label setting upon toi headlines dataset to emphasize our results. in practice, we use the all-mpnet-base-v2 model from sentencetransformers library to obtain the text representations of each generation. next, for generations each label i and j in the labelspace, we compute the pairwise cosine similarities of all generations corresponding to label i, to that of label j. the pairwise cosine similarities are then added and the mean label-wise similarity is computed. we hypothesize that in our approach (hybrid corrsynth), if the intra label contrast is increased, then, within each class the generations should get further away so that the net cosine similarity within the class should reduce across all classes. as we can see in figure 3a , the diagonals become lighter as we go left to right. on the other hand, if the cross-label contrast is increased net separability between every pair of classes should increase. as expected, we can see in figure 3b , in the heatmaps the off-diagonal label similarities are becoming lighter as cross contrast is increased. effect of δ: to visualize the effect of varying δ on the generations obtained through corrsynth, we plot 2-dimensional representations of the generations. we use uniform manifold approximation and projection (umap) @xcite for dimension reduction 3 of text representations obtained using all-mpnet-base-v2 model. as earlier, we perform this analysis in a multi-label setting with toi headlines. in figure 4 , we can see that as δ is reduced from (0.9, 0.5, 0), the representations become more and more diffused with each other, leading to overlaps, making the student model hard to learn the deci-3 https://umap-learn.readthedocs.io/en/latest/ sion boundary. for δ = 0.9, we can visualize the clusters containing data points from different labels are well-separated, which resonates with our best performing results as well. note that overlapping/diffused datapoints could be indicators of mislabelled generations as well as hard negatives. we hypothesize that as we decrease delta from 0.9, first we see an increase in hard negative generations than mislabeled generations, whereas after some threshold, the extent of mislabeled generations increase. thus there is a sweet spot which provides good amount of hard examples with minimal number of wrong generations. we can see this effect in the corresponding cartography plots @xcite in figure 5 where as we go from left to right, the density of gray and blue points increase but blue points density increases more for much smaller delta than for gray points. the gray points here typically denote hard to learn examples, where as the blue one predominantly represent mislabeled example. these hard negative generations benefit the student model training. more recently, these models have gained popularity in their superior ability to synthesize taskspecific datasets @xcite @xcite @xcite . llms such as gpt-3 @xcite @xcite and chat-tuned models @xcite @xcite have shown promising results on the task of generating synthetic data. certain works like @xcite fine-tune an llm to generate nlu datasets, whereas our work is similar to @xcite ; @xcite which use frozen llms with task-dependent prompts to generate data, targeting text classification. text classification dataset synthesis employs class-specific prompts; previous studies explored zero-shot @xcite and iterative few-shot prompting @xcite . however, only recently has the lack of diversity in synthetic classification datasets been recognized. @xcite advocated for using diverse prompts that explicitly introduce variations, such as subtopics and brands, resulting in more diverse conditioning. in contrast, our approach achieves diversity with a fixed prompt. divekar and durrett (2024) employs retrieval augmentation to introduce variety into the dataset synthesis process by seeding the llm with different content. however, the diversity here is constrained by the corpus availability, whereas our work improves diversity despite relying only on llm parameters. @xcite and later extended to autoregressive llms @xcite . cfg falls under general guidance based techniques, where a guidance distribution is used at inference to alter the sampling distribution towards the desired goal.in cfg, this guidance distribution is provided by the llm itself but with a different prompt as described in appendix d. context-aware decoding @xcite also uses the same formulation as cfg. ## conclusion in this work, we propose a novel technique corrsynth which uses correlated sampling and intuition from classifier free guidance and contrastive decoding to generate strongly diverse datasets across a variety of tasks with good crosslabel separations. we provide the mathematical intuition of our approach and back our theoretical discussion with empirical results. our extensive experimentation across 4 datasets show the robustness of our approach in generating synthetic data. in the future, we would like to study the effect of including intra-label contrasts while generating with the llms, and mixing up both cross-label and intra-label contrasts (a hybrid approach) to see how the generations are affected with respect to both intrinsic and extrinsic evaluation.