Leveraging Code Generation to Improve Code Retrieval and Summarization via Dual Learning
Table 5. Rank of Code Retrieval for Examples.
['Model', 'Example(a)', 'Example(b)']
The examples show that our model not only achieves the best rank in code retrieval task, but also generates a human-readable summary. This indicates that CO3 can capture the inner association between human-provided text and code more accurately, which is consistent with previous quantitative analysis. More details are explained below. In the second example, due to the more complex logic of the query, none of the code summarization models were able to achieve a good result. Compared with the human-written summary, all the generated summaries lost the key information about “compare“ and “discarding.“ However, even in this complex scenario, CO3 did successfully find the corresponding code snippet. The main reason behind this is that CO3 can capture the intrinsic connection among tasks of code summarization, code generation and code retrieval better through an end-to-end model, thanks to dual learning and multi-task learning. More specifically, the three tasks collaborate to generate more accurate and richer semantic representations of both natural language and source code. These representations are vectors in a continuous semantic space, and contain most of the key information. The discrete words generated by sampling from continuous space may lose some key information, but those continuous representations can still maintain such information and thus assist down-stream tasks such as code retrieval better.