Selective Prompt Anchoring for Code Generation

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Tian, Yuan, Zhang, Tianyi
Format: Preprint
Publié: 2024
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866912503361961984
author Tian, Yuan
Zhang, Tianyi
author_facet Tian, Yuan
Zhang, Tianyi
contents Recent advances in large language models (LLMs) have transformed software development by automatically generating code from natural language. Yet challenges remain in generating fully correct code that aligns with user intent. Our study reveals that LLMs tend to pay less attention to user prompts as more code tokens are generated. We hypothesize that this attention dilution issue is an important reason for code generation errors. To mitigate this issue, we propose Selective Prompt Anchoring (SPA) to guide code LLMs to pay more attention to user intent when generating code. We evaluate SPA using six base LLMs across six benchmarks. Our results demonstrate that SPA enhances Pass@1 by up to 12.9%, consistently outperforming SOTA code generation methods in all settings. Our code is available at https://github.com/magic-YuanTian/Selective-Prompt-Anchoring.
format Preprint
id arxiv_https___arxiv_org_abs_2408_09121
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Selective Prompt Anchoring for Code Generation
Tian, Yuan
Zhang, Tianyi
Machine Learning
Artificial Intelligence
Computation and Language
Software Engineering
Recent advances in large language models (LLMs) have transformed software development by automatically generating code from natural language. Yet challenges remain in generating fully correct code that aligns with user intent. Our study reveals that LLMs tend to pay less attention to user prompts as more code tokens are generated. We hypothesize that this attention dilution issue is an important reason for code generation errors. To mitigate this issue, we propose Selective Prompt Anchoring (SPA) to guide code LLMs to pay more attention to user intent when generating code. We evaluate SPA using six base LLMs across six benchmarks. Our results demonstrate that SPA enhances Pass@1 by up to 12.9%, consistently outperforming SOTA code generation methods in all settings. Our code is available at https://github.com/magic-YuanTian/Selective-Prompt-Anchoring.
title Selective Prompt Anchoring for Code Generation
topic Machine Learning
Artificial Intelligence
Computation and Language
Software Engineering
url https://arxiv.org/abs/2408.09121