Compositional API Recommendation for Library-Oriented Code Generation

Compositional API Recommendation for Library-Oriented Code Generation

April 15-16, 2024 | Zexiong Ma, Shengnan An, Bing Xie, Zeqi Lin
This paper proposes CAPIR, a novel compositional API recommendation approach for library-oriented code generation. CAPIR addresses the challenge of generating code for libraries not present in the training data of large language models (LLMs) by decomposing coarse-grained requirements into fine-grained subtasks. The approach involves three main components: task decomposition, subtask API retrieval, and API reranking. CAPIR uses an LLM-based Decomposer to break down tasks into subtasks, an embedding-based Retriever to find relevant APIs, and an LLM-based Reranker to refine the recommendations. The method is evaluated on two benchmarks, RAPID and LOCG, demonstrating significant improvements in API recommendation and code generation performance compared to existing baselines. CAPIR outperforms existing methods in terms of recall and precision, and shows effectiveness in practical applications. The results indicate that CAPIR can effectively recommend APIs for low-resource libraries and improve code generation performance for both single and multi-library scenarios. The approach is also tested with different LLMs, showing its effectiveness across various models. The paper concludes that CAPIR provides a promising solution for library-oriented code generation by leveraging the compositional nature of API recommendations.This paper proposes CAPIR, a novel compositional API recommendation approach for library-oriented code generation. CAPIR addresses the challenge of generating code for libraries not present in the training data of large language models (LLMs) by decomposing coarse-grained requirements into fine-grained subtasks. The approach involves three main components: task decomposition, subtask API retrieval, and API reranking. CAPIR uses an LLM-based Decomposer to break down tasks into subtasks, an embedding-based Retriever to find relevant APIs, and an LLM-based Reranker to refine the recommendations. The method is evaluated on two benchmarks, RAPID and LOCG, demonstrating significant improvements in API recommendation and code generation performance compared to existing baselines. CAPIR outperforms existing methods in terms of recall and precision, and shows effectiveness in practical applications. The results indicate that CAPIR can effectively recommend APIs for low-resource libraries and improve code generation performance for both single and multi-library scenarios. The approach is also tested with different LLMs, showing its effectiveness across various models. The paper concludes that CAPIR provides a promising solution for library-oriented code generation by leveraging the compositional nature of API recommendations.
Reach us at info@study.space