A text question answering method, device and equipment and computer readable storage medium

CN122594433APending Publication Date: 2026-08-18HITHINK ROYALFLUSH INFORMATION NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610761885.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-29
Publication Date
2026-08-18

AI Technical Summary

Technical Problem

此外,长文本训练数据多依赖简单拼接或填充构造,缺乏语义连贯性,导致信噪比低,模型难以捕捉长程依赖

Benefits of technology

[0015] The text question answering method provided in this application includes: receiving a text question of arbitrary length to be answered; searching for the answer to the text question by using a target question answering model obtained through iterative training with a loss function with gradient truncation; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question answering model includes core cue samples, intermediate samples, and full samples; and outputting the target answer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122594433A_ABST
    Figure CN122594433A_ABST
Patent Text Reader

Abstract

The application discloses a text question answering method and device, equipment and a computer readable storage medium, comprising: receiving a text question to be answered of any length; finding an answer to the text question to be answered by using a target question answering model obtained by iterative training of a loss function with gradient truncation, to obtain a target answer; wherein the loss function with gradient truncation comprises a stop gradient operator for blocking the gradient of the model output item corresponding to the intermediate state text in the back propagation; each sample pair in the training sample set used for training the target question answering model comprises a core clue sample, an intermediate state sample and a full sample; and an output operation is performed on the target answer. The application improves the direct alignment effect and can balance the question answering performance of short texts and long texts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a text question-answering method, apparatus, device, and computer-readable storage medium. Background Technology

[0002] In recent years, large language models have achieved excellent performance in short text question answering tasks, but the quality of the model's generated answers often drops significantly in long text scenarios. Related techniques mainly rely on preference alignment methods to improve model performance, but these methods are mostly designed for short texts and struggle to maintain consistency, relevance, and factual accuracy in long texts. To address the long text adaptation problem, existing solutions such as SoLoPO attempt to unlock long text capabilities through short text preference optimization, but it easily collapses into noisy solutions under extremely long contexts (e.g., 64K words), resulting in significant performance degradation. While LongPO introduces KL divergence constraints to prevent performance degradation in short texts, it ignores the significant distribution gap between short and long contexts, leading to poor direct alignment and an inability to handle both short and long texts. Furthermore, long text training data often relies on simple concatenation or padding, lacking semantic coherence, resulting in a low signal-to-noise ratio and making it difficult for models to capture long-range dependencies.

[0003] In conclusion, how to effectively solve the problems of poor direct alignment and inability to accommodate both short and long texts is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] The purpose of this application is to provide a text question-answering method that improves the direct alignment effect and can take into account the question-answering performance of both short and long texts; another purpose of this application is to provide a text question-answering device, apparatus and computer-readable storage medium.

[0005] To solve the above-mentioned technical problems, this application provides the following technical solution: A text-based question-answering method, comprising: It can accept unanswered text questions of any length; The target question-answering model, obtained by iterative training using a loss function with gradient truncation, searches for the answer to the text question to be answered, and obtains the target answer; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question-answering model includes a core cue sample, the intermediate sample, and the full sample; The target answer is output.

[0006] In one specific embodiment of this application, the method further includes a training process for the target question-answering model, which includes: Obtain each original document and determine the core clue sample, intermediate sample, and full sample corresponding to each original document; Obtain the correct and incorrect reference answers for each original document; By constructing sample pairs using the core clue samples, intermediate samples, full samples, correct reference answers, and incorrect reference answers corresponding to each original document, a training sample set consisting of each sample pair is obtained. Obtain a pre-built initial question-answering model and determine the initial question-answering model as the current question-answering model; The training sample set is traversed through sample pairs, and the current output probability distribution corresponding to the traversed sample pairs is calculated using the current question answering model; Based on the current output probability distribution, the model parameters are updated using the gradient-truncation loss function; wherein, the gradient-truncation loss function includes a basic preference alignment term and a directional traction term, and the directional traction term includes the stopping gradient operator; Determine whether the traversal of each sample pair in the training sample set has been completed; If not, the question-answering model with updated model parameters is determined as the new current question-answering model, and the step of traversing the training sample set is repeated. If so, the current question-answering model is determined as the target question-answering model.

[0007] In one specific embodiment of this application, the core clue sample, intermediate sample, and full sample corresponding to each original document are determined respectively, including: Extract the core clue text containing key information about the answer from each original document, and identify each core clue text as a core clue sample. Retrieve interfering texts unrelated to each core clue text from the irrelevant text library, and treat each interfering text as a noise text; Each core clue text is concatenated with its corresponding noisy text to obtain each full text, and each full text is identified as a full sample. Each noisy text is randomly masked or discarded to generate at least one intermediate text, and each generated intermediate text is identified as an intermediate sample.

[0008] In one specific embodiment of this application, after calculating the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model, the method further includes: Based on the current output probability distribution, determine the current first output probability of the current question answering model generating the preference response corresponding to the core clue sample under the intermediate sample condition, and determine the current second output probability of the current question answering model generating the preference response corresponding to the core clue sample under the full sample condition; The current first output probability and the current second output probability are compared to obtain the current comparison result; Based on the current comparison results, update the number of times the first output probability is less than the second output probability, and obtain the current number; When it is determined that the current number of attempts exceeds a preset threshold, a model capability degradation warning message is output.

[0009] In one specific embodiment of this application, the number of times the first output probability is less than the second output probability, which has been statistically calculated, is updated based on the current comparison result to obtain the current number. When it is determined that the current number is greater than a preset number threshold, a model capability degradation warning message is output, including: Based on the current comparison results, the number of consecutive occurrences where the first output probability is less than the second output probability is updated to obtain the current number of consecutive occurrences. When it is determined that the current consecutive occurrences exceed the preset threshold, the model capability degradation prompt message is output.

[0010] In one specific embodiment of this application, the calculation of the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model includes: When the total text length of the traversed sample pairs exceeds the preset length threshold, the traversed sample pairs are segmented, and the resulting text blocks are assigned to each graphics processor. Copy the model parameters of the current question-answering model to each graphics processor; Each graphics processor is used to calculate the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model; The current output probability distribution is obtained by concatenating the probability distributions of each sub-output.

[0011] In one specific embodiment of this application, each graphics processor is used to calculate the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model, including: Each graphics processor, utilizing an integrated fast attention mechanism, computes the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model.

[0012] A text-based question-answering device, comprising: The question receiving module is used to receive unanswered text questions of any length; The answer acquisition module is used to search for the answer to the text question to be answered by the target question-answering model obtained through iterative training using a loss function with gradient truncation, and obtain the target answer; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question-answering model includes a core cue sample, the intermediate sample, and the full sample; The answer output module is used to output the target answer.

[0013] A text-based question-answering device, comprising: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the text question-answering method as described above.

[0014] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the text question-answering method as described above.

[0015] The text question answering method provided in this application includes: receiving a text question of arbitrary length to be answered; searching for the answer to the text question by using a target question answering model obtained through iterative training with a loss function with gradient truncation; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question answering model includes core cue samples, intermediate samples, and full samples; and outputting the target answer.

[0016] As can be seen from the above technical solutions, by introducing intermediate state samples as bridging contexts during the training phase, the training sample pairs simultaneously contain core cue samples, intermediate state samples, and full samples, forming a progressive structure from high signal-to-noise ratio (SNR) to low SNR. This effectively compensates for the distribution differences between short and long contexts, enabling the model to smoothly adapt to SNR changes from short to long texts, alleviating the distribution gap, making preference alignment more robust, and improving direct alignment performance. By forcing the long text output to align with the high-fidelity intermediate state through a loss function with gradient truncation, and combining this with a stopping gradient operator to block the backpropagation gradient of the intermediate output term, data noise interference can be effectively suppressed, enhancing model robustness. While improving the accuracy of long text question answering, it avoids the degradation of short text capabilities, thus balancing the question answering performance of both short and long texts.

[0017] Accordingly, this application also provides a text question-answering device, equipment, and computer-readable storage medium corresponding to the above-mentioned text question-answering method, which have the above-mentioned technical effects, and will not be repeated here. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 This is a flowchart illustrating one implementation of the text-based question-and-answer method in this application. Figure 2 This is a flowchart illustrating another implementation of the text-based question-and-answer method in this application. Figure 3 This is a schematic diagram of a sample pair construction process in an embodiment of this application; Figure 4 This is a structural block diagram of a text question-and-answer device according to an embodiment of this application; Figure 5 This is a structural block diagram of a text question-answering device according to an embodiment of this application; Figure 6 This is a schematic diagram of the specific structure of a text question-and-answer device provided in an embodiment of this application. Detailed Implementation

[0020] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0022] See Figure 1 , Figure 1This is a flowchart illustrating one implementation of the text-based question-and-answer method in this application. The method may include the following steps: S101: Receive unanswered text questions of any length.

[0023] When text-based question answering is needed, a text question of any length is sent to the text question answering center, which then receives the text question question of any length. The text question answering center can be a server, processor, or similar device that has a question-answering model deployed to answer the text questions.

[0024] S102: The target question answering model, obtained by iterative training using a loss function with gradient truncation, searches for answers to the text questions to be answered and obtains the target answer.

[0025] Among them, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question answering model includes core cue samples, intermediate samples, and full samples.

[0026] An initial question-answering model and training sample set are pre-built. Each sample pair in the training sample set includes core clue samples, intermediate state samples, and the full set of samples. Based on the training sample set, the initial question-answering model is iteratively trained using a loss function with gradient truncation to obtain the target question-answering model. The loss function with gradient truncation includes a stopping gradient operator to block the gradient of the model output term corresponding to the intermediate text during backpropagation. After receiving a text question of arbitrary length, the target question-answering model, obtained through iterative training using the loss function with gradient truncation, searches for the answer to the text question and obtains the target answer. By using the loss function with gradient truncation, the path from good to bad learning is cut off by truncating the intermediate gradient, retaining only the optimization momentum of bad-to-good alignment. As the model parameters are updated, the performance of long texts gradually moves towards the intermediate state with high fidelity, ultimately achieving robust performance across all lengths.

[0027] S103: Output the target answer.

[0028] The target question-answering model, obtained through iterative training using a loss function with gradient truncation, searches for answers to the text questions to be answered, and outputs the target answer after obtaining it. This application enhances the performance of large language models on long texts by using a bridging preference alignment approach, without affecting performance on short texts.

[0029] As can be seen from the above technical solutions, by introducing intermediate state samples as bridging contexts during the training phase, the training sample pairs simultaneously contain core cue samples, intermediate state samples, and full samples, forming a progressive structure from high signal-to-noise ratio (SNR) to low SNR. This effectively compensates for the distribution differences between short and long contexts, enabling the model to smoothly adapt to SNR changes from short to long texts, alleviating the distribution gap, making preference alignment more robust, and improving direct alignment performance. By forcing the long text output to align with the high-fidelity intermediate state through a loss function with gradient truncation, and combining this with a stopping gradient operator to block the backpropagation gradient of the intermediate output term, data noise interference can be effectively suppressed, enhancing model robustness. While improving the accuracy of long text question answering, it avoids the degradation of short text capabilities, thus balancing the question answering performance of both short and long texts.

[0030] It should be noted that, based on the above embodiments, this application also provides corresponding improvement solutions. In subsequent embodiments, steps that are the same as or corresponding to those in the above embodiments can be referred to each other, and the corresponding beneficial effects can also be referred to each other. These improvements will not be elaborated upon in the following improved embodiments.

[0031] See Figure 2 , Figure 2 This is a flowchart illustrating another implementation of the text-based question-and-answer method in this application. The method may include the following steps: S201: Obtain each original document and determine the core clue sample, intermediate sample, and full sample corresponding to each original document.

[0032] Obtain each original document and determine the core clue sample, intermediate sample, and full sample corresponding to each original document.

[0033] In one specific embodiment of this application, determining the core clue sample, intermediate sample, and full sample corresponding to each original document may include the following steps: Step 1: Extract the core clue text containing key information about the answer from each original document, and identify each core clue text as a core clue sample; Step 2: Retrieve interfering texts that are unrelated to each core clue text from the irrelevant text library, and treat each interfering text as a noise text; Step 3: Concatenate each core clue text with its corresponding noise text to obtain each full text, and identify each full text as a full sample. Step 4: Randomly mask or discard portions of each noisy text to generate at least one intermediate text, and identify each generated intermediate text as an intermediate sample.

[0034] For ease of description, the four steps above can be combined for explanation.

[0035] After obtaining each original document, core clue text containing key information about the answer is extracted from each original document, and each core clue text is determined as a core clue sample. By extracting core clue text containing key information about the answer from the original documents as core clue samples, it is ensured that the model can directly learn the core content necessary to generate the correct answer, providing high-quality, high signal-to-noise ratio anchor points for subsequent preference alignment.

[0036] Interference texts unrelated to each core clue text are retrieved from an irrelevant text library and treated as noise texts. Each core clue text is then concatenated with its corresponding noise text to obtain a complete text set, which is then defined as a complete sample. By retrieving semantically irrelevant interference texts from the irrelevant text library as noise texts, redundant information commonly found in long texts is realistically simulated. This allows the model to adapt to low signal-to-noise ratio environments during training, effectively improving its robustness against noise in real-world long text question answering. By directly concatenating the core clue texts with noise texts to obtain the complete sample, the length characteristics of long texts are preserved while clearly distinguishing between core information and noise, facilitating the model's ability to learn to locate key clues amidst a large amount of interference.

[0037] Each portion of the noisy text is randomly masked or discarded to generate at least one intermediate text, which is then designated as an intermediate sample. This process constructs bridging samples with progressively decreasing signal-to-noise ratios between the core cue samples and the full sample set, effectively mitigating the distribution gap between short and long texts. This allows the model to smoothly adapt to increased noise, avoiding performance drops or training crashes caused by direct alignment. When multiple intermediate texts exist, the presence of several intermediate samples with different discard ratios provides a data foundation for subsequent step-by-step bridging alignment, further improving the model's convergence speed and final performance in long text tasks.

[0038] S202: Obtain the correct and incorrect reference answers for each original document.

[0039] After obtaining each original document, obtain the correct and incorrect reference answers for each original document.

[0040] S203: Construct sample pairs using the core clue samples, intermediate samples, full samples, correct reference answers, and incorrect reference answers corresponding to each original document to obtain a training sample set composed of each sample pair.

[0041] After identifying the core clue samples, intermediate state samples, and full samples corresponding to each original document, and obtaining the correct and incorrect reference answers corresponding to each original document, sample pairs are constructed using the core clue samples, intermediate state samples, full samples, correct and incorrect reference answers corresponding to each original document, resulting in a training sample set composed of each sample pair.

[0042] See Figure 3 , Figure 3 This is a schematic diagram illustrating a sample pair construction process in an embodiment of this application. Training data is constructed by simulating signal-to-noise ratio (SNR) changes in signal processing. It includes two steps: (1) Construction of three-level sample sequences: Core Clue Text ( ): Includes generating the target response The key information required.

[0043] Noisy text ( ): Retrieved from an irrelevant document library Semantically irrelevant interfering text.

[0044] Full text ( ):Depend on and It is pieced together. .

[0045] (2) Intermediate text Dynamic generation: Through the Some content is randomly masked or discarded to generate an intermediate state. .

[0046] Discard ratio Settings: Experiments show that, (Preserving half the noise) is better than (No noise is preserved at all), which shows that the existence of intermediate gradients can effectively alleviate the distribution gap between short and long texts.

[0047] Intermediate text There can be n, where n is greater than or equal to 1.

[0048] In short text ( ) and long text ( Constructing a multi-segment bridging context for intermediate states between () This approach simulates the transition from high signal-to-noise ratio (SNR) to low SNR by progressively adding irrelevant documents (noise) to short texts. The optimization objective is no longer to directly align long texts with short texts, but rather to utilize a bridging strategy. Reduce distribution discrepancies and smooth out optimized paths. The model input is text. At that time, the output is The probability of.

[0049] Forward Collapse: Identifies a specific degradation phenomenon where the performance of bridging strategies tends to converge towards that of low-quality long text strategies.

[0050] Using the log-probability of the selected response The numerical differences are used to make a judgment. If , , If the condition is met, it is determined that the model has experienced a degradation in its ability to handle long texts, i.e., forward collapse.

[0051] Based on the above diagnostic results, the model is guided to enter backward collapse, which forces the performance of long texts to align with an intermediate state with a higher signal-to-noise ratio.

[0052] By acquiring each original document and identifying core clue samples, intermediate samples, and full samples, while also obtaining the corresponding correct and incorrect reference answers, a progressive sample pair containing samples ranging from high signal-to-noise ratio to low signal-to-noise ratio is constructed. This allows the model to gradually adapt to the introduction of noise during training, effectively mitigating the distribution gap between short and long texts and avoiding performance loss caused by direct alignment.

[0053] S204: Obtain the pre-built initial question-answering model and determine the initial question-answering model as the current question-answering model.

[0054] Obtain the pre-built initial question-answering model and determine the initial question-answering model as the current question-answering model.

[0055] S205: Traverse the training sample set for each sample pair and use the current question answering model to calculate the current output probability distribution corresponding to the traversed sample pair.

[0056] After constructing a training sample set consisting of sample pairs and determining the current question answering model, the training sample set is traversed by sample pairs, and the current output probability distribution corresponding to the traversed sample pairs is calculated using the current question answering model.

[0057] In one specific embodiment of this application, after calculating the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model, the method may further include the following steps: Step 1: Based on the current output probability distribution, determine the current first output probability of the current question answering model generating the preference response corresponding to the core clue sample under the intermediate sample condition, and determine the current second output probability of the current question answering model generating the preference response corresponding to the core clue sample under the full sample condition; Step 2: Compare the current first output probability with the current second output probability to obtain the current comparison result; Step 3: Update the number of times the first output probability is less than the second output probability based on the current comparison results, and obtain the current number; Step 4: When it is determined that the current number of attempts exceeds the preset threshold, output a message indicating that the model's capabilities have degraded.

[0058] For ease of description, the four steps above can be combined for explanation.

[0059] After calculating the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model, the system determines the current first output probability of the current question-answering model generating the preference response corresponding to the core clue sample under the intermediate sample condition, and determines the current second output probability of the current question-answering model generating the preference response corresponding to the core clue sample under the full sample condition. The current first output probability and the current second output probability are compared to obtain the current comparison result. Based on the current comparison result, the system updates the number of times the first output probability is less than the second output probability, obtaining the current count. When the current count is determined to be greater than the preset count threshold, the system determines that the model has degraded, which means that the model performs worse in the intermediate state with less noise. That is, the model is sacrificing its original short text understanding ability to cater to the noise in the long text, and outputs a model capability degradation prompt message.

[0060] By comparing the first output probability of intermediate samples with the second output probability of the entire sample after each forward computation, and counting the cumulative number of times the first output probability is less than the second output probability, this method can directly capture whether the model performs worse in high signal-to-noise ratio (SNR) environments with less noise than in low SNR environments. Compared to methods that rely solely on loss functions or reward differences, this method can more sensitively detect the specific degradation phenomenon of forward collapse. By setting a preset threshold for the number of iterations, the degradation of model capabilities is transformed into a quantifiable metric. When the cumulative number of iterations exceeds the threshold, a prompt message is output, allowing developers to promptly recognize that the model is sacrificing its ability to understand short texts to accommodate the noise of long texts, thus enabling them to take appropriate intervention measures, such as adjusting hyperparameters, stopping training, or rolling back the model, effectively preventing the model from silently collapsing into a noisy solution.

[0061] It should be noted that the preset number of times threshold can be set and adjusted according to the actual situation, and this application embodiment does not limit this.

[0062] In one specific embodiment of this application, updating the number of times the first output probability is less than the second output probability based on the current comparison result to obtain the current number, and outputting a model capability degradation prompt when it is determined that the current number is greater than a preset number threshold, may include the following steps: Step 1: Update the number of consecutive occurrences where the first output probability is less than the second output probability based on the current comparison results, and obtain the current number of consecutive occurrences; Step 2: When it is determined that the current consecutive occurrences exceed the preset threshold, output a model capability degradation warning message.

[0063] For ease of description, the two steps above can be combined for explanation.

[0064] After comparing the current first output probability and the current second output probability to obtain the current comparison result, the number of consecutive occurrences where the first output probability is less than the second output probability is updated based on the current comparison result, resulting in the current consecutive occurrence count. When it is determined that the current consecutive occurrence count exceeds a preset threshold, a model capability degradation warning message is output. By setting the system to only trigger a degradation warning when the model exhibits an anomaly where the intermediate output probability is lower than the full output probability in multiple consecutive training steps, compared to the cumulative count, the consecutive count can effectively filter out occasional probability flips caused by random fluctuations or individual abnormal samples during training, significantly reducing the false alarm rate and improving the reliability of degradation diagnosis.

[0065] In one specific embodiment of this application, calculating the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model may include the following steps: Step 1: When the total text length of the traversed sample pairs exceeds the preset length threshold, the traversed sample pairs are segmented, and the resulting text blocks are assigned to each graphics processor. Step 2: Copy the model parameters of the current question-answering model to each graphics processor; Step 3: Utilize each graphics processor to calculate the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model; Step 4: Concatenate the probability distributions of each sub-output to obtain the current output probability distribution.

[0066] For ease of description, the four steps above can be combined for explanation.

[0067] After traversing the training sample set, when the total text length of the traversed sample pairs exceeds a preset length threshold, the traversed sample pairs are segmented, and the resulting text blocks are assigned to each graphics processing unit (GPU). The model parameters of the current question answering model are copied to each GPU, and each GPU is used to compute the sub-output probability distribution corresponding to each text block in parallel based on the current question answering model. The sub-output probability distributions are then concatenated to obtain the current output probability distribution.

[0068] When the total text length of a sample pair exceeds a preset threshold, it is divided into multiple text blocks and distributed to different GPUs for parallel processing. Simultaneously, the model parameters are copied to each GPU, effectively distributing the memory pressure caused by long texts. This allows for efficient training of extremely long sequences (such as 64K words) that were previously impossible to process due to insufficient memory on a single GPU, thereby expanding the model's adaptability to long text question-answering tasks. Each GPU independently and in parallel computes the sub-output probability distribution of its assigned text block, eliminating the need for sequential waiting. Compared to processing a complete sequence on a single GPU, this significantly shortens the time for a single forward computation, accelerates model iteration, and reduces overall training costs.

[0069] In one specific embodiment of this application, utilizing each graphics processor to compute the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model may include the following steps: Each graphics processor, utilizing an integrated fast attention mechanism, computes the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model.

[0070] By integrating a fast attention mechanism (such as FlashAttention-2) into each graphics processing unit (GPU), and copying the model parameters of the current question-answering model to each GPU, the GPUs with integrated fast attention mechanisms can compute the sub-output probability distributions corresponding to each text block in parallel based on the current question-answering model. Integrating the fast attention mechanism into each GPU significantly improves the forward computation speed of the attention mechanism when computing the sub-output probability distributions in parallel.

[0071] You can also use DeepSpeed ​​ZeRO-3 in conjunction with CPU Offloading technology to train a model with hundreds of billions of parameters in a 64K length with limited video memory.

[0072] S206: Update the model parameters using a loss function with gradient truncation based on the current output probability distribution.

[0073] The loss function with gradient truncation includes a basic preference alignment term and a directional traction term, with the directional traction term including a stopping gradient operator.

[0074] After calculating the current output probability distribution for each sample pair traversed using the current question-answering model, the model parameters are updated using a loss function with gradient truncation based on the current output probability distribution. The loss function with gradient truncation includes a basic preference alignment term and a directional traction term, with the directional traction term including a stopping gradient operator.

[0075] The model parameters can be updated using a loss function with gradient truncation using the following formula: ; Wherein, Preference Gap refers to the model in different lengths or different signal-to-noise ratio contexts (e.g., and To address the difference in log probabilities assigned to preferred and unpreferred responses, this application introduces a bridging context to smooth the gap, thereby achieving robust performance migration. To calculate the loss value, This refers to the model input being text. At that time, the output is The probability of.

[0076] Alignment with basic preferences, For directional traction, through The system freezes the parameter update direction of the bridging strategy during backpropagation, and the gradient generated by this term only acts on the [missing term]. This forces the model to maintain its comprehension ability in a bridging state (high signal-to-noise ratio) without declining, while requiring the model's output distribution to move closer to a high-quality bridging state when faced with long texts (low signal-to-noise ratio).

[0077] .

[0078] By using the current question-answering model to calculate the output probability distribution corresponding to the sample pair in each iteration, and updating the model parameters with a loss function that includes basic preference alignment terms and directional traction terms, the gradient backpropagation of intermediate sample output terms can be blocked, preventing the model from collapsing into noisy solutions, thereby significantly improving the stability and convergence efficiency of the long text training process.

[0079] S207: Determine whether the traversal of each sample pair in the training sample set has been completed. If not, proceed to step S208; if yes, proceed to step S209.

[0080] After updating the model parameters using a loss function with gradient truncation based on the current output probability distribution, determine whether the traversal of each sample pair in the training sample set has been completed. If not, it means that the remaining sample pairs in the training sample set need to be traversed again, and step S208 is executed. If yes, it means that the training sample set is empty, and step S209 is executed.

[0081] S208: Determine the question-answering model with updated model parameters as the new current question-answering model, and return to step S205.

[0082] When it is determined that each sample pair in the training sample set has not been traversed, it means that the remaining sample pairs in the training sample set need to be traversed again. The question-answering model with updated model parameters is determined as the new current question-answering model, and the process returns to step S205.

[0083] S209: Determine the current question-answering model as the target question-answering model.

[0084] Once it is determined that all sample pairs in the training sample set have been traversed, the current question answering model is identified as the target question answering model.

[0085] By traversing each pair of samples in the training sample set, the model is ensured to fully learn the preference relationships among all sample pairs, avoiding training bias. This allows the final target question-answering model to generate accurate and consistent answers to text questions of any length, taking into account both short and long text question-answering performance.

[0086] S210: Receive unanswered text questions of any length.

[0087] S211: The target question answering model, obtained by iterative training using a loss function with gradient truncation, searches for answers to the text questions to be answered and obtains the target answer.

[0088] Among them, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question answering model includes core cue samples, intermediate samples, and full samples.

[0089] S212: Output the target answer.

[0090] Corresponding to the above method embodiments, this application also provides a text question-answering device, which can be referred to in correspondence with the text question-answering method described above.

[0091] See Figure 4 , Figure 4 This is a structural block diagram of a text question-answering device according to an embodiment of this application. The device may include: The question receiving module 41 is used to receive unanswered text questions of any length; The answer acquisition module 42 is used to find the answer to the text question to be answered by the target question answering model obtained by iterative training using a loss function with gradient truncation; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text in backpropagation; each sample pair in the training sample set used to train the target question answering model includes core clue samples, intermediate samples and full samples; The answer output module 43 is used to output the target answer.

[0092] As can be seen from the above technical solutions, by introducing intermediate state samples as bridging contexts during the training phase, the training sample pairs simultaneously contain core cue samples, intermediate state samples, and full samples, forming a progressive structure from high signal-to-noise ratio (SNR) to low SNR. This effectively compensates for the distribution differences between short and long contexts, enabling the model to smoothly adapt to SNR changes from short to long texts, alleviating the distribution gap, making preference alignment more robust, and improving direct alignment performance. By forcing the long text output to align with the high-fidelity intermediate state through a loss function with gradient truncation, and combining this with a stopping gradient operator to block the backpropagation gradient of the intermediate output term, data noise interference can be effectively suppressed, enhancing model robustness. While improving the accuracy of long text question answering, it avoids the degradation of short text capabilities, thus balancing the question answering performance of both short and long texts.

[0093] In one specific embodiment of this application, the device may further include a model training module, which may include: The sample acquisition submodule is used to acquire each original document and determine the core clue sample, intermediate sample and full sample corresponding to each original document respectively; The Reference Answer Acquisition submodule is used to retrieve the correct and incorrect reference answers for each original document. The training sample set acquisition submodule is used to construct sample pairs using the core clue samples, intermediate samples, full samples, correct reference answers and incorrect reference answers corresponding to each original document, so as to obtain a training sample set composed of each sample pair; The current question-answering model determination submodule is used to obtain the pre-built initial question-answering model and determine the initial question-answering model as the current question-answering model; The current output probability distribution calculation submodule is used to traverse the training sample set for sample pairs and use the current question answering model to calculate the current output probability distribution corresponding to the traversed sample pairs. The model parameter update submodule is used to update the model parameters according to the current output probability distribution using a loss function with gradient truncation. The loss function with gradient truncation includes a basic preference alignment term and a directional traction term, and the directional traction term includes a stopping gradient operator. The judgment submodule is used to determine whether the traversal of each sample pair in the training sample set has been completed; The repeat execution submodule is used to determine the question answering model with updated model parameters as the new current question answering model when it is determined that the traversal of each sample pair in the training sample set has not been completed, and to repeatedly execute the step of traversing the sample pairs in the training sample set. The target question answering model determination submodule is used to determine the current question answering model as the target question answering model when it is determined that all sample pairs in the training sample set have been traversed.

[0094] In one specific embodiment of this application, the sample acquisition submodule may include: The core clue sample determination unit is used to extract core clue texts containing key information of the answer from each original document and determine each core clue text as a core clue sample. The noise text determination unit is used to retrieve interference texts that are unrelated to each core clue text from the irrelevant text library, and to treat each interference text as a noise text. The full sample determination unit is used to concatenate each core clue text with the corresponding noise text to obtain each full text, and determine each full text as a full sample. The intermediate sample determination unit is used to randomly mask or discard parts of each noisy text to generate at least one intermediate text, and to determine each generated intermediate text as an intermediate sample.

[0095] In one specific embodiment of this application, the device may further include: The output probability determination module is used to determine the current first output probability of the current question answering model generating the preference response corresponding to the core clue sample under the intermediate sample condition, and to determine the current second output probability of the current question answering model generating the preference response corresponding to the core clue sample under the full sample condition, after calculating the current output probability distribution corresponding to the sample pair traversed by the current question answering model. The current comparison result acquisition module is used to compare the current first output probability and the current second output probability to obtain the current comparison result. The current count acquisition module is used to update the counts where the first output probability is less than the second output probability based on the current comparison results, and obtain the current count. The prompt message output module is used to output a model capability degradation prompt message when it is determined that the current number of attempts exceeds a preset number threshold.

[0096] In one specific embodiment of this application, the current count acquisition module is specifically a module that updates the number of consecutive occurrences where the first output probability is less than the second output probability based on the current comparison result to obtain the current number of consecutive occurrences; The prompt message output module is specifically designed to output a model capability degradation prompt message when it is determined that the current consecutive occurrences exceed a preset threshold.

[0097] In one specific embodiment of this application, the current output probability distribution calculation submodule may include: The text block segmentation unit is used to segment the traversed sample pairs when the total text length of the traversed sample pairs exceeds a preset length threshold, and to allocate the segmented text blocks to each graphics processor. The model parameter unit is used to copy the model parameters of the current question-answering model to each graphics processor. The sub-output probability distribution calculation unit is used to calculate the sub-output probability distribution corresponding to each text block in parallel using each graphics processor based on the current question-answering model; The current output probability distribution acquisition unit is used to concatenate the sub-output probability distributions to obtain the current output probability distribution.

[0098] In one specific embodiment of this application, the sub-output probability distribution calculation unit is specifically a unit that uses each graphics processor with an integrated fast attention mechanism to calculate the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model.

[0099] For the method embodiments described above, see [link to relevant documentation]. Figure 5 , Figure 5 This is a schematic diagram of the text question-answering device provided in this application. The device may include: Memory 332 is used to store computer programs; The processor 322 is used to implement the steps of the text question-and-answer method in the above method embodiments when executing a computer program.

[0100] For details, please refer to Figure 6 , Figure 6This is a schematic diagram illustrating the specific structure of a text-based question-answering device provided in this embodiment. The text-based question-answering device can vary significantly due to differences in configuration or performance. It may include a processor (central processing unit, CPU) 322 (e.g., one or more processors) and a memory 332. The memory 332 stores one or more computer programs 342 or data 344. The memory 332 can be temporary or persistent storage. The program stored in the memory 332 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the data processing device. Furthermore, the processor 322 may be configured to communicate with the memory 332 and execute the series of instruction operations stored in the memory 332 on the text-based question-answering device 301.

[0101] The text-based question-and-answer device 301 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341.

[0102] The steps in the text question answering method described above can be implemented by the structure of a text question answering device.

[0103] Corresponding to the above method embodiments, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can perform the following steps: The system receives text questions of arbitrary length; it iteratively trains a target question-answering model using a loss function with gradient truncation to find the answer to the text question and obtain the target answer; the loss function with gradient truncation includes a stopping gradient operator to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question-answering model includes core cue samples, intermediate samples, and full samples; and it outputs the target answer.

[0104] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0105] For a description of the computer-readable storage medium provided in this application, please refer to the above method embodiments; further details will not be repeated here.

[0106] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatuses, devices, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.

[0107] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions and core ideas of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.

Claims

1. A text-based question-answering method, characterized in that, include: It can accept unanswered text questions of any length; The target question-answering model, obtained by iterative training using a loss function with gradient truncation, searches for the answer to the text question to be answered, and obtains the target answer; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question-answering model includes a core cue sample, the intermediate sample, and the full sample; The target answer is output.

2. The text-based question-answering method according to claim 1, characterized in that, It also includes the training process of the target question-answering model, which includes: Obtain each original document and determine the core clue sample, intermediate sample, and full sample corresponding to each original document; Obtain the correct and incorrect reference answers for each original document; By constructing sample pairs using the core clue samples, intermediate samples, full samples, correct reference answers, and incorrect reference answers corresponding to each original document, a training sample set consisting of each sample pair is obtained. Obtain a pre-built initial question-answering model and determine the initial question-answering model as the current question-answering model; The training sample set is traversed through sample pairs, and the current output probability distribution corresponding to the traversed sample pairs is calculated using the current question answering model; Based on the current output probability distribution, the model parameters are updated using the gradient-truncation loss function; wherein, the gradient-truncation loss function includes a basic preference alignment term and a directional traction term, and the directional traction term includes the stopping gradient operator; Determine whether the traversal of each sample pair in the training sample set has been completed; If not, the question-answering model with updated model parameters is determined as the new current question-answering model, and the step of traversing the training sample set is repeated. If so, the current question-answering model is determined as the target question-answering model.

3. The text-based question-answering method according to claim 2, characterized in that, The core clue samples, intermediate samples, and full samples corresponding to each original document were determined separately, including: Extract the core clue text containing key information about the answer from each original document, and identify each core clue text as a core clue sample. Retrieve interfering texts unrelated to each core clue text from the irrelevant text library, and treat each interfering text as a noise text; Each core clue text is concatenated with its corresponding noisy text to obtain each full text, and each full text is identified as a full sample. Each noisy text is randomly masked or discarded to generate at least one intermediate text, and each generated intermediate text is identified as an intermediate sample.

4. The text-based question-answering method according to claim 2 or 3, characterized in that, After calculating the current output probability distribution corresponding to the traversed sample pairs using the current question-answering model, the method further includes: Based on the current output probability distribution, determine the current first output probability of the current question answering model generating the preference response corresponding to the core clue sample under the intermediate sample condition, and determine the current second output probability of the current question answering model generating the preference response corresponding to the core clue sample under the full sample condition; The current first output probability and the current second output probability are compared to obtain the current comparison result; Based on the current comparison results, update the number of times the first output probability is less than the second output probability, and obtain the current number; When it is determined that the current number of attempts exceeds a preset threshold, a model capability degradation warning message is output.

5. The text-based question-answering method according to claim 4, characterized in that, Based on the current comparison results, the number of times the first output probability is less than the second output probability is updated to obtain the current number. When the current number is determined to be greater than a preset threshold, a model capability degradation warning message is output, including: Based on the current comparison results, the number of consecutive occurrences where the first output probability is less than the second output probability is updated to obtain the current number of consecutive occurrences. When it is determined that the current consecutive occurrences exceed the preset threshold, the model capability degradation prompt message is output.

6. The text-based question-answering method according to claim 2, characterized in that, The current output probability distribution corresponding to the traversed sample pairs is calculated using the current question-answering model, including: When the total text length of the traversed sample pairs exceeds the preset length threshold, the traversed sample pairs are segmented, and the resulting text blocks are assigned to each graphics processor. Copy the model parameters of the current question-answering model to each graphics processor; Each graphics processor is used to calculate the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model; The current output probability distribution is obtained by concatenating the probability distributions of each sub-output.

7. The text-based question-answering method according to claim 6, characterized in that, The sub-output probability distributions corresponding to each text block are calculated in parallel using each graphics processor based on the current question-answering model, including: Each graphics processor, utilizing an integrated fast attention mechanism, computes the sub-output probability distribution corresponding to each text block in parallel based on the current question-answering model.

8. A text-based question-and-answer device, characterized in that, include: The question receiving module is used to receive unanswered text questions of any length; The answer acquisition module is used to search for the answer to the text question to be answered by the target question-answering model obtained through iterative training using a loss function with gradient truncation, and obtain the target answer; wherein, the loss function with gradient truncation includes a stopping gradient operator used to block the gradient of the model output term corresponding to the intermediate text during backpropagation; each sample pair in the training sample set used to train the target question-answering model includes a core cue sample, the intermediate sample, and the full sample; The answer output module is used to output the target answer.

9. A text-based question-and-answer device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the text question-answering method as described in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the text question-answering method as described in any one of claims 1 to 7.