Code improvement device, code improvement method, and code improvement program

The code improvement device uses a language model to automate the program code improvement process, evaluating and deciding on code changes, resulting in efficient and high-performance code generation.

JP2025185935APending Publication Date: 2025-12-23NEC CORP
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
JP2024094439
Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-06-11
Publication Date
2025-12-23

AI Technical Summary

Technical Problem

Improving program code requires significant manual effort in rewriting, execution, and evaluation, leading to inefficiencies.

Method used

A code improvement device and method utilizing a language model to automatically improve program code based on prompts, execute the improved code, evaluate its performance, and decide whether to adopt the changes based on evaluation results.

Benefits of technology

Efficiently improves program code by automating the improvement process, ensuring high-performance code generation while reducing manual effort and enhancing execution efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2025185935000001_ABST
    Figure 2025185935000001_ABST
Patent Text Reader

Abstract

To provide a code improvement device capable of efficiently improving program code.SOLUTION: A code improvement device 10 comprises a code improvement unit 12, an execution unit 13, an evaluation unit 15, and a determination unit 16. The code improvement unit 12 improves program code using a language model for improving the program code on the basis of a prompt indicating the improved contents of the program code. The execution unit 13 executes processing using the improved code. The evaluation unit 15 evaluates execution performance of the code on the basis of the execution results of the code. The determination unit 16 determines whether to adopt the improved code on the basis of the evaluation results of the execution performance.SELECTED DRAWING: Figure 2
Need to check novelty before this filing date? Find Prior Art

Description

[Technical Field]

[0001] The present disclosure relates to a code improvement device and the like. [Background technology]

[0002] The resources and processing time required for a program used in an information processing device may vary depending on the quality of the code. For this reason, for example, a program creator can reduce the resources and processing time required for execution by improving the code they create. However, improving a program can require repeated rewriting of the code, execution, and evaluation of the code based on the execution results, which can result in a large amount of work.

[0003] The processor in Patent Document 1 extracts metadata related to the program to be generated, and then generates the code of the program using the metadata as input to a language model. [Prior art documents] [Patent documents]

[0004] [Patent Document 1] Japanese Patent Application Publication No. 2023-47334 Summary of the Invention [Problem to be solved by the invention]

[0005] In the technique described in Patent Document 1, the work involved in improving the program code can be lengthy.

[0006] In order to solve the above-mentioned problems, the present disclosure aims to provide a code improvement device and the like that can efficiently improve program code. [Means for solving the problem]

[0007] In order to solve the above problems, the code improvement device of the present disclosure includes a code improvement means that improves the code of a program using a language model that improves the code of the program based on a prompt that indicates the content of the improvement to the code of the program, an execution means that executes processing using the improved code, an evaluation means that evaluates the execution performance of the code based on the execution result of the code, and a decision means that decides whether to adopt the improved code based on the evaluation result of the execution performance.

[0008] The code improvement method disclosed herein improves the program code using a language model for improving the program code based on a prompt indicating the content of the improvement to the program code, executes processing using the improved code, evaluates the execution performance of the code based on the execution results of the code, and determines whether to adopt the improved code based on the evaluation results of the execution performance.

[0009] The code improvement program of the present disclosure causes a computer to perform the following processes: improving the code of a program using a language model that improves the code of the program based on a prompt indicating the content of the improvement to the code of the program; executing a process using the improved code; evaluating the execution performance of the code based on the execution results of the code; and deciding whether to adopt the improved code based on the evaluation results of the execution performance. [Effects of the Invention]

[0010] According to the present disclosure, program code can be efficiently improved. [Brief explanation of the drawings]

[0011] [Figure 1] FIG. 1 is a diagram illustrating an example of a configuration of a code improvement system according to an embodiment of the present disclosure. [Figure 2] FIG. 1 is a diagram illustrating an example of a configuration of a code improvement device according to an embodiment of the present disclosure. [Figure 3] FIG. 1 is a diagram illustrating an example of a configuration of a code improvement system according to an embodiment of the present disclosure. [Figure 4]FIG. 1 is a diagram illustrating an example of a configuration of a code improvement system according to an embodiment of the present disclosure. [Figure 5] FIG. 10 is a diagram illustrating an example of a display screen according to an embodiment of the present disclosure. [Figure 6] FIG. 10 is a diagram illustrating an example of a display screen according to an embodiment of the present disclosure. [Figure 7] FIG. 10 is a diagram illustrating an example of an operation flow of a code improvement device according to an embodiment of the present disclosure. [Figure 8] FIG. 1 is a diagram illustrating an example of a hardware configuration according to an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE INVENTION

[0012] Embodiments of the present disclosure will be described in detail with reference to the drawings. FIG. 1 is a diagram showing an example of the configuration of a code improvement system. The code improvement system includes, for example, a code improvement device 10 and a terminal device 20. The code improvement device 10 is connected to the terminal device 20 via, for example, a network. There may be multiple terminal devices 20. The number of terminal devices 20 can be set as appropriate.

[0013] A code improvement system is, for example, a system that improves program code. The code improvement system improves the execution performance of the code by, for example, improving the code of a program whose operation has been confirmed. The code is, for example, the source code of a computer program executed on an information processing device. The code may be test code. Furthermore, "operation confirmed" means, for example, that it has been confirmed that correct output data is obtained for input data when the code is executed. Furthermore, improving code means, for example, changing a part of the code while the code is still executable.

[0014] The code improvement system improves the code using, for example, a language model that takes a prompt and the code to be improved as input and generates code based on the prompt and the code. The prompt includes, for example, information indicating the content of the code improvement. That is, the code improvement system uses, for example, the prompt and the code as input to the language model and improves the code based on the prompt. For example, a natural language model called a large-scale language model can be used as the language model. Examples of language models will be described later.

[0015] The execution performance of code is, for example, an index that indicates the efficiency of code execution. For example, the execution performance of code is, for example, an index related to the resources required to execute the code. For example, the fewer resources required to execute the code, the higher the execution performance of the code. For example, the execution performance of code includes at least one of indexes related to the execution time of the code, the amount of memory consumed when executing the code, and the power consumption when executing the code. Furthermore, the execution performance of code may include, for example, an index that indicates the efficiency when checking or improving the code. For example, the execution performance of code may include the readability of the code. The execution performance of code is not limited to the above.

[0016] Here, an example of the configuration of the code improvement device 10 will be described. Fig. 2 is a diagram showing an example of the configuration of the code improvement device 10. The code improvement device 10 basically includes a code improvement unit 12, an execution unit 13, an evaluation unit 15, and a determination unit 16. The code improvement device 10 may also include, for example, an acquisition unit 11, a code correction unit 14, a prompt generation unit 17, an output unit 18, and a storage unit 19.

[0017] The acquisition unit 11 acquires, for example, the code of a program to be improved. For example, the acquisition unit 11 acquires, as the code of the program to be improved, code that has been confirmed to not cause errors when executed. Furthermore, for example, the acquisition unit 11 acquires, as the code of the program to be improved, code that has been confirmed to produce correct output data for input data when executed. The code of the program to be improved is input to the terminal device 20, for example, by a person in charge of improving the code. Then, the acquisition unit 11 acquires, for example, the code of the program to be improved from the terminal device 20. The acquisition unit 11 may acquire the code of the program to be improved via an input device (not shown) connected to the code improvement device 10. Furthermore, the code of the program to be improved may be stored in the storage unit 19.

[0018] The acquisition unit 11 acquires, for example, correct answer data for input / output data in the code to be improved. The correct answer data for input / output data is, for example, data that combines input data and output data when code that operates normally is executed. That is, the input / output data is, for example, test data for verifying the operation of the code. The correct answer data for input / output data in the code to be improved is input to the terminal device 20 by, for example, a person who is responsible for improving the code. The acquisition unit 11 then acquires the correct answer data for input / output data in the code to be improved from, for example, the terminal device 20. The acquisition unit 11 may acquire the correct answer data for input / output data in the code to be improved via an input device (not shown) connected to the code improvement device 10. The correct answer data for input / output data in the code to be improved may be stored in the storage unit 19.

[0019] The acquisition unit 11 acquires, for example, a prompt indicating the content of the code improvement. The acquisition unit 11 may also acquire information indicating changes to the prompt. The prompt indicating the content of the code improvement is, for example, input to the terminal device 20 by a person in charge of improving the code. Then, the acquisition unit 11 acquires the code of the program to be improved from, for example, a terminal device (not shown). The acquisition unit 11 may acquire the code of the program to be improved via an input device (not shown) connected to the code improvement device 10.

[0020] The code improvement unit 12 improves the code of the program using a language model. The language model improves the code based on a prompt that indicates the improvement content of the program code. The language model is a machine learning model that takes, for example, a prompt and code as input, and outputs code that has been changed based on the prompt. For example, the language model takes, as input, a prompt that indicates the improvement content of the code, such as "Please speed up the following code," and the code to be improved, and outputs code that has been improved based on the prompt.

[0021] Furthermore, improving code refers to, for example, changing at least a portion of the code. That is, the language model performs a process of changing at least a portion of the code based on a prompt. Furthermore, the code generated by the language model in the process of changing at least a portion of the code based on a prompt may include code whose execution performance is not improved compared to the code before the improvement.

[0022] The language model may be, for example, GPT-2 (Generative Pre-trained Transformer-2), GPT-3, GPT-3.5, or GPT-4. Alternatively, the language model may be T5 (Text-to-Text Transfer Transformer), BERT (Bidirectional Encoder Representations from Transformers), RoBERTa (Robustly optimized BERT approach), or ELECTRA (Efficiently Learning an Encoder that Classifies Token Replacements Accurately). The language model used to improve the code is not limited to the above.

[0023] When the decision unit 16 determines to adopt the improved code, the code improvement unit 12 further improves the improved code using a language model, for example, based on a prompt. When the decision unit 16 determines not to adopt the improved code, the code improvement unit 12 further improves the pre-improvement code using a language model, for example, based on a prompt. When the decision unit 16 determines to discard the improved code, the code improvement unit 12 treats the pre-improvement code as a target for improvement and improves the pre-improvement code using a language model, for example, based on a prompt. Rejecting a code means, for example, excluding the code from targets for improvement. Rejecting a code is performed, for example, when an error occurs during execution of the code. Rejecting a code may also be performed when output data for input data during execution of the code does not match correct data.

[0024] When repeatedly improving code, the code improvement unit 12 improves the code based on, for example, the same prompt. For example, if the decision unit 16 decides to adopt the improved code, the code improvement unit 12 further improves the improved code based on the same prompt used to improve the code. Repeated code improvement refers to, for example, making multiple improvements to the original code acquired by the acquisition unit 11. For example, repeated code improvement refers to repeating a cycle of a series of processes including improving the code by the code improvement unit 12, executing the code by the execution unit 13, evaluating the execution performance of the code by the evaluation unit 15, determining whether to adopt the improved code by the decision unit 16, and improving the code decided to adopt by the code improvement unit 12. Furthermore, when repeatedly improving code, the code that is the target of the re-improvement process may include the code before improvement. For example, if it is decided not to adopt the improved code or if the code does not execute normally, the code improvement unit 12 improves the code before the improvement that was evaluated, rather than the code whose execution performance was evaluated.

[0025] When code improvement is performed repeatedly, the code improvement unit 12 may improve the code, for example, based on a prompt that has been changed since the previous improvement in the iteration. The changed prompt is, for example, input by a person who generates the code. The code improvement unit 12 may improve the code based on a prompt generated by the prompt generation unit 17. Furthermore, when the code correction unit 14 debugs code that has generated an error when executed, the code improvement unit 12 improves the code after debugging, for example.

[0026] The process for improving the code may be performed in a device external to the code improvement device 10. When the process for improving the code is performed in a device external to the code improvement device 10, the code improvement unit 12 outputs a prompt indicating the content of the code improvement and the code to be improved to, for example, an information processing device on which a language model that performs the process for improving the code operates. Then, the code improvement unit 12 acquires the improved code from, for example, the information processing device that performed the code improvement.

[0027] FIG. 3 shows an example of the configuration of a code improvement system in which a generation device 30 performs processing related to code improvement. In the example of FIG. 3, the code improvement device 10 is connected to the generation device 30, for example, via a network. The generation device 30 is an information processing device that generates improved code from input code, for example, using a language model. The code improvement unit 12, for example, outputs the code to be improved and a prompt indicating the content of the code improvement to the generation device 30. The generation device 30 also generates improved code using the code to be improved and the prompt indicating the content of the code improvement as input for the language model. The code improvement unit 12 then obtains the improved code from the generation device 30 that has improved the code.

[0028] The execution unit 13 executes processing using the code improved by the code improvement unit 12. The execution unit 13 executes the code improved by the code improvement unit 12 using, for example, input data acquired as correct answer data, and acquires output data as the execution result of the code. The execution unit 13 also measures execution performance during code execution. For example, the execution unit 13 measures at least one of the execution time of the code, the amount of memory consumed during code execution, and the power consumption during code execution as the execution performance. The execution time of the code is, for example, the time from the start of code execution to the end of code execution. The amount of consumed memory is, for example, the memory capacity used during code execution. The execution unit 13 measures, for example, the size of the largest memory area occupied by the code during execution as the consumed memory amount. The execution unit 13 also measures, for example, parameters required for calculating power consumption. For example, the execution unit 13 measures the amount of processed data, the amount of memory consumed, and the number of accesses to the storage device as parameters required for calculating power consumption. The parameters required for calculating power consumption are not limited to those described above. Furthermore, the execution performance measured by the execution unit 13 is not limited to the above.

[0029] Furthermore, the execution unit 13 may execute the same code multiple times. The number of times the same code is executed is set so that, for example, when a statistical value is calculated in an evaluation of execution performance, a significant evaluation result is obtained. When the same code is executed multiple times, the execution unit 13 measures the execution performance, for example, each time the code is executed. Furthermore, when the same code is executed multiple times, if an error occurs during the execution of the code, the execution unit 13 may interrupt the multiple executions of the code.

[0030] If an error occurs during execution, the execution unit 13 extracts information indicating the content of the error as an error message. The error message is, for example, information indicating the phenomenon that occurred when the execution of the code stopped or the cause of the stop. If an error occurs during execution, the execution unit 13 may identify the location in the code where the error occurred.

[0031] The execution unit 13 may execute the code in an information processing device in which the code is actually used. The information processing device in which the code is actually used is also referred to as, for example, a target machine. For example, the execution unit 13 outputs the generated code to the information processing device in which the code is actually used and obtains the execution result of the code in the information processing device. Furthermore, the actual use of the code means, for example, that the code is executed to process actual data. For example, if the code is code for a program that manages sales in a store, the information processing device in which the code is actually used is a device that manages sales data of the store.

[0032] FIG. 4 shows an example of the configuration of a code improvement system that executes code in an information processing device 40. In the example of FIG. 4, the code improvement device 10 is connected to the information processing device 40, for example, via a network. The information processing device 40 processes data by, for example, executing program code. The execution unit 13 outputs code improved by the code improvement unit 12 to the information processing device 40, for example. The execution unit 13 outputs input data from the correct answer data to the information processing device 40, for example, as test data. The information processing device 40 executes the code using the test data as input data. The execution unit 13 then obtains output data from the information processing device 40 that executed the code as the execution result of the code in the information processing device 40. The execution unit 13 also obtains, for example, information indicating the execution performance of the code when it is executed from the information processing device 40. If an error occurs during the execution of the code, the execution unit 13 obtains an error message indicating the content of the error from the information processing device 40.

[0033] When the code is executed in an information processing device where the code is actually used, the execution unit 13 may execute the code in the information processing device where the code is actually used, for each predetermined number of iterations of the process related to the improvement. The predetermined number is set, for example, so that execution performance in an actual operating environment can be appropriately evaluated while suppressing the load on the information processing device. For example, if the predetermined number is five, the execution unit 13 executes the code generated in the improvement in the first to fourth iterations of the improvement in the code improvement device 10, and executes the code generated in the fifth iteration in the information processing device where the code is actually used. Then, for example, the execution unit 13 executes the code generated in the improvement in the sixth to ninth iterations of the improvement in the code improvement device 10, and executes the code generated in the tenth iteration in the information processing device where the code is actually used. In this way, by executing the improved code in the information processing device where the code is actually used in some of the iterations, it is possible to generate code suitable for an actual operating environment while suppressing the load on the information processing device, for example.

[0034] Furthermore, when the code is executed in an information processing device in which the code is actually used, the execution unit 13 may execute, in the information processing device in which the code is actually used, code whose execution performance in the code improvement device 10 is equal to or higher than a standard. In this way, by executing only code whose execution performance is equal to or higher than a standard in the information processing device in which the code is actually used, it is possible to generate code with high execution performance while suppressing the load on the information processing device, for example.

[0035] The execution unit 13 may execute the code in a simulator that reproduces an information processing device in which the code is actually used. The execution unit 13 executes the code improved by the code improvement unit 12 in the simulator, for example, using input data included in the test data. Then, the execution unit 13 obtains output data for the input data as a simulation result. Furthermore, the execution unit 13 obtains, for example, execution performance measured by the simulator when the code is executed.

[0036] The execution unit 13 may also execute the code using a simulator and an information processing device in which the code is actually used. The execution unit 13 executes the code on the information processing device in which the code is actually used every predetermined number of iterations of the improvement process, and executes the code using the simulator during normal iterations. The predetermined number is set, for example, so that the execution performance in the actual operating environment can be appropriately evaluated while reducing the load on the information processing device. For example, if the predetermined number is five, the execution unit 13 executes the code generated in the improvement in the first to fourth iterations of the improvement in the simulator, and executes the code generated in the fifth improvement in the information processing device in which the code is actually used. Then, for example, the execution unit 13 executes the code generated in the improvement in the sixth to ninth iterations of the improvement in the simulator, and executes the code generated in the tenth improvement in the information processing device in which the code is actually used. In this way, by executing the code using the information processing device in which the code is actually used and the simulator, it is possible to generate code suitable for the actual operating environment while reducing the load on the information processing device.

[0037] For example, when an error occurs during code execution, the code correction unit 14 corrects the code using a prompt including an error message and the code in which the error occurred as inputs to a language model. That is, when an error occurs during code execution, the code correction unit 14 debugs the code using a language model. For example, the code correction unit 14 corrects the code using a prompt including a constraint based on the error message as input to the language model. For example, when an error message indicating that an error has occurred in processing requiring a GPU (Graphics Processing Unit) is acquired, the code correction unit 14 corrects the code using a prompt saying, "Please correct the following code to code that runs without using a GPU," as input to the language model.

[0038] The code correction unit 14 may correct the code when output data corresponding to input data during execution of the code does not match the correct data. For example, the code correction unit 14 identifies a function that may be the cause of the output data corresponding to input data during execution of the code not matching the correct data. Then, the code correction unit 14 corrects the code using a prompt including an instruction to correct the identified function as input to a language model.

[0039] The code correction unit 14 corrects the code based on, for example, the evaluation result of the evaluation unit 15. Furthermore, if an error occurs during the execution of the code by the execution unit 13, the code correction unit 14 may correct the code in which the error occurred. Furthermore, the prompt used to correct the code may be input by a person who generates the code.

[0040] For example, GPT-2, GPT-3, GPT-3.5, or GPT-4 can be used as the language model for correcting the code. Furthermore, T5, BERT, RoBERTa, or ELECTRA can also be used as the language model. The language model used for improving the code is not limited to the above. Furthermore, the language model for correcting the code may be the same as the language model for improving the code, or may be a different language model.

[0041] The evaluation unit 15 evaluates the code, for example, based on the execution result of the code. As the evaluation of the code, the evaluation unit 15 evaluates the execution performance of the code based on the execution result of the code. The evaluation unit 15 evaluates the execution performance of the code, for example, based on the execution result when the same code is executed multiple times. For example, the evaluation unit 15 calculates a statistical value of the execution performance when the same code is executed multiple times as the evaluation result of the execution performance of the code. The statistical value is, for example, an average value. The statistical value may be a mode, a median, or a standard deviation. The statistical value is not limited to the above.

[0042] For example, when the execution performance is the processing time of the code, the evaluation unit 15 calculates the average processing time when the code is executed multiple times as the evaluation result for the processing time. Furthermore, when the code is executed on a simulator, the evaluation unit 15 may measure the processing time required to execute the code for each configuration of the information processing device. For example, the presence or absence of a GPU can significantly change the processing speed of the code. For example, when the code is executed on a simulator, the evaluation unit 15 calculates the processing time of the code for each setting that reproduces an information processing device with a GPU and a setting that reproduces an information processing device without a GPU.

[0043] The evaluation unit 15 may calculate the power consumption during code execution as an evaluation result based on the power consumption of each piece of hardware used to execute the code. For example, the evaluation unit 15 calculates the power consumption during code execution based on the amount of processed data, memory consumption, and the number of accesses to the storage device. The relationship between the amount of processed data, memory consumption, and the number of accesses to the storage device and the power consumption is set as table-format data based on the specifications of the hardware, for example. The power consumption during code execution is calculated.

[0044] The evaluation unit 15 may evaluate the readability of the code as the execution performance of the code. The evaluation unit 15 evaluates the readability of the code based on, for example, the length of the code, the presence or absence of comments, and the length of the comments. The relationship between the code length, the presence or absence of comments, and the length of the comments and the readability evaluation value is set, for example, as data in a table format. Furthermore, the items used to evaluate the readability are not limited to those described above. Furthermore, the execution performance evaluated by the evaluation unit 15 is not limited to those described above.

[0045] The evaluation unit 15, for example, evaluates whether an error has occurred during code execution. If an error has occurred, the evaluation unit 15 outputs an error message to, for example, the code correction unit 14. The evaluation unit 15 may also identify the content or cause of the error based on the error message. The evaluation unit 15 may also identify the content or cause of the error based on the location in the code where the error occurred. For example, if an error occurs at a location where processing by a GPU is required to execute the code, the evaluation unit 15 identifies the absence of a GPU as the cause of the error. If the content or cause of the error has been identified, the evaluation unit 15 outputs the identified content or cause of the error to, for example, the code correction unit 14.

[0046] The evaluation unit 15 may evaluate whether the code is normal, for example, based on output data when the execution unit 13 executes the code. For example, the evaluation unit 15 evaluates whether the code is executed normally, based on correct answer data acquired together with the code. The evaluation unit 15 compares the execution result of the code acquired by the execution unit 13 with the data included in the correct answer data. Then, if the output data included in the execution result of the code acquired by the execution unit 13 matches the data included in the correct answer data, the evaluation unit 15 evaluates that the code has been executed normally. If the execution result of the code acquired by the execution unit 13 includes output data that does not match the data included in the correct answer data, the evaluation unit 15 evaluates, for example, that the code has not been executed normally. In other words, if the execution result of the code acquired by the execution unit 13 includes output data that does not match the data included in the correct answer data, the evaluation unit 15 evaluates that an abnormality has occurred in the execution result of the code.

[0047] The determination unit 16 determines whether to adopt the improved code based on the evaluation result of the execution performance of the code. For example, if the evaluation result of the execution performance satisfies a predetermined standard, the determination unit 16 decides to adopt the improved code. For example, if the evaluation result of the execution performance satisfies a predetermined standard, the determination unit 16 determines the improved code as code to be further improved. For example, if the execution performance of a second code obtained by improving a first code is evaluated, and the execution performance of the second code satisfies the predetermined standard, the determination unit 16 decides to adopt the second code as code to be improved. In this case, the code improvement unit 12 improves the second code based on, for example, a prompt to generate a third code. Furthermore, adopting the improved code may include setting the improved code as a target for saving.

[0048] Furthermore, the determination unit 16 determines not to adopt the improved code, for example, if the evaluation result of the execution performance does not satisfy a predetermined standard. That is, for example, if the evaluation result of the execution performance does not satisfy a predetermined standard, the determination unit 16 determines the code before the improvement as the code to be improved. For example, when the execution performance of a second code obtained by improving a first code is evaluated, if the execution performance of the second code does not satisfy the predetermined standard, the determination unit 16 does not adopt the second code and determines the first code as the code to be improved. In this case, the code improvement unit 12 improves the first code, for example, based on a prompt, to generate a third code. That is, the second code is discarded, and the first code used to generate the second code is used again as the code to be improved. Since codes generated by a language model are different each time they are generated, even if the same first code is targeted for improvement, the second code and the third code generated by the improvement may be different from each other.

[0049] Furthermore, the determination unit 16 may determine the code with higher execution performance as the code to be improved, between two codes before and after improvement. For example, when the execution performance of a second code obtained by improving a first code is evaluated, if the execution performance of the second code is higher than that of the first code, the determination unit 16 adopts the second code and determines it as the code to be improved. For example, when the execution performance of a second code obtained by improving a first code is evaluated, if the execution performance of the second code is lower than that of the first code, the determination unit 16 does not adopt the second code and determines the first code as the code to be improved.

[0050] The determination unit 16 may determine whether to adopt the improved code based on the evaluation results of the execution performance of multiple items. For example, if the power consumption and memory consumption required to execute the code meet the standards, the determination unit 16 determines to adopt the improved code whose execution performance meets the standards. The determination unit 16 may determine whether to adopt the improved code based on a score calculated by weighting the evaluation results of the execution performance of multiple items.

[0051] The determination unit 16 may determine whether to discard the improved code. For example, the determination unit 16 determines to discard the improved code if an error occurs during code execution or if output data for input data during code execution does not match correct data. If the improved code is discarded, for example, the code before improvement becomes the target for improvement. The determination unit 16 may also determine to terminate the process related to code improvement if a termination condition is met when the execution performance of the code is evaluated. The termination condition is set based on, for example, the number of iterations of code improvement or the number of codes whose execution performance meets a standard. The determination unit 16 may also determine to terminate the process related to code improvement if the person generating the code inputs information indicating that code generation is to be terminated.

[0052] The prompt generation unit 17 generates a prompt based on, for example, the evaluation result of the code. The prompt generation unit 17 generates a prompt using, for example, a fixed phrase set according to the execution performance of the code. For example, if the processing time does not satisfy a standard, the prompt generation unit 17 generates a prompt indicating that the number of branches should be reduced. The relationship between the execution performance of the code and the changes to the prompt is set, for example, as data in a table format. Furthermore, the changed prompt may be input by the person generating the code.

[0053] Furthermore, the prompt generation unit 17 may generate a prompt based on an item that is important to a person generating code. For example, when the acquisition unit 11 acquires information indicating changes to the prompt, the prompt generation unit 17 generates a prompt based on the acquired information indicating the changes. For example, when the information indicating the changes specifies that the number of branches is to be reduced, the prompt generation unit 17 generates a prompt indicating that the number of branches is to be reduced.

[0054] The output unit 18 outputs, for example, information related to the result of code improvement. For example, the output unit 18 outputs the evaluation result of execution performance as information related to the result of code improvement. The output unit 18 may output the improved code as information related to the result of code improvement. Furthermore, the output unit 18 may output a list showing information about the improved code as information related to the result of code improvement. Furthermore, the output unit 18 may output the evaluation results of each of a plurality of execution performances.

[0055] The output unit 18 may store the improved code in the storage unit 19. The output unit 18 may store the improved code in a storage means other than the storage unit 19. For example, the output unit 18 stores the improved code and the evaluation results of the execution performance of the code in association with each other. Furthermore, when evaluation is performed for each of a plurality of execution performances, the output unit 18 stores the improved code and the evaluation results of the execution performance of the code in association with each other.

[0056] FIG. 5 is an example of a display screen for information regarding the results of code improvement. The example display screen in FIG. 5 shows the evaluation results of the code's execution performance. The example display screen in FIG. 5 displays "Original Code," which indicates the name of the original code before improvement, and the execution performance of each improved code. The example display screen in FIG. 5 associates a "Code Identification Number," which is an identifier for each improved code, with a "Processing Time (sec)," which indicates the evaluation result of the execution performance. The "Processing Time (sec)" is, for example, the time required to execute the code in the execution unit 13. Also, in the example display screen in FIG. 5, a button for displaying the original and improved codes is displayed as "Display." The example display screen in FIG. 5 displays the improved codes in order of shortest processing time. For example, a person generating code can easily select code with high execution performance by referring to information regarding the improvement results such as the example in FIG. 5.

[0057] FIG. 6 is an example of a display screen displaying the scores for each execution performance of the improved code as information about the result of code improvement. The example display screen of FIG. 6 displays an "original code" indicating the name of the code before improvement and a score indicating the execution performance of each improved code. The example display screen of FIG. 6 associates a "code identification number" that is an identifier for each improved code with a "score" indicating the evaluation result of the execution performance. The example display screen of FIG. 6 displays the scores for "processing time," "power consumption," "memory consumption," and "overall" for each improved code. In the example display screen of FIG. 6, the "processing time" score is calculated based on the processing time of the code. In the example display screen of FIG. 6, the "power consumption" score is calculated based on the power consumption during execution of the code. In the example display screen of FIG. 6, the "memory consumption" score is calculated based on the memory consumption during execution of the code. Furthermore, in the example display screen of FIG. 6, the "overall" score is, for example, the average of the scores for "processing time," "power consumption," and "memory consumption." In addition, in the example display screen of Figure 6, a button to display the original and improved code is displayed as "Display." In the example display screen of Figure 6, the improved code is displayed in order of shortest processing time. For example, by referring to information about the improvement results such as the example of Figure 6, a person in charge of generating code can select code according to the execution performance that is most important.

[0058] The memory unit 19 stores, for example, data related to the process of improving code. The memory unit 19 stores, for example, the code to be improved acquired by the acquisition unit 11. The memory unit 19 stores, for example, correct answer data for input / output data acquired by the acquisition unit 11. The memory unit 19 stores, for example, prompts used to improve code. The memory unit 19 stores, for example, evaluation criteria for evaluating the execution performance of code. The memory unit 19 also stores, for example, improved code. For example, the memory unit 19 stores the improved code in association with the evaluation results of the execution performance.

[0059] The terminal device 20 is, for example, a terminal device used by a user of the code improvement system. The user of the code improvement system is, for example, a person in charge of generating program code. The terminal device 20 acquires, for example, code to be improved and a prompt indicating the content of the code improvement input by a user. The terminal device 20 then outputs, for example, the code to be improved and a prompt indicating the content of the code improvement to the acquisition unit 11 of the code improvement device 10. The terminal device 20 also acquires information regarding the code improvement results from, for example, the output unit 18 of the code improvement device 10. The terminal device 20 then outputs, for example, the information regarding the code improvement results to a display device (not shown). The terminal device 20 may be, for example, a notebook personal computer or a desktop personal computer. The terminal device 20 is not limited to the above.

[0060] The following describes the process of improving program code in the code improvement device 10. Fig. 7 shows an example of the operational flow of the process of improving program code in the code improvement device 10.

[0061] The acquisition unit 11 acquires, for example, a code to be improved and a prompt indicating the content of the improvement (step S11).

[0062] Once the code to be improved and the prompt indicating the content of the improvement are obtained, the code improvement unit 12 improves the program code using a language model that improves the program code based on the prompt indicating the content of the improvement to the program code (step S12).

[0063] Once the code has been improved, the execution unit 13 executes the process using the improved code (step S13).

[0064] If the code is executed normally (Yes in step S14), the evaluation unit 15 evaluates the execution performance of the code based on the execution result of the code (step S15).

[0065] When the execution performance of the code is evaluated, the output unit 18 stores the code and the evaluation result of the execution performance of the code in association with each other in the storage unit 19, for example.

[0066] When the code and the execution performance evaluation results are saved in step S16, if the criteria for terminating the process for improving the code are not met (No in step S17), the determination unit 16 determines the code to be improved, for example, based on the execution performance evaluation results (step S19). The determination unit 16 determines the code to be improved by deciding whether to adopt the improved code based on the execution performance evaluation results.

[0067] Once the code to be improved is determined, the process returns to step S12, and the code improving unit 12 improves the code determined as the code to be improved, for example.

[0068] Furthermore, when the code and the evaluation results of execution performance are saved in step S16, if the criteria for terminating the process for improving the code are met (Yes in step S17), the code improvement device 10 terminates the process for improving the code.

[0069] Furthermore, if the code is not executed normally in the process of executing the code in step S13 (No in step S14), the determination unit 16, for example, discards the code that was not executed normally and determines the code before improvement as the code to be improved (step S18). Once the code to be improved has been determined, the process returns to step S12, and the code improvement unit 12, for example, improves the code determined as the code to be improved.

[0070] The code improvement device 10 improves the program code using a language model for improving the program code, based on a prompt indicating the content of the improvement to the program code. The code improvement device 10 executes a process using the improved code. The code improvement device 10 also evaluates the execution performance of the code based on the execution results of the code. Then, the code improvement device 10 determines whether to adopt the improved code based on the evaluation results of the execution performance.

[0071] In this way, by improving the code using a language model and determining whether to adopt the improved code based on the results of the execution performance evaluation, the code improvement device 10 can automatically generate high-performance code, thereby enabling it to efficiently improve the code of a program.

[0072] When an error occurs during code execution and the code in which the error occurred is debugged using a language model, the code improvement device 10 can, for example, debug the improved code and utilize the code that becomes usable through debugging, which may enable efficient generation of various codes. Also, by correcting the code in which the error occurred through debugging and discarding the code whose output data does not match the correct data, the code improvement device 10 may be able to generate various codes more efficiently.

[0073] Each process in the code improvement device 10 can be realized by executing a computer program on a computer. Fig. 8 shows an example of the configuration of a computer 100 that executes a computer program that performs each process in the code improvement device 10. The computer 100 includes a CPU (Central Processing Unit) 101, a memory 102, a storage device 103, an input / output I / F (Interface) 104, and a communication I / F 105.

[0074] The CPU 101 reads and executes computer programs for performing each process from the storage device 103. The CPU 101 may be configured by a combination of multiple CPUs. The CPU 101 may also be configured by a combination of a CPU and another type of processor. For example, the CPU 101 may be configured by a combination of a CPU and a graphics processing unit (GPU). The memory 102 is configured by a dynamic random access memory (DRAM) or the like, and temporarily stores the computer programs executed by the CPU 101 and data being processed. The storage device 103 stores the computer programs executed by the CPU 101. The storage device 103 is configured by, for example, a non-volatile semiconductor storage device. Other storage devices such as a hard disk drive may also be used for the storage device 103. The input / output I / F 104 is an interface that receives input from an operator and outputs display data, etc. The communication I / F 105 is an interface that transmits and receives data between the terminal device 20, the generation device 30, the information processing device 40, and other information processing devices. Furthermore, the terminal device 20, the generating device 30, and the information processing device 40 may have the same configuration as the computer 100.

[0075] The computer program used to execute each process can also be stored and distributed on a computer-readable recording medium that non-temporarily stores data. Examples of recording media that can be used include magnetic tapes for recording data and magnetic disks such as hard disks. Optical disks such as CD-ROMs (Compact Disc Read Only Memory) can also be used as recording media. Non-volatile semiconductor storage devices can also be used as recording media.

[0076] A part or all of the above-described embodiments can be described as, but not limited to, the following supplementary notes.

[0077] [Appendix 1] a code improvement means for improving the program code using a language model for improving the program code based on a prompt indicating the content of the improvement to the program code; an execution means for executing a process using the improved code; evaluation means for evaluating the execution performance of the code based on the execution result of the code; a determining means for determining whether to adopt the improved code based on the evaluation result of the execution performance; A code improvement device comprising:

[0078] [Appendix 2] When it is determined that the improved code is to be adopted, the code improvement means improves the code by using the language model and the improved code as a target for improvement based on the prompt, and when it is determined that the improved code is not to be adopted, the code improvement means improves the code by using the language model and the unimproved code as a target for improvement again based on the prompt. 2. A code improvement device as described in Appendix 1.

[0079] [Appendix 3] the code improvement means improves the code to be improved, either the improved code or the unimproved code, based on the same prompt as the prompt used to improve the code; 3. A code improvement device according to claim 1 or 2.

[0080] [Appendix 4] the evaluation means evaluates the execution performance of the code when the code is normally executed. 4. A code improvement device according to any one of appendices 1 to 3.

[0081] [Appendix 5] a code correcting means for correcting the error in the code when an error occurs during execution of the code, using a prompt including an error message as an input to the language model; the code improving means improves the code in which the error has been corrected using the language model based on the prompt. 5. A code improvement device according to any one of appendices 1 to 4.

[0082] [Appendix 6] the execution means outputs the generated code to an information processing device in which the code is actually used, and acquires an execution result of the code in the information processing device. 6. A code improvement device according to any one of appendices 1 to 5.

[0083] [Appendix 7] the execution means executes the code in a simulator that reproduces an information processing device in which the code is actually used. 6. A code improvement device according to any one of appendices 1 to 5.

[0084] [Appendix 8] the determining means determines the code to be improved based on the evaluation results of execution performance in a plurality of items. 8. A code improvement device according to any one of appendices 1 to 7.

[0085] [Appendix 9] further comprising an output unit for outputting the evaluation result of the execution performance, 9. A code improvement device according to any one of appendices 1 to 8.

[0086] [Appendix 10] the output means stores the code and the evaluation result of the execution performance of the code in association with each other. 10. The code improvement device of claim 9.

[0087] [Appendix 11] the output means outputs the evaluation results of each of the plurality of execution performances. 10. The code improvement device of claim 9.

[0088] [Appendix 12] the execution performance includes at least one of an execution time of the code, an amount of memory consumed when the code is executed, power consumption when the code is executed, and readability; 12. A code improvement device according to any one of appendices 1 to 11.

[0089] [Appendix 13] further comprising a prompt generating means for generating the prompt based on an evaluation result of the code. 13. A code improvement device according to any one of appendices 1 to 12.

[0090] [Appendix 14] further comprising an acquisition means for acquiring information indicating a change in the prompt; the prompt generating means generates the prompt based on the acquired information indicating the change. 14. The code improvement apparatus of claim 13.

[0091] [Appendix 15] improving the code of the program using a language model that improves the code of the program based on prompts indicating the content of the improvement of the code of the program; Execute a process using the improved code; Evaluating the execution performance of the code based on the execution result of the code; determining whether to adopt the improved code based on the results of the execution performance evaluation; How to improve the code.

[0092] [Appendix 16] a process of improving the code of the program using a language model for improving the code of the program based on prompts indicating the content of the improvement of the code of the program; executing a process using the improved code; A process of evaluating execution performance of the code based on the execution result of the code; a process of determining whether to adopt the improved code based on the evaluation result of the execution performance; A code improvement program that causes a computer to execute the following.

[0093] Furthermore, some or all of the configurations described in Supplementary Notes 2 to 14, which are dependent on Supplementary Note 1, may also be dependent on Supplementary Notes 15 and 16 in the same dependent relationship as Supplementary Notes 2 to 19. Furthermore, not limited to Supplementary Notes 1, 15, and 16, some or all of the configurations described as Supplements may be made dependent on various hardware, software, various recording means for recording software, or systems, within the scope of each of the above-mentioned embodiments.

[0094] Although the present disclosure has been described above with reference to the embodiments, the present disclosure is not limited to the above-described embodiments. Various modifications that can be understood by those skilled in the art can be made to the configuration and details of the present disclosure within the scope of the present disclosure. Furthermore, each embodiment can be combined with other embodiments as appropriate. [Explanation of symbols]

[0095] 10 Code Improvement Device 11 Acquisition Department 12 Code Improvement Section 13 Executive Department 14 Code Modifications 15 Evaluation Section 16 Decision Section 17 Prompt Generation 18 Output section 19 Memory section 20 Terminal equipment 30 Generator 40 Information processing equipment 100 computers 101 CPU 102 memory 103 Storage device 104 Input / Output Interface 105 Communication I / F

Claims

1. a code improvement means for improving the program code using a language model for improving the program code based on a prompt indicating the content of the improvement to the program code; an execution means for executing a process using the improved code; evaluation means for evaluating the execution performance of the code based on the execution result of the code; a determining means for determining whether to adopt the improved code based on the evaluation result of the execution performance; A code improvement device comprising:

2. When it is determined that the improved code is to be adopted, the code improvement means improves the code by using the language model and the improved code as a target for improvement based on the prompt, and when it is determined that the improved code is not to be adopted, the code improvement means improves the code by using the language model and the unimproved code as a target for improvement again based on the prompt. The code improvement device according to claim 1 .

3. the code improvement means improves the code to be improved, either the improved code or the unimproved code, based on the same prompt as the prompt used to improve the code; The code improvement device according to claim 2 .

4. the evaluation means evaluates the execution performance of the code when the code is normally executed. The code improving device according to any one of claims 1 to 3.

5. a code correcting means for correcting the error in the code when an error occurs during execution of the code, using a prompt including an error message as an input to the language model; the code improving means improves the code in which the error has been corrected using the language model based on the prompt. The code improving device according to any one of claims 1 to 3.

6. the execution means outputs the generated code to an information processing device in which the code is actually used, and acquires an execution result of the code in the information processing device. The code improving device according to any one of claims 1 to 3.

7. the execution means executes the code in a simulator that reproduces an information processing device in which the code is actually used. The code improving device according to any one of claims 1 to 3.

8. the determining means determines the code to be improved based on the evaluation results of execution performance in a plurality of items. The code improving device according to any one of claims 1 to 3.

9. improving the code of the program using a language model that improves the code of the program based on prompts indicating the content of the improvement of the code of the program; Execute a process using the improved code; Evaluating the execution performance of the code based on the execution result of the code; determining whether to adopt the improved code based on the results of the execution performance evaluation; How to improve the code.

10. a process of improving the code of the program using a language model for improving the code of the program based on prompts indicating the content of the improvement of the code of the program; executing a process using the improved code; A process of evaluating execution performance of the code based on the execution result of the code; a process of determining whether to adopt the improved code based on the evaluation result of the execution performance; A code improvement program that causes a computer to execute the following.

Citation Information

Patent Citations

  • Code enrichment through metadata for code synthesis

    JP2023047334A