Towards Better Code Understanding in Decoder-Only Models with Contrastive Learning

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Lin, Jiayi, Wang, Yanlin, Yang, Yibiao, Zhang, Lei, Xie, Yutao
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866912897313013760
author Lin, Jiayi
Wang, Yanlin
Yang, Yibiao
Zhang, Lei
Xie, Yutao
author_facet Lin, Jiayi
Wang, Yanlin
Yang, Yibiao
Zhang, Lei
Xie, Yutao
contents Recent advances in large-scale code generation models have led to remarkable progress in producing high-quality code. These models are trained in a self-supervised manner on extensive unlabeled code corpora using a decoder-only architecture. However, despite their generative strength, decoder-only models often exhibit limited performance on code understanding tasks such as code search and clone detection, primarily due to their generation-oriented training objectives. While training large encoder-only models from scratch on massive code datasets can improve understanding ability but remains computationally expensive and time-consuming. In this paper, we explore a more efficient alternative by transferring knowledge from pre-trained decoder-only code generation models to code understanding tasks. We investigate how decoder-only architectures can be effectively adapted to learn discriminative and semantically meaningful code representations. To this end, we propose CL4D, a contrastive learning framework tailored to strengthen the representation capabilities of decoder-only models. Extensive experiments on multiple benchmark datasets demonstrate that CL4D achieves competitive or superior performance compared to existing methods on representative code understanding tasks, including code search and clone detection. Further analysis reveals that CL4D substantially improves the semantic alignment of code representations by reducing the distance between semantically similar code snippets. These findings highlight the feasibility of leveraging decoder-only models as a unified backbone for both code generation and understanding.
format Preprint
id arxiv_https___arxiv_org_abs_2406_12326
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Towards Better Code Understanding in Decoder-Only Models with Contrastive Learning
Lin, Jiayi
Wang, Yanlin
Yang, Yibiao
Zhang, Lei
Xie, Yutao
Software Engineering
Artificial Intelligence
Recent advances in large-scale code generation models have led to remarkable progress in producing high-quality code. These models are trained in a self-supervised manner on extensive unlabeled code corpora using a decoder-only architecture. However, despite their generative strength, decoder-only models often exhibit limited performance on code understanding tasks such as code search and clone detection, primarily due to their generation-oriented training objectives. While training large encoder-only models from scratch on massive code datasets can improve understanding ability but remains computationally expensive and time-consuming. In this paper, we explore a more efficient alternative by transferring knowledge from pre-trained decoder-only code generation models to code understanding tasks. We investigate how decoder-only architectures can be effectively adapted to learn discriminative and semantically meaningful code representations. To this end, we propose CL4D, a contrastive learning framework tailored to strengthen the representation capabilities of decoder-only models. Extensive experiments on multiple benchmark datasets demonstrate that CL4D achieves competitive or superior performance compared to existing methods on representative code understanding tasks, including code search and clone detection. Further analysis reveals that CL4D substantially improves the semantic alignment of code representations by reducing the distance between semantically similar code snippets. These findings highlight the feasibility of leveraging decoder-only models as a unified backbone for both code generation and understanding.
title Towards Better Code Understanding in Decoder-Only Models with Contrastive Learning
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2406.12326