An answer selection method considering spatio-temporal dependency of questions and answers
By combining the BERT and ConvLSTM models, the spatiotemporal dependencies between questions and answers are captured, solving the problems of accuracy and efficiency in answer recommendation in community question-and-answer systems and achieving more efficient answer selection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HEFEI UNIV OF TECH
- Filing Date
- 2023-03-28
- Publication Date
- 2026-05-08
AI Technical Summary
Existing community question-answering systems cannot accurately characterize the trend changes between hidden features and answers when dealing with the spatiotemporal dependencies between questions and candidate answers. This results in low accuracy of answer recommendations and high requirements for data quantity and text quality, which increases the cost of system development and leads to a poor user experience.
The BERT model is used to obtain the word-level similarity matrix of question-answer pairs. By constructing a 12-layer self-attention layer and a ConvLSTM model, the spatiotemporal dependency between questions and answers is captured. The ConvLSTM model is used for answer selection. By combining the word segmentation encoding of the BERT model and the convolution operation of the ConvLSTM, spatiotemporal features are captured, thereby improving the accuracy of answer recommendation.
By capturing the correlation between spatial features and temporal changes, the accuracy and efficiency of the model are improved. This addresses the shortcomings of existing models that only consider semantic features or temporal relationships, and enhances the answer recommendation effect of the community question-and-answer system.
Smart Images

Figure CN116226352B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of community question-and-answer system technology, and in particular to an answer selection method that considers the spatiotemporal dependency relationship between questions and answers. Background Technology
[0002] With the rapid development of deep learning, question answering (QA) has become an important problem in the field of natural language processing (NLP).
[0003] Deep learning-based question-answering matching models are mainly divided into two categories: those based on neural networks and those based on pre-trained language models. Neural network-based models (such as CNNs and RNNs) typically represent questions and answers as vectors and use neural networks for classification. The former has strong local feature learning capabilities, while the latter has better long-term dependency learning capabilities. Pre-trained language model-based models typically use pre-trained language models (such as BERT and GPT) to represent questions and answers, and then fine-tune the model using a task-specific approach for question-answering matching. This type of model can significantly improve the representation capabilities of natural language.
[0004] However, in real-world community question-and-answer scenarios, complex temporal interactions may exist between questions and candidate answers, such as intense discussions between answers. Therefore, considering deep semantic matching between questions and answers, as well as temporal interactions between candidate answers, plays a crucial role in aggregating knowledge to facilitate answer selection. Using any one of the aforementioned models alone has limitations; it cannot simultaneously and accurately characterize the hidden features between questions and candidate answers, as well as the trend changes between answers. This results in low accuracy in answer recommendations for current community question-and-answer systems, and places higher demands on data quantity and text quality. Consequently, its practicality in specific domains is limited, increasing system development costs and leading to a poor user experience. Therefore, capturing the latent semantic features within time-series question-and-answer data to complete answer selection remains a challenge. Summary of the Invention
[0005] To overcome the shortcomings of existing technologies, this invention provides an answer selection method that considers the spatiotemporal dependency between questions and answers, aiming to uncover the spatiotemporal dependency between questions and answers, thereby accurately recommending the best answer that best matches the question.
[0006] To achieve the above-mentioned objectives, the present invention adopts the following technical solution:
[0007] The answer selection method of this invention, which considers the spatiotemporal dependency of question and answer, is characterized by the following steps:
[0008] Step 1: Construct question-and-answer data and perform data preprocessing;
[0009] Collect question and answer data from community forums, including: M questions Q = {Q i {i = 1, 2, ..., M} and T answers A = {A} for all questions. i The sequence Q is defined as follows: Q = {i = 1, 2, ..., M}, which records the timestamps of each question post and each answer response; where Q... i Let A represent the i-th question. i Let Q represent the i-th question. i T answers, and A i ={A it ,t=1,2,…,T};A it Let Q represent the i-th question. i The t-th answer; the question Q i and its answer A i Form the i-th question-answer pair set QA i ={(Q i A it ),t=1,2,…,T},(Q i A it ) represents the set of the i-th question-answer pairs QA i The t-th question-answer pair in the data;
[0010] Step 2: Use the BERT model to obtain the word-level similarity matrix of the question-answer pairs;
[0011] Step 2.1: Obtain the i-th question-answer pair set (QA) i Question segmentation and each answer segmentation;
[0012] Obtain the t-th question-answer pair (Q) using the built-in tokenization tool of the BERT model. i A it The i-th question Q in ) i Word segmentation set And the t-th answer A it Word segmentation set in, Let Q represent the i-th question. i The m-th word, k i For the i-th question Q i The total number of word segments, Let Q represent the i-th question. i The t-th answer is A it The nth word, p it For the t-th answer A it The total number of word segments;
[0013] For the i-th question Q i The word segmentation set of the T answers {ait Perform a union operation on the set {t = 1, 2, ..., T} to obtain the i-th problem Q. i T answers A i Word segmentation set in, Let Q represent the i-th question. i The g-th segment of the answer, P i Represents the answer set A i The total number of word segments;
[0014] Step 2.2: Construct a BERT model consisting of 12 self-attention layers, with h heads in each self-attention layer, and assign the t-th question-answer pair (Q) to the appropriate response. i A it The input is processed in the BERT model, and the i-th question Q is output by the 11th self-attention layer. i The self-attention weight matrix X of the t-th answer it X it Multiplying by a weight matrix W yields the embedding matrix X. it ';
[0015] The 12th self-attention layer will embed matrix X. it Multiply by the two weight matrices W to be trained respectively Q and W Q Then, the initial query embedding matrix P is generated. it The bond embedding matrix K it ;
[0016] The 12th self-attention layer embeds the initial query into matrix P. it The bond embedding matrix K it Each with h weight matrices to be trained and Perform matrix multiplication to obtain the query embedding matrix with h headers. and key embedding matrix in, and Let represent the query embedding matrix and key embedding matrix of the s-th header, respectively; This represents the query weight matrix to be trained for the s-th query. Let represent the weight matrix of the s-th key embedding to be trained;
[0017] The 12th self-attention layer uses equation (14) to obtain the t-th question-answer pair (Q). i A it The multi-head word-level similarity matrix S it :
[0018]
[0019] In equation (1), softmax represents the normalization exponential function, and the operation is performed on each column of the matrix. S represents a multi-head word-level similarity matrix it The word-level similarity matrix of the s-th head, d k This represents the dimension of the weight matrix for each head, and d model Represents the embedding matrix X it The dimensions of each element in '.
[0020] from Extract the i-th question Q from the... i The word segmentation set q i As a column element, the t-th answer is A. it a it Using the similarity matrix corresponding to the row elements, we obtain the local similarity matrix of the s-th head.
[0021] Step 3: Concatenate the similarity matrices of multiple answers to the same question to obtain the question-answer pair spatiotemporal tensor;
[0022] Step 3.1: Create a word segmentation dictionary for the answer set of each question:
[0023] T answers A i The word segmentation set a i Each word segment in the dictionary is used as the key, and the value corresponding to each word is initialized to 0. This constructs the i-th question Q. i Answer set A i Word segmentation dictionary in, This indicates that the i-th question Q is... i The g-th segment of the answer The g-th key-value pair consisting of the key and its corresponding initial value;
[0024] Step 3.2, Expand the similarity matrix:
[0025] According to the word segmentation dictionary Constructing local similarity matrices The corresponding initial similarity matrix dictionary in, Let Q represent the i-th question. i The index number of the local similarity matrix after the t-th answer is expanded;
[0026] Local similarity matrix The column index is for the i-th question Q. i The word segmentation set q i The row index is the t-th answer A. itThe word segmentation set a it , will a it Each word in the text is associated with... Compare the keys of each element in the list. and If they are the same, then... In local similarity matrices The corresponding columns serve as the similarity matrix dictionary. Middle button The corresponding value; otherwise, the padding length is k. i A column vector with elements equal to 0, if If it appears repeatedly, then In local similarity matrices The corresponding columns are summed and then averaged to obtain the t-th question-answer pair (Q). i A it A set of similarity matrix dictionaries for h multi-attention heads. This leads to the i-th question-answer pair set QA i A dictionary set D of T similar matrices i ={D it ,t=1,2,…,T;
[0027] Step 3.3: Data format conversion to obtain the question-answer pair spatiotemporal tensor:
[0028] Dictionary of similarity matrices Convert to 2D matrix Then, the t-th question-and-answer pair (Q) i A it A set of similarity matrix dictionaries for h multi-attention heads. Stacking the h multi-attention heads together yields a 3D tensor. Then the i-th question-and-answer pair set QA i A dictionary set of T similar matrices Stacking the T similarity matrices along their dictionary dimensions yields a 4-dimensional tensor. Then, padding is performed to obtain a 4D tensor with uniform size. in, Let Q represent the i-th question. i With the t-th answer A it The spacetime tensor of h heads;
[0029] Step 4: Use the ConvLSTM model to predict the question-answer matching degree and select the answer;
[0030] Step 4.1: Convert the spacetime tensor Inputting the data into a ConvLSTM model for prediction yields the i-th question Q. iThe set of predicted scores for T answers in, This represents the t-th question-answer pair (Q). i A it () is the predicted score of a valid answer;
[0031] Step 4.2: Train the ConvLSTM model using gradient descent, calculate the cross-entropy loss function, and update the parameters using the backpropagation algorithm. Stop training when the cross-entropy loss function converges or the number of training iterations reaches a predetermined threshold, thereby obtaining the optimal answer selection model, which is then used to output the best answer for each question in the community question-and-answer system.
[0032] The present invention provides an electronic device, including a memory and a processor, wherein the memory is used to store a program that supports the processor in executing the answer selection method, and the processor is configured to execute the program stored in the memory.
[0033] The present invention discloses a computer-readable storage medium on which a computer program is stored, wherein the computer program is executed by a processor to perform the steps of the answer selection method.
[0034] Compared with existing technologies, the beneficial effects of this invention are reflected in:
[0035] 1. This invention uses the ConvLSTM model, which performs better than LSTM in processing question-and-answer spatiotemporal sequences, mainly in the following aspects:
[0036] ① Capable of capturing spatial features: LSTM can only learn features on a temporal scale and cannot directly capture spatial features. In contrast, ConvLSTM combines CNN layers and LSTM layers, enabling it to learn the features of question-answer pairs simultaneously in both time and space, thus better capturing the spatiotemporal dependencies between questions and answers.
[0037] ② Fewer parameters: Because LSTM has a fully connected layer at each time step, the number of parameters is very large. In contrast, ConvLSTM only needs to perform convolution and LSTM operations at each time step, resulting in a relatively smaller number of parameters and faster training speed.
[0038] ③ Better performance for large datasets: The data in community question-and-answer systems is enormous. When dealing with large datasets, ConvLSTM's convolutional operations can better utilize local correlations and spatial translation invariance, making it more efficient than LSTM in terms of memory and computational resources.
[0039] 2. This invention uses the intermediate structure of the BERT model to obtain the word segmentation and encoding of questions and answers, which saves more time than the traditional method of first segmenting the text and then encoding it, ensuring the efficiency of the model in real-world community question-and-answer systems.
[0040] 3. This invention calculates the word-level similarity matrix between questions and answers through intermediate steps of the BERT model. First, it is more convenient and accurate than traditional cosine similarity. Second, compared to traditional similarity calculation models that only consider one dimension, BERT has multiple heads, thus it can consider the semantic features between question-answer pairs under different dimensions, and can capture more complex spatiotemporal dynamics, thereby continuously improving the accuracy of the model, providing more accurate feature semantic vectors for the ConvLSTM model, and ultimately providing accurate answers for the community question-answering system.
[0041] 4. This invention concatenates the similarity matrices of all answers to a question, and the output results can capture the correlation features between answers as they change over time, thereby improving the interpretability of the model.
[0042] 5. This invention uses the BERT model to obtain the dependency relationship between each question and answer, ensuring the efficiency and accuracy of similarity calculation between question-answer pairs. Then, it uses the ConvLSTM model to learn and represent the latent semantic features hidden in the question-answer text data, which improves the shortcomings of existing models that only consider semantic features or temporal relationships, and improves the performance in handling long sequence problems, capturing temporal and spatial information. Attached Figure Description
[0043] Figure 1 This is a diagram illustrating the construction of the question-and-answer pair set in this invention;
[0044] Figure 2 This invention uses the BERT model to obtain the word-level similarity matrix diagram of question-answer pairs;
[0045] Figure 3 This invention obtains a similarity matrix diagram between questions and answers;
[0046] Figure 4 This invention provides a unified similarity matrix dimension diagram between question-and-answer pairs.
[0047] Figure 5 This is a structural diagram of a single cell state in the ConvLSTM model of this invention. Detailed Implementation
[0048] In this embodiment, an answer selection method that considers the spatiotemporal dependency of question and answer is performed according to the following steps:
[0049] Step 1: Construct question-and-answer data and perform data preprocessing;
[0050] Collect question and answer data from community forums, including: M questions Q = {Q i {i = 1, 2, ..., M} and T answers A = {A} for all questions. i The sequence Q is defined as follows: Q = {i = 1, 2, ..., M}, which records the timestamps of each question post and each answer response; where Q... i Let A represent the i-th question. i Let Q represent the i-th question. i T answers, and A i ={A it ,t=1,2,…,T};A it Let Q represent the i-th question. i The t-th answer; the question Q i and its answer A i Form the i-th question-answer pair set QA i ={(Q i A it ),t=1,2,…,T},(Q i A it ) represents the set of the i-th question-answer pairs QA i The t-th question-answer pair in the data;
[0051] In practice, the collected question-and-answer data from the community forum is stored in XML format. Each record is a question-and-answer pair, forming a question-and-answer pair set. Each question records the question ID (Q_ID), the time the question was asked (Q_DATE), and the question content (QBody); each answer records the answer ID (A_ID), the time the answer was given (A_DATE), the answer's evaluation result (A_RELEVANCE), and the answer content (AText). This yields the question-and-answer data required for this example. Next, the number of answers to each question is set to T. The frequency of the ID (A_ID) tag for each answer under each question (Q_ID) is counted. Questions with fewer than T answers are removed; for questions with more than T answers, only the last T answers are selected. After filtering, there are a total of M questions and N = M × T answers. Finally, the data is reorganized to form a question-and-answer pair set, denoted as:
[0052] QA i ={(Q i A it ),t=1,2,…,T}={(Q i A i1 ),(Q i A i2 ),…,(Q i A iT )}
[0053] Step 2: Use the BERT model to obtain the word-level similarity matrix of the question-answer pairs;
[0054] Step 2.1: Obtain the i-th question-answer pair set (QA) i Question segmentation and each answer segmentation;
[0055] Obtain the t-th question-answer pair (Q) using the built-in tokenization tool of the BERT model. i A it The i-th question Q in ) i Word segmentation set And the t-th answer A it Word segmentation set in, Let Q represent the i-th question. i The m-th word, k i For the i-th question Q i The total number of word segments, Let Q represent the i-th question. i The t-th answer is A it The nth word, p it For the t-th answer A it The total number of word segments;
[0056] For the i-th question Q i The word segmentation set of the T answers {a it Perform a union operation on the set {t = 1, 2, ..., T} to obtain the i-th problem Q. i T answers A i Word segmentation set in, Let Q represent the i-th question. i The g-th segment of the answer, P i Represents the answer set A i The total number of word segments;
[0057] In practice, the BERT model comes with BertTokenizer as its built-in tokenizer. Before use, the relevant files need to be downloaded and placed in the bert-base-uncased folder. The bert-base-uncased folder includes the BERT model's configuration file Config.json, which stores the BERT model's parameters; the BERT model code files; and the tokenizer dictionary tokenzier.json. Additionally, the transformers module needs to be downloaded for method calls.
[0058] In this embodiment, obtaining the word segmentation of the question and answer includes the following steps:
[0059] Step 1: First, use Python's module import statement to import the BERT model BertModel and the tokenization tool BertTokenizer from the transformers module.
[0060] Step 2: Load the BERT model and tokenizer. The model is loaded using the `BertModel.from_pretrained()` method, and the tokenizer is loaded using the `BertTokenizer.from_pretrained()` method.
[0061] Step 3: Import input data and run the model. Since this step does not require the tokens [CLS] and [SEP], first set the BertTokenizer parameter add_special_tokens to False. Then, generate the question-answer pairs (Q... i A it Question Q i And answer A it The content QBody is input into the model as Atext, and encoded using the tokenizer.encode() method to obtain the word segmentation list sets q for the question and answer respectively. i and a it Finally, let's address question Q. i The set of T answer word segmentation sets is used to segment a using the union() method in Python. it Find the union of the sets of words that form the answer set, and obtain the word segmentation set a. i =list(set(a i1 ).union(a i2 ,...,a it The formula is as follows:
[0062]
[0063] Step 2.2: Construct a BERT model consisting of 12 self-attention layers, with h heads in each self-attention layer, and assign the t-th question-answer pair (Q) to the appropriate response. i A it The input is processed in the BERT model, and the i-th question Q is output by the 11th self-attention layer. i The self-attention weight matrix X of the t-th answer it X it Multiplying by a weight matrix W yields the embedding matrix X. it ';
[0064] In this embodiment, because the BERT model can only insert the [CLS] delimiter at the beginning and the [SEP] delimiter at the end, special treatment is needed when segmenting long sequences. Therefore, we set the BertTokenizer parameter add_special_tokens to False, and manually add it to question Q. i The word segmentation set q i Insert the [CLS] symbol at the beginning and the [SEP] symbol at the end; then add the answer A. it The word segmentation set a it Attach it to the end, and insert the [SEP] symbol at the end, i.e.:
[0065] Q i A it =[CLS]q i [SEP]a it [SEP]
[0066] Then it is input into the BERT model for calculation.
[0067] In practice, to obtain the self-attention weight matrix of the 11th layer of the BERT model, the `output_attentions` parameter in the BERT model's configuration file `Config.json` must first be set to `True`. After the BERT model runs, it can save the weight matrices of all self-attention layers. In this embodiment, the BERT model is run and the output is saved and named `outputs`. By using the model to call the `attentions` attribute and performing slicing operations, the i-th question Q can be obtained. i The self-attention weight matrix of the 11th layer for the t-th answer:
[0068] X it =BERT layer=11 (Q i A it = outputs.attentions[10::]
[0069] Further expressed as:
[0070]
[0071] In this embodiment, the embedding matrix X it The specific calculation formula for ' is:
[0072] X it ′=WX it (2)
[0073] In equation (2), X it The dimension d of each element in ' x' =dmodel =768,
[0074] The 12th self-attention layer will embed matrix X. it Multiply by the two weight matrices W to be trained respectively Q and W Q Then, the initial query embedding matrix P is generated. it The bond embedding matrix K it ;
[0075] The 12th self-attention layer embeds the initial query into matrix P. it The bond embedding matrix K it Each with h weight matrices to be trained and Perform matrix multiplication to obtain the query embedding matrix with h headers. and key embedding matrix in, and Let represent the query embedding matrix and key embedding matrix of the s-th header, respectively; This represents the query weight matrix to be trained for the s-th query. Let represent the weight matrix of the s-th key embedding to be trained;
[0076] In this embodiment, the initial query embedding matrix P it The bond embedding matrix K it The calculation formula is:
[0077] P it =W Q X it (3)
[0078] K it =W K X it (4)
[0079] In equations (3) and (4), W Q and Query embedding matrix with h headers and key embedding matrix The calculation formula is:
[0080]
[0081]
[0082] In equations (5) and (6), and
[0083] The 12th self-attention layer uses equation (14) to obtain the t-th question-answer pair (Q).i A it The multi-head word-level similarity matrix S it :
[0084]
[0085] In equation (1), softmax represents the normalization exponential function, and the operation is performed on each column of the matrix. S represents a multi-head word-level similarity matrix it The word-level similarity matrix of the s-th head, d k This represents the dimension of the weight matrix for each head, and d model Represents the embedding matrix X it The dimensions of each element in '.
[0086] from Extract the i-th question Q from the... i The word segmentation set q i As a column element, the t-th answer is A. it a it Using the similarity matrix corresponding to the row elements, we obtain the local similarity matrix of the s-th head.
[0087] In this embodiment, For the s-th layer, the i-th question Q needs to be extracted from it. i With the t-th answer A it The similarity matrix between them is first determined by the length k of the question segmentation. i and the word segmentation length p of each answer it To obtain the index number needed for slicing, we need to find the positions of the markers [CLS] and [SEP]1. Specifically, [CLS] is located at position [0] of the matrix, and [SEP]1 is located at position [k]. i If the position is +1, then the extracted matrix should be:
[0088] Step 3: Concatenate the similarity matrices of multiple answers to the same question to obtain the question-answer pair spatiotemporal tensor;
[0089] Step 3.1: Create a word segmentation dictionary for the answer set of each question:
[0090] T answers A i The word segmentation set a i Each word segment in the dictionary is used as the key, and the value corresponding to each word is initialized to 0. This constructs the i-th question Q. i Answer set A i Word segmentation dictionary in, This indicates that the i-th question Q is... i The g-th segment of the answer The g-th key-value pair consisting of the key and its corresponding initial value;
[0091] In this embodiment, it is necessary to perform a question-and-answer pair (Q) i A it Creating a dictionary requires using a for loop to iterate through the word segmentation set 'a' for each answer. i Each element.
[0092] Step 3.2, Expand the similarity matrix:
[0093] According to the word segmentation dictionary Constructing local similarity matrices The corresponding initial similarity matrix dictionary in Let Q represent the i-th question. i The index number of the local similarity matrix after the t-th answer is expanded;
[0094] Local similarity matrix The column index is for the i-th question Q. i The word segmentation set q i The row index is the t-th answer A. it The word segmentation set a it , will a it Each word in the text is associated with... Compare the keys of each element in the list. and If they are the same, then... In local similarity matrices The corresponding columns serve as the similarity matrix dictionary. Middle button The corresponding value; otherwise, the padding length is k. i A column vector with elements equal to 0, if If it appears repeatedly, then In local similarity matrices The corresponding columns are summed and then averaged to obtain the t-th question-answer pair (Q). i A it A set of similarity matrix dictionaries for h multi-attention heads. This leads to the i-th question-answer pair set QA i A dictionary set D of T similar matrices i ={D it ,t=1,2,…,T;
[0095] In practice, a local similarity matrix is constructed according to formula (7). The corresponding initial similarity matrix dictionary It is a word segmentation dictionary To copy, that is Get the t-th question-answer pair (Q i A it The set of similarity matrix dictionaries D for h multi-attention heads. it like Figure 4 As shown, the loop operation uses a for loop. When iterating through the answer segmentation set, attention needs to be paid to the correct index numbers and the nesting of loops. Using Python statements, the outer loop first iterates through the similarity matrix of each answer. index number a it Extract it, and then the inner loop iterates through the dictionary set of answers. Extract the key, compare its size using string equality, and create a new, expanded similarity matrix dictionary.
[0096]
[0097] Step 3.3: Data format conversion to obtain the question-answer pair spatiotemporal tensor:
[0098] Dictionary of similarity matrices Convert to 2D matrix Then, the t-th question-and-answer pair (Q) i A it A set of similarity matrix dictionaries for h multi-attention heads. Stacking the h multi-attention heads together yields a 3D tensor. Then the i-th question-and-answer pair set QA i A dictionary set of T similar matrices Stacking the T similarity matrices along their dictionary dimensions yields a 4-dimensional tensor. Then, padding is performed to obtain a 4D tensor with uniform size. in, Let Q represent the i-th question. i With the t-th answer A it The spacetime tensor of h heads.
[0099] In practice, the first step is to use Python's data format conversion methods to convert the similarity matrix dictionary... Transform it into a NumPy array:
[0100]
[0101] Then the question and answer pair (Q i A it The set of similarity matrix dictionaries D for h multi-attention heads. itStacking the h multi-attention heads along their dimensions yields a 3D tensor:
[0102]
[0103] Then, Stacking the T similarity matrices along their dictionary dimensions yields a 4-dimensional tensor:
[0104]
[0105] Then, for all question-answer pairs (QA)... i spacetime tensor After padding, a uniform 4D tensor is obtained:
[0106]
[0107] In equation (8), T represents the number of answers to the question, h represents the number of multi-head attention points, k represents the length of the question segment, and P represents the length of the answer segment. T is considered as a time dependency, and h×k×P is considered as a spatial dependency. For This can be further expressed as:
[0108]
[0109] in, Q represents the i-th question in layer h. i With the t-th answer A it 3D tensors of similarity matrices
[0110] Step 4: Use the ConvLSTM model to predict the question-answer matching degree and select the answer;
[0111] Step 4.1: Convert the spacetime tensor Input the data into the ConvLSTM model for prediction to obtain the i-th question Q. i The set of predicted scores for T answers in, This represents the t-th question-answer pair (Q). i A it () is the predicted score of a valid answer;
[0112] In this embodiment, each cell unit of the ConvLSTM model is as follows: Figure 5 As shown, each time step corresponds to the i-th question Q in a total of h layers. i With the t-th answer A it 3D tensors of similar matrices Each hidden state H t Output question-and-answer pairs (Q) i Ait The representation vector of the problem is T, since each problem has T answers, and there are a total of T hidden layers. The specific calculation formula is as follows:
[0113]
[0114]
[0115]
[0116]
[0117]
[0118] In equations (9)-(13), i t ,f t C t ,o t These represent the input gate, forget gate, cell state, and output gate, respectively; W x· W h· and W c· Here is the weight matrix of the ConvLSTM, b is the bias coefficient; H t-1 C represents the hidden state at time t-1, i.e., the representation vector of the (t-1)th answer. t-1 This represents the cell state at time t-1, i.e., the cell state of the (t-1)th answer; σ represents the activation function, using sigmoid; * represents the convolution operation; This indicates the Hadamard product operation.
[0119] In practice, to obtain the i-th question Q i The set of predicted scores for T answers First, the obtained data on H obtained through a multilayer perceptron network must be processed. t By performing a nonlinear transformation, we obtain
[0120]
[0121] In equation (14), σ represents the activation function, W y The weight matrix shares weights across answers T; b y These are the bias coefficients. Finally, we perform a calculation using the normalized exponential function softmax(). By performing normalization, the predicted scores can be sorted, and finally the position of the best answer with the highest score can be output.
[0122] Step 4.2: Train the ConvLSTM model using gradient descent, calculate the cross-entropy loss function, and update the parameters using the backpropagation algorithm. Stop training when the cross-entropy loss function converges or the number of training iterations reaches a predetermined threshold, thereby obtaining the optimal answer selection model, which is then used to output the best answer for each question in the community question-and-answer system.
[0123] In practice, the first step is to address question Q. i For each answer, the data format is converted, with "Good" marked as 1 and "Bad" as 0, to construct the true score y. it The cross-entropy loss function formula for binary classification is:
[0124]
[0125] By using the cross-entropy loss function, gradient backpropagation can be performed, allowing the model to continuously optimize itself through self-learning. This ultimately yields an answer selection model that considers the spatiotemporal dependencies between questions and answers, possessing strong learning and generalization capabilities. Applying this trained model widely to existing community question-answering systems, such as Zhihu and Xiaohongshu, through a more accurate and convenient answer generation mechanism, can increase user stickiness and loyalty, while also providing convenience to users and attracting more resources.
[0126] In this embodiment, an electronic device includes a memory and a processor. The memory stores a program that supports the processor in executing the above-described method, and the processor is configured to execute the program stored in the memory.
[0127] In this embodiment, a computer-readable storage medium stores a computer program, which is executed by a processor to perform the steps of the above method.
Claims
1. A method for answer selection that considers the spatiotemporal dependency of question and answer, characterized in that, The procedure is as follows: Step 1: Construct question-and-answer data and perform data preprocessing; Collect question and answer data from community forums, including: One question And all the questions One answer It also records the timestamps of each question post and each answer response; among them, Indicates the first One question, Indicates the first One question of One answer, and ; Indicates the first One question The t One answer; the question and its answers Composition of the first A set of question-and-answer pairs , Indicates the first A set of question-and-answer pairs The first in t One question and one answer; Step 2: Use the BERT model to obtain the word-level similarity matrix of the question-answer pairs; Step 2.1, obtain the first A set of question-and-answer pairs Question segmentation and each answer segmentation; Using the built-in tokenization tools of the BERT model to obtain the first... t A question and answer pair The Middle One question Word segmentation set and the t One answer Word segmentation set ,in, Indicates the first One question The Each word, For the first One question The total number of word segments, Indicates the first One question The One answer The n Each word, For the first One answer The total number of word segments; For the One question of The word segmentation set of each answer Perform a union operation to obtain the first set. One question of One answer Word segmentation set ;in, Indicates the first One question The answer is number 1 Each word, Represents the answer set The total number of word segments; Step 2.2: Construct a BERT model consisting of 12 self-attention layers, with each self-attention layer containing the following number of heads. and the first t A question and answer pair The input is processed in the BERT model, and the 11th self-attention layer outputs the first... One question The The self-attention weight matrix of each answer ,Will Multiply by a weight matrix The embedding matrix is then obtained. ; The 12th self-attention layer will embed the matrix. Multiply by the two weight matrices to be trained respectively. and Then, an initial query embedding matrix is generated. and bond embedding matrix ; The 12th self-attention layer embeds the initial query into the matrix. and bond embedding matrix respectively with One weight matrix to be trained and Perform matrix multiplication to obtain the corresponding result. The query embedding matrix of each header and bond embedding matrix ,in, and They represent the first The query embedding matrix and key embedding matrix of each header; This represents the query weight matrix to be trained for the s-th query. Let represent the weight matrix of the s-th key embedding to be trained; The 12th self-attention layer uses equation (1) to obtain the t-th question-answer pair. Multi-head word-level similarity matrix : (1) In equation (1), softmax represents the normalization exponential function, and the operation is performed on each column of the matrix. Represents a multi-head word-level similarity matrix The Middle s Word-level similarity matrix of each head, This represents the dimension of the weight matrix for each head, and , Represents the embedding matrix The dimensions of each element in the text; from Take the first one from the middle One question Word segmentation set As a column element, the first One answer The set of words As the similarity matrix corresponding to the row elements, we obtain the first... s Local similarity matrix of each head ; Step 3: Concatenate the similarity matrices of multiple answers to the same question to obtain the question-answer pair spatiotemporal tensor; Step 3.1: Create a word segmentation dictionary for the answer set of each question: Will One answer Word segmentation set Each word segment in the dictionary is used as the key, and the value corresponding to each word is initialized to 0, thus constructing the first... One question Answer set Word segmentation dictionary ,in, Indicates by the first One question The answer is number 1 Each word The first and its corresponding initial values constitute the first One key-value pair; Step 3.2, Expand the similarity matrix: According to the word segmentation dictionary Construct local similarity matrices The corresponding initial similarity matrix dictionary ={ },in, Indicates the first One question With the The index number of the local similarity matrix after the topology of each answer; Local similarity matrix The column index is the first One question Word segmentation set The row index is the t-th answer. Word segmentation set ,Will Each word in the text is associated with... Compare the keys of each element in the list. and If they are the same, then... In local similarity matrices The corresponding columns serve as the similarity matrix dictionary. Middle button The corresponding value; otherwise, the padding length is... A column vector with elements equal to 0, if If it appears repeatedly, then In local similarity matrices The corresponding columns are summed and then averaged to obtain the t-th question-and-answer pair. of A set of similarity matrix dictionaries for multiple attention heads ; and thus obtain the first A set of question-and-answer pairs of A dictionary of similar matrices ; Step 3.3: Data format conversion to obtain the question-answer pair spatiotemporal tensor: Dictionary of similarity matrices Convert to 2D matrix Then the first t A question and answer pair of A set of similarity matrix dictionaries for multiple attention heads exist Stacking multiple attention heads along the dimension yields a 3D tensor. Then the first A set of question-and-answer pairs of A dictionary of similar matrices exist Stacking similar matrices along their dictionary dimensions yields a 4-dimensional tensor. Then, padding is performed to obtain a 4D tensor with uniform size. ,in, Indicates the first One question With the One answer The spacetime tensor of h heads; Step 4: Use the ConvLSTM model to predict the question-answer matching degree and select the answer; Step 4.1: Convert the spacetime tensor Inputting the data into a ConvLSTM model for prediction yields the [number of] [items]. One question The set of predicted scores for T answers ,in, Indicates the first t A question and answer pair It is the predicted score of a valid answer; Step 4.2: Train the ConvLSTM model using gradient descent, calculate the cross-entropy loss function, and update the parameters using the backpropagation algorithm. Stop training when the cross-entropy loss function converges or the number of training iterations reaches a predetermined threshold, thereby obtaining the optimal answer selection model, which is then used to output the best answer for each question in the community question-and-answer system.
2. An electronic device, comprising a memory and a processor, characterized in that, The memory is used to store a program that supports the processor in executing the answer selection method of claim 1, the processor being configured to execute the program stored in the memory.
3. A computer-readable storage medium storing a computer program, characterized in that, The computer program, when run by the processor, performs the steps of the answer selection method as described in claim 1.
Citation Information
Patent Citations
Machine reading comprehension-based information extraction method and related device
WO2021135910A1
Method and apparatus for automatically generating inference questions and answers
WO2021184311A1