Code interpretation method and device
By obtaining and analyzing the context and call relationships of the code segment, using a trained model to generate deep code interpretation, the problem of insufficient code interpretation in the existing technology is solved, and the efficiency of code understanding is improved.
Patent Information
- Application Number
- CN202311785212.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-10-10
- Filing Date
- 2023-12-22
- Publication Date
- 2025-04-11
AI Technical Summary
The existing large language model can only realize the superficial understanding of the code segment, and the output interpretation information is not very helpful to developers to understand the meaning of the code and business logic.
By obtaining the first code segment and its associated second code segment, and using the model obtained by training based on the contact training of multiple sets of associated code segments and interpretation information, the interpretation information of the first code segment is determined. This method includes obtaining the above, the following, the call relationship and the called relationship of the code segment, etc., to generate a deeper code explanation.
A deep understanding of the code segment is achieved. The generated interpretation information can better explain the business logic of the code, helping developers quickly understand the code segment.
Smart Images

Figure CN119806627A_ABST
Abstract
Description
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to a Chinese patent application with application number 202311308643.8 filed on October 10, 2023, and invention name “A global code interpretation method and device with context and call relationship awareness”, the entire contents of which are incorporated by reference into this application. Technical Field
[0003] The present invention relates to the field of artificial intelligence technology, and in particular to a code interpretation method and device. Background Art
[0004] In the field of natural language processing, with the rapid development of large language models (LLM), the code interpretation function of large language models has also received widespread attention. Generally speaking, developers can directly input the code segment to be interpreted into the large language model, and the large language model will output the corresponding interpretation information of the code segment, helping developers to understand the meaning of the code segment more efficiently.
[0005] However, the large language models currently used can only achieve a superficial understanding of code snippets, and the explanatory information of the output code snippets is not very helpful for developers to understand the meaning of the code and business logic. How to obtain effective explanatory information is a technical problem that needs to be solved urgently. Summary of the invention
[0006] The present application provides a code interpretation method and device for obtaining effective interpretation information for a code segment.
[0007] In the first aspect, an embodiment of the present application provides a code interpretation method, which can be executed by a processor of a computer device. The method specifically includes the following steps: the processor obtains a first code segment, the processor determines a second code segment that has an association relationship with the first code segment, wherein the second code segment includes at least one of the following: P first contexts that have an association relationship with the first code segment, Q first contexts that have a context relationship with the first code segment, S first sub-code segments that have a calling relationship with the first code segment, or W second sub-code segments that have a called relationship with the first code segment, P, Q, S, and W are all positive integers, and finally, the processor determines the interpretation information of the first code segment according to the first code segment, the second code segment, and the first model, wherein the interpretation information of the first code segment is used to interpret the meaning expression of the first code segment, and the first model is obtained based on the connection training between multiple groups of first historical code segments and second historical code segments that have an association relationship and the interpretation information of the first historical code segment.
[0008] The explanation information of the first code segment obtained by the above method can explain the business logic of the first code segment, which is helpful for developers to quickly understand the first code segment.
[0009] In a possible design, the processor determines the interpretation information of the first code segment according to the first code segment, the second code segment and the first model, which may include: the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Through this design, the interpretation information of the first code segment can be conveniently determined.
[0010] Alternatively, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, since the encoding vector corresponding to the second code segment can effectively exclude redundant information in the second code segment, and the encoding vector corresponding to the second code segment requires a small memory space, inputting the encoding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0011] In a possible design, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the first code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform the code interpretation task, and the processor then inputs the prompt information corresponding to the first code segment, the first code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In the above design, inputting the prompt information corresponding to the first code segment into the first model is conducive to improving the accuracy of the determined interpretation information of the first code segment.
[0012] In a possible design, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the placeholder of the second code segment, wherein the placeholder of the second code segment is used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the placeholder of the first code segment, the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, the placeholder of the second code segment can effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment, and the first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment.
[0013] In a possible design, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the explanation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the second code segment is used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the prompt information corresponding to the first code segment and the second code segment and the second code segment into the first model, and uses the output of the first model as the explanation information of the first code segment. In this design, the prompt information corresponding to the second code segment can effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the explanation information of the first code segment. Secondly, the prompt information corresponding to the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate explanation information of the first code segment based on the association between the first code segment and the second code segment.
[0014] In a possible design, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the explanation information of the first code segment, which may include: the processor first determines the placeholder of the second code segment and the prompt information corresponding to the second code segment, wherein the placeholder of the second code segment and the prompt information corresponding to the second code segment are used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the prompt information corresponding to the first code segment, the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the explanation information of the first code segment. In this design, the prompt information corresponding to the second code segment and the placeholder of the second code segment can more effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the explanation information of the first code segment. Secondly, the prompt information corresponding to the second code segment and the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment, and the first model can output more accurate explanation information of the first code segment according to the association between the first code segment and the second code segment.
[0015] In one possible design, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of association between the second code segment and the first code segment; then, the processor inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0016] In a possible design, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the first code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform the code interpretation task, and the processor then inputs the prompt information corresponding to the first code segment, the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, the prompt information corresponding to the first code segment can be used to prompt the first model to perform the code interpretation task.
[0017] In a possible design, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the placeholder of the second code segment, wherein the placeholder of the second code segment is used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the placeholder of the first code segment, the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, the placeholder of the second code segment can effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment, and the first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment. Since the coding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment and the coding vector corresponding to the second code segment requires little memory space, inputting the coding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0018] In a possible design, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the second code segment is used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the prompt information corresponding to the first code segment and the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, the prompt information corresponding to the second code segment can effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment. Since the coding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment and the coding vector corresponding to the second code segment requires little memory space, inputting the coding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0019] In a possible design, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the placeholder of the second code segment and the prompt information corresponding to the second code segment, wherein the placeholder of the second code segment and the prompt information corresponding to the second code segment are used to indicate the type of association between the second code segment and the first code segment, and the processor then inputs the prompt information corresponding to the first code segment and the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. In this design, the prompt information corresponding to the second code segment and the placeholder of the second code segment can more effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment and the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment, and the first model can output more accurate interpretation information of the first code segment according to the association between the first code segment and the second code segment. Since the coding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment and the coding vector corresponding to the second code segment requires little memory space, inputting the coding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0020] In one possible design, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which may include: the processor first determines the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of the association relationship between the second code segment and the first code segment; the processor then inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0021] In a possible design, the type of association relationship includes at least one of the following:
[0022] The above relationship is used to indicate that the second code segment is a segment of code before the first code segment;
[0023] The following relationship is used to indicate that the second code segment is a segment of code following the first code segment;
[0024] A calling relationship, used to indicate that different sub-code segments in the second code segment are used to call the first code segment;
[0025] The called relationship is used to indicate that different sub-code segments in the second code segment are used to be called by the first code segment.
[0026] In one possible design, the encoding vector corresponding to the second code segment includes at least one of the following:
[0027] When the second code segment includes P first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the P first contexts respectively;
[0028] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the Q first contexts respectively;
[0029] When the second code segment includes S first sub-codes that have a calling relationship with the first code segment, the encoding vector corresponding to the second code segment is the first calling vectors corresponding to the S first sub-code segments respectively;
[0030] When the second code segment includes W second sub-codes that are in a called relationship with the first code segment, the encoding vector corresponding to the second code segment is the first called vectors corresponding to the W second sub-code segments respectively.
[0031] In a possible design, the P first context vectors are obtained by inputting the P first contexts into the second model respectively, and the P first context vectors correspond to the P first contexts one by one; or
[0032] The Q first context vectors are obtained by inputting the Q first contexts into the second model respectively, and the Q first context vectors correspond to the Q first contexts one by one;
[0033] The second model is used to encode each first context to obtain a corresponding first context vector, or to encode each first context to obtain a corresponding first context vector.
[0034] In one possible design, the P first context vectors are obtained by the following steps:
[0035] For the mth first context among the P first contexts, where m is an integer ranging from [1, P], perform the following steps:
[0036] The processor first segments the mth first context using a first preset length to obtain at least one first context segment, and then the processor inputs the at least one first context segment into the second model to obtain at least one first segment vector, wherein the at least one first segment vector constitutes the mth first context vector. In the above design, since the length of the text segment that can be received by the second model is limited, the segmented first context is input into the second model, which can effectively ensure the correctness of the obtained first context vector.
[0037] In one possible design, the Q first context vectors are obtained by the following steps:
[0038] For the nth first context among the Q first contexts, where n is an integer ranging from [1, Q], perform the following steps:
[0039] The processor first segments the nth first context using a first preset length to obtain at least one first context segment, and then the processor inputs the at least one first context segment into the second model to obtain at least one second segment vector, wherein the at least one second segment vector constitutes the nth first context vector. In the above design, since the length of the text segment that can be received by the second model is limited, the segmented first context is input into the second model, which can effectively ensure the correctness of the obtained first context vector.
[0040] In one possible design, the S first call vectors are obtained by respectively inputting the S first sub-code segments into a third model, the S first call vectors correspond one-to-one to the S first sub-code segments, and the third model is used to encode each first sub-code segment to obtain a corresponding first call vector.
[0041] In a possible design, S first call vectors are obtained by the following steps: for the i-th first sub-code segment among the S first sub-code segments, i is an integer ranging from [1, S], the following steps are performed: the processor first divides the i-th first sub-code segment by a second preset length to obtain at least one first sub-code segment, and the processor then inputs the at least one first sub-code segment into a third model to obtain at least one third segment vector, wherein the at least one third segment vector constitutes the i-th first call vector. In the above design, since the length of the text segment that can be received by the third model is limited, the correctness of the obtained first call vector can be effectively guaranteed by inputting the divided first sub-code segment into the third model.
[0042] In one possible design, W first called vectors are obtained by respectively inputting W second sub-code segments into a fourth model, the W first called vectors correspond one-to-one to the W second sub-code segments, and the fourth model is used to encode each second sub-code segment to obtain the corresponding first called vector.
[0043] In a possible design, W first called vectors are obtained by the following steps: for the jth second sub-code segment among the W second sub-code segments, j is an integer that runs through [1, W], the following steps are performed: the processor first divides the jth second sub-code segment using a third preset length to obtain at least one second sub-code segment, and the processor then inputs the at least one second sub-code segment into the fourth model to obtain at least one fourth segment vector, wherein the at least one fourth segment vector constitutes the jth first called vector. In the above design, since the length of the text segment that the fourth model can receive is limited, the input of the divided second sub-code segment into the fourth model can effectively ensure the correctness of the obtained first called vector.
[0044] In one possible design, the placeholder of the second code segment includes at least one of the following:
[0045] When the second code segment includes P first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the first placeholder of the first context; or
[0046] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the second placeholder of the first context; or
[0047] When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the third placeholder of the first sub-code segment; or
[0048] When the second code segment includes W second sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the fourth placeholder of the second sub-code segment.
[0049] In a possible design, the prompt information corresponding to the second code segment includes at least one of the following:
[0050] When the second code segment includes P first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or
[0051] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or
[0052] When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first sub-code segment; or
[0053] When the second code segment includes W second sub-code segments that are in a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes prompt information corresponding to the second sub-code segments.
[0054] In one possible design, the first model is obtained by training with a first training set, the first training set includes multiple groups of historical training data with explanation labels, the historical training data include multiple groups of first historical code segments, and multiple groups of second historical code segments that are associated with the multiple groups of first historical code segments, the explanation labels corresponding to the historical training data are used to represent the explanation information of the first historical code segments, and the content included in the second historical code segments corresponds to the content included in the second code segments.
[0055] In a possible design, the above method can be applied to an integrated development environment or a cloud code repository. Through this design, an application scenario of the code interpretation method is provided.
[0056] In a second aspect, an embodiment of the present application further provides a code interpretation device, which includes a device for executing the method provided in the first aspect above.
[0057] In a third aspect, an embodiment of the present application further provides a code interpretation device, which includes a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to call the computer program and execute the method provided in the first aspect above.
[0058] In a fourth aspect, an embodiment of the present application further provides a computing device cluster comprising at least one computing device, each computing device comprising a processor and a memory, wherein the processor of at least one computing device is used to execute instructions stored in the memory of at least one computing device, so that the computing device cluster executes the method provided in the first aspect above.
[0059] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed by a computing device cluster, enables the computing device cluster to execute the method provided in the first aspect above.
[0060] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium, comprising computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect above.
[0061] In a seventh aspect, an embodiment of the present application further provides a chip comprising instructions, which, when executed by a computing device cluster, enables the computing device cluster to execute the method provided in the first aspect above.
[0062] In an eighth aspect, an embodiment of the present application provides a chip system including instructions, when the instructions are executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect above. The chip system may be composed of a chip, or may include a chip and other discrete devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A schematic diagram of the structure of a computer device provided in an embodiment of the present application;
[0064] Figure 2 A flowchart of a code interpretation method provided in an embodiment of the present application;
[0065] Figure 3 A schematic diagram of the structure of a first code segment provided in an embodiment of the present application;
[0066] Figure 4 A schematic diagram of the structure of a first code segment provided in an embodiment of the present application;
[0067] Figure 5 A schematic diagram of the structure of a first code segment provided in an embodiment of the present application;
[0068] Figure 6 A schematic diagram of the structure of a first code segment provided in an embodiment of the present application;
[0069] Figure 7 A schematic diagram of a structure of an input form of input data provided in an embodiment of the present application;
[0070] Figure 8 A schematic diagram of a structure of an input form of input data provided in an embodiment of the present application;
[0071] FIG9( a) is a schematic diagram of the structure of explanation information of a first code segment provided in an embodiment of the present application;
[0072] FIG9( b) is a schematic diagram of the structure of explanation information of a first code segment provided in an embodiment of the present application;
[0073] Fig.10 A schematic diagram of the structure of a code interpretation device provided in an embodiment of the present application;
[0074] Fig.11 A schematic diagram of the structure of a code interpretation device provided in an embodiment of the present application;
[0075] Fig.12 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0076] Fig.13 A schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
[0077] Fig.14 A schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0078] In order to make the purpose, technical solution and advantages of the present application more clear, the present application will be further described in detail below with reference to the accompanying drawings. The specific operation methods, functional descriptions, etc. in the method embodiments can also be applied to the device embodiments or system embodiments.
[0079] Below, some terms in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0080] A large language model is a deep learning model trained with a large amount of text data that can generate natural language text or understand the meaning of language text. A large language model can handle a variety of natural language tasks, such as text classification, question answering, and dialogue, and is an important path to artificial intelligence.
[0081] An integrated development environment (IDE) is a software application that provides comprehensive convenience for computer programmers to develop software. An IDE usually contains at least a source code editor, build automation tools, and a debugger.
[0082] Code interpretation uses natural language to analyze and explain a given program code in order to better understand the function and logic of the code. Code interpretation can include explanations of variables, functions, classes, modules, etc., as well as analysis of program logic.
[0083] Prompt information: In a large language model, prompt information is a piece of prompt text used to guide the large language model to generate a specific type of output. By designing and optimizing a set of prompt information, the large language model can perform specific tasks.
[0084] Currently, the big language model can interpret code segments written in any programming language. The programming language can be a high-level language such as C / C++, Java, Python, etc., or a low-level language such as assembly language.
[0085] For ease of explanation, the following code snippets are written in Python as examples. The code snippets may include the following lines of code:
[0086] def extract_codes(data_list):
[0087] codes_list = []
[0088] for line in data_list:
[0089] body = line.get('body')
[0090] code_str = find_code(body)
[0091] code_list.append(code_str)
[0092] return codes_list
[0093] Input the above code snippet into the large language model, and the large language model can output the explanation information of the above code snippet, as follows:
[0094] "This code extracts all the codes from a list of data and returns a list containing those codes.
[0095] The main logic of the code is as follows:
[0096] 1. Create an empty code list codes_list.
[0097] 2. For each row in the data list:
[0098] -Use the get() method to get the body field in the row.
[0099] -Call the find_code() method, pass body as a parameter, and return the code string.
[0100] -Add code string to codes_list.
[0101] 3. Return the codes_list list. "
[0102] It can be seen from the explanation information of the above code segment output by the large language model that the above explanation information can only provide a surface understanding of the above code segment, that is, it only provides a description of each method in the above code segment, and does not provide a logical analysis of the above code segment. Therefore, the explanation information of the above code segment output by the large language model is not very helpful for developers to understand the meaning of the above code segment and the business logic. In view of this, the embodiment of the present application provides a code interpretation method and device.
[0103] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0104] Figure 1 FIG. 1 shows a possible structure diagram of a computer device to which the code interpretation method provided in the embodiment of the present application is applicable. Figure 1 As shown, the computer device includes: a processor 110, a memory 120, a communication module 130, an input unit 140, a display unit 150, a power supply 160 and other components. Those skilled in the art can understand that Figure 1 The structure of the computer device shown in the figure does not constitute a limitation on the computer device. The computer device provided in the embodiment of the present application may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0105] Combine the following Figure 1 A detailed introduction to the various components of a computer device:
[0106] The communication module 130 can be connected to other devices by wireless connection or physical connection to realize data transmission and reception of the computer device. Optionally, the communication module 130 can include any one or a combination of radio frequency (RF) circuit, wireless fidelity (WiFi) module, communication interface, Bluetooth module, etc., which is not limited in the embodiment of the present application.
[0107] The memory 120 may be used to store program instructions and data. The processor 110 executes various functional applications and data processing of the computer device by running the program instructions stored in the memory 120. Among them, the program instructions may enable the processor 110 to execute the code interpretation method provided in the following embodiments of the present application.
[0108] Optionally, the memory 120 may mainly include a program storage area and a data storage area. The program storage area may store an operating system, various application programs, and program instructions, etc.; the data storage area may store various data such as the first model file. In addition, the memory 320 may include a high-speed random access memory, and may also include a non-volatile memory, such as a disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0109] The input unit 140 may be used to receive information such as data or operation instructions input by a user. Optionally, the input unit 140 may include input devices such as a touch panel, function keys, a physical keyboard, a mouse, a camera, and a monitor.
[0110] The display unit 150 can realize human-computer interaction and is used to display information input by the user, information provided to the user, etc. through a user interface. The display unit 150 may include a display panel 151. Optionally, the display panel 151 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.
[0111] Furthermore, when the input unit includes a touch panel, the touch panel may cover the display panel 151. When the touch panel detects a touch event on or near it, it transmits the touch event to the processor 110 to determine the type of the touch event and perform a corresponding operation.
[0112] The processor 110 is the control center of the computer device, and uses various interfaces and lines to connect the above components. The processor 110 can complete various functions of the computer device by executing program instructions stored in the memory 120 and calling data stored in the memory 120 to implement the code interpretation method provided in the embodiment of the present application.
[0113] Optionally, the processor 110 may include one or more processing units. Specifically, the processing unit may include a hardware device such as a CPU and / or a GPU that can perform floating-point operations. The processing unit can determine the interpretation information of the first code segment. When the processor 110 of the computer device implements the code interpretation method, the processing unit reads the first code segment from the storage data area of the memory 120, and determines the second code segment that is associated with the first code segment, and then determines the interpretation information of the first code segment based on the first code segment, the second code segment and the first model.
[0114] The computer device also includes a power supply 160 (such as a battery) for supplying power to various components. Optionally, the power supply 160 can be logically connected to the processor 110 through a power management system, so that the power management system can realize functions such as charging and discharging of the computer device.
[0115] Although not shown, the computer device may also include components such as a camera, a sensor, and an audio collector, which will not be described in detail here.
[0116] The present application embodiment provides a code interpretation method. The method can be Figure 1 The processor in the computer device shown executes. Figure 2 As shown, the process of the method includes:
[0117] S201: The processor obtains a first code segment.
[0118] In an embodiment of the present application, the first code segment may include M lines of code to be interpreted, where M is a positive integer.
[0119] Optionally, the first code segment can be determined from a script file. If the code in the script file is written in an object-oriented programming manner, the processor can determine the first code segment from the class. Generally speaking, a class includes multiple methods, and the processor can select the code in at least one method in the class as the first code segment. For example, Figure 3 As shown, a Demo class is defined, and the processor can select the code in the extract_codes() method from the Demo class as the first code segment.
[0120] If the code in the script file is written in a procedure-oriented programming manner, the processor can directly select the code in at least one method as the first code segment. Figure 4 As shown, the processor can select the code in the extract_codes() method as the first code segment.
[0121] S202: The processor determines a second code segment that is associated with the first code segment.
[0122] In an embodiment of the present application, the association relationship includes at least one of the following: a preceding relationship, a following relationship, a calling relationship, or a called relationship. Among them, the preceding relationship is used to indicate that the second code segment is a segment of code before the first code segment. The following relationship is used to indicate that the second code segment is a segment of code after the first code segment. The calling relationship is used to indicate that different sub-code segments in the second code segment are used to call the first code segment. The called relationship is used to indicate that different sub-code segments in the second code segment are used to be called by the first code segment.
[0123] The second code segment includes at least one of the following: P first contexts that have a context relationship with the first code segment, Q first contexts that have a context relationship with the first code segment, S first sub-code segments that have a calling relationship with the first code segment, or W second sub-code segments that have a called relationship with the first code segment, where P, Q, S, and W are all positive integers.
[0124] The first above, the first below, the first subcode segment, and the second subcode segment are explained below, specifically as follows:
[0125] The first context includes at least one line of code before the first code segment. The processor may use all the code in one or more methods before the first code segment in the script file as the first context, or may use part of the code in one or more methods before the first code segment in the script file as the first context, or may use other code in the script file before the first code segment as the first context.
[0126] It should be understood that the first context may have no relationship with the first code segment, and the first context may also have a calling relationship or a called relationship with the first code segment. For example, the first context calls the first code segment (that is, the first code segment is called by the first context), or the first code segment calls the first context (that is, the first context is called by the first code segment). This is not limited here.
[0127] The first context includes at least one line of code after the first code segment. The processor may use all the code in one or more methods after the first code segment in the script file as the first context, or may use part of the code in one or more methods after the first code segment in the script file as the first context, or may use other code after the first code segment in the script file as the first context.
[0128] It should be understood that the first context may have no relationship with the first code segment, and the first context may also have a calling relationship or a called relationship with the first code segment. For example, the first context calls the first code segment (that is, the first code segment is called by the first context), or the first code segment calls the first context (that is, the first context is called by the first code segment). This is not limited here.
[0129] Each of the S first sub-code segments includes a first call code, wherein the first call code is used to call the first code segment. For the i-th first sub-code segment among the S first sub-code segments, i is an integer that runs through [1, S], and the i-th first sub-code segment can be determined in the following manner: after determining the first call code, the processor can directly use the first call code as the i-th first sub-code segment, or use the x lines of code before the first call code and the first call code as the i-th first sub-code segment, or use the y lines of code after the first call code and the first call code as the i-th first sub-code segment, or use the x lines of code before the first call code, the first call code, and the y lines of code after the first call code as the i-th first sub-code segment, or use the code included in the method including the first call code as the i-th first sub-code segment, or use other methods to determine the i-th first sub-code segment, which are not limited here, wherein x and y are both positive integers.
[0130] Each of the W second sub-code segments includes a first called code, wherein the first called code is used to be called by the first code segment. For the jth second sub-code segment among the W second sub-code segments, j is an integer that runs through [1, W], and the jth second sub-code segment can be determined in the following manner: when the first called code exists in the first code segment, the processor can use the code included in the method corresponding to the first called code as the jth second sub-code segment, and can also use other methods to determine the jth second sub-code segment, which is not limited here.
[0131] It should be understood that, since there may be a calling relationship or a called relationship between the first context and the first code segment, the first context may overlap with the first sub-code segment or the second sub-code segment, which is not limited here.
[0132] Since there may be a calling relationship or a called relationship between the first context and the first code segment, the first context may overlap with the first sub-code segment or the second sub-code segment, which is not limited here.
[0133] For example, if the first code segment determined is Figure 3 As shown, based on Figure 3 The code shown can be determined as Figure 5 The first above context, the first below context, the first sub-code segment, and the second sub-code segment are shown.
[0134] The processor may use all the codes in the parse_html_code() method in the Demo class before the first code segment as the first context, and may use all the codes in the find_code() method in the Demo class after the first code segment as the first context.
[0135] exist Figure 5 In the code shown, the processor can determine two first call codes, namely self.extract_codes(item.get('html')) and demo.extract_codes(). When the first call code is self.extract_codes(item.get('html')), the processor can use all the codes included in the parse_html_code() method including self.extract_codes(item.get('html')) as the first first sub-code segment. When the first call code is demo.extract_codes(), the processor can use a line of code before demo.extract_codes() and demo.extract_codes() as the second first sub-code segment.
[0136] exist Figure 5 In the code shown, after the processor determines that the first called code self.find_code(body) exists in the extract_codes() method, the code included in the method corresponding to self.find_code(body) can be used as the second sub-code segment.
[0137] For example, if the first code segment determined is Figure 4 As shown, based on Figure 4 The code shown can be determined as Figure 6 The first above context, the first below context, the first sub-code segment, and the second sub-code segment are shown.
[0138] The processor may use all the codes in the parse_html_code() method before the first code segment as the first context, and may use all the codes in the find_code() method after the first code segment in the Demo class as the first context.
[0139] exist Figure 6In the code shown, the processor can determine two first call codes, namely extract_codes(item.get('html')) and extract_codes(). When the first call code is extract_codes(item.get('html')), the processor can take all the codes included in the parse_html_code() method including extract_codes(item.get('html')) as the first first sub-code segment. When the first call code is extract_codes(), the processor can take the line of code before extract_codes() and extract_codes() as the second first sub-code segment.
[0140] exist Figure 6 In the code shown, after the processor determines that the first called code find_code(body) exists in the extract_codes() method, the code included in the method corresponding to find_code(body) can be used as the second sub-code segment.
[0141] S203: The processor determines interpretation information of the first code segment according to the first code segment, the second code segment, and the first model.
[0142] In an embodiment of the present application, before executing S203, the processor may use the first training set to train and obtain a first model. Specifically, the processor may obtain a large language model that has been made public, such as a GPT-4 model or a language model for dialogue applications (LaMDA) model, and then use the first training set to fine-tune the GPT-4 model or the LaMDA model to obtain the first model.
[0143] The first training set may include multiple groups of historical training data with explanation labels, the historical training data include multiple groups of first historical code segments, multiple groups of second historical code segments associated with the multiple groups of first historical code segments, and the explanation labels corresponding to the historical training data are used to represent the explanation information of the first historical code segments. The second historical code segments include at least one of the following: A historical contexts that have a context relationship with the first historical code segment, B historical contexts that have a context relationship with the first historical code segment, C first historical sub-code segments that have a calling relationship with the first historical code segment, or D second historical sub-code segments that have a called relationship with the first historical code segment, where A, B, C, and D are all positive integers.
[0144] In the embodiment of the present application, the first model obtained by training is trained based on the relationship between multiple groups of first historical code segments and second historical code segments that have an associated relationship and the explanation information of the first historical code segment. The first model can output the explanation information of the first code segment based on the first code segment and the second code segment, wherein the explanation information of the first code segment can be used to explain the meaning expression of the first code segment.
[0145] It should be understood that the content included in the second historical code segment corresponds to the content included in the second code segment. For example, if the second historical code segment includes A historical contexts, B historical contexts, and C first historical sub-code segments, correspondingly, the second code segment includes P first contexts, Q first contexts, and S first sub-code segments. Among them, the number of historical contexts and the number of first contexts can be the same or different; the number of historical contexts and the number of first contexts can be the same or different; the number of first historical sub-code segments and the number of first sub-code segments can be the same or different, and are not limited here.
[0146] It should be understood that the order in which the first historical code segment and the second historical code segment are input into the first model is the same as the order in which the first code segment and the second code segment are input into the first model. For example, if the order in which the first historical code segment and the second historical code segment are input into the first model is: the first historical code segment, A historical contexts, B historical contexts, C first historical sub-code segments, D second historical sub-code segments, correspondingly, the order in which the first code segment and the second code segment are input into the first model is: the first code segment, P first contexts, Q first contexts, S first sub-code segments, W second sub-code segments.
[0147] In the embodiment of the present application, the interpretation information of the first code segment can be determined through the following ten possible implementation methods.
[0148] In the first implementation mode, the processor inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0149] In a possible implementation manner, when the second code segment includes P first contexts, Q first contexts, S first sub-code segments, and W second sub-code segments, the input data input to the first model may be in the following input form:
[0150] First code snippet
[0151] The first previous context, the second previous context, ..., the Pth previous context
[0152] 1st first context, 2nd first context, ..., Qth first context
[0153] The first first sub-code segment, the second first sub-code segment, ..., the Sth first sub-code segment
[0154] The first second sub-code segment, the second second sub-code segment, ..., the Wth second sub-code segment
[0155] The above method can conveniently determine the interpretation information of the first code segment.
[0156] In implementation mode 2, the processor first determines the prompt information corresponding to the first code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0157] In an embodiment of the present application, the prompt information corresponding to the first code segment can be used to prompt the first model to perform a code interpretation task.
[0158] For example, for Figure 5 or Figure 6 The first code segment shown can determine that the prompt information corresponding to the first code segment is "Please explain the following Python code".
[0159] In a possible implementation manner, when the second code segment includes P first contexts, Q first contexts, S first sub-code segments, and W second sub-code segments, the input data input to the first model may be in the following input form:
[0160] The prompt information corresponding to the first code segment
[0161] First code snippet
[0162] The first previous context, the second previous context, ..., the Pth previous context
[0163] 1st first context, 2nd first context, ..., Qth first context
[0164] The first first sub-code segment, the second first sub-code segment, ..., the Sth first sub-code segment
[0165] The first second sub-code segment, the second second sub-code segment, ..., the Wth second sub-code segment
[0166] In the above method, inputting the prompt information corresponding to the first code segment into the first model is conducive to improving the accuracy of the interpretation information of the first code segment.
[0167] In implementation mode three, the processor first determines the placeholder of the second code segment, and then inputs the first code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment and the placeholder of the second code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0168] In an embodiment of the present application, the placeholder of the second code segment can be used to indicate the type of association relationship between the second code segment and the first code segment. The placeholder of the second code segment includes at least one of the following: when the second code segment includes P first preceding contexts that have a preceding context relationship with the first code segment, the placeholder of the second code segment includes the first placeholder of the first preceding context; or, when the second code segment includes Q first following contexts that have a following context relationship with the first code segment, the placeholder of the second code segment includes the second placeholder of the first following context; or, when the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the third placeholder of the first sub-code segment; or, when the second code segment includes W second sub-code segments that have a called relationship with the first code segment, the placeholder of the second code segment includes the fourth placeholder of the second sub-code segment.
[0169] The first placeholder may be used to indicate that there is a contextual relationship between the second code segment and the first code segment. The first placeholder may appear in pairs, for example, the first placeholder includes <c1>and <\c1>. The first placeholder may be located on both sides of each first context, or on both sides of P first contexts. For ease of description, the following discussion assumes that the first placeholder is located on both sides of P first contexts.
[0170] In the case where the first placeholder is located on both sides of the P first contexts, the first placeholder and the P first contexts may form the following format:
[0171] <c1>The first previous context, the second previous context, ..., the Pth previous context<\c1>
[0172] The second placeholder may be used to indicate that there is a context relationship between the second code segment and the first code segment. The second placeholder may appear in pairs, for example, the second placeholder includes <c2>and <\c2>. The second placeholder can be located on both sides of each first context, or on both sides of Q first contexts. For ease of description, the following discussion assumes that the second placeholder is located on both sides of Q first contexts.
[0173] In the case where the second placeholder is located on both sides of the Q first contexts, the second placeholder and the Q first contexts may form the following form:
[0174] <c2>The first first context, the second first context, ..., the Qth first context<\c2>
[0175] The third placeholder may be used to indicate that there is a calling relationship between the second code segment and the first code segment. The third placeholder may appear in pairs, for example, the third placeholder includes <d1>and <\d1>. The third placeholder may be located on both sides of each first sub-code segment, or may be located on both sides of S first sub-code segments. For ease of description, the following discussion assumes that the third placeholder is located on both sides of S first sub-code segments.
[0176] In the case where the third placeholder is located on both sides of the S first sub-code segments, the third placeholder and the S first sub-code segments may be formed in the following form:
[0177] <d1>The first first subcode segment, the second first subcode segment, ..., the Sth first subcode segment <\d1>
[0178] The fourth placeholder may be used to indicate that there is a calling relationship between the second code segment and the first code segment. The fourth placeholder may appear in pairs, for example, the fourth placeholder includes <d2>and <\d2>. The fourth placeholder may be located on both sides of each second sub-code segment, or may be located on both sides of W second sub-code segments. For ease of description, the following discussion assumes that the fourth placeholder is located on both sides of W second sub-code segments.
[0179] In the case where the fourth placeholder is located on both sides of the W second sub-code segments, the fourth placeholder and the W second sub-code segments may be formed in the following form:
[0180] <d2>The first second subcode segment, the second second subcode segment, ..., the Wth second subcode segment <\d2>
[0181] In a possible implementation manner, if the processor inputs the prompt information corresponding to the first code segment, the first code segment, the placeholder of the second code segment, and the second code segment into the first model, wherein the second code segment includes P first preceding contexts, Q first following contexts, S first sub-code segments, and W second sub-code segments, the input data input into the first model may be in the following input form:
[0182] The prompt information corresponding to the first code segment
[0183] First code snippet
[0184] <c1>The first previous context, the second previous context, ..., the Pth previous context<\c1>
[0185] <c2>The first first context, the second first context, ..., the Qth first context<\c2>
[0186] <d1>The first first subcode segment, the second first subcode segment, ..., the Sth first subcode segment <\d1>
[0187] <d2>The first second subcode segment, the second second subcode segment, ..., the Wth second subcode segment <\d2>
[0188] It should be understood that the input data input into the first model may also be in other input forms, which are not limited here.
[0189] In the above method, the placeholder of the second code segment can effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment.
[0190] In the fourth implementation mode, the processor first determines the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment and the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0191] In an embodiment of the present application, the prompt information corresponding to the second code segment is used to indicate the type of association relationship between the second code segment and the first code segment. The prompt information corresponding to the second code segment includes at least one of the following: when the second code segment includes P first preceding contexts that have a preceding context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first preceding context; or, when the second code segment includes Q first following contexts that have a following context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first following context; or, when the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first sub-code segment; or, when the second code segment includes W second sub-code segments that have a called relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the second sub-code segment.
[0192] The prompt information corresponding to the first context can be used to indicate that there is a context relationship between the first context and the first code segment. The prompt information corresponding to the first context can be located before the first context or after the first context. For the convenience of description, the following discussion assumes that the prompt information corresponding to the first context is located before the first context. The prompt information corresponding to the first context can be located before the first first context or before each first context. For the convenience of description, the following discussion assumes that the prompt information corresponding to the first context is located before the first first context. For example, Figure 5 or Figure 6 The first context shown can determine that the prompt information corresponding to the first context is "the context of the code to be interpreted".
[0193] The prompt information corresponding to the first context can be used to indicate that there is a context relationship between the first context and the first code segment. The prompt information corresponding to the first context can be located before the first context or after the first context. For the convenience of description, the following discussion assumes that the prompt information corresponding to the first context is located before the first context. The prompt information corresponding to the first context can be located before the first first context or before each first context. For the convenience of description, the following discussion assumes that the prompt information corresponding to the first context is located before the first first context. For example, Figure 5 or Figure 6 The first context shown can determine that the prompt information corresponding to the first context is "the context of the code to be interpreted".
[0194] The prompt information corresponding to the first sub-code segment can be used to indicate that there is a calling relationship between the first sub-code segment and the first code segment. The prompt information corresponding to the first sub-code segment can be located before the first sub-code segment, or it can be located after the first sub-code segment. For the convenience of description, the following discussion will assume that the prompt information corresponding to the first sub-code segment is located before the first sub-code segment. The prompt information corresponding to the first sub-code segment can be located before the first first sub-code segment, or it can be located before each first sub-code segment. For the convenience of description, the following discussion will assume that the prompt information corresponding to the first sub-code segment is located before the first first sub-code segment. For example, for Figure 5 or Figure 6 The first sub-code segment shown can determine that the prompt information corresponding to the first sub-code segment is "a code segment that calls the code to be interpreted".
[0195] The prompt information corresponding to the second sub-code segment can be used to indicate that there is a calling relationship between the second sub-code segment and the first code segment. The prompt information corresponding to the second sub-code segment can be located before the second sub-code segment, or it can be located after the second sub-code segment. For the convenience of description, the following discussion will assume that the prompt information corresponding to the second sub-code segment is located before the second sub-code segment. The prompt information corresponding to the second sub-code segment can be located before the first second sub-code segment, or it can be located before each second sub-code segment. For the convenience of description, the following discussion will assume that the prompt information corresponding to the second sub-code segment is located before the first second sub-code segment. For example, for Figure 5 or Figure 6 The second sub-code segment shown can determine that the prompt information corresponding to the second sub-code segment is "the code segment called by the code to be interpreted".
[0196] In a possible implementation manner, if the processor inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, and the second code segment into the first model, wherein the second code segment includes P first preceding contexts, Q first following contexts, S first sub-code segments, and W second sub-code segments, the input data input into the first model may be in the following input form:
[0197] The prompt information corresponding to the first code segment
[0198] First code snippet
[0199] The first corresponding prompt information
[0200] The first previous context, the second previous context, ..., the Pth previous context
[0201] The prompt information corresponding to the first context
[0202] 1st first context, 2nd first context, ..., Qth first context
[0203] Prompt information corresponding to the first sub-code segment
[0204] The first first sub-code segment, the second first sub-code segment, ..., the Sth first sub-code segment
[0205] The prompt information corresponding to the second sub-code segment
[0206] The first second sub-code segment, the second second sub-code segment, ..., the Wth second sub-code segment
[0207] It should be understood that the input data input into the first model may also be in other input forms, which are not limited here.
[0208] In the above method, the prompt information corresponding to the second code segment can effectively distinguish the first code segment from the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment.
[0209] In the fifth implementation mode, the processor first determines the placeholder of the second code segment and the prompt information corresponding to the second code segment, and then inputs the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0210] In an embodiment of the present application, the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of association between the second code segment and the first code segment.
[0211] In a possible implementation manner, if the processor inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, wherein the second code segment includes P first contexts, Q first contexts, S first sub-code segments, and W second sub-code segments, the input data input into the first model may be in the following input form:
[0212] The prompt information corresponding to the first code segment
[0213] First code snippet
[0214] The first corresponding prompt information
[0215] <c1>The first previous context, the second previous context, ..., the Pth previous context<\c1>
[0216] The prompt information corresponding to the first context
[0217] <c2>The first first context, the second first context, ..., the Qth first context<\c2>
[0218] Prompt information corresponding to the first sub-code segment
[0219] <d1>The first first subcode segment, the second first subcode segment, ..., the Sth first subcode segment <\d1>
[0220] The prompt information corresponding to the second sub-code segment
[0221] <d2>The first second subcode segment, the second second subcode segment, ..., the Wth second subcode segment <\d2>
[0222] It should be understood that the input data input into the first model may also be in other input forms, which are not limited here.
[0223] In the above method, the prompt information corresponding to the second code segment and the placeholder of the second code segment can more effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment and the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment.
[0224] For example, according to Figure 5 The first code segment, the first context, the first context, the first sub-code segment, and the second sub-code segment shown in the figure can determine that the prompt information corresponding to the first code segment is "Please explain the following Python code", the prompt information corresponding to the first context is "The context of the code to be explained", the prompt information corresponding to the first context is "The context of the code to be explained", the prompt information corresponding to the first sub-code segment is "The code segment that calls the code to be explained", and the prompt information corresponding to the second sub-code segment is "The code segment called by the code to be explained". It can also be determined that the first placeholder includes <c1>and <\c1>, the second placeholder includes <c2>and <\c2>, the third placeholder includes <d1>and <\d1>, the fourth placeholder includes <d2>and <\d2>, through the above, the input form of the input data of the first model can be determined as Figure 7 As shown, the first model can give the explanation information of the first code segment as follows: The extract_codes() method in this code segment is used to extract all codes (i.e. <code>The text contained in the tag) and returns them as a list of strings. The specific implementation is to traverse the input list and then look for the body of each element. <code>The tag is appended to a list. Finally, the strings in the list are concatenated using newlines and returned.
[0225] Based on the explanation information of the first code segment above, it can be seen that the explanation information not only explains how to implement the extract_codes() method, but also explains the business logic of the first code segment, which is helpful for developers to quickly understand the first code segment.
[0226] In implementation mode six, the processor inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as interpretation information of the first code segment.
[0227] In an embodiment of the present application, the encoding vector corresponding to the second code segment includes at least one of the following: when the second code segment includes P first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the P first contexts respectively; when the second code segment includes Q first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the Q first contexts respectively; when the second code segment includes S first sub-codes that have a calling relationship with the first code segment, the encoding vector corresponding to the second code segment is the first calling vector corresponding to the S first sub-code segments respectively; when the second code segment includes W second sub-codes that have a called relationship with the first code segment, the encoding vector corresponding to the second code segment is the first called vector corresponding to the W second sub-code segments respectively.
[0228] In a possible implementation manner, the P first context vectors may be obtained by respectively inputting the P first contexts into the second model, wherein the P first context vectors correspond one-to-one to the P first contexts.
[0229] For the mth first context among P first contexts, where m is an integer ranging from [1, P], the first context vector corresponding to the mth first context can be obtained by the following two possible implementations:
[0230] In implementation A, the processor directly inputs the mth first context into the second model to obtain the mth first context vector. The above implementation can provide a method for determining the first context vector conveniently and efficiently.
[0231] In implementation mode B, the processor segments the mth first context using a first preset length to obtain at least one first context segment, and then the processor inputs the at least one first context segment into the second model to obtain at least one first segment vector, wherein the at least one first segment vector can constitute the mth first context vector. In the above implementation mode, since the length of the text segment that can be received by the second model is limited, inputting the segmented first context into the second model can effectively ensure the correctness of the obtained first context vector.
[0232] In a possible implementation manner, the Q first context vectors may be obtained by respectively inputting the Q first contexts into the second model, wherein the Q first context vectors correspond one-to-one to the Q first contexts.
[0233] For the nth first context among the Q first contexts, where n is an integer ranging over [1, Q], the first context vector corresponding to the nth first context can be obtained by the following two possible implementations:
[0234] In implementation C, the processor directly inputs the nth first context into the second model to obtain the nth first context vector. The above implementation can provide a method for determining the first context vector conveniently and efficiently.
[0235] In implementation D, the processor segments the nth first context using a first preset length to obtain at least one first context segment, and then the processor inputs the at least one first context segment into the second model to obtain at least one second segment vector, wherein the at least one second segment vector can constitute the nth first context vector. In the above implementation, since the length of the text segment that can be received by the second model is limited, inputting the segmented first context into the second model can effectively ensure the correctness of the obtained first context vector.
[0236] It should be understood that the second model is used to encode the first context or the first context. Specifically, the second model can be used to encode each first context to obtain a corresponding first context vector, or to encode each first context to obtain a corresponding first context vector. The second model can be a common natural language processing (NLP) model, such as word2vec, etc., which is not limited here.
[0237] In a possible implementation manner, the S first call vectors may be obtained by respectively inputting the S first sub-code segments into the third model, wherein the S first call vectors correspond one-to-one to the S first sub-code segments.
[0238] For the i-th first sub-code segment among the S first sub-code segments, where i is an integer ranging from [1, S], the first call vector corresponding to the i-th first sub-code segment can be obtained by the following two possible implementations:
[0239] In implementation mode E, the processor directly inputs the ith first sub-code segment into the third model to obtain the ith first call vector. The above implementation mode can provide a method for determining the first call vector conveniently and efficiently.
[0240] In implementation mode F, the processor segments the i-th first sub-code segment using a second preset length to obtain at least one first sub-code segment, and then the processor inputs the at least one first sub-code segment into a third model to obtain at least one third segment vector, wherein the at least one third segment vector can constitute the i-th first call vector. In the above implementation mode, since the length of the text segment that can be received by the third model is limited, inputting the segmented first sub-code segment into the third model can effectively ensure the correctness of the obtained first call vector.
[0241] It should be understood that the third model is used to encode the first sub-code segment. Specifically, the third model can be used to encode each first sub-code segment to obtain a corresponding first call vector. The third model can be a common NLP model, such as word2vec, etc., which is not limited here.
[0242] In a possible implementation manner, the W first called vectors may be obtained by respectively inputting the W second sub-code segments into the fourth model, wherein the W first called vectors correspond one-to-one to the W second sub-code segments.
[0243] For the j-th second sub-code segment among the W second sub-code segments, where j is an integer ranging from [1, W], the first called vector corresponding to the j-th second sub-code segment can be obtained by the following two possible implementations:
[0244] In implementation G, the processor directly inputs the j-th second sub-code segment into the fourth model to obtain the j-th first called vector. The above implementation can provide a method for determining the first called vector conveniently and efficiently.
[0245] In implementation mode H, the processor segments the j-th second sub-code segment using a third preset length to obtain at least one second sub-code segment, and then the processor inputs the at least one second sub-code segment into the fourth model to obtain at least one fourth segment vector, and the at least one fourth segment vector constitutes the j-th first called vector. In the above implementation mode, since the length of the text segment that can be received by the fourth model is limited, the input of the segmented second sub-code segment into the fourth model can effectively ensure the correctness of the obtained first called vector.
[0246] It should be understood that the fourth model is used to encode the second sub-code segment. Specifically, the fourth model can be used to encode each second sub-code segment to obtain the corresponding first called vector. The fourth model can be a common NLP model, such as word2vec, etc., which is not limited here.
[0247] In a possible implementation manner, when the second code segment includes P first contexts, Q first contexts, S first sub-code segments, and W second sub-code segments, the input data input to the first model may be in the following input form:
[0248] First code snippet
[0249] The first first context vector, the second first context vector, ..., the Pth first context vector
[0250] The first first context vector, the second first context vector, ..., the Qth first context vector
[0251] The first first call vector, the second first call vector, ..., the Sth first call vector
[0252] The first first called vector, the second first called vector, ..., the Wth first called vector
[0253] In the above method, since the coding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment and the coding vector corresponding to the second code segment requires a small memory space, inputting the coding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0254] In implementation mode seven, the processor first determines the prompt information corresponding to the first code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0255] In an embodiment of the present application, the prompt information corresponding to the first code segment can be used to prompt the first model to perform a code interpretation task.
[0256] In implementation mode eight, the processor first determines the placeholder of the second code segment, and then inputs the first code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment and the placeholder of the second code segment, and then inputs the prompt information corresponding to the first code segment, the first code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0257] In the embodiment of the present application, the placeholder of the second code segment is used to indicate the type of association relationship between the second code segment and the first code segment.
[0258] The first placeholder may be located on both sides of each first context vector, or may be located on both sides of P first context vectors. For ease of description, the following discussion assumes that the first placeholder is located on both sides of P first context vectors.
[0259] In the case where the first placeholder is located on both sides of the P first context vectors, the first placeholder and the P first context vectors may be in the following form:
[0260] <c1>The first first context vector, the second first context vector, ..., the Pth first context vector <\c1>
[0261] The second placeholder may be located on both sides of each first context vector, or may be located on both sides of the Q first context vectors. For ease of description, the following discussion assumes that the second placeholder is located on both sides of the Q first context vectors.
[0262] In the case where the second placeholder is located on both sides of the Q first context vectors, the second placeholder and the Q first context vectors may be formed in the following form:
[0263] <c2>The first first context vector, the second first context vector, ..., the Qth first context vector <\c2>
[0264] The third placeholder may be located on both sides of each first call vector, or may be located on both sides of the S first call vectors. For ease of description, the following discussion assumes that the third placeholder is located on both sides of the S first call vectors.
[0265] In the case where the third placeholder is located on both sides of the S first call vectors, the third placeholder and the S first call vectors may be formed in the following form:
[0266] <d1>The first first call vector, the second first call vector, ..., the Sth first call vector <\d1>
[0267] The fourth placeholder may be located at both sides of each first called vector, or may be located at both sides of the W first called vectors. For ease of description, the following discussion assumes that the fourth placeholder is located at both sides of the W first called vectors.
[0268] In the case where the fourth placeholder is located on both sides of the W first called vectors, the fourth placeholder and the W first called vectors may be constructed in the following form:
[0269] <d2>The first first called vector, the second first called vector, ..., the Wth first called vector <\d2>
[0270] In the above method, the placeholder of the second code segment can effectively distinguish the first code segment from the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment. Since the encoding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment, and the encoding vector corresponding to the second code segment requires a small memory space, inputting the encoding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0271] In implementation mode nine, the processor first determines the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment and the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the prompt information corresponding to the first code segment, the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0272] The positional relationship between the prompt information corresponding to the first context and the P first context vectors can refer to the positional relationship between the prompt information corresponding to the first context and the P first context vectors, which will not be elaborated here.
[0273] The positional relationship between the prompt information corresponding to the first context and the Q first context vectors can refer to the positional relationship between the prompt information corresponding to the first context and the Q first contexts, which will not be elaborated here.
[0274] The positional relationship between the prompt information corresponding to the first sub-code segment and the S first call vectors can refer to the positional relationship between the prompt information corresponding to the first sub-code segment and the S first sub-code segments, which will not be elaborated here.
[0275] The positional relationship between the prompt information corresponding to the second sub-code segment and the W first called vectors can refer to the positional relationship between the prompt information corresponding to the second sub-code segment and the W second sub-code segments, which will not be elaborated here.
[0276] In the above method, the prompt information corresponding to the second code segment can effectively distinguish the first code segment from the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment. Since the encoding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment, and the encoding vector corresponding to the second code segment requires a small memory space, inputting the encoding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0277] In implementation mode 10, the processor first determines the placeholder of the second code segment and the prompt information corresponding to the second code segment, and then inputs the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment. Alternatively, the processor first determines the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, and then inputs the prompt information corresponding to the first code segment, the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment.
[0278] In a possible implementation manner, if the processor inputs the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, wherein the second code segment includes P first contexts, Q first contexts, S first sub-code segments, and W second sub-code segments, the input data input to the first model may be in the following input form:
[0279] The prompt information corresponding to the first code segment
[0280] First code snippet
[0281] The first corresponding prompt information
[0282] <c1>The first first context vector, the second first context vector, ..., the Pth first context vector <\c1>
[0283] The prompt information corresponding to the first context
[0284] <c2>The first first context vector, the second first context vector, ..., the Qth first context vector <\c2>
[0285] Prompt information corresponding to the first sub-code segment
[0286] <d1>The first first call vector, the second first call vector, ..., the Sth first call vector <\d1>
[0287] The prompt information corresponding to the second sub-code segment
[0288] <d2>The first first called vector, the second first called vector, ..., the Wth first called vector <\d2>
[0289] It should be understood that the input data input into the first model may also be in other input forms, which are not limited here.
[0290] In the above method, the prompt information corresponding to the second code segment and the placeholder of the second code segment can more effectively distinguish the first code segment and the second code segment, avoid confusion between the first code segment and the second code segment, and help improve the accuracy of the interpretation information of the first code segment. Secondly, the prompt information corresponding to the second code segment and the placeholder of the second code segment can also be used to indicate the type of association between the first code segment and the second code segment. The first model can output more accurate interpretation information of the first code segment based on the association between the first code segment and the second code segment. Since the encoding vector corresponding to the second code segment can effectively eliminate redundant information in the second code segment, and the encoding vector corresponding to the second code segment requires a small memory space, inputting the encoding vector corresponding to the second code segment into the first model can effectively improve the output efficiency and accuracy of the first model.
[0291] For example, according to Figure 5 The first code segment, the first context, the first context, the first sub-code segment, and the second sub-code segment shown in the figure can determine that the prompt information corresponding to the first code segment is "Please explain the following Python code", the prompt information corresponding to the first context is "The context of the code to be explained", the prompt information corresponding to the first context is "The context of the code to be explained", the prompt information corresponding to the first sub-code segment is "The code segment that calls the code to be explained", and the prompt information corresponding to the second sub-code segment is "The code segment called by the code to be explained". It can also be determined that the first placeholder includes <c1>and <\c1>, the second placeholder includes <c2>and <\c2>, the third placeholder includes <d1>and <\d1>, the fourth placeholder includes <d2>and <\d2>, through the above, the input form of the input data of the first model can be determined as Figure 8 As shown, the first model can give the explanation information of the first code segment as follows: The extract_codes() method in this code segment is used to extract all codes (i.e. <code>The text contained in the tag) and returns them as a list of strings. The specific implementation is to traverse the input list and then look for the body of each element. <code>The tag is appended to a list. Finally, the strings in the list are concatenated using newlines and returned.
[0292] Based on the explanation information of the first code segment above, it can be seen that the explanation information not only explains how to implement the extract_codes() method, but also explains the business logic of the first code segment, which is helpful for developers to quickly understand the first code segment.
[0293] In a possible implementation, the above-mentioned code interpretation method can be integrated into a separate application (APP), and can be applied to an integrated development environment or a cloud code repository.
[0294] In the case where the above-mentioned code interpretation method is applied to an integrated development environment, the above-mentioned code interpretation method can be integrated into an IDE plug-in. This application can design IDE plug-ins that can be applied to different IDEs for different IDEs, and the designed IDE plug-ins can all integrate the code interpretation method of this application. If the code to be interpreted is written in java language, the IDE can be IntelliJ IDEA, and an IDE plug-in including the code interpretation method can be designed for IntelliJ IDEA. If the code to be interpreted is written in C / C++ language, the IDE can be VSCode, and an IDE plug-in including the code interpretation method can be designed for VSCode. If the code to be interpreted is written in python language, the IDE can be CodeArts, and an IDE plug-in including the code interpretation method can be designed for CodeArts.
[0295] Taking CodeArts as an example, developers can select the first code segment in the code editing interface of CodeArts, right-click to display the shortcut menu, and select the "Explain Code" option in the shortcut menu to display the explanation information of the first code segment. The display form of the first code segment includes the following two forms: as shown in Figure 9(a), the explanation information of the first code segment is displayed on the right side of the first code segment; as shown in Figure 9(b), the explanation information of the first code segment can also be displayed on a non-editing page.
[0296] When the code interpretation method is applied to a cloud code repository, the code interpretation method can be integrated into a cloud server having a cloud code repository. The cloud code repository can be CodeHub, GitHub, etc.
[0297] Taking CodeHub as an example, developers can select the first code segment in the code display interface of CodeHub, right-click to display the shortcut menu, and select "Explain Code" in the shortcut menu to display the explanation information of the first code segment. The display format of the explanation information of the first code segment can refer to the display of the explanation information of the first code segment in the IDE, which will not be described here.
[0298] Based on the above embodiments, the present application also provides a code interpretation device, which is applied to Figure 1 The processor of the computer device shown is used to implement Figure 2 The embodiment shown provides a code interpretation method. Fig.10 As shown, the device includes: a communication module 1001 and a processing module 1002. Among them:
[0299] The communication module 1001 is used to obtain a first code segment.
[0300] The processing module 1002 is used to determine a second code segment that is associated with the first code segment, where the second code segment includes at least one of the following: P first contexts that are in a context relationship with the first code segment, Q first contexts that are in a context relationship with the first code segment, S first sub-code segments that are in a calling relationship with the first code segment, or W second sub-code segments that are in a called relationship with the first code segment; P, Q, S, and W are all positive integers.
[0301] The processing module 1002 is also used to determine the interpretation information of the first code segment based on the first code segment, the second code segment and the first model, wherein the interpretation information of the first code segment is used to interpret the meaning expression of the first code segment, and the first model is obtained based on the connection training between multiple groups of first historical code segments and second historical code segments that have an associated relationship, and the interpretation information of the first historical code segment.
[0302] In one possible implementation, when the processing module 1002 determines the interpretation information of the first code segment based on the first code segment, the second code segment and the first model, it is specifically used to: input the first code segment and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment, or, input the encoding vectors corresponding to the first code segment and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment.
[0303] In one possible implementation, when the processing module 1002 inputs the first code segment and the second code segment into the first model and uses the output of the first model as the interpretation information of the first code segment, it is specifically used to: determine the prompt information corresponding to the first code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task; input the prompt information corresponding to the first code segment, the first code segment, and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment.
[0304] In a possible implementation, when the processing module 1002 inputs the first code segment and the second code segment into the first model and uses the output of the first model as the interpretation information of the first code segment, it is specifically used to: determine a placeholder for the second code segment, wherein the placeholder for the second code segment is used to indicate the type of association between the second code segment and the first code segment; input the first code segment, the placeholder for the second code segment, and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment.
[0305] In a possible implementation, when the processing module 1002 inputs the first code segment and the second code segment into the first model and uses the output of the first model as the interpretation information of the first code segment, it is specifically used to: determine the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the second code segment is used to indicate the type of association between the second code segment and the first code segment; input the prompt information corresponding to the first code segment and the second code segment and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment.
[0306] In one possible implementation, the processing module 1002 inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, and is specifically used to: determine the placeholder of the second code segment and the prompt information corresponding to the second code segment, wherein the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of association between the second code segment and the first code segment; input the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and determine to use the output of the first model as the interpretation information of the first code segment.
[0307] In one possible implementation, the processing module 1002 inputs the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, which is specifically used to: determine the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of the association relationship between the second code segment and the first code segment; input the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment.
[0308] In one possible implementation, the processing module 1002 inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, specifically for: determining the prompt information corresponding to the first code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task; inputting the prompt information corresponding to the first code segment, the first code segment, and the encoding vectors corresponding to the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment.
[0309] In a possible implementation, the processing module 1002 inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, specifically for: determining a placeholder for the second code segment, wherein the placeholder for the second code segment is used to indicate the type of association between the second code segment and the first code segment; inputting the placeholder for the first code segment, the second code segment, and the encoding vectors corresponding to the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment.
[0310] In one possible implementation, the processing module 1002 inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, specifically for: determining the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the second code segment is used to indicate the type of association between the second code segment and the first code segment; inputting the prompt information corresponding to the first code segment and the second code segment, and the encoding vector corresponding to the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment.
[0311] In a possible implementation, the processing module 1002 inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, specifically for: determining the placeholder of the second code segment and the prompt information corresponding to the second code segment, wherein the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of association between the second code segment and the first code segment; inputting the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment.
[0312] In a possible implementation, the processing module 1002 inputs the encoding vectors corresponding to the first code segment and the second code segment into the first model, and uses the output of the first model as the interpretation information of the first code segment, specifically for: determining the prompt information corresponding to the first code segment, the placeholder of the second code segment, and the prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder of the second code segment and the prompt information corresponding to the second code segment are both used to indicate the type of the association relationship between the second code segment and the first code segment; inputting the prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment.
[0313] In a possible implementation, the type of association relationship includes at least one of the following:
[0314] The above relationship is used to indicate that the second code segment is a segment of code before the first code segment;
[0315] The following relationship is used to indicate that the second code segment is a segment of code following the first code segment;
[0316] A calling relationship, used to indicate that different sub-code segments in the second code segment are used to call the first code segment;
[0317] The called relationship is used to indicate that different sub-code segments in the second code segment are used to be called by the first code segment.
[0318] In a possible implementation, the encoding vector corresponding to the second code segment includes at least one of the following:
[0319] When the second code segment includes P first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the P first contexts respectively;
[0320] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the Q first contexts respectively;
[0321] When the second code segment includes S first sub-codes that have a calling relationship with the first code segment, the encoding vector corresponding to the second code segment is the first calling vectors corresponding to the S first sub-code segments respectively;
[0322] When the second code segment includes W second sub-codes that are in a called relationship with the first code segment, the encoding vector corresponding to the second code segment is the first called vectors corresponding to the W second sub-code segments respectively.
[0323] In a possible implementation, the P first context vectors are obtained by inputting the P first contexts into the second model respectively, and the P first context vectors correspond to the P first contexts one by one; or
[0324] The Q first context vectors are obtained by inputting the Q first contexts into the second model respectively, and the Q first context vectors correspond to the Q first contexts one by one;
[0325] The second model is used to encode each first context to obtain a corresponding first context vector, or to encode each first context to obtain a corresponding first context vector.
[0326] In a possible implementation, the processing module 1002 may obtain P first context vectors through the following steps:
[0327] For the mth first context among the P first contexts, where m is an integer ranging from [1, P], perform the following steps:
[0328] The mth first context is segmented using a first preset length to obtain at least one first context segment; the at least one first context segment is respectively input into the second model to obtain at least one first segment vector; and the at least one first segment vector constitutes the mth first context vector.
[0329] In a possible implementation, the processing module 1002 may obtain Q first context vectors through the following steps:
[0330] For the nth first context among the Q first contexts, where n is an integer ranging over [1, Q], perform the following steps:
[0331] The nth first context is segmented using a first preset length to obtain at least one first context segment; the at least one first context segment is respectively input into a second model to obtain at least one second segment vector; and the at least one second segment vector constitutes the nth first context vector.
[0332] In one possible implementation, the S first call vectors are obtained by respectively inputting the S first sub-code segments into a third model, the S first call vectors correspond one-to-one to the S first sub-code segments, and the third model is used to encode each first sub-code segment to obtain a corresponding first call vector.
[0333] In a possible implementation, the processing module 1002 can obtain S first call vectors through the following steps: for the i-th first sub-code segment among the S first sub-code segments, i is an integer ranging from [1, S], perform the following steps: split the i-th first sub-code segment using a second preset length to obtain at least one first sub-code fragment; input the at least one first sub-code fragment into the third model respectively to obtain at least one third fragment vector, and the at least one third fragment vector constitutes the i-th first call vector.
[0334] In one possible implementation, W first called vectors are obtained by respectively inputting W second sub-code segments into a fourth model, the W first called vectors correspond one-to-one to the W second sub-code segments, and the fourth model is used to encode each second sub-code segment to obtain a corresponding first called vector.
[0335] In a possible implementation, the processing module 1002 can obtain W first called vectors through the following steps: for the j-th second sub-code segment among the W second sub-code segments, where j is an integer that runs through [1, W], perform the following steps: divide the j-th second sub-code segment using a third preset length to obtain at least one second sub-code fragment; input the at least one second sub-code fragment into the fourth model respectively to obtain at least one fourth fragment vector, and the at least one fourth fragment vector constitutes the j-th first called vector.
[0336] In a possible implementation, the placeholder of the second code segment includes at least one of the following:
[0337] When the second code segment includes P first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the first placeholder of the first context; or
[0338] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the second placeholder of the first context; or
[0339] When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the third placeholder of the first sub-code segment; or
[0340] When the second code segment includes W second sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the fourth placeholder of the second sub-code segment.
[0341] In a possible implementation, the prompt information corresponding to the second code segment includes at least one of the following:
[0342] When the second code segment includes P first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or
[0343] When the second code segment includes Q first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or
[0344] When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first sub-code segment; or
[0345] When the second code segment includes W second sub-code segments that are in a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes prompt information corresponding to the second sub-code segments.
[0346] In one possible implementation, the first model is obtained by training with a first training set, the first training set includes multiple groups of historical training data with explanation labels, the historical training data include multiple groups of first historical code segments, and multiple groups of second historical code segments that are associated with the multiple groups of first historical code segments, the explanation labels corresponding to the historical training data are used to represent the explanation information of the first historical code segments, and the content included in the second historical code segments corresponds to the content included in the second code segments.
[0347] In a possible implementation, the code interpretation method can be applied to an integrated development environment or a cloud code repository.
[0348] In the embodiments of the present application, the communication module and the processing module can be implemented by software or hardware. Exemplarily, the implementation of the processing module is described below by taking the processing module as an example. Similarly, the implementation of the communication module can refer to the implementation of the processing module.
[0349] As an example of a software functional unit, a processing module may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the above-mentioned computing instance may be one or more. For example, the processing module may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple data centers with similar geographical locations. Among them, usually a region may include multiple AZs.
[0350] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.
[0351] As an example of a hardware functional unit, the processing module may include at least one computing device, such as a server, etc. Alternatively, the processing module may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0352] The multiple computing devices included in the processing module can be distributed in the same region or in different regions. The multiple computing devices included in the processing module can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the processing module can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0353] It should be noted that, in other embodiments, the communication module can be used to execute the step of obtaining the first code segment, and the processing module can be used to execute the step of determining the second code segment that is associated with the first code segment, and determine any step in the interpretation information of the first code segment based on the first code segment, the second code segment and the first model. The steps that the communication module and the processing module are responsible for implementing can be specified as needed, and the full functions of the code interpretation device are realized by respectively implementing different steps in the code interpretation method through the communication module and the processing module.
[0354] Based on the above embodiments, the present application also provides a code interpretation device, which is used to implement the following Figure 2 The code interpretation method shown has the following Fig.10 The code shown explains the function of the device. Fig.11 As shown, the code interpretation device 1100 includes: a processor 1101 and a memory 1102.
[0355] The processor 1101 and the memory 1102 are connected to each other. Optionally, the processor 1101 and the memory 1102 can be connected to each other via a bus 1103; the bus 1103 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.11 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0356] Optionally, the code interpretation device 1100 further includes a communication module 1104 for communicating and interacting with other devices. Optionally, the communication module 1104 can communicate with other devices via wireless connection, for example, the communication module 1104 can be an RF circuit, a WiFi module, etc. The communication module 1104 can also communicate with other devices via physical connection, for example, the communication module 1104 can be a communication interface.
[0357] The processor 1101 is used to implement Figure 2 The specific process of the code interpretation method shown can refer to the specific description in the above embodiment, which will not be repeated here.
[0358] The memory 1102 is used to store programs and data. Specifically, the program may include program code, which includes instructions for computer operation. The memory 1102 may include random access memory (RAM), and may also include non-volatile memory (non-volatile memory), such as at least one disk storage. The processor 1101 executes the program stored in the memory 1102 to implement the above functions, thereby achieving the following: Figure 2 The code shown explains the method.
[0359] In summary, an embodiment of the present application provides a code interpretation device, which can interpret the business logic of a first code segment, thereby facilitating developers to quickly understand the first code segment.
[0360] The present application also provides a computing device 1200. Fig.12 As shown, the computing device 1200 includes: a bus 1201, a processor 1202, a memory 1204, and a communication interface 1203. The processor 1202, the memory 1204, and the communication interface 1203 communicate through the bus 1201. The computing device 1200 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 1200.
[0361] The bus 1201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.12 The bus 1201 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 1201 may include a path for transmitting information between various components of the computing device 1200 (for example, the memory 1204, the processor 1202, and the communication interface 1203).
[0362] The processor 1202 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0363] The memory 1204 may include a volatile memory, such as a random access memory (RAM). The processor 1202 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0364] The memory 1204 stores executable program codes, and the processor 1202 executes the executable program codes to respectively implement the functions of the aforementioned communication module and processing module, thereby implementing the code interpretation method. That is, the memory 1204 stores instructions for executing the code interpretation method.
[0365] The communication interface 1203 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 1200 and other devices or a communication network.
[0366] The embodiment of the present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.
[0367] like Fig.13 As shown, the computing device cluster includes at least one computing device 1200. The memory 1204 in one or more computing devices 1200 in the computing device cluster may store the same instructions for executing the code interpretation method.
[0368] In some possible implementations, the memory 1204 of one or more computing devices 1200 in the computing device cluster may also store partial instructions for executing the code interpretation method. In other words, the combination of one or more computing devices 1200 may jointly execute instructions for executing the code interpretation method.
[0369] It should be noted that the memory 1204 in different computing devices 1200 in the computing device cluster can store different instructions, which are respectively used to execute part of the functions of the code interpretation device. That is, the instructions stored in the memory 1204 in different computing devices 1200 can implement the functions of one or more modules in the communication module and the processing module.
[0370] In some possible implementations, one or more computing devices in the computing device cluster may be connected via a network, which may be a wide area network or a local area network. Fig.14 A possible implementation is shown. Fig.14 As shown, two computing devices 1200A and 1200B are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 1204 in the computing device 1200A stores instructions for executing the functions of the communication module. At the same time, the memory 1204 in the computing device 1200B stores instructions for executing the functions of the processing module.
[0371] It should be understood that Fig.14 The functions of the computing device 1200A shown in FIG. 1200A may also be completed by multiple computing devices 1200. Similarly, the functions of the computing device 1200B may also be completed by multiple computing devices 1200.
[0372] The present application embodiment also provides another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similar to that of Fig.13 and Fig.14 The connection mode of the computing device cluster is different in that the memory 1204 in one or more computing devices 1200 in the computing device cluster may store the same instructions for executing the code interpretation method.
[0373] In some possible implementations, the memory 1204 of one or more computing devices 1200 in the computing device cluster may also store partial instructions for executing the code interpretation method. In other words, the combination of one or more computing devices 1200 may jointly execute instructions for executing the code interpretation method.
[0374] The embodiment of the present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the code interpretation method.
[0375] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the code interpretation method.
[0376] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
[0377] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0378] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0379] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0380] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0381] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.< / code> < / code> < / code> < / code>
Claims
1. A code interpretation method, characterized in that: The method comprises: Get the first code segment; Determine a second code segment associated with the first code segment, the second code segment comprising at least one of the following: P first contexts that have a context relationship with the first code segment, Q first contexts that have a context relationship with the first code segment, S first sub-code segments that have a calling relationship with the first code segment, or W second sub-code segments that have a called relationship with the first code segment; P, Q, S, and W are all positive integers; According to the first code segment, the second code segment and the first model, interpretation information of the first code segment is determined, and the interpretation information of the first code segment is used to interpret the meaning expression of the first code segment; the first model is trained based on the connection between multiple groups of first historical code segments and second historical code segments that have an associated relationship and the interpretation information of the first historical code segment.
2. The method according to claim 1, characterized in that The determining, according to the first code segment, the second code segment, and the first model, interpretation information of the first code segment includes: Input the first code segment and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment, or The encoding vectors corresponding to the first code segment and the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
3. The method according to claim 2, characterized in that The step of inputting the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the first code segment, where the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task; The prompt information corresponding to the first code segment, the first code segment, and the second code segment are input into the first model, and the output of the first model is used as the explanation information of the first code segment.
4. The method according to claim 2, characterized in that The step of inputting the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine a placeholder for the second code segment, where the placeholder for the second code segment is used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, the placeholder of the second code segment, and the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
5. The method according to claim 2, characterized in that The step of inputting the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the second code segment, where the prompt information corresponding to the second code segment is used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, prompt information corresponding to the second code segment, and the second code segment are input into the first model, and the output of the first model is used as explanation information of the first code segment.
6. The method according to claim 2, characterized in that The step of inputting the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine a placeholder for the second code segment and prompt information corresponding to the second code segment, where the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, prompt information corresponding to the second code segment, a placeholder of the second code segment, and the second code segment are input into the first model, and the output of the first model is used as explanation information of the first code segment.
7. The method according to claim 2, characterized in that The step of inputting the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the first code segment, a placeholder for the second code segment, and prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
8. The method according to claim 2, characterized in that The step of inputting the encoding vectors corresponding to the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the first code segment, where the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task; The prompt information corresponding to the first code segment, the first code segment, and the encoding vector corresponding to the second code segment are input into the first model to obtain the interpretation information of the first code segment.
9. The method according to claim 2, characterized in that The step of inputting the encoding vectors corresponding to the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine a placeholder for the second code segment, where the placeholder for the second code segment is used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment are input into the first model to obtain interpretation information of the first code segment.
10. The method according to claim 2, characterized in that The step of inputting the encoding vectors corresponding to the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the second code segment, where the prompt information corresponding to the second code segment is used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, prompt information corresponding to the second code segment, and the encoding vector corresponding to the second code segment are input into the first model, and the output of the first model is used as interpretation information of the first code segment.
11. The method according to claim 2, characterized in that The step of inputting the encoding vectors corresponding to the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine a placeholder for the second code segment and prompt information corresponding to the second code segment, where the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The first code segment, prompt information corresponding to the second code segment, a placeholder of the second code segment, and an encoding vector corresponding to the second code segment are input into the first model to obtain interpretation information of the first code segment.
12. The method according to claim 2, characterized in that The step of inputting the encoding vectors corresponding to the first code segment and the second code segment into the first model, and using the output of the first model as the interpretation information of the first code segment includes: Determine prompt information corresponding to the first code segment, a placeholder for the second code segment, and prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
13. The method according to any one of claims 1 to 12, characterized in that: The type of the association relationship includes at least one of the following: The above relationship is used to indicate that the second code segment is a segment of code before the first code segment; The following relationship is used to indicate that the second code segment is a segment of code following the first code segment; A calling relationship, used to indicate that different sub-code segments in the second code segment are used to call the first code segment; The called relationship is used to indicate that different sub-code segments in the second code segment are used to be called by the first code segment.
14. The method according to claim 2, characterized in that The encoding vector corresponding to the second code segment includes at least one of the following: When the second code segment includes P first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the P first contexts respectively; When the second code segment includes Q first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vector corresponding to the Q first contexts respectively; When the second code segment includes S first sub-codes that have a calling relationship with the first code segment, the encoding vector corresponding to the second code segment is the first calling vectors respectively corresponding to the S first sub-code segments; When the second code segment includes W second sub-codes that are in a called relationship with the first code segment, the encoding vector corresponding to the second code segment is the first called vector corresponding to the W second sub-code segments respectively.
15. The method according to claim 14, characterized in that The P first context vectors are obtained by inputting the P first contexts into the second model respectively, and the P first context vectors correspond one-to-one to the P first contexts; or Q first context vectors are obtained by inputting the Q first contexts into the second model respectively, and the Q first context vectors correspond to the Q first contexts one by one; The second model is used to encode each first context to obtain the corresponding first context vector, or to encode each first context to obtain the corresponding first context vector.
16. The method according to any one of claims 14 to 15, characterized in that: The S first call vectors are obtained by respectively inputting the S first sub-code segments into the third model, the S first call vectors correspond one-to-one to the S first sub-code segments, and the third model is used to encode each of the first sub-code segments to obtain the corresponding first call vector.
17. The method according to any one of claims 14 to 16, characterized in that: The W first called vectors are obtained by respectively inputting the W second sub-code segments into the fourth model, the W first called vectors correspond one-to-one to the W second sub-code segments, and the fourth model is used to encode each of the second sub-code segments to obtain the corresponding first called vector.
18. The method of claim 4, 6, 7, 9, 11 or 12, wherein: The placeholder of the second code segment includes at least one of the following: When the second code segment includes P first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the first placeholder of the first context; or When the second code segment includes Q first contexts that have a context relationship with the first code segment, the placeholder of the second code segment includes the second placeholder of the first context; or When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes the third placeholder of the first sub-code segment; or When the second code segment includes W second sub-code segments that have a calling relationship with the first code segment, the placeholder of the second code segment includes a fourth placeholder of the second sub-code segment.
19. The method of claim 5, 6, 7, 10, 11 or 12, wherein: The prompt information corresponding to the second code segment includes at least one of the following: When the second code segment includes P first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or When the second code segment includes Q first contexts that have a context relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first context; or When the second code segment includes S first sub-code segments that have a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the first sub-code segment; or When the second code segment includes W second sub-code segments that are in a calling relationship with the first code segment, the prompt information corresponding to the second code segment includes the prompt information corresponding to the second sub-code segment.
20. The method according to any one of claims 1 to 19, characterized in that: The first model is obtained by training with a first training set, wherein the first training set includes multiple groups of historical training data with explanation labels, the historical training data include multiple groups of first historical code segments, and multiple groups of second historical code segments that are associated with the multiple groups of first historical code segments, the explanation labels corresponding to the historical training data are used to represent the explanation information of the first historical code segments, and the content included in the second historical code segments corresponds to the content included in the second code segments.
21. A code interpretation device, characterized in that: include: A communication module, used for acquiring a first code segment; a processing module, configured to determine a second code segment associated with the first code segment, wherein the second code segment includes at least one of the following: P first contexts associated with the first code segment, Q first contexts associated with the first code segment, S first sub-code segments in a calling relationship with the first code segment, or W second sub-code segments in a called relationship with the first code segment; wherein P, Q, S, and W are all positive integers; and, based on the first code segment, the second code segment, and the first model, determining interpretation information of the first code segment, wherein the interpretation information of the first code segment is used to interpret the meaning expression of the first code segment; The first model is obtained by training based on the connection between multiple groups of first historical code segments and second historical code segments that are associated with each other, and the explanation information of the first historical code segments.
22. The device according to claim 21, characterized in that The processing module is specifically used for: Input the first code segment and the second code segment into the first model, and use the output of the first model as the interpretation information of the first code segment, or The encoding vectors corresponding to the first code segment and the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
23. The device according to claim 22, characterized in that The processing module is specifically used for: Determine prompt information corresponding to the first code segment, a placeholder for the second code segment, and prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
24. The device according to claim 22, characterized in that The processing module is specifically used for: Determine prompt information corresponding to the first code segment, a placeholder for the second code segment, and prompt information corresponding to the second code segment, wherein the prompt information corresponding to the first code segment is used to prompt the first model to perform a code interpretation task, and the placeholder for the second code segment and the prompt information corresponding to the second code segment are both used to indicate a type of association relationship between the second code segment and the first code segment; The prompt information corresponding to the first code segment, the first code segment, the prompt information corresponding to the second code segment, the placeholder of the second code segment, and the encoding vector corresponding to the second code segment are input into the first model, and the output of the first model is used as the interpretation information of the first code segment.
25. The device according to any one of claims 21 to 24, characterized in that: The type of the association relationship includes at least one of the following: The above relationship is used to indicate that the second code segment is a segment of code before the first code segment; The following relationship is used to indicate that the second code segment is a segment of code following the first code segment; A calling relationship, used to indicate that different sub-code segments in the second code segment are used to call the first code segment; The called relationship is used to indicate that different sub-code segments in the second code segment are used to be called by the first code segment.
26. The device according to claim 22 or 24, characterized in that The encoding vector corresponding to the second code segment includes at least one of the following: When the second code segment includes P first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vectors corresponding to the P first contexts respectively; When the second code segment includes Q first contexts that have a context relationship with the first code segment, the encoding vector corresponding to the second code segment is the first context vector corresponding to the Q first contexts respectively; When the second code segment includes S first sub-codes that have a calling relationship with the first code segment, the encoding vector corresponding to the second code segment is the first calling vectors respectively corresponding to the S first sub-code segments; When the second code segment includes W second sub-codes that are in a called relationship with the first code segment, the encoding vector corresponding to the second code segment is the first called vector corresponding to the W second sub-code segments respectively.
27. A code interpretation device, characterized in that: Including memory and processor: The memory is used to store computer programs; The processor is used to call and execute the computer program to implement the method according to any one of claims 1 to 20.
28. A computing device cluster, characterized in that: comprising at least one computing device, each computing device comprising a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1 to 20.
29. A computer program product comprising instructions, characterized in that When the instructions are executed by a computing device cluster, the computing device cluster executes the method according to any one of claims 1 to 20.
30. A computer-readable storage medium, characterized in that: The method comprises computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster performs the method according to any one of claims 1 to 20.