We use cookies to improve your experience with our site.

基于概率模型的API程序合成方法

ProSy: API-Based Synthesis with Probabilistic Model

  • 摘要: 1、研究背景(context):
    程序合成是根据用户意图,自动生成相关代码的软件技术。为了解决程序合成面临的搜索空间问题,许多方法为特定任务定义了领域特定语言。虽然这些技术对于某些领域的问题是有效的,但是它们并不适合于一般的程序合成。基于组件的程序合成是程序合成的一个重要研究领域。SyPet是一种先进的基于组件的程序合成方法。它能生成仅由API组成的Java程序。但是由所有API序列构成的程序空间仍然非常庞大,寻找正确的解程序非常耗时,在实践中通常只能找到较小的程序。
    2、目的(Objective):
    为了针对实际问题合成更复杂的基于API的程序,本文提出了一种基于概率模型的API程序合成方法ProSy。其核心思想是利用从Javadoc和Stack Overflow等各种编码资源中获取的知识,构造出API的使用概率模型。该模型能为编程任务更有可能使用的API赋予更高的概率值。在合成时,概率更高的API会被优先使用,从而能够提高程序合成的效率。
    3、方法(Method):
    本文通过从Javadoc以及Stack Overflow上获取API的相关使用知识。给定了编程任务的自然语言描述,我们通过将其与Javadoc和Stack Overflow中的文本进行相似度比较,计算得到每个API与该编程任务的相似度分数。
    接下来,利用API与任务的相似度分数构造出程序空间的概率模型。该模型能够为更有可能用来实现给定任务的API赋予更高的概率。在程序合成时,概率更高的API组成的可达路径会被优先枚举,因此能够提高程序合成的效率。此外,本文还提出了对程序空间进行缩减的剪枝算法,能够缩小程序空间。
    4、结果(Result&Findings):
    本文首先在SyPet提供的30个编程任务上进行了对比实验。平均程序合成时间与原有方法相比能够减少80.83%,程序的搜索空间减少了50%。此外,本文又在额外收集的20个编程任务上进行了对比实验。ProSy能够全部得到解程序,平均时间为7秒。而原方法在给定的时间内只能合成其中的8个程序。实验结果表明,本文提出的方法能够有效地缩小程序的搜索空间,能够显著地提高程序合成的效率。
    5、结论(Conclusions):
    在本文中,我们研究了如何利用各种代码资源中的知识来提高基于API的程序合成方法性能。我们在一组编程任务上对本文方法进行了评估实验。实验结果表明,该方法能显著缩小程序的搜索空间并提高程序合成的效率。通过本文的研究可以看出,充分利用互联网中的代码知识来提高程序合成的效率是可行的。

     

    Abstract: Program synthesis is an exciting topic that desires to generate programs satisfying user intent automatically. But in most cases, only small programs for simple or domain-specific tasks can be synthesized. The major obstacle of synthesis lies in the huge search space. A common practice in addressing this problem is using a domain-specific language, while many approaches still wish to synthesize programs in general programming languages. With the rapid growth of reusable libraries, component-based synthesis provides a promising way, such as synthesizing Java programs which are only composed of APIs (application programming interfaces). However, the efficiency of searching for proper solutions for complex tasks is still a challenge. Given an unfamiliar programming task, programmers would search for API usage knowledge from various coding resources to reduce the search space. Considering this, we propose a novel approach named ProSy to synthesize API-based programs in Java. The key novelty is to retrieve related knowledge from Javadoc and Stack Overflow and then construct a probabilistic reachability graph. It assigns higher probabilities to APIs that are more likely to be used in implementing the given task. In the synthesis process, the program sketch with a higher probability will be considered first; thus, the number of explored reachable paths would be decreased. Some extension and optimization strategies are further studied in the paper. We implement our approach and conduct several experiments on it. We compare ProSy with SyPet and other state-of-the-art API-based synthesis approaches. The experimental results show that ProSy reduces the synthesis time of SyPet by up to 80%.

     

/

返回文章
返回