Question and answer matching method, question and answer matching device, electronic device and storage medium
By performing context feature extraction and sequence annotation on the original sentence data, combined with feature extraction and matching probability calculation of the question-and-answer matching model, the target question-and-answer pairs are selected, solving the problem of low matching of questions and answers in the existing technology, and achieving higher matching accuracy.
Patent Information
- Application Number
- CN202210687408.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-17
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2042-06-17
AI Technical Summary
In the prior art, the matching degree between questions and answers is not high enough, resulting in the matching between answer prediction and questions in the field of intelligent prediction.
By obtaining the original sentence data, context feature extraction and sequence annotation, a Q&A pair is constructed, and a preset Q&A matching model is used to perform feature extraction and matching probability calculation, and the target Q&A pair is selected.
It improves the matching accuracy of questions and answers, can better capture the complete semantic information of target questions and candidate answers, and improves the matching effect.
Smart Images

Figure CN115033674B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a question-answer matching method, a question-answer matching device, an electronic device, and a storage medium. Background Art
[0002] In the field of intelligent prediction, it is usually possible to predict answers based on questions. Currently, predictions are usually made by extracting matching answers from a database based on the questions. However, the predicted answers do not match the questions well enough. Therefore, how to improve the matching accuracy between questions and answers has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to propose a question-answer matching method, a question-answer matching device, an electronic device and a storage medium, aiming to improve the matching accuracy of questions and answers.
[0004] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a question-answer matching method, the method comprising:
[0005] Get the original sentence data to be processed;
[0006] Extracting context features from the original sentence data to obtain initial sentence data;
[0007] Performing sequence tagging on the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each of the candidate answers being used to answer one of the target questions;
[0008] Constructing an initial question-answer pair according to the target question and the candidate answers;
[0009] Extracting features from the initial question and answer pair using a preset question and answer matching model to obtain question and answer semantic features;
[0010] The question-answer matching model is used to calculate the matching probability of the question-answer semantic features to obtain a question-answer matching value, and the initial question-answer pair is screened according to the question-answer matching value to obtain a target question-answer pair, wherein the target question-answer pair includes a target question and a target answer corresponding to the target question.
[0011] In some embodiments, the step of extracting context features from the original sentence data to obtain initial sentence data includes:
[0012] Performing feature embedding processing on the original sentence data to obtain a sentence embedding vector;
[0013] Context features are extracted from the sentence embedding vector using a preset attention mechanism model to obtain the initial sentence data.
[0014] In some embodiments, the step of performing feature embedding processing on the original sentence data to obtain a sentence embedding vector includes:
[0015] Performing word segmentation processing on the original sentence data to obtain original word segments;
[0016] Performing word embedding processing on the original word segment to obtain an original word embedding vector;
[0017] The original word embedding vectors are concatenated to obtain the sentence embedding vector.
[0018] In some embodiments, the step of performing sequence tagging on the initial sentence data to obtain target question data and candidate answer data includes:
[0019] Performing position prediction on the initial sentence data according to a preset first function and a BIO label to obtain a question position label and an answer position label of the initial sentence data;
[0020] The initial sentence data is segmented according to the question position label to obtain the target question data, and the initial sentence data is segmented according to the answer position label to obtain the candidate answer data.
[0021] In some embodiments, the step of segmenting the initial sentence data according to the question position label to obtain the target question data, and segmenting the initial sentence data according to the answer position label to obtain the candidate answer data includes:
[0022] Extracting a question start tag and a question end tag from the question position tag, and segmenting the initial sentence data according to the question start tag and the question end tag to obtain the target question data;
[0023] The answer start tag and the answer end tag in the answer position tag are extracted, and the candidate answer data are segmented according to the answer start tag and the answer end tag to obtain the candidate answer data.
[0024] In some embodiments, the step of extracting features from the initial question and answer pair using a preset question and answer matching model to obtain question and answer semantic features includes:
[0025] Encoding the initial question and answer pair through the question and answer matching model to obtain a question and answer encoding vector;
[0026] The question-answer encoding vector is normalized to obtain the question-answer semantic feature, where the question-answer semantic feature is a representation feature used to represent the context semantic information of a sentence.
[0027] In some embodiments, the step of calculating the matching probability of the question and answer semantic features by using the question and answer matching model to obtain a question and answer matching value, and screening the initial question and answer pairs according to the question and answer matching value to obtain a target question and answer pair includes:
[0028] Calculating the matching probability of the question and answer semantic features by using the second function of the question and answer matching model to obtain the question and answer matching value;
[0029] The initial question-answer pair with the largest question-answer matching value is used as the target question-answer pair.
[0030] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a question-answer matching device, the device comprising:
[0031] An acquisition module, used to acquire original sentence data to be processed;
[0032] A first feature extraction module, used to extract context features from the original sentence data to obtain initial sentence data;
[0033] A sequence labeling module is used to perform sequence labeling on the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each of which is used to answer one of the target questions;
[0034] A construction module, used to construct an initial question-answer pair according to the target question and the candidate answer;
[0035] A second feature extraction module is used to extract features from the initial question and answer pair through a preset question and answer matching model to obtain question and answer semantic features;
[0036] A calculation module is used to calculate the matching probability of the question and answer semantic features through the question and answer matching model to obtain a question and answer matching value, and to screen the initial question and answer pairs according to the question and answer matching value to obtain a target question and answer pair, wherein the target question and answer pair includes a target question and a target answer corresponding to the target question.
[0037] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program, when executed by the processor, implements the method described in the first aspect above.
[0038] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium used for computer-readable storage, and the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method described in the first aspect above.
[0039] The question-answer matching method, question-answer matching device, electronic device and storage medium proposed in the present application obtain the original sentence data to be processed; extract the contextual features of the original sentence data to obtain the initial sentence data, which can better preserve the contextual semantic information of the original sentence and improve the semantic integrity of the original sentence. Furthermore, the initial sentence data is sequence-labeled to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions, and the target question and candidate answer in the initial sentence data can be split into independent text data according to the labeling information, so as to pair the target question and the candidate answer to construct an initial question-answer pair, each of which includes a target question and a candidate answer. Finally, the preset question-answer matching model is used to extract features of the initial question-answer pair to obtain question-answer semantic features, thereby extracting the question-answer representation information of the initial question-answer pair, and calculating the matching probability of the question-answer semantic features to obtain the question-answer matching value. The initial question-answer pair is screened according to the question-answer matching value to obtain the target question-answer pair, where the target question-answer pair includes the target question and the target answer corresponding to the target question. This method can better capture the complete semantic information of the target question and candidate answers, improve the matching effect of the target question and the target answer, and improve the matching accuracy of the question and answer. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a flowchart of the question-answer matching method provided in an embodiment of the present application;
[0041] Figure 2 yes Figure 1 Flow chart of step S102 in FIG.
[0042] Figure 3 yes Figure 2 Flow chart of step S201 in FIG.
[0043] Figure 4 yes Figure 1 Flow chart of step S103 in FIG.
[0044] Figure 5 yes Figure 4 Flow chart of step S402 in FIG.
[0045] Figure 6 yes Figure 1 Flow chart of step S105 in FIG.
[0046] Figure 7 yes Figure 1 Flow chart of step S106 in FIG.
[0047] Figure 8 is a schematic diagram of the structure of a question-answer matching device provided in an embodiment of the present application;
[0048] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0050] 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 may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0052] First, some nouns involved in this application are analyzed:
[0053] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0054] Natural language processing (NLP): NLP uses computers to process, understand and apply human languages (such as Chinese, English, etc.). NLP is a branch of artificial intelligence and an interdisciplinary subject between computer science and linguistics. It is often referred to as computational linguistics. Natural language processing includes grammatical analysis, semantic analysis, and text understanding. Natural language processing is often used in technical fields such as machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, information intent recognition, information extraction and filtering, text classification and clustering, public opinion analysis and opinion mining. It involves data mining related to language processing, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computing.
[0055] Information Extraction: A text processing technology that extracts specified types of entity, relationship, event and other factual information from natural language text and forms structured data output. Information extraction is a technology that extracts specific information from text data. Text data is composed of some specific units, such as sentences, paragraphs, and chapters. Text information is composed of some small specific units, such as characters, words, phrases, sentences, paragraphs, or a combination of these specific units. Extracting noun phrases, names, place names, etc. from text data are all text information extraction. Of course, the information extracted by text information extraction technology can be various types of information.
[0056] Encoder: Converts the input sequence into a vector of fixed length.
[0057] Embedding: The Embedding Layer is a word embedding that is jointly learned with a neural network model for specific natural language processing. This embedding method one-hot encodes the words in the cleaned text, and the size or dimension of the vector space is specified as part of the model, such as 50, 100, or 300 dimensions. The vector is initialized with a small random number. The Embedding Layer is used at the front end of the neural network and is supervised by the backpropagation algorithm. The encoded words are mapped into word vectors, and if a multi-layer perceptron model MLP is used, the word vectors are cascaded before being input into the model. If a recurrent neural network RNN is used, each word can be used as an input in the sequence. This method of learning the embedding layer requires a lot of training data and can be slow, but it can learn and train embedding models that are both specific to text data and for NLP. Embedding is a vector representation, which means using a low-dimensional vector to represent an object. The object can be a word, a product, a movie, etc. The nature of this Embedding vector is that it can make objects corresponding to vectors with similar distances have similar meanings. For example, the distance between Embedding (Avengers) and Embedding (Iron Man) will be very close, but the distance between Embedding (Avengers) and Embedding (Gone with the Wind) will be farther. Embedding is essentially a mapping from semantic space to vector space, while trying to maintain the relationship of the original samples in the semantic space in the vector space. For example, the positions of two words with similar semantics in the vector space are also relatively close. Embedding can encode objects with low-dimensional vectors and retain their meaning. It is often used in machine learning. In the process of building machine learning models, objects are encoded into a low-dimensional dense vector and then passed to DNN to improve efficiency.
[0058] Long Short-Term Memory (LSTM): It is a time-recurrent neural network specially designed to solve the long-term dependency problem of general RNN (recurrent neural network). All RNNs have a chain form of repeated neural network modules. In standard RNN, this repeated structural module has only a very simple structure, such as a tanh layer. LSTM is a type of neural network containing LSTM blocks or other. In literature or other materials, LSTM blocks may be described as intelligent network units because they can remember values of indefinite lengths of time. There is a gate in the block that can determine whether the input is important enough to be remembered and whether it can be output.
[0059] Bi-directional Long Short-Term Memory (Bi-LSTM): It is composed of forward LSTM and backward LSTM. It is often used to model contextual information in natural language processing tasks. Bi-LSTM combines the information of the input sequence in both the forward and backward directions based on LSTM. For the output at time t, the forward LSTM layer has the information at time t and before in the input sequence, while the backward LSTM layer has the information at time t and after in the input sequence. The output of the forward LSTM layer at time t is recorded as X, and the output of the backward LSTM layer at time t is recorded as Y. The vectors output by the two LSTM layers can be processed by addition, average or concatenation.
[0060] Tokenizer: Divides text into individual units (usually words).
[0061] Softmax function: The Softmax function is a normalized exponential function that can "compress" a K-dimensional vector z containing any real number into another K-dimensional real vector σ(z) so that the range of each element is between (0,1) and the sum of all elements is 1. This function is often used in multi-classification problems.
[0062] Normalization: There are two forms of normalization methods, one is to convert the number into a decimal between (0, 1), and the other is to convert the dimensional expression into a dimensionless expression. It is mainly proposed for the convenience of data processing. Mapping the data to the range of 0 to 1 for processing is more convenient and faster, and should be classified as part of digital signal processing.
[0063] In the field of intelligent prediction, it is usually possible to predict answers based on questions. Currently, predictions are usually made by extracting matching answers from a database based on the questions. In specific question-and-answer scenarios, this method often predicts answers for each question individually, and the predicted answers do not match the questions well enough. Therefore, how to improve the matching accuracy of questions and answers has become a technical problem that needs to be solved urgently.
[0064] Based on this, the embodiments of the present application provide a question-answer matching method, a question-answer matching device, an electronic device, and a storage medium, aiming to improve the matching accuracy of questions and answers.
[0065] The question-answer matching method, question-answer matching device, electronic device and storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the question-answer matching method in the embodiments of the present application is described.
[0066] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0067] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0068] The question-answer matching method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The question-answer matching 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 a server cluster or a distributed system composed of multiple physical servers, or 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-answer matching method, etc., but is not limited to the above forms.
[0069] 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, etc. 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, etc. 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 through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0070] Figure 1 is an optional flowchart of the question-answer matching method provided in an embodiment of the present application. Figure 1The method may include but is not limited to steps S101 to S106.
[0071] Step S101, obtaining original sentence data to be processed;
[0072] Step S102, extracting context features from the original sentence data to obtain initial sentence data;
[0073] Step S103, sequence tagging the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions;
[0074] Step S104, constructing an initial question-answer pair based on the target question and candidate answers;
[0075] Step S105, extracting features from the initial question and answer pair using a preset question and answer matching model to obtain question and answer semantic features;
[0076] Step S106, calculate the matching probability of the question and answer semantic features through the question and answer matching model to obtain the question and answer matching value, and screen the initial question and answer pairs according to the question and answer matching value to obtain the target question and answer pair, wherein the target question and answer pair includes the target question and the target answer corresponding to the target question.
[0077] Steps S101 to S106 shown in the embodiment of the present application, by obtaining the original sentence data to be processed; extracting context features from the original sentence data to obtain initial sentence data, can better preserve the contextual semantic information of the original sentence and improve the semantic integrity of the original sentence. Further, the initial sentence data is sequence labeled to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions, and the target question and candidate answer in the initial sentence data can be split into independent text data according to the labeled information, so as to pair the target question and the candidate answer to construct an initial question-answer pair, each of which includes a target question and a candidate answer. Finally, the preset question-answer matching model is used to extract features of the initial question-answer pair to obtain question-answer semantic features, thereby extracting the question-answer representation information of the initial question-answer pair, and calculating the matching probability of the question-answer semantic features to obtain the question-answer matching value. The initial question-answer pair is screened according to the question-answer matching value to obtain the target question-answer pair, where the target question-answer pair includes the target question and the target answer corresponding to the target question. This method can better capture the complete semantic information of the target question and candidate answers, improve the matching effect of the target question and the target answer, and improve the matching accuracy of the question and answer.
[0078] In step S101 of some embodiments, a web crawler may be written, and after setting a data source, data may be crawled in a targeted manner to obtain the original sentence data to be processed. The original sentence data may also be obtained in other ways, not limited thereto. The original sentence data may be text data, and the original sentence data mainly includes two types of sentences, namely, question sentences and answer sentences.
[0079] See also Figure 2 In some embodiments, step S102 may include but is not limited to steps S201 to S202:
[0080] Step S201, performing feature embedding processing on the original sentence data to obtain a sentence embedding vector;
[0081] Step S202, extracting context features from the sentence embedding vector using a preset attention mechanism model to obtain initial sentence data.
[0082] In step S201 of some embodiments, feature embedding is performed on the original sentence data through a preset pre-trained model, and this feature embedding process includes embedding processing of the question sentence part and the answer sentence part in the original sentence data, wherein the preset pre-trained model may be a roberta model, etc. For example, feature embedding processing is performed on the original sentence data through the roberta model to obtain initial word embedding data and initial sentence embedding data corresponding to the original sentence data, multi-head attention calculation is performed on the word embedding data to obtain candidate sentence embedding data, and the candidate sentence embedding data and the initial sentence embedding data are concatenated to obtain a sentence embedding vector.
[0083] In step S202 of some embodiments, the preset attention mechanism model can be constructed based on the LSTM algorithm or the Bi-LSTM algorithm. Taking the Bi-LSTM algorithm as an example, the sentence embedding vector can be encoded and processed from left to right through the attention mechanism model to obtain a first feature vector a, and then the sentence embedding vector is encoded and processed from right to left to obtain a second feature vector b. The first feature vector and the second feature vector are processed by vector addition, vector averaging, etc., which can better capture the contextual semantic information of the sentence embedding vector, thereby obtaining initial sentence data, which is mainly CLS feature data.
[0084] It should be noted that the CLS feature mainly obtains the representation of sentence-level information through the self-attention mechanism. In different tasks, the CLS feature can be used to represent the contextual information in a specific environment. In an embodiment of the present application, the CLS feature can represent the contextual information of questions and answers in a question-and-answer matching environment.
[0085] The above steps S201 to S202 can better preserve the contextual semantic information of the original sentence, thereby improving the semantic integrity of the original sentence.
[0086] See also Figure 3 In some embodiments, step S201 may include but is not limited to steps S301 to S303:
[0087] Step S301, performing word segmentation processing on the original sentence data to obtain original word segments;
[0088] Step S302, performing word embedding processing on the original word segment to obtain an original word embedding vector;
[0089] Step S303, concatenate the original word embedding vectors to obtain a sentence embedding vector.
[0090] In step S301 of some embodiments, the original sentence data is segmented by a preset Jieba word segmenter. Specifically, the dictionary file in the Jieba word segmenter is first loaded, and each word and the number of times the word appears in the Jieba word segmenter are obtained. Further, the dictionary file is traversed, and a directed acyclic graph of all possible word segmentation situations in the original sentence data is constructed by string matching, and the maximum probability of all paths from each Chinese character node in the original sentence data to the end of the sentence is calculated, and the end position of the corresponding Chinese character segment in the directed acyclic graph when the maximum probability is recorded. Finally, the original sentence data is segmented according to the node path to obtain the original segment. In addition, for the original sentence data that does not have a corresponding word in the dictionary file, it can be processed by a statistical method to obtain the original segment.
[0091] In step S302 of some embodiments, word embedding processing is performed on the original word segment to achieve mapping of the original word segment from the semantic space to the vector space, and obtain the original word embedding vector.
[0092] In step S303 of some embodiments, the original word embedding vectors are concatenated according to the order of the original word segments in the entire original sentence data to obtain a complete long vector, which is the sentence embedding vector.
[0093] See also Figure 4 In some embodiments, step S103 may include but is not limited to steps S401 to S402:
[0094] Step S401, performing position prediction on the initial sentence data according to the preset first function and BIO label to obtain the question position label and the answer position label of the initial sentence data;
[0095] Step S402, segmenting the initial sentence data according to the question position label to obtain target question data, and segmenting the initial sentence data according to the answer position label to obtain candidate answer data.
[0096] In step S401 of some embodiments, when the position of the initial sentence data is predicted according to a preset first function, the first function may adopt a classification function such as a softmax function, and a joint labeling method may be introduced, that is, a BIO labeling method is adopted to label different sentence parts of each initial sentence with different labels, wherein in the BIO labeling, Bx generally means that the segment where the part is located belongs to X and is at the beginning position, Ix generally means that the segment where the part is located belongs to X and is in the middle position, and O generally means that it does not belong to any part.
[0097] Specifically, according to the BIO annotation, the preset BIO tags are set as question position tags and answer position tags, wherein the question position tags include the question start tag Bq, the question middle tag Iq, and the question end tag Oq, and the answer position tags include the answer start tag Ba, the answer middle tag Ia, and the answer end tag Oa. The position probability of the initial sentence data is calculated by the softmax function to obtain the probability distribution of each preset position tag of the initial sentence data (i.e., the position probability vector). The probability distribution reflects the degree of matching between the sentence fragment corresponding to the initial sentence data and the preset position tag. The larger the initial probability vector, the greater the possibility that the sentence fragment belongs to the preset position tag. Therefore, the preset position tag corresponding to the position probability vector with the largest value is selected as the position tag of each sentence fragment, and the question position tag and the answer position tag of the initial sentence data are obtained.
[0098] It should be noted that each target question includes question content and a question location label, and the question location label is used to mark the location of the question content. Each candidate answer includes answer content and an answer location label, and the answer location label is used to mark the location of the answer content.
[0099] For example, for an initial sentence: All articles have advantages and disadvantages. Please point out the advantages and disadvantages of this article based on the content and results of the text. Ask another question, what is the core idea of the article? According to the first function and the preset position label, it can be split into sentence fragments. Each sentence fragment and the corresponding position label can form a notation form of <sentence fragment n, position label n>, that is, <All articles have advantages and disadvantages, Bq1>, <Please point out the advantages and disadvantages of this article based on the content and results of the article, Iq1>, <Point out the advantages and disadvantages of this article, Iq2>, <Ask another question, Oq1>, <What is the core idea of the article? , Bq2>. In this way, we can more intuitively get the target questions in the initial sentence as "Please point out the advantages and disadvantages of this article based on the content and results of the article" and "What is the core idea of the article".
[0100] See also Figure 5 In some embodiments, step S402 may include but is not limited to steps S501 to S502:
[0101] Step S501, extracting the question start tag and the question end tag in the question position tag, and segmenting the initial sentence data according to the question start tag and the question end tag to obtain target question data;
[0102] Step S502: extract the answer start tag and the answer end tag in the answer position tag, and segment the candidate answer data according to the answer start tag and the answer end tag to obtain the candidate answer data.
[0103] In step S501 of some embodiments, the question position label includes a question start label Bq, a question middle label Iq, and a question end label Oq. Since a target question can be formed between the question start label Bq and the question end label Oq, the initial sentence data is segmented according to the question start label and the question end label, and the sentence fragment between the question start label Bq and the question end label Oq is cut out to obtain the target question data.
[0104] In step S502 of some embodiments, the answer position tag includes an answer start tag Ba, an answer middle tag Ia, and an answer end tag Oa. Since a candidate question can be formed between the answer start tag Ba and the answer end tag Oa, the initial sentence data is segmented according to the answer start tag and the answer end tag, and the sentence fragment between the answer start tag Ba and the answer end tag Oa is cut out to obtain the candidate answer data.
[0105] Through the above steps S501 to S502, the initial sentence data can be split into multiple separate target questions and candidate answers according to the question position label and the answer position label while retaining the contextual semantic information of the original sentence, thereby improving the matching accuracy of questions and answers.
[0106] In step S104 of some embodiments, when constructing an initial question-answer pair based on the target question and the candidate answers, the target question is paired with each candidate answer to form a one-to-many mapping relationship between the target question and the candidate answers, thereby obtaining an initial question-answer pair, wherein each initial question-answer pair includes a target question and a candidate answer.
[0107] Before step S105 in some embodiments, the question-answer matching method further includes pre-training a question-answer matching model, wherein the question-answer matching model can be constructed based on the Roberta model, and the question-answer matching model includes an encoding layer and a linear layer, wherein the encoding layer is mainly used to encode the input question-answer pair and capture the CLS features of the input question-answer pair, and the linear layer is mainly used to perform probability calculations on the CLS features and determine the degree of relevance between the question and the answer in each question-answer pair. When training the question-answer matching model, the sample question-answer pairs are input into the question-answer matching model, and the model loss is calculated by the loss function of the question-answer matching model, wherein the loss function can be a commonly used cross entropy loss function, and at the same time, the gradient descent method can be used to back-propagate the model loss, and the model parameters of the question-answer matching are adjusted according to the model loss to train the question-answer matching model.
[0108] See also Figure 6 In some embodiments, step S105 includes but is not limited to steps S601 to S602:
[0109] Step S601, encoding the initial question and answer pair through the question and answer matching model to obtain a question and answer encoding vector;
[0110] Step S602, normalize the question and answer encoding vector to obtain question and answer semantic features, where the question and answer semantic features are representation features used to represent the semantic information of the sentence context.
[0111] In step S601 of some embodiments, the initial question and answer pair can be processed by word embedding through the transformer algorithm of the question and answer matching model, so as to realize the mapping of the initial question and answer pair from the semantic space to the vector space, and can maintain the relationship of the initial question and answer pair in the semantic space in the vector space, so as to obtain the question and answer encoding vector in an embedded form.
[0112] In step S602 of some embodiments, the question and answer encoding vector is normalized by a question and answer matching model to convert the question and answer encoding vector from a dimensional form to a dimensionless representation of question and answer semantic features, where the question and answer semantic features are CLS features that can be used to characterize the semantic context information of the question and answer pair in a question and answer matching scenario.
[0113] In some specific embodiments, the specific process of encoding and normalizing the initial question-answer pair by the question-answer matching model can be expressed as shown in formula (1):
[0114] h cls =BERT(X) Formula (1)
[0115] Among them, h cls is the question-answer semantic feature, X is the initial question-answer pair input, and BERT is the encoding and normalization operation process.
[0116] See also Figure 7 In some embodiments, step S106 may include but is not limited to steps S701 to S702:
[0117] Step S701, calculating the matching probability of the question and answer semantic features through the second function of the question and answer matching model to obtain a question and answer matching value;
[0118] Step S702: taking the initial question-answer pair with the largest question-answer matching value as the target question-answer pair.
[0119] In step S701 of some embodiments, the second function may be a classification function such as a softmax function or a sigmoid function. Taking the softmax function as an example, the matching probability of the question and answer semantic features is calculated by the softmax function to obtain the probability distribution of each question and answer semantic feature in the preset classification label. The probability distribution is the question and answer matching value. If the question and answer matching value is greater than the preset matching threshold, it means that the target question and candidate answers of the initial question and answer pair corresponding to the question and answer semantic feature are related. If the question and answer matching value is less than or equal to the preset matching threshold, it means that the target question and candidate answers of the initial question and answer pair corresponding to the question and answer semantic feature are not related. In this way, the degree of correlation between the target question and candidate answers of each initial question and answer pair can be obtained more conveniently.
[0120] Furthermore, in order to characterize whether the target question and candidate answers of the initial question and answer pair are relevant, the initial question and answer pairs can be classified according to the question and answer matching value and the preset matching threshold, and the classification label of the initial question and answer pair whose question and answer matching value is greater than the preset matching threshold is marked as relevant, represented by the number 1; the classification label of the initial question and answer pair whose question and answer matching value is less than or equal to the preset matching threshold is marked as irrelevant, represented by the number 0.
[0121] In step S702 of some embodiments, since the larger the question-answer matching value, the higher the correlation between the target question and the candidate answers of the initial question-answer pair, among the initial question-answer pairs with the classification label of 1, the initial question-answer pair with the largest question-answer matching value is selected as the target question-answer pair, wherein the target question-answer pair includes the target question and the target answer corresponding to the target question.
[0122] The question-answer matching method of the embodiment of the present application obtains the original sentence data to be processed; extracts the contextual features of the original sentence data to obtain the initial sentence data, which can better preserve the contextual semantic information of the original sentence and improve the semantic integrity of the original sentence. Furthermore, the initial sentence data is sequence-labeled to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions, and the target question and candidate answer in the initial sentence data can be split into independent text data according to the labeling information, so as to pair the target question and the candidate answer to construct an initial question-answer pair, each of which includes a target question and a candidate answer. Finally, the preset question-answer matching model is used to extract features of the initial question-answer pair to obtain question-answer semantic features, thereby extracting the question-answer representation information of the initial question-answer pair, and calculating the matching probability of the question-answer semantic features to obtain the question-answer matching value. The initial question-answer pair is screened according to the question-answer matching value to obtain the target question-answer pair, where the target question-answer pair includes the target question and the target answer corresponding to the target question. This method can better capture the complete semantic information of the target question and candidate answers, improve the matching effect of the target question and the target answer, and improve the matching accuracy of the question and answer.
[0123] See also Figure 8 The embodiment of the present application also provides a question-answer matching device, which can implement the above-mentioned question-answer matching method, and the device includes:
[0124] An acquisition module 801 is used to acquire original sentence data to be processed;
[0125] A first feature extraction module 802 is used to extract context features from original sentence data to obtain initial sentence data;
[0126] The sequence labeling module 803 is used to perform sequence labeling on the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions;
[0127] A construction module 804 is used to construct an initial question-answer pair based on the target question and the candidate answers;
[0128] A second feature extraction module 805 is used to extract features from the initial question and answer pair using a preset question and answer matching model to obtain question and answer semantic features;
[0129] The calculation module 806 is used to calculate the matching probability of the question and answer semantic features through the question and answer matching model to obtain the question and answer matching value, and screen the initial question and answer pairs according to the question and answer matching value to obtain the target question and answer pair, wherein the target question and answer pair includes the target question and the target answer corresponding to the target question.
[0130] In some embodiments, the first feature extraction module 802 includes:
[0131] The embedding unit is used to perform feature embedding processing on the original sentence data to obtain a sentence embedding vector;
[0132] The extraction unit is used to extract context features from the sentence embedding vector through a preset attention mechanism model to obtain initial sentence data.
[0133] In some embodiments, the embedding unit comprises:
[0134] The word segmentation subunit is used to perform word segmentation processing on the original sentence data to obtain the original word segment;
[0135] The word embedding subunit is used to perform word embedding processing on the original word segment to obtain the original word embedding vector;
[0136] The concatenation subunit is used to concatenate the original word embedding vectors to obtain the sentence embedding vector.
[0137] In some embodiments, the sequence labeling module 803 includes:
[0138] A position prediction unit, used to perform position prediction on the initial sentence data according to a preset first function and a BIO tag, to obtain a question position tag and an answer position tag of the initial sentence data;
[0139] The segmentation unit is used to segment the initial sentence data according to the question position label to obtain the target question data, and to segment the initial sentence data according to the answer position label to obtain the candidate answer data.
[0140] In some embodiments, the segmentation unit comprises:
[0141] The first segmentation subunit is used to extract the question start tag and the question end tag in the question position tag, and segment the initial sentence data according to the question start tag and the question end tag to obtain target question data;
[0142] The second segmentation subunit is used to extract the answer start tag and the answer end tag in the answer position tag, and segment the candidate answer data according to the answer start tag and the answer end tag to obtain the candidate answer data.
[0143] In some embodiments, the second feature extraction module 805 includes:
[0144] An encoding unit, used to encode the initial question-answer pair through a question-answer matching model to obtain a question-answer encoding vector;
[0145] The normalization unit is used to normalize the question-answer encoding vector to obtain question-answer semantic features, which are representation features used to represent the contextual semantic information of the sentence.
[0146] In some embodiments, the calculation module 806 includes:
[0147] A probability calculation unit, used to calculate the matching probability of the question and answer semantic features through the second function of the question and answer matching model to obtain a question and answer matching value;
[0148] The screening unit is used to select the initial question-answer pair with the largest question-answer matching value as the target question-answer pair.
[0149] The specific implementation of the question-answer matching device is basically the same as the specific implementation of the above-mentioned question-answer matching method, and will not be repeated here.
[0150] The embodiment of the present application also provides an electronic device, the electronic device comprising: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program is executed by the processor to realize the above-mentioned question-answer matching method. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0151] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0152] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0153] The memory 902 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). The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the question-answer matching method of the embodiment of this application;
[0154] Input / output interface 903, used to implement information input and output;
[0155] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);
[0156] A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);
[0157] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .
[0158] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium used for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned question and answer matching method.
[0159] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0160] The question-answer matching method, question-answer matching device, electronic device and storage medium provided in the embodiment of the present application obtain the original sentence data to be processed; extract the contextual features of the original sentence data to obtain the initial sentence data, which can better preserve the contextual semantic information of the original sentence and improve the semantic integrity of the original sentence. Furthermore, the initial sentence data is sequence-labeled to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each candidate answer is used to answer one of the target questions, and the target question and candidate answer in the initial sentence data can be split into independent text data according to the labeling information, so as to pair the target question and the candidate answer to construct an initial question-answer pair, each of which includes a target question and a candidate answer. Finally, the preset question-answer matching model is used to extract features of the initial question-answer pair to obtain question-answer semantic features, thereby extracting the question-answer representation information of the initial question-answer pair, and calculating the matching probability of the question-answer semantic features to obtain the question-answer matching value. The initial question-answer pair is screened according to the question-answer matching value to obtain the target question-answer pair, where the target question-answer pair includes the target question and the target answer corresponding to the target question. This method can better capture the complete semantic information of the target question and candidate answers, improve the matching effect of the target question and the target answer, and improve the matching accuracy of the question and answer.
[0161] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0162] It can be understood by those skilled in the art that Figure 1-7 The technical solutions shown in the figure do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figure, or a combination of certain steps, or different steps.
[0163] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0164] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0165] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, 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 "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0166] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0167] In the several embodiments provided in the present 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 schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0168] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0169] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0170] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0171] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A question-answer matching method, characterized in that: The method comprises: Get the original sentence data to be processed; Extracting context features from the original sentence data to obtain initial sentence data; Performing sequence tagging on the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each of the candidate answers being used to answer one of the target questions; Constructing an initial question-answer pair according to the target question and the candidate answers; Extracting features from the initial question and answer pair using a preset question and answer matching model to obtain question and answer semantic features; The question-answer matching model is used to calculate the matching probability of the question-answer semantic features to obtain a question-answer matching value, and the initial question-answer pair is screened according to the question-answer matching value to obtain a target question-answer pair, wherein the target question-answer pair includes a target question and a target answer corresponding to the target question; The extracting context features from the original sentence data to obtain initial sentence data includes: Perform word segmentation processing on the original sentence data to obtain original word segments; perform word embedding processing on the original word segments to obtain original word embedding vectors; perform concatenation processing on the original word embedding vectors to obtain sentence embedding vectors; perform context feature extraction on the sentence embedding vectors through a preset attention mechanism model to obtain the initial sentence data; The step of performing sequence tagging on the initial sentence data to obtain target question data and candidate answer data includes: Performing position prediction on the initial sentence data according to a preset first function and a BIO label to obtain a question position label and an answer position label of the initial sentence data; Extracting a question start tag and a question end tag from the question position tag, and segmenting the initial sentence data according to the question start tag and the question end tag to obtain target question data; The answer start tag and the answer end tag in the answer position tag are extracted, and the candidate answer data are segmented according to the answer start tag and the answer end tag to obtain the candidate answer data.
2. The question-answer matching method according to claim 1, characterized in that: The step of extracting features from the initial question-answer pair using a preset question-answer matching model to obtain question-answer semantic features includes: Encoding the initial question and answer pair through the question and answer matching model to obtain a question and answer encoding vector; The question-answer encoding vector is normalized to obtain the question-answer semantic feature, wherein the question-answer semantic feature is a representation feature used to represent the semantic information of the sentence context.
3. The question-answer matching method according to any one of claims 1 to 2, characterized in that: The step of calculating the matching probability of the question-answer semantic features by using the question-answer matching model to obtain a question-answer matching value, and screening the initial question-answer pairs according to the question-answer matching value to obtain a target question-answer pair includes: Calculating the matching probability of the question and answer semantic features by using the second function of the question and answer matching model to obtain the question and answer matching value; The initial question-answer pair with the largest question-answer matching value is used as the target question-answer pair.
4. A question-answer matching device, characterized in that: The device comprises: An acquisition module, used to acquire original sentence data to be processed; A first feature extraction module, used to extract context features from the original sentence data to obtain initial sentence data; A sequence labeling module is used to perform sequence labeling on the initial sentence data to obtain target question data and candidate answer data; the target question data includes at least one target question, and the candidate answer data includes at least one candidate answer, each of which is used to answer one of the target questions; A construction module, used to construct an initial question-answer pair according to the target question and the candidate answer; A second feature extraction module is used to extract features from the initial question and answer pair through a preset question and answer matching model to obtain question and answer semantic features; A calculation module, configured to calculate a matching probability of the question-answer semantic features through the question-answer matching model to obtain a question-answer matching value, and to screen the initial question-answer pairs according to the question-answer matching value to obtain a target question-answer pair, wherein the target question-answer pair includes a target question and a target answer corresponding to the target question; The extracting context features from the original sentence data to obtain initial sentence data includes: Perform word segmentation processing on the original sentence data to obtain original word segments; perform word embedding processing on the original word segments to obtain original word embedding vectors; perform concatenation processing on the original word embedding vectors to obtain sentence embedding vectors; perform context feature extraction on the sentence embedding vectors through a preset attention mechanism model to obtain the initial sentence data; The step of performing sequence tagging on the initial sentence data to obtain target question data and candidate answer data includes: Performing position prediction on the initial sentence data according to a preset first function and a BIO label to obtain a question position label and an answer position label of the initial sentence data; Extracting a question start tag and a question end tag from the question position tag, and segmenting the initial sentence data according to the question start tag and the question end tag to obtain target question data; The answer start tag and the answer end tag in the answer position tag are extracted, and the candidate answer data are segmented according to the answer start tag and the answer end tag to obtain the candidate answer data.
5. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the question-answer matching method as described in any one of claims 1 to 3 are realized.
6. A storage medium, the storage medium being a computer-readable storage medium, used for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the question-answer matching method described in any one of claims 1 to 3.
Citation Information
Patent Citations
Question and answer pair generation method and device, electronic equipment and storage medium
CN114579725A