Document difficult negative sample generation method, device and equipment

By reconstructing documents into a three-level index structure and utilizing GANs to generate logically inconsistent difficult negative samples, the problem of low efficiency in generating high-quality difficult negative samples is solved, thereby improving the question-answering accuracy of the retrieval enhancement generation system.

CN121658636APending Publication Date: 2026-03-13HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-03
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

In existing technologies, generating high-quality hard negative samples is inefficient, which limits the performance improvement of retrieval augmentation generation systems (RAG systems).

Method used

The document is reconstructed into a three-level index structure using a recursive algorithm and a large language model. A generative adversarial network (GAN) generator and discriminator are used to filter and train difficult negative samples to ensure that the samples and answers are semantically similar but logically inconsistent.

Benefits of technology

It improves the accuracy of question answering in large language models, reduces phantom responses, and enhances the performance of the retrieval augmentation generation system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121658636A_ABST
    Figure CN121658636A_ABST
Patent Text Reader

Abstract

The invention provides a document difficult negative sample generation method, device and equipment, and the method comprises the steps: reconstructing a sampling document into a three-level index structure based on a recursive algorithm and a large language model, and obtaining a sample database, the three-level index structure comprising an abstract vector, a text block and an abstract; a discriminator of a GAN (Generative Adversarial Network) judges a first probability that the multiple pieces of sample data correctly answer the to-be-processed question based on the abstracts and the text blocks of the multiple pieces of sample data, and takes the sample data of which the first probability is lower than a threshold value as candidate negative samples; the candidate negative samples with the similarity between the abstracts and the answers higher than a threshold value serve as sampling negative samples; a GAN generator generates difficult negative samples based on the multiple sampling negative samples, a loss function comprising semantic loss items and logic loss items is adopted to train a GAN model, the similarity between the difficult negative samples and answers reaches an extreme value, and logic is inconsistent; and generating document difficult negative samples based on the difficult negative samples.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of intelligent document processing technology, and in particular to a method, apparatus and device for generating difficult negative samples of documents. Background Technology

[0002] Retrieval-Augmented Generation (RAG) systems, as a key technology integrating information retrieval and Large Language Model (LLM) generation capabilities, enhance the accuracy and timeliness of LLM-generated answers by retrieving relevant document fragments from external knowledge bases in real time. RAG systems comprise two core modules: retrieval and generation. The retrieval module typically employs a two-stage process: initial semantic retrieval based on an embedding model and refined ranking based on a reranking model. The performance of the embedding and reranking models directly determines the quality of the final answers generated by the RAG system.

[0003] Training both the Embedding and Reranker models relies on high-quality negative samples, especially hard negative samples—those that are easily misclassified as positive samples by the model during training. These negative samples, along with positive samples, can improve the model's discrimination accuracy during training. However, the difficulty in efficiently and in batches generating such high-quality hard negative samples has become a major bottleneck restricting further performance improvements in RAG systems.

[0004] Therefore, there is an urgent need in this field for a technical solution that can automatically and intelligently generate high-quality, highly targeted difficult negative samples in order to further improve the retrieval performance of the RAG system. Summary of the Invention

[0005] The purpose of this application is to provide a method for generating difficult negative samples for documents, which solves the technical problems of low generation efficiency, low sample quality, and insufficient semantic discriminativeness in negative sample generation technology.

[0006] Firstly, this application provides a method for generating difficult negative samples of documents, the method comprising:

[0007] Based on recursive algorithms and large language models, the sampled documents are reconstructed into a three-level index structure to obtain a sample database. The three-level index structure includes a summary vector, text blocks, and a summary. For the question to be processed and the corresponding answer, multiple summary vectors related to the answer are generated by the large language model. Using the multiple summary vectors as search conditions, multiple sample data with similar summary vectors are selected from the sample database. The discriminator of the Generative Adversarial Network (GAN) determines the first probability that the multiple sample data correctly answers the question to be processed based on the summary and text blocks of the multiple sample data, and uses the sample data with the first probability below a threshold as candidate negative samples. Candidate negative samples whose similarity to the summary and the answer is higher than a threshold are selected as negative samples for sampling. The generator of the GAN generates difficult negative samples based on multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, and the logic is inconsistent. Based on the aforementioned difficult negative samples, generate document difficult negative samples.

[0008] Optionally, based on recursive algorithms and large language models, the sampled documents are reconstructed into a three-level index structure, including: The sampled document is divided into multiple text blocks using a recursive segmentation algorithm, with the summary vector as the level. Semantic analysis of the multiple text blocks is performed using a large language model to obtain corresponding summaries; The summary vector, the text block, and the summary are associated to form a three-level index structure.

[0009] Optionally, using the plurality of summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: The problem to be processed is input into a large language model to generate multiple summary vectors related to the answer; Select all summaries and text blocks corresponding to each summary vector from the sample database; The problem to be processed, the summary, and the text block are input into the large language model. It is determined whether the text block and the summary can correctly answer the problem to be processed. If they can answer it correctly, the summary and the text block are marked as true; otherwise, they are marked as false. Delete all summaries and text blocks marked as true, and keep the summaries and text blocks marked as false; Calculate the cosine similarity between all retained summaries and the answer; The top K summaries by cosine similarity and their corresponding text blocks are retained as candidate negative samples, where K is a positive integer.

[0010] Optionally, using the plurality of summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: Using the BGE algorithm, the embedding representation of the summary vector of each candidate negative sample is connected to the t most similar embedding representations to form a sample graph structure. Based on the K-means algorithm and the sample graph structure, obtain s centroids of the candidate negative sample; Based on the sample graph structure, the text blocks corresponding to the j nearest embeddings to each centroid are stored in the hard negative sample set L; For the remaining text blocks in the candidate text blocks that do not belong to the hard negative sample set, the m remaining text blocks with the fewest edges connected to the hard negative samples in the hard negative sample set are determined by iterative method. The m remaining text blocks are added to the hard negative sample set L as representative hard negative samples, where t, s, j and m are positive integers.

[0011] Optionally, the method further includes: The semantic loss term is used to increase the similarity between the difficult negative samples generated by the generator of the GAN model and the answer, and the logistic loss term is used to reduce the probability that the difficult negative samples generated by the generator of the GAN model correctly answer the question to be processed.

[0012] Optionally, the similarity between the difficult negative sample and the answer reaches an extreme value, and the logic is inconsistent, including: The semantic loss term is calculated by the discriminator of the GAN model. When the semantic loss term reaches its minimum value, it is determined that the similarity between the difficult negative sample and the answer has reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample and the answer generated by the generator of the GAN model, the vector similarity between the reconstructed questions and the questions, and the similarity loss between the difficult negative samples in the difficult negative sample set. The discriminator of the GAN model calculates a logistic loss term. When the logistic loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logistic loss term represents the probability that the difficult negative sample generated by the generator of the GAN model correctly answers the question.

[0013] Optionally, the similarity between the difficult negative sample and the answer reaches an extreme value, and the logic is inconsistent, including: The semantic loss term is calculated by the generator. When the semantic loss term reaches its minimum value, it is determined that the similarity between the difficult negative sample and the answer has reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample generated by the generator of the GAN model and the answer, as well as the vector similarity between the reconstructed questions and the questions. The generator calculates a logical loss term. When the logical loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logical loss term represents the probability that the negative sample generated by the generator of the GAN model is judged as true by the discriminator.

[0014] Optionally, the loss function includes a discriminator loss function and a generator loss function; The discriminator loss function is obtained by summing the products of the discriminator's true loss term and its corresponding weighting coefficient, the discriminator's semantic loss term and its corresponding weighting coefficient, and the discriminator's logical loss term and its corresponding weighting coefficient. The generator loss function is obtained by summing the product of the generator's true loss term, the generator's semantic loss term and the corresponding weighting coefficient, and the generator's logical loss term and the corresponding weighting coefficient.

[0015] On the other hand, embodiments of this application provide a document hard negative sample generation apparatus, including: The document structuring module is used to reconstruct the sampled documents into a three-level index structure based on recursive algorithms and large language models to obtain a sample database. The three-level index structure includes a summary vector, text blocks, and a summary. The negative sample filtering module is used to generate multiple summary vectors related to the answer through the large language model for the question to be processed and the corresponding answer, and select multiple sample data with similar summary vectors from the sample database using the multiple summary vectors as search conditions. A Generative Adversarial Network (GAN) model training module is used to determine the first probability that the multiple sample data correctly answer the question based on the GAN-based discriminator's summary and text blocks, and to select sample data with the first probability below a threshold as candidate negative samples. A GAN-based generator generates difficult negative samples based on the multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, while the logic is inconsistent. The document difficult negative sample generation module is used to generate document difficult negative samples based on the difficult negative samples.

[0016] This application also provides an apparatus for generating difficult negative samples of documents, including a memory and a processor. The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the above-described method for generating difficult negative samples of documents is implemented.

[0017] The beneficial effects of the technical solutions provided in this application include at least the following: This application embodiment splits documents into a three-level index structure, uses the summary vector as the filtering criterion to initially screen samples, uses the discriminator of a GAN to filter candidate negative samples that correctly answer questions, uses candidate negative samples with high semantic similarity as sampled negative samples, uses a generator to generate logically inconsistent difficult negative samples, combines the difficult negative samples to obtain document difficult negative samples, and uses document difficult negative samples to train the network, which can greatly improve the ability of large language models to answer questions and avoid incorrect answers caused by illusions. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments 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 of a document difficult negative sample generation method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a three-level index structure obtained by processing documents using LLM, provided in an embodiment of this application; Figure 3 This is a flowchart illustrating how to obtain a three-level index structure by processing documents using LLM, as provided in an embodiment of this application. Figure 4 This is a schematic diagram illustrating an embodiment of the present application for retrieving samples with similar summary vectors using LLM; Figure 5 This is a schematic diagram of the structure of a GAN provided in an embodiment of this application; Figure 6 This is a schematic diagram of a sample diagram structure provided in an embodiment of this application; Figure 7 This is a schematic diagram illustrating the training of an Embedding model and a Reranker model using difficult negative samples generated by GAN, as provided in an embodiment of this application. Detailed Implementation

[0020] The present application will be described in detail below with reference to the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present application. Any structural, methodological, or functional modifications made by those skilled in the art based on these embodiments are included within the protection scope of the present application.

[0021] In some documents converted from speech to text, or meeting minutes, the speakers and logical order of the text are not necessarily arranged in chronological order. When organizing these documents (formats can be, but are not limited to, Word, PDF, PPT, etc.), it is necessary to organize their semantics and logic.

[0022] When using a generalized large language model (LLM) to process documents containing massive amounts of text, the LLM's semantic understanding capabilities are limited and logical errors are frequently observed. To improve the accuracy of document processing, this application's method utilizes a recursive algorithm and the semantic analysis capabilities of the LLM to reconstruct sampled documents into a three-level index structure of "summary vector - text block - summary," obtaining a sample database that lays a solid foundation for generating high-quality samples. A dual screening process, employing answer correctness judgment and answer similarity calculation, automatically and intelligently mines sampled negative samples from the sample database that are linguistically similar but logically inconsistent and easily confused, providing high-quality seeds for subsequent generation. By training a generative adversarial network (GAN) model using sampled negative samples in conjunction with a specific loss function, the generated difficult negative samples not only exhibit high semantic similarity to the standard answers but also possess logically plausible deception. The trained GAN can efficiently and effectively generate a large number of difficult negative samples. The document processing model trained using these difficult negative samples can better process the logic and semantics within documents, improving the accuracy of subsequent responses to questions input from documents.

[0023] The document hard negative sample generation method provided in this application embodiment can be achieved through, for example, Figure 1 The steps shown are implemented, and the steps include: Step 101: Based on the recursive algorithm and the large language model, the sampled documents are reconstructed into a three-level index structure to obtain the sample database. The three-level index structure includes a summary vector, text blocks, and a summary. Step 102: For the question to be processed and the corresponding answer, generate multiple summary vectors related to the answer through the large language model, and select multiple sample data with similar summary vectors from the sample database using the multiple summary vectors as search conditions; Step 103: Based on the summary and text blocks of the multiple sample data, the discriminator of the Generative Adversarial Network (GAN) determines the first probability that the multiple sample data correctly answers the question to be processed, and the sample data with the first probability below the threshold are taken as candidate negative samples. Step 104: Select candidate negative samples whose similarity to the summary and the answer is higher than a threshold as negative samples for sampling; Step 105: The generator of the GAN generates difficult negative samples based on multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss terms and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, and the logic is inconsistent.

[0024] For example, such as Figure 2 As shown, step 101 uses a recursive algorithm to segment the sampled document according to the summary vector hierarchy, obtaining multiple semantically coherent text blocks. A certain overlap area is maintained between adjacent text blocks to ensure the integrity of the content. Semantic analysis of the text blocks is performed through a large language model to obtain a summary. Metadata annotation is used to establish the association between the summary vector, text blocks, and summaries, forming a three-level index structure of "summary vector-text block-summary" to obtain sample data, and finally, a sample database containing a large amount of sample data is obtained.

[0025] For example, based on recursive algorithms and large language models, sampled documents can be reconstructed into a three-level index structure, which can be achieved through methods such as... Figure 3 The steps shown are as follows: Step 301: Using a recursive segmentation algorithm, the sampled document is divided into multiple text blocks at the level of the summary vector; Step 302: Perform semantic analysis on the multiple text blocks using a large language model to obtain the corresponding summary; Step 303: Associate the summary vector, the text block, and the summary to form a three-level index structure.

[0026] The three-level index structure is stored in the DB (database).

[0027] For example, through steps 102 to 104, negative samples are filtered based on LMM discrimination and similarity calculation for the question to be processed and the corresponding answer, resulting in sampled negative samples. The negative sample filtering process is as follows: Figure 4 As shown.

[0028] The question is input into an LLM (Library Module), and the LLM outputs a document summary vector (title) of the candidate documents that may contain the top n probabilities of the answer; the candidate documents are then input into a database. Based on the candidate summary vectors of the candidate documents, the corresponding chunks and summaries are matched, and the LLM determines whether these chunks and summaries can answer the question. LLM filtering removes Chunks (positive samples) marked as True and retains Summaries marked as False (negative samples).

[0029] LLM generates N chunks with the highest semantic similarity to answer 'a' based on negative samples labeled 'False', and uses these as candidate chunks.

[0030] See Figure 5 As shown, based on candidate chunks, a difficult negative sample can be generated through an adversarial generative network (GAN). The GAN includes a discriminator D and a generator G. The discriminator judges the authenticity, semantic relevance, and logical coherence of the chunk content. For example, it judges authenticity through an authenticity loss term, semantic relevance through a semantic loss term, and logical coherence through a logical loss term. The generator G learns to generate chunks that are semantically similar to the question but logically deviate from it as difficult negative samples through adversarial training.

[0031] Optionally, using the plurality of summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: The problem to be processed is input into a large language model to generate multiple summary vectors related to the answer; Select all summaries and text blocks corresponding to each summary vector from the sample database; The problem to be processed, the summary, and the text block are input into the large language model. It is determined whether the text block and the summary can correctly answer the problem to be processed. If they can answer it correctly, the summary and the text block are marked as true; otherwise, they are marked as false. Delete all summaries and text blocks marked as true, and keep the summaries and text blocks marked as false; Calculate the cosine similarity between all retained summaries and the answer; The top K summaries by cosine similarity and their corresponding text blocks are retained as candidate negative samples, where K is a positive integer.

[0032] Optionally, using the plurality of summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: Using the BGE algorithm, the embedding representation of the summary vector of each candidate negative sample is connected to the t most similar embedding representations to form a sample graph structure. Based on the K-means algorithm and the sample graph structure, obtain s centroids of the candidate negative sample; Based on the sample graph structure, the text blocks corresponding to the j nearest embeddings to each centroid are stored in the hard negative sample set L; For the remaining text blocks in the candidate text blocks that do not belong to the hard negative sample set, the m remaining text blocks with the fewest edges connected to the hard negative samples in the hard negative sample set are determined by iterative method. The m remaining text blocks are added to the hard negative sample set L as representative hard negative samples, where t, s, j and m are positive integers.

[0033] In this way, the j text blocks with the highest similarity and the m text blocks with the highest representativeness can be used as hard negative samples, thereby increasing the diversity of hard negative samples.

[0034] For example, see Figure 6 As shown, the BGE algorithm is used to embed the summary vectors of the n chunks of the candidate negative samples. Each chunk is connected to its five closest chunks via edges, constructing a sample graph structure G=(V,E), where V represents the chunk node and E represents the edges based on the nearest similarity. The embedding representations of the summary vectors of the n chunks are clustered using the K-means algorithm to obtain s centroids. Combining this with the sample graph structure, the chunks corresponding to the j nearest embedding representations to each centroid are calculated. Since the nearest embedding representations corresponding to the s centroids may have duplicates, the j chunks corresponding to the embedding representations can be obtained by deduplication. These j chunks are then stored as hard negative samples in the hard negative sample set L.

[0035] For the remaining text blocks in the candidate text blocks that do not belong to the hard negative sample set, an iterative method is used to determine the m remaining text blocks in the sample graph structure that have the fewest edges connected to the hard negative samples in the hard negative sample set. In each round of iteration, the text block with the highest screening score can be selected using the following formula. In this way, after m rounds of iteration, m remaining text blocks can be obtained.

[0036] Score(u) = max(s (v)), (u,v)∈E,

[0037] Where u represents the summary vector of the candidate text block, and v represents the 5 nearest neighbor nodes of the summary vector of the candidate text block. Indicates a specified constant. Let L represent the set of difficult negative samples.

[0038] For example, the authenticity loss term can be obtained through the following process: The discriminator D can be trained using the truth loss function in the following way:

[0039] Among them, L DThis represents the discriminator, where α, β, and γ represent constants. This represents the initial loss function used by the GAN to distinguish between real and generated sample data.

[0040]

[0041] in, Represents a real sample; Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); This represents the data distribution of the real samples; Indicates noise distribution; This represents the generated samples produced by the generator based on the noise z; This represents the probability (a probability value between 0 and 1) that the discriminator outputs a true sample.

[0042] First item : Indicates the discriminator's ability to identify real samples, when The time discriminator determines that it is a real sample. When the maximum value is reached, the discriminator can accurately identify the real sample.

[0043] Second item : Indicates the discriminator's ability to recognize generated samples, when The time discriminator determines that it is a generated sample. When the minimum value is reached, the discriminator can accurately identify the generated sample.

[0044] When the result corresponding to each loss function is maximized (the corresponding discriminator reaches its optimization objective), when both the first and second terms are optimal: the first term makes... The second item is determined to be a real sample. The determination that it is not a generated sample reflects the discriminator's overall ability to distinguish between real samples and generated samples.

[0045] Thus, after the discriminator of the large language model has the ability to identify real samples and generate samples, the discriminator of the large language model determines the first probability of the multiple sample data correctly answering the question to be processed, and the sample data with the first probability below the threshold are taken as candidate negative samples. Candidate negative samples whose similarity to the summary and the answer is higher than a threshold are selected as negative samples for sampling.

[0046] Generative Adversarial Network (GAN) models generate difficult negative samples based on multiple sampled negative samples. For example, the generator compares the summary vectors of the generated samples and the summary vectors of the answers generated by the generator based on the noise z, and the summary vectors of the reconstructed questions and answers for the generated samples through LLM, with the similarity loss between the summary vectors of the generator's generated samples and answer pairs and the reconstructed questions and answers pairs as a semantic loss term.

[0047] The semantic loss term is calculated using the discriminator of the GAN model. When the semantic loss term reaches its minimum value, the similarity between the difficult negative sample and the answer is determined to have reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample generated by the generator of the GAN model and the answer, the vector similarity between the reconstructed questions and the questions, and the similarity loss between difficult negative samples in the difficult negative sample set. The semantic loss term can be obtained in the following way:

[0048] in, Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); Indicate the answer; τ represents the similarity threshold; This represents the generated samples produced by the generator based on the noise z; This represents the probability (a probability value between 0 and 1) that the discriminator outputs a true sample. The embedding vector representing the answer; This indicates the question corresponding to the answer; This represents the problem of reconstructing generated samples from G(z) using LLM.

[0049]

[0050] S(G(z)) represents the similarity loss between the generated samples of G(z) and the hard negative samples in the hard negative sample set by LLM.

[0051] The discriminator of the GAN model calculates a logistic loss term. When the logistic loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logistic loss term represents the probability that the difficult negative sample generated by the generator of the GAN model correctly answers the question.

[0052] The logical loss term is obtained using the following formula:

[0053] in, Represents a real sample; Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); This represents the data distribution of the real samples; Indicates noise distribution; This indicates whether the question can be answered by the current sample's chunk and context; This represents the probability (a probability value between 0 and 1) that the discriminator outputs a true sample.

[0054] The loss function of this logistic loss term is essentially binary cross-entropy loss. When the time indicates that the question can be answered by the current sample, the loss is simplified to Discriminator output This indicates that the discriminator can correctly identify that the current sample can answer the question. When the time condition is met, it indicates that the question cannot be answered by the current sample, and the loss is simplified to Discriminator output This indicates that the discriminator can correctly identify that the sample cannot answer the question. Thus, by minimizing the logistic loss term, the discriminator D can be trained as a logistic judge capable of distinguishing whether a sample has the ability to answer a question.

[0055] The discriminator loss function is obtained by summing the products of the discriminator's true loss term and its corresponding weighting coefficient, the discriminator's semantic loss term and its corresponding weighting coefficient, and the discriminator's logical loss term and its corresponding weighting coefficient. The generator loss function is obtained by summing the products of the generator's true loss term, the generator's semantic loss term and the corresponding weighting coefficients, and the generator's logical loss term and the corresponding weighting coefficients.

[0056] For example, the discriminator's output can be obtained by summing the authenticity loss term, semantic loss term, and logical loss term according to their respective weights. This allows for the training of algorithms that can identify difficult negative samples that possess realism, semantic similarity, and logical irrelevance. For the discriminator's true loss item, For the discriminator semantic loss term, For the discriminator logic loss term, α, β and γ are the corresponding weighting coefficients, which can be preset constant parameters.

[0057] The loss function for training the generator is designed as follows:

[0058] in This represents the generator's true loss term. For the generator semantic loss term, For generator logical loss term, μ and μ are the corresponding weighting coefficients, which can be preset constant parameters.

[0059] The semantic loss term is calculated by the generator. When the semantic loss term reaches its minimum value, it is determined that the similarity between the difficult negative sample and the answer has reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample generated by the generator of the GAN model and the answer, as well as the vector similarity between the reconstructed questions and the questions. The generator calculates a logical loss term. When the logical loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logical loss term represents the probability that the negative sample generated by the generator of the GAN model is judged as true by the discriminator.

[0060] 1. Actual Loss Items

[0061] in, Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); Indicates noise distribution; This represents the generated samples produced by the generator based on the noise z; The true loss term function represents the generator's attempt to maximize the probability of the discriminator misclassifying the generated samples.

[0062] when At times: The discriminator misclassifies generated samples as real samples. Reaching the maximum value indicates that the generator has successfully deceived the discriminator.

[0063] The ideal state for generating difficult negative samples: (This state indicates that the discriminator cannot distinguish the authenticity of the samples generated by the generator.)

[0064] 2. Semantic loss term

[0065] in, Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); Indicate the answer; τ represents the similarity threshold; This represents the generated samples produced by the generator based on the noise z; This represents the probability (a probability value between 0 and 1) that the discriminator outputs a true sample. The embedding vector representing the answer.

[0066] The semantic loss function is the same as that of the discriminator, requiring the generation of samples and answers. The cosine similarity must reach at least the threshold. This ensures that the generated samples are semantically similar to the answer. If the similarity is lower than [a certain value], [the sample will be considered]. If the loss value is positive, it guides the generator to optimize semantic relevance; if it is higher... The loss value is 0, thus avoiding over-optimization.

[0067] 3. Logical loss term × PPL(q_hat, a) in, Represents a real sample; Represents a random vector derived from a prior noise distribution (such as a Gaussian distribution); This represents the data distribution of the real samples; Indicates noise distribution; This indicates whether the question can be answered by the current sample's chunk and context; This represents the probability (a probability value between 0 and 1) that the discriminator outputs a true sample. The embedding vector representing the answer; This indicates the question corresponding to the answer; This represents the problem of reconstructing generated samples from G(z) using LLM; PPL represents the perplexity level of an LLM, indicating whether an LLM can provide a true answer. .

[0068]

[0069] Where x i Let represent the i-th chunk of text, S represent the entire text sequence of the input LLM, and n represent the number of chunks of text in the text sequence.

[0070] If the sample generated by the generator is logically irrelevant (i.e., cannot answer question q), the discriminator should classify it as "false". ;at this time Minimizing the loss value means the generator doesn't need adjustment; if the discriminator misclassifies logically irrelevant samples as "true" (i.e., ... As the loss value increases, the generator needs to be optimized to generate more difficult and subtle negative samples that are harder to distinguish. The discriminator's gradient signal guides the generator to generate logically unrelated but semantically similar samples.

[0071] pass This allows you to train a generator that produces more realistic, semantically relevant, and logically independent samples.

[0072] Thus, after training the discriminator and generator, the discriminator D integrates the capabilities of content authenticity judgment, question-answer semantic relevance analysis, and logical coherence detection; the generator G learns to generate difficult negative samples with semantically similar but logically unrelated characteristics through adversarial training.

[0073] Reference Figure 7 As shown, multiple difficult negative samples are combined with question-answer pairs according to a three-level index structure to train the Embedding model and the Reranker model. In this way, after generating difficult negative samples, the difficult negative samples can be used to generate a three-level index structure through the trained Embedding model, and then rearranged through the Reranker model to obtain a more accurate answer.

[0074] This application also provides a document processing method, including: After inputting the document to be processed into the document processing model, a reconstructed document based on a three-level index structure is obtained. The corresponding answer is obtained based on the reconstructed document. The document processing model is trained on the difficult negative samples generated by the document difficult negative sample generation method mentioned above. The document processing model includes an Embedding model and a Reranker model.

[0075] On the other hand, embodiments of this application provide a document hard negative sample generation apparatus, including: The document structuring module is used to reconstruct the sampled documents into a three-level index structure based on recursive algorithms and large language models to obtain a sample database. The three-level index structure includes a summary vector, text blocks, and a summary. The negative sample filtering module is used to generate multiple summary vectors related to the answer through the large language model for the question to be processed and the corresponding answer, and select multiple sample data with similar summary vectors from the sample database using the multiple summary vectors as search conditions. A Generative Adversarial Network (GAN) model training module is used to determine the first probability that the multiple sample data correctly answer the question based on the GAN-based discriminator's summary and text blocks, and to select sample data with the first probability below a threshold as candidate negative samples. A GAN-based generator generates difficult negative samples based on the multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, while the logic is inconsistent. The document difficult negative sample generation module is used to generate document difficult negative samples based on the difficult negative samples.

[0076] This application also provides an apparatus for generating difficult negative samples of documents, including a memory and a processor. The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the above-described method for generating difficult negative samples of documents is implemented.

[0077] This application also provides a document processing device, including a memory and a processor. The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the above-described document processing method is implemented.

[0078] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. A and B can be singular or plural. Additionally, the character " / " in this article generally indicates an "or" relationship between the preceding and following related objects, but it can also represent an "and / or" relationship. Please refer to the context for a more accurate understanding.

[0079] In this invention, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of a single item or a plurality of items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be a single item or multiple items.

[0080] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, 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. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.

[0081] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0082] The above are merely preferred embodiments of this application and are not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A method for generating difficult negative samples for documents, characterized in that, The method includes: Based on recursive algorithms and large language models, the sampled documents are reconstructed into a three-level index structure to obtain a sample database. The three-level index structure includes a summary vector, text blocks, and a summary. For the question to be processed and the corresponding answer, multiple summary vectors related to the answer are generated by the large language model. Using the multiple summary vectors as search conditions, multiple sample data with similar summary vectors are selected from the sample database. The discriminator of the Generative Adversarial Network (GAN) determines the first probability that the multiple sample data correctly answers the question to be processed based on the summary and text blocks of the multiple sample data, and uses the sample data with the first probability below a threshold as candidate negative samples. Candidate negative samples whose similarity to the summary and the answer is higher than a threshold are selected as negative samples for sampling. The generator of the GAN generates difficult negative samples based on multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, and the logic is inconsistent. Based on the aforementioned difficult negative samples, generate document difficult negative samples.

2. The method as described in claim 1, characterized in that, Based on recursive algorithms and large language models, the sampled documents are restructured into a three-level index structure, including: The sampled document is divided into multiple text blocks using a recursive segmentation algorithm, with the summary vector as the level. Semantic analysis of the multiple text blocks is performed using a large language model to obtain corresponding summaries; The summary vector, the text block, and the summary are associated to form a three-level index structure.

3. The method as described in claim 1, characterized in that, Using the multiple summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: The problem to be processed is input into a large language model to generate multiple summary vectors related to the answer; Select all summaries and text blocks corresponding to each summary vector from the sample database; The problem to be processed, the summary, and the text block are input into the large language model. It is determined whether the text block and the summary can correctly answer the problem to be processed. If they can answer it correctly, the summary and the text block are marked as true; otherwise, they are marked as false. Delete all summaries and text blocks marked as true, and keep the summaries and text blocks marked as false; Calculate the cosine similarity between all retained summaries and the answer; The top K summaries by cosine similarity and their corresponding text blocks are retained as candidate negative samples, where K is a positive integer.

4. The method as described in claim 3, characterized in that, Using the multiple summary vectors as search criteria, multiple sample data with similar summary vectors are selected from the sample database, including: Using the General Semantic Vector Model (BGE) algorithm, the embedding representation of the summary vector of each candidate negative sample is connected to the t most similar embedding representations to form a sample graph structure. Based on the K-means algorithm and the sample graph structure, obtain s centroids of the candidate negative sample; Based on the sample graph structure, the text blocks corresponding to the j nearest embeddings to each centroid are stored in the hard negative sample set L; For the remaining text blocks in the candidate text blocks that do not belong to the hard negative sample set, the m remaining text blocks with the fewest edges connected to the hard negative samples in the hard negative sample set are determined by iterative method. The m remaining text blocks are added to the hard negative sample set L as representative hard negative samples, where t, s, j and m are positive integers.

5. The method as described in claim 1, characterized in that, The method further includes: The semantic loss term is used to increase the similarity between the difficult negative samples generated by the generator of the GAN model and the answer, and the logistic loss term is used to reduce the probability that the difficult negative samples generated by the generator of the GAN model correctly answer the question to be processed.

6. The method as described in claim 4, characterized in that, The similarity between the difficult negative sample and the answer reaches an extreme value, and the logic is inconsistent, including: The semantic loss term is calculated by the discriminator of the GAN model. When the semantic loss term reaches its minimum value, it is determined that the similarity between the difficult negative sample and the answer has reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample and the answer generated by the generator of the GAN model, the vector similarity between the reconstructed questions and the questions, and the similarity loss between the difficult negative samples in the difficult negative sample set. The discriminator of the GAN model calculates a logistic loss term. When the logistic loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logistic loss term represents the probability that the difficult negative sample generated by the generator of the GAN model correctly answers the question.

7. The method as described in claim 1, characterized in that, The similarity between the difficult negative sample and the answer reaches an extreme value, and the logic is inconsistent, including: The semantic loss term is calculated by the generator. When the semantic loss term reaches its minimum value, it is determined that the similarity between the difficult negative sample and the answer has reached its extreme value. The semantic loss term is calculated based on the vector similarity between the difficult negative sample generated by the generator of the GAN model and the answer, as well as the vector similarity between the reconstructed questions and the questions. The generator calculates a logical loss term. When the logical loss term reaches its minimum, it is determined that the difficult negative sample is logically inconsistent with the answer. The logical loss term represents the probability that the negative sample generated by the generator of the GAN model is judged as true by the discriminator.

8. The method as described in claim 1, characterized in that, The loss function includes a discriminator loss function and a generator loss function; The discriminator loss function is obtained by summing the products of the discriminator's true loss term and its corresponding weighting coefficient, the discriminator's semantic loss term and its corresponding weighting coefficient, and the discriminator's logical loss term and its corresponding weighting coefficient. The generator loss function is obtained by summing the product of the generator's true loss term, the generator's semantic loss term and the corresponding weighting coefficient, and the generator's logical loss term and the corresponding weighting coefficient.

9. A document hard negative sample generation device, characterized in that, include: The document structuring module is used to reconstruct the sampled documents into a three-level index structure based on recursive algorithms and large language models to obtain a sample database. The three-level index structure includes a summary vector, text blocks, and a summary. The negative sample filtering module is used to generate multiple summary vectors related to the answer through the large language model for the question to be processed and the corresponding answer, and select multiple sample data with similar summary vectors from the sample database using the multiple summary vectors as search conditions. A Generative Adversarial Network (GAN) model training module is used to determine the first probability that the multiple sample data correctly answer the question based on the GAN-based discriminator's summary and text blocks, and to select sample data with the first probability below a threshold as candidate negative samples. A GAN-based generator generates difficult negative samples based on the multiple sampled negative samples, and trains the GAN model using a loss function that includes semantic loss and logical loss terms, so that the similarity between the difficult negative samples and the answer reaches an extreme value, while the logic is inconsistent. The document difficult negative sample generation module is used to generate document difficult negative samples based on the difficult negative samples.

10. An apparatus for generating difficult negative samples of documents, comprising a memory and a processor, characterized in that, The memory stores computer-readable instructions, which, when executed by the processor, implement the document hard negative sample generation method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • A Chinese abstract generation method and device based on a generative adversarial network

    CN109766432A

  • Text generation method based on generative adversarial network

    CN112560438A

  • Text abstract model production method and device, equipment and medium

    CN115129819A

  • Method, device, and medium for consistency detection of a document and an abstract

    US20240232245A1

  • Model training method and related apparatus

    WO2021204014A1