Method and system for enhancing reasoning stability of large model in text scene

By constructing a structured text knowledge graph and optimizing the large model using gradient direction consistency loss, the problem of unstable output in text extraction tasks is solved. This improves the stability and consistency of the model under semantically equivalent inputs, making it suitable for scenarios with stringent requirements for accuracy and consistency.

CN121502009APending Publication Date: 2026-02-10DIGITAL HEALTH CHINA TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511547815.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-28
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

Existing technologies struggle to achieve output stability and consistency for large models in text extraction tasks, especially in scenarios with high requirements for consistency and interpretability, such as healthcare and finance. The models' extraction results for semantically equivalent inputs vary significantly, leading to unreliable results and difficulty in practical application.

Method used

By constructing a structured text knowledge graph, using a graph attention network for dynamic text knowledge embedding, and inserting a text knowledge-gated cross-attention module into the decoder layer of a pre-trained large model, combined with gradient direction consistency loss for training, the model parameters are optimized to improve output stability.

Benefits of technology

It significantly improves the output consistency and stability of the model under semantically equivalent inputs, reduces output fluctuations, and achieves accuracy and reliability of text extraction results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121502009A_ABST
    Figure CN121502009A_ABST
Patent Text Reader

Abstract

The invention discloses a large model reasoning stability enhancement method and system in a text scene, and relates to the technical field of knowledge enhancement deep learning, and the method comprises the steps: building a structured text knowledge graph based on a text knowledge base, and generating a dynamic text knowledge embedding matrix through a graph attention network; inserting a text knowledge gating cross attention module into a decoder selection layer of the pre-trained large model, taking the text knowledge gating cross attention module as an external knowledge source, obtaining a knowledge enhanced hidden state after gating fusion, and constructing a transformation model; semantic equivalent perturbation is carried out on an input text to obtain a perturbation sample, the perturbation sample is input into the transformation model in parallel to obtain extraction probability distribution, and divergence and gradient direction consistency loss between two distributions are calculated; and combining cross entropy loss and gradient direction consistency loss to train and transform the model, and updating parameters to convergence to obtain a final large model. According to the method, the fact consistency of output can be improved, common optimization of knowledge guidance and stability constraint is realized, and the result is accurate and reliable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge-enhanced deep learning technology, and in particular to a method and system for enhancing the stability of large model inference in text scenarios. Background Technology

[0002] With the widespread application of large language models in tasks such as text understanding and information extraction, output stability has gradually become a key requirement. Especially in text extraction scenarios such as healthcare and finance, where consistency and interpretability are extremely important, models often produce significantly different extraction results for semantically equivalent inputs, leading to unreliable results and difficulty in practical application.

[0003] To address this issue, existing technologies primarily employ two approaches: first, introducing structured knowledge during the inference phase through external knowledge retrieval (such as RAG) to assist model judgment; and second, using contrastive learning or data augmentation during the training phase to enhance the model's robustness to input perturbations. Furthermore, some methods attempt to embed knowledge graphs as additional input for attention calculation, aiming to achieve knowledge guidance within the model itself.

[0004] However, the above methods have obvious drawbacks. External knowledge retrieval introduces additional latency, and knowledge is only used as a supplement to the input, unable to deeply influence the model's internal representation; contrastive learning methods lack explicit constraints on gradient behavior, causing the model to change drastically even under small perturbations; and simply introducing graph embedding is not deeply coupled with the model structure, resulting in low knowledge utilization and susceptibility to noise.

[0005] In summary, existing technologies cannot simultaneously meet the dual requirements of "knowledge internalization" and "reasoning stability." There is an urgent need for a method that deeply integrates structured knowledge into the model structure to improve the consistency and reliability of large models in text extraction tasks. Summary of the Invention

[0006] The technical problem this invention aims to solve is to address the shortcomings of existing technologies, specifically the issues of inconsistent semantically equivalent inputs and outputs and unstable inference results in large models during text extraction tasks. Specifically, it provides a method and system for enhancing the inference stability of large models in text scenarios, as detailed below: 1) In a first aspect, the present invention provides a method for enhancing the stability of large model inference in text scenarios, the specific technical solution of which is as follows: S1. Construct a structured text knowledge graph based on a text knowledge base to obtain a ternary set; based on the ternary set, use a graph attention network to encode the neighbor subgraphs of the current input text sequence to obtain a dynamic text knowledge embedding matrix. S2, insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model, use the dynamic text knowledge embedding matrix as an external knowledge source, and obtain the knowledge-enhanced hidden state after gating and fusion, thereby constructing the modified model; S3, perform semantic equivalence perturbation on the input text sequence to obtain perturbation samples, and input the text sequence as the original sample and the perturbation sample in parallel into the modified model to obtain extraction probability distributions respectively; calculate the divergence between the two extraction probability distributions, and calculate the gradient of the model parameters of the modified model to obtain the gradient direction consistency loss; S4. The modified model is trained by combining the cross-entropy loss and the gradient direction consistency loss, and the model parameters are updated until convergence is obtained to obtain the final large model, so that the output of the text extraction task is stable.

[0007] The beneficial effects of the method for enhancing the stability of large model inference in text scenarios provided by this invention are as follows: By employing triple sets and graph attention networks, structured textual knowledge is internalized as dynamic embeddings, enabling the model to reason directly along the graph path during the extraction phase, thus improving the consistency of the output facts. A gated fusion mechanism allows the model to autonomously choose whether to reference knowledge at each position, suppressing interference from irrelevant triples and enhancing robustness to input perturbations. Introducing gradient direction consistency loss ensures that the extraction results of semantically equivalent samples tend to be consistent, significantly reducing output fluctuations. Joint training with cross-entropy and gradient direction consistency loss achieves simultaneous optimization of knowledge guidance and stability constraints, resulting in text extraction results that are both accurate and reliable.

[0008] Based on the above solution, the present invention can be further improved as follows.

[0009] Furthermore, the neighbor subgraph takes the mentioned node obtained by entity linking as the center and performs 1-hop neighbor sampling within the structured text knowledge graph, and the number of nodes sampled each time does not exceed fifty; wherein, the entity comes from the triple set, and the triple set is composed of entity-attribute-attribute value triples.

[0010] Furthermore, the gating fusion is achieved in the following way: The current hidden state is obtained by passing a single-layer linear mapping and Sigmoid activation to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

[0011] Furthermore, the weight coefficient of the gradient direction consistency loss ranges from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

[0012] 2) In a second aspect, the present invention also provides a system for enhancing the stability of large model inference in text scenarios, the specific technical solution of which is as follows: a ternary construction module, a modified construction module, a gradient constraint module, and a joint training module; The ternary construction module is used to construct a structured text knowledge graph based on a text knowledge base to obtain a ternary set; based on the ternary set, a graph attention network is used to encode the neighbor subgraphs of the current input text sequence to obtain a dynamic text knowledge embedding matrix. The modified construction module is used to insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model, and use the dynamic text knowledge embedding matrix as an external knowledge source. After gating and fusion, the knowledge-enhanced hidden state is obtained, thereby constructing the modified model. The gradient constraint module is used to perform semantic equivalence perturbation on the input text sequence to obtain perturbation samples. The text sequence is then used as the original sample and the perturbation sample, which are input into the modified model in parallel to obtain extraction probability distributions. The divergence between the two extraction probability distributions is calculated, and the gradient of the model parameters of the modified model is obtained to obtain the gradient direction consistency loss. The joint training module is used to train the modified model by combining the cross-entropy loss and the gradient direction consistency loss, update the model parameters until convergence, and obtain the final large model, so that the output of the text extraction task is stable.

[0013] Based on the above solution, the present invention can be further improved as follows.

[0014] Furthermore, the neighbor subgraph takes the mentioned node obtained by entity linking as the center and performs 1-hop neighbor sampling within the structured text knowledge graph, and the number of nodes sampled each time does not exceed fifty; wherein, the entity comes from the triple set, and the triple set is composed of entity-attribute-attribute value triples.

[0015] Furthermore, the gating fusion is achieved in the following way: The current hidden state is obtained by passing a single-layer linear mapping and Sigmoid activation to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

[0016] Furthermore, the weight coefficient of the gradient direction consistency loss ranges from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

[0017] 3) In a third aspect, the present invention also provides a computer device, the computer device including a processor coupled to a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to enable the computer device to implement any of the above methods.

[0018] 4) In a fourth aspect, the present invention also provides a computer-readable storage medium storing at least one computer program, which is loaded and executed by a processor to enable a computer to implement any of the above methods.

[0019] It should be noted that the beneficial effects of the technical solutions of the second to fourth aspects of the present invention and their corresponding possible implementations can be found in the above description of the technical effects of the first aspect and its corresponding possible implementations, and will not be repeated here. Attached Figure Description

[0020] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a flowchart illustrating the steps of a method for enhancing the stability of large model inference in a text-based scenario, according to an embodiment of the present invention. Figure 2 This is a structural framework diagram of an electronic device according to the present invention. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.

[0022] like Figure 1 As shown in the figure, a method for enhancing the stability of large model inference in a text scenario according to an embodiment of the present invention includes the following steps: S1. Construct a structured text knowledge graph based on the text knowledge base to obtain a ternary set; based on the ternary set, use a graph attention network to encode the neighbor subgraphs of the current input text sequence to obtain a dynamic text knowledge embedding matrix. S2, insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model, use the dynamic text knowledge embedding matrix as an external knowledge source, and obtain the knowledge-enhanced hidden state after gating and fusion, thereby constructing the modified model; S3, perform semantic equivalence perturbation on the input text sequence to obtain perturbation samples, and input the text sequence as the original sample and the perturbation sample in parallel into the modified model to obtain extraction probability distributions respectively; calculate the divergence between the two extraction probability distributions, and calculate the gradient of the model parameters of the modified model to obtain the gradient direction consistency loss; S4 combines cross-entropy loss and gradient direction consistency loss to train and modify the model, updating the model parameters until convergence, resulting in the final large model, which stabilizes the output of the text extraction task.

[0023] The beneficial effects of the method for enhancing the stability of large model inference in text scenarios provided by this invention are as follows: By employing triple sets and graph attention networks, structured textual knowledge is internalized as dynamic embeddings, enabling the model to reason directly along the graph path during the extraction phase, thus improving the consistency of the output facts. A gated fusion mechanism allows the model to autonomously choose whether to reference knowledge at each position, suppressing interference from irrelevant triples and enhancing robustness to input perturbations. Introducing gradient direction consistency loss ensures that the extraction results of semantically equivalent samples tend to be consistent, significantly reducing output fluctuations. Joint training with cross-entropy and gradient direction consistency loss achieves simultaneous optimization of knowledge guidance and stability constraints, resulting in text extraction results that are both accurate and reliable.

[0024] It should be noted that, for ease of understanding, the technical terms used in this solution will be explained one by one, and will not be repeated hereafter: Text knowledge base: Original documents such as contracts, instructions, and domain dictionaries are used as a "text knowledge base" to generate triples.

[0025] Structured text knowledge graph: It combines (entity, attribute, attribute value) triples into the same graph, which corresponds to the most basic triple form of head entity-relation-tail entity. In this graph, node = entity (or attribute value) and edge = attribute (i.e. relation). All triples are stored in the graph database as undirected single relation edges, without adding edge attributes or nesting subgraphs.

[0026] A ternary set is a set of all rows (entity, attribute, attribute value) in the structured text knowledge graph described above.

[0027] Text sequence: comes from the training set composed of a text knowledge base, such as contracts, instructions, announcements, OCR results of scanned documents uploaded by users, etc.; Training set construction steps: randomly extract sentences or paragraphs from the text knowledge base as "input text sequence".

[0028] Neighbor subgraph: After linking entities in the input sentence, only the triples directly connected to the mentioned entities are retrieved to form a first-order subgraph. Here, as mentioned above, "node = entity," meaning the mentioned entity and the mentioned node have the same meaning.

[0029] 1-hop neighbor sampling: Starting from an entity, only the nodes and edges directly connected to it (by one edge) are extracted to form a local subgraph, without further expansion outwards.

[0030] Sigmoid: An S-shaped function that compresses any real number into a range of 0-1. It is used to generate a gating value for each token in real time, determining whether or not to reference external knowledge.

[0031] Graph Attention Network (GAT) refers to an aggregation method that, for each neighbor of the current node, first calculates a "relevance score" using a learnable attention function; then normalizes the score into weights using softmax; finally, sums the vectors of the neighbors according to the weights to obtain a new representation of the current node. In essence, it reweights the vectors of each node in the subgraph and outputs a "dynamic textual knowledge embedding matrix." It uses a learnable attention function to calculate the importance of each neighbor, then performs a weighted average to update the node vectors.

[0032] Dynamic text knowledge embedding matrix: A matrix composed of node embeddings output by GAT, which varies depending on the input sentence. In other words, the output vectors of all nodes in the subgraph are stacked row by row, with the structure [number of subgraph nodes, vector dimension], which is the "dynamic text knowledge embedding matrix".

[0033] Pre-trained large model: can be the publicly available LLaMA-2-7B, with text as input, and the weight initialization method remains unchanged, which can be preset according to experience or needs.

[0034] Decoder Selected Layers: Insert a learnable sublayer (i.e., "text knowledge gated cross attention module") into layers 8, 16, and 24 of the Transformer decoder.

[0035] The text knowledge gating cross-attention module can be broken down into three steps: Cross-attention: The input latent state is used as the query, and the external knowledge embedding is used as the key / value pair to calculate the attention weights. Gating mechanism: A 0–1 weight gate (i.e., a gating signal) is generated using a sigmoid function to automatically determine whether "this text knowledge should participate in the representation of the current token". Weighted fusion: The knowledge attention result and the original self-attention result are linearly interpolated according to the gate, and a new latent state is output.

[0036] Gated fusion: The weighted sum of bitwise text knowledge attention and standard self-attention is used to determine "whether to refer to knowledge".

[0037] Hidden state: The "intermediate vector matrix" output by each layer in the Transformer - each row corresponds to a vector representation of a token, which has not yet become the final probability.

[0038] Model modification: This refers to combining the pre-trained large model with the newly inserted "text knowledge-gated cross-attention module" and its associated parameters. The construction process is as follows: The vocabulary and most weights of the original LLaMA-2-7B large model are retained; a learnable sub-layer is added to the decoder blocks at layers 8, 16, and 24, introducing a learnable linear projection matrix with a dimension of... , The hidden layer dimension is used; the remaining layers are frozen or fully updated. The new weight file obtained after training is the "modified model", which can both understand general text and dynamically reference graph knowledge to complete stable extraction.

[0039] Semantic equivalence perturbation: paraphrasing a text sequence. Perturbation can be understood as paraphrasing, such as changing "penalty for breach of contract" to "penalty for breach of contract". The perturbation rules can be obtained from a domain thesaurus.

[0040] Perturbation samples: These are the sentences obtained by paraphrasing the above-mentioned synonyms. In other words, the text sequence refers to "natural language sentences sampled from the original documents corresponding to the text knowledge base," while perturbation samples refer to sentences obtained by paraphrasing the text sequence.

[0041] Extracting probability distributions: Modify the probability vectors output by the model for the original samples and perturbed samples, respectively, for subsequent calculations.

[0042] Divergence: Measures the difference between the two extracted probability distributions of the original sample and the perturbed sample. The larger the difference value, the greater the difference between the modified model and the training of synonyms. It is used to obtain the gradient direction consistency loss after calculating the gradient.

[0043] Gradient: Take the partial derivative of the divergence with respect to each parameter of the modified model to obtain a vector with the same dimension as the parameter. Its direction points to the update direction where the divergence increases the fastest, and its magnitude represents the rate of change.

[0044] Gradient direction consistency loss: take the square of the L2 norm of the above vector and multiply it by λ to force the gradient of the synonym pair to be as small as possible; as long as the direction is consistent and the length is shortened, the output difference between the original sample and the perturbation sample of the modified model will be compressed, thereby achieving "stable synonym extraction results".

[0045] Cross-entropy loss: The most commonly used loss function in classification tasks, used to measure the difference between the probability distribution predicted by the model and the true label. The greater the difference, the larger the loss value; the more accurate the prediction, the closer the loss is to 0. Cross-entropy is responsible for "predicting results as accurately as possible," while gradient direction consistency loss is responsible for "making the results as stable as possible when the input has small perturbations." The two are complementary. Adding the cross-entropy loss and the gradient direction consistency loss together guides the modification of model parameter updates.

[0046] In another embodiment of this solution, S1 is specifically implemented as follows: Original documents such as contracts and instructions are compiled into a text knowledge base. Regular expressions or domain-specific NER tools are used to extract "entity-attribute-attribute value" triples. After deduplication and normalization, these triples are stored in a graph database. Nodes represent entities or attribute values, and edges represent attributes, forming a structured text knowledge graph. The triple set is the set of all edges in the graph. The current input text sequence is then segmented and entity-linked to obtain the set of mentioned nodes, V. mention = {v1, v2, ..., v k}, with V mention A 1-hop neighborhood sampling is performed within the graph centered at the node, with a maximum sampling node count of 50, forming a neighborhood subgraph. The subgraph nodes are initially embedded into a two-layer graph attention network. Each layer first processes the node vector h... i and its neighbor vector h j Perform a linear transformation to obtain the transformed vector, and then calculate the attention coefficient 'a'. ij Then use a ij Update the node representation h' by weighted summation of neighbor vectors. i The new embeddings of all nodes are concatenated row by row to form a dynamic text knowledge embedding matrix E. K ∈R m×d , where m is the number of nodes in the subgraph (i.e. the number of activation triples), and d is the hidden layer dimension. This matrix changes dynamically depending on the input text.

[0047] In another embodiment of this solution, S2 is specifically implemented as follows: In the decoder of the pre-trained large model, the original self-attention sublayers are retained unchanged at layers 8, 16, and 24. Immediately following this, a text knowledge-gated cross-attention module is inserted: the current layer's hidden state matrix H is used as the query, and the dynamic text knowledge embedding matrix E... K Using the key and value, standard dot product attention is performed to obtain the attention weight matrix, calculated as follows: ; Among them, the The input hidden state matrix of the Transformer layer, dimension , For sequence length, For hidden layer dimensions, To add a learnable linear projection matrix, dimension ; Embedding matrix for dynamic text knowledge, dimensions , To activate the number of triples; The scaling factor dimension is usually equal to ; This is the normalized dot product attention score; To output the attention weight matrix, the dimension is... Then, 0–1 weights are generated through gating fusion, as shown in the following formula: ; in, , For the Sigmoid function, , , and To add a new one-dimensional linear parameter, For the learnable weight matrix in gated fusion, the current hidden state is... The linear mapping is converted to logits, and then the Sigmoid function is used to obtain the 0–1 gate value Gate. This is a learnable bias vector in gated fusion, responsible for shifting the overall gate logits to ensure that the mean Gate value is close to 0.5 in the initial stage of the model and can freely converge to 0 or 1 after training. The gate value is applied bit by bit to the knowledge attention result, and then linearly interpolated with the original self-attention result to obtain the knowledge-enhanced hidden state. The output dimension of this sub-layer is consistent with the input, and multiple layers can be directly stacked. During training, all new parameters are updated together with the original weights. During inference, the Gate changes dynamically with the input, realizing the decision to reference external knowledge on a token-by-token basis, thereby completing the construction of the modified model.

[0048] In another embodiment of this solution, S3 is specifically implemented as follows: When semantically perturbing the input text sequence x, a domain thesaurus or UMLS CUI chain is used to replace entity words and attribute words with semantically equivalent expressions, such as replacing "penalty for breach of contract" with "penalty for breach of contract," while keeping the other tokens unchanged, resulting in a perturbed sample x′. x and x′ are then tokenized separately and combined into the same batch, which are fed into the modified model in parallel. Two extraction probability distributions are obtained through forward computation. and Calculate the KL divergence D between the two. KL ( || Then, the gradient of all parameters of the modified model is calculated to obtain the vector g = ∇. θ D KL Taking the square of the L2 norm and multiplying it by the regularization coefficient λ, we obtain the gradient direction consistency loss L. GDCL L GDCL The calculation formula is as follows: ; ; in, This represents an equivalent input pair between a text sequence and a perturbed sample. for Semantic perturbation samples; To modify the model for input and The extraction probability distribution The target label (also called "correct category" or "gold label") for the task to be extracted refers to the entity-attribute-attribute value combination or the corresponding category number to be extracted from the current sentence; KL divergence measures the difference in extraction probability distributions; To modify the model parameters The gradient operator; The square of the L2 norm; The regularization coefficient (0.1~1.0), i.e., the weight coefficient of the gradient direction consistency loss, ranges from 0.1 to 1.0. Its final value is automatically determined on the validation set by minimizing the variance of the extraction results, and is used to control stability weights. This loss ensures that the modified model maintains extraction consistency during text extraction. This loss is added to the cross-entropy loss and backpropagated, forcing the modified model to have consistent gradient directions and similar output distributions under semantically equivalent inputs.

[0049] In another embodiment of this solution, S4 is specifically implemented as follows: The cross-entropy loss and gradient direction consistency loss are added together to form the total loss. The AdamW optimizer is used, and the original samples and corresponding perturbation samples are fed into the batch simultaneously. The maximum norm of the gradient is clipped to 1.0. At each step, the cross-entropy loss is calculated first and then the gradient direction consistency loss is calculated. The gradients of the two are accumulated and added to all parameters of the modified model, including the original LLaMA-2-7B weights and the newly added dynamic text knowledge embedding matrix, GAT, and gated fusion network parameters. Training is stopped when the variance of the extraction results on the validation set no longer decreases for 3 consecutive epochs. The overall weight file after convergence is saved to obtain the final large model. Dropout is turned off during inference, but the gate is dynamically calculated to ensure that synonymous inputs obtain consistent extraction results.

[0050] Furthermore, the neighbor subgraph takes the mentioned node obtained by entity linking as the center and performs 1-hop neighbor sampling within the structured text knowledge graph, with the number of sampling nodes not exceeding fifty each time; among them, entities come from triple sets, and triple sets are composed of entity-attribute-attribute value triples.

[0051] Furthermore, gating fusion is achieved through the following methods: The current hidden state is obtained by passing a single-layer linear mapping and Sigmoid activation to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

[0052] Furthermore, the weight coefficients of the gradient direction consistency loss range from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

[0053] By constructing a knowledge-aware attention mechanism at the model structure level, introducing a gradient direction consistency constraint loss function at the training objective level, and building a high-confidence structured knowledge base in conjunction with the scenario, we achieve a synergistic improvement in the interpretability, factual consistency, and robustness to perturbations of reasoning. Through the synergistic effect of structure, loss, and data, significant improvements can be achieved in tasks such as generation compared to baseline models (such as LLaMA-2-7B and Med-PaLM) in metrics such as consistency (CIDEr-D variance reduced by 38.7%), factual accuracy (F1 improved by 29.5%), and robustness to perturbations (accuracy against symptom description improved by 32.4%).

[0054] This invention achieves, for the first time, joint optimization of "knowledge-guided reasoning" and "gradient stability constraints" within a large model through the synergistic effect of three innovations: structure, loss, and data. It is particularly suitable for scenarios with stringent requirements for accuracy and consistency, such as decision support and text analysis, and has significant technological advancements and application value.

[0055] In the above embodiments, although the steps are numbered S1, S2, etc., they are only specific embodiments given by the present invention. Those skilled in the art can adjust the execution order of S1, S2, etc. according to the actual situation, which is also within the protection scope of the present invention. It can be understood that in some embodiments, some or all of the above embodiments may be included.

[0056] This invention also provides a system for enhancing the stability of large model inference in text scenarios. The specific technical solution is as follows: a ternary construction module, a modified construction module, a gradient constraint module, and a joint training module. The ternary construction module is used to construct a structured text knowledge graph based on a text knowledge base, and obtain a ternary set; based on the ternary set, a graph attention network is used to encode the neighbor subgraphs of the current input text sequence to obtain a dynamic text knowledge embedding matrix; The modified construction module is used to insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model. The dynamic text knowledge embedding matrix is ​​used as an external knowledge source. After gating and fusion, the knowledge-enhanced hidden state is obtained, thereby constructing the modified model. The gradient constraint module is used to semantically perturb the input text sequence to obtain perturbed samples. The text sequence is used as the original sample and the perturbed sample in parallel to be input into the model to obtain extraction probability distributions. The divergence between the two extraction probability distributions is calculated, and the gradient of the model parameters of the modified model is obtained to obtain the gradient direction consistency loss. The joint training module is used to train and modify the model by combining cross-entropy loss and gradient direction consistency loss, updating the model parameters until convergence, and obtaining the final large model, which makes the output of the text extraction task stable.

[0057] Based on the above solution, the present invention can be further improved as follows.

[0058] Furthermore, the neighbor subgraph takes the mentioned node obtained by entity linking as the center and performs 1-hop neighbor sampling within the structured text knowledge graph, with the number of sampling nodes not exceeding fifty each time; among them, entities come from triple sets, and triple sets are composed of entity-attribute-attribute value triples.

[0059] Furthermore, gating fusion is achieved through the following methods: The current hidden state is obtained by passing a single-layer linear mapping and Sigmoid activation to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

[0060] Furthermore, the weight coefficients of the gradient direction consistency loss range from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

[0061] It should be noted that the beneficial effects of the large model inference stability enhancement system in text scenarios provided in the above embodiments are the same as the beneficial effects of the large model inference stability enhancement method in text scenarios described above, and will not be repeated here. Furthermore, the system provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the system can be divided into different functional modules according to the actual situation to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiments, and will not be repeated here.

[0062] like Figure 2 As shown, an embodiment of the present invention provides a computer device 300, which includes a processor 320 coupled to a memory 310. The memory 310 stores at least one computer program 330, which is loaded and executed by the processor 320 to enable the computer device 300 to implement any of the above-described methods. Specifically: The computer device 300 can vary considerably due to differences in configuration or performance. It may include one or more processors 320 (Central Processing Units, CPUs) and one or more memories 310. The one or more memories 310 store at least one computer program 330, which is loaded and executed by the one or more processors 320 to enable the computer device 300 to implement the method for enhancing the stability of large model inference in a text-based scenario provided in the above embodiments. Of course, the computer device 300 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The computer device 300 may also include other components for implementing device functions, which will not be elaborated upon here.

[0063] An embodiment of the present invention provides a computer-readable storage medium storing at least one computer program, which is loaded and executed by a processor to enable a computer to implement any of the above-described methods.

[0064] Alternatively, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, a floppy disk, and an optical data storage device, etc.

[0065] In an exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the above-described methods for enhancing the stability of large model inference in text scenarios.

[0066] Those skilled in the art will recognize that this invention can be implemented as a system, method, or computer program product. Therefore, this disclosure can be specifically implemented in the following forms: it can be entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software, generally referred to herein as a "circuit," "module," or "system." Furthermore, in some embodiments, the invention can also be implemented as a computer program product contained in one or more computer-readable media, which includes computer-readable program code.

[0067] Any combination of one or more computer-readable media may be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.

[0068] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A method for enhancing the stability of large model inference in text scenarios, characterized in that, include: S1, Construct a structured text knowledge graph based on the text knowledge base to obtain a ternary set; Based on the aforementioned ternary set, a graph attention network is used to encode the neighbor subgraph of the current input text sequence to obtain a dynamic text knowledge embedding matrix. S2, insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model, use the dynamic text knowledge embedding matrix as an external knowledge source, and obtain the knowledge-enhanced hidden state after gating and fusion, thereby constructing the modified model; S3, perform semantic equivalence perturbation on the input text sequence to obtain perturbation samples, and input the text sequence as the original sample and the perturbation sample in parallel into the modified model to obtain extraction probability distributions respectively; calculate the divergence between the two extraction probability distributions, and calculate the gradient of the model parameters of the modified model to obtain the gradient direction consistency loss; S4. The modified model is trained by combining the cross-entropy loss and the gradient direction consistency loss, and the model parameters are updated until convergence is obtained to obtain the final large model, so that the output of the text extraction task is stable.

2. The method for enhancing the stability of large model inference in a text scenario according to claim 1, characterized in that, The neighbor subgraph is centered on the mentioned node obtained by entity linking, and performs 1-hop neighbor sampling within the structured text knowledge graph, with the number of sampling nodes not exceeding fifty each time; wherein, the entity comes from the triple set, and the triple set is composed of entity-attribute-attribute value triples.

3. The method for enhancing the stability of large model inference in a text scenario according to claim 1, characterized in that, The gating fusion is achieved in the following way: The current hidden state is mapped to a single-layer linear state and activated by a Sigmoid function to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

4. The method for enhancing the stability of large model inference in a text scenario according to claim 1, characterized in that, The weight coefficient of the gradient direction consistency loss ranges from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

5. A system for enhancing the stability of large-scale model inference in text scenarios, characterized in that, include: The module includes a ternary construction module, a modified construction module, a gradient constraint module, and a joint training module. The ternary construction module is used to construct a structured text knowledge graph based on a text knowledge base to obtain a ternary set; based on the ternary set, a graph attention network is used to encode the neighbor subgraphs of the current input text sequence to obtain a dynamic text knowledge embedding matrix. The modified construction module is used to insert a text knowledge-gated cross-attention module into the selected layer of the decoder of the pre-trained large model, and use the dynamic text knowledge embedding matrix as an external knowledge source. After gating and fusion, the knowledge-enhanced hidden state is obtained, thereby constructing the modified model. The gradient constraint module is used to perform semantic equivalence perturbation on the input text sequence to obtain perturbation samples. The text sequence is then used as the original sample and the perturbation sample, which are input into the modified model in parallel to obtain extraction probability distributions. The divergence between the two extraction probability distributions is calculated, and the gradient of the model parameters of the modified model is obtained to obtain the gradient direction consistency loss. The joint training module is used to train the modified model by combining the cross-entropy loss and the gradient direction consistency loss, update the model parameters until convergence, and obtain the final large model, so that the output of the text extraction task is stable.

6. The system for enhancing the stability of large model inference in a text scenario according to claim 5, characterized in that, The neighbor subgraph is centered on the mentioned node obtained by entity linking, and performs 1-hop neighbor sampling within the structured text knowledge graph, with the number of sampling nodes not exceeding fifty each time; wherein, the entity comes from the triple set, and the triple set is composed of entity-attribute-attribute value triples.

7. The system for enhancing the stability of large model inference in a text scenario according to claim 5, characterized in that, The gating fusion is achieved in the following way: The current hidden state is mapped to a single-layer linear state and activated by a Sigmoid function to obtain a gating value. Then, the text knowledge attention and standard self-attention are weighted and summed bit by bit to form the fused hidden state.

8. The system for enhancing the stability of large model inference in a text scenario according to claim 5, characterized in that, The weight coefficient of the gradient direction consistency loss ranges from 0.1 to 1.0, and the final value is automatically determined on the validation set by minimizing the variance of the extraction results.

9. A computer device, characterized in that, The computer device includes a processor coupled to a memory storing at least one computer program, which is loaded and executed by the processor to enable the computer device to perform the method as claimed in any one of claims 1 to 4.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to enable the computer to perform the method as described in any one of claims 1 to 4.