Semantic Similarity Loss for Neural Source Code Summarization

Chia-Yi Su, Collin McMillan
8/14/2023
10 citations
cs.SEcs.AI

Official code: apcl-research/funcom-useloss (3 stars, Python, last commit 2024-06-11).

Abstract

This paper presents a procedure for and evaluation of using a semantic similarity metric as a loss function for neural source code summarization. Code summarization is the task of writing natural language descriptions of source code.

Show full abstract

Neural code summarization refers to automated techniques for generating these descriptions using neural networks. Almost all current approaches involve neural networks as either standalone models or as part of a pretrained large language models e.g., GPT, Codex, LLaMA. Yet almost all also use a categorical cross-entropy (CCE) loss function for network optimization. Two problems with CCE are that 1) it computes loss over each word prediction one-at-a-time, rather than evaluating a whole sentence, and 2) it requires a perfect prediction, leaving no room for partial credit for synonyms. In this paper, we extend our previous work on semantic similarity metrics to show a procedure for using semantic similarity as a loss function to alleviate this problem, and we evaluate this procedure in several settings in both metrics-driven and human studies. In essence, we propose to use a semantic similarity metric to calculate loss over the whole output sentence prediction per training batch, rather than just loss for each word. We also propose to combine our loss with CCE for each word, which streamlines the training process compared to baselines. We evaluate our approach over several baselines and report improvement in the vast majority of conditions.

View on arXivView PDF

Code Implementations(1)

31Python, Jupyter NotebookAug 1, 20232 years ago

Similar Papers

Cite this paper

@article{su2023semantic,
  title  = {Semantic Similarity Loss for Neural Source Code Summarization},
  author = {Chia-Yi Su and Collin McMillan},
  year   = {2023},
  eprint = {2308.07429},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2308.07429v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2308.07429.svg)](https://codeofpaper.com/paper/2308.07429)

Discussion