Text generation system
The text generation system addresses the inefficiency in generating repository documentation by identifying key code portions and using a processor to generate explanatory text, effectively summarizing extensive program code, thus enhancing documentation creation efficiency.
Patent Information
- Application Number
- PCT/JP2024/017108
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-16
- Filing Date
- 2024-05-08
- Publication Date
- 2024-11-21
AI Technical Summary
Current methods for generating documentation for an entire repository, such as README files, are inefficient as they rely on manual creation or static template filling, and existing code comment generation techniques are inadequate for summarizing large volumes of program code, failing to support the creation of abstract summaries from tens of thousands to millions of lines of code.
A text generation system that identifies representative program code portions and uses a processor to generate explanatory text based on model information and prompt templates, capable of abstractly summarizing extensive program code, including features like representative program code identification and content generation units, to produce documentation for entire repositories.
Enables the automatic generation of comprehensive documentation for entire repositories by abstractly summarizing large volumes of program code, improving efficiency and reducing manual effort in creating detailed explanations.
Smart Images

Figure JP2024017108_21112024_PF_FP_ABST
Abstract
Description
Text Generation System
[0001] The present invention relates to text generation systems.
[0002] In recent years, automation of software development has progressed significantly, as exemplified by low-code / no-code development. However, the current situation is that explanatory text (documentation) for the entire repository, such as readmes, which is as important as the program code, is still created manually, despite being a source of worry for many developers.
[0003] As a means to support the creation of documentation for the entire repository, a system is known that presents static templates to developers and fills in the templates based on user input. However, these methods only show developers the requirements for creating documentation, and do not actually support developers in writing the content of the documentation.
[0004] Related technologies include, for example, Patent Document 1 and Non-Patent Document 1.
[0005] Patent Document 1 discloses a method for creating documentation for an entire repository by collecting one or more code comments from program code and combining the code comments.
[0006] Non-Patent Document 1 discloses a system that generates code comments for a class or function from the program code of the class or function by utilizing a large-scale language model.
[0007] Japanese Patent Application Laid-Open No. 2000-163260
[0008] Yue Wang, Weishi Wang, Shafiq Joty and Steven C. H. Hoi. 2021. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pp. 8696-8708. Association for Computational Linguistics.
[0009] Patent Document 1 merely compiles code comments that have already been written by the developer, and does not disclose a method for creating documentation for the entire repository from the program code itself.
[0010] In Non-Patent Document 1, the generation of code comments for a class or function merely involves generating at most a few lines of highly specific explanatory text from several tens of lines of program code.
[0011] On the other hand, when generating documentation for an entire repository, such as readme, it is necessary to abstractly summarize and generate tens of thousands to millions of lines of program code, but the amount of calculation in Non-Patent Document 1 increases quadratically with the length of the input program code. Therefore, code comment generation technology cannot be applied to the problem of generating documentation for an entire repository.
[0012] The object of the present invention is to generate documentation for an entire repository by abstractly summarizing tens of thousands to millions of lines of program code in a text generation system.
[0013] A text generation system according to one aspect of the present invention is a text generation system that generates explanatory text for program code from program code using a processor, and is characterized by having a representative program code identification unit that identifies a program code portion that describes representative processing of the program from the program code, and a content generation unit that generates the explanatory text for the program code based on the program code portion and at least one setting value as model information.
[0014] According to one aspect of the present invention, a text generation system can abstractly summarize tens of thousands to millions of lines of program code to generate documentation for an entire repository.
[0015] FIG. 1 is a diagram illustrating an example of the configuration of a text generation system according to a first embodiment. FIG. 2 is a diagram illustrating an example of the configuration of a text generation system according to a first embodiment. FIG. 3 is a flowchart illustrating an example of processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 4 is a diagram illustrating input and output of data in processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 5 is a diagram illustrating input and output of data in processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 6 is a diagram illustrating input and output of data in processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 7 is a diagram illustrating input and output of data in processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 8 is a flowchart illustrating an example of processing executed by a representative program code identification unit 110 according to a first embodiment. FIG. 9 is a flowchart illustrating an example of processing executed by a content generation unit 112 according to a first embodiment. FIG. 10 is a diagram illustrating an example of a token dictionary. FIG. 11 is a diagram illustrating an example of the configuration of a text generation system according to a second embodiment. FIG. 12 is a flowchart illustrating an example of processing executed by a learning unit 1310 according to a second embodiment. FIG. 13 is a diagram illustrating an example of a prompt template. FIG. 10 is a diagram showing an example of a prompt template. FIG. 11 is a diagram showing an example of the configuration of a text generation system of Example 3. FIG. 12 is a flowchart explaining an example of processing executed by an output ranking unit 1601 of Example 3. FIG. 13 is a diagram showing an example of the configuration of a text generation system of Example 4. FIG. 14 is a diagram showing an example of a prompt template. FIG. 15 is a diagram showing an example of a prompt template. FIG. 16 is a diagram showing an example of a prompt template. FIG. 17 is a diagram showing an example of a prompt template. FIG. 18 is a diagram showing an example of a prompt template. FIG. 19 is a diagram showing an example of the configuration of a text generation system of Example 5. FIG. 19 is a flowchart explaining an example of processing executed by an interactive input accepting unit 2101 of Example 5. FIG. 19 is a diagram showing an example of a prompt template ... content displayed on a user interface of an output unit (display unit) of Example 6.It is a figure which shows an example of the contents to be displayed on the user interface of the output unit (display unit) of Example 6. It is a figure which shows an example of the contents to be displayed on the user interface of the output unit (display unit) of Example 6. It is a figure which shows an example of the prompt template.
[0016] Hereinafter, examples of the present invention will be described with reference to the drawings. However, the present invention should not be construed as being limited to the description of the embodiments shown below. Those skilled in the art will readily understand that the specific configuration can be changed within the scope of the idea or purpose of the present invention.
[0017] In the configuration of the invention described below, the same or similar configurations or functions are denoted by the same reference numerals, and redundant explanations will be omitted.
[0018] In this specification, the terms "first," "second," "third," etc. are used to identify components and do not necessarily limit the number or order.
[0019] To facilitate understanding of the invention, the position, size, shape, range, etc. of each component shown in the drawings etc. may not represent the actual position, size, shape, range, etc. Therefore, the present invention is not limited to the position, size, shape, range, etc. disclosed in the drawings etc.
[0020] 1 and 1A are diagrams illustrating an example of the configuration of a text generation system (computer system) according to a first embodiment.
[0021] The text generation system receives a program code repository as input and outputs documentation for the entire repository. In the first embodiment, a computer system is assumed that receives a repository written in Python as input and outputs one English readme that is documentation for the entire repository.
[0022] The program code in question is not limited to Python, but may be any computer language intended to be executed by a computer for the purpose of providing one or more functions, such as programming languages or markup languages such as Java, JavaScript, C, R, Mathematica, Visual Basic for Applications, HTML, or a domain-specific language (DSL) created by a user, or a combination thereof, regardless of whether it is in a state or form that can actually be executed by a computer.
[0023] Furthermore, the output documentation may be not only a readme but also a part of a design specification, a user document, a usage manual, or the like, regardless of language, as long as it is abstract documentation for the entire repository.
[0024] The text generation system is composed of a single computer 100. The computer 100 has a processor 101, a memory 102, and a network interface 103. Each piece of hardware is connected to each other via an internal bus. The computer 100 may also have storage devices such as a hard disk drive (HDD) and a solid state drive (SSD), input devices such as a keyboard, a mouse, and a touch panel, and an output device such as a display.
[0025] The processor 101 executes a program stored in the memory 102. The processor 101 executes processing in accordance with the program, thereby operating as a functional unit (module) having a predetermined function. In the following description, when a processing is described using a functional unit as the subject, it means that the processor 101 is executing a program that realizes the functional unit.
[0026] The memory 102 stores programs executed by the processor 101 and information required for the programs. The memory 102 also includes a work area temporarily used by the programs. The network interface 103 connects to other devices via a network.
[0027] Here, the programs and information stored in the memory 102 of the computer 100 will be described.
[0028] The memory 102 of the computer 100 holds model information 111 and a prompt template database 113 , and also stores programs that realize a representative program code identification unit 110 and a content generation unit 112 .
[0029] The representative program code identification unit 110 receives program code as input and identifies from the program code a program code fragment that describes a representative process of the program. The representative process of the program is, for example, an abstract overall process of the program.
[0030] The representative program code may take various forms, such as an entry point for an application, a facade in a facade design pattern, or a base class in an object-oriented library.
[0031] The program code fragment is a part of the program code, and is at least one of a file, a package, a function, a class, a code block, a user interface component, etc. In the first embodiment, a file is used as the program code fragment.
[0032] The content generation unit 112 receives the program code fragment and generates explanatory text for the program code based on at least one setting value stored in the model information 111 .
[0033] The computer system may also include a terminal or the like for inputting data to the computer 100 and acquiring data from the computer 100. The functions of the computer 100 may be realized by two or more computers connected via a network. The computer 100 may also be realized using virtualization technology.
[0034] The processing executed by the representative program code identification unit 110 will be described with reference to Figures 2 to 9. Figures 2, 7, and 9 are flowcharts illustrating an example of processing executed by the representative program code identification unit 110 of Example 1. Figures 3, 4, 5, 6, and 8 are diagrams illustrating input and output of data in processing executed by the representative program code identification unit 110 of Example 1.
[0035] First, the representative program code identifying unit 110 receives program code written in the programming language Python and consisting of one or more files (step S201).
[0036] The program code may be a set of files managed by a single repository, a set of files managed across multiple repositories, a subset of files managed by a single repository, or a set of files managed by means other than a repository.
[0037] Next, the representative program code identification unit 110 divides the program code into N files 300 (step S202). The division may be by file, or by a unit smaller than a file, such as a function or class. It may also be by a unit spanning multiple files, such as a package, or by a non-exclusive unit, such as a combination of a package and a function.
[0038] As shown in FIG. 3, a file 300 stores a file identifier 301 unique to the file 300, a file directory 302 that is the storage location of the file 300 in the repository, and file contents 303 recorded in the file.
[0039] Next, the representative program code identification unit 110 starts loop processing of the file 300 (step S203).
[0040] Next, the representative program code identification unit 110 analyzes the file contents 303 of the target file 300 and identifies the files 300 on which the program code in the file contents 303 depends (step S204). A dependency edge 401 is added from the target file 300 to the dependency graph 400 (see FIG. 4 ) to the file 300 on which the program code depends. Static program analysis may be used, regular expressions may be used, or dynamic analysis or reverse engineering may be performed after compiling the program code.
[0041] Next, the representative program code identification unit 110 analyzes the file contents 303 of the target file 300 to identify the file 300 containing a class that is inherited by a class contained in the target file (step S205). An inheritance edge 501 is added from the target file 300 to the dependent file 300 in the inheritance graph 500 (see FIG. 5).
[0042] Next, the representative program code identification unit 110 determines whether or not the processing has been executed for all files 300 included in the program code (step S206).
[0043] If it is determined that there is at least one file 300 for which processing has not been executed, the representative program code identification unit 110 returns to step S203 and executes the same processing.
[0044] If it is determined that processing has been executed for all files 300 included in the program code, the representative program code identification unit 110 ends the loop processing of the files 300 and proceeds to step S207.
[0045] Next, the representative program code identification unit 110 calculates the dependency graph ordinal number 602 of each file 300 from the dependency graph 400 (step S207). The calculation of the dependency graph ordinal number S207 will be described with reference to FIGS.
[0046] The representative program code identification unit 110 starts loop processing of the file 300 (step S701). The target file 300 is referred to as target file i.
[0047] The representative program code identification unit 110 starts loop processing of the file 300 (step S702). The target file 300 is referred to as target file j.
[0048] The representative program code identification unit 110 stores the distance (the number of edges in the shortest path) on the directed graph from target file j to target file i in the dependency graph 400 at the coordinate (i, j) in the distance matrix 601 (step S703). If target file i cannot be reached from target file j, 0 is stored.
[0049] Next, the representative program code identification unit 110 determines whether or not the process of step S703 has been executed for all files 300 included in the program code (step S704).
[0050] If it is determined that there is at least one file 300 for which processing has not been executed, the representative program code identification unit 110 returns to step S702 and executes the same processing.
[0051] If it is determined that processing has been executed for all files 300 included in the program code, the representative program code identification unit 110 ends the loop processing of the files 300 and proceeds to step S705.
[0052] The representative program code identification unit 110 calculates the maximum value of the i-th column of the distance matrix 601 and stores it as the dependency graph ordinal number 602 of the target file i (step S705).
[0053] Next, the representative program code identification unit 110 determines whether or not the processes from step S702 to step S705 have been executed for all files 300 included in the program code (step S706).
[0054] If it is determined that there is at least one file 300 for which processing has not been executed, the representative program code identification unit 110 returns to step S701 and executes the same processing.
[0055] If it is determined that processing has been executed for all files 300 included in the program code, the representative program code identification unit 110 ends the loop processing of the files 300 and ends the calculation of the dependency graph ordinal numbers S207.
[0056] Next, the representative program code identification unit 110 starts loop processing of the file 300 (step S208).
[0057] Next, the representative program code identification unit 110 calculates a provisional classification result 801 indicating the likelihood of the target file 300 being a representative program code (step S209). The calculation of the provisional classification result S209 will be described with reference to FIGS.
[0058] If the dependency graph ordinal number 602 of the target file 300 is the same as the smallest value of the dependency graph ordinal numbers 602 of all files 300, the representative program code identification unit 110 determines that the target file 300 is at the top of the dependency graph (step S901). Since a file at the top of the dependency graph is likely to describe a representative and abstract process of code, such as an entry point, if the determination result is true, the value "1" is stored in (i, 0) of the provisional classification result 801, which indicates the likelihood that the target file 300 is representative program code, and if the determination result is negative, the value "0" is stored in (i, 0) of the provisional classification result 801.
[0059] Next, if the dependency graph ordinal number 602 of the target file 300 is the same as the maximum value of the dependency graph ordinal numbers 602 of all files 300, the representative program code identification unit 110 determines that the target file 300 is at the bottom of the dependency graph 400 (step S902).
[0060] Since a file at the bottom of the dependency graph is unlikely to be an entry point that is likely to describe representative and abstract processing, if the judgment result is true, the value "-1" is stored in (i, 1) of the provisional classification result 801, which indicates the likelihood of the target file 300 being representative program code, and if the judgment result is negative, the value "0" is stored in (i, 1) of the provisional classification result 801.
[0061] Next, the representative program code identification unit 110 determines whether the in-degree of the target file 300 in the inheritance graph 500 is 3 or greater (step S903).
[0062] When a class inherits from many classes, there is a high possibility that the class describes representative and abstract processing of code, such as a base class in an object-oriented library, and therefore, if the judgment result is true, a value of "1" is stored in (i, 2) of the provisional classification result 801, which indicates the likelihood of the target file 300 being representative program code, and if the judgment result is negative, a value of "0" is stored in (i, 2) of the provisional classification result 801. The threshold value of the in-degree may be any value.
[0063] Next, the representative program code identification unit 110 determines whether the file name of the target file 300 includes the character string "main" based on the file directory 302 of the target file 300 (step S904).
[0064] When a file has a file name containing the character string "main," there is a high possibility that the file describes a representative and abstract process of code, such as an entry point. Therefore, if the determination result is true, a value of "1" is stored in (i, 3) of the provisional classification result 801, which indicates the likelihood of the target file 300 being representative program code, and if the determination result is negative, a value of "0" is stored in (i, 3) of the provisional classification result 801. Note that any character string, such as "cli" or "command," may be used instead of the character string "main."
[0065] Next, the representative program code identification unit 110 determines whether or not a function containing the character string "main" exists in the target file 300 based on the file contents 303 of the target file 300 (step S905).
[0066] When a function contains the character string "main," there is a high possibility that the function describes a representative and abstract process of the code, such as an entry point, and therefore, if the determination result is true, a value of "1" is stored in (i, 4) of the provisional classification result 801, which indicates the likelihood of the function being representative program code of the target file 300, and if the determination result is negative, a value of "0" is stored in (i, 4) of the provisional classification result 801. Note that instead of the character string "main," any character string, such as "cli," may be used.
[0067] Next, the representative program code identification unit 110 determines whether the file size of the target file 300 is 300 bytes or less based on the file contents 303 of the target file 300 (step S906). If the program code written in a certain file is extremely short, it is unlikely that specific processing is written in the file. Therefore, if the determination result is true, a value of "-1" is stored in (i, 5) of the provisional classification result 801, which indicates the likelihood of the target file 300 being representative program code. If the determination result is negative, a value of "0" is stored in (i, 5) of the provisional classification result 801. Note that the threshold value may be any value other than 300 bytes, and the determination target may be another indicator, such as the number of Unicode characters.
[0068] Next, the representative program code identification unit 110 ends the calculation of the provisional classification result S209.
[0069] Next, the representative program code identification unit 110 determines whether or not the process of step S209 has been executed for all files 300 included in the program code (step S210).
[0070] If it is determined that there is at least one file 300 for which processing has not been executed, the representative program code identification unit 110 returns to step S208 and executes the same processing.
[0071] If it is determined that processing has been executed for all files 300 included in the program code, the representative program code identification unit 110 ends the loop processing of the files 300 and proceeds to step S211.
[0072] Next, the representative program code identification unit 110 calculates a file score 802 indicating the likelihood of the target file 300 being a representative program code by adding up the provisional classification results 801 for each file (step S211). Any integration method, such as weighted sum or voting, may be used to integrate the provisional classification results 801. Alternatively, weakly supervised learning may be used in which the file scores 802 are regarded as pseudo-ground truth data, a file score 802 predictor is created using the provisional classification results 801 or the file contents 303 as features, and the file scores 802 are recalculated using the predictor.
[0073] Next, the representative program code identification unit 110 selects the file 300 with the largest file score 802 of each file 300 (step S212). Note that two or more files 300 may be selected, for example, by selecting files 300 in descending order of the file score 802 of each file 300 until the total file size exceeds a threshold value.
[0074] Furthermore, when selecting two or more files 300, the files 300 may be selected using a combination of different viewpoints, such as excluding files 300 whose file contents 303 are highly similar to those of the selected file 300. In the first embodiment, when multiple files 300 are selected, the file contents 303 are combined and treated as if they were a single file 300.
[0075] Although the first embodiment describes a method using six weak classifiers, any number of weak classifiers may be used. The weak classifiers used are not limited to those disclosed above, and may include a variety of processing, including programming language-dependent processing, application format-dependent processing, and meta-information-dependent processing, such as "whether an argument analyzer is included," "is the processing equivalent to a controller in an MVC model," "whether the file name does not start with 'test_'," "is the file initially registered in version control software," and "is the file created by a specific user." Furthermore, the weak classifiers may be specified by the user, regardless of the file contents 303.
[0076] This concludes the description of the processing executed by the representative program code identification unit 110.
[0077] The content generation unit 112 generates a readme using the model information 111, the prompt template database 113, and the selected file 300 as inputs. The processing of the content generation unit 112 will be explained using Figs.
[0078] The content generator 112 receives an input of the selected file 300 (step S1001).
[0079] Next, the content generation unit 112 performs preprocessing on the files 300 (step S1002). In this preprocessing, import statements and license statements at the beginning of the files that are deemed unnecessary for understanding the abstract processing of the code repository are removed from the file contents 303 of each file 300 using regular expressions, and the file contents 303 of each file 300 are then combined. Note that this preprocessing may also involve removing duplicate descriptions and identifying important parts based on heuristics.
[0080] Next, the content generator 112 shortens the combined file contents 303 to a representative program code string of the first K characters based on a predetermined threshold K (step S1003). Note that instead of removing only the first K characters, any shortening method may be used, such as removing only the last K characters, or removing only the first K / 2 characters and the last K / 2 characters. Furthermore, any value may be specified for the threshold K according to the desired calculation time.
[0081] Next, the content generator 112 creates a prompt by combining the representative program code character string with a prompt template (for example, prompt template 1100-1 in FIG. 18A) obtained from the prompt template 113 (step S1004).
[0082] 18A, prompt template 1100-1 is composed of prompt text 1101 that prompts the creation of documentation in natural language, a representative program code placeholder 1102, and a file placeholder 1103. The content generator 112 stores the representative program code character string in the representative program code placeholder 1102, extracts file names from the file directories 302 of files 300 randomly extracted from the repository, combines the file names, and stores them in the file placeholder 1103.
[0083] If the prompt template 1100-1 is intended to generate documentation using representative program code, it does not need to be configured with prompt text 1101, representative program code placeholder 1102, and file placeholder 1103, and may include various information such as repository name, user name, license information, etc. Furthermore, such information may be separately input from the user through interactive questions, a setting file, or the like (see FIG. 24).
[0084] Next, the content generator 112 divides the prompt into a prompt token string consisting of one or more tokens (step S1005). A "token" generally refers to the smallest unit constituting a programming language, such as a variable name, reserved word, or operator, but in the present invention, division may be performed using a unit other than a "token" in a programming language, such as byte pair encoding.
[0085] Next, the content generator 112 converts the prompt token sequence into a prompt token index sequence {t 0 , t 1 ,...t P} (step S1006). This conversion is realized by matching each token constituting the prompt token string with a token 1201 in the token dictionary 1200 and obtaining an index 1202 associated with the matching token 1201. If there is no token 1201 that matches the token, the token is associated with a predetermined index 1202.
[0086] Next, the content generator 112 starts loop processing of the variable i (step S1007). 0 is stored in the variable i as an initial value. Using a probability distribution model for token index sequences such as GPT-3, the prompt token index sequence and the generated token index sequences up to the (i-1)th sequence are input, and the generated token index x i Calculate the probability distribution of .
[0087] p(x i |θ, t 0 , t 1 ,...t P , x 0 , x 1 , ..., x i-1 ) where θ is a setting value (parameter) of the probability distribution model stored in the model information 111.
[0088] The generated token index with the maximum probability value is acquired as the i-th generated token index.
[0089] argmax xi p(x i |t 0 , t 1 ,...t P , x 0 , x 1 , ..., x i-1 Note that instead of selecting the token index with the maximum probability value, it is also possible to perform sampling based on a probability distribution, or to select a token index using beam search, etc. Furthermore, the probability distribution model may be realized by a model based on a Transformer architecture such as T5 or BLOOM, a model based on recursive computation such as ELMo, or a model based on distributed computation such as GShare.
[0090] The probability distribution model may be a model that learns the probability distribution of words using various documents, a model with the same architecture as the above model that learns the probability distribution of words using an original corpus, or any combination of these models.As long as an input token index can be generated based on the input token index sequence, the probability distribution requirement does not need to be met.
[0091] Next, the content generator 112 determines whether the i-th generated token index is a token index indicating the end of the document, or whether the variable i is the predetermined number of generated tokens L minus 1 (step S1009).
[0092] If it is determined that the condition is not satisfied, the content generation unit 112 increments the variable i and returns to step S1007 to execute the same process. If it is determined that the condition is satisfied, the content generation unit 112 ends the loop process of the variable i and proceeds to step S1010.
[0093] The content generator 112 generates the generated token index sequence {x 0 , x 1 , ..., x L-1} is converted into generated text 1104 (step S1010). In this conversion, first, each token index constituting the generated token index string is matched with an index 1202 in a token dictionary 1200, and a generated token string is obtained by acquiring a token 1201 linked to the matching index 1202. Then, the generated token string is combined to obtain a generated text.
[0094] In this way, generated text 1104 such as that shown in prompt template 1100-3 of FIG. 19 is obtained.
[0095] Next, the content generator 112 performs post-processing on the generated text (step S1011). In this post-processing, three or more line breaks in the generated text are converted into two line breaks. Note that any conversion based on heuristics or machine learning may be performed depending on the desired state of the generated text.
[0096] According to the first embodiment, the computer system can generate documentation for the entire repository by abstractly summarizing tens of thousands to millions of lines of program code.
[0097] FIG. 12 is a diagram illustrating an example of the configuration of a text generation system (computer system) according to the second embodiment.
[0098] In the second embodiment, the computer 100 generates documentation without using the prompt template database 113. The second embodiment will be described below, focusing on the differences from the first embodiment.
[0099] The configuration of the computer system of the second embodiment is the same as that of the first embodiment. The hardware configuration of the computer 100 of the second embodiment is the same as that of the first embodiment. Furthermore, the processing executed by the representative program code identification unit 110 of the second embodiment is the same as that of the first embodiment.
[0100] In the second embodiment, the software configuration of the computer 100 is partially different. In the memory 102 of the computer 100 in the third embodiment, a program for realizing a model learning unit 1301 is stored in addition to a program for realizing a content generation unit 112.
[0101] The model learning unit 1301 receives one or more selected files 300 as input, calculates the setting values (parameters) of the probability distribution model of the model, and stores the values in the model information 111. The processing performed by the model learning unit 1301 will be described with reference to Figures 13, 14A, and 14B.
[0102] The model learning unit 1301 receives a file 300 and one or more pairs of correct documentation pairs corresponding to the file 300 (S1401).
[0103] The correct documentation may be created manually, or readme files may be extracted from a repository that is publicly available as open source software.
[0104] Next, the model learning unit 1301 starts a loop process of the file 300 and the correct documentation pair (step S1402).
[0105] The processing from S1002 to S1006 is the same as in Example 1. However, in Example 2, model learning is performed, so there is no need for a prompt template that prompts the generation of documentation as in Example 1. Instead, as shown in prompt 1510-1 in Fig. 14A, the representative program code placeholder 1102 and file placeholder 1103 are combined with an appropriate character string to create prompt 1510-2 (see Fig. 14B).
[0106] In steps S1403 and S1404, the same processes as in steps S1005 and S1006 are performed on the supervised documentation, respectively, to obtain a supervised documentation token index string.
[0107] Next, the model learning unit 1301 starts loop processing of the variable i (step S1405), storing 0 as the initial value in the variable i.
[0108] The process of S1008 is the same as that of claim 1.
[0109] Generated token index x at i-th i and the correct documentation token index x' at the i-th i Based on the probability distribution of loss l iCalculate.
[0110] l i = -log p(x i = x' i |θ, t 0 , t 1 ,...t P , x 0 , x 1 , ..., x i-1 Next, the model learning unit 1301 determines whether the i-th correct documentation token index is a token index indicating the end of the document (step S1009).
[0111] If it is determined that the condition is not satisfied, the content generation unit 112 increments the variable i and returns to step S1007 to execute the same process. If it is determined that the condition is satisfied, the content generation unit 112 ends the loop process of the variable i and proceeds to step S1407.
[0112] Next, the model learning unit 1301 calculates the sum L of the losses (step S1408).
[0113] L = Σ i l i Next, the model learning unit 1301 calculates each parameter θ from the sum L of the losses. k∈ Gradient Δ with respect to θ k Calculate the parameter θ k is updated based on the gradient (step S1409).
[0114] Δ k = ∂L / ∂θ k θ k ←θ k -ηΔ k Next, the model learning unit 1301 determines whether the processes from step S1002 to step S1409 have been executed for all file 300 and correct documentation pairs (step S1410). If it is determined that there is at least one file 300 and correct documentation pair for which the processes have not been executed, the model learning unit 1301 returns to step S1002 and executes the same processes.
[0115] If it is determined that the processing has been executed for all file 300 and correct documentation pairs, the model learning unit 1301 ends the loop processing of the file 300 and correct documentation pairs, and proceeds to step S1409.
[0116] Next, the model learning unit 1301 stores the updated parameter θ in the model information 111 (step S1401).
[0117] This concludes the description of the processing executed by the model learning unit 1301.
[0118] While the above example illustrates model training using stochastic gradient approximation, it is also possible to use mini-batch stochastic gradient approximation or more sophisticated optimization methods using AdamW or second-order derivatives. Furthermore, instead of a word-by-word classification problem, symmetric learning or reinforcement learning may also be used.
[0119] The processing of the content generation unit 112 in the second embodiment is the same as that in the first embodiment. However, similar to the model learning unit 1301, as shown in Fig. 14A, the representative program code placeholder 1102 and the file placeholder 1103 are combined with an appropriate character string to create a prompt 1510-2 (Fig. 14B).
[0120] According to Example 2, the computer system can efficiently generate documentation by learning a model and utilizing a relatively smaller model than in Example 1. In addition, it is no longer necessary to adjust prompt templates for each model, allowing for more robust generation.
[0121] FIG. 15 is a diagram illustrating an example of the configuration of a text generation system (computer system) according to the third embodiment.
[0122] In the third embodiment, the computer 100 generates a plurality of documentation candidates. The third embodiment will be described below, focusing on the differences from the first embodiment.
[0123] The configuration of the computer system of the third embodiment is the same as that of the first embodiment. The hardware configuration of the computer 100 of the third embodiment is the same as that of the first embodiment.
[0124] In the third embodiment, the software configuration of the computer 100 is partially different. The memory 102 of the computer 100 in the third embodiment stores a program that realizes an output ranking unit 1601 in addition to programs that realize an input unit 117, a representative program code identification unit 110, a content generation unit 112, and an output unit 118.
[0125] The representative program code identifying unit 110 of the third embodiment will be described with reference to FIGS. 2 and 8. FIG.
[0126] The processes from steps S201 to S211 are the same as those in the first embodiment.
[0127] Next, the representative program code identification unit 110 selects P (P≧1) files 300 with the highest file scores 802 (step S212). When selecting multiple files 300, the files 300 may be selected using a different perspective, such as excluding files 300 whose file contents 303 are highly similar to those of the selected files 300. Instead of selecting multiple files 300, file 300 selection may be repeated P times until the total file size exceeds a threshold, thereby selecting P sets of files 300. When multiple sets of files 300 are selected, the file contents 303 of each set of files 300 are combined and treated as if they were P files 300.
[0128] The above is a description of the process executed by the representative program code identification unit 110 of the third embodiment.
[0129] The processing performed by the content generation unit 112 in the third embodiment is the same as that in the first embodiment. However, processing is performed for a combination (P×Q sets) of the P files 300 and Q (Q≧1) prompt templates 1100-1. Note that it is not necessary to apply the content generation unit 112 to all combinations of the P×Q sets. For example, the content generation unit 112 may be applied to R sets (≦P×Q) selected at random. Furthermore, the content generation unit 112 in the third embodiment may generate K (K≧1) documentation candidates using nucleus sampling or the like.
[0130] The output ranking unit 1601 receives the one or more documentation candidates and sorts the documentation candidates in an order that is deemed appropriate for documentation. The processing performed by the output ranking unit 1601 will be described with reference to FIG.
[0131] The output ranking unit 1601 receives one or more documentation candidates (step S1701).
[0132] Next, the output ranking unit 1601 starts a loop process of the documentation candidates (step S1702).
[0133] Next, the output ranking unit 1601 analyzes the selected candidate documentation and calculates the coverage score s of the candidate documentation. c Since the appropriate Readme must describe the project's purpose and installation information, if the documentation candidate contains any of the strings "goal," "aim," "objective," or "provide" as a reference to the project purpose, then s c = 1, if the documentation candidate contains any of the strings "install", "set up", "getting started", "prerequisite", or "how to" c = 1, if both of the above conditions are met, s c = 2, if both of the above conditions are met, s c =0.
[0134] Next, the output ranking unit 1601 analyzes the selected candidate documentation and calculates the redundancy score s of the candidate documentation. r (Step S1704). Since it is not desirable for the same description to be repeated many times in an appropriate Readme, if two or more document candidates contain the same character string of 30 or more characters, s r = -1, otherwise s r =0.
[0135] Next, the output ranking unit 1601 analyzes the selected candidate documentation and calculates the content amount score s of the candidate documentation. l Since an appropriate Readme usually has a certain length or more, if the number of characters in the documentation candidate is less than 200, s l = -2, otherwise s l =0.
[0136] Next, the output ranking unit 1601 calculates the coverage score s c , the redundancy score s r , the content amount score s l Based on these scores, a total score s of the selected documentation candidate is calculated (step S1705). The total score s is calculated as the simple sum of the three scores.
[0137] s=s c +s r +s l Next, the output ranking unit 1601 determines whether the process has been executed for all the documentation candidates (step S1707).
[0138] If it is determined that there is at least one documentation candidate for which processing has not been performed, the output ranking unit 1601 returns to step S1702 and performs the same processing.
[0139] If it is determined that the process has been executed for the documentation candidate, the output ranking unit 1601 ends the loop process for the documentation candidate, and the process proceeds to step S1708.
[0140] Next, the output ranking unit 1601 sorts the documentation candidates so that the total score s of each documentation candidate is in descending order (step S1708). Note that when sorting the documentation candidates, the sorting may be performed using a different perspective, such as deleting a documentation candidate whose content is highly similar to a selected documentation candidate. This concludes the description of the processing executed by the output ranking unit 1601.
[0141] Although the output ranking unit 1301 using three heuristics has been described in the third embodiment, the output ranking unit 1601 may be implemented using different heuristics. Also, a rank learner trained using pairs of documentation candidates and their manually assigned appropriateness scores may be used.
[0142] The output unit 118 of the third embodiment receives the one or more sorted documentation candidates and outputs one documentation. At this time, the top-ranked documentation may be output, or the top T documentation candidates may be presented to the user and the user may be prompted to select one.
[0143] According to the third embodiment, the computer system can generate appropriate documentation with a higher probability than the first embodiment. Furthermore, since an appropriate prompt template is selected for each model, the robustness of the prompt template is improved. Furthermore, by presenting multiple documentation candidates to the user, the documentation can be generated based on the user's preferences, which may differ from those of the system designer.
[0144] FIG. 17 is a diagram illustrating an example of the configuration of a text generation system (computer system) according to the fourth embodiment.
[0145] In the fourth embodiment, the computer 100 generates the documentation in multiple batches and then aggregates them. The fourth embodiment will be described below, focusing on the differences from the first embodiment.
[0146] The configuration of the computer system of the fourth embodiment is the same as that of the first embodiment. The hardware configuration of the computer 100 of the fourth embodiment is the same as that of the first embodiment.
[0147] In the fourth embodiment, the software configuration of the computer 100 is partially different. The memory 102 of the computer 100 in the fourth embodiment stores a program that realizes the input portion 117, the representative program code identification unit 110, the content generation unit 112, and the output unit 118, as well as a program that realizes the generated text aggregating unit 1801.
[0148] The processing performed by the content generator 112 in the fourth embodiment is the same as that in the first embodiment, except for the prompt template database 113, which stores one or more prompt templates 1100-1 including documentation write-out 1901, as shown in Figures 18A, 18B, and 19.
[0149] The documentation opening 1901 is the title of the content to be included in the Readme. The content generator 112 generates generated text 1104 for each prompt template 1100-1 (see FIG. 19). The prompt template database 113 may also use prompt templates 1100-1 that have other documentation openings 1901, such as license information. Furthermore, the user's desired content may be selected based on the prompt template 1100-1 (see FIG. 24).
[0150] The generated text aggregating unit 1801 combines the one or more generated texts 1104 to create a final documentation. The generated text aggregating unit 1801 will be described with reference to Fig. 19. The generated text aggregating unit 1801 combines the one or more generated texts 1104 to create a documentation 2000.
[0151] According to the third embodiment, the computer system can generate documentation that always includes desired content.
[0152] FIG. 20 is a diagram illustrating an example of the configuration of a text generation system (computer system) according to the fifth embodiment.
[0153] In the fifth embodiment, the computer 100 generates documentation in multiple steps through dialogue with the user. The fifth embodiment will be described below, focusing on the differences from the first embodiment.
[0154] The configuration of the computer system of the fifth embodiment is the same as that of the first embodiment. The hardware configuration of the computer 100 of the fifth embodiment is the same as that of the first embodiment.
[0155] In the fifth embodiment, the software configuration of the computer 100 is partially different. The memory 102 of the computer 100 in the fifth embodiment stores a program that realizes an interactive input receiving unit 2101 in addition to the programs that realize the input portion 117, the representative program code identifying unit 110, the content generating unit 112, and the output unit 118.
[0156] The processing performed by the content generating unit 112 and the interactive input receiving unit 2101 of the fifth embodiment will be described with reference to FIGS. 21 to 22D.
[0157] The interactive input receiving unit 2101 receives the documentation 2301 edited by the user (step S2201). When step S2201 is executed for the first time, the user inputs the writing of the documentation as shown in FIG.
[0158] Next, the content generation unit 112 of Example 5 generates documentation based on the documentation 2301 edited by the user (step S2202). The process performed by the content generation unit 112 of Example 5 is the same as that of Example 1. However, the content generation unit 112 regards the documentation 2301 edited by the user as part of the prompt 1110-2, and generates the remaining documentation 2302 (FIG. 22B).
[0159] Next, the interactive input receiving unit 2101 presents the generated text 1104 to the user (step S2203).
[0160] Next, the content generation unit 112 receives an input from the user indicating whether or not additional dialogue is desired (step S2204). If the user does not desire additional dialogue, the interactive input receiving unit 2101 ends the process. If the user desires additional dialogue, the content generation unit 112 returns to step S2201.
[0161] Next, interactive input accepting unit 2101 accepts documentation 2301 edited by the user based on generated text 1104 (step S2201). When step S2201 is executed for the second time, for example, the user can erase or add to the content of generated text 1104, as shown in FIG. 22C.
[0162] Next, the content generation unit 112 of Example 5 generates documentation based on the documentation 2301 that has been re-edited by the user (step S2202). The process performed by the content generation unit 112 of Example 5 is the same as that of Example 1. However, the content generation unit 112 regards the documentation 2301 that has been edited by the user as part of the prompt, and generates the remaining documentation 2302 (see FIG. 22D).
[0163] The above is the description of the processes executed by the content generating unit 112 and the interactive input receiving unit 2101 of the fifth embodiment.
[0164] According to the fifth embodiment, the computer system can interactively generate documentation including content desired by the user.
[0165] In the sixth embodiment, the computer 100 presents the generated text 1104 together with the prompt 1110-2 and the selected file 300 used to generate the generated text 1104.
[0166] The configuration of the computer system and the hardware configuration of the computer 100 of the sixth embodiment are the same as those of the first embodiment. The hardware configuration and the software configuration of the computer 100 of the sixth embodiment are the same as those of the first embodiment.
[0167] The output unit (display unit) 118 (see FIG. 1) of the sixth embodiment will be described with reference to FIGS. 23A to 23C.
[0168] The output unit (display unit) 118 of the sixth embodiment displays a user interface 2300. The user interface 2300 is composed of a tab 2301 for switching between display panes, an output pane 2302-1 for displaying the generated text 1104, a prompt pane 2302-2 for displaying the prompt used to generate the generated text 1104, and a representative code pane 2302-3 for displaying the selected file 300 used to create the prompt. Note that the user interface 2300 may also include other intermediate outputs generated in the process of implementing the present invention, such as a provisional classification result 801 indicating the likelihood that each file 300 is representative program code.
[0169] According to the sixth embodiment, the computer system can provide the user with a means to check whether the generated documentation is valid.
[0170] According to the above embodiment, by identifying representative code fragments that provide an overview of what the code repository does, it is possible to generate documentation for the entire repository by abstractly summarizing tens of thousands to millions of lines of program code using a large-scale language model in a realistic execution time.
[0171] REFERENCE SIGNS LIST 100 Computer 101 Processor 102 Memory 103 Network interface 110 Representative program code identification unit 111 Model information 112 Content generation unit 117 Input unit 118 Output unit 1301 Learning unit 1601 Output ranking unit 1801 Generated text aggregation unit 2101 Interactive input unit
Claims
1. A text generation system that generates explanatory text for program code from program code using a processor, comprising: a representative program code identification unit that identifies a program code portion that is a part of the program code in which a representative process of the program is described; and a content generation unit that generates the explanatory text for the program code based on the program code portion and at least one setting value as model information.
2. The text generation system according to claim 1, characterized in that the representative program code identification unit identifies, as the program code portion, a program code fragment that constitutes the program code fragment.
3. The text generation system described in claim 1, characterized in that the representative program code identification unit identifies a program code portion in which an abstract overall processing of the program is described as the representative processing of the program, and identifies at least one of a file, a package, a function, a class, a code block, and a user interface component as the program code portion.
4. The text generation system according to claim 1, characterized in that the representative program code identification unit identifies the program code portion from the program code based on the contents of the program code.
5. The text generation system described in claim 1, characterized in that the representative program code identification unit divides the program code into a plurality of program code portions, and identifies the program code portions based on at least one of the contents of the divided plurality of program code portions and the structural relationships between the divided plurality of program code portions.
6. The text generation system according to claim 1, characterized in that the content generation unit uses parameter values of an affine transformation or a nonlinear transformation as the setting values, and generates the explanatory text by the affine transformation or the nonlinear transformation.
7. The text generation system according to claim 1, further comprising a prompt template database which holds at least one character string that controls the content generated by the content generation unit, wherein the content generation unit receives input of the character string from the prompt template database and generates the explanatory text based on the setting value and the character string.
8. The text generation system according to claim 1, further comprising a model learning unit that learns the model information from the program code portion identified by the representative program code identification unit, and generates the setting value based on the learned model information.
9. The text generation system according to claim 1, characterized in that the content generation unit generates a plurality of explanatory texts for the program code.
10. The text generation system according to claim 9, further comprising an output ranking unit that assigns a predetermined order to the multiple explanatory texts.
11. The text generation system according to claim 9, further comprising a generated text aggregation unit that generates an aggregated generated text by aggregating a plurality of the explanatory texts.
12. The text generation system according to claim 1, further comprising an interactive input accepting unit that accepts text input by a user, wherein the content generation unit generates the explanatory text based on the text input, the program code portion and the setting value.
13. The text generation system according to claim 1, further comprising a display unit for displaying the explanatory text.
Citation Information
Patent Citations
Specification generating program and its recording medium, and specification generating device and method
JP2005122407A
Device for extracting specification from source code
JP2018005746A
Code enrichment through metadata for code synthesis
JP2023047334A
Data storage apparatus and operation method the same
KR1020240167242A
Cited By
Information processing system, information processing apparatus, control method, and program
WO2025253881A1
