Question and answer processing method, apparatus, device, and medium

By constructing a historical question-and-answer dataset and training an answer path ranking model, the semantic relevance and logical consistency are evaluated, which solves the problem of insufficient answer reliability in existing question-and-answer processing methods and improves the accuracy and robustness of question-and-answer in the fields of finance, insurance and healthcare.

CN122152893APending Publication Date: 2026-06-05CHINA PING AN PROPERTY INSURANCE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA PING AN PROPERTY INSURANCE CO LTD
Filing Date
2026-03-05
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing question-answering methods lack logical type supervision, resulting in insufficient reliability of answers, especially in professional fields such as finance, insurance, and healthcare, where it is difficult to guarantee the accuracy and logical consistency of answers.

Method used

By constructing a historical question-and-answer dataset containing answer paths of both positive and negative samples, a joint learning mechanism is used to train an answer path ranking model. This model evaluates the semantic relevance and logical type consistency between user questions and candidate answer paths, and generates the optimal answer path.

Benefits of technology

It significantly improves the sorting accuracy and model robustness in complex query scenarios, effectively distinguishes semantically similar but logically different questions, avoids information confusion, and ensures the accuracy and reliability of the answer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152893A_ABST
    Figure CN122152893A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of data processing, and discloses a question and answer processing method, device, equipment and medium. Through joint training of a sorting task and an answer type prediction task, a model learns logical type constraints between questions and answers while optimizing semantic correlation, effectively suppresses false correlations caused by training data bias or high-frequency answer interference. Further, in the question and answer reasoning process, with the aid of an answer path sorting model and a cross-sequence interaction attention mechanism, comprehensive sorting results of each candidate answer path fusion semantic score and type consistency score can be obtained, multi-granularity accurate matching from overall semantics to local elements is realized, and the sorting accuracy and model robustness in a complex query scene are significantly improved. Therefore, in the knowledge base question and answer task in the fields of finance and insurance, medical treatment and the like, questions with similar semantics but different logical types can be effectively distinguished, information confusion is avoided, and the final answer has accuracy and reliability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a question-and-answer processing method, apparatus, device, and medium. Background Technology

[0002] In knowledge-based question-answering, existing methods often rely on a single global vector or shallow interactions for semantic matching to retrieve answers. However, these methods generally lack explicit supervision mechanisms for the logical type of the answers, making it difficult to guarantee the accuracy and logical consistency of the returned answers, resulting in a low overall accuracy rate. In knowledge-based question-answering scenarios in professional fields such as finance, insurance, and healthcare, their limitations become particularly pronounced when faced with application requirements that are complex in query logic, rigorous in content, and demand extremely high reliability of results. Summary of the Invention

[0003] This invention provides a question-and-answer processing method, apparatus, computer equipment, and medium to solve the technical problem that current question-and-answer processing methods lack logical type supervision, resulting in insufficient reliability of answers.

[0004] Firstly, a question-and-answer processing method is provided, including: Obtain the historical question-and-answer dataset, which includes multiple sets of historical question-and-answer pairs. Each set of historical question-and-answer pairs includes: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path. Based on a historical question-answering dataset, an answer path ranking model is trained through a joint learning mechanism. The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type of each candidate answer path. Obtain the user's question and multiple candidate answer paths; Based on the answer path ranking model, a relevance score and a type consistency score are generated between the user's question and each candidate answer path. Based on relevance score and type consistency score, the optimal answer path is determined among multiple candidate answer paths, and the question answer is generated based on the optimal answer path.

[0005] Secondly, a question-and-answer processing device is provided, comprising: The first acquisition module is used to acquire the historical question and answer dataset, which includes multiple sets of historical question and answer pairs. Each set of historical question and answer pairs includes: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path. The model training module is used to train the answer path ranking model based on the historical question-answering dataset through a joint learning mechanism. The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type of each candidate answer path. The second acquisition module is used to acquire user questions and multiple candidate answer paths; The first generation module is used to generate relevance scores and type consistency scores between user questions and each candidate answer path based on the answer path ranking model. The second generation module is used to determine the optimal answer path among multiple candidate answer paths based on relevance score and type consistency score, and to generate the question answer based on the optimal answer path.

[0006] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described question-and-answer processing method.

[0007] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described question-and-answer processing method.

[0008] In the aforementioned question-answering processing method, apparatus, computer equipment, and storage medium, by jointly training the ranking task and the answer type prediction task, the model optimizes semantic relevance while explicitly learning the logical type constraints between questions and answers, effectively suppressing spurious associations caused by biased training data or interference from high-frequency answers. Furthermore, during the question-answer reasoning process, by leveraging the answer path ranking model and the cross-sequence interactive attention mechanism, a comprehensive ranking result combining semantic scores and type consistency scores for each candidate answer path can be obtained. This achieves multi-granularity precise matching from overall semantics to local elements, significantly improving ranking accuracy and model robustness in complex query scenarios. Therefore, in knowledge base question-answering tasks in fields such as finance, insurance, and healthcare, it can effectively distinguish between semantically similar but logically different questions, avoiding information confusion and ensuring the accuracy and reliability of the final answer. Attached Figure Description

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

[0010] Figure 1This is a schematic diagram of an application environment for a question-and-answer processing method according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating a question-and-answer processing method according to an embodiment of the present invention; Figure 3 yes Figure 2 A schematic diagram of a specific implementation method for step S10; Figure 4 yes Figure 2 A schematic diagram of a specific implementation of step S40; Figure 5 yes Figure 2 A schematic diagram of a specific implementation method for step S41; Figure 6 yes Figure 2 A schematic diagram of a specific implementation method for step S50; Figure 7 This is a schematic diagram of a question-and-answer processing device according to an embodiment of the present invention; Figure 8 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention; Figure 9 This is another structural schematic diagram of a computer device according to one embodiment of the present invention. Detailed Implementation

[0011] 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, not all, of the embodiments of the present invention. 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.

[0012] The question-and-answer processing method provided in this embodiment of the invention can be applied to, for example... Figure 1In this application environment, the client communicates with the server via a network. The server acquires a historical question-and-answer dataset; based on the historical dataset, it trains an answer path ranking model through a joint learning mechanism; it acquires the user's question and multiple candidate answer paths; based on the answer path ranking model, it generates relevance scores and type consistency scores between the user's question and each candidate answer path; based on the relevance and type consistency scores, it determines the optimal answer path among the multiple candidate answer paths and generates the question answer based on the optimal answer path. This achieves multi-granularity precise matching from overall semantics to local elements, significantly improving the ranking accuracy and model robustness in complex query scenarios. Therefore, in knowledge base question-and-answer tasks in fields such as finance, insurance, and healthcare, it can effectively distinguish semantically similar but logically different questions, avoiding information confusion and ensuring the accuracy and reliability of the final answer. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The invention will be described in detail below through specific embodiments.

[0013] Please see Figure 2 As shown, Figure 2 A flowchart illustrating a question-and-answer processing method provided in an embodiment of the present invention includes the following steps: S10: Obtain the historical question-and-answer dataset; The historical question-answering dataset includes multiple sets of historical question-answering pairs. Each set of historical question-answering pairs includes: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path.

[0014] In this step, a structured historical question-and-answer dataset is constructed, which contains multiple sets of historical question-and-answer pairs. Each set of data includes a historical question, the correct answer path corresponding to the question, and multiple incorrect answer paths as similar distractors. The correct answer paths and incorrect answer paths are used as positive / negative samples to simulate the complex decision-making scenarios faced by the model in actual ranking tasks.

[0015] Furthermore, the dataset centrally labels each historical question with its corresponding expected answer type. For example, questions asking "when does it take effect?" are labeled as "date." Each answer path is also labeled with the entity type defined in the knowledge base for its answer entity, such as the "date" type corresponding to the answer entity "2023-01-01". This data construction, which includes comparisons of correct / incorrect answer paths and type labeling, provides a foundation for the model to learn fine-grained ranking and logical constraints.

[0016] For example, in an insurance knowledge Q&A scenario, real historical questions are first collected from insurance company customer service logs, online consultation platforms, and policy term databases, such as "What is the waiting period for my critical illness insurance?" and "How is the annual cash value of this policy calculated?". For each question, the corresponding correct answer path is extracted from a structured knowledge graph. For example, for a waiting period query, the correct answer path can be represented as "The user holds a XX critical illness insurance policy with a waiting period of 180 days." Simultaneously, incorrect answer paths are constructed using various strategies: semantically similar distractors are constructed by replacing the relationships at the end of the path, such as replacing "waiting period" with "cooling-off period"; type-conflicting distractors are constructed by replacing answer entities, such as replacing "180 days" with "20,000 yuan"; and basic negative examples are constructed by randomly sampling unrelated paths. Furthermore, each question is labeled with its corresponding expected answer type. For example, a question containing "how many days" is labeled as "duration" type, and a question involving "how to calculate" is labeled as "formula" type. The answer entities in all answer paths are labeled with their entity types defined in the knowledge base. For example, "180 days" is labeled as "duration" type, and "20,000 yuan" is labeled as "amount" type.

[0017] In one embodiment of this application, such as Figure 3 As shown, a specific data acquisition scheme is provided. In S10, which is to acquire the historical question-and-answer dataset, the following steps S11-S14 are specifically included: S11: Obtain multiple historical questions, and the correct answer path for each historical question.

[0018] In this step, a large number of historical questions raised by users and the standard correct answer path for each question are obtained from the historical Q&A log. For example, in the insurance field, the question is "What is the waiting period for my critical illness insurance policy?", and the correct answer path is "Critical Illness Insurance B Waiting Period Clause 180 days".

[0019] S12: Based on a pre-defined knowledge base, identify at least one target entity that is semantically related to each historical question and its correct answer path.

[0020] In this step, after obtaining historical questions and their correct answer paths, the core entities involved in the historical questions and correct answer paths are used as the starting point for retrieval. First- or second-degree relation expansion is performed in a pre-defined knowledge base to identify semantically related or structurally adjacent target entities. For example, for the historical question "When can I receive the cash value of my 'Ankang Whole Life Insurance'?", the correct answer path points to the entity "60 years old". Starting from this entity, the pre-defined knowledge base is queried for target entities directly related to it, such as those associated with "annual premium", "death benefit", and "insured age". Simultaneously, starting from the path header entity "'Ankang Whole Life Insurance'", other attribute entities of this type of insurance, such as "insurance liability" and "exclusion clauses", can be found. The set of relevant entities obtained in this way provides an entity resource library for the subsequent automatic generation of diverse incorrect answer paths, thereby enhancing the comparative learning effect of the training data and the robustness of the model.

[0021] S13: Based on at least one target entity and the correct answer path, generate multiple incorrect answer paths corresponding to each historical question through a preset path construction strategy.

[0022] In this step, using the identified semantically related target entities and the elements of the correct answer path, negative samples, i.e. incorrect answer paths, are automatically generated for model training through a preset path construction strategy.

[0023] Specifically, the pre-defined path construction strategy includes: (1) Relationship replacement: keeping the head entity and its basic structure of the correct answer path unchanged, and replacing the relationship at the end of the path with other semantically similar but logically different relationships selected from the target entity set, thereby constructing a relationship error type answer path; (2) Answer replacement: keeping the relationship chain structure in the correct answer path unchanged, and replacing its answer entity with other target entities of the same or different types, thereby generating an answer error type answer path; (3) Path perturbation: randomly replacing or deleting intermediate entities or relationships in the correct answer path to construct a perturbation type error answer path that is structurally similar but semantically deviates.

[0024] By constructing incorrect answer paths that are highly similar to the original correct answer paths in terms of surface structure or local semantics, the ranking model can effectively simulate the difficult negative example discrimination scenarios that it may face in real-world applications, thereby significantly enhancing the model's discrimination ability and ranking robustness in complex comparison environments.

[0025] S14: Obtain the predefined type corresponding to the answer entity of each answer path, and use it as the entity type label for each answer path.

[0026] In this step, for each answer path in the dataset (including correct answer paths and generated incorrect answer paths), the answer entity at its end is extracted, and the standardized definition of this entity in the knowledge base schema or type system is queried, mapping it to a unified entity type label. For example, the answer entity "90 days" is defined as the "duration" type in the insurance knowledge base; the answer entity "2025-12-31" is defined as the "date" type; and the answer entity "1 million yuan" is defined as the "amount" type. These type labels are then used as entity type annotations for the corresponding answer paths.

[0027] By using the above method, a structured type truth value is provided for each answer path, enabling the model to learn the correspondence between answer entities and their logical types during training. This provides a supervisory signal for the answer type prediction task and strengthens the model's ability to identify and verify the logical attributes of answers.

[0028] S20: Based on historical question-and-answer datasets, an answer path ranking model is trained through a joint learning mechanism; The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type for each candidate answer path.

[0029] In this step, a pre-constructed dataset containing positive / negative samples and corresponding entity type labels is used as training samples. Machine learning algorithms automatically optimize the internal parameters of the neural network model to train an answer path ranking model. This model, through a joint learning mechanism, simultaneously masters the ability to evaluate the semantic relevance and logical type consistency of answers. Therefore, when faced with new user questions and their multiple candidate answer paths, it can accurately perform a comprehensive evaluation and ranking, ultimately identifying the optimal answer path.

[0030] Specifically, by introducing comparative training with correct / incorrect answer paths, the model can effectively identify the most relevant answer path from a list containing correct options and several incorrect or distracting options. Simultaneously, leveraging the expected answer type and entity type labeled in the dataset, the model, in identifying the most relevant answer, also needs to predict the expected answer type corresponding to the user's question and the type of answer entities in each candidate answer path, and calculate a type consistency score accordingly. By using type consistency as a key decision criterion in parallel with semantic relevance, logical correctness is elevated to an equal level of importance with semantic relevance, thus systematically solving the problem of spurious associations caused by semantically similar but logically inconsistent relationships in traditional methods.

[0031] In one embodiment of this application, a specific model training scheme is provided. In S20, namely, training an answer path ranking model based on a historical question-and-answer dataset, the specific steps include S21-S29: S21: Construct a neural network model based on a dual-tower interactive Transformer architecture.

[0032] In this step, a neural network model based on a dual-tower interactive Transformer architecture is constructed as the core component of the knowledge base question-answering path fine-grained ranking task. This architecture employs a dual-tower design, using two identical Transformer encoders with shared parameters to independently encode the user's natural language question and the candidate answer path, respectively. Building upon this, the model further introduces a cross-sequence interactive attention mechanism to achieve fine-grained semantic alignment and information interaction between the question and the path after the encoding layer. This design balances independent semantic understanding of the question and the path with dynamic relationship modeling between them, thereby achieving accurate matching of complex semantic relationships.

[0033] In one embodiment of this application, the neural network model includes: an input representation layer for serializing each candidate answer path; an encoding and interaction layer for encoding and interacting with the input user question and each candidate answer path, wherein the encoding and interaction layer includes: a basic encoding layer and a cross-sequence interaction attention layer, wherein the basic encoding layer is used to independently encode the serialized user question and each candidate answer path to obtain their respective overall semantic representations; the cross-sequence interaction attention layer is used to calculate the relevance weight between each word in the serialized user question and each element in each candidate answer path, and generate a context-aware interaction representation; a feature fusion layer is used to concatenate and aggregate the overall semantic representation and the interaction representation to form a fused feature vector; and an output layer including: a multilayer perceptron for receiving the fused feature vector and outputting the relevance score of the answer path; and a type classifier for receiving the fused feature vector and outputting the type probability distribution of the answer entity in the answer path.

[0034] In this embodiment, the input representation layer, as the front-end processing module of the model, undertakes the crucial task of transforming the original knowledge base paths into a standardized input format suitable for deep learning model processing. This layer is mainly responsible for the structured serialization processing of each candidate answer path. First, each answer path is parsed to identify the key structural elements in the path, including the head entity, a series of relational chains, intermediate entities, and the final target answer entity. Then, these elements are labeled using a predefined semantic role labeling system, using special markers such as "[HEAD]", "[REL]", "[ENT]", and "[ANS]" to clearly identify the semantic role of each element. Finally, according to a predefined serialization template, these labeled elements are sequentially combined into a text sequence. This serialization process not only preserves the complete structural information of the path but also provides the model with important inductive biases through special markers, helping the model understand the semantic role differences of different elements and laying the foundation for subsequent encoding and matching.

[0035] Furthermore, the encoding and interaction layer is responsible for deep semantic understanding and interaction analysis of the serialized user questions and answer paths. This layer contains two key sub-components: the basic encoding layer and the cross-sequence interaction attention layer, which together achieve a multi-level understanding of questions and paths from a holistic to a local perspective.

[0036] Specifically, the base encoding layer employs a parameter-sharing dual-tower architecture, independently encoding the serialized question text and path sequences. Using a Transformer-based pre-trained language model, this layer captures the contextual dependencies within each sequence, generating a high-quality overall semantic representation. For question sequences, the base encoding layer understands referentiality, ellipsis, and complex sentence structures in natural language; for path sequences, it utilizes special tagging information to accurately distinguish the logical positions of different elements in the reasoning chain.

[0037] The cross-sequence interaction attention layer builds upon the basic encoding to achieve fine-grained semantic alignment between questions and paths. This layer establishes a dynamic association matrix between the two by calculating the attention weights between each word in the question and each element in the path.

[0038] The formula for calculating the cross-sequence attention weight matrix is:

[0039] Where A is the attention weight matrix; H q H represents the hidden state of the problem sequence; p W represents the hidden state of the path sequence. q W p ∈Rd×d is a learnable linear transformation matrix; d is the hidden layer dimension; T is the transpose operator.

[0040] Subsequently, based on the attention matrix A, the context-aware path representation H of the problem is calculated. q1 H, a context-aware representation of paths p1 :

[0041] This allows each word in the question to focus on the most relevant part of the path, and vice versa. For example, for the keyword "compensation amount" in the question, the model can accurately locate the entity or relationship representing the monetary value in the path through interactive attention. This interactive mechanism can accurately locate the corresponding position of the key constraints in the question in the path, even if there are significant differences in their expression. Through this cross-sequence attention interaction, the question representation generated by the model can perceive the most relevant path information, and the path representation can also be dynamically adjusted according to the question, forming a context-aware enhanced representation.

[0042] Optionally, the pre-trained language model ERNIE, which performs well in the Chinese domain, can be used as the base encoding layer.

[0043] Furthermore, the feature fusion layer is responsible for integrating the multi-layered semantic information output from the encoding and interaction layers, aggregating them into a unified feature representation. This layer receives the overall semantic representation generated by the previous layer's basic encoding layer, as well as the context-aware interaction representation generated by the cross-sequence interaction attention layer. The overall semantic representations of the question and path are concatenated to form a feature vector reflecting the global matching degree between the two. Simultaneously, the interactive question-aware path representation and the path-aware question representation are pooled (e.g., max pooling) to extract the most significant interaction features. Finally, these feature vectors of different granularities and perspectives are further concatenated to form a fusion feature vector that comprehensively represents the question-path matching relationship.

[0044] in, To fuse feature vectors; h q The global representation of the problem sequence; h p H is a global representation of the path sequence. q1 The context-aware representation of the question after interactive attention; H p1 This is the context-aware representation of the path after interactive attention; maxpool() performs max pooling along the sequence length dimension.

[0045] The overall semantic representation provides a macroscopic assessment of the matching degree, while the fine-grained interaction representation captures the precise local correspondences. The combination of the two enables the model to simultaneously grasp the dual criteria of whether the overall semantics are relevant and whether key details match, providing rich and comprehensive feature support for the final discrimination decision.

[0046] Furthermore, the output layer, as the final decision module of the model architecture, receives the comprehensive feature vector from the feature fusion layer and produces two key outputs: a path relevance score and an answer entity type probability distribution. Specifically, the main output part adopts a multilayer perceptron structure, responsible for calculating the relevance score between the candidate answer path and the user question. This multilayer perceptron typically contains one or more fully connected layers, coupled with a non-linear activation function (such as GeLU), enabling deep non-linear transformation of the fused features. The final output is a scalar value as the relevance score s.

[0047] Where s is the correlation score; Vfusion is the fusion feature vector; W1 is the first layer weight matrix; b1 is the first layer bias vector; GeLU(·) is the Gaussian error linear unit activation function; W2 is the second layer weight matrix; b2 is the second layer bias scalar; W1, W2, b1, and b2 are learnable parameters.

[0048] The numerical value directly reflects the semantic matching degree between the path and the question. A higher score indicates that the path is more likely to be the correct answer. The parallel output section is a specially designed type classifier, which also receives the same fused feature vector as input. This classifier typically uses a fully connected layer with a Softmax activation function, outputting a multi-dimensional probability distribution vector, where each dimension corresponds to a predefined entity type (such as date, amount, name, location, etc.). This probability distribution represents the model's confidence in predicting the type of the answer entity.

[0049] The dual-output design, as described above, embodies the model's multi-task learning architecture. Relevance scoring serves the primary ranking task, ensuring the model finds the semantically best-matching path; while type prediction acts as an auxiliary task, verifying the logical consistency of the answer. Both share the underlying feature extraction network, guaranteeing consistency in feature representations and enhancing the model's overall reasoning ability through inter-task constraints. During training, each output calculates its own loss, and a weighted sum is used to form a joint optimization objective. During inference, the relevance score serves as the primary basis for path ranking, while the type prediction result serves as a supplementary reference for answer credibility.

[0050] S22: Based on the preset semantic role markers, assign roles to each answer path and determine the role type corresponding to each element in each answer path; The preset semantic role markers include at least one of the following: head entity marker, first relation marker, intermediate entity marker, second relation marker, and answer entity marker.

[0051] S23: Based on the preset path serialization template and role type, sort and combine the marked elements in each answer path to generate a sample sequence corresponding to each answer path.

[0052] For steps S22-S23, in order to effectively input the structured answer paths from the knowledge base into the neural network model, the answer paths need to be pre-serialized. Based on preset semantic role labels, each answer path is first identified and labeled to clarify the semantic role type corresponding to each element. Among them, the preset semantic role labels include, but are not limited to: Head Entity Label (HEAD), First Relation Label (REL), Intermediate Entity Label (ENT), Second Relation Label (REL), and Answer Entity Label (ANS).

[0053] Specifically, first, each answer path is parsed to identify the head entity, relation sequence, and answer entity. Then, based on a pre-defined path serialization template and labeled role types, the elements are combined into a text sequence in a predetermined order. For example, for a typical two-hop reasoning path P=(e, r1, e1, r2, eans), the serialized format is: “[HEAD] e [REL]r1[ENT] e1[REL] r2[ANS] eans”. This explicit injection of structural information provides the model with key inductive biases, helping it to accurately understand the path's inherent logical structure.

[0054] By using the above method, the original graph-structured knowledge base answer path is transformed into a sequence format suitable for the Transformer model to process. While retaining the original structured information, this enables the model to effectively distinguish the functional roles of different elements in the path, providing a necessary foundation for subsequent semantic matching and type verification.

[0055] S24: Input the serialized historical question-and-answer dataset as training samples into the neural network model.

[0056] In this step, the serialized historical question-and-answer dataset is used as training samples and input into the neural network model in batches. Each training batch contains multiple independent question-and-answer instances, each consisting of three parts: the original historical question text, the serialized correct answer path, and multiple serialized incorrect answer paths. During training, the model processes all samples within the same batch in parallel. This organization provides the necessary data structure foundation for subsequent list-level loss calculations.

[0057] S25: Obtain the relevance score for each answer path.

[0058] In this step, after training samples are input into the neural network model, the model calculates a relevance score for each answer path through forward propagation. Specifically, the model's dual-tower component semantically encodes the question and path respectively, the interactive attention layer calculates the fine-grained association between them, the feature fusion layer integrates semantic representations of different granularities, and finally the output layer generates the relevance score. This relevance score is a scalar value, and its value directly reflects the degree of semantic matching between the path and the question. For each question, the model calculates a score for each of its corresponding correct / incorrect answer paths, forming a corresponding score sequence. This sequence not only reflects the overall semantic similarity between the path and the question but also contains local alignment information captured by the interactive attention mechanism, thus providing a more discriminative signal basis for subsequent ranking optimization.

[0059] S26: Based on the relevance scores of the correct answer path and the relevance scores of the incorrect answer path, the ranking loss is calculated using a list-level weighted margin ranking loss function.

[0060] In this step, a list-level weighted margin ranking loss function is used as the optimization objective for the main ranking task. Unlike traditional cross-entropy loss, the list-level loss function uses the set of correct answer paths and the set of incorrect answer paths corresponding to the same question as the overall optimization unit. Its core objective is to widen the score gap between positive and negative sample paths among all candidate paths. This loss function particularly strengthens the ability to distinguish "hard negative samples," that is, those incorrect answer paths that are highly similar to the correct answer paths in semantics or structure and are difficult to distinguish. By applying higher penalty weights to these samples, the model's discrimination robustness and ranking accuracy in the fine ranking task are effectively improved.

[0061] The formula for calculating the list-level loss function is:

[0062] in, For ranking loss; p + The correct answer path; p - The path to the incorrect answer; P + P represents the set of correct answer paths. - A set of incorrect answer paths; These are marginal hyperparameters; The path relevance score for the correct answer; The path relevance score for incorrect answers.

[0063] S27: Perform the answer entity type prediction task, and calculate the type prediction loss based on the difference between the predicted entity type and the answer entity type using the type constraint loss function.

[0064] In this step, to enhance the model's logical reasoning ability, this application proposes introducing an answer entity type prediction task trained in parallel with the main ranking task. This task forces the model to consider not only semantic matching degree when evaluating path relevance, but also to verify whether the type of the answer entity conforms to the logical constraints implicit in the question. For example, for a question like "When?", the answer should be a date type; for "How much is the premium?", the answer should be an amount type; and for "Who is his beneficiary?", the answer should be a name type. Furthermore, while "date of birth" and "place of birth" are similar in expression, the former corresponds to a date type answer, and the latter to a location type answer.

[0065] Specifically, firstly, the true type labels corresponding to the answer entities in each answer path are obtained, covering categories such as date, amount, name, and location. After the model's feature fusion layer, a type classifier is connected in parallel. This classifier receives the same fused feature vector input as the main ranking task and outputs the corresponding type probability distribution. This auxiliary task acts as a regularizer, guiding the model to consider both semantic relevance and logical correctness during the ranking process, thereby effectively mitigating the problem of spurious associations caused by the lack of intermediate supervision signals.

[0066] S28: The ranking loss and type prediction loss are weighted and summed according to preset weights to obtain the joint training total loss.

[0067] S29: Based on the joint training total loss, the parameters of the neural network model are updated through gradient backpropagation to obtain the trained neural network model, which serves as the answer path ranking model.

[0068] For steps S28-S29, the ranking loss and type prediction loss are organically combined. The total loss function is defined as the weighted sum of the two:

[0069] in, Total training loss; The ranking loss; To balance the hyperparameters; Predict loss for the type.

[0070] During training, the model simultaneously optimizes the ranking loss and type prediction loss using the gradient backpropagation algorithm. During backpropagation, the gradient of the total loss with respect to the model parameters consists of two parts: one part originates from the ranking task, driving the model to improve its semantic matching discrimination ability; the other part originates from the type prediction task, guiding the model to establish association rules between the logical type of the question and the entity type of the answer. In this joint optimization mechanism, the type prediction task provides explicit logical constraints for the main ranking task, effectively preventing the model from falling into false semantic associations. Simultaneously, the ranking task provides rich contextual semantic information for the type prediction task, thereby improving the accuracy of type discrimination. Through collaborative training, the model ultimately learns a comprehensive reasoning ability that integrates deep semantic matching and rigorous logical verification.

[0071] Through the above methods, the trained answer path ranking model significantly improves the accuracy of processing complex queries, especially demonstrating excellent performance in query scenarios with large differences in expression and complex logical relationships. At the same time, the model has good generalization ability, adapting to the ever-changing query methods and terminology in various business scenarios.

[0072] S30: Obtain the user's question and multiple candidate answer paths.

[0073] In this step, the system receives a natural language question input from the user. Based on a pre-defined knowledge base corresponding to the business scenario, it retrieves multiple candidate answer paths that may be related to the user's question.

[0074] For example, in an insurance scenario, a user asks, "How much is the annual premium for the 'Healthy Growth' education savings insurance I purchased for my child?" Subsequently, preliminary semantic analysis, including entity linking and relationship mapping, is performed on the question to identify the key entities: "healthy growth," "education savings insurance," and the core intent: inquiring about "annual premium." Based on this analysis, multi-hop retrieval and path enumeration are performed in the insurance knowledge graph. The following candidate answer paths are retrieved: "Annual premium for Healthy Growth Education Savings Insurance: 5000 yuan"; "Total premium for Healthy Growth Education Savings Insurance: 150,000 yuan."

[0075] S40: Based on the answer path ranking model, generate relevance scores and type consistency scores between user questions and each candidate answer path.

[0076] In this step, after obtaining the user question and multiple candidate answer paths, they are input into a pre-trained answer path ranking model for two-dimensional evaluation. This model performs deep semantic analysis and alignment on the question and each path, outputting a relevance score to measure the semantic probability of the path answering the question. Simultaneously, the model parallelizes the answer type probability distribution of each candidate answer path to calculate the type consistency score between the expected answer type of the user question and the answer entities of each candidate answer, evaluating the logical fit between the entity type of the path's answer and the expected answer type of the question.

[0077] For example, taking an insurance scenario, for the user question "When will the 'Growth Without Worry' insurance I purchased for my child take effect?" and candidate path A: "Growth Without Worry insurance effective date 2024-01-01", the model calculates a correlation score of 0.92 between the two, predicts the entity type "date" in the answer path to match the expected answer type "date" in the question, and calculates a type consistency score of 0.95. For another candidate path B: "Growth Without Worry insurance annual premium of 6000 yuan", the model gives a correlation score of 0.65 between the two, predicts the entity type of the answer path to be "amount", and calculates a type consistency score of 0.05.

[0078] In one embodiment of this application, such as Figure 4 As shown, a specific scheme for generating relevance scores and type consistency scores is provided. In S40, based on the answer path ranking model, the relevance scores and type consistency scores between the user question and each candidate answer path are generated, specifically including the following steps S41-S44: S41: Input the user's question and each candidate answer path into the answer path ranking model to generate a fused feature vector.

[0079] In this step, the system receives a user question and a set of candidate answer paths retrieved from the knowledge base as input, which are then fed into a pre-trained answer path ranking model. The model first performs structured serialization on each candidate answer path, converting it into a text sequence with explicit semantic role labels. Subsequently, it independently encodes the user question sequence and each path sequence to extract their overall semantic information. By calculating fine-grained relevance weights between each word in the question and each element in the path, it generates a context-aware interactive representation. Finally, the overall semantic representation and the interactive representation are concatenated and aggregated to generate a fusion feature vector for each candidate answer path that comprehensively represents the matching relationship between the question and the path.

[0080] The above methods comprehensively integrate multi-level information from global semantic similarity to local element alignment, laying the foundation for subsequent accurate evaluation.

[0081] In one embodiment of this application, such as Figure 5 As shown, a specific scheme for generating fused feature vectors is provided. In S41, the user question and each candidate answer path are input into the answer path ranking model to generate fused feature vectors, which specifically includes the following steps S411-S415: S411: Based on preset semantic role tags, serialize each candidate answer.

[0082] In this step, pre-defined semantic role markers are used to label elements in the path, such as the head entity, relation chain, intermediate entities, and answer entity. Special markers (such as "[HEAD]", "[REL]", "[ENT]", and "[ANS]") are used to clearly identify the semantic role of each element. For example, a typical two-hop inference path "Entity A → Relation R1 → Entity B → Relation R2 → Answer C" will be serialized into the standard text format "[HEAD]Entity A [REL]Relation R1 [ENT]Entity B [REL]Relation R2 [ANS]Answer C". This serialization process, while fully preserving the path structure information, provides the model with crucial inductive biases, helping it accurately understand the functional differences of different elements in the inference chain.

[0083] S412: Independently encode the user question and each candidate answer path after serialization to obtain the semantic sequence of the first question and the semantic sequence of the first answer path.

[0084] In this step, after serialization, the user's natural language question and each candidate answer path are input into the model's dual-tower encoding architecture. This architecture employs two identical Transformer encoders with shared parameters, independently encoding the question sequence and path sequence. Through deep contextual understanding based on a pre-trained language model, the base encoding layer generates a first question semantic sequence for the question sequence and a first answer path semantic sequence for each path sequence. These two sequences capture independent semantic information of the question text and path structure, respectively. The question semantic sequence can parse referencing, ellipsis, and complex sentence structures in natural language, while the path semantic sequence accurately distinguishes the logical roles of entities and relationships using special markers, providing high-quality basic semantic representations for subsequent interaction matching.

[0085] S413: Calculate the cross-sequence interaction attention matrix based on the semantic sequence of the first question and the semantic sequence of the first answer path; The elements in the cross-sequence interaction attention matrix are used to characterize the relevance weights between each word in the user's question and each element in each candidate answer path.

[0086] In this step, based on the obtained independent encodings, the model introduces a cross-sequence interactive attention mechanism to establish fine-grained semantic associations between questions and paths. A cross-sequence interactive attention matrix is ​​generated by calculating the attention weights between the first question semantic sequence and the first answer path semantic sequence. Each element in this matrix represents the relevance strength between a specific term in the user's question and a specific element in the candidate answer path. This mechanism allows the model to dynamically focus on the corresponding positions of key constraints in the question (such as the compensation amount) in the path, even if the two differ in their representation.

[0087] Optionally, the relevance strength is usually calculated using the scaled dot product attention method, which maps the problem representation and the path representation to the same semantic space through a learnable linear transformation matrix, calculates their similarity, and then normalizes them using the softmax function.

[0088] S414: Based on the cross-sequence interaction attention matrix, the first question semantic sequence and the first answer path semantic sequence are weighted and fused to generate the second question semantic sequence and the second answer path semantic sequence; In this context, each lexical representation in the second question semantic sequence incorporates contextual information from the candidate answer path, and each element representation in the second answer path semantic sequence incorporates contextual information from the user question text.

[0089] In this step, the first question semantic sequence is weighted and combined with the first answer path semantic sequence using a calculated attention matrix to generate the second question semantic sequence. Each word representation incorporates contextual information from relevant path elements, enabling the question representation to perceive the most matching path semantics. Similarly, the first answer path semantic sequence is weighted and combined with the first question semantic sequence using the transpose of the attention matrix to generate the second answer path semantic sequence. Each element representation incorporates contextual information from the question text, allowing the path representation to be dynamically adjusted based on the specific question.

[0090] The above methods enable bidirectional information flow and semantic alignment between problems and paths.

[0091] S415: Merge the semantic sequence of the first question, the semantic sequence of the first answer path, the semantic sequence of the second question, and the semantic sequence of the second answer path to obtain the fused feature vector.

[0092] In this step, the semantic sequences of the first question and the first answer path are pooled (e.g., extracting [CLS] token representations or performing sequence averaging) to obtain global features reflecting overall semantic matching. The semantic sequences of the second question and the second answer path are then pooled (e.g., max pooling) to extract local alignment features reflecting fine-grained interactions. Subsequently, these feature representations of different granularities and perspectives are concatenated along the feature dimension to form a unified fusion feature vector. This vector simultaneously contains information on global semantic similarity and local element correspondence, providing comprehensive and rich feature support for subsequent relevance scoring and type prediction, enabling the model to make comprehensive judgments based on both overall relevance and detail matching standards.

[0093] S42: Based on the fused feature vector, the correlation score between the user's question and each candidate answer path, as well as the probability distribution of the type of the answer entity of each candidate answer, are output through the answer path ranking model.

[0094] In this step, a multilayer perceptron performs a nonlinear transformation on the fused feature vector, outputting a scalar value as a relevance score. This score directly quantifies the semantic matching degree between the current candidate answer path and the user's question; a higher score indicates a greater likelihood that the path is the correct answer. Simultaneously, the auxiliary type prediction task branch processes the same fused feature vector through an independent type classifier, outputting a type probability distribution. This distribution is a multi-dimensional vector, where each dimension corresponds to a predefined entity type (e.g., date, amount, name, location), and the numerical value represents the model's confidence that the answer entity in the path belongs to the corresponding category.

[0095] For example, for a candidate path, its type probability distribution may show that the answer entity of the path has an 85% probability of being of the "amount" type and a 15% probability of being of the "numerical" type.

[0096] S43: Generate the type probability distribution of the expected answer type for the user's question through the answer path ranking model.

[0097] In this step, the user's question is input into the model, activating its type classifier branch, which directly generates a question-level type probability distribution based on the question's semantics. This distribution reflects the implicit expected answer type tendency of the question. For example, for the question "How much is the insurance premium?", the expected type distribution inferred by the model will be highly concentrated in the monetary category. Essentially, this reuses the question-answer type mapping learned during training for type parsing of user questions during the inference phase.

[0098] S44: Determine the type consistency score between the user's question and each candidate answer path based on the expected answer type and type probability distribution.

[0099] In this step, after obtaining the probability distribution of answer entity types for each candidate answer path and the expected answer type distribution for the user's question, a type consistency score is determined by calculating the degree of matching between the two. This type consistency score is a scalar value between 0 and 1; a higher score indicates a closer match between the candidate answer's type and the expected type of the question. For example, if the expected type of the question is "date," and the type distribution of a candidate answer shows that it has the highest probability of being a date, then its type consistency score is high; conversely, if it has the highest probability of being a name, then its type consistency score is low.

[0100] Optionally, the degree of matching can be calculated using various metrics, such as calculating the cosine similarity or KL divergence between two probability distributions, or directly calculating their probability product on the principal types. This application does not impose any specific limitations on these metrics.

[0101] S50: Based on relevance score and type consistency score, determine the optimal answer path among multiple candidate answer paths, and generate the question answer based on the optimal answer path.

[0102] In this step, after obtaining the relevance score and type consistency score for each candidate answer path, a comprehensive score is calculated for each path. Then, all candidate paths are sorted in descending order based on the comprehensive score, and the path ranking first is determined as the optimal answer path for this round of query. Finally, the system extracts the corresponding answer entity from this optimal answer path, organizes it into text content conforming to natural language expression standards, and returns it to the user as the final answer.

[0103] In one embodiment of this application, such as Figure 6 As shown, a specific question-answer generation scheme is provided. In S50, the optimal answer path is determined from multiple candidate answer paths based on relevance score and type consistency score, and the question answer is generated based on the optimal answer path. Specifically, it includes the following steps S51-S54: S51: Determine the comprehensive score of each candidate answer sequence based on the relevance score and the type consistency score.

[0104] In this step, after obtaining the relevance score and type consistency score of each candidate answer path, a weighted comprehensive score is calculated for each candidate path to ensure that while focusing on the semantic relevance of the path to the question, constraints are also imposed on the logical correctness of the answer type.

[0105] S52: Sort multiple comprehensive scores in descending order, and take the candidate answer path corresponding to the largest comprehensive score after sorting as the optimal answer path.

[0106] In this step, the comprehensive scores of all candidate answer paths are sorted in descending order to form an ordered path. After sorting, the candidate answer path with the highest comprehensive score is selected and determined as the optimal answer path for the current question. This path not only highly matches the question at the semantic level, but its answer entity type also conforms to the logical expectations of the question.

[0107] S53: Obtain the answer entity for the optimal answer path.

[0108] In this step, after determining the optimal answer path, which is represented in serialized form, the answer entity is explicitly identified by the special marker "[ANS]". By parsing this sequence and locating the text segment after the "[ANS]" marker, the answer entity can be directly extracted.

[0109] For example, for the serialization path "[HEAD]Policy123[REL]Beneficiary is [ENT]Zhang San[REL]Insurance type is [ANS]Health Insurance", the extracted answer entity is "Health Insurance".

[0110] S54: Generate the answer to the question based on the answer entity.

[0111] In this step, based on the extracted answer entities, the final answer to the question is generated and returned to the user.

[0112] Optionally, the presentation format of the answer can be flexibly adapted to the needs of the application scenario: in a simple question-and-answer scenario, the answer entity (such as "health insurance") can be directly returned as a text answer; in a scenario that requires explanatory or structured output, the answer entity can be combined with some path information to generate a richer response, such as "The type of insurance in policy 123 is health insurance".

[0113] As can be seen, in the above scheme, by jointly training the ranking task and the answer type prediction task, the model optimizes semantic relevance while explicitly learning the logical type constraints between questions and answers, effectively suppressing spurious associations caused by biased training data or interference from high-frequency answers. Furthermore, during the question-answer reasoning process, by leveraging the answer path ranking model and the cross-sequence interaction attention mechanism, a comprehensive ranking result combining semantic scores and type consistency scores for each candidate answer path can be obtained. This achieves multi-granularity precise matching from overall semantics to local elements, significantly improving ranking accuracy and model robustness in complex query scenarios. Therefore, in knowledge base question-answering tasks in fields such as finance, insurance, and healthcare, it can effectively distinguish between semantically similar but logically different questions, avoiding information confusion and ensuring the accuracy and reliability of the final answer.

[0114] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0115] In one embodiment, a question-and-answer processing apparatus is provided, which corresponds one-to-one with the question-and-answer processing methods described in the above embodiments. For example... Figure 7 As shown, the question-and-answer processing device includes: a first acquisition module 101, a model training module 102, a second acquisition module 103, a first generation module 104, a determination module 105, and a second generation module 106. Detailed descriptions of each functional module are as follows: The first acquisition module 101 is used to acquire a historical question and answer dataset, wherein the historical question and answer dataset includes multiple sets of historical question and answer pairs. Each set of historical question and answer pairs includes: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path. The model training module 102 is used to train the answer path ranking model based on the historical question-answering dataset through a joint learning mechanism. The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type of each candidate answer path. The second acquisition module 103 is used to acquire the user's question and multiple candidate answer paths; The first generation module 104 is used to generate a relevance score and a type consistency score between the user question and each candidate answer path based on the answer path ranking model. The determination module 105 is used to determine the optimal answer path among multiple candidate answer paths based on the relevance score and the type consistency score; the second generation module 106 is used to generate the question answer based on the optimal answer path.

[0116] In one embodiment, the first acquisition module 101 is specifically used for: Obtain multiple historical questions, along with the correct answer paths for each historical question; Based on a pre-defined knowledge base, identify at least one target entity that is semantically related to each historical question and its correct answer path. Based on at least one target entity and the correct answer path, multiple incorrect answer paths are generated for each historical question through a preset path construction strategy. Retrieve the predefined type corresponding to the answer entity for each answer path, and use it as the entity type label for each answer path.

[0117] In one embodiment, the model training module 102 is specifically used for: Construct a neural network model based on a dual-tower interactive Transformer architecture; Based on preset semantic role tags, each answer path is identified by role, and the role type corresponding to each element in each answer path is determined. The preset semantic role tags include at least one of the following: head entity tag, first relation tag, intermediate entity tag, second relation tag, and answer entity tag. Based on the preset path serialization template and role type, the marked elements in each answer path are sorted and combined to generate a sample sequence corresponding to each answer path; The serialized historical question-and-answer dataset is used as training samples and input into the neural network model. Obtain the relevance score for each answer path; The ranking loss is calculated using a list-level weighted margin ranking loss function based on the relevance scores of the correct answer path and the incorrect answer path. Perform the task of predicting the entity type of the answer, and calculate the type prediction loss based on the difference between the predicted entity type and the answer entity type using the type constraint loss function; The ranking loss and the type prediction loss are weighted and summed according to preset weights to obtain the joint training total loss; Based on the joint training total loss, the parameters of the neural network model are updated through gradient backpropagation to obtain the trained neural network model, which serves as the answer path ranking model.

[0118] In one embodiment, the neural network model includes: The input representation layer is used to serialize the paths of each candidate answer; The encoding and interaction layer is used to encode and interact with the input user question and each candidate answer path. The encoding and interaction layer includes a basic encoding layer and a cross-sequence interaction attention layer. The basic encoding layer is used to independently encode the serialized user question and each candidate answer path to obtain their respective overall semantic representations. The cross-sequence interaction attention layer is used to calculate the relevance weight between each word in the serialized user question and each element in each candidate answer path, and generate a context-aware interaction representation. The feature fusion layer is used to concatenate and aggregate the overall semantic representation and the interaction representation to form a fused feature vector; The output layer includes: a multilayer perceptron, which receives the fused feature vector and outputs the relevance score of the answer path; and a type classifier, which receives the fused feature vector and outputs the type probability distribution of the answer entity in the answer path.

[0119] In one embodiment, the first generation module 104 is specifically used for: The user's question and the paths of each candidate answer are input into the answer path ranking model to generate a fused feature vector. Based on the fused feature vector, the correlation score between the user's question and each candidate answer path, as well as the probability distribution of the type of the answer entity of each candidate answer, are output through the answer path ranking model. The expected answer type probability distribution for user questions is generated using an answer path ranking model. Based on the expected answer type and type probability distribution, the type consistency score between the user's question and each candidate answer path is determined.

[0120] In one embodiment, the first generation module 104 is further configured to: Based on preset semantic role tags, each candidate answer is serialized. The user question and each candidate answer path after serialization are independently encoded to obtain the semantic sequence of the first question and the semantic sequence of the first answer path. Based on the semantic sequence of the first question and the semantic sequence of the first answer path, a cross-sequence interaction attention matrix is ​​calculated, where the elements in the cross-sequence interaction attention matrix are used to characterize the relevance weights between each word in the user question and each element in each candidate answer path; Based on the cross-sequence interaction attention matrix, the first question semantic sequence and the first answer path semantic sequence are weighted and fused to generate the second question semantic sequence and the second answer path semantic sequence. Each word in the second question semantic sequence represents the fusion of contextual information from the candidate answer path, and each element in the second answer path semantic sequence represents the fusion of contextual information from the user's question text. The first question semantic sequence, the first answer path semantic sequence, the second question semantic sequence, and the second answer path semantic sequence are fused to obtain a fused feature vector.

[0121] In one embodiment, the determining module 105 is specifically used for: Based on relevance score and type consistency score, determine the comprehensive score of each candidate answer sequence; Sort the multiple comprehensive scores in descending order, and select the candidate answer path corresponding to the highest comprehensive score as the optimal answer path.

[0122] In one embodiment, the second generation module 106 is specifically used for: The answer entity that retrieves the optimal answer path; Generate the answer to the question based on the answer entity.

[0123] This invention provides a question-answering processing device that, through joint training of ranking and answer type prediction tasks, allows the model to optimize semantic relevance while explicitly learning the logical type constraints between questions and answers, effectively suppressing spurious associations caused by biased training data or interference from high-frequency answers. Furthermore, during the question-answer reasoning process, by leveraging an answer path ranking model and a cross-sequence interactive attention mechanism, a comprehensive ranking result combining semantic scores and type consistency scores of each candidate answer path can be obtained. This achieves multi-granularity precise matching from overall semantics to local elements, significantly improving ranking accuracy and model robustness in complex query scenarios. Therefore, in knowledge base question-answering tasks in fields such as finance, insurance, and healthcare, it can effectively distinguish between semantically similar but logically different questions, avoiding information confusion and ensuring the accuracy and reliability of the final answer.

[0124] For specific limitations regarding the question-and-answer processing device, please refer to the limitations on the question-and-answer processing method above, which will not be repeated here. Each module in the aforementioned question-and-answer processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.

[0125] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When the computer program is executed by the processor, it implements the functions or steps of a question-and-answer processing method on the server side.

[0126] In one embodiment, a computer device is provided, which may be a client, and its internal structure diagram may be as follows: Figure 9 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with an external server via a network connection. When executed by the processor, the computer program implements the client-side functions or steps of a question-and-answer processing method.

[0127] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described question-and-answer processing method.

[0128] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the above-described question-and-answer processing method.

[0129] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.

[0130] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0131] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0132] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A question-and-answer processing method, characterized in that, include: Obtain a historical question-and-answer dataset, wherein the historical question-and-answer dataset includes multiple sets of historical question-and-answer pairs, each set of historical question-and-answer pairs including: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path; Based on the historical question-and-answer dataset, an answer path ranking model is trained through a joint learning mechanism. The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type of each candidate answer path. Obtain the user's question and multiple candidate answer paths; Based on the answer path ranking model, a relevance score and a type consistency score are generated between the user question and each candidate answer path. Based on the relevance score and the type consistency score, the optimal answer path is determined among the multiple candidate answer paths, and the question answer is generated based on the optimal answer path.

2. The question-and-answer processing method according to claim 1, characterized in that, The steps for obtaining the historical question-and-answer dataset specifically include: Obtain multiple historical questions, along with the correct answer paths for each historical question; Based on a pre-defined knowledge base, identify at least one target entity that is semantically related to each historical question and its correct answer path. Based on the at least one target entity and the correct answer path, multiple incorrect answer paths corresponding to each historical question are generated through a preset path construction strategy; Retrieve the predefined type corresponding to the answer entity for each answer path, and use it as the entity type label for each answer path.

3. The question-and-answer processing method according to claim 1, characterized in that, The step of training the answer path ranking model based on the historical question-and-answer dataset through a joint learning mechanism specifically includes: Construct a neural network model based on a dual-tower interactive Transformer architecture; Based on preset semantic role tags, each answer path is identified by role, and the role type corresponding to each element in each answer path is determined. The preset semantic role tags include at least one of the following: head entity tag, first relation tag, intermediate entity tag, second relation tag, and answer entity tag. Based on the preset path serialization template and role type, the marked elements in each answer path are sorted and combined to generate a sample sequence corresponding to each answer path; The serialized historical question-and-answer dataset is used as training samples and input into the neural network model. Obtain the relevance score for each answer path; The ranking loss is calculated using a list-level weighted margin ranking loss function based on the relevance scores of the correct answer path and the incorrect answer path. Perform the task of predicting the entity type of the answer, and calculate the type prediction loss based on the difference between the predicted entity type and the answer entity type using the type constraint loss function; The ranking loss and the type prediction loss are weighted and summed according to preset weights to obtain the joint training total loss; Based on the joint training total loss, the parameters of the neural network model are updated through gradient backpropagation to obtain the trained neural network model, which serves as the answer path ranking model.

4. The question-and-answer processing method according to claim 3, characterized in that, The neural network model includes: The input representation layer is used to serialize the paths of each candidate answer; The encoding and interaction layer is used to encode and interact with the input user question and each candidate answer path. The encoding and interaction layer includes a basic encoding layer and a cross-sequence interaction attention layer. The basic encoding layer is used to independently encode the serialized user question and each candidate answer path to obtain their respective overall semantic representations. The cross-sequence interaction attention layer is used to calculate the relevance weight between each word in the serialized user question and each element in each candidate answer path, and generate a context-aware interaction representation. The feature fusion layer is used to concatenate and aggregate the overall semantic representation and the interaction representation to form a fused feature vector; The output layer includes: a multilayer perceptron, which receives the fused feature vector and outputs the relevance score of the answer path; and a type classifier, which receives the fused feature vector and outputs the type probability distribution of the answer entity in the answer path.

5. The question-and-answer processing method according to claim 1, characterized in that, The step of generating relevance scores and type consistency scores between the user question and each candidate answer path based on the answer path ranking model specifically includes: The user question and each candidate answer path are input into the answer path ranking model to generate a fused feature vector; Based on the fused feature vector, the correlation score between the user's question and each candidate answer path, as well as the probability distribution of the type of the answer entity of each candidate answer, are output through the answer path ranking model. The expected answer type probability distribution for the user's question is generated using the answer path sorting model. Based on the expected answer type and type probability distribution, the type consistency score between the user's question and each candidate answer path is determined.

6. The question-and-answer processing method according to claim 5, characterized in that, The step of inputting the user question and each candidate answer path into the answer path ranking model to generate a fused feature vector specifically includes: Based on preset semantic role tags, each candidate answer is serialized. The user question and each candidate answer path after serialization are independently encoded to obtain the semantic sequence of the first question and the semantic sequence of the first answer path. Based on the first question semantic sequence and the first answer path semantic sequence, a cross-sequence interaction attention matrix is ​​calculated, wherein the elements in the cross-sequence interaction attention matrix are used to characterize the relevance weights between each word in the user question and each element in each candidate answer path; Based on the cross-sequence interaction attention matrix, the first question semantic sequence and the first answer path semantic sequence are weighted and fused to generate a second question semantic sequence and a second answer path semantic sequence. Each word in the second question semantic sequence represents the fusion of contextual information from the candidate answer path, and each element in the second answer path semantic sequence represents the fusion of contextual information from the user's question text. The first question semantic sequence, the first answer path semantic sequence, the second question semantic sequence, and the second answer path semantic sequence are fused to obtain the fused feature vector.

7. The question-and-answer processing method according to claim 1, characterized in that, The step of determining the optimal answer path from the plurality of candidate answer paths based on the relevance score and the type consistency score, and generating the question answer based on the optimal answer path, specifically includes: Based on the relevance score and the type consistency score, a comprehensive score is determined for each candidate answer sequence; Sort the multiple comprehensive scores in descending order, and take the candidate answer path corresponding to the highest comprehensive score after sorting as the optimal answer path; Obtain the answer entity for the optimal answer path; Based on the answer entity, the answer to the question is generated.

8. A question-and-answer processing device, characterized in that, include: The first acquisition module is used to acquire a historical question and answer dataset, wherein the historical question and answer dataset includes multiple sets of historical question and answer pairs, and each set of historical question and answer pairs includes: a historical question, a correct answer path corresponding to the historical question as a positive sample, multiple incorrect answer paths as negative samples, and the entity type of each answer path; The model training module is used to train an answer path ranking model based on the historical question-and-answer dataset through a joint learning mechanism. The answer path ranking model is used to evaluate the semantic relevance between the user's question and each candidate answer path, and to output the probability distribution of the answer entity type of each candidate answer path. The second acquisition module is used to acquire user questions and multiple candidate answer paths; The first generation module is used to generate a relevance score and a type consistency score between the user question and each candidate answer path based on the answer path ranking model. The determining module is used to determine the optimal answer path among the multiple candidate answer paths based on the relevance score and the type consistency score; the second generating module is used to generate the question answer based on the optimal answer path.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the question-and-answer processing method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the question-and-answer processing method as described in any one of claims 1 to 7.