A processing method and device of a large language model with introduced conditional constraints

By customizing the state prediction model for large language models and introducing a multi-rule state prediction module, the problem of generated text not conforming to rules was solved, achieving efficient conditional text generation and reducing model complexity and computational cost.

CN119476208BActive Publication Date: 2025-10-24BEIJING DP TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411493187.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-24
Publication Date
2025-10-24
Estimated Expiration
2044-10-24

AI Technical Summary

Technical Problem

Existing large language models lack the ability to impose conditional constraints when generating text, resulting in generated text that does not meet specific rule requirements. Existing solutions increase model complexity and computational cost, and are also less timely.

Method used

A state prediction model is customized for each type of conditional rule, and a multi-rule state prediction model and constraint decoding control module are introduced into the large language model to realize single-step text constraints. By dynamically replacing the rule model instead of secondary training, the model complexity and computational cost are reduced.

Benefits of technology

This approach improves the model's flexibility in adapting to rules and its timeliness in task processing without increasing model training costs, while reducing computational load and timeliness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119476208B_ABST
    Figure CN119476208B_ABST
Patent Text Reader

Abstract

The embodiment of the application relates to a processing method and device of a large language model with introduced conditional constraints, the method comprising: customizing a corresponding first state prediction model for each conditional rule; creating a corresponding model training data set for each conditional rule to train the corresponding first state prediction model; recording any type of large language model based on a Transformer architecture and having completed pre-training and fine-tuning as a first large language model; selecting all first state prediction models corresponding to one or more conditional rules to form a multi-rule state prediction model, and adding the multi-rule state prediction model and a constraint decoding control module to the first large language model to form a second large language model; and performing corresponding constraint text generation processing based on the second large language model according to user input text and outputting corresponding constraint generated text to feedback to the user. The application can improve the rule adaptation flexibility of the model, reduce the computational amount, and improve the timeliness.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and particularly relates to a processing method and device of a large language model with introduced conditional constraints. BACKGROUND

[0002] Large language models (LLMs) are widely used in various natural language processing (NLP) tasks. The mainstream large language models at present are mostly implemented based on a Transformer architecture, such as GPT series models, BERT series models, T5 series models, etc. After large-scale pre-training and fine-tuning in a specific field, such large language models can have stable language understanding and language generation capabilities. However, starting from the implementation principle of the model basic architecture (i.e., the Transformer architecture), it can be known that such large language models do not have the capability of conditionally constraining generated text. This may result in that the generated text of the model may not meet some specific rule requirements, such as some specific semantic, grammatical, and formatting expression rules.

[0003] To solve this problem, some researchers add a conditional / rule constraint coding step to the coding process of the traditional large language model to improve the conditional / rule constraint ability of the model. The specific method is simply to add a conditional encoder to encode the specified conditional rules (such as semantic rules, syntax rules, and formatted expression rules) into a conditional vector, and to fuse the conditional vector encoding and the text encoding, and then to decode and generate the processing according to the fused features through the text generation module (or decoding module). Some other researchers add a series of post-processing modules to the back end of the traditional large language model to improve the conditional / rule constraint ability of the model. The specific method is simply to pre-construct a corresponding text post-processing module through the specified conditional rules (such as semantic rules, syntax rules, and formatted expression rules), and then to check the generated text through this text post-processing module according to the corresponding rules, and to call the decoding module of the model to generate a new text again when the generated text cannot meet the corresponding rule requirements, and to check the new text again until the latest text can meet the corresponding rule requirements. But we found through practical application that both of these two solving mechanisms have some problems: 1) the first solving mechanism will increase the complexity of the model, and every time the conditional rules are switched or added or removed, the model needs to be retrained or fine-tuned, which will increase the complexity of the model design, increase the cost of model training, and reduce the flexibility of the model in adapting to rules; 2) the second solving mechanism only checks the final sequence based on the output of the whole sequence, and repeatedly generates text when the check is not up to standard, which will increase the probability of finding errors in the process, that is, the probability of repeated decoding of the whole sequence will be higher, which will naturally cause problems such as large amount of calculation and poor timeliness. SUMMARY

[0004] The present application aims at the defects of the prior art, and provides a processing method and device of a large language model with introduced conditional constraints, electronic equipment and a computer readable storage medium. The present application pre-customizes a rule detection state prediction model, i.e., a first state prediction model, for each type of conditional rule and trains the same; then, any large language model based on a Transformer architecture and having completed pre-training and fine-tuning is recorded as a first large language model, and one or more first state prediction models corresponding to known conditional rules are selected to construct a corresponding multi-rule state prediction model, and a multi-rule state prediction model and a constraint decoding control module are added to the first large language model to form a constraint text generation model capable of performing conditional constraints on each step of generated text in a single-step detection manner, recorded as a second large language model; and based on the second large language model, corresponding constraint text generation processing is performed according to user input text, and corresponding constraint generated text is output to the user for feedback. The second large language model designed by the present application has single-step text constraint capability, and the corresponding computational amount is effectively reduced compared with a conventional post-processing mechanism, and the corresponding timeliness is effectively improved compared with the conventional post-processing mechanism. The second large language model designed by the present application does not need to modify the encoding / decoding components of the large language model, and only needs to dynamically replace / add / remove the first state prediction model in the multi-rule state prediction model when switching conditional rules, without the need for secondary pre-training or secondary directional fine-tuning of the model. Through the present application, the design complexity of the model can be reduced, the model training cost can be saved, the adaptability and flexibility of the model to rules can be improved, and the computational amount of the model can be reduced and the timeliness of the model in task processing can be improved.

[0005] To achieve the above object, the first aspect of the embodiment of the present application provides a processing method of a large language model with introduced conditional constraints, which comprises:

[0006] Step 1: customizing a corresponding first state prediction model for each first conditional rule in a preset first conditional rule set; creating a corresponding model training data set for each first conditional rule to obtain a corresponding first data set; and training the corresponding first state prediction model based on each first data set;

[0007] The first condition rule set includes a plurality of first condition rules; the rule types of the first condition rules include at least semantic rules, syntax rules, sentiment rules, and formatted expression rules; each first state prediction model is sequentially connected by a corresponding convolutional neural network, a full connection network, and an activation layer; the convolutional neural network is composed of one convolutional layer or a plurality of sequentially connected convolutional layers; the full connection network is composed of one full connection layer or a plurality of sequentially connected full connection layers; each first state prediction model is used to perform corresponding single-step rule state prediction according to a model input text sequence to obtain a corresponding single-step prediction state; the single-step prediction state includes an acceptable state and an unacceptable state.

[0008] Step 2: any large language model based on the Transformer architecture and having completed pre-training and fine-tuning is denoted as a corresponding first large language model;

[0009] Step 3: one or more first condition rules are selected from the first condition rule set to form a corresponding current rule set; a corresponding multi-rule state prediction model is constructed based on all first state prediction models corresponding to the current rule set; and the multi-rule state prediction model and a constraint decoding control module are added to the first large language model to form a corresponding second large language model;

[0010] Step 4: based on the second large language model, corresponding constraint text generation processing is performed according to user input text, and corresponding constraint generated text is output to the user as feedback.

[0011] Preferably, the first data set includes a plurality of first data records; the first data record includes a first training text sequence and a first label state vector; the first training text sequence is sequentially sorted by a plurality of first training texts, and the first training text is a number, a symbol, a single character, a word, or a phrase; the first label state vector is sequentially sorted by a plurality of first label states; the first label state includes an acceptable state and an unacceptable state; and the first label state corresponds to the first training text one by one.

[0012] Preferably, the first data set is obtained by creating a corresponding model training data set for each first condition rule, specifically including:

[0013] Step 31: any first condition rule is denoted as a corresponding current condition rule;

[0014] Step 32, enumerate all rule entries of the current condition rule to obtain a corresponding current rule entry set, and perform regular expression conversion on each first rule entry of the current rule entry set to obtain a corresponding first regular expression, and form a corresponding current expression set by all the obtained first regular expressions;

[0015] The current rule entry set includes a plurality of first rule entries, the current expression set includes a plurality of first regular expressions, and the first regular expression corresponds to the first rule entry one by one.

[0016] Step 33, selecting a type of automatic machine from a plurality of types of automatic machines that is adapted to the current condition rule as a corresponding first automatic machine, and identifying the automatic machine type of the first automatic machine; if the automatic machine type is a deterministic finite automaton or a non-deterministic finite automaton, configuring the quintuple of the first automatic machine based on the current expression set; if the automatic machine type is a push-down automaton, configuring the sextuple of the first automatic machine based on the current expression set.

[0017] The plurality of types of automatic machines at least include a deterministic finite automaton, a non-deterministic finite automaton and a push-down automaton; the quintuple of the deterministic finite automaton includes a finite state set Q, a finite alphabet ∑, a transition function δ, a start state q0 and an acceptance state set F; the quintuple of the non-deterministic finite automaton includes a finite state set Q, a finite alphabet ∑, a transition function δ, a start state q start and an acceptance state q accept ; the sextuple of the push-down automaton includes a state set Q, an input alphabet ∑, a stack alphabet Γ, a transition function δ, a start state q0 and an acceptance state set F; the first automatic machine is used for compliance state determination of an input text sequence and obtains a corresponding determination result; the determination result includes an acceptable state and an unacceptable state.

[0018] Step 34, based on the corresponding text features of the current condition rule and according to a preset first positive-negative sample ratio, collecting corresponding positive-negative sample corpus to obtain a corresponding first text corpus;

[0019] The first text corpus includes a plurality of first text corpora, and the first text corpus at least includes a single sentence corpus; the positive and negative sample text corpus ratio of the first text corpus meets the first positive-negative sample ratio.

[0020] Step 35, performing word segmentation processing on each first text corpus to obtain a corresponding molecular sequence as a corresponding first training text sequence.

[0021] Step 36, take each of the first training text sequence as a corresponding current training text sequence; and initialize a corresponding first input sequence and a first output sequence as empty; and perform a round of sequential traversal on all the first training texts of the current training text sequence; and in the traversal process, add the first training text currently traversed to the end of the first input sequence, and input the first input sequence after completing this addition into the corresponding first automaton to perform compliance state judgment and obtain a corresponding current judgment result added to the end of the first output sequence; and at the end of this round of traversal, take the obtained first output sequence as a corresponding first label state vector;

[0022] Step 37, compose a corresponding first data record from each of the first training text sequence and the corresponding first label state vector; and compose a corresponding first data set from all the obtained first data records.

[0023] Preferably, the first state prediction model is trained based on each of the first data set, specifically comprising:

[0024] Step 41, take any first data set as a corresponding current data set; and take the first state prediction model corresponding to the current data set as a corresponding current state prediction model; and divide the current data set into two sub-data sets according to a preset first segmentation ratio, taking the first training set and the first evaluation set as corresponding;

[0025] Wherein, the first training set and the first evaluation set are both composed of a plurality of first data records; the ratio of the total number of records of the first training set to the total number of records of the first evaluation set meets the first segmentation ratio;

[0026] Step 42, take the first first data record of the first training set as a corresponding current training record;

[0027] Step 43, take the first training text sequence of the current training record as a corresponding current training text sequence; and initialize a corresponding second input sequence and a second output sequence as empty; and perform a round of sequential traversal on all the first training texts of the current training text sequence; and in the traversal process, add the first training text currently traversed to the end of the second input sequence, and input the second input sequence after completing this addition into the current state prediction model to perform a corresponding single-step rule state prediction to obtain a corresponding first single-step prediction state added to the end of the second output sequence; and at the end of this round of traversal, take the obtained second output sequence as a corresponding first prediction state vector;

[0028] The expression of the single-step rule state prediction corresponding to the current state prediction model is:

[0029] s = F con (Y2; β),

[0030] F con is a single-step rule state prediction function expression of the current state prediction model, Y2 is the second input sequence, β is a model parameter of the current state prediction model, and s is the first single-step prediction state. The first single-step prediction state s includes an acceptable state and an unacceptable state.

[0031] The first prediction state vector is sequentially sorted by a plurality of first single-step prediction states s. The first single-step prediction state s is one-to-one corresponding to the first training text.

[0032] Step 44, the first prediction state vector and the first label state vector of the current training record are brought into a preset first model loss function; and based on a preset first model optimizer, the model parameter β of the current state prediction model is optimized in a direction of minimizing the first model loss function;

[0033] The first model loss function includes an L1 loss function, an L2 loss function, and a cross-entropy loss function. The first model optimizer includes at least an SGD optimizer and an ADAM optimizer.

[0034] Step 45, whether the current training record is the last first data record of the first training set is identified; if yes, go to step 46; if no, the next first data record of the first training set is extracted as a new current training record and returns to step 43.

[0035] Step 46, a round of traversal is performed on all the first data records of the first evaluation set; during the round of traversal, the first data record currently traversed is taken as a corresponding current evaluation record; a third input sequence and a third output sequence are initialized as empty; all the first training texts of the first training text sequence of the current evaluation record are sequentially polled; during polling, the first training text currently polled is added to the end of the third input sequence, and the third input sequence after the addition is input into the current state prediction model to obtain a corresponding second single-step prediction state by corresponding single-step rule state prediction, and the second single-step prediction state is added to the end of the third output sequence; at the end of polling, the third output sequence obtained is taken as a corresponding second prediction state vector; a corresponding first prediction-label pair is formed by the second prediction state vector and the first label state vector of the current evaluation record; at the end of the round of traversal, a first confusion matrix is constructed according to all the first prediction-label pairs obtained, and corresponding first accuracy, first precision, first recall and first F1 score are calculated based on the first confusion matrix to obtain corresponding first accuracy, first precision, first recall and first F1 score;

[0036] Step 47, the first accuracy, the first precision, the first recall and the first F1 score are identified; if the first accuracy does not meet a preset first accuracy range or the first precision does not meet a preset first precision range or the first recall does not meet a preset first recall range or the first F1 score does not meet a preset first F1 score range, the method returns to step 42 for continuous training; if the first accuracy meets the first accuracy range, the first precision meets the first precision range, the first recall meets the first recall range and the first F1 score meets the first F1 score range, the training is stopped and it is confirmed that the current state prediction model training is completed.

[0037] Preferably, the first large language model is used to understand the natural language features of the model input text and perform corresponding text generation processing based on the understanding features and output corresponding model generated text;

[0038] The first large language model comprises a first encoding module and a first decoding module;

[0039] In the first large language model, the input end of the first encoding module is connected with the model input end, and the output end is connected with the encoding feature input end of the first decoding module; the output end of the first decoding module is connected with the model output end;

[0040] The first large language model, the first encoding module is implemented based on the encoder structure of the Transformer model or based on another type of deep learning model for feature encoding; the first encoding module is used for performing word segmentation processing on the model input text to obtain a corresponding word segmentation sequence; and the obtained word segmentation sequence is subjected to feature encoding processing to obtain a corresponding encoding vector X, which is sent to the first decoding module;

[0041] The first large language model, the first decoding module is implemented based on the decoder structure of the Transformer model or based on another type of text generator model for feature decoding and text generation;

[0042] The first large language model, the first decoding module is used to set a single step index t = 1 at the initial moment of receiving the encoding vector X, and set an initial character y0 corresponding to the preset starting character, and initialize the previous step generation sequence Y as {y0}; and when the single step index t changes every time, the encoding vector X, the single step index t and the corresponding previous step generation sequence Y are subjected to a single step text generation processing to obtain a corresponding single step generation text y t ; and whether the single step generation text y t matches the preset end symbol is identified; if the single step generation text y t does not match the preset end symbol, the single step generation text y t is added to the end of the previous step generation sequence Y {y0, y1, … y t-1} to obtain a reset previous step generation sequence Y {y0, y1, … y t-1 ,y t}, and the single step index t is incremented by 1, and the next single step text generation processing is continued based on the encoding vector X, the new single step index t and the previous step generation sequence Y; if the single step generation text y t matches the preset end symbol, the initial character y0 is removed from the previous step generation sequence Y {y0, y1, … y t-1} to obtain a reset previous step generation sequence Y {y1, … y t-1}, and the previous step generation sequence Y {y1, … y t-1} is output as the corresponding model generation text.

[0043] The expression of the single step text generation processing of the first decoding module is: y t =F dec (Y, X; θ), wherein F dec() is a function expression of a single-step text generation process, Y is a previous step generation sequence, X is an encoding feature output by the first encoding module, θ is a model parameter of the first decoding module, y t is a single-step generated text of the tth step.

[0044] Preferably, the second large language model is used to understand the natural language features of the model input text and generate corresponding constraint text based on the understanding features and output corresponding model generated text.

[0045] The second large language model comprises the first encoding module, the first decoding module, the multi-rule state prediction model and the constraint decoding control module.

[0046] In the second large language model, the input end of the first encoding module is connected with the model input end, and the output end is connected with the first input end of the first decoding module; the single-step decoding output end of the first decoding module is connected with the input end of the multi-rule state prediction model; the output end of the multi-rule state prediction model is connected with the input end of the constraint decoding control module; the first output end of the constraint decoding control module is connected with the second input end of the first decoding module, and the second output end is connected with the model output end.

[0047] In the second large language model, the first encoding module is used to perform word segmentation processing on the model input text to obtain a corresponding word segmentation sequence, and perform feature encoding processing on the obtained word segmentation sequence to obtain a corresponding encoding vector X, which is sent to the first decoding module.

[0048] In the second large language model, the first decoding module is used to set a single-step index t = 1 at the initial moment of receiving the encoding vector X, and initialize a previous step generation sequence Y as {y0}; and each time the single-step index t changes, a single-step text generation process is performed based on the encoding vector X, the single-step index t and the corresponding previous step generation sequence Y to obtain a corresponding single-step generated text y t is sent to the multi-rule state prediction model.

[0049] In the second large language model, the multi-rule state prediction model comprises a sequence splicing module, one or more parallel first state prediction models and a multi-rule state fusion module; the input end of the sequence splicing module is connected with the input end of the multi-rule state prediction model, and the output end is connected with the input end of each first state prediction model; the output end of each first state prediction model is connected with one input end of the multi-rule state fusion module; the output end of the multi-rule state fusion module is connected with the output end of the multi-rule state prediction model.

[0050] In the second language model, the multi-rule state prediction model is used to generate the text y in each step. t When the sequence splicing module receives the single-step generated text y t Add to the previous step to generate the sequence Y{y0,y1,…y t-1} at the end of the corresponding current generated sequence {y0,…y t} is sent to each of the first state prediction models; and each of the first state prediction models generates a sequence {y0, y1, ... y t-1 ,y t} Perform the corresponding single-step rule state prediction to obtain the corresponding single-step prediction state s i,t Send to the multi-rule state fusion module, 1≤ rule index i≤ total number of rules N, the total number of rules N is the total number of the first state prediction model; and the multi-rule state fusion module will obtain N single-step prediction states s i,t Form a corresponding single-step state vector S t Sending to the constraint decoding control module;

[0051] The single-step rule state prediction expression corresponding to each of the first state prediction models is: i,t =F con,i ({y0,…y t};β i ), where F con,i () is the single-step rule state prediction function expression of the i-th first state prediction model, β i is the model parameter of the i-th first state prediction model, the single-step prediction state s i,t Includes acceptable and unacceptable states;

[0052] In the second language model, the constraint decoding control module is used to receive a single-step state vector S t When the single-step state vector S currently received is t With the preset label state vector S tag The vector difference modulus is calculated to obtain the corresponding first modulus value a=|S t -S tag |; and identifying whether the first modulus value a is zero;

[0053] If the first modulus value a is not zero, then the objective function is set to Based on the preset second model optimizer, the model parameter θ of the first decoding module is fine-tuned in the direction of minimizing the objective function, and at the end of this round of fine-tuning, the single-step generated text y generated in the previous step t-1 is converted tot-1 The single-step generated text y t-1 is removed from the previous step generated sequence Y{y0,y1,…y t-2}, and the single-step index t is reduced by 1, and the next single-step text generation process is continued based on the encoding vector X, the new single-step index t and the previous step generated sequence Y; the second model optimizer at least includes an SGD optimizer, an ADAM optimizer;

[0054] If the first modulus a is zero, the single-step generated text y t is identified whether it matches a preset end symbol; if the single-step generated text y t does not match the preset end symbol, the single-step generated text y t is added to the end of the previous step generated sequence Y{y0,y1,…y t-1} to obtain a reset previous step generated sequence Y{y0,y1,…y t-1 ,y t}, and the single-step index t is increased by 1, and the next single-step text generation process is continued based on the encoding vector X, the new single-step index t and the previous step generated sequence Y; if the single-step generated text y t matches the preset end symbol, the initial character y0 is removed from the previous step generated sequence Y{y0,y1,…y t-1} to obtain a reset previous step generated sequence Y{y1,…y t-1}, and the previous step generated sequence Y{y1,…y t-1} is taken as the corresponding model generated text and output.

[0055] The second aspect of the embodiment of the application provides a device for implementing the processing method of the large language model with introduced conditional constraints in the first aspect, and the device comprises a state prediction model preparation module, a large language model selection module, a large language model modification module and a modified model application module.

[0056] The state prediction model preparation module is configured to customize a corresponding first state prediction model for each first condition rule in a preset first condition rule set, create a corresponding model training data set for each first condition rule to obtain a corresponding first data set, and train the corresponding first state prediction model based on each first data set, wherein the first condition rule set includes a plurality of first condition rules, the rule types of the first condition rules include at least semantic rules, syntax rules, sentiment rules, and formatted expression rules, each first state prediction model is sequentially connected by a corresponding convolutional neural network, a full connection network, and an activation layer, the convolutional neural network is composed of one convolutional layer or a plurality of sequentially connected convolutional layers, and the full connection network is composed of one full connection layer or a plurality of sequentially connected full connection layers, each first state prediction model is configured to perform corresponding single-step rule state prediction to obtain a corresponding single-step prediction state according to a model input text sequence, and the single-step prediction state includes an acceptable state and an unacceptable state.

[0057] The large language model selection module is configured to record any type of large language model based on a Transformer architecture and implemented and pre-trained and fine-tuned as a corresponding first large language model.

[0058] The large language model modification module is configured to select one or more first condition rules from the first condition rule set to form a corresponding current rule set, construct a corresponding multi-rule state prediction model based on all first state prediction models corresponding to the current rule set, and increase the multi-rule state prediction model and a constraint decoding control module based on the first large language model to form a corresponding second large language model.

[0059] The modified model application module is configured to perform corresponding constraint text generation processing based on the second large language model according to user input text and output corresponding constraint generation text to feedback to the user.

[0060] The third aspect of the embodiment of the application provides an electronic device, including a memory, a processor and a transceiver.

[0061] The processor is configured to be coupled with the memory, read and execute instructions in the memory to realize the method steps of the first aspect;

[0062] The transceiver is coupled with the processor, and the transceiver is controlled by the processor to perform message transceiving.

[0063] The fourth aspect of the embodiment of the present application provides a computer readable storage medium, which stores computer instructions, and when the computer instructions are executed by a computer, the computer instructions make the computer execute the method of the first aspect.

[0064] The embodiment of the present application provides a processing method and device of a large language model with introduced conditional constraints, electronic equipment and computer readable storage medium. From the above content, it can be known that the embodiment of the present application pre-customizes a rule detection state prediction model, that is, a first state prediction model, for each type of conditional rule and trains the first state prediction model; then, any type of large language model based on a Transformer architecture and having completed pre-training and fine-tuning is recorded as a first large language model, one or more first state prediction models corresponding to known conditional rules are selected to construct a corresponding multi-rule state prediction model, and the multi-rule state prediction model and a constraint decoding control module are added to the first large language model to form a constraint text generation model capable of performing conditional constraints on each step of generated text in a single-step detection manner, which is recorded as a second large language model; and based on the second large language model, corresponding constraint text generation processing is performed on the user input text, and corresponding constraint generated text is output to the user for feedback. The second large language model designed in the embodiment of the present application has a single-step text constraint capability, and the corresponding computational amount is effectively reduced compared with a conventional post-processing mechanism, and the corresponding timeliness is effectively improved compared with the conventional post-processing mechanism. The second large language model designed in the embodiment of the present application does not need to modify the encoding / decoding component of the large language model, and only needs to dynamically replace / add / remove the first state prediction model in the multi-rule state prediction model when switching the conditional rule, without the need for secondary pre-training or secondary directional fine-tuning of the model. Through the embodiment of the present application, the design complexity of the model is reduced, the model training cost is saved, the adaptation flexibility of the model to the rule is improved, and the computational amount of the model is reduced and the timeliness of the model task processing is improved. BRIEF DESCRIPTION OF DRAWINGS

[0065] Figure 1 A processing method of a large language model with introduced conditional constraints is provided for the embodiment one of the present application;

[0066] Figure 2 A module structure diagram of the first state prediction model is provided for the embodiment one of the present application;

[0067] Figure 3 A module structure diagram of the first and second large language models is provided for the embodiment one of the present application;

[0068] Figure 4 A flowchart of a text generation processing flow of the first large language model is provided for the embodiment one of the present application;

[0069] Figure 5 A flowchart of a constraint text generation process flow of a second large language model provided for the first embodiment of the present application;

[0070] Figure 6 A module structure diagram of a processing device of a large language model with introduced conditional constraints provided for the second embodiment of the present application;

[0071] Figure 7 A structure diagram of an electronic device provided for the third embodiment of the present application. DETAILED DESCRIPTION

[0072] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts fall within the scope of the present application.

[0073] The first embodiment of the present application provides a processing method of a large language model with introduced conditional constraints, which comprises the following steps: Figure 1 As shown in a processing method diagram of a large language model with introduced conditional constraints provided for the first embodiment of the present application, the method mainly comprises the following steps:

[0074] Step 1, customizing a corresponding first state prediction model for each first conditional rule in a preset first conditional rule set; creating a corresponding model training data set for each first conditional rule to obtain a corresponding first data set; and training the corresponding first state prediction model based on each first data set;

[0075] Specifically, step 1 comprises the following step 11: customizing a corresponding first state prediction model for each first conditional rule in a preset first conditional rule set;

[0076] Here, the first conditional rule set of the embodiment of the present application comprises a plurality of first conditional rules; the rule types of the first conditional rules at least include semantic rules, syntax rules, sentiment rules and formatted expression rules;

[0077] As shown in a module structure diagram of a first state prediction model provided for the first embodiment of the present application, the model structure of each first state prediction model of the embodiment of the present application is sequentially connected by a corresponding convolutional neural network, a full connection network and an activation layer; wherein the convolutional neural network is composed of one convolutional layer or a plurality of sequentially connected convolutional layers, and the full connection network is composed of one full connection layer or a plurality of sequentially connected full connection layers; it should be noted that the first state prediction model of the embodiment of the present application can also be sequentially connected by a full connection network and an activation layer; Figure 2 As shown in a module structure diagram of a first state prediction model provided for the first embodiment of the present application, the model structure of each first state prediction model of the embodiment of the present application is sequentially connected by a corresponding convolutional neural network, a full connection network and an activation layer; wherein the convolutional neural network is composed of one convolutional layer or a plurality of sequentially connected convolutional layers, and the full connection network is composed of one full connection layer or a plurality of sequentially connected full connection layers; it should be noted that the first state prediction model of the embodiment of the present application can also be sequentially connected by a full connection network and an activation layer;

[0078] Each first state prediction model of the embodiment of the application is used to obtain a corresponding single-step prediction state by performing corresponding single-step rule state prediction according to a text sequence input into the model; wherein the single-step prediction state includes an acceptable state and an unacceptable state; when the single-step prediction state is the acceptable state, it indicates that all texts in the text sequence input into the model and the text ordering manner satisfy the corresponding first condition rule, and when the single-step prediction state is the unacceptable state, it indicates that at least one sequence text or one text ordering sequence in the text sequence input into the model does not satisfy the corresponding first condition rule;

[0079] Step 12, and create a corresponding model training data set for each first condition rule to obtain a corresponding first data set;

[0080] The first data set includes a plurality of first data records; each first data record includes a first training text sequence and a first label state vector; the first training text sequence is composed of a plurality of first training texts ordered in sequence, and each first training text is a number, a symbol, a single character, a single word or a phrase; the first label state vector is composed of a plurality of first label states ordered in sequence; the first label state includes an acceptable state and an unacceptable state; and each first label state corresponds to one first training text.

[0081] Specifically, it includes the following steps: step 121, any first condition rule is recorded as a corresponding current condition rule;

[0082] Step 122, enumerate all rule items of the current condition rule to obtain a corresponding current rule item set; and perform regular expression conversion on each first rule item in the current rule item set to obtain a corresponding first regular expression; and all the obtained first regular expressions form a corresponding current expression set;

[0083] The current rule item set includes a plurality of first rule items; the current expression set includes a plurality of first regular expressions; and each first regular expression corresponds to one first rule item.

[0084] Step 123, select one type of first automaton from the multi-type automaton that is suitable for the current condition rule as a corresponding first automaton; identify the automaton type of the first automaton; if the automaton type is a deterministic finite automaton or a non-deterministic finite automaton, configure the five-tuple of the first automaton based on the current expression set; if the automaton type is a push-down automaton, configure the six-tuple of the first automaton based on the current expression set;

[0085] Wherein, the plurality of automata (Automaton) at least includes deterministic finite automata (DFA), non-deterministic finite automaton (NFA) and push down automata (PDA); the five-tuple of deterministic finite automata includes finite state set Q, finite alphabet ∑, transition function δ, start state q0 and acceptance state set F; the five-tuple of non-deterministic finite automaton includes finite state set Q, finite alphabet ∑, transition function δ, start state q start And acceptance state q accept ; The six-tuple of push down automata includes state set Q, input alphabet ∑, stack alphabet Γ, transition function δ, start state q0 and acceptance state set F; The first automaton is used for compliance state judgment on input text sequence and obtains corresponding judgment result, wherein, the judgment result includes acceptable state and unacceptable state;

[0086] Here, the automata used in the embodiments of the application are all commonly used automata, and as can be known from the technical materials disclosed by each type of automaton: under the premise of knowing a type of language rule A, the corresponding automaton A can be configured based on the type of language rule A, and after the configuration is completed, the state of whether the input text / text sequence satisfies the language rule A can be checked based on the automaton A and the corresponding judgment result is output, which includes acceptable state and unacceptable state;

[0087] Step 124, based on the text features corresponding to the current conditional rule and according to the preset first positive-negative sample ratio, corresponding positive-negative sample corpus is collected to obtain a corresponding first text corpus;

[0088] Wherein, the first positive-negative sample ratio is a pre-set ratio parameter, for example, 1:1; The first text corpus includes a plurality of first text corpora; If the first text corpus is a positive sample text corpus, it means that all texts and the ordering mode of all texts in the first text corpus satisfy the current conditional rule, if the first text corpus is a negative sample text corpus, it means that at least part of the texts or part of the text ordering sequence in the first text corpus does not satisfy the current conditional rule; The first text corpus should at least be a single sentence corpus; The positive and negative sample text corpus ratio of the first text corpus satisfies the first positive-negative sample ratio;

[0089] Step 125, performing word segmentation processing on each first text corpus to obtain corresponding molecular sequences as corresponding first training text sequences;

[0090] Step 126, take each first training text sequence as a corresponding current training text sequence; initialize a corresponding first input sequence and a first output sequence as empty; perform a round of sequential traversal on all first training texts of the current training text sequence; in the traversal process, add the currently traversed first training text to the end of the first input sequence, input the first input sequence after this addition into the corresponding first automaton to obtain a corresponding current determination result, and add the current determination result to the end of the first output sequence; and at the end of this round of traversal, take the obtained first output sequence as a corresponding first label state vector;

[0091] Step 127, compose a corresponding first data record from each first training text sequence and a corresponding first label state vector; and compose a corresponding first data set from all obtained first data records;

[0092] Step 13, train a corresponding first state prediction model based on each first data set;

[0093] Specifically, it includes: step 131, record any first data set as a corresponding current data set; record the first state prediction model corresponding to the current data set as a corresponding current state prediction model; and divide the current data set into two sub-data sets based on a pre-set first split ratio, record them as a corresponding first training set and a first evaluation set;

[0094] Wherein, the first split ratio is a pre-set ratio parameter, for example, 8:2; the first training set and the first evaluation set are both composed of multiple first data records; the ratio of the total number of records of the first training set to the total number of records of the first evaluation set meets the first split ratio;

[0095] Step 132, extract the first first data record of the first training set as a corresponding current training record;

[0096] Step 133, take the first training text sequence of the current training record as a corresponding current training text sequence; initialize a corresponding second input sequence and a second output sequence as empty; perform a round of sequential traversal on all first training texts of the current training text sequence; in the traversal process, add the currently traversed first training text to the end of the second input sequence, input the second input sequence after this addition into the current state prediction model to obtain a corresponding first single-step prediction state through a corresponding single-step rule state prediction, and add the first single-step prediction state to the end of the second output sequence; and at the end of this round of traversal, take the obtained second output sequence as a corresponding first prediction state vector;

[0097] Here, the expression of the single-step rule state prediction of the current state prediction model is: s = F con (Y2; β); wherein, F con() is a single-step rule state prediction function expression of the current state prediction model, Y2 is a second input sequence, β is a model parameter of the current state prediction model, s is a first single-step prediction state, and the first single-step prediction state s includes an acceptable state and an unacceptable state;

[0098] The first prediction state vector is sequentially ordered by a plurality of first single-step prediction states s; and the first single-step prediction state s is one-to-one corresponding to the first training text;

[0099] In step 134, the first prediction state vector and the first label state vector of the current training record are brought into a preset first model loss function; and based on a preset first model optimizer, a round of optimization is performed on the model parameter β of the current state prediction model in a direction of minimizing the first model loss function;

[0100] The first model loss function includes an L1 loss function, an L2 loss function and a cross-entropy loss function; and the first model optimizer at least includes an SGD optimizer and an ADAM optimizer.

[0101] In step 135, whether the current training record is the last first data record of the first training set is identified; if yes, step 136 is entered; and if no, the next first data record of the first training set is extracted as a new current training record and step 133 is returned.

[0102] In step 136, all first data records of the first evaluation set are traversed in a round; and in the round of traversal, the current traversed first data record is taken as a corresponding current evaluation record; and a third input sequence and a third output sequence are initialized as empty; and all first training texts of the first training text sequence of the current evaluation record are sequentially polled; and in the polling process, the current polled first training text is added to the end of the third input sequence, and the third input sequence after the addition is input into the current state prediction model to obtain a corresponding second single-step prediction state, which is added to the end of the third output sequence; and at the end of the polling, the obtained third output sequence is taken as a corresponding second prediction state vector; and the second prediction state vector and the first label state vector of the current evaluation record form a corresponding first prediction-label pair; and at the end of the round of traversal, a first confusion matrix is obtained according to all first prediction-label pairs; and based on the first confusion matrix, a first accuracy, a first precision, a first recall and a first F1 score are calculated to obtain a corresponding first accuracy, a first precision, a first recall and a first F1 score.

[0103] Step 137, the first accuracy, the first precision, the first recall and the first F1 score are identified; if the first accuracy does not meet the preset first accuracy range or the first precision does not meet the preset first precision range or the first recall does not meet the preset first recall range or the first F1 score does not meet the preset first F1 score range, return to step 132 for continuous training; if the first accuracy meets the first accuracy range, the first precision meets the first precision range, the first recall meets the first recall range and the first F1 score meets the first F1 score range, stop training and confirm that the current state prediction model training is completed.

[0104] Here, the first accuracy range, the first precision range, the first recall range and the first F1 score range are four pre-set numerical range parameters.

[0105] Step 2, any type of large language model based on the Transformer architecture is realized and has completed pre-training and fine-tuning, and is denoted as the corresponding first large language model.

[0106] Here, the first large language model of the embodiment of the application at least includes GPT series models, BERT series models, T5 series models, etc. The first large language model is used to understand the natural language features of the model input text and perform corresponding text generation processing based on the understanding features and output corresponding model generated text.

[0107] As Figure 3 As shown in the module structure diagram of the first and second large language models provided for the embodiment of the application, the core model components of the first large language model include a first encoding module and a first decoding module; the connection relationship of the core model components is that the input end of the first encoding module is connected with the model input end, and the output end is connected with the coding feature input end of the first decoding module; the output end of the first decoding module is connected with the model output end.

[0108] The component information of the core model components of the first large language model is as follows:

[0109] 1) The first encoding module is realized based on the encoder structure of the Transformer model or based on another type of deep learning model for feature coding;

[0110] The first encoding module is used to perform word segmentation processing on the model input text to obtain a corresponding word segmentation sequence; and perform feature coding processing on the obtained word segmentation sequence to obtain a corresponding coding vector X and send it to the first decoding module;

[0111] 2) The first decoding module is realized based on the decoder structure of the Transformer model or based on another type of text generator model for feature decoding and text generation;

[0112] The first decoding module is configured to set a single-step index t = 1 at an initial moment of receiving the encoding vector X, set an initial character y0 corresponding to the preset starting character, and initialize a previous-step generated sequence Y as {y0}; and when the single-step index t changes every time, perform a single-step text generation processing based on the encoding vector X, the single-step index t, and the corresponding previous-step generated sequence Y to obtain a single-step generated text y t corresponding to the preset ending character; if the single-step generated text y t does not match the preset ending character, add the single-step generated text y t to the end of the previous-step generated sequence Y {y0, y1, … y t} to obtain a reset previous-step generated sequence Y {y0, y1, … y t-1}, add 1 to the single-step index t, and continue to perform a next single-step text generation processing based on the encoding vector X, the new single-step index t, and the previous-step generated sequence Y; if the single-step generated text y t-1 matches the preset ending character, remove the initial character y0 from the previous-step generated sequence Y {y0, y1, … y t} to obtain a reset previous-step generated sequence Y {y1, … y t}, and output the previous-step generated sequence Y {y1, … y t-1} as a corresponding model generated text. t-1 t-1

[0113] The expression of the single-step text generation processing of the first decoding module is as follows:

[0114] y t = F dec (Y, X; θ).

[0115] F dec () is a function expression of the single-step text generation processing, Y is the previous-step generated sequence, X is the encoding feature output by the first encoding module, θ is a model parameter of the first decoding module, and y t is the single-step generated text generated at the t-th step.

[0116] To intuitively understand the text generation processing flow realized by the first decoding module, the embodiment of the present application provides a flowchart of a text generation processing flow of a first large language model. Figure 4 The flowchart of the text generation processing flow of the first large language model is used to illustrate the above-mentioned text generation processing flow.

[0117] ​​Step 3, selecting one or more first conditional rules from the first conditional rule set to form a corresponding current rule set; and constructing a corresponding multi-rule state prediction model based on all first state prediction models corresponding to the current rule set; and adding the multi-rule state prediction model and the constraint decoding control module to the first large language model to form a corresponding second large language model;

[0118] Specifically, step 31, selecting one or more first conditional rules from the first conditional rule set to form a corresponding current rule set;

[0119] Step 32, and constructing a corresponding multi-rule state prediction model based on all first state prediction models corresponding to the current rule set; and adding the multi-rule state prediction model and the constraint decoding control module to the first large language model to form a corresponding second large language model.

[0120] Here, the second large language model of the embodiment of the application is used to understand the natural language features of the model input text and perform corresponding constraint text generation processing based on the understood features and output corresponding model generated text.

[0121] As shown in Figure 3 The core model components of the second large language model include a first encoding module, a first decoding module, a multi-rule state prediction model, and a constraint decoding control module. The connection relationship of the core model components is as follows: the input end of the first encoding module is connected with the model input end, and the output end is connected with the first input end of the first decoding module; the single-step decoding output end of the first decoding module is connected with the input end of the multi-rule state prediction model; the output end of the multi-rule state prediction model is connected with the input end of the constraint decoding control module; the first output end of the constraint decoding control module is connected with the second input end of the first decoding module, and the second output end is connected with the model output end.

[0122] The component information of the core model components of the second large language model is as follows:

[0123] 1) The first encoding module is used to perform word segmentation processing on the model input text to obtain a corresponding word segmentation sequence; and perform feature encoding processing on the obtained word segmentation sequence to obtain a corresponding encoding vector X, which is sent to the first decoding module;

[0124] 2) The first decoding module is used to set the single-step index t = 1 at the initial moment of receiving the encoding vector X, and initialize the previous step generation sequence Y as {y0}; and each time the single-step index t changes, perform a single-step text generation processing based on the encoding vector X, the single-step index t, and the corresponding previous step generation sequence Y to obtain a corresponding single-step generated text y t to the multi-rule state prediction model;

[0125] 3) the multi-rule state prediction model is composed of a sequence splicing module, one or more parallel first state prediction models, and a multi-rule state fusion module; wherein the input end of the sequence splicing module is connected with the input end of the multi-rule state prediction model, and the output end is connected with the input end of each first state prediction model; the output end of each first state prediction model is connected with an input end of the multi-rule state fusion module; the output end of the multi-rule state fusion module is connected with the output end of the multi-rule state prediction model;

[0126] The multi-rule state prediction model is used to add the received single-step generated text y t to the end of the previous step generated sequence y t {y0, y1, … y t-1} to form a corresponding current generated sequence y t {y0, … y t-1} to each first state prediction model; and each first state prediction model performs corresponding single-step rule state prediction according to the current generated sequence y t {y0, y1, … y i,t} to obtain a corresponding single-step predicted state s i,t , 1≤rule index i≤total number of rules N, and the total number of rules N is the total number of first state prediction models; and the multi-rule state fusion module forms a corresponding single-step state vector S t from the N single-step predicted states s i,t and sends it to the constraint decoding control module;

[0127] Here, the expression of the single-step rule state prediction of each first state prediction model is: s con,i i = F t ({y0, … y i}; β con,i ); wherein F i () is the single-step rule state prediction function expression of the i-th first state prediction model, β i,t is the model parameter of the i-th first state prediction model, and the single-step predicted state s t includes acceptable states and unacceptable states;

[0128] 4) The constraint decoding control module is used to calculate the vector difference modulus of the current received single-step state vector S t and the preset label state vector S tag to obtain a corresponding first modulus value a = |S t -S tag |; and identify whether the first modulus value a is zero;

[0129] If the first modulus a is not zero, the objective function is set as and based on the preset second model optimizer, the model parameters θ of the first decoding module are fine-tuned in a direction of minimizing the objective function, and the single-step generated text y t-1 is removed from the previous step generated sequence Y {y0, y1, … y t-1} to obtain the reset previous step generated sequence Y {y1, … y t-2}, and the single-step index t is reduced by 1, and the next single-step text generation processing is continued based on the encoding vector X, the new single-step index t and the previous step generated sequence Y.

[0130] If the first modulus a is zero, whether the single-step generated text y t matches the preset end symbol is identified; if the single-step generated text y t does not match the preset end symbol, the single-step generated text y t is added to the end of the previous step generated sequence Y {y0, y1, … y t-1} to obtain the reset previous step generated sequence Y {y0, y1, … y t-1 , y t}, and the single-step index t is increased by 1, and the next single-step text generation processing is continued based on the encoding vector X, the new single-step index t and the previous step generated sequence Y; if the single-step generated text y t matches the preset end symbol, the initial character y0 is removed from the previous step generated sequence Y {y0, y1, … y t-1} to obtain the reset previous step generated sequence Y {y1, … y t-1}, and the previous step generated sequence Y {y1, … y t-1} is taken as the corresponding model generated text and output.

[0131] Wherein, the label state vector S tag is a pre-set vector parameter, the vector length of the label state vector S tag is consistent with the vector length of the single-step state vector S t , and is sequentially sorted by N single-step label states s tag,i , the single-step label state s tag,i corresponds to the single-step predicted state s i,t by index i, and each single-step label state s tag,i is an acceptable state; the second model optimizer at least includes an SGD optimizer and an ADAM optimizer.

[0132] To intuitively understand the constraint text generation process linked by the first decoding module, the multi-rule state prediction model and the constraint decoding control module, embodiments of the present application show and describe the process of the constraint text generation process of the second large language model provided for the first embodiment of the present application through Figure 5 The flowchart of the constraint text generation process of the second large language model provided for the first embodiment of the present application is shown and described.

[0133] By comparing Figure 4 , Figure 5 It can be clearly seen that: the first embodiment of the present application does not modify the first encoding module of the first large language model or substantially modify the first decoding module. Only by embedding two removable components (multi-rule state prediction model and constraint decoding control module), the conditional compliance of each step output of the first decoding module is checked. If the check passes, the first decoding module is prompted to perform t+1 step text generation processing. If the check does not pass, the decoding strategy of the first decoding module is fine-tuned by a small-scale fine-tuning of the first decoding module, and the first decoding module is prompted to re-generate the t step text. It should be noted that the first embodiment of the present application can also set an error checking threshold, and the number of consecutive re-generations of each t step text is counted. If the number of consecutive re-generations exceeds the error checking threshold, the first decoding module is prompted to back to t-1 step to re-generate the t-1 step text. This not only reduces the probability of overfitting of the model, but also indirectly improves the diversity of the generated text.

[0134] Step 4, based on the second large language model, the corresponding constraint text generation process is performed according to the user input text, and the corresponding constraint generated text is output to the user as feedback.

[0135] Here, from the function description of the second large language model in the above, it can be known that using the second large language model can perform corresponding text generation processing based on the user's input text and can perform conditional constraint processing on the generated text. The constraint generated text obtained by the second large language model has greater compliance than the generated text output by the first large language model.

[0136] Figure 6 The module structure diagram of the processing device of the large language model with introduced conditional constraints provided for the second embodiment of the present application. The device is a terminal device or a server for implementing the foregoing method embodiments, or a device capable of enabling the foregoing terminal device or server to implement the foregoing method embodiments, such as a device or chip system of the foregoing terminal device or server. As shown in the figure, the device includes a state prediction model preparation module 201, a large language model selection module 202, a large language model modification module 203 and a modified model application module 204. Figure 6

[0137] ​The state prediction model preparation module 201 is configured to customize a corresponding first state prediction model for each first condition rule in a preset first condition rule set, create a corresponding model training data set for each first condition rule to obtain a corresponding first data set, and train the corresponding first state prediction model based on each first data set, wherein the first condition rule set includes a plurality of first condition rules, the rule type of the first condition rule includes at least a semantic rule, a syntax rule, an emotion rule, and a formatted expression rule, each first state prediction model is sequentially connected by a corresponding convolutional neural network, a full connection network, and an activation layer, the convolutional neural network is composed of one convolutional layer or a plurality of sequentially connected convolutional layers, the full connection network is composed of one full connection layer or a plurality of sequentially connected full connection layers, each first state prediction model is configured to perform corresponding single-step rule state prediction to obtain a corresponding single-step prediction state according to a text sequence input by the model, and the single-step prediction state includes an acceptable state and an unacceptable state.

[0138] The large language model selection module 202 is configured to record any type of large language model based on a Transformer architecture and having completed pre-training and fine-tuning as a corresponding first large language model.

[0139] The large language model modification module 203 is configured to select one or more first condition rules from the first condition rule set to form a corresponding current rule set, construct a corresponding multi-rule state prediction model based on all first state prediction models corresponding to the current rule set, and increase the multi-rule state prediction model and a constraint decoding control module on the basis of the first large language model to form a corresponding second large language model.

[0140] The modified model application module 204 is configured to perform corresponding constraint text generation processing based on the second large language model according to a user input text and output corresponding constraint generation text to feedback to the user.

[0141] The processing device of the large language model with introduced condition constraints provided by the embodiment of the application can perform the method steps in the method embodiment, and the implementation principle and technical effects are similar, which will not be described here.

[0142] It should be noted that the division of each module of the above apparatus is only a logical function division, and all or part of them can be integrated into a physical entity or physically separated when actually implemented. These modules can all be implemented in the form of software called by a processing element; all can be implemented in the form of hardware; or part of the modules can be implemented in the form of software called by a processing element, and part of the modules can be implemented in the form of hardware. For example, the state prediction model preparation module can be a separately set processing element, or can be integrated in a chip of the above apparatus, in addition, it can also be stored in the form of program code in the memory of the above apparatus, and the function of the above determination module is called and executed by a processing element of the above apparatus. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together or independently implemented. The processing element described herein can be an integrated circuit with signal processing capability. In the implementation process, each step of the above method or each module can be completed by integrated logic circuit of hardware in the processor element or instruction in the form of software.

[0143] For example, the above modules can be one or more integrated circuits configured to implement the above method, such as one or more application specific integrated circuits (ASICs), or one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs), etc. For another example, when a certain module above is implemented in the form of program code called by a processing element, the processing element can be a general purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules can be integrated together to implement in the form of system on a chip (SOC).

[0144] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed by a computer, all or part of the computer program instructions generate the processes or functions described in the foregoing method embodiments. The computer can be a general purpose computer, a special purpose computer, a computer network or other programmable apparatus. The computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transferred from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (Digital Subscriber Line, DSL)) or wireless (such as infrared, wireless, Bluetooth, microwave, etc.) mode. The computer readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media sets. The available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, solid state disk (solid state disk, SSD)) and the like.

[0145] Figure 7 A structural schematic diagram of an electronic device is provided for the third embodiment of the present application. The electronic device can be a terminal device or a server for implementing the method of the foregoing embodiments, or a terminal device or a server connected with the foregoing terminal device or server for implementing the method of the foregoing embodiments. As shown in the figure, the electronic device can include a processor 301 (such as a CPU), a memory 302, a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transceiving action of the transceiver 303. The memory 302 can store various instructions for completing various processing functions and implementing the processing steps described in the foregoing embodiment methods. Preferably, the electronic device related to the embodiments of the present application further includes a power supply 304, a system bus 305 and a communication port 306. The system bus 305 is used to realize the communication connection between elements. The communication port 306 is used for the connection and communication between the electronic device and other external devices. Figure 7

[0146] In Figure 7 ​The system bus 305 mentioned above 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 the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus. The communication interface is used to realize the communication between the database access device and other devices (such as a client, a read-write library and a read-only library). The memory can include a Random Access Memory (RAM), and can also include a Non-Volatile Memory, such as at least one disk memory.

[0147] The processor mentioned above can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), a Graphics Processing Unit (GPU), etc.; 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 gate or transistor logic devices, discrete hardware components.

[0148] It should be noted that the embodiments of the present application also provide a computer readable storage medium, which stores instructions, and when the instructions run on a computer, the computer executes the method and process provided in the above embodiments.

[0149] The embodiment of the present application provides a processing method and device of a large language model with introduced conditional constraints, an electronic device and a computer readable storage medium. According to the above content, the embodiment of the present application pre-customizes a rule detection state prediction model, that is, a first state prediction model, for each type of conditional rule and trains the same; then, any type of large language model based on a Transformer architecture and having completed pre-training and fine-tuning is recorded as a first large language model, and one or more first state prediction models corresponding to known conditional rules are selected to construct a corresponding multi-rule state prediction model, and a multi-rule state prediction model and a constraint decoding control module are added to the first large language model to form a constraint text generation model capable of performing conditional constraints on each step of generated text in a single-step detection manner, that is, a second large language model; and based on the second large language model, corresponding constraint text generation processing is performed according to user input text, and corresponding constraint generated text is output to the user for feedback. The second large language model designed by the embodiment of the present application has a single-step text constraint capability, and the corresponding computational amount is effectively reduced compared with a conventional post-processing mechanism, and the corresponding timeliness is effectively improved compared with the conventional post-processing mechanism. The second large language model designed by the embodiment of the present application does not need to modify the encoding / decoding components of the large language model, and only needs to dynamically replace / add / remove the first state prediction model in the multi-rule state prediction model when switching conditional rules, without the need for secondary pre-training or secondary directional fine-tuning of the model. Through the embodiment of the present application, the design complexity of the model is reduced, the model training cost is saved, the adaptation flexibility of the model to rules is improved, and the computational amount of the model is reduced, and the timeliness of the model task processing is improved.

[0150] The steps of a method or algorithm described in connection with the embodiments disclosed herein can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in random access memory (RAM), flash memory, read-only memory (ROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0151] The above specific embodiments further illustrate the purpose, technical solutions and beneficial effects of the present application. It should be understood that the above description is only a specific embodiment of the present application and is not used to limit the protection scope of the present application, and any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims

1. A processing method of a large language model with introduced conditional constraints, characterized in that, The method comprises: Step 1, customizing a corresponding first state prediction model for each first condition rule in a preset first condition rule set; creating a corresponding model training data set for each first condition rule to obtain a corresponding first data set; and training the corresponding first state prediction model based on each first data set; Wherein, the first condition rule set comprises a plurality of first condition rules; the rule type of the first condition rule comprises at least semantic rules, syntax rules, sentiment rules, and formatted expression rules; each first state prediction model is sequentially connected by a corresponding convolutional neural network, a fully connected network, and an activation layer, the convolutional neural network is composed of one convolutional layer or multiple sequentially connected convolutional layers, and the fully connected network is composed of one fully connected layer or multiple sequentially connected fully connected layers; each first state prediction model is used to perform corresponding single-step rule state prediction according to the input text sequence of the model to obtain a corresponding single-step prediction state; the single-step prediction state comprises an acceptable state and an unacceptable state; Step 2, any large language model based on the Transformer architecture and having completed pre-training and fine-tuning is recorded as a corresponding first large language model; Step 3, one or more first condition rules are selected from the first condition rule set to form a corresponding current rule set; a corresponding multi-rule state prediction model is constructed based on all first state prediction models corresponding to the current rule set; and the multi-rule state prediction model and the constraint decoding control module are added to the first large language model to form a corresponding second large language model; Step 4, based on the second large language model, corresponding constraint text generation processing is performed according to user input text, and corresponding constraint generated text is output to the user for feedback.

2. The processing method of the large language model with introduced condition constraints according to claim 1, characterized in that: The first data set comprises a plurality of first data records; the first data record comprises a first training text sequence and a first label state vector; the first training text sequence is sequentially sorted by a plurality of first training texts, and the first training text is a number, a symbol, a single character, a single word, or a phrase; the first label state vector is sequentially sorted by a plurality of first label states; the first label state comprises an acceptable state and an unacceptable state; and the first label state corresponds to the first training text one by one.

3. The processing method of claim 2, wherein, The first data set is obtained by creating a corresponding model training data set for each first condition rule, specifically comprising: Step 31, recording any first condition rule as a corresponding current condition rule; Step 32, enumerating all rule items of the current condition rule to obtain a corresponding current rule item set; performing regular expression conversion on each first rule item of the current rule item set to obtain a corresponding first regular expression; and composing a corresponding current expression set from all obtained first regular expressions; The current rule item set includes a plurality of the first rule items; the current expression set includes a plurality of the first regular expressions; the first regular expression corresponds to the first rule item one by one; Step 33, selecting a type of the multi-type automaton that is adapted to the current conditional rule as a corresponding first automaton, and identifying the automaton type of the first automaton; if the automaton type is a deterministic finite automaton or a non-deterministic finite automaton, configuring the quintuple of the first automaton based on the current expression set; if the automaton type is a pushdown automaton, configuring the sextuple of the first automaton based on the current expression set; The multiple types of automata include at least deterministic finite automata, non-deterministic finite automata and pushdown automata; the five-tuple of the deterministic finite automata includes a finite state set Q, a finite alphabet ∑, a transition function δ, a starting state q0 and an accepting state set F; the five-tuple of the non-deterministic finite automata includes a finite state set Q, a finite alphabet ∑, a transition function δ, a starting state q0 and an accepting state set F. start and accept state q accept The six-tuple of the pushdown automaton includes a state set Q, an input alphabet ∑, a stack alphabet Γ, a transition function δ, a starting state q0, and an acceptance state set F; the first automaton is used to determine the compliance state of the input text sequence and obtain a corresponding determination result; the determination result includes an acceptable state and an unacceptable state; Step 34, based on the text features corresponding to the current conditional rule, and according to a preset first positive and negative sample ratio, collecting corresponding positive and negative sample corpora to obtain a corresponding first text corpus; The first text corpus includes a plurality of first text corpora; the first text corpus at least includes one single sentence corpus; the ratio of positive and negative sample text corpora of the first text corpus meets the first positive and negative sample ratio; Step 35, performing word segmentation processing on each first text corpus to obtain a corresponding molecular sequence as a corresponding first training text sequence; Step 36, taking each first training text sequence as a corresponding current training text sequence; initializing a corresponding first input sequence and a first output sequence as empty; performing one round of sequential traversal on all first training texts of the current training text sequence; in the traversal process, adding the first training text currently traversed to the end of the first input sequence, inputting the first input sequence after this addition into the corresponding first automaton to perform compliance state judgment and obtaining a corresponding current judgment result added to the end of the first output sequence; and at the end of this round of traversal, taking the obtained first output sequence as a corresponding first label state vector; Step 37, each first training text sequence and the corresponding first label state vector form a corresponding first data record; and all obtained first data records form a corresponding first data set.

4. The processing method of claim 2, wherein, The first state prediction model is trained based on each first data set, and specifically includes: Step 41, taking any first data set as a corresponding current data set; taking the first state prediction model corresponding to the current data set as a corresponding current state prediction model; and based on a preset first segmentation ratio, the current data set is segmented into two sub-data sets, which are taken as a corresponding first training set and a first evaluation set; The first training set and the first evaluation set both include a plurality of first data records; the ratio of the total number of records of the first training set to the total number of records of the first evaluation set meets the first segmentation ratio; Step 42, extracting the first first data record of the first training set as a corresponding current training record; Step 43, taking the first training text sequence of the current training record as a corresponding current training text sequence; initializing a corresponding second input sequence and a second output sequence as empty; performing a round of sequential traversal on all the first training texts of the current training text sequence; in the traversal process, adding the first training text being currently traversed to the end of the second input sequence, inputting the second input sequence after the addition into the current state prediction model to obtain a corresponding first single-step prediction state through a corresponding single-step rule state prediction, and adding the first single-step prediction state to the end of the second output sequence; and at the end of the round of traversal, taking the obtained second output sequence as a corresponding first prediction state vector; wherein the expression of the single-step rule state prediction of the current state prediction model is: s = F con (Y2; β), F con Y2 = f (s, β) is a single-step rule state prediction function expression of the current state prediction model, Y2 is the second input sequence, β is a model parameter of the current state prediction model, s is the first single-step prediction state, the first single-step prediction state s includes an acceptable state and an unacceptable state; The first prediction state vector is sequentially sorted by a plurality of first single-step prediction states s; the first single-step prediction state s corresponds to the first training text one by one; Step 44, taking the first prediction state vector and the first label state vector of the current training record into a pre-set first model loss function; and based on a pre-set first model optimizer, performing a round of optimization on the model parameters β of the current state prediction model in the direction of making the first model loss function reach a minimum value; wherein the first model loss function includes an L1 loss function, an L2 loss function and a cross-entropy loss function; and the first model optimizer at least includes an SGD optimizer and an ADAM optimizer; Step 45, identifying whether the current training record is the last first data record of the first training set; if yes, going to step 46; if no, extracting the next first data record of the first training set as a new current training record and returning to step 43; Step 46, a round of traversal is performed on all the first data records of the first evaluation set; during the round of traversal, the first data record currently traversed is taken as a corresponding current evaluation record; a third input sequence and a third output sequence are initialized as empty; all the first training texts of the first training text sequence of the current evaluation record are sequentially polled; during polling, the first training text currently polled is added to the end of the third input sequence, and the third input sequence after the addition is input into the current state prediction model to obtain a corresponding second single-step prediction state by corresponding single-step rule state prediction, and the second single-step prediction state is added to the end of the third output sequence; at the end of polling, the third output sequence obtained is taken as a corresponding second prediction state vector; a corresponding first prediction-label pair is formed by the second prediction state vector and the first label state vector of the current evaluation record; at the end of the round of traversal, a first confusion matrix is constructed according to all the first prediction-label pairs obtained, and a first accuracy, a first precision, a first recall and a first F1 score are calculated based on the first confusion matrix to obtain a corresponding first accuracy, a first precision, a first recall and a first F1 score; Step 47, the first accuracy, the first precision, the first recall and the first F1 score are identified; if the first accuracy does not satisfy a preset first accuracy range or the first precision does not satisfy a preset first precision range or the first recall does not satisfy a preset first recall range or the first F1 score does not satisfy a preset first F1 score range, the method returns to step 42 for continuous training; if the first accuracy satisfies the first accuracy range, the first precision satisfies the first precision range, the first recall satisfies the first recall range and the first F1 score satisfies the first F1 score range, the method stops training and confirms that the current state prediction model training is completed.

5. The processing method of the large language model with introduced conditional constraints according to claim 1, characterized in that, the first large language model is used to understand the natural language features of the model input text and perform corresponding text generation processing based on the understanding features and output corresponding model generated text; the first large language model comprises a first encoding module and a first decoding module; in the first large language model, the input end of the first encoding module is connected with the model input end, the output end is connected with the encoding feature input end of the first decoding module, the output end of the first decoding module is connected with the model output end. In the first large language model, the first encoding module is implemented based on an encoder structure of a Transformer model or based on another type of deep learning model for feature encoding; the first encoding module is configured to perform word segmentation processing on the model input text to obtain a corresponding word segmentation sequence; and perform feature encoding processing on the obtained word segmentation sequence to obtain a corresponding encoding vector X, which is sent to the first decoding module; In the first large language model, the first decoding module is implemented based on a decoder structure of a Transformer model or based on another type of text generator model for feature decoding and text generation; In the first large language model, the first decoding module is configured to set a single-step index t = 1 at an initial moment of receiving the encoding vector X, set an initial character y0 corresponding to the preset starting character, and initialize a previous step generation sequence Y as {y0}; and each time the single-step index t changes, the single-step text generation processing is performed based on the encoding vector X, the single-step index t and the previous step generation sequence Y to obtain a corresponding single-step generated text y t ; and whether the single-step generated text y t matches a preset end symbol is identified; if the single-step generated text y t does not match the preset end symbol, the single-step generated text y t is added to the end of the previous step generation sequence Y {y0, y1, … y t-1} to obtain a reset previous step generation sequence Y {y0, y1, … y t-1 , y t}, the single-step index t is incremented by 1, and the next single-step text generation processing is continued based on the encoding vector X, the new single-step index t and the previous step generation sequence Y; if the single-step generated text y t matches the preset end symbol, the initial character y0 is removed from the previous step generation sequence Y {y0, y1, … y t-1} to obtain a reset previous step generation sequence Y {y1, … y t-1}, and the previous step generation sequence Y {y1, … y t-1} is taken as a corresponding model generated text and output. The expression of the single-step text generation process of the first decoding module is: y t = F dec (Y, X; θ), wherein F dec () is a function expression of the single-step text generation process, Y is a previous step generation sequence, X is an encoding feature output by the first encoding module, θ is a model parameter of the first decoding module, and y t is a single-step generated text of the tth step.

6. The processing method of the large language model with introduced condition constraints according to claim 5, characterized in that, The second large language model is configured to understand natural language features of the model input text and perform corresponding constraint text generation processing based on the understood features and output corresponding model generated text; The second large language model comprises the first encoding module, the first decoding module, the multi-rule state prediction model, and the constraint decoding control module; In the second large language model, the input end of the first encoding module is connected with the model input end, and the output end is connected with the first input end of the first decoding module; the single-step decoding output end of the first decoding module is connected with the input end of the multi-rule state prediction model; the output end of the multi-rule state prediction model is connected with the input end of the constraint decoding control module; the first output end of the constraint decoding control module is connected with the second input end of the first decoding module, and the second output end is connected with the model output end; In the second large language model, the first encoding module is configured to perform word segmentation processing on the model input text to obtain a corresponding word segmentation sequence; and perform feature encoding processing on the obtained word segmentation sequence to obtain a corresponding encoding vector X, which is sent to the first decoding module; In the second large language model, the first decoding module is configured to set a single-step index t = 1 at an initial moment when the encoded vector X is received, and initialize a previous step generation sequence Y as {y0}; and each time the single-step index t changes, perform a single-step text generation process based on the encoded vector X, the single-step index t, and the corresponding previous step generation sequence Y to obtain a corresponding single-step generated text y t sending to the multi-rule state prediction model; In the second large language model, the multi-rule state prediction model comprises a sequence splicing module, one or more parallel first state prediction models, and a multi-rule state fusion module; the input end of the sequence splicing module is connected with the input end of the multi-rule state prediction model, and the output end is connected with the input end of each first state prediction model; the output end of each first state prediction model is connected with one input end of the multi-rule state fusion module; the output end of the multi-rule state fusion module is connected with the output end of the multi-rule state prediction model; In the second language model, the multi-rule state prediction model is used to generate the text y in each step. t When the sequence splicing module receives the single-step generated text y t Add to the previous step to generate the sequence Y{y0,y1,…y t-1 } at the end of the corresponding current generated sequence {y0,…y t } is sent to each of the first state prediction models; and each of the first state prediction models generates a sequence {y0, y1, ... y t-1 ,y t } Perform the corresponding single-step rule state prediction to obtain the corresponding single-step prediction state s i,t Send to the multi-rule state fusion module, 1≤ rule index i≤ total number of rules N, the total number of rules N is the total number of the first state prediction model; and the multi-rule state fusion module will obtain N single-step prediction states s i,t Form a corresponding single-step state vector S t Sending to the constraint decoding control module; The expression of the single-step rule state prediction corresponding to each of the first state prediction models is: i,t = F con,i t ; β i ), wherein F con,i () is a single-step rule state prediction function expression of the i-th first state prediction model, β i is a model parameter of the i-th first state prediction model, and the single-step prediction state s i,t includes an acceptable state and an unacceptable state.​ In the second large language model, the constraint decoding control module is configured to, upon receiving each single-step state vector S t , calculate the vector difference between the currently received single-step state vector S t and a preset label state vector S tag to obtain a corresponding first modulus value a = |S t -S tag |, and identify whether the first modulus value a is zero. If the first modulus value a is not zero, then the objective function is set to Based on the preset second model optimizer, the model parameter θ of the first decoding module is fine-tuned in the direction of minimizing the objective function, and at the end of this round of fine-tuning, the single-step generated text y generated in the previous step t-1 is converted to t-1 Generate a sequence Y{y0,y1,…y t-1 } remove the reset sequence Y{y1,…y t-2 }, and decrement the single-step index t by 1, and continue to perform the next single-step text generation process based on the encoding vector X, the new single-step index t and the previous step generation sequence Y; the second model optimizer includes at least an SGD optimizer and an ADAM optimizer; If the first modulus a is zero, the single-step generated text y t is identified whether it matches a preset ending symbol; if the single-step generated text y t does not match the preset ending symbol, the single-step generated text y t is added to the end of the previous step generated sequence Y{y0, y1, … y t-1} to obtain a reset previous step generated sequence Y{y0, y1, … y t-1 ,y t}, the single-step index t is added by 1, and the next single-step text generation processing is continued based on the encoding vector X, the new single-step index t, and the previous step generated sequence Y; if the single-step generated text y t matches the preset ending symbol, the initial character y0 is removed from the previous step generated sequence Y{y0, y1, … y t-1} to obtain a reset previous step generated sequence Y{y1, … y t-1}, and the previous step generated sequence Y{y1, … y t-1} is taken as the corresponding model generated text and output.

7. An apparatus for performing the processing method of the large language model with the introduction condition constraint of any one of claims 1-6, characterized in that, The device comprises a state prediction model preparation module, a large language model selection module, a large language model modification module, and a modified model application module. The state prediction model preparation module is configured to customize a corresponding first state prediction model for each first condition rule in a preset first condition rule set, create a corresponding model training data set for each first condition rule to obtain a corresponding first data set, and train the corresponding first state prediction model based on each first data set. The first condition rule set includes a plurality of first condition rules. The rule types of the first condition rules include at least semantic rules, syntax rules, sentiment rules, and formatted expression rules. Each first state prediction model is sequentially connected by a corresponding convolutional neural network, a full connection network, and an activation layer. The convolutional neural network is composed of one convolutional layer or multiple sequentially connected convolutional layers. The full connection network is composed of one full connection layer or multiple sequentially connected full connection layers. Each first state prediction model is configured to perform corresponding single-step rule state prediction to obtain a corresponding single-step prediction state according to a model input text sequence. The single-step prediction state includes an acceptable state and an unacceptable state. The large language model selection module is configured to record any type of large language model based on a Transformer architecture and having completed pre-training and fine-tuning as a corresponding first large language model. The large language model modification module is configured to select one or more first condition rules from the first condition rule set to form a corresponding current rule set, construct a corresponding multi-rule state prediction model based on all first state prediction models corresponding to the current rule set, and increase the multi-rule state prediction model and a constraint decoding control module based on the first large language model to form a corresponding second large language model. The modified model application module is configured to perform corresponding constraint text generation processing based on the second large language model according to user input text and output corresponding constraint generated text to feedback to the user.

8. An electronic device, comprising: It includes: a memory, a processor, and a transceiver; the processor is configured to couple with the memory, read and execute instructions in the memory to implement the method of any one of claims 1-6; the transceiver is coupled with the processor, and the transceiver is controlled by the processor to perform message transmission and reception.

9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, when the computer instructions are executed by a computer, the computer executes the method of any one of claims 1-6. The computer readable storage medium stores computer instructions, when the computer instructions are executed by a computer, the computer executes the method of any one of claims 1-6.

Citation Information

Patent Citations

  • Method and device for training language model based on multiple word vectors, equipment and medium

    CN111737995A

  • Text classification method and related device

    CN112214605A