Improving Sentence Embeddings with Automatic Generation of Training Data Using Few-shot Examples

Soma Sato, Hayato Tsukagoshi, Ryohei Sasano, Koichi TakedaStudent Research Workshop @ ACL 2024

Abstract

High-quality sentence embeddings are vital for semantic search and document clustering, yet the most effective models rely on supervised fine-tuning with expensive, manually annotated Natural Language Inference (NLI) datasets. This paper explores the use of Large Language Models (LLMs) to automatically generate synthetic NLI training data. By strategically leveraging a distributed "5-shot × 4" few-shot approach, the authors demonstrate that synthetic data can significantly outperform existing unsupervised methods and approach the performance of models trained on human-labeled data.

Introduction

Sentence embeddings represent text as numerical vectors that capture semantic meaning. Currently, state-of-the-art performance is achieved through supervised fine-tuning on NLI tasks, where models learn relationships between "premise" and "hypothesis" sentences (entailment, neutral, or contradiction). However, the reliance on massive, human-annotated datasets like SNLI and MNLI creates a significant bottleneck. While LLMs offer a potential solution for data generation, naive zero-shot prompting often yields repetitive and low-diversity datasets. This research investigates how to optimize few-shot prompting to generate synthetic NLI data that is both accurate and linguistically diverse.

Methodology

The researchers developed a pipeline to generate NLI data without human intervention, utilizing LLaMA-2-7B-Chat as the generator and PromptEOL as the target embedding model.

Data Generation Pipeline

  1. Premise Selection: One million random sentences were extracted from Wikipedia to serve as base premises.
  2. Hypothesis Generation: For each premise, the LLM was prompted to generate "entailment" and "contradiction" hypotheses.
  3. Few-Shot Strategies: The core innovation lies in the distribution of examples. The authors compared standard 0-shot to 20-shot prompts against a "distributed" strategy. In the 5-shot × 4 approach, four distinct sets of five examples were used across different batches of data generation to inject stylistic variety.

Fine-tuning

The generated synthetic pairs were used to fine-tune PromptEOL, a decoder-based model that generates embeddings by summarizing sentences into a single representative word.

Results and Analysis

The study revealed a critical trade-off between label quality and data diversity. While increasing the number of few-shot examples generally improves the accuracy of the generated labels, using a single large set of examples (e.g., 20-shot) can lead to outputs that are overly dependent on the prompt's style, reducing the model's ability to generalize.

Label Accuracy and LLM Bias

Interestingly, LLMs demonstrated a natural proficiency for generating contradictions even in zero-shot settings, but struggled significantly with entailment. As shown in the table below, few-shot examples were essential for aligning the LLM's output with the expected definition of entailment.

Agreement between generated labels and a classifier across different shot counts.

Performance on STS Benchmarks

The model fine-tuned on the "5-shot × 4" synthetic dataset achieved an average score of 82.71 on STS tasks. This represents a substantial improvement over the unsupervised PromptEOL baseline (71.62) and surpasses the previous state-of-the-art unsupervised model, PromptRoBERTa (79.14).

Comparison of STS performance across different data sizes and training methods.

As illustrated in the figure above, the synthetic data approach effectively closes the gap between unsupervised methods and those relying on manual datasets. Performance gains were observed with as few as 4,000 pairs, with results stabilizing as the dataset size reached 256,000 pairs.

Conclusion

This research demonstrates that LLMs can be effectively harnessed to generate high-quality training data for sentence embeddings. The "5-shot × 4" strategy provides an optimal balance between label accuracy and linguistic diversity. While currently limited to English and specific model architectures, this approach offers a scalable path toward high-performance sentence embeddings without the need for extensive human annotation. Future work may explore dynamic few-shot selection and cross-lingual applications.

Summary updated

BibTeX
@inproceedings{sato2024improving,
  author = {Soma Sato and Hayato Tsukagoshi and Ryohei Sasano and Koichi Takeda},
  title = {{Improving Sentence Embeddings with Automatic Generation of Training Data Using Few-shot Examples}},
  booktitle = {Student Research Workshop @ ACL},
  year = {2024},
  doi = {10.18653/v1/2024.acl-srw.43},
}
Figure