Question answering model training method, device, computer equipment and readable storage medium

By adjusting the auxiliary network in the Q&A model, the problem of low answer prediction accuracy in complex tasks and data set changes is solved, achieving higher answer prediction accuracy and resource savings.

CN119646165BActive Publication Date: 2025-04-29SHENZHEN SMARTMORE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510163452.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-14
Publication Date
2025-04-29
Estimated Expiration
2045-02-14

AI Technical Summary

Technical Problem

Existing Q&A models have problems with low answer prediction accuracy when performing Q&A tasks, especially when facing complex tasks or dataset changes.

Method used

By obtaining training questions and answers in the target field, the initial question-and-answer model (including pre-trained question-and-answer networks and auxiliary networks) is used to extract the problem features, generate predicted answers, and adjust the feature extraction unit and dimension control unit of the auxiliary network based on the model loss until the convergence conditions are met, and the target question-and-answer model of the target field is obtained.

Benefits of technology

The accuracy of the answer prediction of the question-and-answer model for target domain questions is improved, the resources for adjusting the parameters of the pre-trained question-and-answer network are saved, and adaptability to data of different scales is achieved through the trainable dimension control unit.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646165B_ABST
    Figure CN119646165B_ABST
Patent Text Reader

Abstract

The present application relates to a training method, device, computer equipment and readable storage medium for a question-answering model. The method includes: obtaining training questions corresponding to the target domain and training answers corresponding to the training questions; inputting the training questions into the initial question-answering model, the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; extracting the first question feature of the training question through the pre-trained question-answering network, and extracting the second question feature of the training question through the auxiliary network; determining the predicted answer to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit; generating a model loss based on the predicted answer and the training answer; adjusting the feature extraction unit based on the model loss; adjusting the dimension control unit based on the model loss and the reference threshold until the convergence condition is met, and obtaining the target question-answering model corresponding to the target domain. By adopting this method, it is possible to improve the accuracy of answer prediction of the question-answering model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a training method, apparatus, computer equipment and readable storage medium for a question-answering model. Background Art

[0002] In recent years, with the widespread application of pre-trained models for large models (such as GPT, BERT, etc.), the management and use efficiency of API documents within enterprises have become the key to improving development efficiency. However, API documents within enterprises usually have complex structures and unintuitive use, which leads to low efficiency when users search for API functions.

[0003] To solve this problem, API documents are usually used to generate question-answer pairs, and the generated question-answer pairs are used to fine-tune the question-answer model obtained by the large model to achieve efficient query.

[0004] Current large model fine-tuning techniques, such as by inserting an Adapter or modifying the Prompt, cannot adapt to data changes for some complex tasks or new data sets. As a result, the question-answering model has low answer prediction accuracy when performing question-answering tasks. Summary of the invention

[0005] Based on this, it is necessary to provide a question-answering model training method, apparatus, computer device, computer-readable storage medium and computer program product that can improve the answer prediction accuracy of the question-answering model in response to the above-mentioned technical problems.

[0006] In a first aspect, the present application provides a method for training a question-answering model, comprising:

[0007] Obtain training questions corresponding to the target domain and training answers corresponding to the training questions;

[0008] Inputting the training question into the initial question-answering model, the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; extracting a first question feature of the training question through the pre-trained question-answering network, and extracting a second question feature of the training question through the auxiliary network; determining a predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit;

[0009] Generate model loss based on the predicted answer and the training answer;

[0010] Based on the model loss, adjust the feature extraction unit; based on the model loss and the reference threshold, adjust the dimension control unit until the convergence conditions are met to obtain the target question-answering model corresponding to the target domain.

[0011] In a second aspect, the present application also provides a training device for a question-answering model, comprising:

[0012] An acquisition module is used to obtain training questions corresponding to the target domain and training answers corresponding to the training questions;

[0013] A processing module, configured to input a training question into an initial question-answering model, wherein the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; extract a first question feature of the training question through the pre-trained question-answering network, and extract a second question feature of the training question through the auxiliary network; determine a predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit;

[0014] The loss calculation module is used to generate the model loss based on the predicted answer and the training answer;

[0015] The model optimization module is used to adjust the feature extraction unit based on the model loss; adjust the dimension control unit based on the model loss and the reference threshold until the convergence conditions are met to obtain the target question-answering model corresponding to the target domain.

[0016] In a third aspect, the present application further provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.

[0017] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.

[0018] In a fifth aspect, the present application also provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.

[0019] The training method, apparatus, computer device, computer-readable storage medium and computer program product of the above-mentioned question-answering model input the training questions of the target domain into the initial question-answering model, the initial question-answering model includes a pre-trained question-answering network and an auxiliary network. After obtaining the predicted answer by the first question feature extracted by the trained question-answering network and the second question feature extracted by the auxiliary network, the model loss generated by the predicted answer and the training answer is used to adjust the parameters of the auxiliary network without adjusting the parameters of the pre-trained question-answering network, thereby achieving accurate training of the auxiliary network in the target domain, improving the accuracy of the target question-answering model in predicting the answers to the target domain questions, and saving resources for adjusting the parameters of the pre-trained question-answering network.

[0020] In addition, a trainable dimension control unit is provided in the auxiliary network, through which the dimension control unit can control the dimension of the feature extraction unit, so as to realize the adaptability of the feature extraction unit to data of different scales. For example, the dimension parameter amount of the feature extraction unit can be increased for large-scale data, and the dimension parameter amount of the feature extraction unit can be reduced for small-scale data, so as to improve the data processing accuracy of the feature extraction unit and save unnecessary computing resources. Furthermore, since the dimension control unit is a trainable network model, when adjusting the feature extraction unit according to the model loss, the dimension control unit is also adjusted according to the model loss and the reference threshold, so as to realize adaptive dynamic adjustment of the dimension control unit, thereby improving the data processing accuracy of the auxiliary network and further improving the answer prediction accuracy of the target question-answering model. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 An application environment diagram of a question-answering model training method provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of a method for training a question-answering model provided in an embodiment of the present application;

[0023] Figure 3 A flowchart of the training steps of a question-answering model provided in an embodiment of the present application;

[0024] Figure 4 A schematic diagram of a question-answering model training process including a question-answering model architecture provided in an embodiment of the present application;

[0025] Figure 5 A structural block diagram of a training device for a question-answering model provided in an embodiment of the present application;

[0026] Figure 6 An internal structure diagram of a computer device provided in an embodiment of the present application;

[0027] Figure 7 An internal structure diagram of another computer device provided in an embodiment of the present application;

[0028] Figure 8 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0030] The training method of the question-answering model provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The head-mounted device can be a virtual reality (VR) device, an augmented reality (AR) device, smart glasses, etc. The server 104 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.

[0031] like Figure 2 As shown, the embodiment of the present application provides a training method for a question-answering model, and the method is applied to Figure 1 The terminal 102 or the server 104 in the example is used for explanation. It is understandable that the computer device may include at least one of the terminal and the server. The method comprises the following steps:

[0032] Step 202: Obtain training questions corresponding to the target domain and training answers corresponding to the training questions.

[0033] The target domain refers to the specific business knowledge domain to which the training questions and training answers belong, such as the interface knowledge domain for implementing interface calls, the business logic knowledge domain for implementing business processing, etc. The training questions refer to business questions generated based on the existing business knowledge in the target domain. The training answers refer to the answers to questions in the existing business knowledge in the target domain that match the training questions. The training questions and training answers are used to retrain the existing question-answering model for the target domain, so that the retrained question-answering model can perform question-answering tasks in the target domain.

[0034] Exemplarily, the server receives a question-answering model training request for a target domain sent by a terminal, and obtains training questions and training answers corresponding to the target domain according to the question-answering model training request. The server may obtain the training questions and training answers corresponding to the target domain carried in the question-answering model training request, or the server may pre-deploy a world knowledge base of various knowledge domains, obtain the target business knowledge corresponding to the target domain from the world knowledge base according to the domain identifier of the target domain carried in the question-answering model training request, and generate training questions and training answers according to the target business knowledge.

[0035] Step 204: input the training question into the corresponding initial question-answering model, where the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; extract the first question feature of the training question through the pre-trained question-answering network, and extract the second question feature of the training question through the auxiliary network; determine the predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit.

[0036] Among them, the initial question-answering model refers to a large model that has been pre-trained with large-scale data, but still needs to be retrained with training questions and training answers in the target field, which is used to perform question-answering tasks. The pre-trained question-answering network refers to the weight matrix obtained by pre-training with large-scale data in the initial question-answering model. The auxiliary network refers to the weight matrix newly added to the initial question-answering model to be trained with training questions and training answers in the target field. The feature extraction unit refers to the weight matrix used to extract question features in the auxiliary network, including various weight parameters. The dimension control unit refers to the weight matrix in the auxiliary network that participates in the calculation and is also used to control the dimensional parameter amount of the feature extraction unit. The dimensional parameter amount refers to the number of weight parameters involved in the calculation in each dimension of the feature extraction network.

[0037] Exemplarily, the server calls the initial question-answering model, which includes a pre-trained question-answering network and an auxiliary network. In the process of training the initial question-answering model using training questions and training answers, the server freezes the weight parameters of the pre-trained question-answering network and trains the auxiliary network. The auxiliary network can be a weight matrix obtained by fusion of a feature extraction unit and a dimension control unit. The weight parameters in the feature extraction unit and the dimension control unit can be randomly generated in advance, and the weight parameters in the feature extraction unit and the dimension control unit will be adjusted in the subsequent process of training the auxiliary network using training questions and training answers.

[0038] Step 206, generating a model loss based on the predicted answer and the training answer.

[0039] Step 208, based on the model loss, adjust the feature extraction unit; based on the model loss and the reference threshold, adjust the dimension control unit until the convergence condition is met, and obtain the target question answering model corresponding to the target domain.

[0040] The reference threshold is data used to adjust each weight parameter in the dimension control unit, and can be represented as an adjustment range for each weight parameter in the dimension control unit.

[0041] Exemplarily, the server calculates the model loss of the initial question-answering model based on the difference between the predicted answer and the training answer, and obtains the reference threshold corresponding to the auxiliary network. According to the model loss, the current update value corresponding to each weight parameter in the feature extraction unit is calculated, and each weight parameter of the feature extraction unit is updated using the calculated current update value to obtain an updated feature extraction unit.

[0042] The server calculates the current update values ​​corresponding to each weight parameter in the dimension control unit according to the model loss, and determines each threshold range and the parameter update logic corresponding to each threshold range according to the reference threshold. According to the parameter update logic of the threshold range to which the current update value corresponding to each weight parameter in the dimension control unit belongs, the target update value corresponding to each weight parameter in the dimension control unit is calculated, and each weight parameter in the dimension control unit is updated using the calculated target update value to obtain an updated dimension control unit.

[0043] The server obtains an updated auxiliary network based on the updated feature extraction unit and the updated dimension control unit, and obtains an updated question-answering model based on the pre-trained question-answering network and the updated auxiliary network. The server then uses the updated question-answering model as the initial question-answering model and returns to the step of inputting the training question into the corresponding initial question-answering model until the convergence conditions are met, such as the model loss is less than the loss threshold, the number of iterations reaches the upper limit, etc., to obtain the target question-answering model corresponding to the target field.

[0044] In the training method of the above-mentioned question-answering model, the training questions in the target domain are input into the initial question-answering model, and the initial question-answering model includes a pre-trained question-answering network and an auxiliary network. After the predicted answers are obtained by extracting the first question features through the trained question-answering network and the second question features through the auxiliary network, the model loss generated by the predicted answers and the training answers is used to adjust the parameters of the auxiliary network without adjusting the parameters of the pre-trained question-answering network. This achieves accurate training of the auxiliary network in the target domain, improves the accuracy of the target question-answering model in predicting the answers to the target domain questions, and saves resources for adjusting the parameters of the pre-trained question-answering network.

[0045] In addition, a trainable dimension control unit is provided in the auxiliary network, through which the dimension control unit can control the dimension of the feature extraction unit, so as to realize the adaptability of the feature extraction unit to data of different scales. For example, the number of dimensions of the feature extraction unit can be increased for large-scale data, and the number of dimensions of the feature extraction unit can be reduced for small-scale data, so as to improve the data processing accuracy of the feature extraction unit and save unnecessary computing resources. Furthermore, since the dimension control unit is a trainable network model, when adjusting the feature extraction unit according to the model loss, the dimension control unit is also adjusted according to the model loss and the reference threshold, so as to realize adaptive dynamic adjustment of the dimension control unit, thereby improving the data processing accuracy of the auxiliary network and further improving the answer prediction accuracy of the target question-answering model.

[0046] In some embodiments, the target domain is a functional interface query domain; step 202, obtaining training questions corresponding to the target domain and training answers corresponding to the training questions, includes:

[0047] Structuring the function information of each functional interface in the acquired functional interface document to obtain a structured document;

[0048] Based on the function description of each functional interface in the structured document, generate training questions corresponding to the target domain and training answers corresponding to the training questions.

[0049] The functional interface document is a document used to describe the functions, usage and technical specifications of each functional interface. The functional interface document includes the function information of each functional interface, and the function information refers to the pre-defined function logic of the functional interface. The functional interface can be an API (Application Programming Interface) interface.

[0050] Exemplarily, after receiving the question-and-answer training request for the target domain sent by the terminal, the server determines that the target domain is the functional interface query domain according to the question-and-answer training request, and then obtains the functional interface document (API document) according to the functional interface query domain, that is, the target business knowledge corresponding to the functional interface query domain. Then, the function information of each functional interface in the functional interface document is structured, which can be input into a natural language model, and the function structure of the function information of each functional interface is segmented through the natural language model to obtain a structured document. The natural language model is, for example, a named entity recognition model. The functional interface document is input into the named entity recognition model, and the function information of each functional interface in the functional interface document is segmented into function structures such as function name, function description, function example, and parameter description through the named entity recognition model.

[0051] The server then generates training questions and corresponding training answers based on the function descriptions of each functional interface in the structured document, such as function descriptions, function examples, etc. The server can embed a prompt (prompt word) template in the natural language model to obtain the target natural language model. The target natural language model generates interface function requirement questions and corresponding recommended interface functions based on the function description. For example, the interface function requirement question is "What function can I call if I want to achieve channel conversion of an image?", and the recommended interface function is "You can use the CvtColor function." The server uses the interface function requirement question output by the target natural language model as a training question and the corresponding recommended interface function as a training answer.

[0052] In this embodiment, by performing structured processing on the API document and generating question-answer pairs as training data, the initial question-answer model is trained using the training data, so that the target question-answer model can perform question-answer tasks in the API document field, thereby improving the answer prediction accuracy of the target question-answer model.

[0053] In some embodiments, the dimension control unit includes diagonal elements; Figure 3 As shown, step 208, adjusting the dimension control unit based on the model loss and the reference threshold, includes:

[0054] Step 302: Based on the model loss and the iteration step, the dimension control unit is gradient updated to obtain an intermediate dimension control unit;

[0055] Step 304: adjust each diagonal element in the intermediate dimension control unit based on the reference threshold to obtain an updated dimension control unit.

[0056] The iteration step size represents the amplitude of parameter adjustment for the dimensional control unit. Gradient update refers to the process of calculating the gradient of the model loss with respect to the weight parameters of the dimensional control unit during the training of the dimensional control unit, and updating the weight parameters of the dimensional control unit according to the gradient. Diagonal elements refer to the weight parameters in the dimensional control unit.

[0057] Exemplarily, the dimension control unit may be a diagonal matrix, the weight parameters in the dimension control unit are diagonal elements, and the dimension control unit includes element values ​​corresponding to the diagonal elements. In the process of adjusting the weight parameters of the dimension control unit, the server calculates the gradient update value corresponding to the dimension control unit according to the model loss and the preset iteration step size, and then adjusts the weight parameters of each diagonal element of the dimension control unit according to the gradient update value to obtain an intermediate dimension control unit. The intermediate dimension control unit includes element values ​​corresponding to each diagonal element (which can be expressed as the current update value). The calculation process of the intermediate dimension control unit can be expressed as: .in, represents the dimension control unit, including various weight parameters of the dimension control unit of the t-th iteration; is the original loss function of the language model; Represents the complete trainable weight parameters; represents the step size of the tth iteration; That is, the gradient update value of the dimension control unit in the model update.

[0058] Then, a reference threshold is obtained, and each threshold range and the parameter update logic corresponding to each threshold range are determined according to the reference threshold. For the element value of any diagonal element in the intermediate dimension control unit, the reference threshold range to which the element value belongs is determined, and the element value is calculated according to the parameter update logic corresponding to the reference threshold range to obtain the updated element value of the diagonal element (which can be expressed as a target update value). According to the updated element values ​​corresponding to each diagonal element, an update control unit is obtained.

[0059] In some embodiments, the reference threshold includes a positive reference threshold and a negative reference threshold; step 304, adjusting each diagonal element in the intermediate dimension control unit based on the reference threshold to obtain an updated dimension control unit, including:

[0060] For any diagonal element in the intermediate dimension control unit, when the element value of the diagonal element is greater than the positive reference threshold, determining an updated element value of the diagonal element based on the difference between the element value and the positive reference threshold; or,

[0061] When the element value of the diagonal element is less than or equal to the positive reference threshold and greater than the negative reference threshold, a zero value is used as the updated element value of the diagonal element; or,

[0062] When the element value of the diagonal element is less than or equal to the negative reference threshold, an updated element value of the diagonal element is determined based on a difference between the element value and the negative reference threshold.

[0063] The positive reference threshold refers to the threshold data whose value is greater than 0. The negative reference threshold refers to the threshold data whose absolute value is the same as the positive reference threshold but whose value is less than 0.

[0064] The parameter update of the diagonal elements in the dimensional control unit is shown in formula (1).

[0065] (1)

[0066] in, is the reference threshold, represents the step size of the tth iteration, λ>0 is the regularization parameter; is a threshold function of the reference threshold, used to calculate the updated element value of each diagonal element x in the intermediate dimension control unit; represents the intermediate dimension control unit after the t-th gradient update; Represents an updated dimension control unit obtained after each diagonal element x in the intermediate dimension control unit is updated based on the threshold function.

[0067] In this embodiment, the element values ​​of the diagonal elements of the intermediate dimension control unit are updated according to the parameter threshold, including setting the diagonal elements to zero, to obtain an updated dimension control unit. The sparsity of the weight parameters in the updated dimension control unit can be reflected by the zeroed diagonal elements, thereby compressing the invalid dimensions of the feature extraction unit through the updated dimension control unit to improve the accuracy of the feature extraction unit.

[0068] In some embodiments, the initial question-answering model includes various decoding layers (Decoder), each decoding layer includes its own pre-trained question-answering network and auxiliary network. In the process of training the initial question-answering model using training questions and training answers, the weight parameters of the auxiliary networks of each decoding layer are adjusted. The reference thresholds corresponding to each decoding layer can be the same or different.

[0069] In some embodiments, the reference threshold can be used to reflect the sparsity of the feature extraction unit in the auxiliary network. Specifically, as shown in formula (1), there may be diagonal elements set to zero in the update dimension control unit after parameter adjustment. The dimension to which the diagonal elements set to zero in the update dimension control unit belong is used as the zero dimension. Then, the update feature extraction unit and the update dimension control unit are fused to obtain an updated auxiliary network. The fusion can be performed by performing a dot product calculation on the update dimension control unit and the update feature extraction unit. In the fused update feature extraction unit, the weight parameter of the dimension that is the same as the zero dimension of the update dimension control unit is also set to zero. At this time, the sparsity of the fused update feature extraction unit (i.e., the auxiliary network) can be determined according to the proportion of the dimension with the zero weight parameter in the fused update feature extraction unit in each dimension.

[0070] In some embodiments, the reference thresholds corresponding to each decoding layer can also be determined according to the levels of each decoding layer in the initial question-answering model, for example, the larger the level of the decoding layer, the smaller the reference threshold corresponding to the decoding layer. As can be seen from formula (1), the smaller the reference threshold, the lower the probability of setting the diagonal elements in the intermediate dimension control unit to zero, and the smaller the number of diagonal elements set to zero in the updated dimension control unit after parameter adjustment, and the smaller the number of dimensions in which the weight parameters are set to zero in the feature extraction unit after fusion with the updated dimension control unit. Therefore, the sparsity of the feature extraction unit corresponding to the decoding layer with a larger level (lower layer) is less than the sparsity of the feature extraction unit corresponding to the decoding layer with a smaller level (upper layer).

[0071] In some embodiments, the reference threshold may also change according to the number of iterations of the auxiliary network in the decoding layer. For example, the larger the number of iterations, the smaller the corresponding reference threshold. In the process of iterating the auxiliary network, the sparsity of the feature extraction unit corresponding to the decoding layer gradually decreases.

[0072] In this embodiment, by dynamically adjusting the reference threshold according to the level of the decoding layer or the number of iterations of the auxiliary network, the training flexibility of the initial question-answering model is improved, thereby improving the accuracy of the target question-answering model.

[0073] In some embodiments, before obtaining training questions corresponding to the target domain and training answers corresponding to the training questions in step 202, the training method of the question-answering model further includes:

[0074] Determine the decomposition rank number based on the number of dimensions of the obtained original incremental weight matrix;

[0075] Decomposing the original incremental weight matrix based on the decomposition rank number to obtain a decomposition weight matrix and a diagonal matrix;

[0076] Determine a feature extraction unit based on the decomposed weight matrix, and determine a dimension control unit based on the diagonal matrix;

[0077] Based on the feature extraction unit and the dimension control unit, an auxiliary network is determined.

[0078] Among them, the original incremental weight matrix is ​​used to decompose the weight matrix of the feature extraction unit and the dimension control unit. The decomposition rank number is used to indicate that the original incremental weight matrix is ​​decomposed into a weight matrix of the same rank number. The rank number refers to the maximum number of linearly independent vectors in the row vector group or column vector group of the matrix. The decomposed weight matrix refers to the weight matrix obtained by decomposing the original incremental weight matrix according to the decomposition rank number. A diagonal matrix refers to a matrix in which all elements outside the main diagonal are zero.

[0079] Exemplarily, the server obtains the original incremental weight matrix, which can be expressed as The original incremental weight matrix can be a weight matrix with the same number of dimensions as the pre-trained question-answering network, and each weight parameter in the original incremental weight matrix can be randomly generated. The pre-trained question-answering network can be expressed as , the number of dimensions of the pre-trained question-answering network is expressed as Then the decomposition rank is determined according to the number of dimensions of the original incremental weight matrix, which can be expressed as .

[0080] According to the decomposition rank number, the original incremental weight matrix Decomposition can be performed by performing singular value decomposition on the original incremental weight matrix to obtain two decomposed weight matrices and a diagonal matrix. The decomposed weight matrix can be expressed as and , It is expressed as the maximum decomposition rank number. The decomposed weight matrix is ​​a low-rank matrix relative to the original incremental weight matrix. The diagonal matrix can be expressed as g. The server decomposes the weight matrix and As a feature extraction unit, the diagonal matrix g is used as a dimension control unit, and then the auxiliary network is obtained according to the decomposition weight matrix and the diagonal matrix. The auxiliary network can be expressed as: , Represents dot product calculation. The forward propagation process of the auxiliary network is shown in formula (2):

[0081] (2)

[0082] Among them, X represents the input data; z represents the output result of the auxiliary network.

[0083] In some embodiments, the original incremental weight matrix is ​​subjected to singular value decomposition as shown in formula (3):

[0084] (3)

[0085] Among them, the matrix and matrix mutually orthogonal; is a diagonal matrix with diagonal elements The singular values ​​of are as shown in formula (4):

[0086] (4)

[0087] For convenience, The diagonal of is reshaped into a column vector, as shown in formula (5).

[0088] (5)

[0089] because , which represents the diagonal matrix g The norm can be used to control the rank of the decomposed weight matrix by adjusting the sparsity of the diagonal matrix g (when there are diagonal elements in the diagonal matrix set to zero). Therefore, the diagonal matrix g can be used as a dimension control unit to achieve the decomposition of the weight matrix by controlling its sparsity. and Dynamic configuration of the rank.

[0090] In this embodiment, the original incremental weight matrix is ​​decomposed to obtain a low-rank matrix and a diagonal matrix. The diagonal matrix is ​​used as a dimension control unit to adjust the sparsity of the low-rank matrix, enable the low-rank matrix to flexibly adapt to data changes, and reduce the computing resources of weight parameters of unnecessary dimensions.

[0091] In some embodiments, the training method of the question-answering model further includes:

[0092] The pre-trained question-answering network and the auxiliary network in the target question-answering model are integrated to obtain the specified question-answering model corresponding to the target domain;

[0093] Get the target question corresponding to the target field, input the target question into the specified question-answering model for processing, and output the target predicted answer corresponding to the target question.

[0094] Exemplarily, the server performs weight parameter fusion on the pre-trained question-answering network and the auxiliary network in the target question-answering model, which may be by adding the weights to obtain an optimized weight matrix, and then obtains the specified question-answering model based on the optimized weight matrix. The server then obtains the target question corresponding to the target field, inputs the target question into the specified question-answering model, and obtains the target predicted answer corresponding to the target question.

[0095] The optimized weight matrix is ​​shown in formula (6):

[0096] (6)

[0097] Where W represents the optimized weight matrix; Represents the weight matrix of the pre-trained question-answering network; represents the weight matrix of the auxiliary network, where and represents the weight matrix of the feature extraction unit, and g represents the weight matrix of the dimension control unit; Represents a dot product calculation.

[0098] In this embodiment, the trained auxiliary network and the pre-trained question-answering network are merged to obtain an optimized weight matrix. The optimized weight matrix can be used to process the input data in a unified manner without the need to process the input data separately through the auxiliary network and the pre-trained question-answering network, thereby saving unnecessary resource consumption and improving the processing efficiency of the specified question-answering model.

[0099] In some embodiments, Figure 4 As shown in FIG. 1 , a schematic diagram of a question-answering model training process including a question-answering model architecture is provided. The question-answering model can be a neural network model (such as Figure 4The large model in the question-answering model includes an embedding layer, various decoding layers, and a linear softmax layer. Corresponding dynamic low-rank adapters are set in each decoding layer of the question-answering model. The structure of the dynamic low-rank adapter includes the large model pre-trained weights of the decoding layer (i.e., the pre-trained question-answering network) and an auxiliary network composed of a low-rank matrix (i.e., a feature extraction unit) and a gating unit (i.e., a dimension control unit). The dynamic low-rank adapter is used to adjust the parameters of the auxiliary network of the corresponding decoding layer.

[0100] The training process of the question-answering model is as follows:

[0101] The API document is structured through a natural language processing model to obtain a structured document, and then training questions and training answers are generated based on the structured document, such as "Question: What function can I call if I want to achieve channel conversion of an image?" and "Answer: You can use the CvtColor function."

[0102] For the dynamic low-rank adapter of any decoding layer in the question-answering model, the pre-trained weights of the question-answering model itself are frozen, and the low-rank matrix and gating unit in the auxiliary network are trained to obtain the trained auxiliary network. During the training of the low-rank matrix and gating unit in the auxiliary network, the sparsity of the gating unit is used to compress the invalid dimensions of the low-rank matrix, and finally the optimal rank of the low-rank matrix is ​​achieved. Then the weights of the trained auxiliary network are added to the pre-trained weights to obtain the optimized weights, and the specified question-answering model is obtained based on the optimized weights.

[0103] In this embodiment, by introducing a dynamic low-rank adapter structure, the training process of the question-answering model is optimized (which can be expressed as fine-tuning of the question-answering model), so that the trained question-answering model can be more flexibly adapted to different input data, and can generate customized question-answering pair data. At the same time, no additional overhead is introduced in the calculation process of the question-answering model, thereby reducing resource consumption.

[0104] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0105] Based on the same inventive concept, the embodiment of the present application also provides a training device for a question-answering model. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the training device for one or more question-answering models provided below can refer to the limitations of the training method for the question-answering model above, and will not be repeated here.

[0106] like Figure 5 As shown, the embodiment of the present application provides a training device 500 for a question-answering model, including:

[0107] An acquisition module 502 is used to obtain training questions corresponding to the target domain and training answers corresponding to the training questions;

[0108] Processing module 504, used to input the training question into the initial question-answering model, the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; extract the first question feature of the training question through the pre-trained question-answering network, and extract the second question feature of the training question through the auxiliary network; determine the predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit;

[0109] A loss calculation module 506, for generating a model loss based on the predicted answer and the training answer;

[0110] The model optimization module 508 is used to adjust the feature extraction unit based on the model loss; adjust the dimension control unit based on the model loss and the reference threshold until the convergence condition is met to obtain the target question answering model corresponding to the target domain.

[0111] In some embodiments, the target domain is a functional interface query domain; in terms of obtaining training questions corresponding to the target domain and training answers corresponding to the training questions, the obtaining module 502 is specifically used to:

[0112] Structuring the function information of each functional interface in the acquired functional interface document to obtain a structured document;

[0113] Based on the function description of each functional interface in the structured document, generate training questions corresponding to the target domain and training answers corresponding to the training questions.

[0114] In some embodiments, the dimension control unit includes diagonal elements; in adjusting the dimension control unit based on the model loss and the reference threshold, the model optimization module 508 is specifically used to:

[0115] Based on the model loss and iteration step size, the dimension control unit is gradient updated to obtain the intermediate dimension control unit;

[0116] Each diagonal element in the intermediate dimension control unit is adjusted based on the reference threshold to obtain an updated dimension control unit.

[0117] In some embodiments, the reference threshold includes a positive reference threshold and a negative reference threshold; in adjusting each diagonal element in the intermediate dimension control unit based on the reference threshold to obtain an updated dimension control unit, the model optimization module 508 is specifically used to:

[0118] For any diagonal element in the intermediate dimension control unit, when the element value of the diagonal element is greater than the positive reference threshold, determining an updated element value of the diagonal element based on the difference between the element value and the positive reference threshold; or,

[0119] When the element value of the diagonal element is less than or equal to the positive reference threshold and greater than the negative reference threshold, a zero value is used as the updated element value of the diagonal element; or,

[0120] When the element value of the diagonal element is less than or equal to the negative reference threshold, an updated element value of the diagonal element is determined based on a difference between the element value and the negative reference threshold.

[0121] In some embodiments, the training device 500 for the question-answering model also includes a construction module; the construction module is used to determine the decomposition rank number based on the number of dimensions of the acquired original incremental weight matrix; decompose the original incremental weight matrix based on the decomposition rank number to obtain a decomposition weight matrix and a diagonal matrix; determine a feature extraction unit based on the decomposition weight matrix, and determine a dimension control unit based on the diagonal matrix; determine an auxiliary network based on the feature extraction unit and the dimension control unit.

[0122] In some embodiments, the training device 500 for the question-answering model also includes an application module; the application module is used to fuse the pre-trained question-answering network and the auxiliary network in the target question-answering model to obtain a specified question-answering model corresponding to the target domain; obtain the target question corresponding to the target domain, input the target question into the specified question-answering model for processing, and output the target predicted answer corresponding to the target question.

[0123] Each module in the training device of the question-answering model can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0124] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to the training of the question-answering model. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the training method of the above-mentioned question-answering model are implemented.

[0125] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (Near Field Communication, NFC) or other technologies. When the computer program is executed by the processor, the steps in the training method of the above-mentioned question-answering model are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0126] Those skilled in the art will understand that Figure 6 or Figure 7The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0127] In some embodiments, a computer device is also provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0128] In some embodiments, Figure 8 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0129] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0131] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0132] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0133] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A training method for a question-answering model, characterized in that: include: Structuring the function information of each functional interface in the acquired functional interface document to obtain a structured document; Generate training questions corresponding to the target domain and training answers corresponding to the training questions based on the function descriptions of the various functional interfaces in the structured document; The target domain is a functional interface query domain; Inputting the training question into an initial question-answering model, wherein the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; Extracting a first question feature of the training question through the pre-trained question answering network, and extracting a second question feature of the training question through the auxiliary network; Determine a predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit; the dimension control unit includes each diagonal element; Generating a model loss based on the predicted answer and the training answer; Based on the model loss, adjusting the feature extraction unit; Based on the model loss and the reference threshold, the dimension control unit is adjusted until a convergence condition is met, thereby obtaining a target question-answering model corresponding to the target domain; The reference threshold includes a positive reference threshold and a negative reference threshold; The adjusting the dimension control unit based on the model loss and the reference threshold comprises: Based on the model loss and the iteration step, the dimension control unit is gradient updated to obtain an intermediate dimension control unit; For any diagonal element in the intermediate dimension control unit, when the element value of the diagonal element is greater than the positive reference threshold, the updated element value of the diagonal element is determined based on the difference between the element value and the positive reference threshold; or, when the element value of the diagonal element is less than or equal to the positive reference threshold and greater than the negative reference threshold, zero is used as the updated element value of the diagonal element; or, when the element value of the diagonal element is less than or equal to the negative reference threshold, the updated element value of the diagonal element is determined based on the difference between the element value and the negative reference threshold.

2. The method according to claim 1, characterized in that The function information of each functional interface in the acquired functional interface document is structured to obtain a structured document, including: The acquired functional interface document is input into a natural language model, and the function structure corresponding to the function information of each functional interface in the functional interface document is segmented by the natural language model to obtain a structured document.

3. The method according to claim 1, characterized in that The method further comprises: According to the levels of each decoding layer in the initial question-answering model, the reference thresholds corresponding to each decoding layer are determined; each decoding layer includes its own pre-trained question-answering network and auxiliary network.

4. The method according to claim 1, characterized in that The method further comprises: According to the number of iterations of the auxiliary network corresponding to each decoding layer in the initial question-answering model, the reference threshold corresponding to each decoding layer is determined.

5. The method according to claim 1, characterized in that Before the function information of each functional interface in the acquired functional interface document is structured to obtain the structured document, the method further includes: Determine the decomposition rank number based on the number of dimensions of the obtained original incremental weight matrix; Decomposing the original incremental weight matrix based on the decomposition rank number to obtain a decomposition weight matrix and a diagonal matrix; Determine the feature extraction unit based on the decomposition weight matrix, and determine the dimension control unit based on the diagonal matrix; Based on the feature extraction unit and the dimension control unit, the auxiliary network is determined.

6. The method according to claim 1, characterized in that The method further comprises: Fusing the pre-trained question-answering network and the auxiliary network in the target question-answering model to obtain a specified question-answering model corresponding to the target domain; Obtain a target question corresponding to the target field, input the target question into the specified question-answering model for processing, and output a target predicted answer corresponding to the target question.

7. A training device for a question-answering model, characterized in that: include: The acquisition module is used to perform structured processing on the function information of each functional interface in the acquired functional interface document to obtain a structured document; Generate training questions corresponding to the target domain and training answers corresponding to the training questions based on the function descriptions of the various functional interfaces in the structured document; The target domain is a functional interface query domain; A processing module, configured to input the training question into an initial question-answering model, wherein the initial question-answering model includes a pre-trained question-answering network and an auxiliary network; Extracting a first question feature of the training question through the pre-trained question answering network, and extracting a second question feature of the training question through the auxiliary network; Determine a predicted answer corresponding to the training question based on the first question feature and the second question feature; the auxiliary network includes a feature extraction unit and a dimension control unit for the feature extraction unit; the dimension control unit includes each diagonal element; A loss calculation module, used for generating a model loss based on the predicted answer and the training answer; A model optimization module, used for adjusting the feature extraction unit based on the model loss; Based on the model loss and the reference threshold, adjusting the dimension control unit until a convergence condition is met, and obtaining a target question-answering model corresponding to the target domain, wherein the reference threshold includes a positive reference threshold and a negative reference threshold; The model optimization module is also used to perform gradient update on the dimension control unit based on the model loss and the iteration step to obtain an intermediate dimension control unit; for any diagonal element in the intermediate dimension control unit, when the element value of the diagonal element is greater than the positive reference threshold, the updated element value of the diagonal element is determined based on the difference between the element value and the positive reference threshold; or, when the element value of the diagonal element is less than or equal to the positive reference threshold and greater than the negative reference threshold, zero is used as the updated element value of the diagonal element; or, when the element value of the diagonal element is less than or equal to the negative reference threshold, the updated element value of the diagonal element is determined based on the difference between the element value and the negative reference threshold.

8. The device according to claim 7, characterized in that The apparatus further comprises a construction module, the construction module being configured to determine a decomposition rank number based on the number of dimensions of the acquired original incremental weight matrix; The original incremental weight matrix is ​​decomposed based on the decomposition rank number to obtain a decomposition weight matrix and a diagonal matrix; the feature extraction unit is determined based on the decomposition weight matrix, and the dimension control unit is determined based on the diagonal matrix; the auxiliary network is determined based on the feature extraction unit and the dimension control unit.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Dialogue model training method, dialogue processing method and device

    CN117951264A

  • Construction method of professional question and answer model based on large language model fine tuning algorithm

    CN118469020A