Question and answer database construction method, question and answer method, device, electronic device and storage medium
By parsing the answer text and generating templates to build a question and answer database, the problem of difficulty in matching user questions is solved, the coverage of the question and answer database and user experience are improved, and the construction cost is reduced.
Patent Information
- Application Number
- CN202111601186.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2041-12-24
AI Technical Summary
It is difficult to match user questions in the existing question-and-answer database, which reduces the user experience and increases the difficulty and cost of building the question-and-answer database.
By parsing the answer text, obtaining the question template, and building a question and answer library, including word segmentation, sequence labeling, relationship and intent recognition of the answer text, and using the natural language understanding model for parsing, a rich question and answer library is generated.
It improves the coverage and user experience of the Q&A database, reduces the construction cost of the Q&A database, and facilitates maintenance.
Smart Images

Figure CN114328803B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of text processing technology, and in particular to a question and answer library construction method, a question and answer method, a device, an electronic device, and a storage medium. Background Art
[0002] With the rapid development of technology, automated information query processing has gradually replaced manual query processing. Automated information query mainly involves users providing a question and then automatically searching for relevant information from a question-and-answer database as an answer.
[0003] Currently, Q&A databases are typically constructed by collecting a large number of questions and their corresponding answers, storing the correspondence between questions and answers. However, due to the varying ways users ask questions, the database may not be able to find a matching question, and thus, unable to provide an answer, which directly impacts the user experience. To improve user experience, the number of questions and their corresponding answers in the database needs to be increased. This not only increases the difficulty and cost of building the database, but also hinders its maintenance.
[0004] Therefore, there is an urgent need to provide a method for constructing a question-answer database. Summary of the Invention
[0005] The present invention provides a question-answering database construction method, a question-answering method, a device, an electronic device, and a storage medium to address the defects in the prior art.
[0006] The present invention provides a method for constructing a question-answer database, comprising:
[0007] Get the answer text;
[0008] Parsing the answer text to determine first parsed information of the answer text; the first parsed information includes first element information and first relationship information;
[0009] Based on the first parsed information of the answer text, a question template corresponding to the answer text is obtained, and a question and answer library is constructed based on the answer text and the question template.
[0010] According to a method for constructing a question-answer database provided by the present invention, the method further comprises: obtaining a question template corresponding to the answer text based on the first parsed information of the answer text, and then parsing the question template to obtain second parsed information of the question template; the second parsed information includes second element information, second relationship information, and intent information;
[0011] Accordingly, the question-answer library is constructed based on the answer text and the question template, including:
[0012] The question and answer library is constructed based on the answer text, the question template and the second parsing information.
[0013] According to a question-answer database construction method provided by the present invention, parsing the question template to obtain second parsed information of the question template includes:
[0014] Performing word segmentation processing on the question template to determine the word vector representation of each word in the question template;
[0015] Based on the word vector representation of each word in the question template, the question template is sequence labeled to determine the second element information; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0016] Based on the word vector representation corresponding to the non-intentional element, performing relationship classification on the non-intentional element to determine the second relationship information;
[0017] Based on the word vector representation corresponding to the intention element, the intention element is classified into intent categories to determine the first intention information.
[0018] According to a question-answer database construction method provided by the present invention, parsing the question template to obtain second parsed information of the question template includes:
[0019] Inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model;
[0020] The natural language understanding model is trained based on question samples that carry parsing information labels.
[0021] According to a question-answer database construction method provided by the present invention, inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model includes:
[0022] Inputting the question template into the character language sub-model of the natural language understanding model to obtain a word vector representation of each word in the question template output by the character language sub-model;
[0023] Inputting the word vector representation of each word in the question template into the sequence labeling sub-model of the natural language understanding model to obtain the second element information output by the sequence labeling sub-model; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0024] Inputting the word vector representation of each word in the question template and the non-intentional element into the relationship classification sub-model of the natural language understanding model to obtain the second relationship information output by the relationship classification sub-model;
[0025] Inputting the word vector representation of each word in the question template and the intent element into the intent classification sub-model of the natural language understanding model to obtain the first intent information output by the intent classification sub-model;
[0026] The sequence labeling sub-model, the relationship classification sub-model and the intention classification sub-model are jointly trained based on question samples carrying parsing information labels.
[0027] According to a question-answer database construction method provided by the present invention, the parsing of the answer text to determine the first parsing information of the answer text includes:
[0028] The answer text is converted into a structured expression to obtain sub-answer texts corresponding to the answer text.
[0029] According to a question-answer database construction method provided by the present invention, parsing the answer text to determine first parsing information of the answer text includes:
[0030] For any sub-answer text in the answer text, perform word segmentation processing on the sub-answer text to determine a word vector representation of each word in the sub-answer text;
[0031] Based on the word vector representation of each word in the any sub-answer text, sequence labeling is performed on the any sub-answer text to determine the third element information of the any sub-answer text; the third element information includes the elements in the any sub-answer text;
[0032] Based on the word vector representation of each word in the any sub-answer text, performing relationship classification on the elements in the any sub-answer text to determine the third relationship information of the any sub-answer text;
[0033] The first parsing information is determined based on the third element information and the third relationship information of each sub-answer text.
[0034] According to a question-answer database construction method provided by the present invention, obtaining a question template corresponding to the answer text based on the first parsed information of the answer text includes:
[0035] For any sub-answer text in the answer text, based on the syntactic order corresponding to each element in the third element information of the any sub-answer text and the third relationship information of the any sub-answer text, the elements are recombined to obtain a combination result corresponding to the any sub-answer text;
[0036] The question template is determined based on the combination results corresponding to the sub-answer texts.
[0037] The present invention also provides a question-answering method, comprising:
[0038] Get user questions;
[0039] Selecting an answer text matching the user's question from the question and answer library;
[0040] The question-and-answer database is constructed based on the above-mentioned question-and-answer database construction method.
[0041] The present invention also provides a question-answer database construction device, comprising:
[0042] Text acquisition module, used to obtain answer text;
[0043] a parsing module, configured to parse the answer text and determine first parsed information of the answer text; the first parsed information including first element information and first relationship information;
[0044] A construction module is used to obtain a question template corresponding to the answer text based on the first parsing information of the answer text, and to construct a question and answer library based on the answer text and the question template.
[0045] The present invention also provides a question-answering device, comprising:
[0046] Question acquisition module, used to obtain user questions;
[0047] A selection module, configured to select an answer text matching the user's question from the question-answer library;
[0048] The question-and-answer database is constructed based on the above-mentioned question-and-answer database construction method.
[0049] According to a question-answering method provided by the present invention, selecting an answer text matching the user question from the question-answering library includes:
[0050] Parsing the user question to determine fourth parsed information of the user question, where the fourth parsed information includes fourth element information, fourth relationship information, and second intent information;
[0051] Based on the second intent information in the fourth parsed information of the user question and the first intent information in the second parsed information of the question template in the question and answer library, matching the user question with the question template to obtain a first matching result;
[0052] If the first matching result is a match failure, matching the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question and answer library to obtain a second matching result;
[0053] Based on the second matching result, an answer text in the question and answer library that matches the user question is determined.
[0054] According to a question-and-answer method provided by the present invention, the user question is matched with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question-and-answer library to obtain a second matching result, including:
[0055] Obtain a knowledge graph of the field in which the answer text resides;
[0056] Based on the knowledge graph, the fourth element information, the fourth relationship information, the second element information, and the second relationship information, a graph-structure-based similarity calculation method is used to calculate the similarity between the user question and the question template;
[0057] Based on the similarity, the second matching result is determined.
[0058] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, the steps of any of the above-mentioned question-and-answer library construction methods or the above-mentioned question-and-answer method are implemented.
[0059] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of any of the above-mentioned question-and-answer database construction methods or the above-mentioned question-and-answer method are implemented.
[0060] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned question-and-answer database construction methods or the above-mentioned question-and-answer method.
[0061] The question-and-answer library construction method, question-and-answer method, device, electronic device, and storage medium provided by the present invention first obtain an answer text, then parse the answer text, determine the first parsing information of the answer text, and finally obtain the question template corresponding to the answer text based on the first parsing information of the answer text, and construct a question-and-answer library based on the answer text and the question template. This method parses the answer text and obtains the question template through the first parsing information obtained by parsing, thereby realizing the construction of the question-and-answer library. It can make the answer text correspond to a rich set of question templates, make the construction of the question-and-answer library more comprehensive, reduce the possibility that the user's question cannot be matched with the corresponding question template in the question-and-answer library, and improve the user experience. Moreover, this method can increase the number of question templates corresponding to the answer text under the premise of knowing the answer text when constructing the question-and-answer library, which can reduce the construction cost of the question-and-answer library, reduce the construction difficulty of the question-and-answer library, and facilitate the maintenance of the question-and-answer library. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on the drawings in the following description without any creative work.
[0063] Figure 1 Schematic diagram of the process of constructing a question-answer database provided by the present invention;
[0064] Figure 2 Schematic diagram of the structure of the natural language understanding model used in the question-answer database construction method provided by the present invention;
[0065] Figure 3 1 is a flow chart of the question-answering method provided by the present invention;
[0066] Figure 4 It is a structural diagram of the question-answer database construction device provided by the present invention;
[0067] Figure 5 It is a structural diagram of the question-answering device provided by the present invention;
[0068] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0069] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0070] Currently, due to the different ways users ask questions, it may be impossible to find a matching question in the Q&A database, and thus unable to provide the user with an answer, which reduces the user experience. To improve the user experience, it is necessary to increase the number of questions and their corresponding answers in the Q&A database. This not only increases the difficulty and cost of building the Q&A database, but also is not conducive to database maintenance. To this end, an embodiment of the present invention provides a Q&A database construction method. The constructed Q&A database can be applied in the field of construction to store building specifications and related issues.
[0071] Figure 1 A flowchart of a method for constructing a question-answer database is provided in an embodiment of the present invention. Figure 1 As shown, the method includes:
[0072] S11, obtain the answer text;
[0073] S12, parsing the answer text to determine first parsed information of the answer text; the first parsed information includes first element information and first relationship information;
[0074] S13, based on the first parsed information of the answer text, obtaining the question template corresponding to the answer text, and constructing a question and answer library based on the answer text and the question template.
[0075] Specifically, a question-and-answer database construction method provided in an embodiment of the present invention is executed by a question-and-answer database construction device, which can be configured in a server. The server can be a local server or a cloud server. The local server can specifically be a computer and a tablet computer, etc., and this is not specifically limited in the embodiment of the present invention.
[0076] First, step S11 is executed to obtain the answer text. This answer text is the textual form of information that needs to be stored in the question-and-answer database and can be retrieved by searching the posed question. This answer text can be information from various fields. For example, the fields may include construction, in which case the answer text could be construction specifications; the fields may also include operating machinery, in which case the answer text could be operating machinery operating specifications. Furthermore, the fields may also include finance, in which case the answer text could be finance-related knowledge; the fields may also include customer service, in which case the answer text could be customer service-related knowledge; and so on.
[0077] The number of answer texts can be set as needed and is not specifically limited here.
[0078] Then, step S12 is executed to parse the answer text and determine the first parsed information of the answer text. The process of parsing the answer text may include element identification and relationship identification of each word in the answer text. The element identification process can be understood as the process of determining the first element information of the answer text, and the relationship identification process can be understood as the process of determining the first relationship information of the answer text. That is, the first parsed information may include the first element information and the first relationship information of the answer text.
[0079] The first element information may include elements in the answer text. Elements in the answer text may include entities, attributes, relationships, operations, and attribute values, and may be represented using element representations such as E, A, R, P, and V. Each word in the answer text may be associated with an element label, which may be used to represent the type of each word in the answer text. The element label may correspond one-to-one with each word in the answer text, and the element label may be represented by the position of the corresponding word in the answer text in combination with the element representation.
[0080] For example, answer text 1 is "When the corridor leads to the bedroom, the net width of the corridor is >= 1.00m". "Corridor" and "bedroom" are both entity elements, so their element labels can be represented by E1 and E2, "leading to" is an operation element, so its element label can be represented by P1, "net width" is an attribute element, so its element label can be represented by A1, and ">= 1.00m" is an attribute value element, so its element label can be represented by V1.
[0081] The first relationship information may include the relationships between elements in the answer text. Taking the architectural field as an example, the relationships between elements in the answer text may include explicit and implicit relationships. Explicit relationships include "the corridor leads to the bedroom," while implicit relationships include "the corridor's clear width" and "directly lit corridor." To ensure consistency, in this embodiment, triples can be used to represent the relationship, such as [corridor, leads to, bedroom], [corridor, clear width, X], [corridor, directly lit, true], etc.
[0082] Based on this, the first parsed information of answer text 1 can be expressed as: E1P1E2, E1A1V1. The first parsed information can also be understood as a set of element labels of the answer text.
[0083] Here, the parsing process can be implemented using a trained neural network model. For example, the answer text can be input into a trained first neural network model, which directly outputs the first parsed information of the answer text. The first neural network model can be trained using a first initial model using answer samples that carry parsed information labels.
[0084] Finally, step S13 is executed to obtain the question template corresponding to the answer text according to the first parsed information of the answer text. Here, the element tags in the first element information can be recombined in syntactic order and combined with the first relationship information to obtain multiple element tag sequences.
[0085] For example, the element labels in the first parsed information of answer text 1 are: E1, P1, E2, A1 and V1. The element labels can be recombined in syntactic order to obtain multiple element label sequences, namely E1, E2, E1A1, P1E2E1 and P1E2E1A1.
[0086] The question template corresponding to each element tag sequence can then be determined. In embodiments of the present invention, the question template corresponding to each element tag sequence can be determined through manual sorting. The question template corresponding to each element tag sequence is the question template corresponding to the answer text. Each answer text can correspond to multiple question templates, which is not specifically limited here.
[0087] Thereafter, a question-and-answer library may be constructed based on the answer text and the question template, that is, the answer text and the question template may be stored correspondingly to obtain a question-and-answer library, in which the corresponding relationship between the answer text and the question template is stored.
[0088] The question-and-answer library construction method provided in an embodiment of the present invention first obtains the answer text, then parses the answer text, determines the first parsing information of the answer text, and finally obtains the question template corresponding to the answer text based on the first parsing information of the answer text, and constructs the question-and-answer library based on the answer text and the question template. This method parses the answer text and obtains the question template through the first parsing information obtained by parsing, thereby realizing the construction of the question-and-answer library. It can make the answer text correspond to a rich set of question templates, make the construction of the question-and-answer library more comprehensive, reduce the possibility that the user's question cannot be matched with the corresponding question template in the question-and-answer library, and improve the user experience. Moreover, this method can increase the number of question templates corresponding to the answer text under the premise of knowing the answer text when constructing the question-and-answer library, which can reduce the construction cost of the question-and-answer library, reduce the construction difficulty of the question-and-answer library, and facilitate the maintenance of the question-and-answer library.
[0089] Based on the above embodiment, the question-answer database construction method provided in the embodiment of the present invention, wherein the method obtains a question template corresponding to the answer text based on the first parsed information of the answer text, and then includes: parsing the question template to obtain second parsed information of the question template; the second parsed information includes second element information, second relationship information, and intent information;
[0090] Accordingly, the question-answer library is constructed based on the answer text and the question template, including:
[0091] The question and answer library is constructed based on the answer text, the question template and the second parsing information.
[0092] Specifically, in an embodiment of the present invention, after obtaining the question template corresponding to the answer text, the question template can be further parsed to obtain the second parsing information of the question template. Here, the process of parsing the question template can include the process of element identification, relationship identification and intention identification of each word in the question template. The process of element identification can be understood as the process of determining the second element information of the question template, the process of relationship identification can be understood as the process of determining the second relationship information of the question template, and the process of intention identification can be understood as the process of determining the intention information of the question template. The intention information can be the specific type of the intention element in the element information of the question template. Therefore, the second parsing information can include the second element information, second relationship information and intention information of the question template.
[0093] The second element information can include elements in the question template. Since questions usually contain the questioner's intention, for example, intention can include answer retrieval, judgment, fill-in-the-blank, etc., and fill-in-the-blank can be divided into numerical fill-in-the-blank, type fill-in-the-blank, function fill-in-the-blank, time fill-in-the-blank, etc. Therefore, the elements involved in the question template can include entities, attributes, relationships, operations, attribute values, and intentions, which can be represented by elements such as E, A, R, P, V, and I.
[0094] Each word in the question template can correspond to an element label, and the element label can be used to represent the type of each word in the question template. The element label can correspond one-to-one to each word in the question template. The element label can be represented by the position of the corresponding word in the question template and combined with the element representation.
[0095] The second relationship information may include the relationship between the elements in the question template, and may also be represented by a triple.
[0096] The intent information of the question template may refer to the specific type of the intent element in the question template, such as answer retrieval, judgment, or fill-in-the-blank.
[0097] For example, question template 1 is "What are the requirements for the clear width of the corridor leading to the bedroom?", and the second parsed information of question template 1 can be expressed as: P1E1E2A1I1. The second parsed information can be understood as a set of element labels of the question template.
[0098] Here, the parsing process can also be implemented using a trained second neural network model. For example, a question template can be input into the trained second neural network model, and the second parsing information of the question template can be directly output through the second neural network model. The second neural network model can be trained on a second initial model using question samples that carry parsing information labels.
[0099] It is understandable that, in an embodiment of the present invention, a second neural network model may also be used to parse the answer text to obtain first parsed information of the answer text.
[0100] Furthermore, when constructing a question-and-answer database, the second parsing information can be introduced. The question-and-answer database can be constructed based on the answer text, question template and the second parsing information of the question template. That is, the answer text and the question template can be stored correspondingly, and the second parsing information of the question template can be stored to obtain a question-and-answer database. The question-and-answer database not only stores the correspondence between the answer text and the question template, but also stores the second parsing information of the question template.
[0101] In an embodiment of the present invention, introducing the second parsing information of the question template into the question and answer library can enrich the information in the question and answer library, facilitate the matching process between user questions and question templates, and be more helpful in finding the question template corresponding to the user question in the question and answer library, thereby improving the user experience.
[0102] Based on the above embodiment, in the question-answer database construction method in the embodiment of the present invention, the step of parsing the question template to obtain second parsed information of the question template includes:
[0103] Performing word segmentation processing on the question template to determine the word vector representation of each word in the question template;
[0104] Based on the word vector representation of each word in the question template, the question template is sequence labeled to determine the second element information; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0105] Based on the word vector representation corresponding to the non-intentional element, performing relationship classification on the non-intentional element to determine the second relationship information;
[0106] Based on the word vector representation corresponding to the intention element, the intention element is classified into intent categories to determine the first intention information.
[0107] Specifically, when parsing the question template to obtain the second parsed information of the question template, the question template can be first segmented to determine the word vector representation of each word in the question template. The word vector representation can be a token vector. The word segmentation method can be implemented by natural language processing (NLP) methods, which are not specifically limited here.
[0108] Then, based on the word vector representation of each word in the question template, the question template can be sequence labeled. The process of sequence labeling is the process of element recognition. Through sequence labeling, the second element information can be determined. Among them, the second element information can include elements in the question template, and the elements can include intentional elements and non-intentional elements. Intentional elements can be used to represent the intended words in the question template, and non-intentional elements can be used to represent non-intentional words in the question template.
[0109] After that, regardless of the intent, the non-intent elements in the question template can be classified based on their corresponding word vector representations. Non-intent elements are word vector representations of non-intent words, so relationship classification can be understood as classifying the relationships between non-intent words in the question template, which can yield secondary relationship information.
[0110] Finally, considering only the intent elements, we can classify the intent elements in the question template based on their corresponding word vector representations. The word vector representations corresponding to the intent elements are the word vector representations of the intent words, so intent classification can be understood as classifying the intent words in the question template to obtain intent information.
[0111] In this embodiment of the present invention, the parsing process is broken down into word segmentation, sequence labeling, relationship classification, and intent classification. This allows the parsing process to obtain richer information, facilitates the matching of user questions with question templates, and helps find the corresponding question template in the question-and-answer database, thereby improving the user experience.
[0112] Based on the above embodiment, the question and answer database construction method provided in the embodiment of the present invention, wherein the question template is parsed to obtain the second parsed information of the question template, includes:
[0113] Inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model;
[0114] The natural language understanding model is trained based on question samples that carry parsing information labels.
[0115] Specifically, in an embodiment of the present invention, when parsing the question template, a natural language understanding (NLU) model can be used, that is, the question template is input into the natural language understanding model, and the natural language understanding model can be used to realize element recognition, relationship recognition, and intent recognition of the question template, and obtain and output the second parsing information of the question template.
[0116] Among them, the natural language understanding model can be a second neural network model.
[0117] In the embodiment of the present invention, parsing the question template through a natural language understanding model can not only improve the parsing efficiency, but also improve the parsing accuracy, thereby improving the efficiency of constructing the question and answer database.
[0118] Based on the above embodiment, the question-answer database construction method provided in the embodiment of the present invention, wherein the question template is input into the natural language understanding model to obtain the second parsed information output by the natural language understanding model, includes:
[0119] Inputting the question template into the character language sub-model of the natural language understanding model to obtain a word vector representation of each word in the question template output by the character language sub-model;
[0120] Inputting the word vector representation of each word in the question template into the sequence labeling sub-model of the natural language understanding model to obtain the second element information output by the sequence labeling sub-model; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0121] Inputting the word vector representation of each word in the question template and the non-intentional element into the relationship classification sub-model of the natural language understanding model to obtain the second relationship information output by the relationship classification sub-model;
[0122] Inputting the word vector representation of each word in the question template and the intent element into the intent classification sub-model of the natural language understanding model to obtain the first intent information output by the intent classification sub-model;
[0123] The character language sub-model, the sequence labeling sub-model, the relationship classification sub-model and the intention classification sub-model are jointly trained based on question samples carrying parsing information labels.
[0124] Specifically, in an embodiment of the present invention, the natural language understanding model includes a character language sub-model (Character Language Model), a sequence labeling sub-model (Sequence Labeling Model), a relationship classification sub-model (Relation Classification Model) and an intent classification sub-model (Intent Classification Model). The character language sub-model can be connected to the sequence labeling sub-model, the relationship classification sub-model and the intent classification sub-model respectively, and the sequence labeling sub-model can be connected to the relationship classification sub-model and the intent classification sub-model respectively.
[0125] After the question template is input into the natural speech understanding model, it can be jointly processed by the four sub-models described above. For example, the question template can first be input into the character language sub-model, and then the character speech sub-model can be used to segment the question template to obtain word vector representations for each word in the question template. Here, the character language sub-model can be a language representation model (Bidirectional Encoder Representation from Transformers, BERT).
[0126] Then, the word vector representation of each word in the question template can be input into the sequence labeling sub-model, which performs element recognition on the question template and outputs the second element information. Here, the sequence labeling sub-model can be a sequence labeling model built based on BERT, Bi-directional Long Short-Term Memory (BiLSTM) model, and Conditional Random Field (CRF).
[0127] Furthermore, the word vector representations of each word in the question template and the non-intentional elements can be input into the relationship classification sub-model. The non-intentional elements are classified by the relationship classification sub-model to obtain the second relationship information. This relationship information can be represented by triples. The relationship classification sub-model can be a binary classification model. The output of the model can be 0 or 1, where 0 indicates that the relationship represented by the triple does not exist, and 1 indicates that the relationship represented by the triple does exist.
[0128] Finally, the word vector representations of each word in the question template and the intent elements can be input into the intent classification sub-model. The intent classification sub-model classifies the intent elements and obtains the intent information. The structure of this intent classification sub-model can be the same as the sequence labeling sub-model, or it can be a classification model built based on BERT, Long Short-Term Memory (LSTM) model, and attention mechanism. The output of this model can be a probability table of the existence of a certain intent.
[0129] Since the relationship classification sub-model generates triples based on the element recognition results of the sequence labeling sub-model, if there are elements other than the intent elements that make up the triples after the relationship classification sub-model is completed, that is, there are non-intent elements that have no relationship, then the element recognition results of the sequence labeling sub-model need to be penalized. If the intent finally predicted by the intent classification sub-model has nothing to do with the intent elements identified in the sequence labeling sub-model, then the intent recognition results of the sequence labeling sub-model also need to be penalized. Therefore, in an embodiment of the present invention, the three tasks of element recognition, relationship extraction, and intent recognition are jointly trained, that is, the initial models of the sequence labeling sub-model, the relationship classification sub-model, and the intent classification sub-model are jointly trained, and the three initial models share the lowest-level character language sub-model.
[0130] In this embodiment of the present invention, the specific structure of the natural language understanding model is presented. Different sub-models are used to implement different task functions, thereby achieving a certain degree of independence between the various task functions. Furthermore, by jointly training the sub-models, the sub-models are not completely independent, but rather mutually constrained, thereby ensuring the accuracy of the question template parsing.
[0131] On the basis of the above embodiment, in the question-answer database construction method provided in the embodiment of the present invention, the element information further includes: position information of each word in the element.
[0132] Specifically, in the embodiment of the present invention, since an element is generally a word, which may include one or more characters, the element information may include position information of each character within the element. For example, the position information may include a start bit, a middle bit, and an end bit, which may be represented by B, I, and E, respectively.
[0133] In the embodiment of the present invention, the position information of each word in the element is introduced into the element information, which can improve the richness of the element information and further improve the matching accuracy of the question template.
[0134] Figure 2 is a schematic diagram of the structure of the natural language understanding model used in the question-answer database construction method provided in the embodiment of the present invention. Figure 2 As shown in the figure, the natural language understanding model includes a character language sub-model (Character Language Model), a sequence labeling sub-model (Sequence Labeling Model), a relation classification sub-model (RelationClassification Model) and an intent classification sub-model (Intent Classification Model).
[0135] Taking question template 1, "What are the requirements for the clear width of the hallway leading to the bedroom?" as an example, after running through the character language sub-model and sequence labeling sub-model, question template 1 can obtain element information, which can be expressed as BP EP BE EE O BE E-EO BA EA OOO BI EI O. Question template 1 also obtains relationship information after running through the character language sub-model and relationship classification sub-model, which can be represented as a two-dimensional graph. After running through the character language sub-model and intent classification sub-model, question template 1 can obtain intent information, which can be the probabilities corresponding to each intent. For example, the corresponding probabilities for intents I1, I2, I3, and I4 are 0.9, 0.8, 0.7, and 0.1, respectively.
[0136] Based on the above embodiment, the question-answer database construction method provided in the embodiment of the present invention, wherein the answer text is parsed to determine the first parsed information of the answer text, includes:
[0137] The answer text is converted into a structured expression to obtain sub-answer texts corresponding to the answer text.
[0138] Specifically, in an embodiment of the present invention, before parsing the answer text, the answer text may be converted into a structured expression, thereby obtaining sub-answer texts corresponding to the answer text. The conversion process may be implemented using a natural language processing (NLP) method, which is not specifically limited herein.
[0139] For example, answer text 2 is "The net width of the aisle leading to the bedroom and living room (hall) should not be less than 1.00m". After conversion into a structured expression, two sub-answer texts can be obtained, namely: sub-answer text 1 "When the aisle leads to the bedroom, the net width of the aisle is ≥1.00m" and sub-answer text 2 "When the aisle leads to the living room (hall), the net width of the aisle is ≥1.00m".
[0140] The sub-answer text 1 can be obtained by the following code:
[0141]
[0142] Obtaining sub-answer text 2 can be achieved through the following code:
[0143]
[0144] In the embodiment of the present invention, the answer text is converted into a structured expression, and then the sub-answer texts corresponding to the answer text are obtained, which can simplify the difficulty of parsing the answer text and improve the parsing efficiency.
[0145] Based on the above embodiment, the question-answer database construction method provided in the embodiment of the present invention, wherein the parsing of the answer text to determine the first parsing information of the answer text includes:
[0146] For any sub-answer text in the answer text, perform word segmentation processing on the sub-answer text to determine a word vector representation of each word in the sub-answer text;
[0147] Based on the word vector representation of each word in the any sub-answer text, sequence labeling is performed on the any sub-answer text to determine the third element information of the any sub-answer text; the third element information includes the elements in the any sub-answer text;
[0148] Based on the word vector representation of each word in the any sub-answer text, performing relationship classification on the elements in the any sub-answer text to determine the third relationship information of the any sub-answer text;
[0149] The first parsing information is determined based on the third element information and the third relationship information of each sub-answer text.
[0150] Specifically, in an embodiment of the present invention, when parsing the answer text, any sub-answer text in the answer text can be segmented, and then the word vector representation of each word in the sub-answer text can be determined.
[0151] Then, based on the word vector representation of each word in the sub-answer text, we can perform sequence labeling on the sub-answer text to determine the third element information of the sub-answer text. Since the answer text usually does not contain user intent, the third element information includes the elements in the sub-answer text, which are all non-intent elements.
[0152] Then, the elements in any sub-answer text may be classified into relationships based on the word vector representation of each word in any sub-answer text, and the third relationship information of any sub-answer text may be determined.
[0153] Finally, the first parsing information can be determined based on the third element information and third relationship information of each sub-answer text in the answer text, wherein the third element information of each sub-answer text together constitutes the first element information, and the third relationship information of each sub-answer text together constitutes the first relationship information.
[0154] It is understandable that the specific implementation of the above-mentioned word segmentation processing, sequence labeling and relationship classification can be found in the above-mentioned embodiments and will not be repeated here.
[0155] In an embodiment of the present invention, a detailed solution for parsing the answer text is provided, which introduces the third element information and third relationship information of each sub-answer text, thereby ensuring the comprehensiveness of the first parsing information and the number of question templates.
[0156] Based on the above embodiment, the question-answer database construction method provided in the embodiment of the present invention, wherein the step of obtaining the question template corresponding to the answer text based on the first parsed information of the answer text includes:
[0157] For any sub-answer text in the answer text, based on the syntactic order corresponding to each element in the third element information of the any sub-answer text and the third relationship information of the any sub-answer text, the elements are recombined to obtain a combination result corresponding to the any sub-answer text;
[0158] The question template is determined based on the combination results corresponding to the sub-answer texts.
[0159] Specifically, in an embodiment of the present invention, when obtaining a question template corresponding to an answer text, for any sub-answer text in the answer text, the elements in the third element information of the sub-answer text can be recombined based on the syntactic order corresponding to each element in the third element information of the sub-answer text and in combination with the third relationship information of the sub-answer text to obtain a combination result corresponding to the sub-answer text. The combination result is the label sequence of each element.
[0160] The syntactic order is the logical order of the sub-answer texts. For example, if sub-answer text 1 is "When the corridor leads to the bedroom, the corridor's net width is greater than or equal to 1.00m," the elements in the third element information can be represented by element tags as E1, P1, E2, A1, and V1, respectively. Therefore, after recombining, the resulting combination will include element tag sequences such as E1, E2, E1A1, P1E2E1, and P1E2E1A1.
[0161] Finally, the question template can be determined based on the combination results corresponding to the sub-answer texts. That is, the corresponding question template can be determined based on the label sequence of each element in the combination results through manual sorting or other methods.
[0162] In the embodiment of the present invention, the question template is determined by each sub-answer text, so that the answer text corresponding to the question template can be more accurate.
[0163] like Figure 3 As shown, based on the above embodiment, an embodiment of the present invention provides a question-answering method, which includes:
[0164] S31, obtain user questions;
[0165] S32, selecting an answer text matching the user question from the question and answer library;
[0166] The question-and-answer database is constructed based on the question-and-answer database construction method according to any one of claims 1 to 8.
[0167] Specifically, the question-and-answer method provided in the embodiment of the present invention has a question-and-answer device as its execution body, which can be configured in a server. The server can be a local server or a cloud server. The local server can specifically be a computer and a tablet computer, etc., which is not specifically limited in the embodiment of the present invention.
[0168] First, step S31 is executed to obtain a user question. The user question can be in voice or text form. The user can input the user question through the user terminal held by the user. The question-answering device can be connected to the user terminal or configured within the user terminal so that the question-answering device can obtain the user question input by the user.
[0169] Then, step S32 is executed to select the answer text that matches the user question from the question and answer database. Since the information stored in the question and answer database is all in text format, if the user question obtained in step S31 is in text format, step S32 can be executed directly. If the user question obtained in step S31 is in voice format, the voice format must be converted into text format before executing step S32.
[0170] In the embodiment of the present invention, the question-and-answer library used can be constructed using the question-and-answer library construction method provided in the above embodiments. For details, please refer to the above embodiments and will not be described in detail here. The question-and-answer library can store the correspondence between question templates and answer texts, and can also store second parsing information of the question templates. Therefore, when executing step S32, the user question can first be matched with the question templates in the question-and-answer library, and the answer text corresponding to the successfully matched question template can be output to the user terminal as the answer text matched with the user.
[0171] The question-answering method provided in the embodiment of the present invention first obtains a user question and then selects an answer text that matches the user question from a question-answering library. By utilizing the question-answering library, the probability of successfully matching the user question can be greatly increased.
[0172] Based on the above embodiment, the question-answering method provided in the embodiment of the present invention, wherein the step of selecting an answer text matching the user question from the question-answer library includes:
[0173] Parsing the user question to determine fourth parsed information of the user question, where the fourth parsed information includes fourth element information, fourth relationship information, and second intent information;
[0174] Based on the second intent information in the fourth parsed information of the user question and the first intent information in the second parsed information of the question template in the question and answer library, matching the user question with the question template to obtain a first matching result;
[0175] If the first matching result is a match failure, matching the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question and answer library to obtain a second matching result;
[0176] Based on the second matching result, an answer text in the question and answer library that matches the user question is determined.
[0177] Specifically, in this embodiment of the present invention, when selecting an answer text that matches a user question from the question-and-answer database, the user question may be parsed first to obtain fourth parsed information about the user question. The process of parsing the user question is identical to the process of parsing the question template in the above-described embodiment and will not be further described here.
[0178] Then, the user question and the question template can be matched by combining the second intent information of the user question and the first intent information of the question template to obtain a first matching result. Specifically, a determination is first made as to whether the first target question template exists in the question-answer library, and whether the first intent information of the first target question template matches the second intent information. If the first target question template exists, the first matching result is considered a successful match, and the answer text that matches the user question can then be determined to be the answer text corresponding to the first target question template.
[0179] If it is determined that the first target question template does not exist in the question and answer database, the first matching result is a match failure. At this point, the user question and the question template can be further matched based on the fourth element information and fourth relationship information in the fourth parsed information of the user question and the second element information and second relationship information in the second parsed information of the question template in the question and answer database to obtain a second matching result. That is, it is determined whether the second target question template exists in the question and answer database, the second element information of the second target question template matches the fourth element information, and the second relationship information of the second target question template matches the fourth relationship information. If the second target question template exists, the second matching result is considered a match success, and it can be determined that the answer text that matches the user question is the answer text corresponding to the second target question template.
[0180] If it is determined that the second target question template does not exist in the question and answer database, the second matching result is a matching failure, and the answer text that is determined to match the user question is empty.
[0181] In an embodiment of the present invention, the user question is first matched with the question template using the intent information, and then the element information and relationship information are used for matching when the matching fails. This can improve the matching efficiency and further improve the efficiency of determining the answer text corresponding to the user question.
[0182] Based on the above embodiment, the question-answering method provided in the embodiment of the present invention matches the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question-answering library to obtain a second matching result, including:
[0183] Obtain a knowledge graph of the field in which the answer text resides;
[0184] Based on the knowledge graph, the fourth element information, the fourth relationship information, the second element information, and the second relationship information, a graph-structure-based similarity calculation method is used to calculate the similarity between the user question and the question template;
[0185] Based on the similarity, the second matching result is determined.
[0186] Specifically, in embodiments of the present invention, a knowledge graph can be introduced when matching using element information and relationship information. This knowledge graph can be a knowledge graph for the field in which the answer text resides. For example, it can be a knowledge graph for the field of architecture. This knowledge graph includes multiple nodes and the connection relationships between each node. Each node represents a different non-intentional element in the field of architecture, carries corresponding element information, and the connection relationships between nodes represent the relationship information between the non-intentional elements.
[0187] Then, the knowledge graph can be combined, and according to the fourth element information, the fourth relationship information and the second element information, the second relationship information, a similarity calculation method based on the graph structure can be used to calculate the similarity between the user question and the question template.
[0188] The specific method may be: using the fourth element information and the fourth relationship information, a corresponding first graph structure is obtained in the knowledge graph. This first graph structure can be equivalent to a first knowledge graph corresponding to the user question constructed using the fourth element information and the fourth relationship information. Similarly, using the second element information and the second relationship information, a corresponding second graph structure can also be obtained in the knowledge graph. This second graph structure can be equivalent to a second knowledge graph corresponding to the question template constructed using the second element information and the second relationship information.
[0189] Each user question corresponds to a first graph structure, and each question template corresponds to a second graph structure. The graph structure-based similarity calculation method can calculate the similarity between the first graph structure and the second graph structure.
[0190] The similarity calculation method based on graph structure can be implemented by the following formula:
[0191]
[0192] Among them, A represents the first graph structure, B represents the second graph structure, Sim(A,B) represents the similarity between the first graph structure and the second graph structure, C is a constant, I i (a) represents the i-th node in the first graph structure, I j (b) represents the jth node in the second graph structure, I(a) represents the node set in the first graph structure, and I(b) represents the node set in the second graph structure.
[0193] s(I i (a),I j (b)) represents the similarity between the i-th node in the first graph structure and the j-th node in the second graph structure. Let m = s(I i (a), n=s(I i (a), the similarity can be calculated using the following formula:
[0194] s(m,n)=(RandWalk(m,n)+Sim emb(m,n) ) / 2
[0195] Where s(m,n)=s(I i (a),I j (b)), RandWalk(m,n) is the probability of going from the i-th node in the first graph structure to the j-th node in the second graph structure, ranging from 0 to 1, Sim emb(m,n) is the cosine similarity between the first vector representation and the second vector representation, where the first vector representation refers to the vector representation (embedding) of the fourth element information and the fourth relationship information of the i-th node in the first graph structure, i.e., the embedding vector; the second vector representation refers to the vector representation (embedding) of the second element information and the second relationship information of the j-th node in the second graph structure, i.e., the embedding vector.
[0196] Finally, the second matching result is determined using the similarity Sim(A, B). Here, the relationship between this similarity and the similarity threshold is determined. If the similarity is greater than or equal to the similarity threshold, the second matching result is considered a successful match, and B is the question template that successfully matches the user's question. If the similarity is less than the similarity threshold, the second matching result is considered a successful match.
[0197] It is understood that a large number of question templates are stored in the Q&A database. Therefore, all question templates can be matched with user questions, and then all question templates in the Q&A database that successfully match the user questions can be determined. As long as there is a question template in the Q&A database that successfully matches the user question, the match is considered successful. Conversely, if there is no question template in the Q&A database that successfully matches the user question, the match is considered unsuccessful.
[0198] In an embodiment of the present invention, a similarity calculation method based on a graph structure is adopted to calculate the similarity between user questions and question templates, making full use of the domain knowledge graph, and can improve the efficiency of finding question templates that match user questions, and can also improve the accuracy of the found question templates.
[0199] like Figure 4As shown, based on the above embodiment, an embodiment of the present invention provides a question and answer library construction device, including:
[0200] A text acquisition module 41 is used to acquire the answer text;
[0201] A parsing module 42 is configured to parse the answer text and determine first parsed information of the answer text; the first parsed information includes first element information and first relationship information;
[0202] The construction module 43 is used to obtain the question template corresponding to the answer text based on the first parsing information of the answer text, and to construct a question and answer library based on the answer text and the question template.
[0203] On the basis of the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the parsing module is further configured to:
[0204] Parsing the question template to obtain second parsed information of the question template; the second parsed information includes second element information, second relationship information, and first intention information;
[0205] Accordingly, the building blocks are used to:
[0206] The question and answer library is constructed based on the answer text, the question template and the second parsing information.
[0207] On the basis of the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the parsing module is further configured to:
[0208] Performing word segmentation processing on the question template to determine the word vector representation of each word in the question template;
[0209] Based on the word vector representation of each word in the question template, the question template is sequence labeled to determine the second element information; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0210] Based on the word vector representation corresponding to the non-intentional element, performing relationship classification on the non-intentional element to determine the second relationship information;
[0211] Based on the word vector representation corresponding to the intention element, the intention element is classified into intent categories to determine the first intention information.
[0212] On the basis of the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the parsing module is further configured to:
[0213] Inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model;
[0214] The natural language understanding model is trained based on question samples that carry parsing information labels.
[0215] On the basis of the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the parsing module is further configured to:
[0216] Inputting the question template into the character language sub-model of the natural language understanding model to obtain a word vector representation of each word in the question template output by the character language sub-model;
[0217] Inputting the word vector representation of each word in the question template into the sequence labeling sub-model of the natural language understanding model to obtain the second element information output by the sequence labeling sub-model; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements;
[0218] Inputting the word vector representation of each word in the question template and the non-intentional element into the relationship classification sub-model of the natural language understanding model to obtain the second relationship information output by the relationship classification sub-model;
[0219] Inputting the word vector representation of each word in the question template and the intent element into the intent classification sub-model of the natural language understanding model to obtain the first intent information output by the intent classification sub-model;
[0220] The sequence labeling sub-model, the relationship classification sub-model and the intention classification sub-model are jointly trained based on question samples carrying parsing information labels.
[0221] Based on the above embodiment, the question-answer database construction device provided in the embodiment of the present invention further includes a conversion module for:
[0222] The answer text is converted into a structured expression to obtain sub-answer texts corresponding to the answer text.
[0223] Based on the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the parsing module is specifically configured to:
[0224] For any sub-answer text in the answer text, perform word segmentation processing on the sub-answer text to determine a word vector representation of each word in the sub-answer text;
[0225] Based on the word vector representation of each word in the any sub-answer text, sequence labeling is performed on the any sub-answer text to determine the third element information of the any sub-answer text; the third element information includes the elements in the any sub-answer text;
[0226] Based on the word vector representation of each word in the any sub-answer text, performing relationship classification on the elements in the any sub-answer text to determine the third relationship information of the any sub-answer text;
[0227] The first parsing information is determined based on the third element information and the third relationship information of each sub-answer text.
[0228] On the basis of the above embodiment, in the apparatus for constructing a question-and-answer database provided in the embodiment of the present invention, the construction module is further configured to:
[0229] For any sub-answer text in the answer text, based on the syntactic order corresponding to each element in the third element information of the any sub-answer text and the third relationship information of the any sub-answer text, the elements are recombined to obtain a combination result corresponding to the any sub-answer text;
[0230] The question template is determined based on the combination results corresponding to the sub-answer texts.
[0231] Specifically, the functions of each module in the question-and-answer database construction device provided in the embodiment of the present invention correspond one-to-one to the operational procedures of each step in the above-mentioned method embodiment, and the effects achieved are also consistent. Please refer to the above-mentioned embodiment for details, and no further details will be given in the embodiment of the present invention.
[0232] like Figure 5 As shown, based on the above embodiment, an embodiment of the present invention provides a question-answering device, including:
[0233] The question acquisition module 51 is used to obtain user questions;
[0234] A selection module 52 is configured to select an answer text matching the user question from the question and answer library;
[0235] The question and answer database is constructed based on the question and answer database construction method provided in the above embodiments.
[0236] On the basis of the above embodiment, in the question-answering device provided in the embodiment of the present invention, the selection module is specifically configured to:
[0237] Parsing the user question to determine fourth parsed information of the user question, where the fourth parsed information includes fourth element information, fourth relationship information, and second intent information;
[0238] Based on the second intent information in the fourth parsed information of the user question and the first intent information in the second parsed information of the question template in the question and answer library, matching the user question with the question template to obtain a first matching result;
[0239] If the first matching result is a match failure, matching the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question and answer library to obtain a second matching result;
[0240] Based on the second matching result, an answer text in the question and answer library that matches the user question is determined.
[0241] On the basis of the above embodiment, in the question-answering device provided in the embodiment of the present invention, the selection module is further specifically configured to:
[0242] Obtain a knowledge graph of the field in which the answer text resides;
[0243] Based on the knowledge graph, the fourth element information, the fourth relationship information, the second element information, and the second relationship information, a graph-structure-based similarity calculation method is used to calculate the similarity between the user question and the question template;
[0244] Based on the similarity, the second matching result is determined.
[0245] Specifically, the functions of each module in the question-and-answer device provided in the embodiment of the present invention correspond one-to-one to the operation process of each step in the above method embodiment, and the effects achieved are also consistent. Please refer to the above embodiment for details, and no further details will be given in the embodiment of the present invention.
[0246] Figure 6 An example of a physical structure diagram of an electronic device is shown below. Figure 6As shown, the electronic device may include: a processor (Processor) 610, a communication interface (Communications Interface) 620, a memory (Memory) 630 and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other via the communication bus 640. The processor 610 can call the logic instructions in the memory 630 to execute the question-answer library construction method provided in the above embodiment, which includes: obtaining an answer text; parsing the answer text to determine the first parsing information of the answer text; based on the first parsing information of the answer text, obtaining the question template corresponding to the answer text, and constructing a question-answer library based on the answer text and the question template. Alternatively, the question-answer method provided in each of the above embodiments is executed, which includes: obtaining a user question; selecting an answer text that matches the user question from the question-answer library; wherein the question-answer library is constructed based on the question-answer library construction method provided in the above embodiment.
[0247] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0248] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the question-answer library construction method provided in the above embodiment, the method comprising: obtaining an answer text; parsing the answer text to determine the first parsing information of the answer text; based on the first parsing information of the answer text, obtaining a question template corresponding to the answer text, and constructing a question-answer library based on the answer text and the question template. Alternatively, executing the question-answer method provided in each of the above embodiments, which comprises: obtaining a user question; selecting an answer text that matches the user question from the question-answer library; wherein the question-answer library is constructed based on the question-answer library construction method provided in the above embodiment.
[0249] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the question-and-answer library construction method provided in the above-mentioned embodiments, the method comprising: obtaining an answer text; parsing the answer text to determine first parsing information of the answer text; obtaining a question template corresponding to the answer text based on the first parsing information of the answer text, and constructing a question-and-answer library based on the answer text and the question template. Alternatively, executing the question-and-answer method provided in each of the above-mentioned embodiments comprises: obtaining a user question; selecting an answer text from the question-and-answer library that matches the user question; wherein the question-and-answer library is constructed based on the question-and-answer library construction method provided in the above-mentioned embodiments.
[0250] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0251] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0252] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A method for constructing a question-answer database, characterized in that: include: Get the answer text; Parsing the answer text to determine first parsing information of the answer text; The first parsed information includes first element information and first relationship information; the first element information includes elements in the answer text, the elements are represented by element representations, each word in the answer text corresponds to an element label, and the element label is represented based on the position of the corresponding word in the answer text and in combination with the element representation; Based on the first parsed information of the answer text, obtaining a question template corresponding to the answer text, and constructing a question and answer library based on the answer text and the question template; The question template is determined based on the following steps: Recombining the element labels in syntactic order and in combination with the first relationship information to obtain multiple element label sequences, and determining the question template corresponding to each element label sequence; The step of obtaining a question template corresponding to the answer text based on the first parsed information of the answer text further includes: parsing the question template to obtain second parsed information of the question template; the second parsed information includes second element information, second relationship information, and first intent information; Accordingly, the question-answer library is constructed based on the answer text and the question template, including: Building the question and answer library based on the answer text, the question template, and the second parsing information; The parsing of the answer text to determine first parsed information of the answer text includes: The answer text is converted into a structured expression to obtain sub-answer texts corresponding to the answer text.
2. The method for constructing a question-answer database according to claim 1, wherein: The step of parsing the question template to obtain second parsed information of the question template includes: Performing word segmentation processing on the question template to determine the word vector representation of each word in the question template; Based on the word vector representation of each word in the question template, the question template is sequence labeled to determine the second element information; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements; Based on the word vector representation corresponding to the non-intentional element, performing relationship classification on the non-intentional element to determine the second relationship information; Based on the word vector representation corresponding to the intention element, the intention element is classified into intent categories to determine the first intention information.
3. The method for constructing a question-answer database according to claim 1, wherein: The step of parsing the question template to obtain second parsed information of the question template includes: Inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model; The natural language understanding model is trained based on question samples that carry parsing information labels.
4. The method for constructing a question-answer database according to claim 3, wherein: Inputting the question template into a natural language understanding model to obtain the second parsed information output by the natural language understanding model includes: Inputting the question template into the character language sub-model of the natural language understanding model to obtain a word vector representation of each word in the question template output by the character language sub-model; Inputting the word vector representation of each word in the question template into the sequence labeling sub-model of the natural language understanding model to obtain the second element information output by the sequence labeling sub-model; the second element information includes elements in the question template, and the elements include intention elements and non-intention elements; Inputting the word vector representation of each word in the question template and the non-intentional element into the relationship classification sub-model of the natural language understanding model to obtain the second relationship information output by the relationship classification sub-model; Inputting the word vector representation of each word in the question template and the intent element into the intent classification sub-model of the natural language understanding model to obtain the first intent information output by the intent classification sub-model; The sequence labeling sub-model, the relationship classification sub-model and the intention classification sub-model are jointly trained based on question samples carrying parsing information labels.
5. The method for constructing a question-answer database according to claim 1, wherein: The parsing of the answer text to determine first parsed information of the answer text includes: For any sub-answer text in the answer text, perform word segmentation processing on the sub-answer text to determine a word vector representation of each word in the sub-answer text; Based on the word vector representation of each word in the any sub-answer text, sequence labeling is performed on the any sub-answer text to determine the third element information of the any sub-answer text; the third element information includes the elements in the any sub-answer text; Based on the word vector representation of each word in the any sub-answer text, performing relationship classification on the elements in the any sub-answer text to determine the third relationship information of the any sub-answer text; The first parsing information is determined based on the third element information and the third relationship information of each sub-answer text.
6. The method for constructing a question-answer database according to claim 5, wherein: The obtaining, based on the first parsed information of the answer text, a question template corresponding to the answer text, includes: For any sub-answer text in the answer text, based on the syntactic order corresponding to each element in the third element information of the any sub-answer text and the third relationship information of the any sub-answer text, the elements are recombined to obtain a combination result corresponding to the any sub-answer text; The question template is determined based on the combination results corresponding to the sub-answer texts.
7. A question-answering method, characterized in that: include: Get user questions; Selecting an answer text matching the user's question from the question and answer library; The question-and-answer database is constructed based on the question-and-answer database construction method according to any one of claims 1 to 6.
8. The question-answering method according to claim 7, wherein: The step of selecting an answer text matching the user question from the question-answer library includes: Parsing the user question to determine fourth parsed information of the user question, where the fourth parsed information includes fourth element information, fourth relationship information, and second intent information; Based on the second intent information in the fourth parsed information of the user question and the first intent information in the second parsed information of the question template in the question and answer library, matching the user question with the question template to obtain a first matching result; If the first matching result is a match failure, matching the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question and answer library to obtain a second matching result; Based on the second matching result, an answer text in the question and answer library that matches the user question is determined.
9. The question-answering method according to claim 8, wherein: The matching of the user question with the question template based on the fourth element information and the fourth relationship information in the fourth parsed information of the user question and the second element information and the second relationship information in the second parsed information of the question template in the question-and-answer library to obtain a second matching result includes: Obtain a knowledge graph of the field in which the answer text resides; Based on the knowledge graph, the fourth element information, the fourth relationship information, the second element information, and the second relationship information, a graph-structure-based similarity calculation method is used to calculate the similarity between the user question and the question template; Based on the similarity, the second matching result is determined.
10. A question-answer database construction device, characterized in that: include: Text acquisition module, used to obtain answer text; A parsing module, configured to parse the answer text and determine first parsing information of the answer text; The first parsed information includes first element information and first relationship information; the first element information includes elements in the answer text, the elements are represented by element representations, each word in the answer text corresponds to an element label, and the element label is represented based on the position of the corresponding word in the answer text and in combination with the element representation; A construction module, configured to obtain a question template corresponding to the answer text based on the first parsed information of the answer text, and to construct a question-answer library based on the answer text and the question template; The question template is determined based on the following steps: Recombining the element labels in syntactic order and in combination with the first relationship information to obtain multiple element label sequences, and determining the question template corresponding to each element label sequence; The step of obtaining a question template corresponding to the answer text based on the first parsed information of the answer text further includes: parsing the question template to obtain second parsed information of the question template; the second parsed information includes second element information, second relationship information, and first intent information; Accordingly, the question-answer library is constructed based on the answer text and the question template, including: Building the question and answer library based on the answer text, the question template, and the second parsing information; The parsing of the answer text to determine first parsed information of the answer text includes: The answer text is converted into a structured expression to obtain sub-answer texts corresponding to the answer text.
11. A question-answering device, characterized in that: include: Question acquisition module, used to obtain user questions; A selection module, configured to select an answer text matching the user's question from the question-answer library; The question-and-answer database is constructed based on the question-and-answer database construction method according to any one of claims 1 to 6.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the question-answer database construction method according to any one of claims 1 to 6 or the steps of the question-answer method according to any one of claims 7 to 9 are implemented.
13. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the question-answering database construction method according to any one of claims 1 to 6 or the steps of the question-answering method according to any one of claims 7 to 9 are implemented.
Citation Information
Patent Citations
Intelligent question answer method, device and computer readable storage medium
CN107918634A
Question and answer library construction method and related device
CN113761109A