Program generation device, program generation system, program generation method, and program generation program

JP7898653B1Active Publication Date: 2026-07-31MITSUBISHI ELECTRIC CORP
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
MITSUBISHI ELECTRIC CORP
Filing Date
2025-09-22
Publication Date
2026-07-31

AI Technical Summary

Benefits of technology

【0007】 本開示では、修正指示情報と基準コードとを学習済モデルに入力として、基準コードに対して修正を加えた修正後コードを生成させる。これにより、ユーザがプログラム全体の 仕様を把握することなく、修正を反映したプログラムのソースコードを生成可能である。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007898653000001
    Figure 0007898653000001
  • Figure 0007898653000002
    Figure 0007898653000002
  • Figure 0007898653000003
    Figure 0007898653000003
Patent Text Reader

Abstract

The input prompt generation unit (22) generates an input prompt that includes correction instruction information indicating the content of the correction, a reference code which is the source code of the program before the correction is made, and an instruction to generate a corrected code which is the source code with the content of the correction instruction information applied to the reference code. The program correction unit (23) inputs the input prompt to the trained model and obtains the corrected code generated by the trained model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to a technique for modifying an existing program.

Background Art

[0002] In the process of program development, it is often required to modify the specifications of existing programs. There is a need for a technique to assist users in modifying programs for the purpose of reducing man-hours. When changing the specifications of a program, specialized knowledge regarding the grammar and algorithms of the programming language is required. Therefore, it is difficult for users without specialized knowledge to make modifications.

[0003] Patent Document 1 describes a technique for generating a program from a program specification described in natural language. In Patent Document 1, a program is generated from a program specification using a program creation model learned using teacher data that associates the program specification with the generated program result.

Prior Art Documents

Patent Documents

[0004]

Patent Document 1

Summary of the Invention

Problems to be Solved by the Invention

[0005] Patent Document 1 does not describe modifying an existing program. When generating the source code of a program that reflects the modification using the technique described in Patent Document 1, it is necessary to prepare specification data indicating the specifications of the entire program including the modified specifications. For users without specialized knowledge, understanding the specifications of an entire program can be difficult. Therefore, there is a risk of omissions or errors when creating specification data that outlines the overall program specifications, potentially resulting in inaccurate specification data. Without proper specification data, it becomes impossible to generate a program that retains the original specifications while incorporating the intended modifications. This disclosure aims to enable the generation of program source code that reflects the modifications without requiring an understanding of the overall program specifications. [Means for solving the problem]

[0006] The program generation device related to this disclosure is An input prompt generation unit generates an input prompt that includes correction instruction information indicating the content of the correction, a reference code which is the source code of the program before the correction is made, and an instruction to generate a corrected code which is the source code which has been modified according to the content of the correction instruction information applied to the reference code. A program modification unit inputs the input prompt generated by the input prompt generation unit into a trained model and obtains the modified code generated by the trained model. It is equipped with. [Effects of the Invention]

[0007] In this disclosure, the correction instruction information and the reference code are input to a trained model, which generates a modified code by applying the modifications to the reference code. This allows the user to understand the entire program. It is possible to generate program source code that reflects the modifications without needing to understand the specifications. [Brief explanation of the drawing]

[0008] [Figure 1] Configuration diagram of the program generation system 100 according to Embodiment 1. [Figure 2] Configuration diagram of the program generation device 10 according to Embodiment 1. [Figure 3]Flowchart showing the processing flow of the program generation device 10 according to Embodiment 1. [Figure 4] Explanatory diagram of the input prompt 34 according to Embodiment 1. [Figure 5] Explanatory diagram of the input prompt 34 according to Modification 2. [Figure 6] Configuration diagram of the program generation device 10 according to Embodiment 2. [Figure 7] Flowchart showing the processing flow of the program generation device 10 according to Embodiment 2. <H [Figure 8] Explanatory diagram of the reference information 35 according to Embodiment 2. [Figure 9] Flowchart of the reference information search process according to Embodiment 2. [Figure 10] Explanatory diagram of the reference information search process according to Embodiment 2. <H [Figure 11] Explanatory diagram of the input prompt 34 according to Embodiment 2. [Figure 12] Configuration diagram of the program generation device 10 according to Embodiment 3. [Figure 13] Flowchart showing the processing flow of the program generation device 10 according to Embodiment 3. [Figure 14] Explanatory diagram of the input prompt 34 according to Embodiment 3. [Figure 15] Diagram showing an example of the processing of the program generation device 10 according to Embodiment 3. [Figure 16] Configuration diagram of the program generation device 10 according to Embodiment 4. [Figure 17] Flowchart showing the processing flow of the program generation device 10 according to Embodiment 4. [Figure 18] Flowchart of the relationship identification process according to Embodiment 4. [Figure 19] Explanatory diagram of the symbol table generation process according to Embodiment 4. [Figure 20] Explanatory diagram of the input prompt 34 according to Embodiment 4. [Figure 21] Explanatory diagram of the effects according to Embodiment 4. [Figure 22]Explanatory diagram of the effects according to Embodiment 4. [Figure 23] Explanatory diagram of the effects according to Embodiment 4. [Figure 24] Configuration diagram of the program generation device 10 according to Embodiment 5. [Figure 25] Flowchart showing the processing flow of the program generation device 10 according to Embodiment 5.

Modes for Carrying Out the Invention

[0009] Embodiment 1. ***Explanation of Configuration*** Referring to FIG. 1, the configuration of the program generation system 100 according to Embodiment is described. The program generation system 100 includes a program generation device and an input terminal 51 and an output terminal 52. The program generation system 100 is a computer such as a server. The input terminal 51 and the output terminal 52 are computers such as a PC. PC is an abbreviation for Personal Computer. The input terminal 101 inputs correction instruction information 31 indicating the content of the correction and reference code 32 which is the source code of the program before the correction to the program generation device 10. The program generation device 10 causes the learned model 60 to generate a corrected code 33 which is the source code with the correction of the content indicated by the correction instruction information 31 added to the reference code 32. The program generation device 1 outputs the corrected code 33 to the output terminal 52.

[0010] The learned model 60 outputs relevant text information for an input prompt, which is This is a loosely generated AI. AI stands for Artificial Intelligence. The trained model 60 may be constructed using algorithms such as BERT and GPT, as concrete examples. BERT stands for Bidirectional Encoder Representations from Transformers. GPT stands for Generative Pretrained Transformer. The trained model 60 may be constructed by combining multiple algorithms, including these algorithms. The trained model 60 may be a model that operates over the internet or a model that operates in an on-premises environment.

[0011] Referring to Figure 2, the configuration of the program generation device 10 according to Embodiment 1 will be described. The program generation device 10 comprises hardware including a processor 11, memory 12, storage 13, and a communication interface 14. The processor 11 is connected to the other hardware via signal lines and controls this other hardware.

[0012] Processor 11 is an IC that performs processing. IC stands for Integrated Circuit. Specific examples of processor 11 include CPU, DSP, and GPU. CPU stands for Central Processing Unit. DSP stands for Digital Signal Processor. GPU stands for Graphics Processing Unit.

[0013] Memory 12 is a storage device that temporarily stores data. Specific examples of memory 12 include SRAM and DRAM. SRAM stands for Static Random Access Memory. DRAM stands for Dynamic Random Access Memory.

[0014] Storage 13 is a storage device for storing data. Specific examples of storage 13 include HDDs and SSDs. HDD stands for Hard Disk Drive. SSD stands for Solid State Drive. Storage 13 may also be a portable recording medium such as an SD® memory card, CompactFlash®, NAND flash, flexible disk, optical disk, compact disk, Blu-ray® disc, or DVD. SD stands for Secure Digital. DVD stands for Digital Versatile Disk.

[0015] Communication interface 14 is an interface for communicating with external devices. Specific examples of communication interface 14 include Ethernet®, USB, and HDMI® ports. USB stands for Universal Serial Bus. HDMI stands for High-Definition Multimedia Interface.

[0016] The program generation device 10 comprises, as functional components, an input data acquisition unit 21, an input prompt generation unit 22, a program modification unit 23, and a modified code output unit 24. The functions of each functional component of the program generation device 10 are implemented by software. Storage 13 stores programs that realize the functions of each functional component of the program generation device 10. These programs are loaded into memory 12 by the processor 11 and executed by the processor 11. This realizes the functions of each functional component of the program generation device 10.

[0017] In Figure 2, only one processor 11 was shown. However, there are multiple processors 11. It may be a number, or multiple processors 11 may work together to execute programs that implement each function.

[0018] ***Explanation of operation*** The operation of the program generation device 10 according to Embodiment 1 will be explained with reference to Figures 3 and 4. The operation procedure of the program generation device 10 according to Embodiment 1 corresponds to the program generation method according to Embodiment 1. Furthermore, the program that realizes the operation of the program generation device 10 according to Embodiment 1 corresponds to the program generation program according to Embodiment 1.

[0019] Referring to Figure 3, the processing flow of the program generation device 10 according to Embodiment 1 will be explained. (Step S11: Input data acquisition process) The input data acquisition unit 21 acquires the modification instruction information 31 and the reference code 32 entered by the user via the input terminal 51 through the communication interface 14. The modification instruction information 31 is text data describing the content of the modification to the program's behavior. For example, the modification instruction information 31 is text data describing the content of the modification in natural language. The reference code 32 is text data of the source code to be modified. For example, the reference code 32 is text data of the version of the source code before the modification is made to the program to be generated.

[0020] (Step S12: Input prompt generation process) The input prompt generation unit 22 generates an input prompt 34 from the correction instruction information 31 and the reference code 32 entered in step S11. Specifically, the input prompt generation unit 22 generates an input prompt 34 as shown in Figure 4. In Figure 4, {correction instruction information} is replaced with correction instruction information 31. Similarly, {reference code} is replaced with reference code 32. In other words, the input prompt generation unit 22 generates an input prompt 34 that includes the correction instruction information 31 and the reference code 32, and an instruction to generate a modified code 33, which is a source code that modifies the reference code 32 according to the content indicated by the correction instruction information 31.

[0021] (Step S13: Program modification process) The program modification unit 23 inputs the input prompt 34 generated in step S12 to the trained model 60. In this case, if the trained model 60 is located outside the program generation device 10, such as on the internet, the program modification unit 23 transmits the input prompt 34 to the trained model 60 via the communication interface 14.

[0022] (Step S14: Process to obtain the corrected code) The program modification unit 23 obtains the modified code 33 generated by the trained model 60 in response to the input prompt 34 entered in step S13.

[0023] (Step S15: Outputting corrected code) The modified code output unit 24 outputs the modified code 33 obtained in step S14. Specifically, the modified code output unit 24 outputs the modified code 33 to the storage 13 for storage. The modified code output unit 24 also outputs the modified code 33 to the output terminal 52 via the communication interface 14 for display. In this case, the modified code output unit 24 may output the modified code 33 while indicating the changes from the reference code 32.

[0024] ***Effects of Embodiment 1*** As described above, the program generation device 10 according to Embodiment 1 takes the modification instruction information 31 and the reference code 32 as input to the learned model 60 and generates a modified code 33 by modifying the reference code 32. This makes it possible for the user to generate source code of a program that reflects the modifications without having to understand the specifications of the entire program.

[0025] In particular, the program generation device 10 according to Embodiment 1 generates the modified code 33 using the trained model 60, and therefore can provide instructions using modification instruction information 31 written in natural language.

[0026] Alternatively, instead of using the pre-trained model 60, it is also possible to generate the modified code 33 from the modification instruction information 31 using a rule-based approach. In this case, for example, it is necessary to set up a large number of conversion rules in proportion to the number of combinations of elements such as morphemes and words that may appear in the modification instruction information 31. Therefore, setting up conversion rules becomes difficult when natural language is used as the modification instruction information 31.

[0027] Alternatively, it is possible to generate the modified code 33 using the trained model 60 without inputting the reference code 32. In this case, in order to generate the input prompt 34 to be input to the trained model 60, the entire specification of the reference code 32 to be modified must be described in the input prompt 34. Therefore, this would be difficult to implement if the user does not understand the entire specification of the reference code 32.

[0028] ***Other configurations*** <Example 1> In Embodiment 1, the corrected code 33 was output. To verify the correctness of the corrected code 33, it is effective to look at the results of executing the corrected code 33. Therefore, the corrected code 33 may be executed and the obtained results may be output. In this case, the program generation device 10 includes a program execution unit that executes the modified code 33, and a result output unit that outputs the execution result obtained when the modified code 33 is executed by the program execution unit. For example, the program execution unit may take one or more pre-prepared test data as input, execute the modified code 33, and obtain the execution result. This makes it possible to obtain the execution result corresponding to each test data.

[0029] <Modification 2> In Embodiment 1, the input prompt 34 was generated using the correction instruction information 31 as is. Alternatively, the input prompt 34 may be generated from the result of some processing performed on the correction instruction information 31. In this case, step S12 in Figure 3 is modified as follows, for example.

[0030] As the first step, the input prompt generation unit 22 extracts three elements from the text of the correction instruction information 31 entered in step S11: the intention to correct, the target of correction, and the purpose of correction. Possible extraction methods include a rule-based approach that determines if a string matches a specific element, and a pre-trained model that extracts three elements using an input prompt. In this case, the extraction result may be one element or two or more elements. Furthermore, if the input prompt generation unit 22 cannot extract any element from the text of the correction instruction information 31, it will complete the element. Possible completion methods include using the text of the correction instruction information 31 as a query to search a vector database in which descriptions of elements have been stored in advance. Alternatively, completion methods include using the text of the correction instruction information 31 and the reference code 32 as input to generate the corresponding element using a trained model.

[0031] Next, in the second process, the input prompt generation unit 22 generates an input prompt 34 from the three elements extracted: the intention to modify, the target to modify, and the purpose of the modification, along with the reference code 32. Specifically, the input prompt generation unit 22 generates an input prompt 34 as shown in Figure 5. In Figure 5, {Modification Intent} is substituted with the extracted modification intent. Similarly, {Modification Target} is substituted with the extracted modification target. Similarly, {Modification Objective} is substituted with the extracted modification target. Similarly, {Reference Code} is substituted with the reference code 32. In other words, the input prompt generation unit 22 generates an input prompt 34 that includes the three elements of the extracted modification intent, modification target, and modification objective, the reference code 32, and an instruction to generate a modified code 33, which is the source code that has been modified to reflect the content indicated by the three elements relative to the reference code 32.

[0032] Embodiment 2. Embodiment 2 differs from Embodiment 1 in that it searches for reference information 35 and includes it in the input prompt 34. Embodiment 2 explains this difference and omits the points of similarity.

[0033] ***Explanation of the structure*** Referring to Figure 6, the configuration of the program generation device 10 according to Embodiment 2 will be described. The program generation device 10 differs from the program generation device 10 shown in Figure 2 in that it includes a reference information retrieval unit 25 as a functional component. The reference information retrieval unit 25, like the other functional components, is implemented by software.

[0034] ***Explanation of operation*** Referring to Figures 7 and 7, the processing flow of the program generation device 10 according to Embodiment 2 will be explained. The process in step S21 is the same as the process in step S11 in Figure 3. The processes in steps S24 to S26 are the same as the processes in steps S13 to S15 in Figure 3.

[0035] (Step S22: Reference information retrieval process) The reference information retrieval unit 25 searches for reference information 35 based on the correction instruction information 31 entered in step S21. Reference Information 35 is a collection of one or more text-formatted data containing information useful during program generation. This information includes source code or text describing algorithms. For example, the source code or algorithm described in Figure 8 constitutes Reference Information 35. The file format for Reference Information 35 may be a common document format such as TXT, PDF, or DOCX, or it may be any other format. Furthermore, there may be one or any number of Reference Information 35 files. Reference Information 35 is created, for example, by extracting text from source code, software development specifications, and papers describing algorithms from similar past software development projects. The created Reference Information 35 is stored in an external database or similar. Reference Information 35 may also be stored in Storage 13.

[0036] Referring to Figure 9, the reference information retrieval process according to Embodiment 2 will be explained. (Step S221: Data acquisition process) The reference information retrieval unit 25 retrieves the correction instruction information 31 and the stored reference information 35.

[0037] (Step S222: Vectorization process) The reference information retrieval unit 25 vectorizes the text of the correction instruction information 31 obtained in step S221. Similarly, the reference information retrieval unit 25 vectorizes the text of each reference information 35 obtained in step S221. Methods for vectorizing text include using machine learning models such as Doc2Vec and BERT. BERT stands for Bidirectional Encoder Representations from Transformers. Alternatively, non-machine learning methods such as TF-IDF can also be used to vectorize text. TF-IDF stands for Term Frequency-Inverse Document Frequency.

[0038] When the reference information retrieval unit 25 vectorizes the correction instruction information 31, it may vectorize the entire text of the correction instruction information 31. Alternatively, the reference information retrieval unit 25 may vectorize only a portion of the text contained in the correction instruction information 31. For example, the reference information retrieval unit 25 may vectorize only the text of certain parts of speech, such as nouns, from the words obtained from the text of the correction instruction information 31 through morphological analysis or punctuation. Furthermore, the reference information retrieval unit 25 may vectorize a text obtained by converting the text of the correction instruction information 31 into another text. For example, the reference information retrieval unit 25 may vectorize the text of a summary of the text of the correction instruction information 31, which is obtained by inputting the text of the correction instruction information 31 into an AI that performs text summarization. The reference information retrieval unit 25 may vectorize each text-format data included in the reference information 35 file by file. Alternatively, the reference information retrieval unit 25 may vectorize each unit, which is divided into predetermined sentence units such as every certain number of characters in an individual file.

[0039] The reference information retrieval unit 25 may pre-vectorize the reference information 35 and store the vectors in the storage unit 13. Then, it may read the vectors from the storage unit 13 when necessary.

[0040] (Step S223: Similarity calculation process) The reference information retrieval unit 25 sets each reference information 35 as the target reference information 35. The reference information retrieval unit 25 calculates the similarity between the vector of the correction instruction information 31 generated in step S222 and the vector of the target reference information 35 generated in step S222. Cosine similarity can be used to calculate the similarity between vectors. Alternatively, any measure of distance between vectors, such as Euclidean distance, can be used as the measure of similarity between vectors.

[0041] The reference information retrieval unit 25 extracts a predetermined number of reference information items 35, starting with those with the highest similarity. In this case, the reference information retrieval unit 25 may also extract a predetermined number of reference information items 35 from among those reference information items 35 with a similarity higher than the threshold, starting with those with the highest similarity. If the number of reference information items 35 with a similarity higher than the threshold is less than the predetermined number, the number of reference information items 35 extracted will be less than the predetermined number.

[0042] For example, as shown in Figure 10, suppose the vector value for correction instruction information 31 is (0.5, 0.5). Also, suppose the vector value for text 1 of reference information 35 is (0.5, 0.1) and the vector value for text 2 is (0.4, 0.5). In this case, for example, if we consider the closeness of the Euclidean distance as similarity, text 2 is closer to the correction instruction information 31 than text 1, and is therefore judged to have a higher similarity with the correction instruction information 31.

[0043] This section explained an example of performing a vector search. However, it is also possible to perform a rule-based search, not just a vector search. A rule-based search involves a word and reference information 35 This method involves associating the two and extracting reference information 35 corresponding to the words extracted from the correction instruction information 31 through morphological analysis, etc.

[0044] (Step S23: Input prompt generation process) The input prompt generation unit 22 generates an input prompt 34 from the correction instruction information 31 and reference code 32 entered in step S21 and the reference information 35 retrieved in step S22. Specifically, the input prompt generation unit 22 generates an input prompt 34 as shown in Figure 11. In Figure 11, {correction instruction information} is substituted with correction instruction information 31. Similarly, {reference code} is substituted with reference code 32. Similarly, {search result} is substituted with the retrieved reference information 35. In other words, the input prompt generation unit 22 generates an input prompt 34 that includes correction instruction information 31, reference code 32, reference information 35, and an instruction to generate a modified code 33, which is a source code that modifies the reference code 32 based on the reference information 35, according to the content indicated by the correction instruction information 31. In this case, the input prompt generation unit 22 may embed the text of the reference information 35 obtained as a search result directly into the input prompt 34, or it may convert the reference information 35, or embed the text obtained by partially extracting it. For example, the input prompt generation unit 22 may embed only the text of certain parts of speech, such as nouns, from the words obtained from the text of the reference information 35 through morphological analysis or punctuation. Alternatively, for example, the input prompt generation unit 22 may embed the text of a summary of the text of the reference information 35, obtained by inputting the text of the reference information 35 into an AI that performs text summarization.

[0045] ***Effects of Embodiment 2*** As described above, the program generation device 10 according to Embodiment 2 searches for reference information 35 and inputs it into the input prompt 34. This allows the trained model 60 to generate a modified code 33 based on the reference information 35. As a result, it becomes possible to generate a more appropriate modified code 33.

[0046] Embodiment 3. Embodiment 3 differs from Embodiments 1 and 2 in that, among the multiple code blocks 36 obtained by dividing the reference code 32 into reference units, the code block 36 corresponding to the correction instruction information 31 is included as the reference code 32 in the input prompt 34. Embodiment 3 will explain this difference, and the same points will not be explained. Embodiment 3 describes a case in which a modification has been made to Embodiment 1. However, it is also possible to modify Embodiment 2.

[0047] ***Explanation of the structure*** Referring to Figure 12, the configuration of the program generation device 10 according to Embodiment 3 will be described. The program generation device 10 differs from the program generation device 10 shown in Figure 2 in that it includes a modification location identification unit 26 as a functional component. The modification location identification unit 26, like the other functional components, is implemented by software.

[0048] ***Explanation of operation*** Referring to Figures 13 and 14, the processing flow of the program generation device 10 according to Embodiment 3 will be explained. The process from step S35 to step S37 is the same as the process from step S13 to step S15 in Figure 3.

[0049] (Step S31: Input data acquisition process) The input data acquisition unit 21 acquires correction instruction information 31, a reference code 32, and block data 37 indicating a code block 36 for the reference code 32 via the communication interface 14. A code block 36 is a subcode obtained by dividing the base code 32 into base units such as functions and classes. Block data 37 is electronic data that records, for each code block 36, a set of text indicating the subcode, one or more classifications, and the start and end line numbers that appear in the base code 32. One or more classifications are set to the classification to which the code block 36 belongs from among several predetermined classifications.

[0050] Block data 37 is created manually. Alternatively, block data 37 may be created by a trained machine learning model that takes the text of code block 36 as input and outputs a classification and a pair of start and end line numbers. Alternatively, block data 37 may be created by determining the classification label using a rule-based method, such as assigning a corresponding classification if a string in code block 36 contains a specific string.

[0051] (Step S32: Correction instruction classification process) The modification location identification unit 26 determines which of several predetermined classifications the text of the modification instruction information 31 acquired in step S31 belongs to. Based on this, the modification location identification unit 26 identifies the classification corresponding to the modification instruction information 31. The text of the correction instruction information 31 may be classified using a machine learning model capable of text classification, such as BERT. Alternatively, a rule-based classification method may be used, where a specific classification is assigned if the text of the correction instruction information 31 contains a specific word. There may be one classification or two or more classifications corresponding to the correction instruction information 31.

[0052] (Step S33: Identifying the areas to be corrected) The modification location identification unit 26 compares the classification corresponding to the modification instruction information 31 identified in step S32 with the classification of each code block 36 indicated by the block data 37. The modification location identification unit 26 then identifies the code block 36 that contains the same classification as the classification corresponding to the modification instruction information 31 as the corresponding block. The modification location identification unit 26 writes the identified code block 36, which is the corresponding block, to the memory 12. Here, a code block 36 containing the same classification as the classification corresponding to the correction instruction information 31 means a code block 36 that contains at least one of the one or more classifications corresponding to the correction instruction information 31. Alternatively, the meaning of a code block 36 containing the same classification as the classification corresponding to the correction instruction information 31 may be interpreted as the one or more classifications corresponding to the correction instruction information 31 being exactly the same as the one or more classifications corresponding to the code block 36.

[0053] (Step S34: Input prompt generation process) The input prompt generation unit 22 generates an input prompt 34 from the correction instruction information 31 entered in step S31 and the corresponding block, which is the code block 36 identified in step S33. Specifically, the input prompt generation unit 22 generates an input prompt 34 as shown in Figure 14. In Figure 14, {correction instruction information} is substituted with correction instruction information 31. Similarly, {code block} is substituted with the text of the code block 36 identified in step S33. In other words, the input prompt generation unit 22 includes only the text of the corresponding block, which is the code block 36 identified in step S33, as the reference code 32 in the input prompt 34. That is, the input prompt generation unit 22 includes the correction instruction information 31 and the code block 36, and for the code block 36 Then, an input prompt 34 is generated that includes an instruction to generate a modified code 33, which is the source code with the modifications indicated by the modification instruction information 31.

[0054] Please refer to Figure 15 for a specific example. Assume that the correction instruction information 31 shown in Figure 15(A) and the block data 37 shown in Figure 15(B) have been acquired. At this time, assume that in step S32, the classification corresponding to the correction instruction information 31 has been identified as a string display. Then, in step S33, code blocks 36 with block IDs B002 and B003 are identified as code blocks 36 having the same classification as the classification corresponding to the correction instruction information 31. As a result, as shown in Figure 15(C), the text of the correction instruction information 31 shown in Figure 15(A) is set in {correction instruction information}, and the text of the code blocks 36 with block IDs B002 and B003 is set in {source code}, and the input prompt 34 is generated.

[0055] ***Effects of Embodiment 3*** As described above, the program generation device 10 according to Embodiment 3 includes the code block 36 corresponding to the correction instruction information 31 as the reference code 32 in the input prompt 34. This limits the range of the reference code 32 that can be included in the input prompt 34. Therefore, the number of input tokens for the trained model 60 is reduced, which reduces the generation time and cost of the trained model 60. In addition, the output accuracy of the trained model 60 can be improved because code blocks 36 that are irrelevant to the modification are removed from the input prompt 34.

[0056] Embodiment 4. Embodiment 4 differs from Embodiment 3 in that it also includes in the input prompt 34 the code block 36 on which the code block 36 corresponding to the correction instruction information 31 depends. Embodiment 4 will explain this difference, and will omit explanations of the same points.

[0057] ***Explanation of the structure*** Referring to Figure 16, the configuration of the program generation device 10 according to Embodiment 4 will be described. The program generation device 10 differs from the program generation device 10 shown in Figure 2 in that it includes a relationship identification unit 27 as a functional component. The relationship identification unit 27, like other functional components, is implemented by software.

[0058] ***Explanation of operation*** Referring to Figure 17, the processing flow of the program generation device 10 according to Embodiment 4 will be explained. The processes in steps S41 and S42 are the same as the processes in steps S31 and S32 in Figure 13. The processes in steps S46 to S48 are the same as the processes in steps S35 to S37 in Figure 13.

[0059] (Step S43: Relationship Identification Process) The relationship identification unit 27 identifies the dependencies between the multiple code blocks 36 indicated by the block data 37. The relationship identification unit 27 generates a directed graph that shows the dependencies between the code blocks 36 as higher-level nodes and lower-level nodes.

[0060] Referring to Figure 18, the relationship identification process according to Embodiment 4 will be explained. (Step S431: Data acquisition process) The relationship identification unit 27 obtains the reference code 32 and the block data 37.

[0061] (Step S432: Symbol table generation process) The relationship identification unit 27 generates a symbol table from the reference code 32 obtained in step S431. As shown in Figure 19(A), the symbol table is a table that stores the symbol name, the symbol type, the scope in which the symbol is valid, and the definition location. Figure 19(A) shows the symbol table for source code written in C language shown in Figure 19(B). Symbols are unique identifiers defined by the user in standard code 32, such as variable names, function names, and constant names. Scope refers to the range within which a symbol is valid. There are two types of scope: Global, which means that a symbol is valid throughout the entire source code, and Local, which means that a symbol is valid only within a function or class. In Embodiment 4, only the higher-level Global scope and lower-level Local scope are considered, but other scopes may exist. The relationship identification unit 27 may create a symbol table by identifying each element of the symbol table using a compiler or interpreter of the programming language in which the reference code 32 is written. Compilers and interpreters generally have a function to generate symbol tables. Alternatively, the relationship identification unit 27 may create a symbol table by identifying each element of the symbol table by determining each identifier that becomes a symbol in the reference code 32 using syntax rules determined for each programming language.

[0062] (Step S433: Symbol identification process) The relationship identification unit 27 refers to the symbol table generated in step S432 and identifies the symbols included in each code block 36 indicated by the block data 37 obtained in step S431. Specifically, the relationship identification unit 27 sets each code block 36 indicated by the block data 37 as the target code block 36. The relationship identification unit 27 identifies the symbol names included in the target code block 36 from among the symbol names defined in the symbol table. The relationship identification unit 27 determines that the symbols of the identified symbol names are included in the target code block 36.

[0063] (Step S434: Correspondence Identification Process) The relationship identification unit 27 identifies the dependencies between the code blocks 36. Specifically, the relationship identification unit 27 sets each code block 36 indicated by the block data 37 as the target code block 36. The relationship identification unit 27 determines whether the scope of the symbols included in the target code block 36 identified in step S433 is within the target code block 36. Here, the relationship identification unit 27 determines whether the scope of the symbols included in the target code block 36 is Local. Here, if the scope is Local, it is determined that the scope is within the target code block 36. The relationship identification unit 27 terminates processing for the target code block 36 if it finds that only symbols whose scope is within the target code block 36 exist. On the other hand, if there are symbols whose scope extends outside the target code block 36, the relationship identification unit 27 refers to the symbol table to identify the definition location of those symbols. The relationship identification unit 27 identifies the code block 36 that contains the identified definition location. The relationship identification unit 27 then identifies that the target code block 36 depends on the identified code block 36. In other words, the relationship identification unit 27 identifies the identified code block 36 as a higher-level code block 36 than the target code block 36.

[0064] (Step S435: Graph generation process) The relationship identification unit 27 generates a directed graph based on the dependencies identified in step S434. Specifically, the relationship identification unit 27 generates nodes representing each code block 36 indicated by the block data 37. The relationship identification unit 27 treats each code block 36 as a target code block 36 and generates effective edges from the nodes representing the higher-level code blocks 36 of the target code block 36 identified in step S434 to the nodes representing the target code block 36. This generates a directed graph representing the dependencies between the block data 37.

[0065] (Step S44: Identifying the areas to be corrected) The modification location identification unit 26, similar to step S33, identifies a code block 36 that includes the same classification as the classification corresponding to the modification instruction information 31 as the corresponding block. Furthermore, the modification location identification unit 26 identifies the dependent block, which is the code block 36 that the corresponding block, which is the code block 36 identified in step S42, depends on, in the dependency relationships identified in step S43. Specifically, the modification location identification unit 26 traces the directed graph generated in step S43 upwards from the corresponding block and identifies the code block 36 that is the higher-level node of the corresponding block as the dependent block, which is the code block 36 that the corresponding block depends on. Here, the higher-level node for the corresponding block is not only the higher-level node directly connected to the corresponding block in the directed graph, but also all nodes identified by tracing the directed graph showing the dependency relationships upwards. Alternatively, the higher-level node for the corresponding block may be a node identified by tracing the directed graph showing the dependency relationships upwards, with a predetermined upper limit. The modification location identification unit 26 writes the identified code block 36 to memory 12. In other words, the modification location identification unit 26 writes the corresponding block and dependent blocks to memory 12.

[0066] (Step S45: Input prompt generation process) The input prompt generation unit 22 generates an input prompt 34 from the correction instruction information 31 entered in step S41 and the corresponding block and dependent block identified in step S44. Specifically, the input prompt generation unit 22 generates an input prompt 34 as shown in Figure 20. In Figure 20, {correction instruction information} is shown to be substituted with correction instruction information 31. Similarly, {code block} is shown to be substituted with the text of the corresponding block and dependent block code block 36 identified in step S44. In other words, the input prompt generation unit 22 includes only the text of the corresponding block and dependent block portion of the code block 36 identified in step S44 as the base code 32 in the input prompt 34. The input prompt generation unit 22 generates an input prompt 34 that includes correction instruction information 31, the corresponding block and dependent block code block 36, and an instruction to generate a modified code 33, which is the source code with the content indicated by the correction instruction information 31 applied to the code block 36. Here, the input prompt generation unit 22 embeds the text of each code block 36 into {source code}, starting from the highest-level code block 36. The input prompt generation unit 22 may also embed the text of each code block 36 in any other order.

[0067] ***Effects of Embodiment 4*** As described above, the program generation device 10 according to Embodiment 4 also includes in the input prompt 34 the code block 36 on which the code block 36 corresponding to the modification instruction information 31 depends. This makes it possible to modify other code blocks 36 when modification of a specific code block 36 requires modification of other code blocks 36.

[0068] If the dependent code block 36 is not included in the input prompt 34, the relationships between code blocks 36 could not be tracked when modifications to other code blocks 36 were required in relation to a modification to a specific code block 36. For example, suppose the modification instruction information 31 is to modify the string to be displayed to "HELLO WORLD". In this case, suppose that in the source code shown in Figure 21, code blocks 36C and 36D are identified as the target code blocks 36 and included in the input prompt 34. In this case, in order to modify the output_message function's output, the trained model 60 may modify the argument in the printf function to "HELLO WORLD". Then, the variable message in code block 36B remains as a meaningless variable. Here, let's assume that a directed graph representing dependencies has been generated, as shown in Figure 22. In this case, the program generation device 10 according to Embodiment 4 also includes code blocks 36A and 36B, which are code blocks 36C on which it depends, in the input prompt 34, as shown in Figure 23. Then, the trained model 60 can determine that if the argument in the printf function is changed to "HELLO WORLD", the variable message in code block 36B will become a meaningless variable. Therefore, when changing the argument in the printf function to "HELLO WORLD", there is a possibility that the definition of the variable message in code block 36B will be deleted as a modification.

[0069] ***Other configurations*** <Variation 3> In Embodiment 4, the dependencies of code block 36 were identified based on the definition of symbols. However, the dependencies of code block 36 are not limited to this and can also be identified based on other information.

[0070] (Example 1) The relationship identification unit 27 can identify the dependencies of the code blocks 36 based on the function call relationships. Specifically, the relationship identification unit 27 considers the calling code block 36 as the upper node and the code block 36 containing the called function as the lower node. To create a directed graph, the relationship identification unit 27 can identify the function call relationships by using a call graph created by a static analysis tool.

[0071] (Example 2) The relationship identification unit 27 can identify the dependencies of code blocks 36 based on the usage relationships of the same global variables. Specifically, the relationship identification unit 27 sets the code block 36 that defines the global variable as the highest level, and sets the code blocks 36 that include the process of rewriting the value of the said global variable as higher-level nodes in order of their execution order in the source code. The execution order of each code block 36 can be determined by performing an AST analysis or creating a CFG using a static analysis tool. AST stands for Abstract Syntax. It is an abbreviation for Tree. CFG is an abbreviation for Control Flow Graph.

[0072] Embodiment 5. Embodiment 5 differs from Embodiments 1 to 4 in that it selects a reference code 32 from source code stored in a database. Embodiment 5 explains this difference, while omitting explanations of the same points. Embodiment 5 describes a case in which a modification has been made to Embodiment 1. However, it is also possible to make modifications to Embodiments 2 to 4.

[0073] ***Explanation of the structure*** Referring to Figure 24, the configuration of the program generation device 10 according to Embodiment 5 will be described. The program generation device 10 differs from the program generation device 10 shown in Figure 2 in that it includes a reference code selection unit 28 as a functional component. The reference code selection unit 28, like the other functional components, is implemented by software. Furthermore, a source code database 41 is connected to the program generation device 10. The source code database 41 is a database that stores multiple source code files that may be subject to modification.

[0074] ***Explanation of operation*** Referring to Figure 25, the processing flow of the program generation device 10 according to Embodiment 5 will be explained. (Step S51: Input data acquisition process) The input data acquisition unit 21 acquires the correction instruction information 31 entered by the input terminal 51 through user operation. In this case, unlike in Embodiment 1, the reference code 32 is not acquired.

[0075] (Step S52: Selection of reference code) The reference code selection unit 28 selects a source code corresponding to the modification instruction information 31 as the reference code 32 from the source code database 41 which stores multiple source codes. Specifically, the reference code selection unit 28 searches the source code database 41 based on the correction instruction information 31. For example, similar to the search for reference information 35 described in Embodiment 2, the reference code selection unit 28 vectorizes the text of the correction instruction information 31 and the text of each source code stored in the source code database 41. Then, the reference code selection unit 28 calculates the similarity between the vector of the correction instruction information 31 and the vector of the source code. The reference code selection unit 28 selects source codes with a similarity of a certain level or higher as reference codes 32. In this case, the reference code selection unit 28 selects one or more source codes as reference codes 32. For example, if there are multiple source codes with a similarity of a certain level or higher, the reference code selection unit 28 selects each of them as a reference code 32. Also, if there are no source codes with a similarity of a certain level or higher, the reference code selection unit 28 selects the source code with the highest similarity as a reference code 32. Furthermore, similar to the search for reference information 35 described in Embodiment 2, the search may be performed using a rule-based method.

[0076] (Step S53: Input prompt generation process) The input prompt generation unit 22 generates an input prompt 34 from the correction instruction information 31 entered in step S51 and the reference code 32 selected in step S52. Specifically, the input prompt generation unit 22 sets one or more reference codes 32 selected in step S52 as the target reference code 32. The input prompt generation unit 22 generates an input prompt 34 as shown in Figure 4. In Figure 4, {correction instruction information} is shown to be substituted with correction instruction information 31. Similarly, {reference code} is shown to be substituted with the target reference code 32. As a result, an input prompt 34 corresponding to each of the one or more reference codes 32 selected in step S52 is generated.

[0077] (Step S54: Program modification process) The program modification unit 23 inputs each input prompt 34 generated in step S53 to the trained model 60.

[0078] (Step S55: Process to obtain the corrected code) The program modification unit 23 obtains the modified code 33 generated by the trained model 60 for each input prompt 34 entered in step S54. The modification unit 23 obtains a modified code 33 corresponding to each of the one or more input prompts 34.

[0079] (Step S56: Process to output corrected code) The modified code output unit 24 outputs each modified code 33 obtained in step S55.

[0080] ***Other configurations*** <Modification 4> In Embodiment 1, each functional component was implemented in software. However, in Modification 4, each functional component may be implemented in hardware. The differences between this Modification 4 and Embodiment 1 will be explained below.

[0081] When each functional component is implemented in hardware, the program generation device 10 includes an electronic circuit 15 instead of a processor 11, memory 12, and storage 13. The electronic circuit 15 is a dedicated circuit that implements the functions of each functional component, as well as the functions of the memory 12 and storage 13.

[0082] Electronic circuits 15 can include single circuits, complex circuits, programmed processors, parallel programmed processors, logic ICs, GAs, ASICs, and FPGAs. GA stands for Gate Array. ASIC stands for Application Specific Integrated Circuit. FPGA stands for Field-Programmable Gate Array. Each functional component may be implemented in a single electronic circuit 15, or each functional component may be implemented by distributing them across multiple electronic circuits 15.

[0083] <Modification 5> As a fifth variation, some of the functional components may be implemented in hardware, while others may be implemented in software.

[0084] The processor 11, memory 12, storage 13, and electronic circuit 15 are collectively referred to as the processing circuit. In other words, the function of each functional component is realized by the processing circuit.

[0085] Furthermore, the term "part" in the above explanation may be replaced with "circuit," "process," "procedure," "processing," or "processing circuit."

[0086] The embodiments and variations of this disclosure have been described above. Some of these embodiments and variations may be implemented in combination. Alternatively, some or all of them may be implemented in part. However, this disclosure is not limited to the embodiments and variations described above, and various modifications are possible as needed. [Explanation of Symbols]

[0087] 100 Program generation system, 10 Program generation device, 11 Processor, 12 Memory, 13 Storage, 14 Communication interface, 21 Input data acquisition unit, 22 Input prompt generation unit, 23 Program modification unit, 24 Modified code output unit, 25 Reference information retrieval unit, 26 Modification location identification unit, 27 Relationship identification unit, 28 Reference code selection unit, 31 Modification instruction information, 32 Reference code, 33 Modified code, 34 Input prompt, 35 Reference information, 36 Code block, 37 Block data, 41 Source code database, 51 Input terminal, 52 Output terminal, 60 Trained model.

Claims

1. An input prompt generation unit generates an input prompt that includes correction instruction information, which is text data describing the content of the program's behavior modification in natural language; a reference code, which is the source code of the program before the modification is made; and an instruction to generate a modified code, which is the source code that has been modified according to the content of the correction instruction information applied to the reference code. A program modification unit inputs the input prompt generated by the input prompt generation unit into a trained model and obtains the modified code generated by the trained model. A correction location identification unit identifies the code block corresponding to the correction instruction information from among a plurality of code blocks obtained by dividing the aforementioned reference code into reference units, A relationship identification unit that identifies dependencies between the aforementioned plurality of code blocks and Equipped with, The input prompt generation unit is a program generation device that includes the portion of the corresponding block identified by the modification location identification unit and the code block on which the corresponding block depends in the dependency relationship identified by the relationship identification unit as the reference code in the input prompt.

2. The program generation device further, Reference Information Search Unit: Based on the aforementioned correction instruction information, the unit searches for reference information that is useful when generating the program. Equipped with, The input prompt generation unit generates the input prompt which includes the reference information retrieved by the reference information retrieval unit. The program generation device according to claim 1.

3. Each of the aforementioned code blocks has a function classification assigned to it. The modification location identification unit identifies the functional classification of the content indicated by the modification instruction information, and identifies the code block containing the same classification as the identified classification as the corresponding block. The program generation device according to claim 1.

4. The relationship identification unit identifies the dependency relationship by considering each of the plurality of code blocks as a target code block, and determining that the target code block depends on the code block in which the symbol is defined if the target code block contains a symbol whose validity range extends outside the target code block. The program generation device according to claim 1.

5. The program generation device further, A reference code selection unit selects a source code corresponding to the correction instruction information from a source code database that stores multiple source codes, and uses that source code as the reference code. Equipped with, The input prompt generation unit generates the input prompt which includes the reference code selected by the reference code selection unit. The program generation device according to claim 1.

6. The program generation device further, A modified code output unit outputs the modified code obtained by the program modification unit, indicating the changes from the reference code. The program generation device according to claim 1, comprising:

7. The program generation device further, A program execution unit that executes the modified code obtained by the program modification unit, The program execution unit executes the modified code and outputs the result output unit. The program generation device according to claim 1, comprising:

8. A program generation system comprising a program generation device, an input terminal, and an output terminal, The program generation device is An input prompt generation unit generates an input prompt that includes correction instruction information, which is text data describing the content of the program behavior modification obtained from the input terminal in natural language; a reference code, which is the source code of the program before the modification is made; and an instruction to generate a modified code, which is the source code that has been modified according to the content indicated by the correction instruction information to the reference code. A program modification unit inputs the input prompt generated by the input prompt generation unit into a trained model and obtains the modified code generated by the trained model. A modified code output unit that outputs the modified code obtained by the program modification unit to the output terminal, A correction location identification unit identifies the code block corresponding to the correction instruction information from among a plurality of code blocks obtained by dividing the aforementioned reference code into reference units, A relationship identification unit that identifies dependencies between the aforementioned plurality of code blocks and Equipped with, The input prompt generation unit is a program generation system that includes the portion of the corresponding block identified by the modification location identification unit and the code block on which the corresponding block depends in the dependency relationship identified by the relationship identification unit as the reference code in the input prompt.

9. The computer generates an input prompt that includes correction instruction information, which is text data describing the content of the program's behavior modification in natural language; a reference code, which is the source code of the program before the modification is made; and an instruction to generate a modified code, which is the source code that has been modified according to the content of the correction instruction information applied to the reference code. The computer inputs the input prompt to the trained model and obtains the modified code generated by the trained model. The computer divides the reference code into reference units and identifies the code block corresponding to the correction instruction information from among the multiple code blocks obtained, as the corresponding block. The computer identifies the dependencies between the aforementioned multiple code blocks, A program generation method in which a computer includes the portion of the corresponding block and the code block on which the corresponding block depends in the dependency relationship as the reference code in the input prompt.

10. An input prompt generation process that generates an input prompt including: modification instruction information, which is text data describing the content of the modification of the program's behavior in natural language; a reference code, which is the source code of the program before the modification is made; and an instruction to generate a modified code, which is the source code that has been modified according to the content of the modification instruction information applied to the reference code; A program modification process that inputs the input prompt generated by the input prompt generation process into the trained model and obtains the modified code generated by the trained model, A modification location identification process that identifies the code block corresponding to the modification instruction information as the corresponding block from among a plurality of code blocks obtained by dividing the aforementioned reference code into reference units, Relationship identification process to identify dependencies between the aforementioned multiple code blocks and The computer functions as a program generation device to perform this task. A program generation program that, in the input prompt generation process, includes the portion of the corresponding block identified by the modification location identification process and the code block on which the corresponding block depends in the dependency relationship identified by the relationship identification process as the base code in the input prompt.