Model training method and device, interface document generation method and device, equipment and medium

Through multiple rounds of pre-trained models for interface code and documents, an interface document generation model is generated, which solves the problems of interface code complexity and high maintenance costs, and realizes efficient and readable automatic generation of interface documents.

CN119047430APending Publication Date: 2024-11-29CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411100876.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

When generating interface documents, the dependency packages and annotations will change the interface code structure, increasing code complexity and development and maintenance costs.

Method used

The pre-trained model is used to train interface code and documents for multiple rounds, generate interface document generation models, and automatically generate interface documents to reduce the dependency packages and annotation requirements on the code.

Benefits of technology

It reduces the structural complexity and development and maintenance costs of interface code, and improves the readability and generation efficiency of interface documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119047430A_ABST
    Figure CN119047430A_ABST
Patent Text Reader

Abstract

The invention provides a model training method and device, an interface document generation method and device, equipment and a medium. Relates to the technical field of data processing. According to the technical scheme, for each operation environment, multiple pieces of sample data in the operation environment are obtained, multiple rounds of model training are carried out based on the multiple pieces of sample data in the operation environment, and the interface document generation model corresponding to the operation environment is obtained. In an actual application process, an interface document generation model corresponding to a target operation environment and a code of a to-be-processed interface in the target operation environment are obtained. And inputting the code of the to-be-processed interface into the interface document generation model obtained through training, and obtaining an interface document output by the interface document generation model. And finally, associating the interface document with the code of the processing interface. According to the method, the structure complexity, development cost and maintenance cost of interface codes are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a model training method, an interface document generation method, a device, a equipment and a medium. Background Art

[0002] An interface document is a document that describes the application programming interface, detailing how to interact with a software component, system, or library.

[0003] The prior art uses an interface design tool for generating interface documents to read annotations in interface codes to automatically generate interface documents online. The specific steps are: first, add corresponding dependency packages to the interface code; second, configure the interface design tool; third, add annotations for marking and describing the interface to the controller or controller method; finally, automatically generate the corresponding interface document online.

[0004] However, dependency packages and annotations will change the structure and content of the interface code, so that the code contains additional information that is not related to the business logic. Developers also need to learn and maintain these additional dependency packages and annotations. This will not only increase the complexity of the interface code structure, but also increase the development and maintenance costs of the interface code. Summary of the invention

[0005] The present application provides a model training method, an interface document generation method, an apparatus, a device and a medium to solve the problems of the complexity of the interface code structure and the high development and maintenance costs of the interface code in the prior art.

[0006] In a first aspect, the present application provides a model training method, comprising: for each operating environment, obtaining a plurality of sample data in the operating environment, each sample data comprising a sample interface code and an interface document;

[0007] Processing the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data;

[0008] Based on the processed sample data, the pre-trained model is subjected to multiple rounds of model training until a training cutoff condition is met, and an interface document generation model corresponding to the operating environment is obtained; wherein a preset script is deployed in the pre-trained model, and the preset script is used to calculate the loss value of the pre-trained model in each round of training, and the training cutoff condition is related to the loss value; the interface document generation model is used to generate an interface document of the interface to be processed according to the code of the interface to be processed in the operating environment; the target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a base matrix, and the low-rank matrix is ​​updated with each round of model training.

[0009] In a possible design, performing multiple rounds of model training on the pre-trained model based on the processed sample data until a training cutoff condition is met, and obtaining an interface document generation model corresponding to the operating environment, includes:

[0010] Performing multiple rounds of model training on the pre-trained model based on the processed sample data, and calculating the loss value of each round of training through the preset script;

[0011] If the loss value of this round of training is less than the preset loss value, continue to perform multiple rounds of training on the pre-trained model;

[0012] If the loss values ​​of the multiple rounds of training are all less than the preset loss value, and the loss difference between the loss values ​​of any two adjacent rounds of training is less than the preset loss difference, it is determined that the training cutoff condition is met, and the interface document generation model corresponding to the operating environment is obtained.

[0013] In a possible design, for each operating environment, obtaining a plurality of sample data in the operating environment includes:

[0014] For each operating environment, a plurality of sample data in the operating environment is obtained from a preset directory, and the plurality of sample data stored in the preset directory is pre-uploaded by a plurality of developers through a terminal device.

[0015] In a possible design, the processing of the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data includes:

[0016] According to the input data format, the codes of multiple sample interfaces are concatenated to generate an initial code string;

[0017] Annotating the initial code string to associate the code in the initial code string with the corresponding interface document to generate a target code string;

[0018] The format of each interface document is converted into a preset format to generate an interface document in the preset format; wherein, for the pre-trained model, the interface document in the preset format is more readable than the interface document; the target code string and all interface documents in the preset format are determined as processed sample data.

[0019] In a second aspect, the present application provides a method for generating an interface document, comprising:

[0020] Obtain an interface document generation model corresponding to a target operating environment; obtain the code of an interface to be processed in the target operating environment;

[0021] Inputting the code of the interface to be processed into the interface document generation model, obtaining the interface document output by the interface document generation model, wherein the interface document generation model is trained by the model training method described in the first aspect and various possible designs of the first aspect;

[0022] The interface document is associated with the code of the interface to be processed.

[0023] In a possible design, inputting the code of the interface to be processed into the interface document generation model includes:

[0024] Processing the code of the interface to be processed according to the input data format of the interface document generation model to generate a processed code;

[0025] The processed code is input into the interface document generation model to obtain the interface document output by the interface document generation model.

[0026] In a possible design, inputting the code of the interface to be processed into the interface document generation model and obtaining the interface document output by the interface document generation model includes:

[0027] Inputting the code of the interface to be processed into the interface document generation model, and obtaining the initial interface document output by the interface document generation model;

[0028] The initial interface document is format-converted to obtain an interface document in a converted format; wherein, for developers, the interface document in the converted format is more readable than the initial interface document.

[0029] In a third aspect, the present application provides a model training device, comprising:

[0030] An acquisition module, used for acquiring, for each operating environment, a plurality of sample data in the operating environment, each sample data including a sample interface code and an interface document;

[0031] A processing module, used to process the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data;

[0032] A training module is used to perform multiple rounds of model training on the pre-trained model based on the processed sample data until the training cutoff condition is met, and obtain the interface document generation model corresponding to the operating environment; the target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a base matrix, and the low-rank matrix is ​​updated with each round of model training.

[0033] In a possible design, the acquisition module is used to:

[0034] For each operating environment, a plurality of sample data in the operating environment is obtained from a preset directory, and the plurality of sample data stored in the preset directory is pre-uploaded by a plurality of developers through a terminal device.

[0035] In one possible design, the processing module is used to:

[0036] According to the input data format, the codes of multiple sample interfaces are concatenated to generate an initial code string;

[0037] Annotating the initial code string to associate the code in the initial code string with the corresponding interface document to generate a target code string;

[0038] The format of each interface document is converted into a preset format to generate an interface document in the preset format; wherein, for the pre-trained model, the interface document in the preset format is more readable than the interface document; the target code string and all interface documents in the preset format are determined as processed sample data.

[0039] In a possible design, before performing multiple rounds of model training on the pre-trained model based on the processed sample data, the training module is further used to:

[0040] The target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a basis matrix, and the low-rank matrix is ​​updated with each round of model training.

[0041] In one possible design, the training model is used to:

[0042] Performing multiple rounds of model training on the pre-trained model based on the processed sample data, and calculating the loss value of each round of training through the preset script;

[0043] If the loss value of this round of training is less than the preset loss value, continue to perform multiple rounds of training on the pre-trained model;

[0044] If the loss values ​​of the multiple rounds of training are all less than the preset loss value, and the loss difference between the loss values ​​of any two adjacent rounds of training is less than the preset loss difference, it is determined that the training cutoff condition is met, and the interface document generation model corresponding to the operating environment is obtained.

[0045] In a fourth aspect, the present application provides an interface document generating device, comprising:

[0046] An acquisition module is used to acquire an interface document generation model corresponding to a target operating environment;

[0047] The acquisition module is further used to acquire the code of the interface to be processed in the target operating environment;

[0048] An input module, used to input the code of the interface to be processed into the interface document generation model, and obtain the interface document output by the interface document generation model;

[0049] An association module is used to associate the interface document with the code of the interface to be processed.

[0050] In one possible design, the input module includes:

[0051] A first input subunit, used to process the code of the interface to be processed according to the input data format of the interface document generation model to generate a processed code;

[0052] The second input subunit is used to input the processed code into the interface document generation model to obtain the interface document output by the interface document generation model.

[0053] In one possible design, the input module includes:

[0054] A fifth input subunit, used for inputting the code of the interface to be processed into the interface document generation model, and obtaining the initial interface document output by the interface document generation model;

[0055] The fourth input subunit is used to convert the format of the initial interface document and obtain the interface document after the conversion.

[0056] In the fifth aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor and a memory; the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, so that the at least one processor executes the interface document generation method described in the first aspect, the second aspect and various possible designs above.

[0057] In the sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When the processor executes the computer execution instructions, the interface document generation method described in the first aspect, the second aspect and various possible designs is implemented.

[0058] In the seventh aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the interface document generation method described in the first aspect, the second aspect and various possible designs above.

[0059] The model training method, interface document generation method, device, equipment and medium provided by the present application, in the present technical scheme, for each operating environment, multiple sample data in the operating environment are obtained, and multiple rounds of model training are performed based on the multiple sample data in the operating environment to obtain the interface document generation model corresponding to the operating environment. Among them, the target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a base matrix, and the low-rank matrix is ​​updated with each round of model training. In the actual application process, the interface document generation model corresponding to the target operating environment and the code of the interface to be processed in the target operating environment are obtained. After that, the code of the interface to be processed is input into the interface document generation model obtained after training, and the interface document output by the interface document generation model is obtained. Finally, the interface document is associated with the code for processing the interface. Since the interface document generation model can automatically understand and generate the mapping relationship between the interface code and the interface document by learning a large amount of interface code and the corresponding interface document, this means that the interface document generation model can automatically generate the interface document, and the developer does not need to follow a specific format or annotation specification to write the interface code, nor does he need to learn additional operations or spend extra time to maintain the interface code. Therefore, the present technical scheme effectively reduces the structural complexity, development cost and maintenance cost of the interface code. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0061] Figure 1 An application scenario diagram of the interface document generation method provided in an embodiment of the present application;

[0062] Figure 2 A flowchart of a model training method provided in an embodiment of the present application;

[0063] Figure 3 A flowchart of a method for generating an interface document provided in an embodiment of the present application;

[0064] Figure 4 A schematic diagram of the structure of a model training device provided in an embodiment of the present application;

[0065] Figure 5 A schematic diagram of the structure of an interface document generation device provided in an embodiment of the present application;

[0066] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0067] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0068] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0069] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data involved shall comply with the provisions of relevant laws and regulations and shall not violate public order and good morals.

[0070] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0071] Terminology explanation:

[0072] Interface documentation: a document that describes the application interface functions, usage methods, and return results. It usually includes detailed information about the interface, such as interface name, interface access path, request method, request parameters, response format, etc. The purpose of the interface documentation is to help developers understand and use the interface for system integration and development.

[0073] Large model: also known as the basic model, refers to a machine learning model with a large number of parameters and complex structure. It can process massive data and complete various complex tasks, such as natural language processing, computer vision, speech recognition, etc.

[0074] ChatGLM: The full name is Chat General Language Model. It is an open source conversational language model that supports both Chinese and English. It is based on the generative language model (General Language Model, GLM) architecture and combines model quantization technology to optimize Chinese answers and conversations. After bilingual training in Chinese and English, supplemented by supervised fine-tuning, feedback self-help, and repeated human reinforcement learning, it has good conversation and question-answering capabilities under certain conditions.

[0075] PyTorch: is a flexible and efficient deep learning framework suitable for building and training various neural network models.

[0076] The interface design tool used in the prior art is a type of software tool specifically used to generate, manage and display interface documents. This type of tool can help developers generate and maintain interface documents, and can also provide interactive test interfaces, simulate interface requests and responses. In the process of using the interface design tool to generate interface documents, first, it is necessary to add corresponding dependency packages to the interface code, where these dependency packages refer to the external libraries, frameworks or modules that the interface code depends on to run normally in the interface design tool. Secondly, the interface design tool is configured, that is, various options and parameters of the interface design tool are set and adjusted to meet specific needs. The interface design tool usually provides a wealth of configuration options so that developers can customize its behavior and output to ensure that the generated interface document meets the requirements. After that, annotations are added to the controller or controller method to mark and describe the interface. Adding annotations can help automatically generate detailed interface documents, including the request method, path, parameters, response type, etc. of each endpoint. Finally, the corresponding interface document is automatically generated online, and the automatically generated interface document can be viewed by accessing the specified path in the browser.

[0077] However, when writing interface code, the use of dependency packages and annotations will have an impact on the interface and content of the code. Specifically, these dependency packages and annotations will cause the interface code to contain more elements that are not directly related to the business logic, but are introduced to achieve certain functions or features, resulting in a more complex structure of the interface code and a certain degree of invasiveness to the code. If relevant annotations are not added during the writing process, the interface design tool will not be able to automatically generate the corresponding interface document after the interface code is completed. In addition, developers need to spend extra time and energy to learn and understand the usage and principles of these dependency packages and annotations, resulting in increased development difficulty and cost. In the subsequent code maintenance process, developers also need to deal with these additional dependency packages and annotations to ensure their correctness and effectiveness, which increases the difficulty and cost of maintaining the interface code.

[0078] In response to the above technical problems, the inventors found in the process of studying the problem of automatically generating interface documents that if the existing tools are used to automatically generate interface documents corresponding to the interface code, not only is it necessary to add dependency packages to the interface code, but in order to ensure the accuracy and completeness of the interface document, a large number of annotations need to be added to the interface code, resulting in increased complexity of the code structure and increased development and maintenance costs. Based on this, the inventors thought that the big model has powerful language understanding and generation capabilities. The powerful language understanding ability can help the big model understand the interface code without adding annotations. The generation ability can help the big model generate detailed interface documents. The big model is trained with known interface codes and interface documents to obtain a model for generating interface documents. The interface code to be processed is input into the model for generating interface documents, and the required interface documents can be obtained. Based on this, this scheme proposes a method for automatically generating interface documents through a big model to further reduce the complexity of the interface code interface and the development and maintenance costs.

[0079] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0080] Figure 1 The application scenario diagram of the interface document generation method provided in the embodiment of the present application is as follows: Figure 1 As shown, the application scenario includes six main system modules, namely: data collection module, training module, reasoning module, preprocessing module, post-processing module, and interface calling module.

[0081] Next, the function of each system module is briefly described.

[0082] The data collection module is used to collect the code and interface documents of the sample interface, and use the collected code and interface documents of the sample interface as original training data.

[0083] The training module is used to train the pre-trained model according to the original training data to obtain the interface document generation model.

[0084] The reasoning module is used to input the code of the interface to be processed in the actual application into the interface document generation model for reasoning, so as to obtain the interface document corresponding to the interface to be processed.

[0085] The preprocessing module is used to preprocess the input data of the pretraining model or the interface document generation model so that the pretraining model or the interface document generation model can recognize the input data. For example, for the pretraining model, the input data can be the original training data mentioned above; for the interface document generation model, the input data can be the code of the interface to be processed in the actual application.

[0086] The post-processing module performs post-processing on the output data of the model, that is, performs corresponding format optimization to improve the readability of the output data. Exemplarily, the output data of the model can generate an interface document corresponding to the interface to be processed output by the model.

[0087] The interface calling module is used to provide an interface to the outside through the backend server for developers to call.

[0088] based on Figure 1 In the application scenario shown, an embodiment of the present application also provides a model training method. Figure 2 The following is a flow chart of the model training method provided in the embodiment of the present application. Figure 2 As shown, the model training method includes:

[0089] S201. For each operating environment, obtain a plurality of sample data in the operating environment.

[0090] The execution subject of the embodiment of the present application is an electronic device, which can be a terminal device, such as a laptop, a desktop computer, a tablet computer, etc., or a server. In practical applications, whether the electronic device is a terminal device or a server can be determined according to actual conditions, and no specific limitation is imposed on this.

[0091] In this step, you can Figure 1 The data collection module shown acquires sample data in the operating environment, each sample data includes a sample interface code and interface document.

[0092] The operating environment refers to the information technology environment of enterprises and organizations, which can be an internal network of an enterprise, a cloud service platform, an operating system platform, a database platform, a development platform, an enterprise application platform, an Internet of Things platform, etc. The operating environment may include one or more of the above platforms, and this application does not limit this. In addition, the interfaces involved in the operating environment include but are not limited to web interfaces, database interfaces, operating system interfaces, etc.

[0093] It is understandable that the developer uploads the acquired multiple sample data to a designated preset directory in advance through the terminal device, and when performing sample data training, the electronic device only needs to obtain the corresponding sample data from the preset directory.

[0094] Among them, the preset directory is a directory or folder used to store and manage sample interface code and interface documents. It can be presented as an organized directory structure, including interface code files, interface document files and configuration files; the collection directory can exist in multiple storage locations, including the version control system in the running environment, file storage system, development and deployment environment, document management system and pre-set storage path in the pre-trained model. Developers can choose the appropriate storage location and management method according to specific needs and development processes to facilitate file sharing, access and version control.

[0095] Optionally, the sample interface may be an interface deployed in the operating environment, and the code and interface document of the sample interface may be determined by analyzing relevant data of the operating environment in a historical period.

[0096] Furthermore, the sample interface can be determined from the interfaces deployed in the operating environment according to the sample interface determination strategy. Exemplarily, the sample interface determination strategy can be to determine the interface in the operating environment that has not reported an error within a preset time as the sample interface.

[0097] It should be understood that the interface determination strategy may also include other content, and its main purpose is to determine the interface with accurate code and interface documentation from the operating environment. The embodiment of the present application does not limit the specific content included in the interface determination strategy.

[0098] S202: Process multiple sample data according to the input data format of the pre-trained model to generate processed sample data.

[0099] In this step, the code of the sample interface is used as input data, and the interface document is used as the expected result corresponding to the code of the sample interface, that is, the output data. Figure 1 The preprocessing module shown processes the sample interface code and interface document respectively. Specifically, the code of the interface sample is processed by the preprocessing module, including:

[0100] Step a1: splice the codes of multiple sample interfaces according to the input data format to generate an initial code string;

[0101] Step a2: annotate the initial code string to associate the code in the initial code string with the corresponding interface document to generate a target code string.

[0102] In one possible implementation, the code of the sample interface in the sample data is spliced, and all code files related to the sample interface need to be collected. Assuming there are three code files, read the content of each code file, splice the read code content into a long text, and indicate the code file to which each code block belongs in front of it. Furthermore, according to the input requirements of the pre-trained model, the spliced ​​long text is preprocessed as necessary to obtain the target code string. Specifically, it can be to remove unnecessary blank lines or comments, or to change the length of the long text. For example, if the length of the spliced ​​long text exceeds the preset length specified by the pre-trained model, the long text needs to be truncated according to the preset length to ensure that the length of the truncated text is less than or equal to the preset length.

[0103] Specifically, the interface document is processed by the preprocessing module, including: converting the format of each interface document into a preset format, and generating an interface document in the preset format.

[0104] Among them, for pre-trained models, the interface document in the preset format is more readable than the interface document.

[0105] In one possible implementation, in order to better understand, design and use the interface, the core, common concepts and structures can be extracted from the interface document. That is, the interface document in the sample data is abstracted and refined, and uniformly converted into a lightweight data exchange format json structure. Among them, the document format of the interface document may be a text document, a table, a slide, etc. First, it is necessary to read the content in the interface document. For example, if the interface document is a text document, the python-docx library of python can be used to process the interface document. For other types of documents, the corresponding library can be used to read. Secondly, the read content is uniformly converted into a json structure and saved as a json document for model learning. For example, the json library of python can be used to generate data in json format, and the final data structure is {"context": code content splicing, "target": structured json after abstraction of the interface document}. The Python language is only used as a possible method to implement the processing of interface documents.

[0106] In the above possible implementation methods, the preset format is json.

[0107] S203: Perform multiple rounds of model training on the pre-trained model based on the processed sample data until the training cutoff condition is met, and obtain an interface document generation model corresponding to the operating environment.

[0108] In this step, you can Figure 1The training module shown performs multiple rounds of model training on the pre-trained model according to the code and interface documentation of the processed sample interface.

[0109] Optionally, you need to pull the required pre-trained model from the platform for software developers. First, find the platform warehouse corresponding to the required pre-trained model in the platform, then clone the platform warehouse, and finally download the pre-trained model file from the platform warehouse and load the pre-trained model.

[0110] Optionally, the pre-trained model can adopt a model of the ChatGLM series, such as the ChatGLM3-6B-Base model. The ChatGLM3-6B-Base model is the third-generation model of the ChatGLM series and can be used for various dialogue generation tasks. It can be further fine-tuned to adapt to specific application scenarios or task requirements.

[0111] Among them, the pre-trained model obtains a series of model parameters by learning patterns and features in a large amount of data. These model parameters usually exist in the form of matrices or tensors, namely the target weight matrix, which can be used to fine-tune the pre-trained model in subsequent tasks. Furthermore, in order to optimize and accelerate model training, the method of decomposing the target weight matrix into a low-rank matrix and a base matrix is ​​adopted. This method can effectively reduce the number of model parameters and computational complexity while maintaining the performance of the model; wherein, the low-rank matrix is ​​a matrix with a lower rank, and the rank refers to the maximum number of independent rows or columns in the matrix. The low-rank matrix usually has fewer parameters; the base matrix is ​​a basic matrix used to multiply the low-rank matrix to approximate the original target weight matrix. During the model training process, the parameters of the low-rank matrix will be updated with each round of model training. By updating the parameters of the low-rank matrix, the pre-trained model can gradually optimize its performance, while the base matrix is ​​not updated with each round of model training.

[0112] It can be understood that performing multiple rounds of model training on the pre-trained model based on the processed sample data is an iterative training process, that is, the training process will continue until the training cutoff condition is met, which specifically includes the following steps:

[0113] Step b1: perform multiple rounds of model training on the pre-trained model based on the processed sample data, and calculate the loss value of each round of training through a preset script;

[0114] Among them, a preset script is deployed in the pre-trained model, and the preset script is used to calculate the loss value of the pre-trained model in each round of training.

[0115] Optionally, the preset script may include code for calculating the loss value, which is called repeatedly in each round of training. The preset script may also include multiple repeated sections of code for calculating the loss value. Each round of model training is equivalent to executing a repeated section of code for calculating the loss value and outputting a loss value.

[0116] In addition, the number of nodes and graphics cards in the operating environment will affect the output rate of the loss value. The output rate of the loss value can be adjusted by setting the number of nodes and graphics cards in the operating environment.

[0117] For example, the pre-trained model uses the ChatGLM series model, based on pytorch and low-rank models, and executes the preset scripts that come with the pre-trained model. It can be understood that pytorch and low-rank models are equivalent to the environmental basis for executing scripts. The preset scripts in the pre-trained model need to be combined with the low-rank model to be executed normally, and the low-rank model needs to work normally in pytorch.

[0118] Step b2: If the loss value of this round of training is less than the preset loss value, continue to perform multiple rounds of training on the pre-trained model;

[0119] Step b3: If the loss values ​​of multiple rounds of training are all less than the preset loss value, and the loss difference between the loss values ​​of any two adjacent rounds of training is less than the preset loss difference, it is determined that the training cutoff condition is met;

[0120] For example, the preset loss value is set to 0.5, and the preset loss difference is set to 0.01. When the loss values ​​of multiple rounds of training are all less than 0.5 and the loss difference of any two adjacent rounds of training is less than 0.01, the tuning is stopped, and the model parameters at this time are used as the available model parameters. The training is completed and the corresponding interface document generation model is obtained.

[0121] Step b4: Obtain the interface document generation model corresponding to the operating environment.

[0122] This embodiment obtains multiple sample data including sample interface codes and interface documents in each operating environment, processes the multiple sample data according to the input data format of the pre-trained model, and generates processed sample data; based on the processed sample data, the pre-trained model is trained for multiple rounds until the training cutoff condition is met, and an interface document generation model corresponding to the operating environment is obtained. In this technical solution, the powerful language understanding and generation capabilities of the large model are utilized, and the sample interface code and interface document are used to train it so that it has the ability to understand the interface code and the ability to generate the corresponding interface document. Using the interface document generation model generated by this embodiment, it is only necessary to input the code of the interface to be processed of the operating environment into the corresponding interface document generation model, and the interface document generation model can use its own capabilities to generate the corresponding interface document, so that there is no need to add dependency packages and annotations to the interface code, which effectively reduces the complexity of the interface code structure and the development and maintenance costs of the interface code.

[0123] After obtaining the above-mentioned interface document generation model, the interface document generation model can be used to generate interface documents for the code of the interface to be processed. The following is a detailed description of the method for generating interface documents for the code of the interface to be processed using the interface document generation model in conjunction with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0124] In specific implementation, the execution subject of the interface document generation method can also be an electronic device with processing capabilities such as a terminal or a server. It should be understood that the electronic device that executes the interface document generation method and the electronic device that executes the above-mentioned execution model training method can be the same device or different devices.

[0125] Next, the specific implementation process of the interface document generation method is explained.

[0126] The present application also provides a method for generating an interface document. Figure 3 The following is a flow chart of the method for generating an interface document provided in the embodiment of the present application. Figure 3 As shown, the interface document generation method includes:

[0127] S301. Obtain an interface document generation model corresponding to a target operating environment.

[0128] In this step, since different operating environments correspond to different interface document generation models, when determining to generate the corresponding interface document based on the code of the interface to be processed, it is first necessary to determine the target operating environment of the interface to be processed, and then determine the interface document generation model corresponding to the target operating environment.

[0129] Optionally, the interface document generation models corresponding to different operating environments can be pre-stored in the local storage space of the electronic device, or in other data storage devices independent of the electronic device. The storage location of the interface document generation models corresponding to each operating environment is not specifically limited in the embodiments of the present application.

[0130] It should be understood that the relevant explanations and instructions of the operating environment and interface document generation model can be referred to Figure 2 The embodiments shown will not be described in detail here.

[0131] S302: Obtain the code of the interface to be processed in the target operating environment.

[0132] In this step, since the input data of the interface document generation model is the interface code, after determining the interface to be processed, it is also necessary to obtain the code of the interface to be processed.

[0133] S303: Input the code of the interface to be processed into the interface document generation model, and obtain the interface document output by the interface document generation model.

[0134] In this step, before the code of the interface to be processed is input into the interface document generation model, the code of the interface to be processed needs to be preprocessed so as to meet the input format of the interface document generation model.

[0135] Specifically, the steps of preprocessing the code of the interface to be processed include:

[0136] Step c1: according to the input data format of the interface document generation model, the code of the interface to be processed is processed to generate the processed code.

[0137] In step c1, assuming that the interface to be processed has three code files, the content of each code file is read, and the read code content is spliced ​​into a long text. Afterwards, the spliced ​​long text is preprocessed as necessary according to the input data format of the interface document generation model, and then the processed code is obtained. Exemplarily, the preprocessing can be to remove redundant blank lines, comments, and change the length of the long text.

[0138] Step c2: input the processed code into the interface document generation model to obtain the initial interface document output by the interface document generation model.

[0139] Step c3: convert the format of the initial interface document to obtain the interface document after the conversion.

[0140] It is understandable that the initial interface document output by the interface document generation model is formatted accordingly and converted into an interface document with higher readability. That is, for developers, the interface document after format conversion is more readable than the initial interface document.

[0141] Specifically, the interface document after conversion can be in word, PDF, excel, ppt and other document types.

[0142] S304: Associating the interface document with the code of the interface to be processed.

[0143] In addition, after associating the interface document with the code of the interface to be processed, the existing framework can be used to build a backend server to provide an interface for developers to call and to refer to the interface document for collaborative development.

[0144] The interface document generation method provided by the present application obtains multiple sample data including code of sample interfaces and interface documents in each operating environment, processes multiple sample data according to the input data format of the pre-trained model, and generates processed sample data; performs multiple rounds of model training on the pre-trained model based on the processed sample data until the training cutoff condition is met, and obtains the interface document generation model corresponding to the operating environment; inputs the code of the interface to be processed into the trained interface document generation model, obtains the interface document output by the interface document generation model; and associates the interface document with the code for processing the interface. Since the interface document generation model can automatically understand and generate the mapping relationship between the interface code and the interface document by learning a large amount of interface code and the corresponding interface document, the developer only needs to input the input data to be processed into the interface document generation model, and the interface document can be automatically generated by the model. Developers do not need to follow a specific format or annotation specification to write interface code, nor do they need to learn additional operations or spend extra time to maintain interface code. Therefore, the complexity of the interface code structure and the development and maintenance costs of the interface code can be reduced.

[0145] Figure 4 This is a schematic diagram of the structure of the model training device provided in the embodiment of the present application. Figure 4 As shown, the model training device includes: an acquisition module 401, a processing module 402, and a training module 403;

[0146] The acquisition module 401 is used to acquire, for each operating environment, a plurality of sample data in the operating environment, each sample data including a sample interface code and an interface document;

[0147] A processing module 402 is used to process the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data;

[0148] The training module 403 is used to perform multiple rounds of model training on the pre-trained model based on the processed sample data until the training cutoff condition is met, and obtain the interface document generation model corresponding to the operating environment; the target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a basis matrix, and the low-rank matrix is ​​updated with each round of model training.

[0149] In some embodiments, the acquisition module 401 is specifically used to:

[0150] For each operating environment, a plurality of sample data in the operating environment is obtained from a preset directory, and the plurality of sample data stored in the preset directory is pre-uploaded by a plurality of developers through a terminal device.

[0151] In some embodiments, the processing module 402 is specifically used to:

[0152] According to the input data format, the codes of multiple sample interfaces are concatenated to generate an initial code string;

[0153] Annotating the initial code string to associate the code in the initial code string with the corresponding interface document to generate a target code string;

[0154] The format of each interface document is converted into a preset format to generate an interface document in the preset format; wherein, for the pre-trained model, the interface document in the preset format is more readable than the interface document; the target code string and all interface documents in the preset format are determined as processed sample data.

[0155] In some embodiments, before performing multiple rounds of model training on the pre-trained model based on the processed sample data, the training module 403 is further used to:

[0156] The target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a basis matrix, and the low-rank matrix is ​​updated with each round of model training.

[0157] In some embodiments, the training model 403 is specifically used for:

[0158] Performing multiple rounds of model training on the pre-trained model based on the processed sample data, and calculating the loss value of each round of training through the preset script;

[0159] If the loss value of this round of training is less than the preset loss value, continue to perform multiple rounds of training on the pre-trained model;

[0160] If the loss values ​​of the multiple rounds of training are all less than the preset loss value, and the loss difference between the loss values ​​of any two adjacent rounds of training is less than the preset loss difference, it is determined that the training cutoff condition is met, and the interface document generation model corresponding to the operating environment is obtained.

[0161] It should be understood that the acquisition module 401 can be implemented as Figure 1 The data collection module shown, the processing module 402 can be implemented as Figure 1 The preprocessing module shown.

[0162] The model training device provided in the embodiments of the present application can be used to execute the model training method in any of the above embodiments. Its implementation principles and technical effects are similar and will not be repeated here.

[0163] Figure 5 This is a schematic diagram of the structure of the interface document generation device provided in the embodiment of the present application. Figure 5 As shown, the interface document generating device includes: an acquisition module 501, an input module 502, and an association module 503;

[0164] Wherein, the acquisition module 501 is used to acquire the interface document generation model corresponding to the target operating environment;

[0165] The acquisition module 501 is further used to acquire the code of the interface to be processed in the target operating environment;

[0166] An input module 502 is used to input the code of the interface to be processed into the interface document generation model to obtain the interface document output by the interface document generation model;

[0167] The association module 503 is used to associate the interface document with the code of the interface to be processed.

[0168] In some embodiments, the input module 502 includes:

[0169] A first input subunit, used to process the code of the interface to be processed according to the input data format of the interface document generation model to generate a processed code;

[0170] The second input subunit is used to input the processed code into the interface document generation model to obtain the interface document output by the interface document generation model.

[0171] In some embodiments, the input module 502 includes:

[0172] A fifth input subunit, used for inputting the code of the interface to be processed into the interface document generation model, and obtaining the initial interface document output by the interface document generation model;

[0173] The fourth input subunit is used to convert the format of the initial interface document and obtain the interface document after the conversion.

[0174] It should be understood that the input module 502 can be implemented as Figure 1 In the reasoning module shown in FIG. 1 , the first input subunit can be implemented as Figure 1 The preprocessing module shown in FIG. 1 , the fourth input subunit can be implemented as Figure 1 The post-processing module shown.

[0175] The interface document generation device provided in the embodiment of the present application can be used to execute the technical solution of the interface document generation method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0176] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, the input module 502 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above input module 502. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0177] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 As shown, the electronic device may include: a transceiver 61 , a processor 62 , and a memory 63 .

[0178] The processor 62 executes the computer execution instructions stored in the memory, so that the processor 62 executes the scheme in the above embodiment. The processor 62 can be a general-purpose processor, including a central processing unit CPU, a network processor (NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0179] The memory 63 is connected to the processor 62 via a system bus and completes communication between them. The memory 63 is used to store computer program instructions.

[0180] The transceiver 61 may be used to communicate with other devices.

[0181] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.

[0182] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.

[0183] The electronic device provided in the embodiment of the present application is used to execute the technical solution of the model training method or the interface document generation method in the above-mentioned embodiment.

[0184] An embodiment of the present application also provides a chip for running instructions, which is used to execute the technical solution of the model training method or the interface document generation method in the above embodiment.

[0185] An embodiment of the present application also provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes the technical solution of the model training method or the interface document generation method in the above-mentioned embodiment.

[0186] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the model training method or the interface document generation method in the above-mentioned embodiment.

[0187] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0188] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.

[0189] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0190] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0191] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

[0192] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0193] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0194] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0195] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.

[0196] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0197] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application 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 replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A model training method, characterized in that: include: For each operating environment, a plurality of sample data in the operating environment is obtained, each sample data including code and interface document of a sample interface; Processing the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data; Based on the processed sample data, the pre-trained model is subjected to multiple rounds of model training until a training cutoff condition is met, and an interface document generation model corresponding to the operating environment is obtained; wherein a preset script is deployed in the pre-trained model, and the preset script is used to calculate the loss value of the pre-trained model in each round of training, and the training cutoff condition is related to the loss value; the interface document generation model is used to generate an interface document of the interface to be processed according to the code of the interface to be processed in the operating environment; the target weight matrix of the pre-trained model is decomposed into a low-rank matrix and a base matrix, and the low-rank matrix is ​​updated with each round of model training.

2. The method according to claim 1, characterized in that The pre-training model is subjected to multiple rounds of model training based on the processed sample data until a training cutoff condition is met, and an interface document generation model corresponding to the operating environment is obtained, including: Performing multiple rounds of model training on the pre-trained model based on the processed sample data, and calculating the loss value of each round of training through the preset script; If the loss value of this round of training is less than the preset loss value, continue to perform multiple rounds of training on the pre-trained model; If the loss values ​​of the multiple rounds of training are all less than the preset loss value, and the loss difference between the loss values ​​of any two adjacent rounds of training is less than the preset loss difference, it is determined that the training cutoff condition is met, and the interface document generation model corresponding to the operating environment is obtained.

3. The method according to claim 1 or 2, characterized in that: The step of acquiring, for each operating environment, a plurality of sample data in the operating environment includes: For each operating environment, a plurality of sample data in the operating environment is obtained from a preset directory, and the plurality of sample data stored in the preset directory is pre-uploaded by a plurality of developers through a terminal device.

4. The method according to claim 1 or 2, characterized in that: The processing of the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data includes: According to the input data format, the codes of multiple sample interfaces are concatenated to generate an initial code string; Annotating the initial code string to associate the code in the initial code string with the corresponding interface document to generate a target code string; Converting the format of each interface document into a preset format to generate an interface document in the preset format; wherein, for the pre-trained model, the interface document in the preset format is more readable than the interface document; The target code string and all interface documents in a preset format are determined as processed sample data.

5. A method for generating an interface document, characterized in that: include: Obtain the interface document generation model corresponding to the target operating environment; Obtaining the code of the interface to be processed in the target operating environment; Inputting the code of the interface to be processed into the interface document generation model, and obtaining the interface document output by the interface document generation model, wherein the interface document generation model is trained by the model training method described in any one of claims 1 to 4 above; The interface document is associated with the code of the interface to be processed.

6. The method according to claim 5, characterized in that The step of inputting the code of the interface to be processed into the interface document generation model comprises: Processing the code of the interface to be processed according to the input data format of the interface document generation model to generate a processed code; The processed code is input into the interface document generation model to obtain the interface document output by the interface document generation model.

7. The method according to claim 5 or 6, characterized in that: The step of inputting the code of the interface to be processed into the interface document generation model and obtaining the interface document output by the interface document generation model comprises: Inputting the code of the interface to be processed into the interface document generation model, and obtaining the initial interface document output by the interface document generation model; The initial interface document is format-converted to obtain an interface document in a converted format; wherein, for developers, the interface document in the converted format is more readable than the initial interface document.

8. A model training device, characterized in that: include: An acquisition module, used for acquiring, for each operating environment, a plurality of sample data in the operating environment, each sample data including a sample interface code and an interface document; A processing module, used to process the plurality of sample data according to the input data format of the pre-trained model to generate processed sample data; A training module is used to perform multiple rounds of model training on the pre-trained model based on the processed sample data until a training cutoff condition is met, and obtain an interface document generation model corresponding to the operating environment; wherein a preset script is deployed in the pre-trained model, and the preset script is used to calculate the loss value of the pre-trained model in each round of training, and the training cutoff condition is related to the loss value. The interface document generation model is used to generate an interface document of the interface to be processed according to the code of the interface to be processed in the operating environment.

9. An interface document generating device, characterized in that: include: An acquisition module is used to acquire an interface document generation model corresponding to a target operating environment; The acquisition module is further used to acquire the code of the interface to be processed in the target operating environment; An input module, used to input the code of the interface to be processed into the interface document generation model, and obtain the interface document output by the interface document generation model, wherein the interface document generation model is trained by the model training method described in any one of claims 1 to 4 above; An association module is used to associate the interface document with the code of the interface to be processed.

10. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.

12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.