NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Refining Joint Text and Source Code Embeddings for Retrieval Task with Parameter-Efficient Fine-Tuning

Karim Galliamov, Leila Khaertdinova, Karina DenisovaarXiv 2024

Abstract

The latest developments in Natural Language Processing (NLP) have demonstrated remarkable progress in a code-text retrieval problem. As the Transformer-based models used in this task continue to increase in size, the computational costs and time required for end-to-end fine-tuning become substantial. This poses a significant challenge for adapting and utilizing these models when computational resources are limited. Motivated by these concerns, we propose a fine-tuning framework that leverages Parameter-Efficient Fine-Tuning (PEFT) techniques. Moreover, we adopt contrastive learning objectives to improve the quality of bimodal representations learned by transformer models. Additionally, for PEFT methods we provide extensive benchmarking, the lack of which has been highlighted as a crucial problem in the literature. Based on the thorough experimentation with the CodeT5+ model conducted on two datasets, we demonstrate that the proposed fine-tuning framework has the potential to improve code-text retrieval performance by tuning only 0.4% parameters at most.

Introduction

As Transformer-based models grow in size, "full fine-tuning"—updating every single weight in the model—has become prohibitively expensive in terms of time and hardware. This is a major hurdle for researchers or engineers working with limited compute. Furthermore, code retrieval is a "bimodal" task: the model must bridge the semantic gap between how humans describe logic (Natural Language) and how computers execute it (Programming Language). While massive models handle this well, smaller models often struggle to align these two different worlds. This research introduces a framework for improving code-text retrieval by using Parameter-Efficient Fine-Tuning (PEFT) to refine embeddings efficiently without requiring massive GPU clusters.

Methodology

The proposed framework is built upon the CodeT5+ model (specifically the 110M parameter encoder). It combines two powerful concepts to optimize the retrieval process:

  1. Contrastive Learning: Instead of standard next-token prediction, the model is trained to "pull" matching pairs of text and code closer together in a shared latent space while "pushing" non-matching pairs apart.
  2. PEFT Techniques: Rather than updating all 110 million parameters, the authors evaluated four lightweight tuning methods: LoRA & AdaLoRA (adding low-rank matrices to attention layers), Prompt-Tuning (adding learnable virtual tokens), and (IA)3 (scaling internal activations).

By freezing the original model weights and only training these tiny additions—representing as little as 0.4% of total parameters—the computational load is drastically reduced without sacrificing performance.

The proposed fine-tuning framework using CodeT5+ and PEFT with contrastive loss.

Datasets

The study evaluated the framework on two primary sources:

  • CodeSearchNet (CSN): A standard industry benchmark covering Ruby, JavaScript, Go, Java, and PHP.
  • Custom Dataset: A self-assembled dataset to test the model on Python, C#, C++, and SQL. This was particularly important for testing "low-resource" scenarios and languages like SQL, which were not part of the original model's pre-training.
Data distribution for the custom dataset across four programming languages.

Results and Discussion

The experimental results demonstrate that tuning just the "adapter" layers via PEFT is sufficient to outperform the base model significantly. Key findings include:

  • Performance Gains: On the custom dataset, AdaLoRA boosted the Mean Reciprocal Rank (MRR)—a measure of retrieval accuracy—by 17% for C++ and C#, and over 6% for SQL.
  • Domain Adaptation: The base CodeT5+ model initially performed poorly on SQL. However, PEFT allowed the model to adapt to SQL's unique syntax quickly, showcasing its strength in domain adaptation for languages not seen during pre-training.
  • Convergence Speed: Reparameterization-based methods like LoRA and AdaLoRA reached peak performance much faster than Prompt-Tuning, making them more suitable for rapid experimentation.
  • RAG Integration: These refined embeddings were integrated into a Retrieval-Augmented Generation (RAG) pipeline, resulting in a stable increase in ROUGE scores for code generated by a larger LLM (DeepSeek-Coder).

Conclusion and Future Work

This research proves that efficiency can get you very close to state-of-the-art performance. By tuning only 0.4% of parameters, the 110M model achieved results in the "second-best" tier compared to massive models with up to 175B parameters. Future work will focus on scaling these PEFT methods to larger base models and optimizing batch sizes to further improve contrastive learning outcomes.

Summary updated

BibTeX
@misc{galliamov2024refining,
  author = {Karim Galliamov and Leila Khaertdinova and Karina Denisova},
  title = {{Refining Joint Text and Source Code Embeddings for Retrieval Task with Parameter-Efficient Fine-Tuning}},
  year = {2024},
  eprint = {2405.04126},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.04126},
}
Figure