[Paper Review] Bridging Semantic Gaps between Natural Languages and APIs with Word Embedding
This paper proposes Word2API, a method that bridges semantic gaps between natural language queries and APIs by jointly modeling words and APIs in a shared vector space using word embeddings. By mining millions of word-API pairs from GitHub source code and comments, and applying a shuffling strategy to align them, Word2API improves relatedness estimation by 10%–49.6% in precision and NDCG, outperforming baselines in query expansion and API document linking tasks.
Developers increasingly rely on text matching tools to analyze the relation between natural language words and APIs. However, semantic gaps, namely textual mismatches between words and APIs, negatively affect these tools. Previous studies have transformed words or APIs into low-dimensional vectors for matching; however, inaccurate results were obtained due to the failure of modeling words and APIs simultaneously. To resolve this problem, two main challenges are to be addressed: the acquisition of massive words and APIs for mining and the alignment of words and APIs for modeling. Therefore, this study proposes Word2API to effectively estimate relatedness of words and APIs. Word2API collects millions of commonly used words and APIs from code repositories to address the acquisition challenge. Then, a shuffling strategy is used to transform related words and APIs into tuples to address the alignment challenge. Using these tuples, Word2API models words and APIs simultaneously. Word2API outperforms baselines by 10%-49.6% of relatedness estimation in terms of precision and NDCG. Word2API is also effective on solving typical software tasks, e.g., query expansion and API documents linking. A simple system with Word2API-expanded queries recommends up to 21.4% more related APIs for developers. Meanwhile, Word2API improves comparison algorithms by 7.9%-17.4% in linking questions in Question&Answer communities to API documents.
Motivation & Objective
- To address the semantic gap between natural language queries and APIs, which hinders effective information retrieval in software engineering.
- To overcome the limitations of existing methods that model words or APIs in isolation, leading to inaccurate relatedness estimation.
- To develop a scalable approach for acquiring large-scale, diverse word-API pairs from real-world code repositories.
- To enable more accurate and effective software engineering tasks such as query expansion and API document linking.
- To model words and APIs simultaneously in a shared vector space to improve semantic relatedness estimation.
Proposed method
- Word2API collects millions of word-API pairs from GitHub source code and method comments to address the acquisition challenge.
- It extracts words from method comments and APIs from source code using heuristic rules to ensure semantic relevance.
- Words and APIs from the same method are grouped into word-API tuples to preserve contextual relationships.
- A shuffling strategy is applied to randomly reorder words and APIs within each tuple to create diverse training samples and improve alignment.
- Word2API trains a joint embedding model using these shuffled tuples, learning low-dimensional vectors that capture semantic similarity between words and APIs.
- The model uses skip-gram with negative sampling (similar to Word2Vec) to optimize the embedding space for word-API relatedness.
Experimental results
Research questions
- RQ1Can a joint embedding model effectively estimate semantic relatedness between natural language words and APIs?
- RQ2How does Word2API perform compared to existing methods in relatedness estimation across multiple evaluation metrics?
- RQ3To what extent can Word2API improve query expansion in code search and API recommendation tasks?
- RQ4Can Word2API enhance the accuracy of linking software questions to relevant API documentation in Q&A communities?
- RQ5How does the shuffling strategy contribute to better alignment and representation of word-API relationships?
Key findings
- Word2API improves relatedness estimation by 10% to 49.6% in precision and NDCG compared to baseline methods.
- In query expansion, a system using Word2API recommends up to 21.4% more relevant APIs than baseline systems.
- Word2API improves existing comparison algorithms by 7.9% to 17.4% in linking Stack Overflow questions to relevant API documentation.
- The model achieves superior performance on both word-API relatedness estimation and downstream software engineering tasks.
- The shuffling strategy significantly enhances alignment between words and APIs, enabling better joint modeling of semantic relationships.
- Word2API demonstrates strong generalization across diverse programming tasks, including code search and API recommendation.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.