TSTR: Target Similarity Tuning Meets the Real World

Anirudh Khatry, Sumit Gulwani, Priyanshu Gupta, Vu Le, Mukul Singh, Ananya Singha, Gust Verbruggen

Introduction

In-context learning (ICL) has become a cornerstone of code generation using Large Language Models (LLMs), where providing a few high-quality examples in the prompt significantly enhances performance. However, the effectiveness of ICL is highly dependent on the selection of these examples. While Target Similarity Tuning (TST) was previously introduced to align Natural Language (NL) similarity with underlying code similarity, it faces significant challenges in practical, large-scale applications. This paper introduces TSTR (Target Similarity Tuning for the Real World), a robust and efficient framework designed to overcome these hurdles.

The Real-World Hurdles of TST

The authors identify four primary limitations that prevent standard TST from being production-ready:

  1. Sensitivity to Language: Models often overfit to specific training phrasing, failing when encountered with diverse user vocabularies.
  2. Inference Overhead: Utilizing full transformer models for example selection is computationally prohibitive in production.
  3. Dataset Curation: Random sampling for training data is inefficient, often resulting in noisy, irrelevant pairs.
  4. Expensive Evaluation: Traditional end-to-end evaluation requires costly code generation runs.

The TSTR Methodology

TSTR introduces three technical innovations to address these issues:

  • The "Tiny" Adapter: Instead of fine-tuning an entire model, TSTR employs a frozen, high-quality embedding model (e.g., OpenAI’s text-embedding-ada-002) and trains a small, two-layer Fully Connected Neural Network (FCNN) adapter. This ensures lightning-fast inference while leveraging broad linguistic foundations.
  • Boundary-Based Training: To improve data efficiency, the authors use a "hard negative" sampling strategy. By focusing on pairs near the decision boundary—where NL looks similar but code differs, or vice versa—the model learns to ignore superficial linguistic cues.
  • Ranking-Based Proxy: A pairwise ranking metric was developed as a cheap, reliable proxy for end-to-end execution accuracy, allowing for rapid iteration without expensive LLM calls.
Figure 2: Correlation between Ranking Proxy and Execution Match across various models, demonstrating TSTR's superior positioning.

Experimental Setup and Results

The researchers evaluated TSTR across three benchmarks: Power Query M (data transformation), SMCalFlow (task-oriented dialogue), and Bash (shell commands).

As shown in the results, TSTR consistently outperforms both vanilla embeddings and the original TST approach. On the Power Query M dataset, TSTR achieved an execution match of 0.55, surpassing the 0.52 achieved by the original TST and the 0.53 of SentenceBERT.

Figure 5: Performance comparison of TSTR against baseline techniques across three benchmarks (M, SMCalFlow, and Bash).

Key Insights

  • Robustness: TSTR remains stable even when training and testing data come from different distributions, a scenario where original TST performance often degrades.
  • Efficiency: The boundary-based selection strategy allows for training effective models with significantly fewer examples than random sampling.
  • Frozen Foundations: Building on top of massive pre-trained models prevents overfitting to specific training "dialects."

Conclusion and Future Work

TSTR demonstrates that a lightweight adapter combined with smart data selection can create a robust, production-ready system for example selection in code generation. While highly effective, future work remains to refine code similarity metrics beyond structural "sketch matches" and to address potential network latencies associated with third-party embedding APIs. Nonetheless, the discovery that pairwise ranking correlates strongly with execution accuracy provides a powerful tool for future research in the field.

Summary updated

BibTeX
@inproceedings{khatry2023tstr,
  author = {Anirudh Khatry and Sumit Gulwani and Priyanshu Gupta and Vu Le and Mukul Singh and Ananya Singha and Gust Verbruggen},
  title = {{TSTR: Target Similarity Tuning Meets the Real World}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.687},
}
Figure