WO2022239179A1 - プログラム生成装置、プログラム生成方法及びプログラム - Google Patents

プログラム生成装置、プログラム生成方法及びプログラム Download PDF

Info

Publication number
WO2022239179A1
WO2022239179A1 PCT/JP2021/018183 JP2021018183W WO2022239179A1 WO 2022239179 A1 WO2022239179 A1 WO 2022239179A1 JP 2021018183 W JP2021018183 W JP 2021018183W WO 2022239179 A1 WO2022239179 A1 WO 2022239179A1
Authority
WO
WIPO (PCT)
Prior art keywords
program
source code
similarity
degree
attention
Prior art date
Application number
PCT/JP2021/018183
Other languages
English (en)
French (fr)
Inventor
利行 倉林
優 吉村
治門 丹野
Original Assignee
日本電信電話株式会社
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 日本電信電話株式会社 filed Critical 日本電信電話株式会社
Priority to PCT/JP2021/018183 priority Critical patent/WO2022239179A1/ja
Publication of WO2022239179A1 publication Critical patent/WO2022239179A1/ja

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Definitions

  • the present invention relates to a program generation device, a program generation method, and a program.
  • Non-Patent Document 1 there is a method of automatically generating a program by using two types of information: a natural language that describes the specifications of the program to be generated and input/output examples.
  • a natural language that describes the specifications of the program to be generated
  • input/output examples Non-Patent Document 1
  • Similar programs are retrieved from natural language to acquire similar programs.
  • program synthesis is performed so as to satisfy the input/output example, and a program is automatically generated.
  • program synthesis is performed using a program that is assumed to be similar to the correct program obtained by searching as a template, compared to the program generation method using only input/output examples , it is difficult to generate overfitted programs.
  • program synthesis is a technology that randomly combines program parts to satisfy input/output examples, even if a program similar to the correct program is used as a template, tokens in the template that should not be changed is also changed, and in that case, there is a possibility that the correct program (desired program) cannot be generated.
  • the present invention has been made in view of the above points, and aims to improve the probability of generating a desired program.
  • a program generation device calculates the degree of similarity with a sentence explaining the specification of a desired program in a natural language for a plurality of first source codes, and calculates the first source code.
  • FIG. 1 is a diagram showing a functional configuration example of a program generation device 10 according to an embodiment of the present invention
  • FIG. FIG. 11 is a flowchart for explaining an example of a processing procedure of learning processing of a similarity calculation model m1
  • FIG. It is a figure which shows an example of the data set for a search. It is a figure for demonstrating learning of the similarity calculation model m1.
  • 7 is a flowchart for explaining an example of a processing procedure of automatic program generation processing; It is a figure which shows an example of an object description. It is a figure which shows the mode of searching for a similar code.
  • FIG. 11 is a flowchart for explaining an example of a processing procedure of learning processing of a similarity calculation model m1
  • FIG. It is a figure which shows an example of the data set for a search. It is a figure for demonstrating learning of the similarity calculation model m1.
  • 7 is a flowchart for explaining an example of a processing procedure of automatic program generation processing
  • FIG. 10 is a diagram illustrating an example of template generation; It is a figure which shows an example of an input-output example set.
  • FIG. 10 is a diagram showing an example of a program parts list;
  • FIG. 4 is a diagram showing an example of synthetic code generated using a template;
  • FIG. 1 is a diagram showing a hardware configuration example of a program generation device 10 according to an embodiment of the present invention.
  • the program generation device 10 of FIG. 1 has a drive device 100, an auxiliary storage device 102, a memory device 103, a CPU 104, an interface device 105, a display device 106, an input device 107, etc., which are connected to each other via a bus B, respectively.
  • a program that implements processing in the program generation device 10 is provided by a recording medium 101 such as a CD-ROM.
  • a recording medium 101 such as a CD-ROM.
  • the program is installed from the recording medium 101 to the auxiliary storage device 102 via the drive device 100 .
  • the program does not necessarily need to be installed from the recording medium 101, and may be downloaded from another computer via the network.
  • the auxiliary storage device 102 stores installed programs, as well as necessary files and data.
  • the memory device 103 reads and stores the program from the auxiliary storage device 102 when a program activation instruction is received.
  • the CPU 104 realizes functions related to the program generation device 10 according to programs stored in the memory device 103 .
  • the interface device 105 is used as an interface for connecting to a network.
  • a display device 106 displays a program-based GUI (Graphical User Interface) or the like.
  • the input device 107 is composed of a keyboard, a mouse, etc., and is used to input various operational instructions.
  • FIG. 2 is a diagram showing a functional configuration example of the program generation device 10 according to the embodiment of the present invention.
  • the program generation device 10 has a learning section 11, a similar code search section 12, a template generation section 13, and a program synthesis section . Each of these units is implemented by processing that one or more programs installed in the program generation device 10 cause the CPU 104 to execute.
  • the similarity calculation model m1 in FIG. 2 is a model (neural network) that calculates the similarity between a statement (description) that explains the program specifications in natural language and the source code of the program.
  • FIG. 3 is a flowchart for explaining an example of a processing procedure of learning processing of the similarity calculation model m1.
  • step S101 the learning unit 11, for example, randomly acquires two (two sets) of programs with explanations from the search data set stored in the auxiliary storage device 102.
  • FIG. 4 is a diagram showing an example of a search data set.
  • a unit surrounded by a dashed line is one program with explanatory text.
  • a program with explanation refers to data that includes source code of the program and a sentence (explanation) explaining the specifications of the program in a natural language (Japanese in this embodiment) in association with each other. That is, the data structure of the search data set is described below in a format based on the BNF (Backus-Naur form) notation.
  • ⁇ dataset for search> :: [description source code] +
  • a plurality of programs with explanations are prepared in advance as search data sets.
  • step S101 a set of two programs with explanations is obtained at random from a plurality of programs with explanations. However, in step S101 for the second and subsequent times, two sets other than the already obtained combinations are obtained.
  • the search data set is used as a learning data set of the similarity calculation model m1.
  • the learning unit 11 calculates the similarity of the structure of the source code included in each of the two programs with explanatory text (hereinafter referred to as "similarity X") (S102). For example, Tree Edit Distance may be used as the similarity X index.
  • the learning unit 11 calculates the cosine of the result of vectorizing the explanatory text of one of the two programs with explanatory text and the vectorization result of the source code of the other program with the explanatory text.
  • the similarity calculation model m1 is trained so that the similarity (hereinafter referred to as “similarity Y”) approaches the similarity X (for example, so that the difference between the similarity Y and the similarity X becomes small) (similarity
  • the model parameters of the degree calculation model m1 are updated (S103).
  • the similarity calculation model m1 can be realized using a model or the like used in a program search method using a deep learning model.
  • the model is "Yao Wan, Jingdong Shu, Yulei Sui, Guandong Xu, Zhou Zhao, Jian Wu, and Philip S. Yu. Multi-modal attention network learning for semantic source code retrieval.
  • the model is "Yao Wan, Jingdong Shu, Yulei Sui, Guandong Xu, Zhou Zhao, Jian Wu, and Philip S. Yu. Multi-modal attention network learning for semantic source code retrieval.
  • FIG. 5 is a diagram for explaining the learning of the similarity calculation model m1.
  • the similarity calculation model m1 includes a neural network L1, an attention layer L2, a neural network L3, an attention layer L4, and the like.
  • the neural network L1 is a neural network that converts each word of the description into a vector (hereinafter referred to as "vector v1") with a predetermined number of dimensions (eg, 512 dimensions). For example, if the description includes J words, J vectors v1 are output from neural network L1.
  • the Attention layer L2 is a neural network that receives J vectors v1 and outputs one vector (hereinafter referred to as "vector v2").
  • the Attention layer L2 weights each vector v1 with the weight parameter of the Attention layer L2 to generate one vector v2.
  • the neural network L2 is a neural network that converts each token of the source code into a vector (hereinafter referred to as "vector v3") with a predetermined number of dimensions (eg, 512 dimensions). For example, if the description contains K tokens, then K vectors v2 are output from neural network L2.
  • the Attention layer L4 is a neural network that receives K vectors v3 and outputs one vector (hereinafter referred to as "vector v4").
  • the Attention layer L4 weights each vector v1 and each vector v3 with the weight parameter of the Attention layer L4 to generate one vector v4.
  • the weight for each vector v3 corresponds to the degree of interest for each token of the source code in calculating the vector v4 (and thus in calculating the similarity Y).
  • step S103 the learning unit 11 learns the neural network L1, the neural network L2, the attention layer L3, and the attention layer L4 so that the cosine similarity (similarity Y) between the vector v2 and the vector v4 approaches the similarity X. do.
  • the learning unit 11 determines whether steps S101 and subsequent steps have been executed for all two sets of programs with explanations in the search data set (S104). If there are two unprocessed sets (No in S104), step S101 and subsequent steps are repeated. At this time, in step S101, two sets of programs with explanations other than the two sets that have already been processed are acquired.
  • the learning unit 11 determines whether the number of executions of steps S101 to S104 has reached a predetermined number of epochs (S105). If the number of executions is less than the predetermined number of epochs (No in S105), steps S101 and subsequent steps are repeated for all combinations. When the number of times of execution reaches the predetermined number of epochs (Yes in S105), the learning unit 11 ends learning of the similarity calculation model m1.
  • a learning end condition may be set for the convergence state of learning of the similarity calculation model m1 (for example, the difference between the similarity X and the similarity Y).
  • FIG. 6 is a flowchart for explaining an example of a processing procedure of automatic program generation processing.
  • step S201 the similar code search unit 12 extracts a sentence (hereinafter referred to as a "target description") describing the specification of a desired (to be generated) program (hereinafter referred to as a "target program”) in a natural language. get.
  • the target description may be input at the timing of step S201, or may be stored in advance in the auxiliary storage device 102 or the like.
  • FIG. 7 shows an example of the object description.
  • the similar code search unit 12 uses the learned similarity calculation model m1 to search for source codes with a relatively high similarity Y to the target description (hereinafter referred to as “similar codes”).
  • the data set is searched (S202).
  • the similar code search unit 12 uses the similarity calculation model m1 to calculate the similarity Y between each source code included in the search data set and the target description, and S (S ⁇ 1) source codes are identified as similar codes.
  • S (S ⁇ 1) source codes are identified as similar codes.
  • the degree of attention to each token of the source code for which the degree of similarity Y is to be calculated is calculated by the Attention layer L4 of the similarity degree calculation model m1.
  • the similar code search unit 12 outputs, for each similar code, the similar code and attention level information indicating the attention level of each token of the similar code.
  • FIG. 8 is a diagram showing how similar codes are searched.
  • the format of the attention level information is described below using a format based on the BNF notation.
  • ⁇ Attention information> :: [Token attention] +
  • attention level information is information in which attention levels in the range of 0 to 1 are given to each token in the form of "(attraction level)".
  • step S202 the description of each program with description in the search data set is not used. Therefore, the search target in step S202 may not be the same data set as in learning, and the search in step S202 may be performed on a mere set of source codes of a program.
  • the template generation unit 13 generates a source code as a template in which tokens whose degree of attention is equal to or higher than the threshold in the similar code are fixed portions (S203). If multiple similar codes are retrieved, multiple templates are generated.
  • FIG. 9 is a diagram illustrating an example of template generation.
  • FIG. 9 shows an example of template generation when the threshold for attention level is 0.7. In this case, "multiply" is fixed in the generated template.
  • the program synthesizing unit 14 uses each template generated by the template generating unit 13 as synthetic code (S204), and executes loop processing L1 including steps S205 and S206 for each synthetic code.
  • the synthesized code to be processed in the loop processing L1 will be referred to as "target code”.
  • step S205 the program synthesizing unit 14 compiles and links the target code to generate an executable program (hereinafter referred to as "synthesized program").
  • the program synthesizing unit 14 inputs each input/output example included in the input/output example set to the synthesizing program (hereinafter referred to as "target synthesizing program"), executes the subject synthesizing program, An output is obtained every time (S206).
  • FIG. 10 is a diagram illustrating an example of an input/output example set.
  • the input/output example set is information indicating conditions to be satisfied by the target program regarding input/output.
  • Each input/output example in the input/output example set includes an input value for the target program and an output value that the target program should output for that input.
  • the data structure of the input/output example set is described below in a format based on the BNF notation.
  • an input/output example set includes one or more input/output examples.
  • An input/output example is a set of input examples and output examples. An input example refers to one or more input values, and an output example refers to one or more output values.
  • the program synthesizing unit 14 executes the target synthesizing program using each of the M input values as an input in step S206. get output values.
  • the program synthesizing unit 14 determines whether there is a synthesizing program that satisfies all the input/output examples (S207). That is, it is determined whether or not there is a synthesized program for which all the output values obtained in step S206 were as expected (correct) among the synthesized programs to be processed in the loop processing L1.
  • the program synthesizing unit 14 randomly selects one or more program parts from the program parts list prepared in advance and stored in the auxiliary storage device 102, for example. , and by synthesizing (by replacing the non-fixed tokens with program parts) the parts that are not fixed (non-fixed tokens) in the template, multiple (for example, N ) is generated (S208).
  • FIG. 11 is a diagram showing an example of a program parts list.
  • the data structure of the program parts list shown in FIG. 11 is described below in a format based on the BNF notation.
  • ⁇ program part list> :: program part + That is, the program parts list includes (the source code of) one or more program parts.
  • program parts are classified into constants and methods.
  • one constant corresponds to one program part
  • one method corresponds to one program part. That is, the unit surrounded by the dashed line in FIG. 11 corresponds to the unit of one program part.
  • FIG. 12 is a diagram showing an example of a synthesized code generated using a template.
  • Each synthesized code in FIG. 12 includes fixed tokens shown in FIG. In other words, a new synthesized code is generated by synthesizing the fixed token and the program part.
  • each program part is represented by a tree structure with an operator as a parent node and a variable, constant, or operator to be operated by the operator as a child node. are replaced by tree structures of other program parts, these program parts can be synthesized.
  • the synthesized code like the program part, includes definitions such as inputting a value, executing a calculation on the input value, and outputting the calculation result of the value.
  • program synthesizing unit 14 repeats loop processing L1 and subsequent steps.
  • the program synthesizing unit 14 outputs synthesized code related to the synthesized program as the source code of the target program (S209).
  • the second synthesized code (hoge2) in FIG. 12 is output as the source code that satisfies the input/output example in FIG.
  • synthetic code is generated based on source code similar to the description of the desired specification. Furthermore, a synthesized code is generated by synthesizing a program part with respect to an important token that contributes highly to the degree of similarity (high degree of attention) in the source code. Therefore, important tokens can be prevented from being lost during synthesis, and as a result, the probability of generating a desired program can be improved.
  • the similar code search unit 12 is an example of a calculation unit.
  • the program synthesizer 14 is an example of a generator.
  • Program generation device 11 Learning unit 12 Similar code search unit 13 Template generation unit 14 Program synthesis unit 100 Drive device 101 Recording medium 102 Auxiliary storage device 103 Memory device 104 CPU 105 interface device 106 display device 107 input device B bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

プログラム生成装置は、所望のプログラムの仕様を自然言語で説明する文との類似度を、複数の第1のソースコードについて算出すると共に、前記第1のソースコードを構成する各トークンについて前記類似度の算出における注目度を算出する算出部と、前記類似度が相対的に高い前記第1のソースコードのうち、前記注目度が相対的に高いトークンと、予め用意された第2のソースコードとを合成して、複数の合成コードを生成する生成部と、を有することで、所望のプログラムが生成される確率を向上させる。

Description

プログラム生成装置、プログラム生成方法及びプログラム
 本発明は、プログラム生成装置、プログラム生成方法及びプログラムに関する。
 近年、社会全体のIT化が進む一方で、IT人材の不足が大きな問題となっている。経済産業省の試算によると、2025年には約36万人のIT人材が不足すると予測されている。特に、専門的な知識を必要とする実装工程におけるIT人材の不足は喫緊の課題であり、自動でプログラミングを行う自動プログラミング技術の研究開発が求められている。
 従来、生成したいプログラムの仕様を記述した自然言語と入出力例という2つの情報を用いることで、プログラムを自動生成する手法が存在する(非特許文献1)。非特許文献1では、まず、自然言語から類似プログラムの検索を行い、類似プログラムを取得する。続いて、そのプログラムをベースとして入出力例を満たすようにプログラム合成を行い、プログラムを自動生成する。非特許文献1の利点として、検索で取得した、正解プログラムに類似していると想定されるプログラムをひな形としてプログラム合成を行っているため、入出力例のみを用いたプログラム生成手法と比べて、オーバーフィットしたプログラムが生成されにくいといった点が挙げられる。
倉林 利行 他、"深層学習と遺伝的アルゴリズムを用いたプログラム自動生成"、ソフトウェアエンジニアリングシンポジウム2020論文集、[online]、インターネット<URL:https://ipsj.ixsq.nii.ac.jp/ej/index.php?active_action=repository_view_main_item_detail&page_id=13&block_id=8&item_id=206745&item_no=1>
 しかしながら、プログラム合成は入出力例を満たすように無作為にプログラム部品を組み合わせる技術であるため、正解プログラムに類似しているプログラムをひな形として用いた場合でも、ひな形中の変更すべきでないトークンも変更されてしまう可能性があり、その場合に、正解プログラム(所望のプログラム)が生成できない可能性がある。
 本発明は、上記の点に鑑みてなされたものであって、所望のプログラムが生成される確率を向上させることを目的とする。
 そこで上記課題を解決するため、プログラム生成装置は、所望のプログラムの仕様を自然言語で説明する文との類似度を、複数の第1のソースコードについて算出すると共に、前記第1のソースコードを構成する各トークンについて前記類似度の算出における注目度を算出する算出部と、前記類似度が相対的に高い前記第1のソースコードのうち、前記注目度が相対的に高いトークンと、予め用意された第2のソースコードとを合成して、複数の合成コードを生成する生成部と、を有する。
 所望のプログラムが生成される確率を向上させることができる。
本発明の実施の形態におけるプログラム生成装置10のハードウェア構成例を示す図である。 本発明の実施の形態におけるプログラム生成装置10の機能構成例を示す図である。 類似度算出モデルm1の学習処理の処理手順の一例を説明するためのフローチャートである。 検索用データセットの一例を示す図である。 類似度算出モデルm1の学習を説明するための図である。 プログラムの自動生成処理の処理手順の一例を説明するためのフローチャートである。 対象説明文の一例を示す図である。 類似コードの検索の様子を示す図である。 テンプレートの生成例を示す図である。 入出力例セットの一例を示す図である。 プログラム部品リストの一例を示す図である。 テンプレートを利用して生成される合成コードの一例を示す図である。
 以下、図面に基づいて本発明の実施の形態を説明する。図1は、本発明の実施の形態におけるプログラム生成装置10のハードウェア構成例を示す図である。図1のプログラム生成装置10は、それぞれバスBで相互に接続されているドライブ装置100、補助記憶装置102、メモリ装置103、CPU104、インタフェース装置105、表示装置106、及び入力装置107等を有する。
 プログラム生成装置10での処理を実現するプログラムは、CD-ROM等の記録媒体101によって提供される。プログラムを記憶した記録媒体101がドライブ装置100にセットされると、プログラムが記録媒体101からドライブ装置100を介して補助記憶装置102にインストールされる。但し、プログラムのインストールは必ずしも記録媒体101より行う必要はなく、ネットワークを介して他のコンピュータよりダウンロードするようにしてもよい。補助記憶装置102は、インストールされたプログラムを格納すると共に、必要なファイルやデータ等を格納する。
 メモリ装置103は、プログラムの起動指示があった場合に、補助記憶装置102からプログラムを読み出して格納する。CPU104は、メモリ装置103に格納されたプログラムに従ってプログラム生成装置10に係る機能を実現する。インタフェース装置105は、ネットワークに接続するためのインタフェースとして用いられる。表示装置106はプログラムによるGUI(Graphical User Interface)等を表示する。入力装置107はキーボード及びマウス等で構成され、様々な操作指示を入力させるために用いられる。
 図2は、本発明の実施の形態におけるプログラム生成装置10の機能構成例を示す図である。図2において、プログラム生成装置10は、学習部11、類似コード検索部12、テンプレート生成部13及びプログラム合成部14を有する。これら各部は、プログラム生成装置10にインストールされた1以上のプログラムが、CPU104に実行させる処理により実現される。
 なお、図2における類似度算出モデルm1とは、プログラムの仕様を自然言語で説明する文(説明文)と、プログラムのソースコードとの類似度を算出するモデル(ニューラルネットワーク)である。
 以下、プログラム生成装置10が実行する処理手順について説明する。図3は、類似度算出モデルm1の学習処理の処理手順の一例を説明するためのフローチャートである。
 ステップS101において、学習部11は、例えば、補助記憶装置102に記憶されている検索用データセットから無作為に2つ(2組)の説明文付きプログラムを取得する。
 図4は、検索用データセットの一例を示す図である。図4において、破線で囲まれた単位が、1つの説明文付きプログラムである。説明文付きプログラムは、プログラムのソースコードと、当該プログラムの仕様を自然言語(本実施の形態では日本語)で説明する文(説明文)とを対応付けて含むデータをいう。すなわち、検索用データセットのデータ構造をBNF(Backus-Naur form)記法に基づく形式によって記すと以下の通りである。
<検索用データセット>::=[説明文 ソースコード]+
 複数の説明文付きプログラムが予め検索用データセットとして用意されている。ステップS101では、複数の説明文付きプログラムの中から、無作為に2つの説明文付きプログラムの組が取得される。但し、2回目以降のステップS101では、既に取得された組み合わせ以外の2組が取得される。なお、類似度算出モデルm1の学習処理において、検索用データセットは、類似度算出モデルm1の学習用データセットとして利用される。
 続いて、学習部11は、2つの説明文付きプログラムのそれぞれに含まれるソースコードの構造の類似度(以下、「類似度X」という。)を算出する(S102)。例えば、Tree Edit Distanceが類似度Xの指標として用いられてもよい。
 続いて、学習部11は、2つの説明文付きプログラムのうちの一方の説明文付きプログラムの説明文をベクトル化した結果と、他方の説明文付きプログラムのソースコードをベクトル化した結果とのコサイン類似度(以下、「類似度Y」という。)が、類似度Xに近付くように(例えば、類似度Yと類似度Xとの差分が小さくなるように)類似度算出モデルm1を学習(類似度算出モデルm1のモデルパラメータを更新)する(S103)。類似度算出モデルm1は、深層学習モデルを用いたプログラム検索手法などで使用されるモデル等を用いて実現することができる。当該モデルは、「Yao Wan, Jingdong Shu, Yulei Sui, Guandong Xu, Zhou Zhao, Jian Wu, and Philip S. Yu. Multi-modal attention network learning for semantic source code retrieval. In Proceedings of the 34th IEEE/ACM International Con-ference on Automated Software Engineering, ASE '19,p. 13{25. IEEE Press, 2019.URL:https://dl.acm.org/doi/abs/10.1109/ASE.2019.00012」に詳しい。
 図5は、類似度算出モデルm1の学習を説明するための図である。図5に示されるように、類似度算出モデルm1は、ニューラルネットワークL1、Attention層L2、ニューラルネットワークL3及びAttention層L4等を含む。
 ニューラルネットワークL1は、説明文の各単語を所定次元数(例えば、512次元)のベクトル(以下、「ベクトルv1」という。)へ変換するニューラルネットワークである。例えば、説明文がJ個の単語を含めば、J個のベクトルv1がニューラルネットワークL1から出力される。
 Attention層L2は、J個のベクトルv1を入力とし、1つのベクトル(以下、「ベクトルv2」という。)を出力するニューラルネットワークである。Attention層L2は、Attention層L2の重みパラメータによって、各ベクトルv1に対して重み付けを行って、1つのベクトルv2を生成する。
 ニューラルネットワークL2は、ソースコードの各トークンを所定次元数(例えば、512次元)のベクトル(以下、「ベクトルv3」という。)へ変換するニューラルネットワークである。例えば、説明文がK個のトークンを含めば、K個のベクトルv2がニューラルネットワークL2から出力される。
 Attention層L4は、K個のベクトルv3を入力とし、1つのベクトル(以下、「ベクトルv4」という。)を出力するニューラルネットワークである。Attention層L4は、Attention層L4の重みパラメータによって、各ベクトルv1及び各ベクトルv3に対して重み付けを行って、1つのベクトルv4を生成する。この重み付けにおける重みのうち、各ベクトルv3に対する重みが、ベクトルv4の算出における(ひいては類似度Yの算出における)、ソースコードの各トークンに対する注目度に相当する。
 ステップS103において、学習部11は、ベクトルv2とベクトルv4とのコサイン類似度(類似度Y)が類似度Xに近付くように、ニューラルネットワークL1、ニューラルネットワークL2、Attention層L3及びAttention層L4を学習する。
 続いて、学習部11は、検索用データセットにおける説明文付きプログラムの全通りの2組についてステップS101以降が実行されたか否かを判定する(S104)。未処理の2組が有る場合(S104でNo)、ステップS101以降が繰り返される。この際、ステップS101では、既に処理対象とされた2組以外の2組の説明文付きプログラムが取得される。
 全通りの2組ついてステップS101以降が実行されると(S104でYes)、学習部11は、ステップS101~S104の実行回数が所定のエポック数に達したか否かを判定する(S105)。当該実行回数が所定のエポック数未満である場合(S105でNo)、ステップS101以降が全ての組み合わせについて繰り返される。当該実行回数が所定のエポック数に達した場合(S105でYes)、学習部11は、類似度算出モデルm1の学習を終了する。なお、類似度算出モデルm1の学習の収束状況(例えば、類似度Xと類似度Yとの差分)に対して学習の終了条件が設定されてもよい。
 類似度算出モデルm1の学習が終了すると、図6の処理手順の実行が可能となる。図6は、プログラムの自動生成処理の処理手順の一例を説明するためのフローチャートである。
 ステップS201において、類似コード検索部12は、所望の(生成対象の)プログラム(以下、「対象プログラム」という。)の仕様を自然言語で記述した文(以下、「対象説明文」という。)を取得する。対象説明文は、ステップS201のタイミングで入力されてもよいし、予め補助記憶装置102等に記憶されていてもよい。図7に、対象説明文の一例を示す。
 続いて、類似コード検索部12は、学習済みの類似度算出モデルm1を利用して、対象説明文との類似度Yが相対的に高いソースコード(以下、「類似コード」という)を検索用データセットの中から検索する(S202)。具体的には、類似コード検索部12は、類似度算出モデルm1を利用して、検索用データセットに含まれる各ソースコードと対象説明文との類似度Yを算出し、類似度Yが上位S件(S≧1)のソースコードを類似コードとして特定する。なお、類似度Yの算出の過程において、類似度Yの算出対象とされたソースコードの各トークンに対する注目度が、類似度算出モデルm1のAttention層L4によって算出される。類似コード検索部12は、類似コードごとに、当該類似コードと、当該類似コードの各トークンの注目度を示す注目度情報とを出力する。
 図8は、類似コードの検索の様子を示す図である。注目度情報の形式をBNF記法に基づく形式によって記すと以下の通りである。
<注目度情報>::=[トークン 注目度]+
 図8の例において、注目度情報は、各トークンに対して「(注目度)」の形式で、0~1の範囲の注目度が付与された情報である。
 なお、ステップS202では、検索用データセットの各説明文付きプログラムの説明文は利用されない。したがって、ステップS202の検索対象は、学習時と同じデータセットでなくてもよく、単なるプログラムのソースコードの集合に対してステップS202の検索が行われてもよい。
 続いて、テンプレート生成部13は、類似コードにおいて注目度が閾値以上であるトークンを固定部分としたソースコードを、テンプレートとして生成する(S203)。類似コードが複数検索されている場合、複数のテンプレートが生成される。
 図9は、テンプレートの生成例を示す図である。図9には、注目度に対する閾値が0.7である場合のテンプレートの生成例が示されている。この場合、生成されるテンプレートにおいて、「multiply」が固定される。テンプレートの形式をBNF記法に基づく形式によって記すと以下の通りである。
<テンプレート>::=[固定トークン or 非固定トークン]+
 図9では、下線部分が固定トークンに相当し、それ以外が非固定トークンに相当する。なお、固定トークンであるか否かは、下線の付与以外の方法によって識別されてもよい。
 続いて、プログラム合成部14は、テンプレート生成部13によって生成された各テンプレートを合成コードとして(S204)、ステップS205及びS206を含むループ処理L1を合成コードごとに実行する。以下、ループ処理L1において処理対象とされている合成コードを「対象コード」という。
 ステップS205において、プログラム合成部14は、対象コードをコンパイル及びリンク等することで、実行形式のプログラム(以下「合成プログラム」という。)を生成する。
 続いて、プログラム合成部14は、当該合成プログラム(以下「対象合成プログラム」という。)に対し、入出力例セットに含まれる各入出力例を入力して対象合成プログラムを実行し、入出力例ごとに出力を得る(S206)。
 図10は、入出力例セットの一例を示す図である。入出力例セットは、入出力に関して対象プログラムが満たすべき条件を示す情報である。入出力例セットの各入出力例は、対象プログラムに対する入力の値と、当該入力に対して対象プログラムが出力すべき出力の値とを含む。なお、入出力例セットのデータ構造をBNF記法に基づく形式によって記すと以下の通りである。
<入出力例セット>::=<入出力例>+
<入出力例>::=<入力例><出力例>
<入力例>::=入力値+
<出力例>::=出力値+
 すなわち、入出力例セットは1以上の入出力例を含む。1つの入出力例は入力例及び出力例の組である。入力例とは1以上の入力値をいい、出力例とは1以上の出力値をいう。
 例えば、入出力例セットに含まれる入出力例がM個である場合、プログラム合成部14は、ステップS206において、M個の入力値ごとに当該入力値を入力として対象合成プログラムを実行し、M個の出力値を得る。
 ループ処理L1が終了すると、プログラム合成部14は、全ての入出力例を満たす合成プログラムの有無を判定する(S207)。すなわち、ループ処理L1において処理対象とされた合成プログラムの中で、ステップS206において得られた全ての出力値が期待通りであった(正しかった)合成プログラムの有無が判定される。
 該当する合成プログラムが無い場合(S207でNo)、プログラム合成部14は、例えば、予め用意されて補助記憶装置102に記憶されているプログラム部品リストの中の1以上のプログラム部品を、例えば、ランダムに選択して、テンプレートにおいて固定されていない部分(非固定トークン)に対して合成することで(非固定トークンをプログラム部品によって置換することで)、1つのテンプレートに基づいて複数(例えば、N個)の合成コードを生成する(S208)。
 図11は、プログラム部品リストの一例を示す図である。図11に示されるプログラム部品リストのデータ構造をBNF記法に基づく形式によって記すと以下の通りである。
<プログラム部品リスト>::=プログラム部品+
 すなわち、プログラム部品リストは、1以上のプログラム部品(のソースコード)を含む。図11では、定数とメソッドとにプログラム部品が分類されている。ここで、1つの定数が1つのプログラム部品に相当し、1つのメソッドが1つのプログラム部品に相当する。すなわち、図11において破線で囲まれた単位が、1つのプログラム部品の単位に相当する。
 また、図12は、テンプレートを利用して生成される合成コードの一例を示す図である。図12の各合成コードは、図9に示した固定トークンを含む。換言すれば、当該固定トークンと、プログラム部品との合成によって新たな合成コードが生成される。
 なお、プログラム部品の合成とは、複数のプログラム部品の計算が組み合わされることをいい、例えば、遺伝的プログラミング等の公知技術を用いて行うことができる。例えば、各プログラム部品を、演算子を親ノードとし、当該演算子による演算対象である変数、定数、又は演算子を子ノードとする木構造によって表現し、いずれかのプログラム部品の木構造のノードを、他のプログラム部品の木構造によって置換することで、これらのプログラム部品を合成することができる。なお、合成コードは、プログラム部品と同様に、値を入力とし、入力された値に関する計算を実行し、値の計算結果を出力するといった定義を含む。
 続いて、プログラム合成部14は、ループ処理L1以降を繰り返す。
 一方、全ての入出力例を満たす合成プログラムが生成されると(S207でYes)、プログラム合成部14は、当該合成プログラムに係る合成コードを、対象プログラムのソースコードとして出力する(S209)。本実施の形態では、図10の入出力例を満たすソースコードとして、図12の2番目の合成コード(hoge2)が出力される。
 上述したように、本実施の形態によれば、所望の仕様の説明文に類似するソースコードに基づいて合成コードが生成される。更に、当該ソースコードのうち、類似度に対する寄与が高い(注目度が高い)重要なトークンに対してプログラム部品が合成されて合成コードが生成される。したがって、重要なトークンが合成時に失われることを防ぐことができ、結果として所望のプログラムが生成される確率を向上させることができる。
 なお、本実施の形態において、類似コード検索部12は、算出部の一例である。プログラム合成部14は、生成部の一例である。
 以上、本発明の実施の形態について詳述したが、本発明は斯かる特定の実施形態に限定されるものではなく、請求の範囲に記載された本発明の要旨の範囲内において、種々の変形・変更が可能である。
10     プログラム生成装置
11     学習部
12     類似コード検索部
13     テンプレート生成部
14     プログラム合成部
100    ドライブ装置
101    記録媒体
102    補助記憶装置
103    メモリ装置
104    CPU
105    インタフェース装置
106    表示装置
107    入力装置
B      バス

Claims (7)

  1.  所望のプログラムの仕様を自然言語で説明する文との類似度を、複数の第1のソースコードについて算出すると共に、前記第1のソースコードを構成する各トークンについて前記類似度の算出における注目度を算出する算出部と、
     前記類似度が相対的に高い前記第1のソースコードのうち、前記注目度が相対的に高いトークンと、予め用意された第2のソースコードとを合成して、複数の合成コードを生成する生成部と、
    を有することを特徴とするプログラム生成装置。
  2.  前記算出部は、プログラムの仕様を自然言語で説明する文とプログラムのソースコードとの類似度と、当該ソースコードを構成する各トークンについて前記類似度の算出における注目度とを算出するニューラルネットワークを用いて、前記所望のプログラムの仕様を自然言語で説明する文と、前記第1のソースコードとの類似度と、前記第1のソースコードを構成する各トークンの注目度とを算出する、
    ことを特徴とする請求項1記載のプログラム生成装置。
  3.  プログラムのソースコードと当該プログラムの仕様を自然言語で説明する文との組を含む学習用データの集合のうちの第1の学習用データの文と第2の学習用データのソースコードとについて前記ニューラルネットワークが算出する前記類似度が、前記第1の学習用データの前記ソースコードと第2の学習用データのソースコードとの類似度に近付くように前記ニューラルネットワークを学習する学習部、
    を有することを特徴とする請求項2記載のプログラム生成装置。
  4.  所望のプログラムの仕様を自然言語で説明する文との類似度を、複数の第1のソースコードについて算出すると共に、前記第1のソースコードを構成する各トークンについて前記類似度の算出における注目度を算出する算出手順と、
     前記類似度が相対的に高い前記第1のソースコードのうち、前記注目度が相対的に高いトークンと、予め用意された第2のソースコードとを合成して、複数の合成コードを生成する生成手順と、
    をコンピュータが実行することを特徴とするプログラム生成方法。
  5.  前記算出手順は、プログラムの仕様を自然言語で説明する文とプログラムのソースコードとの類似度と、当該ソースコードを構成する各トークンについて前記類似度の算出における注目度とを算出するニューラルネットワークを用いて、前記所望のプログラムの仕様を自然言語で説明する文と、前記第1のソースコードとの類似度と、前記第1のソースコードを構成する各トークンの注目度とを算出する、
    ことを特徴とする請求項4記載のプログラム生成方法。
  6.  プログラムのソースコードと当該プログラムの仕様を自然言語で説明する文との組を含む学習用データの集合のうちの第1の学習用データの文と第2の学習用データのソースコードとについて前記ニューラルネットワークが算出する前記類似度が、前記第1の学習用データの前記ソースコードと第2の学習用データのソースコードとの類似度に近付くように前記ニューラルネットワークを学習する学習手順、
    をコンピュータが実行することを特徴とする請求項5記載のプログラム生成方法。
  7.  請求項4乃至6いずれか一項記載のプログラム生成方法をコンピュータに実行させることを特徴とするプログラム。
PCT/JP2021/018183 2021-05-13 2021-05-13 プログラム生成装置、プログラム生成方法及びプログラム WO2022239179A1 (ja)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/JP2021/018183 WO2022239179A1 (ja) 2021-05-13 2021-05-13 プログラム生成装置、プログラム生成方法及びプログラム

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2021/018183 WO2022239179A1 (ja) 2021-05-13 2021-05-13 プログラム生成装置、プログラム生成方法及びプログラム

Publications (1)

Publication Number Publication Date
WO2022239179A1 true WO2022239179A1 (ja) 2022-11-17

Family

ID=84028538

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2021/018183 WO2022239179A1 (ja) 2021-05-13 2021-05-13 プログラム生成装置、プログラム生成方法及びプログラム

Country Status (1)

Country Link
WO (1) WO2022239179A1 (ja)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0553780A (ja) * 1991-08-28 1993-03-05 Nec Corp プログラム自動合成装置

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0553780A (ja) * 1991-08-28 1993-03-05 Nec Corp プログラム自動合成装置

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
KURABAYASHI, TOSHIYUKI ET AL.: "Automatic program generation using deep learning and genetic algorithm", PROCEEDINGS OF IPSJ/SIGSE SOFTWARE ENGINEERING SYMPOSIUM (SES2020), vol. 2020, 2020, pages 143 - 152, XP009541421 *
TOSHIYUKI KURABAYASHI, YU YOSHIMURA, HIROYUKI KIRINUKI, HARMON TANNO, YUUYA TOMITA, JUNNOSUKE MATSUMOTO, MAYU MATSUMOTO, YOSHIKI H: "Automatic program generation using past implementation information", IPSJ TECHNICAL REPORT: SOFTWARE ENGINEERING (SE), INFORMATION PROCESSING SOCIETY OF JAPAN, vol. 2020- SE, no. 2020-SE-204, 27 February 2020 (2020-02-27), JP, pages 1 - 8, XP009541058 *
WAKATAKE, YOSHINORI; AYAKA, OZAWA; FUMIKO, HARADA; HIROMITSU, SHIMAKAWA: "B-006 Mapping of source code with document using word2vec", PROCEEDINGS OF 19TH FORUM ON INFORMATION TECHNOLOGY (FIT2020), vol. 19, 30 November 2019 (2019-11-30), pages 113 - 114, XP009541422 *

Similar Documents

Publication Publication Date Title
Law et al. The ilasp system for inductive learning of answer set programs
CN113283613B (zh) 深度学习模型的生成方法、优化方法、装置、设备及介质
CN111443964B (zh) 更新用户界面的方法、设备和计算机可读存储介质
JP6663873B2 (ja) プログラム自動生成システム及びプログラム自動生成方法
US20230089227A1 (en) Program generation apparatus, program generation method and program
US11341127B2 (en) Information processing system, information processing apparatus, information processing method, and information processing program
JP6312467B2 (ja) 情報処理装置、情報処理方法、およびプログラム
CN112764738A (zh) 基于多视图程序特征的代码自动生成方法及系统
JP2020060922A (ja) ハイパーパラメータチューニング方法、装置及びプログラム
JP7351352B2 (ja) プログラム生成装置、プログラム生成方法及びプログラム
Rodriguez et al. Comparison of information retrieval techniques for traceability link recovery
CN113065322B (zh) 一种代码段注释生成方法、系统及可读存储介质
Moraglio et al. Evolving recursive programs using non-recursive scaffolding
WO2022239179A1 (ja) プログラム生成装置、プログラム生成方法及びプログラム
US20230107200A1 (en) Program generation apparatus, program generation method and program
WO2022230190A1 (ja) プログラム生成装置、プログラム生成方法及びプログラム
JP6698061B2 (ja) 単語ベクトル変換装置、方法、及びプログラム
Rodriguez et al. An IR-based artificial bee colony approach for traceability link recovery
JPH0765022A (ja) 質問回答方法および装置
CN113448852A (zh) 一种测试案例的获取方法、装置、电子设备及存储介质
CN115033884A (zh) 基于危险函数参数依赖的二进制代码漏洞检测方法
Schmelter et al. Toward learning realizable scenario-based, formal requirements specifications
JP5530469B2 (ja) 自然言語解析処理装置、方法、及びプログラム
WO2021161428A1 (ja) プログラム生成装置、プログラム生成方法及びプログラム
JPWO2011016281A1 (ja) ベイジアンネットワーク構造学習のための情報処理装置及びプログラム

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21941913

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 18558200

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21941913

Country of ref document: EP

Kind code of ref document: A1