Question and answer query method, question and answer query device, electronic equipment and storage medium
By introducing non-target domain and target domain encoders into the pre-trained language model and optimizing model parameters using semantic shared space and contrastive learning, the accuracy problem of the pre-trained language model caused by the semantic differences between professional terms and general vocabulary is solved, thereby improving the accuracy of question-and-answer queries in fintech and digital healthcare scenarios.
Patent Information
- Application Number
- CN202510885175.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-10-17
AI Technical Summary
Pre-trained language models are unable to distinguish the semantic differences between professional terms and general vocabulary when generating answers, resulting in low accuracy of question-and-answer queries in fintech and digital healthcare scenarios.
Question and answer features are extracted through the non-target domain encoder and the target domain encoder, and mapped to the semantic shared space for semantic alignment. Contrastive learning and adversarial loss are used to optimize the model parameters to improve the accuracy of answer generation.
It has achieved improved accuracy and adaptability of question-and-answer queries in fintech and digital healthcare scenarios, and enhanced the matching degree between answers and questions.
Smart Images

Figure CN120804252A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and is applied to the fields of financial technology and digital medicine, and in particular relates to a question and answer query method and device, an electronic device and a storage medium. BACKGROUND
[0002] In related technologies, a pre-trained language model is used to generate answers to query questions. However, the pre-trained language model is a general model suitable for multiple different tasks, and there is a significant semantic deviation between the embedding space features of the model and specific domain professional terms, resulting in low accuracy of the generated answers. Taking the financial technology scenario as an example, when a user needs to query the operation process of policy termination, the query question will contain professional terms such as policy termination in the insurance field. However, the pre-trained language model cannot distinguish the semantic difference between the professional term “policy termination” and the general term “contract termination”, resulting in the generation of answers related to the contract termination operation process. Taking the digital medical scenario as an example, when a user needs to query the absorption effect of a specific drug, the query question will contain professional terms such as drug absorption in the medical field. However, the pre-trained language model cannot distinguish the semantic difference between the professional term “absorption” and the general term “absorption”, resulting in the generation of answers unrelated to the absorption effect of the drug. Therefore, how to improve the accuracy of question and answer queries has become a problem to be solved. SUMMARY
[0003] The main purpose of the embodiments of the present application is to provide a question and answer query method, a question and answer query device, an electronic device and a storage medium, which aims to improve the accuracy of question and answer queries.
[0004] To achieve the above-mentioned purpose, a first aspect of the embodiments of the present application provides a question and answer query method, which comprises:
[0005] obtaining a sample question and answer pair, the sample question and answer pair comprising a sample question and a sample domain answer text of the sample question;
[0006] extracting question features of the sample question by a non-target domain encoder to obtain general question features, and extracting answer features of the sample domain answer text by a target domain encoder to obtain domain answer features; wherein the target domain encoder is obtained by training the non-target domain encoder according to a target domain corpus, and the domain category of the target domain corpus is the same as the domain category of the sample question and answer pair;
[0007] mapping the general question features and the domain answer features to a semantic shared space for semantic alignment to obtain semantic alignment features; wherein the semantic shared space has a space weight parameter;
[0008] performing loss calculation according to the semantic alignment features to obtain a target loss;
[0009] updating the model parameters of the non-target domain encoder, the model parameters of the target domain encoder, and the spatial weight parameters according to the target loss to obtain a question-answering query model;
[0010] The question-answering query model is used to query the preset target question and obtain the target answer.
[0011] In some embodiments, the semantic alignment features include a target question alignment feature and a target answer alignment feature, and performing loss calculation based on the semantic alignment features to obtain a target loss includes:
[0012] Performing contrastive learning based on the target question alignment feature and the target answer alignment feature to obtain a contrastive loss;
[0013] Calculating the mean difference based on the target question alignment feature and the target answer alignment feature to obtain the mean difference loss;
[0014] Performing feature discrimination on the target question alignment feature and the target answer alignment feature by a discriminator to obtain an adversarial loss;
[0015] The contrast loss, the mean difference loss, and the adversarial loss are summed to obtain the target loss.
[0016] In some embodiments, the target answer alignment feature includes a positive answer feature and a negative answer feature, and performing comparative learning based on the target question alignment feature and the target answer alignment feature to obtain the comparative loss includes:
[0017] Calculating a feature similarity between the target question alignment feature and the positive example answer feature to obtain a first similarity;
[0018] Calculating a feature similarity between the target question alignment feature and the negative example answer feature to obtain a second similarity;
[0019] Loss calculation is performed according to the first similarity and the second similarity to obtain the comparison loss.
[0020] In some embodiments, extracting answer features from the sample domain answer text using a target domain encoder to obtain domain answer features includes:
[0021] Performing text feature extraction on the sample domain answer text to obtain text content features and text structure features;
[0022] Performing image feature extraction on the sample domain answer text to obtain image visual features;
[0023] perform feature fusion on the text content features, the text structure features, and the image visual features to obtain target text features;
[0024] perform answer feature extraction on the target text features by the target domain encoder to obtain the domain answer features.
[0025] In some embodiments, the performing question query on the preset target question by the question and answer query model to obtain a target answer comprises:
[0026] performing question feature extraction on the target question by the question and answer query model to obtain reference question alignment features;
[0027] querying the semantic sharing space according to the reference question alignment features to obtain reference answer alignment features;
[0028] obtaining a feature index of the reference answer alignment features;
[0029] querying a preset knowledge base according to the feature index to obtain the target answer.
[0030] In some embodiments, the querying the preset knowledge base according to the feature index to obtain the target answer comprises:
[0031] querying a preset knowledge base according to the feature index to obtain an original answer;
[0032] obtaining an original language category of the original answer;
[0033] comparing the original language category with a preset language category;
[0034] if the original language category is different from the preset language category, translating the original answer from the original language category to the preset language category to obtain the target answer.
[0035] In some embodiments, the translating the original answer from the original language category to the preset language category to obtain the target answer if the original language category is different from the preset language category comprises:
[0036] if the original language category is different from the preset language category, obtaining a text length of the original answer;
[0037] obtaining a translation model according to the text length;
[0038] performing text segmentation on the original answer according to the text length to obtain an original answer subsegment; wherein the original answer subsegment has a subsegment sequence identifier;
[0039] translate the original answer sub-segment from the original language category to the preset language category by the translation model to obtain a reference answer sub-segment;
[0040] According to the sub-segment order identification, the reference answer sub-segment is spliced to obtain the target answer.
[0041] To achieve the above object, a second aspect of the embodiment of the present application provides a question and answer query device, the device comprises:
[0042] a sample acquisition module, configured to acquire a sample question and answer pair, the sample question and answer pair comprising a sample question and a sample field answer text of the sample question;
[0043] a feature extraction module, configured to perform question feature extraction on the sample question by a non-target field encoder to obtain general question features, and perform answer feature extraction on the sample field answer text by a target field encoder to obtain field answer features; wherein the target field encoder is obtained by training the non-target field encoder according to a target field corpus, and the field category of the target field corpus is the same as the field category of the sample question and answer pair;
[0044] a semantic alignment module, configured to map the general question features and the field answer features to a semantic shared space for semantic alignment to obtain semantic alignment features; wherein the semantic shared space has a space weight parameter;
[0045] a loss calculation module, configured to perform loss calculation according to the semantic alignment features to obtain a target loss;
[0046] an update module, configured to update model parameters of the non-target field encoder, model parameters of the target field encoder and the space weight parameter according to the target loss to obtain a question and answer query model;
[0047] a query module, configured to perform question query on a preset target question by the question and answer query model to obtain a target answer.
[0048] To achieve the above object, a third aspect of the embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the method of the first aspect when executing the computer program.
[0049] To achieve the above object, a fourth aspect of the embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing a computer program, and the computer program implementing the method of the first aspect when executed by a processor.
[0050] The question-answer query method, question-answer query device, electronic device and computer-readable storage medium proposed in the embodiments of the present application obtain sample question-answer pairs to construct a question-answer query model based on the sample question-answer pairs. The sample question-answer pairs include a sample question and a sample domain answer text of the sample question. In order to fully understand the semantics of the sample question and the sample domain answer text, the non-target domain encoder is used to extract question features of the sample question to obtain general question features, and the target domain encoder is used to extract answer features of the sample domain answer text to obtain domain answer features. In order to make up for the semantic deviation between the general question features extracted by the non-target domain encoder and the domain professional terms, the general question features and the domain answer features are mapped to a semantic shared space for semantic alignment to explicitly model the mapping relationship between the general language and the domain terms, so that the semantics between the general question features and the domain answer features are consistent, and semantic alignment features are obtained. The loss is calculated based on the semantic alignment features to obtain the target loss, so as to optimize the model based on the target loss and improve the accuracy of answer generation. Based on the target loss, the model parameters of the non-target domain encoder, the model parameters of the target domain encoder, and the spatial weight parameters of the semantic shared space are updated to obtain a question-answering query model. This joint optimization model can learn shared semantic representations, improving the adaptability of the question-answering query model and the quality of answer generation. The question-answering query model is used to query the preset target question and obtain the target answer, improving the match between the target answer and the target question, thereby improving the accuracy of the question-answering query. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 This is a flowchart of the question-and-answer query method provided by an embodiment of the present application;
[0052] Figure 2 yes Figure 1 Flowchart of step S120 in FIG.
[0053] Figure 3 yes Figure 1 Flowchart of step S140 in FIG.
[0054] Figure 4 yes Figure 3 Flowchart of step S310 in FIG.
[0055] Figure 5 yes Figure 1 Flowchart of step S160 in FIG.
[0056] Figure 6 yes Figure 5 Flowchart of step S540 in FIG.
[0057] Figure 7 yes Figure 6 Flowchart of step S640 in FIG.
[0058] Figure 8 FIG. 1 is a structural schematic diagram of a question and answer query device provided by an embodiment of the present application;
[0059] Figure 9 FIG. 2 is a hardware structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0060] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not intended to limit the present application.
[0061] It should be noted that although the functional modules are divided in the device schematic diagram, and the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a manner different from the module division in the device or the order in the flowchart. The terms "first", "second", and the like in the specification and claims and the above-described drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0062] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0063] In the related art, the answer to the query question is generated by a pre-trained language model. However, the pre-trained language model is a general model suitable for various tasks, and there is a significant semantic deviation between the embedding space features of the model and the professional terms in a specific field, resulting in low accuracy of the generated answer. For example, in the financial technology scenario, when a user needs to query the operation process of policy termination, the query question will contain professional terms such as policy termination in the insurance field. However, the pre-trained language model cannot distinguish the semantic difference between the professional term "policy termination" and the general term "contract termination", resulting in the generation of an answer related to the contract termination operation process. For example, in the digital medical scenario, when a user needs to query the absorption effect of a specific drug, the query question will contain professional terms such as drug absorption in the medical field. However, the pre-trained language model cannot distinguish the semantic difference between the professional term "absorption" and the general term "absorption", resulting in the generation of an answer unrelated to the absorption effect of the drug. Therefore, how to improve the accuracy of question and answer query has become a problem to be solved.
[0064] Based on this, the embodiments of the present application provide a question and answer query method, a question and answer query device, an electronic device and a computer readable storage medium, which aim to improve the accuracy of question and answer query.
[0065] The question-and-answer query method, question-and-answer query device, electronic device, and computer-readable storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the question-and-answer query method in the embodiments of the present application is described.
[0066] The question-and-answer query method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The question-and-answer query method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the question-and-answer query method, etc., but is not limited to the above forms.
[0067] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and the like. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments in which tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.
[0068] Figure 1 This is an optional flowchart of the question-answer query method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S110 to S160.
[0069] Step S110, obtaining a sample question-answer pair, the sample question-answer pair including a sample question and a sample domain answer text of the sample question;
[0070] In step S120, the sample question is subjected to question feature extraction by a non-target field encoder to obtain general question features, and the sample field answer text is subjected to answer feature extraction by a target field encoder to obtain field answer features; the target field encoder is obtained by training the non-target field encoder according to a target field corpus, and the field category of the target field corpus is the same as the field category of the sample question and answer pair;
[0071] In step S130, the general question features and the field answer features are mapped to a semantic shared space for semantic alignment to obtain semantic alignment features; the semantic shared space has a space weight parameter;
[0072] In step S140, loss calculation is performed according to the semantic alignment features to obtain a target loss;
[0073] In step S150, the model parameters of the non-target field encoder, the model parameters of the target field encoder and the space weight parameter are updated according to the target loss to obtain a question and answer query model;
[0074] In step S160, a target question is subjected to question query by the question and answer query model to obtain a target answer.
[0075] The steps S110 to S160 shown in the embodiments of the present application explicitly model the mapping relationship between the general language and the field terms in the semantic shared space, make up for the semantic deviation between the general question features and the field terms, make the semantic consistent between the general question features and the field answer features, and thus improve the accuracy of the question and answer query.
[0076] In step S110 of some embodiments, a sample question-answer pair is obtained from the corpus, the sample question-answer pair being an information pair composed of a question and an answer for model training. The sample question-answer pair includes a sample question and a sample domain answer text of the sample question, the sample question being question text for a specific domain used in the model training process, and the sample domain answer text being answer text for the sample question. The sample domain answer text includes positive example answer text and negative example answer text, the positive example answer text being answer text that is semantically matched to the sample question and correct, and the negative example answer text being answer text that is semantically mismatched to the sample question or incorrect. There can be multiple negative example answer texts for the same sample question. Taking the financial technology scenario as an example, the sample question is “What is a digital currency wallet”, and the positive example answer text is answer text that can accurately describe the function and use of a digital currency wallet. Negative example answer text 1 is “A digital currency wallet is a tool that can be used to buy stocks”, in which the semantics of buying stocks and a digital currency wallet do not match. Negative example answer text 2 is “A digital currency wallet is an entity wallet for storing cash”, which incorrectly describes the digital currency wallet, which is a software application, as an entity wallet. Taking the digital medical scenario as an example, the sample question is “What is telemedicine”, and the positive example answer text can accurately describe the definition and main functions of telemedicine. Negative example answer text 1 is “Telemedicine is a device that can be used in a hospital”, in which the semantics of telemedicine and a hospital device do not match. Negative example answer text 2 is “Telemedicine is an online shopping service”, which incorrectly describes a medical service as an online shopping service.
[0077] The non-target domain encoder is a general language encoder, such as a 12-layer BERT-base model, which is suitable for various text processing tasks. When users ask questions, they will use different words and sentence patterns to describe the same or similar intent, which makes the sample question usually have a wider semantic range and more flexible expression. In order to accurately understand the semantics of the sample question, the semantic understanding ability and multi-language support ability of the general language encoder are used, and the sample question is converted into a fixed-length vector representation by the non-target domain encoder to capture the semantics of the sample question, obtaining general question features.
[0078] The target domain encoder is a domain-specific encoder, such as a 6-layer DistilBERT model, which is suitable for a specific domain text processing task. The answer contains specific domain professional terms and professional knowledge. In order to ensure the professionalism and accuracy of the answer, the text semantics of the sample domain answer text is captured by the target domain encoder to obtain domain answer features. The target domain encoder is obtained by training a non-target domain encoder according to a target domain corpus, and the domain category of the target domain corpus is the same as the domain category of the sample question and answer pair. The feature dimension of the domain answer feature is the same as the feature dimension of the general question feature. For example, if the domain category is the insurance domain, the target domain encoder can be obtained by fine-tuning the non-target domain encoder according to the insurance corpus of the insurance domain.
[0079] By combining the general language encoder and the domain-specific encoder to build a dual-path encoder, the wide applicability of the general model and the professionalism of the domain-specific model can be fully utilized to achieve better question and answer results.
[0080] Please refer to Figure 2 In some embodiments, step S120 can include but is not limited to steps S210 to S240:
[0081] Step S210, text feature extraction is performed on the sample domain answer text to obtain text content features and text structure features;
[0082] Step S220, image feature extraction is performed on the sample domain answer text to obtain image visual features;
[0083] Step S230, feature fusion is performed on the text content features, the text structure features, and the image visual features to obtain target text features;
[0084] Step S240, answer feature extraction is performed on the target text features by the target domain encoder to obtain domain answer features.
[0085] In step S210 of some embodiments, the sample domain answer text is a text formed by organizing the answer text content according to the text structure. The text structure includes the layout, format, and logical order of the text, and the text structure can be chapter titles, clause numbers, paragraphs, etc. For example, the insurance claim specification is a text obtained by organizing the relevant text content according to the chapters of insurance claim overview, claim process, claim required materials, and common claim problems. The sample domain answer text contains text content and text structure. The text content of the sample domain answer text can be obtained by performing optical character recognition on the sample domain answer text by an optical character recognition (OCR) engine. The text structure of the sample domain answer text can be identified by calling a layout analysis algorithm to obtain the text structure features.
[0086] In step S220 of some embodiments, in order to more accurately and intuitively describe the professional knowledge, the sample field answer text usually contains tables, diagrams and other charts. In order to fully understand the semantics of the sample field answer text and ensure the integrity of the information, image feature extraction can be performed on the sample field answer text by the Vision Transformer model to analyze the visual features of tables, diagrams and other visual features, and obtain image visual features.
[0087] In step S230 of some embodiments, the text content features, text structure features and image visual features are spliced or added to fuse the features of different modalities and fully express the semantics of the answer, and obtain target text features.
[0088] In step S240 of some embodiments, in order to extract deeper semantic features such as the association between the text content and the diagram, the target text features are input into the target field encoder to extract answer features, and obtain field answer features.
[0089] The steps S210 to S240 described above can fully understand the semantics of the answer text for a specific field by multi-modal feature extraction of the answer text, thereby improving the accuracy of the question and answer query.
[0090] In step S130 of some embodiments, in order to solve the semantic deviation between the general language and the field professional terms, the mapping relationship between the general language and the specific field terms is explicitly modeled by establishing a semantic shared space. The general question features and the field answer features are mapped to the same feature space, i.e. the semantic shared space, for semantic alignment, to eliminate the semantic deviation between the general features and the field features, realize cross-domain semantic alignment, and obtain semantic alignment features. The semantic shared space has a space weight parameter, which includes a first weight parameter for the general question features and a second weight parameter for the field answer features. The first weight parameter includes a first weight and a first bias, and the second weight parameter includes a second weight and a second bias. The first weight can be initialized as an identity matrix to preserve the general semantics. The second weight is initialized as Xavier to facilitate field adaptation. The semantic alignment features include target question alignment features and target answer alignment features. The target question alignment features are obtained by feature mapping of the general question features according to the first weight and the first bias. The calculation formula of the target question alignment features is represented as:
[0091] P Gen =W Gen E Gen +b Gen ,
[0092] where P Genis a target question alignment feature; W Gen is a first weight; E Gen is a general question feature; b Gen is a first bias.
[0093] The target answer alignment feature is obtained by performing feature mapping on the domain answer feature according to a second weight and a second bias. A calculation formula of the target answer alignment feature is represented as:
[0094] P Dom = W Dom E Dom +b Dom ,
[0095] wherein, P Dom is the target answer alignment feature; W Dom is the second weight; E Dom is the domain answer feature; b Dom is the second bias.
[0096] A loss value of the model training according to the target question alignment feature and the target answer alignment feature is calculated to obtain a target loss. The calculation process of the target loss is described in detail below.
[0097] Referring to Figure 3 In some embodiments, step S140 can include, but is not limited to, steps S310 to S340:
[0098] Step S310, contrast learning is performed according to the target question alignment feature and the target answer alignment feature to obtain a contrast loss;
[0099] Step S320, mean difference calculation is performed according to the target question alignment feature and the target answer alignment feature to obtain a mean difference loss;
[0100] Step S330, feature discrimination is performed on the target question alignment feature and the target answer alignment feature by a discriminator to obtain an adversarial loss;
[0101] Step S340, loss summation is performed on the contrast loss, the mean difference loss and the adversarial loss to obtain the target loss.
[0102] In step S310 of some embodiments, the target answer alignment feature includes positive example answer features and negative example answer features. The answer feature of the positive example answer text can be extracted by a target domain encoder, and the extracted answer feature is mapped to a semantic shared space to obtain the positive example answer feature. The acquisition process of the negative example answer feature is the same as that of the positive example answer feature, which is not described here.
[0103] To enable the model to learn the semantic alignment relationship between the question and the positive example answer features and the semantic difference relationship between the question and the negative example answer features, contrast learning is performed on the target question alignment features, the positive example answer features and the negative example answer features according to the target question alignment features, the positive example answer features and the negative example answer features, and a loss value of the contrast learning is calculated to obtain a contrast loss.
[0104] In step S320 of some embodiments, the target question alignment features are mapped to a reproducing Hilbert space by a kernel function to obtain intermediate question features. The positive example answer features are mapped to the reproducing Hilbert space by the kernel function to obtain intermediate answer features. The intermediate question features are subjected to mean value calculation to obtain question average features. The intermediate answer features are subjected to mean value calculation to obtain answer average features. To enable the model to learn the semantic alignment relationship between the question and the positive example answer features in a high-dimensional space, loss calculation is performed on the question average features and the answer average features to obtain a mean difference loss. A calculation formula of the mean difference loss is represented as:
[0105]
[0106] wherein, L MMD is the mean difference loss; n is the number of sample question and answer pairs; φ is the kernel function; is the target question alignment features of the i th sample question and answer pair; is the positive example answer features of the i th sample question and answer pair.
[0107] The kernel function can be defined as:
[0108]
[0109] wherein, x is an input parameter; σ is a Gaussian kernel bandwidth, which can be 1.
[0110] In step S330 of some embodiments, the target question alignment features and the positive example answer features are subjected to feature addition to obtain positive example fusion features. The target question alignment features and the negative example answer features are subjected to feature addition to obtain negative example fusion features. The positive example fusion features are subjected to discrimination by a discriminator to obtain a first probability that the sample question and the positive example answer text are a correct question and answer pair. The negative example fusion features are subjected to discrimination by the discriminator to obtain a second probability that the sample question and the negative example answer text are a negative example question and answer pair. An adversarial loss is calculated according to the first probability and the second probability. The discriminator enables the model to learn the correct matching relationship between the question and the answer. A calculation formula of the adversarial loss is represented as:
[0111]
[0112] wherein, L adv is the adversarial loss; D represents the discriminator; n is the number of correct question and answer pairs composed of the sample question and the positive example answer text; P1i represents the ith positive example fusion feature; D(P 1i ) represents the first probability; m is the number of negative example question and answer pairs composed of sample questions and negative example answer texts; P 2j represents the jth negative example fusion feature; 1-D(P 2j ) represents the second probability.
[0113] In step S340 of some embodiments, the contrast loss, the mean difference loss, and the adversarial loss are added to obtain the target loss. Alternatively, the contrast loss, the mean difference loss, and the adversarial loss are weighted and summed according to weights to obtain the target loss. The weights can be set by the actual situation, for example, the weight of the contrast loss is 1, the weight of the mean difference loss is 0.3, and the weight of the adversarial loss is 0.2.
[0114] Through the above steps S310 to S340, the target loss can be obtained to optimize the model parameters according to the target loss and improve the accuracy of the question and answer query.
[0115] Please refer to Figure 4 , in some embodiments, step S310 can include but is not limited to steps S410 to S430:
[0116] Step S410, calculating the feature similarity between the target question alignment feature and the positive example answer feature to obtain the first similarity;
[0117] Step S420, calculating the feature similarity between the target question alignment feature and the negative example answer feature to obtain the second similarity;
[0118] Step S430, loss calculation according to the first similarity and the second similarity to obtain the contrast loss.
[0119] In step S410 of some embodiments, the feature similarity between the target question alignment feature and the positive example answer feature is calculated according to the cosine similarity function to obtain the first similarity. The cosine similarity function is represented as:
[0120] sim(x,y)=x T y / ||x||||y||,
[0121] wherein x and y are input parameters; T represents the transpose operation; ||·|| represents the Euclidean norm.
[0122] The first similarity is represented as sim(P Gen ,P Dom1 ), wherein P Gen is the target question alignment feature, and P Dom1 is the positive example answer feature.
[0123] In step S420 of some embodiments, a feature similarity between the target question alignment feature and the negative example answer feature is calculated according to a cosine similarity function, to obtain a second similarity.
[0124] The second similarity is denoted as sim (P Gen ,P Dom2 ), where P Gen is the target question alignment feature, and P Dom2 is the negative example answer feature.
[0125] In step S430 of some embodiments, a contrastive loss calculation is performed according to the first similarity and the second similarity, to obtain a contrastive loss. The calculation formula of the contrastive loss is denoted as:
[0126]
[0127] wherein, is the i th target question alignment feature; is the i th positive example answer feature; N is the number of negative example answer texts for the i th sample question; denotes the j th negative example answer feature; τ is a temperature coefficient; L Contrastive is the contrastive loss.
[0128] Through the above steps S410 to S430, the contrastive loss can be obtained, so that the model learns the semantic alignment relationship between the question and the answer based on the contrastive loss, thereby improving the efficiency of the question and answer query.
[0129] In step S150 of some embodiments, the target loss is minimized, and the model parameters of the non-target domain encoder, the model parameters of the target domain encoder, the first weight parameter for the general question feature, and the second weight parameter for the domain answer feature are updated to obtain a question and answer query model.
[0130] Referring to Figure 5 , in some embodiments, step S160 can include but is not limited to steps S510 to S540:
[0131] Step S510, performing question feature extraction on the target question through the question and answer query model to obtain a reference question alignment feature;
[0132] Step S520, querying the semantic shared space according to the reference question alignment feature to obtain a reference answer alignment feature;
[0133] Step S530, obtaining a feature index of the reference answer alignment feature;
[0134] Step S540, querying a preset knowledge base according to the feature index to obtain a target answer.
[0135] In step S510 of some embodiments, the target question is a question to be queried for an answer. The question and answer query model includes an updated non-target domain encoder and an updated semantic shared space. The target question is subjected to question feature extraction by the updated non-target domain encoder to obtain reference question features. The reference question features are subjected to feature mapping by the updated first weight parameter in the semantic shared space to obtain reference question alignment features. The non-target domain encoder supports multiple languages and can input target questions in any language.
[0136] In step S520 of some embodiments, the semantic shared space includes a plurality of target answer alignment features, and the similarity between the reference question alignment features and each target answer alignment feature is calculated. The target answer alignment feature with the greatest similarity is taken as the reference answer alignment feature. The reference answer alignment feature is used to query a preset knowledge base to obtain the target answer to the target question. The preset knowledge base is a system for storing domain knowledge.
[0137] In step S530 of some embodiments, in order to improve the efficiency of question and answer queries, support real-time query requirements for ten million question and answer queries, and maintain a millisecond-level response speed, an index is created for the reference answer alignment features by an index creation tool to obtain a feature index. The type of index can be selected according to actual conditions, such as HNSW index, which can support 5000 queries per second.
[0138] In step S540 of some embodiments, the preset knowledge base is queried according to the feature index to obtain the target answer to the target question.
[0139] Through the above steps S510 to S540, the accuracy of question and answer queries is improved, and the efficiency of queries is improved through indexing.
[0140] Please refer to Figure 6 In some embodiments, step S540 can include but is not limited to steps S610 to S640:
[0141] Step S610, querying the preset knowledge base according to the feature index to obtain an original answer;
[0142] Step S620, obtaining an original language category of the original answer;
[0143] Step S630, comparing the original language category and a preset language category;
[0144] Step S640, if the original language category and the preset language category are different, translating the original answer from the original language category to the preset language category to obtain the target answer.
[0145] In step S610 of some embodiments, the answer to the target question is queried in the preset knowledge base according to the feature index, and an original answer is obtained.
[0146] In step S620 of some embodiments, the language category of the original answer is obtained, and an original language category is obtained. The language category is a category obtained by classifying languages according to linguistic features, such as English, Chinese, etc.
[0147] In step S630 of some embodiments, the preset language category is a language type that the answer should use in advance. The original language category and the preset language category are compared to determine whether they are the same, and whether the original language category meets the answer output requirement is evaluated.
[0148] In step S640 of some embodiments, if the original language category and the preset language category are the same, it means that the original language category is a language category that meets the output requirement, and the original answer is taken as the target answer. If the original language category and the preset language category are different, it means that the original language category does not meet the output requirement, and the original answer is translated from the original language category to the preset language category to obtain the target answer.
[0149] Through steps S610 to S640 described above, the answer to the question and answer query can be output according to the set language type, and high-quality question and answer query is realized.
[0150] Please refer to Figure 7 In some embodiments, step S640 can include but is not limited to steps S710 to S750:
[0151] In step S710, if the original language category and the preset language category are different, the text length of the original answer is obtained.
[0152] In step S720, a translation model is obtained according to the text length.
[0153] In step S730, the original answer is text segmented according to the text length, and an original answer subsegment is obtained. The original answer subsegment has a subsegment order identifier.
[0154] In step S740, the original answer subsegment is translated from the original language category to the preset language category by the translation model, and a reference answer subsegment is obtained.
[0155] In step S750, the reference answer subsegment is spliced according to the subsegment order identifier, and a target answer is obtained.
[0156] In step S710 of some embodiments, if the original language category and the preset language category are different, the number of characters in the original answer is counted, and the text length is obtained.
[0157] In step S720 of some embodiments, it is judged according to the text length whether the original answer is a long text or a short text. The short text usually contains less context information, and the translation mainly depends on the direct correspondence of keywords and phrases. The long text contains more context information and complex sentence structure, and the translation needs to deal with complex context dependence. In order to improve the quality of answer generation, different translation models need to be selected for different lengths of text. If the text length is greater than the preset length threshold, it means that the original answer is a long text, and a long text translation model is obtained as the translation model. If the text length is less than or equal to the preset length threshold, it means that the original answer is a short text, and a short text translation model is obtained as the translation model. The long text translation model can be a transformer model, a long short-term memory network, or a pre-trained language model such as BERT, GPT, etc. The short text translation model can be a lightweight translation model, such as a lightweight transformer model. The preset length threshold can be set according to actual conditions, such as 1000.
[0158] In step S730 of some embodiments, if the text length is greater than the preset length threshold, in order to improve the translation efficiency, the original answer is text segmented in units of sentences to obtain original answer subsegments. The original answer field contains complete sentences, and the original answer subsegment has a subsegment order identifier. The subsegment order identifier is used to identify the position order of the original answer subsegment in the original answer, such as 1.1.1 representing the first chapter, the first section, and the first paragraph. If the text length is less than or equal to the preset length threshold, the original answer is translated from the original language category to the preset language category by the translation model to obtain the target answer.
[0159] In step S740 of some embodiments, the translation model is deployed to multiple computing nodes, and the original answer subsegment is translated from the original language category to the preset language category by the translation model deployed on the multiple computing nodes in parallel to obtain the reference answer subsegment.
[0160] In step S750 of some embodiments, in order to ensure the integrity of the answer, the reference answer subsegment is spliced in sequence according to the subsegment order identifier to obtain the target answer.
[0161] Through the above steps S710 to S750, the efficiency of text translation can be improved, thereby improving the efficiency of question and answer query.
[0162] Please refer to Figure 8 The embodiments of the present application also provide a question and answer query device, which can implement the above question and answer query method. The question and answer query device comprises:
[0163] The sample acquisition module 810 is configured to acquire a sample question and answer pair, wherein the sample question and answer pair comprises a sample question and a sample field answer text of the sample question.
[0164] The feature extraction module 820 is configured to perform question feature extraction on the sample question by using a non-target field encoder to obtain general question features, and perform answer feature extraction on the sample field answer text by using a target field encoder to obtain field answer features; the target field encoder is obtained by training the non-target field encoder according to a target field corpus, and the field category of the target field corpus is the same as the field category of the sample question and answer pair;
[0165] The semantic alignment module 830 is configured to map the general question features and the field answer features to a semantic shared space for semantic alignment to obtain semantic alignment features; the semantic shared space has a space weight parameter;
[0166] The loss calculation module 840 is configured to perform loss calculation according to the semantic alignment features to obtain a target loss;
[0167] The updating module 850 is configured to update the model parameters of the non-target field encoder, the model parameters of the target field encoder, and the space weight parameter according to the target loss to obtain a question and answer query model;
[0168] The query module 860 is configured to perform question query on a preset target question by using the question and answer query model to obtain a target answer.
[0169] The specific implementation of the question and answer query device is basically the same as the specific implementation of the question and answer query method described above, and will not be repeated here.
[0170] The embodiments of the present application also provide an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the question and answer query method described above when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a vehicle-mounted computer, etc.
[0171] Please refer to Figure 9 , Figure 9 The hardware structure of the electronic device of another embodiment is illustrated, which includes:
[0172] The processor 910 can be implemented in a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), or one or more integrated circuits, etc., and is configured to execute related programs to implement the technical solutions provided by the embodiments of the present application.
[0173] The memory 920 can be implemented in the form of a read only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM), etc. The memory 920 can store an operating system and other application programs, and when the technical solutions provided by the embodiments of the present specification are implemented by software or firmware, the related program codes are stored in the memory 920 and are called and executed by the processor 910 to implement the question and answer query method of the embodiments of the present application;
[0174] The input / output interface 930 is configured to realize information input and output.
[0175] The communication interface 940 is configured to realize the communication interaction between the device and other devices, which can realize the communication through a wired manner (such as a USB, a network cable, etc.) or a wireless manner (such as a mobile network, WIFI, Bluetooth, etc.).
[0176] The bus 950 is configured to transmit information between various components (such as the processor 910, the memory 920, the input / output interface 930, and the communication interface 940) of the device.
[0177] The processor 910, the memory 920, the input / output interface 930, and the communication interface 940 are connected to each other through the bus 950 to realize the communication connection between the device.
[0178] The embodiments of the present application also provide a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the above question and answer query method.
[0179] The memory is a non-transitory computer readable storage medium, which can be used to store a non-transitory software program and a non-transitory computer executable program. In addition, the memory can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory remotely arranged relative to the processor, and these remote memories can be connected to the processor through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0180] The question and answer query method, the question and answer query device, the electronic device, and the computer storage medium provided by the embodiments of the present application can explicitly model the mapping relationship between the general language and the domain term through the semantic sharing space, make up for the semantic deviation between the general question feature and the domain term, make the semantic consistency between the general question feature and the domain answer feature, and thus improve the accuracy of the question and answer query.
[0181] The embodiments described in the specification are for more clearly illustrating the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those skilled in the art can know that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0182] Those skilled in the art can understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and can include more or fewer steps than shown in the figures, or combine certain steps, or different steps.
[0183] The device embodiments described above are only schematic, and the units described as separate components can or can not be physically separate, that is, can be located in one place, or can be distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0184] Those skilled in the art can understand that all or some of the steps in the above disclosed method, the function modules / units in the system and the device can be implemented as software, firmware, hardware and their appropriate combinations.
[0185] The terms "first", "second", "third", "fourth" and the like (if any) in the specification and above-described drawings of the present application are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0186] It should be understood that, in the application, "at least one" refers to one or more, and "multiple" refers to two or more. "And / or" is used to describe the association relationship of the associated objects, which means that there can be three relationships, for example, "A and / or B" can represent three cases of only A, only B, and A and B existing at the same time, wherein A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after it. "At least one of the following" or similar expressions means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b or c can represent a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, and c can be single or multiple.
[0187] In several embodiments provided in the application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the above units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0188] The units described above as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or they can be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0189] In addition, the functional units in each embodiment of the application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0190] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes multiple instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program storage media.
[0191] The preferred embodiments of the embodiments of the present application are described above with reference to the accompanying drawings, and are not limited to the scope of the embodiments of the present application. Any modifications, equivalent replacements and improvements made by those skilled in the art without departing from the scope and essence of the embodiments of the present application shall be within the scope of the embodiments of the present application.
Claims
1. A question-answering query method, characterized in that: The method comprises: Obtaining a sample question-answer pair, wherein the sample question-answer pair includes a sample question and a sample domain answer text for the sample question; Extracting question features from the sample question using a non-target domain encoder to obtain general question features, and extracting answer features from the sample domain answer text using a target domain encoder to obtain domain answer features; wherein the target domain encoder is obtained by training the non-target domain encoder based on target domain corpus, and the domain category of the target domain corpus is the same as the domain category of the sample question-answer pair; Mapping the general question feature and the domain answer feature to a semantic shared space for semantic alignment to obtain a semantic alignment feature; wherein the semantic shared space has a spatial weight parameter; Calculate the loss based on the semantic alignment features to obtain the target loss; updating the model parameters of the non-target domain encoder, the model parameters of the target domain encoder, and the spatial weight parameters according to the target loss to obtain a question-answering query model; The question-answering query model is used to query the preset target question and obtain the target answer.
2. The method according to claim 1, characterized in that The semantic alignment features include a target question alignment feature and a target answer alignment feature. The loss calculation is performed based on the semantic alignment features to obtain a target loss, including: Performing contrastive learning based on the target question alignment feature and the target answer alignment feature to obtain a contrastive loss; Calculating the mean difference based on the target question alignment feature and the target answer alignment feature to obtain the mean difference loss; Performing feature discrimination on the target question alignment feature and the target answer alignment feature by a discriminator to obtain an adversarial loss; The contrast loss, the mean difference loss, and the adversarial loss are summed to obtain the target loss.
3. The method according to claim 2, characterized in that The target answer alignment feature includes a positive answer feature and a negative answer feature, and performing comparative learning based on the target question alignment feature and the target answer alignment feature to obtain a comparative loss includes: Calculating a feature similarity between the target question alignment feature and the positive answer feature to obtain a first similarity; Calculating a feature similarity between the target question alignment feature and the negative example answer feature to obtain a second similarity; Loss calculation is performed according to the first similarity and the second similarity to obtain the comparison loss.
4. The method according to claim 1, wherein The extracting answer features from the sample domain answer text by the target domain encoder to obtain domain answer features includes: Performing text feature extraction on the sample domain answer text to obtain text content features and text structure features; Performing image feature extraction on the sample domain answer text to obtain image visual features; Performing feature fusion on the text content features, the text structure features, and the image visual features to obtain target text features; The target domain encoder extracts answer features from the target text features to obtain the domain answer features.
5. The method according to any one of claims 1 to 4, characterized in that The step of querying a preset target question using the question-answer query model to obtain a target answer includes: Extracting question features from the target question using the question-answering query model to obtain reference question alignment features; Querying the semantic shared space according to the reference question alignment feature to obtain a reference answer alignment feature; Obtaining a feature index of the reference answer alignment feature; The preset knowledge base is queried according to the feature index to obtain the target answer.
6. The method according to claim 5, characterized in that The querying of a preset knowledge base according to the feature index to obtain the target answer includes: Querying a preset knowledge base according to the feature index to obtain an original answer; Obtaining the original language category of the original answer; comparing the original language category with the preset language category; If the original language category is different from the preset language category, the original answer is translated from the original language category to the preset language category to obtain the target answer.
7. The method according to claim 6, characterized in that If the original language category and the preset language category are different, translating the original answer from the original language category to the preset language category to obtain the target answer includes: If the original language category is different from the preset language category, obtaining the text length of the original answer; Obtaining a translation model according to the length of the text; Segmenting the original answer text according to the text length to obtain original answer sub-segments; wherein the original answer sub-segments have sub-segment sequence identifiers; translating the original answer sub-segment from the original language category to the preset language category using the translation model to obtain a reference answer sub-segment; The reference answer sub-segments are spliced according to the sub-segment sequence identifiers to obtain the target answer.
8. A question-answering query device, characterized in that: The device comprises: A sample acquisition module is used to acquire a sample question-answer pair, wherein the sample question-answer pair includes a sample question and a sample domain answer text of the sample question; A feature extraction module is configured to extract question features from the sample question using a non-target domain encoder to obtain general question features, and to extract answer features from the sample domain answer text using a target domain encoder to obtain domain answer features; wherein the target domain encoder is obtained by training the non-target domain encoder based on target domain corpus, and the domain category of the target domain corpus is the same as the domain category of the sample question-answer pair; A semantic alignment module, configured to map the general question feature and the domain answer feature to a semantic shared space for semantic alignment, thereby obtaining a semantic alignment feature; wherein the semantic shared space has a spatial weight parameter; A loss calculation module, configured to calculate the loss based on the semantic alignment features to obtain a target loss; An updating module, configured to update the model parameters of the non-target domain encoder, the model parameters of the target domain encoder, and the spatial weight parameters according to the target loss to obtain a question-answering query model; The query module is used to query the preset target question through the question-answer query model to obtain the target answer.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.