A knowledge enhancement method and apparatus based on an embedding model
By employing a knowledge augmentation method based on the embedding model, documents are segmented and clustered, improving the retrieval accuracy and fairness of the question-answering system, resolving the class imbalance problem, and generating higher-quality answers.
Patent Information
- Application Number
- CN202511576887.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-31
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2045-10-31
AI Technical Summary
In traditional question-answering systems, the imbalance between document categories leads to low retrieval accuracy and poor answer generation quality, which negatively impacts user experience.
By employing a knowledge enhancement method based on the embedding model, documents are segmented into semantically complete text blocks, clustered, and document weights are calculated. The embedding model is then trained to improve the ability to capture minority class features, and the similarity distance between the question vector and the generated question vector is calculated for recall.
It improves the diversity of search results and the recall rate of minority documents, ensures fair and accurate matching of knowledge across categories, generates more accurate answers, and improves user experience.
Smart Images

Figure CN121029960B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge enhancement technology, and specifically to a knowledge enhancement method and apparatus based on an embedding model. Background Technology
[0002] Traditional question-and-answer systems receive user-uploaded questions and documents, retrieve matching content from the documents, and generate answers. However, user-uploaded documents often exhibit an uneven distribution in terms of topics and content categories. Taking the government and energy sectors as examples, there are a large number of government regulations documents, but relatively few documents interpreting emerging policies; in the energy sector, there is a wealth of documents on common energy technologies, but documents related to new energy technologies are scarce.
[0003] This class imbalance negatively impacts retrieval recall. Because majority class documents are overwhelmingly numerous, the system dedicates most of its resources and attention during training to learning their feature patterns. Meanwhile, minority class documents, with their limited sample size, struggle to fully explore and learn their features. When users ask questions about minority class content, the system struggles to accurately match and retrieve relevant information from the massive document pool, resulting in low retrieval accuracy, poor answer quality, and ultimately, a negative user experience. Summary of the Invention
[0004] In view of this, the present invention provides a knowledge enhancement method and apparatus based on an embedding model to solve the problem that low retrieval accuracy is caused by class imbalance, which in turn leads to poor answer generation quality and ultimately affects user experience.
[0005] In a first aspect, the present invention provides a knowledge enhancement method based on an embedding model, the method comprising:
[0006] Obtain the target question and at least one original document uploaded by the user;
[0007] Each original document is segmented into multiple text blocks, and question-answer pairs are generated for each text block. The question-answer pairs include the generated question and the generated answer.
[0008] The initial embedding model is used to convert each original document into an original vector, and clustering is performed based on all original vectors to obtain multiple cluster categories and the document weight of the original document corresponding to each original vector. The cluster category represents the semantic topic.
[0009] An initial embedding model is trained based on multiple clustering categories to obtain the target embedding model;
[0010] A target embedding model is used to convert the target question and the generated question in each question-answer pair into a target question vector and a generated question vector, respectively.
[0011] Based on the document weight corresponding to each original document, the similarity distance between the target question vector and each generated question vector is calculated, and the target document is recalled from at least one original document based on the similarity distance.
[0012] This invention acquires user-uploaded original documents, segments them into semantically complete text blocks, and generates targeted question-and-answer pairs, providing a richer knowledge base for subsequent retrieval. An initial embedding model is used to convert the original documents into vectors and cluster them, grouping semantically similar documents into one category, resulting in multiple clusters, and calculating document weights. The initial embedding model is trained based on these clusters to enhance its ability to capture category features, especially minority class features. Using the trained model to generate vectors, the weighted similarity distance between the user's target question vector and each generated question vector in the question-and-answer pair is calculated. During recall, the recall order is intelligently adjusted based on the similarity distance, improving the diversity of search results and the recall rate of minority class documents. This ensures that knowledge from all categories is matched fairly and accurately, effectively improving the accuracy and fairness of retrieval and retrieving information, thus solving the problem of class imbalance. This allows for the generation of more accurate and higher-quality question answers from target documents, exhibiting stronger generalization and adaptability when facing novel questions, and effectively improving the user experience.
[0013] In one optional implementation, clustering is performed based on all original vectors to obtain multiple cluster categories and document weights of the original documents corresponding to each original vector, including:
[0014] Clustering is performed based on all the original vectors to obtain multiple cluster categories;
[0015] For each cluster category, determine the number of all original vectors belonging to the cluster category, and determine the total number of all original vectors;
[0016] The ratio of the number of vectors to the total number of vectors is used to determine the proportion of cluster categories.
[0017] The inverse of the proportion of cluster categories is used to determine the document weight of the original document corresponding to each original vector belonging to a cluster category.
[0018] This invention clusters all original vectors to obtain multiple cluster categories, each corresponding to a unique semantic topic. The ratio of the number of vectors in each cluster to the total number of vectors is determined as the proportion of the cluster category, which intuitively reflects the quantitative differences between categories. The reciprocal of the proportion of each cluster category is determined as the document weight, giving higher weight to documents in the minority category, which helps to solve the problem of class imbalance.
[0019] In one alternative implementation, the method further includes:
[0020] Identify the cluster categories to be generated that have a proportion less than a preset threshold;
[0021] For each original vector in the cluster category to be generated, generate question-answer pairs for each text block of the original document corresponding to the original vector.
[0022] This invention improves the matching probability of minority class documents during retrieval by regenerating question-answer pairs when the proportion of cluster categories is less than a preset threshold, thus preventing them from being ignored due to the small number of original documents and further solving the problem of class imbalance.
[0023] In one optional implementation, an initial embedding model is trained based on multiple clustering categories to obtain a target embedding model, including:
[0024] For each cluster category, the center vector and category weight of the cluster category are calculated based on all the original vectors belonging to the cluster category;
[0025] For each original vector, use it as a query and the center vector of the cluster to which the original vector belongs as the key and value to calculate the attention weight of the original vector.
[0026] Based on the attention weights of the original vectors and the center vectors of the clusters to which the original vectors belong, the original vectors are weighted and fused to obtain the enhanced vectors corresponding to the original vectors.
[0027] Using cluster categories as labels, the initial embedding model is used to predict augmentation vectors and obtain prediction probabilities, which represent the probability that the augmentation vector belongs to a cluster category.
[0028] The training loss is calculated based on each original vector, the class weight of the cluster to which each original vector belongs, and the predicted probability of the augmented vector corresponding to each original vector.
[0029] The model parameters of the initial embedding model are updated based on the training loss. The above process of prediction and calculation of training loss is repeated until the training loss is minimized. The initial embedding model after the last update of model parameters is used as the target embedding model.
[0030] This invention improves the model's ability to learn category semantics, especially minority class features, through attention fusion and weighted loss. This provides a reliable semantic representation foundation for subsequent question and document embedding conversion and retrieval matching, ensuring accurate recall of relevant documents, including minority class documents, during the retrieval stage.
[0031] In one alternative implementation, the cluster weights are calculated using the following formula:
[0032]
[0033] In the formula, Indicates the first The cluster category to which the original vectors corresponding to each original document belong; Represents the class weights of the cluster categories; This represents the number of original vectors that belong to the cluster category.
[0034] This invention calculates category weights based on the number of original vectors contained in each cluster category, which can assign higher weights to cluster categories with fewer documents, thus helping to solve the category imbalance problem.
[0035] In one optional implementation, based on the document weight corresponding to each original document, the similarity distance between the target question vector and each generated question vector is calculated, including:
[0036] Calculate the cosine similarity between the target question vector and each generated question vector;
[0037] The similarity distance between the generated question vector and the target question vector is determined by multiplying the document weight of the original document corresponding to the generated question vector with the cosine similarity.
[0038] This invention introduces document weights to calculate similarity. Even if the generated question of a minority class document has a slightly lower original similarity to the target question, it can still rank higher in the ranking due to its higher document weight. This avoids being masked by majority class documents due to the small number of original documents, thereby improving the diversity of search results and the recall rate of minority class documents. It ensures that knowledge of all categories can be matched fairly and accurately, thus improving the quality of answer generation.
[0039] In one alternative implementation, generating question-answer pairs for each text block includes:
[0040] Construct prompts for each text block; these prompts are used to standardize the generation target and output format.
[0041] Using a large language model, question-answer pairs are generated for each text block based on the prompt words.
[0042] This invention effectively expands knowledge by using a large language model to generate question-and-answer pairs that fit the content of text blocks, guided by prompt words.
[0043] Secondly, the present invention provides a knowledge enhancement device based on an embedding model, the device comprising:
[0044] The acquisition module is used to acquire the target question uploaded by the user and at least one original document;
[0045] The first generation module is used to segment each original document to obtain multiple text blocks of the original document, and generate question-answer pairs for each text block. The question-answer pairs include generating questions and generating answers.
[0046] The clustering module is used to convert each original document into an original vector using an initial embedding model, and to perform clustering based on all original vectors to obtain multiple cluster categories and the document weight of the original document corresponding to each original vector. The cluster categories represent semantic topics.
[0047] The training module is used to train an initial embedding model based on multiple clustering categories to obtain the target embedding model;
[0048] The transformation module is used to use the target embedding model to convert the target question and the generated question in each question-answer pair into a target question vector and a generated question vector, respectively.
[0049] The recall module is used to calculate the similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, and to recall the target document from at least one original document based on the similarity distance.
[0050] Thirdly, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the knowledge enhancement method based on the embedding model described in the first aspect or any corresponding embodiment thereof.
[0051] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the knowledge enhancement method based on the embedding model described in the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0052] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0053] Figure 1 This is a flowchart illustrating a knowledge enhancement method based on an embedding model according to an embodiment of the present invention.
[0054] Figure 2 This is a flowchart illustrating another knowledge enhancement method based on an embedding model according to an embodiment of the present invention;
[0055] Figure 3 This is a structural block diagram of a knowledge enhancement device based on an embedding model according to an embodiment of the present invention;
[0056] Figure 4 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0058] Traditional question-answering systems often suffer from an imbalance in the distribution of user-uploaded documents across topics and content categories. When users ask questions about a minority of categories, the system struggles to accurately match and retrieve relevant information from a massive database, resulting in low retrieval accuracy and consequently, poor-quality answers, ultimately impacting user experience. This invention addresses this issue by enhancing the diversity of search results and the recall rate of minority documents, ensuring fair and accurate matching across all knowledge categories. This effectively improves the accuracy and fairness of retrieval, resolving the category imbalance problem and enabling the generation of more accurate and higher-quality answers from target documents, thus significantly improving user experience.
[0059] According to an embodiment of the present invention, a knowledge enhancement method based on an embedding model is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0060] This embodiment provides a knowledge enhancement method based on an embedding model, which can be used in question-answering systems. It has intelligent question-answering, knowledge retrieval, knowledge expansion, and personalized service capabilities. It supports multi-turn dialogue, can accurately retrieve knowledge according to user needs, automatically expand knowledge, and provide exclusive services based on user habits. It can be applied to scenarios such as government public consultation, staff assistance, and internal knowledge sharing and industry knowledge services in energy enterprises. It can improve the efficiency of government services, promote knowledge exchange in the energy field, and has both social and economic benefits.
[0061] Figure 1 This is a flowchart of a knowledge enhancement method based on an embedding model according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps:
[0062] Step S101: Obtain the target question uploaded by the user and at least one original document.
[0063] Specifically, users, as data providers, upload two types of key information: first, the target question to be answered; and second, original documents, i.e., reference materials that may contain answers to the target question. These two constitute the data source for subsequent retrieval and recall. The system will then process these original documents to retrieve documents related to the target question, thereby generating the answer to the target question based on the retrieved documents.
[0064] Step S102: Segment each original document to obtain multiple text blocks of the original document, and generate question-answer pairs for each text block. The question-answer pairs include generating questions and generating answers.
[0065] Specifically, an initial embedding model is used in conjunction with a fixed-length rule to segment each original document into multiple text blocks of uniform length. The embedding model helps identify semantic boundaries, and the fixed length ensures that each text block has a consistent length after segmentation, resulting in multiple text blocks containing relatively complete semantic information. This avoids the loss of key information or semantic fragmentation during subsequent processing due to excessive document length. For each segmented text block, question-answer pairs are generated around its core content to expand knowledge.
[0066] Step S103: The initial embedding model is used to convert each original document into an original vector, and clustering is performed based on all the original vectors to obtain multiple cluster categories and the document weight of the original document corresponding to each original vector. The cluster category represents the semantic topic.
[0067] Specifically, an initial embedding model is used to convert the original documents into raw vectors, transforming unstructured text into structured semantic units, facilitating subsequent retrieval, analysis, and management, and laying the foundation for semantic indexing. All raw vectors are normalized to eliminate interference from vector scale differences in subsequent clustering. Then, all raw vectors are clustered, grouping vectors with similar semantics together to form multiple cluster categories. Each cluster category represents a potential semantic topic, achieving semantic grouping of documents. Based on clustering, the document weight of the original document corresponding to each raw vector is determined, which helps to alleviate the problem of class imbalance in subsequent operations based on document weights.
[0068] Step S104: Train an initial embedding model based on multiple clustering categories to obtain the target embedding model.
[0069] Specifically, in order to enable the embedding model to better capture the semantic features of different cluster categories, especially to improve its ability to learn minority class features, the cluster categories obtained from clustering are used as labels to train the initial embedding model. This makes the model pay more attention to minority class features during training, which helps to deal with the class imbalance problem and lays the foundation for accurate retrieval in the future.
[0070] Step S105: Using the target embedding model, the target question and the generated question in each question-answer pair are converted into a target question vector and a generated question vector, respectively.
[0071] Specifically, the target embedding model, optimized for class imbalance, can more accurately capture the semantic features of different classes, especially the semantic features of the minority class. Compared to the initial model, it is more suitable for handling text vector conversions with class differences, improving the accuracy of vector representation. Therefore, by using this model to convert user-submitted questions and each generated question into a vector, the semantic information of the questions can be quantitatively compared through vector distance. This lays the foundation for subsequent similarity calculations and precise retrieval and recall, ensuring the effectiveness of the retrieval process.
[0072] Step S106: Based on the document weight corresponding to each original document, calculate the similarity distance between the target question vector and each generated question vector, and recall the target document from at least one original document based on the similarity distance.
[0073] Specifically, similarity distance quantifies the degree of similarity between vectors, thus representing the semantic similarity between the target question and the generated question. By incorporating document weights into the calculation of similarity distance, the relevance of minority class documents is fully considered, effectively preventing majority class documents from monopolizing search results, thereby improving the visibility and coverage of long-tail categories and significantly enhancing the accuracy and fairness of retrieval recall. Original documents are sorted according to similarity distance, and one or more original documents with the highest similarity distance are selected as target documents for recall. After inputting the target documents into a large model, answers to the target question can be generated based on their content, improving the contextual matching and credibility of the answers, especially enhancing the response performance for minority class questions and contributing to a better user experience.
[0074] This invention acquires user-uploaded original documents, segments them into semantically complete text blocks, and generates targeted question-and-answer pairs, providing a richer knowledge base for subsequent retrieval. An initial embedding model is used to convert the original documents into vectors and cluster them, grouping semantically similar documents into one category, resulting in multiple clusters, and calculating document weights. The initial embedding model is trained based on these clusters to enhance its ability to capture category features, especially minority class features. Using the trained model to generate vectors, the weighted similarity distance between the user's target question vector and each generated question vector in the question-and-answer pair is calculated. During recall, the recall order is intelligently adjusted based on the similarity distance, improving the diversity of search results and the recall rate of minority class documents. This ensures that knowledge from all categories is matched fairly and accurately, effectively improving the accuracy and fairness of retrieval and retrieving information, thus solving the problem of class imbalance. This allows for the generation of more accurate and higher-quality question answers from target documents, exhibiting stronger generalization and adaptability when facing novel questions, and effectively improving the user experience.
[0075] This embodiment provides a knowledge enhancement method based on an embedding model, which can be used in the question-answering system described above. The method specifically includes the following steps:
[0076] Step S201: Obtain the target question uploaded by the user and at least one original document. See details below. Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0077] Step S202: Segment each original document to obtain multiple text blocks of the original document, and generate question-answer pairs for each text block. The question-answer pairs include generating questions and generating answers.
[0078] Specifically, step S202 above generates question-answer pairs for each text block, including:
[0079] Step S2021: Construct prompt words for each text block. The prompt words are used to standardize the generation target and output format.
[0080] Specifically, to guide the large model in generating relevant question-and-answer pairs for text blocks, specific prompt words need to be constructed for each text block. These prompt words must clearly define the generation objective, namely, generating relevant questions and corresponding answers around the core content of the text block, while also standardizing the output format. By constructing prompt words, it is ensured that the question-and-answer pairs generated by the large model are closely related to the content of the text block, avoiding deviation from the topic. Furthermore, the unified format facilitates subsequent batch processing and application of the question-and-answer pairs, providing high-quality structured data for knowledge expansion, thereby improving the effectiveness and retrieval efficiency of the knowledge base.
[0081] Step S2022: Using a large language model, question-answer pairs are generated for each text block based on the prompt words.
[0082] Specifically, guided by the aforementioned prompts, and leveraging the learning and reasoning capabilities of the large-scale model, the domain knowledge involved in the text block can be deeply mined and expanded, generating question-and-answer pairs that are highly relevant to the content of the text block. For text blocks involving cutting-edge or complex issues such as new energy technologies and policy details, the large-scale model can reason based on existing knowledge and supplement with the latest content; at the same time, by continuously learning newly released government policies and energy research results, the large-scale model can continuously update its knowledge reserves, generating richer and more timely question-and-answer pairs, effectively expanding knowledge while improving the accuracy and robustness of the question-and-answer system.
[0083] In some optional implementations, for a text block about "new solar cell efficiency improvement technology," the prompt could be: "Please generate one {question, answer} pair based on the following text content. The question should focus on the core technical details of the text, and the answer should accurately quote the original text information, in the format 'Question: XXX; Answer: XXX'. Text content: [Insert segmented text block here]." Using this prompt, the large model can generate question-and-answer pairs that fit the text, such as "Question: How much has the photoelectric conversion efficiency of this new solar cell improved? Answer: The text mentions that its efficiency is 15% higher than traditional models."
[0084] Step S203: The initial embedding model is used to convert each original document into an original vector, and clustering is performed based on all the original vectors to obtain multiple cluster categories and the document weight of the original document corresponding to each original vector. The cluster category represents the semantic topic.
[0085] Specifically, step S203 above performs clustering based on all original vectors to obtain multiple cluster categories and the document weights of the original documents corresponding to each original vector, including:
[0086] Step S2031: Clustering is performed based on all original vectors to obtain multiple cluster categories.
[0087] Specifically, existing clustering algorithms (such as k-means) are used to cluster all the original vectors, grouping semantically similar vectors into one class to obtain multiple cluster categories. Each cluster category represents a different semantic topic, such as "legal provisions" and "policy interpretation" in the government affairs field, and "traditional energy technology" and "new energy research and development" in the energy field.
[0088] Step S2032: For each cluster category, determine the number of all original vectors belonging to the cluster category, and determine the total number of all original vectors.
[0089] Step S2033: The ratio of the number of vectors to the total number is determined as the proportion of cluster categories.
[0090] Specifically, for each cluster category, the ratio of the original vector belonging to that cluster category to all original vectors is determined as the proportion of that cluster category. The proportion of cluster categories intuitively reflects the scale differences of different semantic topics. For example, in the field of government affairs, "government regulations" documents may account for 80%, while "interpretation of emerging policies" documents may only account for 5%, showing a significant category imbalance.
[0091] Step S2034: The reciprocal of the proportion of cluster categories is used as the document weight of the original document corresponding to each original vector belonging to the cluster category.
[0092] Specifically, the reciprocal of the percentage is used as the document weight of the original document corresponding to each original vector in that cluster category, i.e., document weight = 1 / percentage. By using the reciprocal of the percentage as the document weight, documents in cluster categories with lower percentages are given higher weights. For example, documents interpreting emerging policies account for 20% of the total, so their document weight is 5, which is higher than the weight of 1.25 for government regulations documents that account for 80%. This effectively solves the retrieval bias caused by category imbalance and ensures that documents in a minority category can be matched and retrieved more accurately.
[0093] Step S2035: Determine the cluster categories to be generated that account for less than a preset threshold.
[0094] Specifically, assuming a preset threshold of 10%, cluster categories with a proportion of less than 10% are selected and marked as cluster categories to be generated, thus accurately locating semantic categories where samples are scarce.
[0095] Step S2036: For each original vector in the cluster category to be generated, generate question-answer pairs for each text block of the original document corresponding to the original vector.
[0096] Specifically, for the cluster category to be generated, referring to steps S2021 and S2022, the question-answer pairs of the original documents corresponding to each original vector under the cluster category to be generated are regenerated. By specifically increasing the question-answer pairs of minority class documents, the matching probability of minority class documents during retrieval can be improved, preventing them from being ignored due to the small number of original documents, and further solving the class imbalance problem.
[0097] Step S204: Train an initial embedding model based on multiple clustering categories to obtain the target embedding model.
[0098] Specifically, step S204 includes:
[0099] Step S2041: For each cluster category, calculate the center vector and category weight of the cluster category based on all the original vectors belonging to the cluster category.
[0100] Specifically, the cluster center, i.e. the center vector, of each cluster category is calculated by the following formula (1), which represents the global speech information of that cluster category.
[0101] (1)
[0102] In the formula, An index representing the cluster categories; Indicates the first The center vectors of each cluster category; Indicates belonging to the first The set of original vectors for each cluster category. Indicates the first The cluster category to which the original vectors corresponding to each original document belong; Indicates the first In the cluster category, the first 1 original vector.
[0103] The class weight of each cluster category can be calculated by formula (2), which can assign higher weights to cluster categories with fewer documents, thus helping to solve the class imbalance problem.
[0104] (2)
[0105] In the formula, Indicates the first The cluster category to which the original vectors corresponding to each original document belong; Represents the class weights of the cluster categories; This represents the number of original vectors that belong to the cluster category.
[0106] Step S2042: Using each original vector as a query and the center vector of the cluster to which the original vector belongs as the key and value, calculate the attention weight of the original vector.
[0107] Specifically, to enable each original document to focus more on the core features of its cluster, a dot product attention mechanism is introduced. Each original vector is used as a query, and the center vector of its cluster is used as the key and value to construct the attention weight shown in Equation (3). The attention weight quantifies the semantic association strength between the original vector and the cluster center. The closer the value is to 1, the stronger the association between the original vector and the core features of the category.
[0108] (3)
[0109] In the formula, Indicates the index of the original vector; Indicates the first Attention weights for each original vector; Indicates the first One original vector; Indicates the first The cluster category to which each original vector belongs; Indicates the first The center vector of the cluster to which each of the original vectors belongs; This represents the dimension of the original vector.
[0110] Step S2043: Based on the attention weights of the original vectors and the center vectors of the cluster categories to which the original vectors belong, the original vectors are weighted and fused to obtain the enhanced vectors corresponding to the original vectors.
[0111] Specifically, for each original vector, its corresponding augmented vector is obtained based on its attention weight and the center vector of its cluster category using the following equation (4). The augmented vector obtained through fusion not only aligns with the core semantics of its category but also retains its unique features, providing a more accurate semantic representation for subsequent model training. For minority class documents, this fusion strengthens their scarce category features, reduces the problem of insufficient feature learning due to the small number of documents, and makes the augmented vector easier to identify in subsequent model training, and more accurately matches similar problems during retrieval.
[0112] (4)
[0113] In the formula, Indicates the index of the original vector; Indicates the first The enhanced vectors corresponding to the original vectors; Indicates the first Attention weights for each original vector; Indicates the first The center vector of the cluster to which each of the original vectors belongs; Indicates the first 1 original vector.
[0114] Step S2044: Using the cluster category as the label, the initial embedding model is used to predict the augmentation vector to obtain the prediction probability, which represents the probability that the augmentation vector belongs to the cluster category.
[0115] Specifically, to optimize the initial embedding model's ability to capture categorical features through supervised learning, the cluster category to which each augmentation vector belongs is used as a pseudo-label and input into the initial embedding model for prediction. The model outputs the probability that the augmentation vector belongs to that label, i.e., the predicted probability. The higher the predicted probability, the stronger the model's ability to recognize the features of that category. For minority classes, since the augmentation vector has enhanced its features, the model can more accurately capture the association between it and its cluster category, thereby improving its ability to distinguish minority classes.
[0116] Step S2045: Calculate the training loss based on each original vector, the class weight of the cluster category to which each original vector belongs, and the predicted probability of the augmented vector corresponding to each original vector.
[0117] Specifically, the training loss is calculated by the following formula (5). The introduction of class weights gives higher weight to the prediction error of minority class documents. When the model is inaccurate in predicting minority class documents, the resulting loss value is larger, which forces the model to pay more attention to the learning of minority class features during the training process, reduces the problem of insufficient feature capture caused by the small number of samples, and ultimately improves the ability of the embedding model to distinguish minority classes, effectively solving the problem of class imbalance.
[0118] (5)
[0119] In the formula, Indicates training loss; Indicates the index of the original vector; This represents the total number of original vectors; Indicates the first The cluster category to which each original vector belongs; Represents the class weights of the cluster categories; Indicates the first The enhanced vectors corresponding to the original vectors; Indicates the first The predicted probability of the augmented vector corresponding to each original vector.
[0120] Step S2046: Update the model parameters of the initial embedding model based on the training loss, repeat the above process of prediction and calculation of training loss until the training loss is minimized, and take the initial embedding model after the last update of model parameters as the target embedding model.
[0121] Specifically, the model parameters of the initial embedding model are updated based on the training loss using the backpropagation algorithm. The updated model is then used to return to step S2044, repeating the process of prediction, loss calculation, and updating model parameters based on the loss. This allows the model to gradually optimize its ability to learn category semantics until the training loss reaches its minimum. At this point, the model's capture of features for each category reaches its optimal state. The model obtained from the last update is used as the target embedding model, providing a reliable semantic representation foundation for subsequent embedding conversion and retrieval matching of questions and documents. This ensures that relevant documents, including minority classes, can be accurately recalled during the retrieval stage.
[0122] Step S205 involves using a target embedding model to convert the target question and the generated question in each question-answer pair into a target question vector and a generated question vector, respectively. For details, please refer to [link to details]. Figure 1 Step S105 of the illustrated embodiment will not be described again here.
[0123] Step S206: Based on the document weight corresponding to each original document, calculate the similarity distance between the target question vector and each generated question vector, and recall the target document from at least one original document based on the similarity distance.
[0124] Specifically, step S206 above calculates the similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, including:
[0125] Step S2061: Calculate the cosine similarity between the target question vector and each generated question vector.
[0126] Specifically, the cosine similarity between the target question vector and each generated question vector is calculated. The closer the value is to 1, the more consistent their directions are in the semantic space and the higher their content relevance, thus providing a preliminary measure of their semantic similarity.
[0127] Step S2062: The product of the document weight and cosine similarity of the original document corresponding to the generated question vector is determined as the similarity distance between the generated question vector and the target question vector.
[0128] Specifically, the document weight of the original document corresponding to the generated question vector is multiplied by the cosine similarity to obtain the weighted similarity distance. For example, if the cosine similarity between the generated question vector of a minority class document and the target question vector is 0.6, its document weight is 20, and the final similarity distance is 12; while the cosine similarity between the generated question vector of a majority class document and the target question vector is 0.8, its weight is 1.25, and the final similarity distance is 1. In this case, the minority class document receives higher priority due to the introduction of document weight. By introducing document weight to calculate similarity, even if the original similarity between the generated question and the target question of a minority class document is slightly lower, its recall order can be adjusted by the higher document weight, avoiding being masked by majority class documents due to the small number of original documents. This improves the diversity of search results and the recall rate of minority class documents, ensuring that knowledge of all categories can be matched fairly and accurately, thereby improving the quality of answer generation.
[0129] In some alternative implementations, Figure 2 This is a flowchart illustrating another knowledge enhancement method based on an embedding model according to an embodiment of the present invention, as shown below. Figure 2 As shown, the user uploads an original document, which is segmented using an initial embedding model to obtain multiple text blocks. For each text block, a targeted question-and-answer pair is generated. The initial embedding model converts each original document into an original vector, and then clusters are performed based on all original vectors to obtain multiple cluster categories. The proportion of each cluster category is calculated to obtain the document weight of the original document corresponding to each original vector. It is determined whether the proportion is less than a preset threshold. If it is less than a threshold, a new question-and-answer pair is generated for the original document corresponding to each original vector in that cluster category. The initial embedding model is trained based on the cluster categories to obtain the target embedding model, which converts the user-uploaded target question into a target question vector and the generated questions in each question-and-answer pair into generated question vectors. The document weight of the original document is introduced, and the similarity distance between the target question vector and each generated question vector is calculated. Based on the similarity distance, the target document is determined from the original document, and the target document is recalled to generate the corresponding answer for the target question.
[0130] This invention acquires user-uploaded original documents, segments them into semantically complete text blocks, and generates targeted question-and-answer pairs, providing a richer knowledge base for subsequent retrieval. An initial embedding model is used to convert the original documents into vectors and cluster them, grouping semantically similar documents into one category, resulting in multiple clusters, and calculating document weights. The initial embedding model is trained based on these clusters to enhance its ability to capture category features, especially minority class features. Using the trained model to generate vectors, the weighted similarity distance between the user's target question vector and each generated question vector in the question-and-answer pair is calculated. During recall, the recall order is intelligently adjusted based on the similarity distance, improving the diversity of search results and the recall rate of minority class documents. This ensures that knowledge from all categories is matched fairly and accurately, effectively improving the accuracy and fairness of retrieval and retrieving information, thus solving the problem of class imbalance. This allows for the generation of more accurate and higher-quality question answers from target documents, exhibiting stronger generalization and adaptability when facing novel questions, and effectively improving the user experience.
[0131] This embodiment also provides a knowledge enhancement device based on an embedding model, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0132] This embodiment provides a knowledge enhancement device based on an embedding model, such as... Figure 3 As shown, it includes:
[0133] The acquisition module 301 is used to acquire the target question uploaded by the user and at least one original document.
[0134] The first generation module 302 is used to segment each original document to obtain multiple text blocks of the original document, and generate question-answer pairs for each text block. The question-answer pairs include generating questions and generating answers.
[0135] Clustering module 303 is used to convert each original document into an original vector using an initial embedding model, and to perform clustering based on all original vectors to obtain multiple cluster categories and the document weight of the original document corresponding to each original vector. The cluster categories represent semantic topics.
[0136] Training module 304 is used to train an initial embedding model based on multiple clustering categories to obtain a target embedding model.
[0137] The transformation module 305 is used to use the target embedding model to convert the target question and the generated question in each question-answer pair into a target question vector and a generated question vector, respectively.
[0138] The recall module 306 is used to calculate the similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, and recall the target document from at least one original document based on the similarity distance.
[0139] In some alternative implementations, clustering module 303 includes:
[0140] Clustering units are used to cluster based on all the original vectors to obtain multiple cluster categories.
[0141] The first determining unit is used to determine, for each cluster category, the number of all original vectors belonging to the cluster category, and the total number of all original vectors.
[0142] The second determining unit is used to determine the ratio of the number of vectors to the total number as the proportion of cluster categories.
[0143] The third determining unit is used to determine the document weight of the original document corresponding to each original vector belonging to the cluster category by taking the inverse of the proportion of the cluster category.
[0144] In some alternative embodiments, the device further includes:
[0145] The determination module is used to identify cluster categories to be generated that have a proportion less than a preset threshold.
[0146] The second generation module is used to generate question-answer pairs for each text block of the original document corresponding to each original vector in the cluster category to be generated.
[0147] In some alternative implementations, training module 304 includes:
[0148] The first computational unit is used to calculate the center vector and class weight of each cluster category based on all the original vectors belonging to the cluster category.
[0149] The second computational unit is used to calculate the attention weight of each original vector as a query and the center vector of the cluster to which the original vector belongs as the key and value.
[0150] The fusion unit is used to perform weighted fusion on the original vector based on the attention weights of the original vector and the center vector of the cluster category to which the original vector belongs, to obtain the enhanced vector corresponding to the original vector.
[0151] The prediction unit is used to predict the augmentation vector using the cluster category as the label and the initial embedding model to obtain the prediction probability, which represents the probability that the augmentation vector belongs to the cluster category.
[0152] The third computational unit is used to calculate the training loss based on each original vector, the class weight of the cluster to which each original vector belongs, and the predicted probability of the augmented vector corresponding to each original vector.
[0153] The training unit is used to update the model parameters of the initial embedding model based on the training loss. The process of predicting and calculating the training loss is repeated until the training loss is minimized. The initial embedding model after the last update of the model parameters is used as the target embedding model.
[0154] In some optional implementations, the cluster weights are calculated using the following formula:
[0155]
[0156] In the formula, Indicates the first The cluster category to which the original vectors corresponding to each original document belong; Represents the class weights of the cluster categories; This represents the number of original vectors that belong to the cluster category.
[0157] In some alternative implementations, the recall module 306 includes:
[0158] The fourth calculation unit is used to calculate the cosine similarity between the target problem vector and each generated problem vector.
[0159] The fourth determining unit is used to determine the similarity distance between the generated question vector and the target question vector by multiplying the document weight of the original document corresponding to the generated question vector with the cosine similarity.
[0160] In some alternative implementations, the first generation module 302 includes:
[0161] The building block is used to construct the prompt words for each text block. The prompt words are used to standardize the generation target and output format.
[0162] The generation unit is used to generate question-answer pairs for each text block based on the prompt words of each text block, using a large language model.
[0163] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0164] In this embodiment, the knowledge enhancement device based on the embedding model is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0165] This invention also provides a computer device having the above-described features. Figure 3 The knowledge enhancement device based on the embedding model is shown.
[0166] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 4 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 4 Take a processor 10 as an example.
[0167] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0168] The memory 20 stores instructions executable by at least one processor 10 to cause at least one processor 10 to perform the method shown in the above embodiments.
[0169] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0170] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0171] The computer device also includes an input device 30 and an output device 40. The processor 10, memory 20, input device 30, and output device 40 can be connected via a bus or other means. Figure 4 Taking the example of a connection between China and Israel via a bus.
[0172] Input device 30 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the computer device, such as a touchscreen, keypad, mouse, trackpad, touchpad, joystick, one or more mouse buttons, trackball, joystick, etc. Output device 40 may include display devices, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors). The aforementioned display devices include, but are not limited to, liquid crystal displays, light-emitting diodes, displays, and plasma displays. In some alternative embodiments, the display device may be a touchscreen.
[0173] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0174] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0175] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A knowledge enhancement method based on an embedding model, characterized in that, The method comprises: obtaining a target question and at least one original document uploaded by a user; segmenting each original document to obtain a plurality of text blocks of the original document, generating a question and answer pair for each text block, the question and answer pair comprising a generated question and a generated answer; converting each original document into an original vector using an initial embedding model, and clustering based on all original vectors to obtain a plurality of cluster categories and a document weight of the original document corresponding to each original vector, the cluster categories representing semantic topics; training the initial embedding model based on the plurality of cluster categories to obtain a target embedding model; converting the target question and the generated question in each question and answer pair into a target question vector and a generated question vector, respectively, using the target embedding model; calculating a similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, and recalling a target document from the at least one original document based on the similarity distance; wherein the training of the initial embedding model based on the plurality of cluster categories to obtain a target embedding model comprises: for each cluster category, calculating a center vector and a category weight of the cluster category based on all original vectors belonging to the cluster category; taking each original vector as a query, and taking the center vector of the cluster category to which the original vector belongs as a key and a value, to calculate an attention weight of the original vector; based on the attention weight of the original vector and the center vector of the cluster category to which the original vector belongs, performing weighted fusion on the original vector to obtain an enhanced vector corresponding to the original vector; taking the cluster category as a label, and using the initial embedding model to predict the enhanced vector to obtain a prediction probability, the prediction probability representing a probability that the enhanced vector belongs to the cluster category; based on each original vector, the category weight of the cluster category to which each original vector belongs, and the prediction probability of the enhanced vector corresponding to each original vector, calculating a training loss; updating model parameters of the initial embedding model based on the training loss, repeating the prediction and calculation of the training loss until the training loss is minimized, and taking the initial embedding model after the last update of the model parameters as the target embedding model; the category weight of the cluster category is calculated using the following formula: In the formula, represents the cluster category to which the original vector corresponding to the first original document belongs; represents the category weight of the cluster category; represents the number of vectors belonging to the cluster category.
2. The method of claim 1, wherein, the clustering based on all original vectors to obtain a plurality of cluster categories and a document weight of the original document corresponding to each original vector comprises: clustering based on all original vectors to obtain a plurality of cluster categories; for each cluster category, determining the number of vectors of all original vectors belonging to the cluster category, and determining the total number of all original vectors; determining the ratio of the number of vectors to the total number as the proportion of the cluster category; determining the reciprocal of the proportion of the cluster category as the document weight of the original document corresponding to each original vector belonging to the cluster category.
3. The method of claim 2, wherein, The method further includes: determining a to-be-generated clustering category with a proportion less than a preset threshold; for each original vector in the to-be-generated clustering category, generating a question and answer pair for each text block of the original document corresponding to the original vector again.
4. The method of claim 1, wherein, The similarity distance between the target question vector and each generated question vector is calculated based on the document weight corresponding to each original document, including: calculating the cosine similarity between the target question vector and each generated question vector; the product of the document weight of the original document corresponding to the generated question vector and the cosine similarity is determined as the similarity distance between the generated question vector and the target question vector.
5. The method of claim 1, wherein, The generation of the question and answer pair for each text block includes: constructing a prompt word for each text block, the prompt word being used to standardize the target and output format; using a large language model to generate the question and answer pair for each text block based on the prompt word of each text block.
6. A knowledge enhancement apparatus based on an embedding model, characterized by, The device includes: an acquisition module configured to acquire a target question and at least one original document uploaded by a user; a first generation module configured to split each original document to obtain a plurality of text blocks of the original document, and generate a question and answer pair for each text block, the question and answer pair including a generated question and a generated answer; a clustering module configured to convert each original document into an original vector using an initial embedding model, and perform clustering based on all original vectors to obtain a plurality of clustering categories and a document weight of the original document corresponding to each original vector, the clustering category representing a semantic topic; a training module configured to train the initial embedding model based on the plurality of clustering categories to obtain a target embedding model; a conversion module configured to convert the target question and the generated question in each question and answer pair into a target question vector and a generated question vector, respectively, using the target embedding model; a recall module configured to calculate a similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, and recall a target document from the at least one original document based on the similarity distance; The training module is specifically configured to: for each clustering category, calculate a center vector and a category weight of the clustering category based on all original vectors belonging to the clustering category; take each original vector as a query, and take the center vector of the clustering category to which the original vector belongs as a key and a value, to calculate an attention weight of the original vector; based on the attention weight of the original vector and the center vector of the clustering category to which the original vector belongs, perform weighted fusion on the original vector to obtain an enhanced vector corresponding to the original vector; take the clustering category as a label, and use the initial embedding model to predict the enhanced vector to obtain a prediction probability, the prediction probability representing a probability that the enhanced vector belongs to the clustering category; based on each original vector, the category weight of the clustering category to which each original vector belongs, and the prediction probability of the enhanced vector corresponding to each original vector, calculate a training loss; and a generation module configured to generate a question and answer pair for each text block based on the prompt word of each text block using a large language model. The device includes: an acquisition module configured to acquire a target question and at least one original document uploaded by a user; a first generation module configured to split each original document to obtain a plurality of text blocks of the original document, and generate a question and answer pair for each text block, the question and answer pair including a generated question and a generated answer; a clustering module configured to convert each original document into an original vector using an initial embedding model, and perform clustering based on all original vectors to obtain a plurality of clustering categories and a document weight of the original document corresponding to each original vector, the clustering category representing a semantic topic; a training module configured to train the initial embedding model based on the plurality of clustering categories to obtain a target embedding model; a conversion module configured to convert the target question and the generated question in each question and answer pair into a target question vector and a generated question vector, respectively, using the target embedding model; a recall module configured to calculate a similarity distance between the target question vector and each generated question vector based on the document weight corresponding to each original document, and recall a target document from the at least one original document based on the similarity distance; The training module is specifically configured to: for each clustering category, calculate a center vector and a category weight of the clustering category based on all original vectors belonging to the clustering category; take each original vector as a query, and take the center vector of the clustering category to which the original vector belongs as a key and a value, to calculate an attention weight of the original vector; based on the attention weight of the original vector and the center vector of the clustering category to which the original vector belongs, perform weighted fusion on the original vector to obtain an enhanced vector corresponding to the original vector; take the clustering category as a label, and use the initial embedding model to predict the enhanced vector to obtain a prediction probability, the prediction probability representing a probability that the enhanced vector belongs to the clustering category; based on each original vector, the category weight of the clustering category to which each original vector belongs, and the prediction probability of the enhanced vector corresponding to each original vector, calculate a training loss; and a generation module configured to generate a question and answer pair for each text block based on the prompt word of each text block using a large language model. updating model parameters of the initial embedding model based on the training loss, repeating the above process of prediction and calculation of training loss until the training loss is minimized, and taking the initial embedding model after the last update of the model parameters as the target embedding model; The category weight of the clustering category is calculated by the following formula: In the formula, represents the cluster category to which the original vector corresponding to the first original document belongs; represents the category weight of the cluster category; represents the number of vectors belonging to the cluster category.
7. A computer device, characterized by including: The memory and the processor are connected in communication with each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the embedding model-based knowledge enhancement method in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for causing a computer to execute the embedding model-based knowledge enhancement method in any one of claims 1 to 5.
Citation Information
Patent Citations
Document-based intelligent question and answer model training method and device and application thereof
CN116910210A
Knowledge searching method and device for enterprise
CN118673128A