Sentence vector generation method and device, matching method and device, and storage medium
By preprocessing the original sentences and fusing multiple models to generate sentence vectors, the problem of insufficient sentence vector generation capability in existing technologies is solved, thereby improving the accuracy of answers in intelligent question answering systems.
Patent Information
- Application Number
- CN202110955229.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-19
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2041-08-19
AI Technical Summary
Existing sentence vector generation methods are insufficient in understanding grammar and word order, resulting in low accuracy of answers output by intelligent question answering systems.
By preprocessing the original sentences, filtering stop words and labeling entity tags, and using the Tianzige-CNN model and the ERNIE deep pre-trained model to generate sentence vectors containing glyph, pronunciation, stroke and entity tag information, the target sentence vector is generated by weighted fusion.
The generated sentence vectors contain more effective information, can more accurately represent the meaning of sentences, and improve the accuracy of the answers output by the intelligent question-answering system.
Smart Images

Figure CN115712704B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of natural language processing, specifically relating to a sentence vector generation method and apparatus, a matching method and apparatus, and a storage medium. Background Technology
[0002] For intelligent question answering systems, the general process involves generating a sentence vector of the question input by the user, then performing similarity matching between the sentence vector of the question and the sentence vector of the pre-saved question in the intelligent question answering system to obtain the target question and its corresponding answer, and finally outputting the answer.
[0003] In existing technologies, text feature extraction methods (such as word2vec, TF-IDF, or word2vec+TF-IDF) are generally used to generate sentence vectors for questions. However, these sentence vector generation methods are relatively weak in understanding grammar and word order, resulting in fewer effective information included in the generated sentence vectors. Consequently, they cannot well express the information in the sentence, leading to a lower accuracy rate of the answers output by the intelligent question answering system. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a sentence vector generation method and apparatus, a matching method and apparatus, and a storage medium. The sentence vectors generated by this vector generation method can cover more effective information, which is beneficial to improving the accuracy of the results output by the intelligent question answering system.
[0005] The embodiments of this application are implemented as follows:
[0006] In a first aspect, embodiments of this application provide a matching method, the method comprising: preprocessing a received original sentence to obtain a sentence after filtering stop words and a sentence after filtering stop words and labeling with entity tags; processing the sentence after filtering stop words to obtain a first sentence vector, the first sentence vector including attribute information of the characters included in the sentence after filtering stop words; the attribute information including at least one of character shape, pronunciation, and stroke count; processing the sentence after filtering stop words and labeling with entity tags and the original sentence to obtain a second sentence vector, the second sentence vector including information of the entity tags; the target vector of the original sentence including the first sentence vector and the second sentence vector.
[0007] The target vector obtained by processing the original sentence through the embodiments of this application includes entity label information in the original sentence and attribute information of Chinese characters after removing stop words in the original sentence. Compared with the existing technology of extracting sentence vectors by text feature extraction, the target sentence vector generated by this solution contains more information and can fully express the meaning represented by the original sentence.
[0008] In conjunction with the first aspect of the embodiment, in one possible implementation, when the attribute information includes character shape, pronunciation, and stroke count, the step of processing the sentence after filtering out stop words to obtain a first sentence vector includes: inputting the sentence after filtering out stop words into a grid-CNN model and outputting a first sub-vector; inputting the sentence after filtering out stop words into a stroke-phonetic model and outputting a second sub-vector; and weightedly fusing the first sub-vector and the second sub-vector to obtain the first sentence vector.
[0009] In conjunction with the first aspect of the embodiment, in one possible implementation, the step of processing the sentence after filtering stop words and labeling entity tags, and the original sentence to obtain the second sentence vector includes: inputting the original sentence into a first ERNIE deep pre-trained model and outputting a third sub-vector; inputting the sentence after filtering stop words and labeling entity tags into a second ERNIE deep pre-trained model and outputting a fourth sub-vector; and weightedly fusing the third sub-vector and the fourth sub-vector to obtain the second sentence vector.
[0010] In conjunction with the first aspect of the embodiment, in one possible implementation, the preprocessing of the received original sentence includes: segmenting the original sentence input using a word segmentation tool to obtain multiple words; filtering words from the multiple words that belong to a preset stop word library to obtain a sentence with filtered stop words; inputting the sentence with filtered stop words into an entity tag recognition model to output entity tags for each word included in the sentence with filtered stop words; and recombining the words including entity tags in their original order to obtain the sentence with filtered stop words and entity tags.
[0011] Secondly, embodiments of this application provide a matching method, the method comprising: processing the obtained question according to the sentence vector generation method described in any of the embodiments of the first aspect above to generate a target vector of the question; calculating the similarity between the target vector of the question and the target vector of a question in a database, and determining the target question based on the similarity; storing a corresponding answer for each question in the database; and returning the answer corresponding to the target question.
[0012] When the intelligent question-answering system matches answers to user-input questions using the matching method provided in this application embodiment, the amount of information contained in the vector used for comparison is far greater than that of the vectors used in the prior art. Therefore, the vectors in this application embodiment can more accurately represent the meaning expressed by the sentence, thereby improving the accuracy of the results output by the intelligent question-answering system.
[0013] In conjunction with the second aspect of the embodiment, in one possible implementation, calculating the similarity between the target vector of the question and the target vector of the questions in the database includes: calculating the similarity between the target vector of the question and the target vector of the candidate questions in the database; wherein the candidate questions are determined by: generating an initial vector of the question according to a preset rule; and performing similarity matching between the initial vector and the initial vector of the questions stored in the database to obtain the candidate questions.
[0014] In this embodiment, the similarity between the target vector of the question and the target vector of the candidate answers in the database is calculated, which can reduce the amount of computation and improve the efficiency of subsequent processing.
[0015] In conjunction with the second aspect of the embodiment, in one possible implementation, the database stores sub-databases corresponding to different intents; before performing similarity matching between the initial vector and the initial vectors of questions stored in the database, the method further includes: performing intent recognition on the question to determine the intent of the question; correspondingly, performing similarity matching between the initial vector and the initial vectors of questions stored in the database includes: performing similarity matching between the initial vector and the initial vectors of questions in the sub-database corresponding to the intent in the database.
[0016] In this embodiment, the initial vector of the question can be matched with the initial vector of the question in the sub-database corresponding to the intent of the question in the database, so as to reduce the number of questions that need to be matched and improve the efficiency of subsequent processing.
[0017] Thirdly, embodiments of this application provide a sentence vector generation device, the device comprising: a preprocessing module and a generation module.
[0018] The preprocessing module is used to preprocess the received raw sentences to obtain sentences after filtering out stop words and sentences after filtering out stop words and tagging entity labels.
[0019] The generation module is used to process the sentence after filtering stop words to obtain a first sentence vector. The first sentence vector includes attribute information of the characters included in the sentence after filtering stop words. The attribute information includes at least one of character shape, pronunciation, and stroke count.
[0020] The generation module is further configured to process the sentence after filtering stop words and labeling entity tags, as well as the original sentence, to obtain a second sentence vector, wherein the second sentence vector includes the information of the entity tags;
[0021] The target vector of the original sentence includes the vector of the first sentence and the vector of the second sentence.
[0022] In conjunction with the third aspect of the embodiment, in one possible implementation, when the attribute information includes character shape, pronunciation, and stroke count, the generation module is configured to: input the sentence after filtering stop words into the grid-CNN model and output a first sub-vector; input the sentence after filtering stop words into the stroke-phonetic model and output a second sub-vector; and perform weighted fusion of the first sub-vector and the second sub-vector to obtain the first sentence vector.
[0023] In conjunction with the third aspect of the embodiment, in one possible implementation, the generation module is configured to: input the original sentence into a first ERNIE deep pre-trained model and output a third sub-vector; input the sentence after filtering stop words and labeling entity tags into a second ERNIE deep pre-trained model and output a fourth sub-vector; and perform weighted fusion of the third sub-vector and the fourth sub-vector to obtain the second sentence vector.
[0024] In conjunction with the third aspect of the embodiment, in one possible implementation, the preprocessing module is configured to: segment the original sentence input using a word segmentation tool to obtain multiple words; filter words from the multiple words that belong to a preset stop word library to obtain a sentence with filtered stop words; input the sentence with filtered stop words into an entity tag recognition model to output entity tags for each word included in the sentence with filtered stop words; and reorganize the words including entity tags in their original order to obtain the sentence with filtered stop words and entity tags.
[0025] Fourthly, embodiments of this application also provide a matching device, including: a generation module, a calculation module, and a return module.
[0026] The generation module is used to process the obtained question according to the sentence vector generation method and generate the target vector of the question.
[0027] The calculation module is used to calculate the similarity between the target vector of the question and the target vector of the questions in the database, and to determine the target question based on the similarity; each question stored in the database has a corresponding answer;
[0028] The return module is used to return the answer corresponding to the target question.
[0029] In conjunction with the second aspect of the embodiment, in one possible implementation, the calculation module is configured to: calculate the similarity between the target vector of the question and the target vector of candidate questions in the database; wherein the candidate questions are determined by: generating an initial vector of the question according to a preset rule; and performing similarity matching between the initial vector and the initial vector of the questions stored in the database to obtain the candidate questions.
[0030] In conjunction with the second aspect of the embodiment, in one possible implementation, the database stores sub-databases corresponding to different intentions; the apparatus further includes:
[0031] The determination module is used to perform intent recognition on the question and determine the intent of the question;
[0032] The matching module is used to perform similarity matching between the initial vector and the initial vector of the question in the sub-database corresponding to the intent in the database.
[0033] Fifthly, embodiments of this application also provide an electronic device, including: a memory and a processor, the memory and the processor being connected; the memory being used to store a program; the processor calling the program stored in the memory to execute the method provided by any possible implementation of the first aspect embodiment and / or in combination with the first aspect embodiment; or to execute the method provided by any possible implementation of the second aspect embodiment and / or in combination with the second aspect embodiment.
[0034] Sixthly, embodiments of this application also provide a non-volatile computer-readable storage medium (hereinafter referred to as the storage medium) storing a computer program thereon, wherein the computer program is executed by a computer to perform the method provided by any possible implementation of the first aspect embodiment and / or in combination with the first aspect embodiment; or to perform the method provided by any possible implementation of the second aspect embodiment and / or in combination with the second aspect embodiment.
[0035] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing embodiments of this application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings. Attached Figure Description
[0036] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly described below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. The above and other objects, features, and advantages of this application will become clearer through the drawings. The same reference numerals indicate the same parts in all the drawings. The drawings are not intentionally drawn to scale to actual size; the focus is on illustrating the main points of this application.
[0037] Figure 1 This document shows a flowchart of a sentence vector generation method provided in an embodiment of this application;
[0038] Figure 2 This document shows a flowchart illustrating a matching method provided in an embodiment of this application.
[0039] Figure 3 This diagram shows a structural block diagram of a sentence vector generation device provided in an embodiment of this application;
[0040] Figure 4 This diagram shows a structural block diagram of a matching device provided in an embodiment of this application;
[0041] Figure 5 This diagram illustrates the structure of an electronic device provided in an embodiment of this application.
[0042] Icons: 100 - Electronic device; 110 - Processor; 120 - Memory; 400 - Sentence vector generation device; 410 - Preprocessing module; 420 - Generation module; 500 - Matching device; 510 - Generation module; 520 - Calculation module; 530 - Return module. Detailed Implementation
[0043] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0044] It should be noted that similar reference numerals and letters in the following figures denote similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, relational terms such as "first," "second," etc., used in the description of this application are merely used to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising," or any other variation thereof, is intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising a…" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0045] Furthermore, the deficiencies in existing sentence vector generation methods (the sentence vectors contain less effective information, resulting in lower accuracy of the results output by the intelligent question-answering system) are the results obtained by the applicant after practice and careful research. Therefore, the discovery process of the above-mentioned deficiencies and the solutions proposed by the embodiments of this application in the following text should be regarded as the applicant's contribution to this application.
[0046] To address the aforementioned issues, embodiments of this application provide a sentence vector generation method and apparatus, a matching method and apparatus, and a storage medium. The sentence vectors generated by this vector generation method can encompass more effective information, which is beneficial for improving the accuracy of the results output by the intelligent question-answering system.
[0047] This technology can be implemented using appropriate software, hardware, or a combination of both. The embodiments of this application are described in detail below. The matching method provided in this application will be described in the following section.
[0048] Please refer to Figure 1 This application provides a sentence vector generation method, which may include the following steps.
[0049] Step S110: Preprocess the received original sentence to obtain the sentence after filtering out stop words and the sentence after filtering out stop words and labeling with entity tags.
[0050] In this embodiment of the application, the obtained original sentence can be preprocessed to filter out stop words in the original sentence, and entity tags can be added to the sentence after filtering out stop words.
[0051] Among them, stop words refer to the function words contained in human natural language. These function words generally do not contain actual meanings and are mostly modal particles, such as "de", "ne", etc.
[0052] In some embodiments, a stop word library can be constructed according to actual needs, and the stop word library includes various words and / or phrases used to represent stop words.
[0053] During preprocessing, the original sentence input can be segmented first through a segmentation tool (such as Stanford, HanLP, Jieba, etc.) to obtain multiple words included in the original sentence.
[0054] For example, for the original sentence "How to apply for the Changshuang Ice Cream Package?", after segmentation, we get: "How, apply for, Changshuang Ice Cream Package, de, application, ne,?"
[0055] For the multiple words included in the original sentence, filter out the words belonging to the stop word library to obtain the sentence after filtering stop words.
[0056] For example, for "How, apply for, Changshuang Ice Cream Package, de, application, ne,?", after filtering stop words, we get: "How, apply for, Changshuang Ice Cream Package, application,?"
[0057] As for entity tags, they refer to the named entities of words and are used to qualitatively define the category to which the words belong.
[0058] In the embodiments of this application, the basic model (such as Hidden Markov Model (HMM), Conditional Random Field Model (CRF), etc.) can be pre-trained to obtain an entity tag recognition model.
[0059] Among them, the samples used to train the basic model are individual sentences, and each word in each sentence is manually labeled with its corresponding entity tag. Among them, when several words should form a phrase, the first word in these words is represented by the entity tag: B-X (X is used to represent a specific sub-tag); the last word in these words is represented by the entity tag: E-X; the other words in these words are represented by the entity tag: M-X. Among them, B represents "Begin", M represents "Intermediate", and E represents "End".
[0060] In the embodiments of this application, after obtaining the sentence after filtering stop words, it can be input into the entity tag recognition model, and the entity tags of each word included in the sentence after filtering stop words are output.
[0061] For example, when inputting the question "How to apply for the Refreshing Ice Cream Package?" into the entity tag recognition model, "Refreshing Ice Cream Package" is recognized as an entity, and the recognition result is: "Refreshing / B-UnicomPackage Refreshing / I-UnicomPackage Ice / I-UnicomPackage Ice / I-UnicomPackage Ice / I-UnicomPackage Set / I-UnicomPackage Meal / E-UnicomPackage". UnicomPackage is a sub-tag used to represent the package name.
[0062] For example, when inputting the question "How to recharge phone credit?" into the entity tag recognition model, "phone credit" is recognized as an entity, and the recognition result is: "phone / B-Business / E-Business". Business is a sub-tag used to represent the business.
[0063] After obtaining the entity tags of the words, the words including the entity tags are recombined in their original order to obtain the sentence after filtering out stop words and annotating the entity tags.
[0064] Step S120: Process the sentence after filtering out stop words to obtain the first sentence vector.
[0065] In this embodiment, the sentence after filtering out stop words can be processed to obtain a corresponding first sentence vector. The first sentence vector includes attribute information of the text included in the sentence after filtering out stop words.
[0066] The attribute information of text can include at least one of the following: character shape, pronunciation, and number of strokes.
[0067] Among them, the glyph information of characters mainly refers to the glyph information of Chinese characters.
[0068] In this embodiment, each Chinese character in a sentence can be converted into an ancient Chinese character (such as bronze inscriptions, seal script, traditional Chinese characters, etc.) based on the grid model. Then, the pixel features of the ancient Chinese characters can be extracted using CNN (Convolutional Neural Network) image processing technology to obtain word vectors. Finally, the word vectors can be combined to obtain the sentence vector.
[0069] The structure of Chinese characters can be further broken down into radicals and components. Many characters sharing the same radical may represent the same meaning and even have the same pronunciation. Radicals and components can be further broken down into linear combinations of horizontal, vertical, left-falling, right-falling, and turning strokes. The pronunciation and stroke information of characters are mainly used to represent the relationship between the pronunciation and structure of Chinese characters, as well as the linear combinations of their strokes.
[0070] In this embodiment of the application, a word vector can be formed based on the strokes and pinyin of each Chinese character in the sentence according to the "stroke-pinyin model", and the word vectors can be combined to obtain the sentence vector.
[0071] The samples used to train the stroke-phonetic model are sentences, and each word in the sentence is pre-labeled with its corresponding strokes and phonetic spelling.
[0072] In some implementations, when the attribute information includes character shape, pronunciation, and stroke count, the sentence after filtering stop words is processed to obtain a first sentence vector, which may include:
[0073] The first sub-vector is obtained by inputting the sentence after filtering out stop words into the grid-CNN model; the second sub-vector is obtained by inputting the sentence after filtering out stop words into the stroke-based pinyin model; the first sub-vector and the second sub-vector are weighted and fused to obtain the first sentence vector.
[0074] In this process, corresponding weights can be pre-set for the first sub-vector and the second sub-vector. For example, if the weight of the first sub-vector is 0.6 and the weight of the second sub-vector is 0.4, then when the first sub-vector and the second sub-vector are weighted and fused, the result is: first sub-vector × 0.6 + first sub-vector × 0.4 = first sub-vector.
[0075] Generally speaking, there are six main ways to generate Chinese characters: pictographs, ideographs, indicative characters, phonetic-semantic characters, and semantic extensions. The resulting first sentence vector contains the character shape, pronunciation, and stroke information for each character in the sentence after filtering out stop words, thus introducing the "six ways to generate Chinese characters" and making the final first sentence vector contain a wealth of information about the characters themselves.
[0076] Step S130: Process the sentence after filtering stop words and labeling entity tags, as well as the original sentence, to obtain the second sentence vector.
[0077] The second sentence vector includes information about the entity labels in the sentence after filtering out stop words and annotating the entity labels.
[0078] In some implementations, the original sentence can be input into a first ERNIE deep pre-trained model to obtain a third sub-vector. The sentence, after filtering out stop words and annotating entity tags, can be input into a second ERNIE deep pre-trained model to obtain a fourth sub-vector.
[0079] The third subvector and the fourth subvector are weighted and merged to obtain the second vector.
[0080] In this process, corresponding weights can be pre-set for the third and fourth sub-vectors. For example, if the weight of the third sub-vector is 0.2 and the weight of the fourth sub-vector is 0.8, then when the third and fourth sub-vectors are weighted and fused, the result is: third sub-vector × 0.2 + fourth sub-vector × 0.8 = second sub-vector.
[0081] As for the ERNIE deep pre-trained model, it is a relatively mature existing technology, so it will not be discussed further here.
[0082] After obtaining the first sentence vector and the second sentence vector, the target vector of the original sentence can be represented by the first sentence vector and the second sentence vector. That is, the target vector of the original sentence includes the first sentence vector and the second sentence vector.
[0083] As can be seen from the above process, the target vector obtained after processing the original sentence through the embodiments of this application contains the complete sentence information of the original sentence (i.e., the third sub-vector), the entity label information of the original sentence (i.e., the fourth sub-vector), and the generation method information of Chinese characters after removing stop words in the original sentence (the first sub-vector and / or the second sub-vector). Compared with the existing technology of extracting sentence vectors by using text feature extraction, the target sentence vector generated by this solution contains more information and is better able to express the original sentence.
[0084] In addition, please refer to Figure 2 This application also provides a matching method for use in an intelligent question-answering system, which may include the following steps:
[0085] Step S210: Process the obtained question according to the sentence vector generation method to generate the target vector of the question.
[0086] When users have a question, they can enter the question in the dialog box provided by the intelligent question-and-answer system through keyboard input or voice input, and submit it to the processing unit of the intelligent question-and-answer system.
[0087] After obtaining the question, the processing unit of the intelligent question answering system can generate a target vector corresponding to the question according to the sentence vector generation method described above, which is referred to here as target vector A.
[0088] As described above, the target vector consists of two vectors, namely the first sentence vector and the second sentence vector, which will be referred to as A1 and A2 respectively.
[0089] Step S220: Calculate the similarity between the target vector of the question and the target vector of the question in the database, and determine the target question based on the similarity.
[0090] Step S230: Return the answer corresponding to the target question.
[0091] It is worth noting that, in this embodiment of the application, a large number of questions are stored in the local or cloud database of the intelligent question-answering system, and each question has a corresponding answer. The questions and their corresponding answers are pre-stored in the database by the developers.
[0092] In this embodiment of the application, the target question can be determined from the questions in the database by calculating the similarity between the target vector A of the question and the target vector of each question in the database (referred to as target vector B).
[0093] Among them, the similarity between the target vector B of the target question and the target vector A of the question exceeds the first similarity threshold, for example, 80%.
[0094] Once the target question is obtained, the intelligent question-answering system can return the corresponding answer from the database for display on either the system's built-in or external display devices.
[0095] Of course, it is worth noting that when the similarity between the target vector B of multiple questions and the target vector A of the question all exceed the first similarity threshold, in one implementation, only the question with the highest first similarity threshold can be identified as the target question, and the answer corresponding to the target question can be returned.
[0096] In another implementation, all questions exceeding a first similarity threshold can be identified as target questions, and answers corresponding to all target questions can be returned.
[0097] Of course, for each problem, the corresponding target vector B is also generated in the same way as the sentence vectors mentioned above, including the first sentence vector and the second sentence vector, which are referred to as B1 and B2 respectively.
[0098] In some implementations, the target vector B corresponding to each question can be generated and persistently stored in the database during the initialization of the intelligent question-answering system; in other implementations, the target vector B corresponding to each question can also be generated in real time when the target vector B is needed.
[0099] As mentioned earlier, the target vector A of the question includes A1 and A2, and the target vector B of the problem includes B1 and B2. When calculating the similarity between the target vector A of the question and the target vector B of each problem, the similarity between A1 and B1 can be calculated to obtain the first similarity, and the similarity between A2 and B2 can be calculated to obtain the second similarity. Then, the first similarity and the second similarity are weighted and summed, and the weighted sum is used as the similarity between the target vector A of the question and the target vector B of the problem.
[0100] The weights of the first similarity and the second similarity are pre-configured by the developers. For example, in one embodiment, the weight of the first similarity is 0.5, and the weight of the second similarity is 0.5. Of course, the weights of the first similarity and the second similarity can be adjusted according to the actual situation.
[0101] To calculate the similarity between two vectors, we can use the following formula: Let's perform the calculation. Here, 'a' is one of the two vectors (e.g., A1), 'b' is the other vector (e.g., B1), ||a|| represents the magnitude of vector 'a', ||b|| represents the magnitude of vector 'b', and the value of cosθ is the similarity between vector 'a' and vector 'b'.
[0102] In addition, in some implementations, before performing step S220, the questions in the database can be filtered to select candidate questions.
[0103] In some implementations, candidate problems can be determined in the following ways.
[0104] Pre-store the initial vectors corresponding to each question in the database (generated by text feature extraction methods, such as word2vec, tfidf, or word2vec+tfidf).
[0105] After obtaining the question, an initial vector for the question is generated according to preset rules, such as text feature extraction methods. Then, the initial vector is matched with the initial vectors of questions in the database for similarity, and questions with a similarity higher than a second similarity threshold (e.g., 50%) are identified as candidate questions.
[0106] After obtaining the candidate questions, when performing step S220, the similarity between the target vector A of the question and the target vector B of the candidate questions can be calculated to reduce the amount of computation and improve processing efficiency.
[0107] Furthermore, in some implementations, the intelligent question-answering system can answer relevant questions in different fields or scenarios, and correspondingly, sub-databases corresponding to different intentions are stored in the database.
[0108] To reduce subsequent computation and improve processing efficiency, before performing similarity matching between the initial vector and the initial vector of the questions stored in the database, intent recognition can be performed on the user's input question to determine the intent of the user's input question.
[0109] Intent recognition mainly involves detecting keywords in the question or the sentence structure of the question.
[0110] Optionally, if a preset keyword is detected in the question, the intent of the question can be determined to be the intent corresponding to the matched preset keyword; if a preset sentence structure is detected in the question, the intent of the question can be determined to be the intent corresponding to the matched sentence structure.
[0111] For example, if the question "I want to apply for number portability" is matched with the preset keyword "number portability", then the intent of the question is the intent corresponding to "number portability" - "service application - number portability".
[0112] For example, if the question "How to handle number portability" is matched with the preset sentence structure "How to XXXX port number", then the intent of the question is the same as the intent of "How to XXXX port number" - "Business handling - number portability".
[0113] If the intent of the question cannot be matched by the above two methods, in some implementations, the sentence obtained after filtering stop words and labeling entities after preprocessing the question can be input into a multi-label classification model (Text-CNN) to output the intent corresponding to the entity labels included in the question.
[0114] Among them, multi-label classification models are relatively mature existing technologies, and will not be elaborated on here.
[0115] After obtaining the intent of the question, when performing similarity matching between the initial vector and the initial vector of the questions stored in the database, the initial vector of the question can be matched with the initial vector of the questions in the sub-database corresponding to the intent of the question, so as to reduce the number of questions that need to be matched.
[0116] When the intelligent question-answering system matches answers to user-input questions using the matching method provided in this application embodiment, the amount of information contained in the vector used for comparison is far greater than that of the vectors used in the prior art. Therefore, the vectors in this application embodiment can more accurately represent the meaning expressed by the sentence, thereby improving the accuracy of the results output by the intelligent question-answering system.
[0117] like Figure 3As shown, this application embodiment also provides a sentence vector generation device 400, which may include a preprocessing module 410 and a generation module 420.
[0118] The preprocessing module 410 is used to preprocess the received original sentence to obtain the sentence after filtering out stop words and the sentence after filtering out stop words and labeling with entity tags;
[0119] The generation module 420 is used to process the sentence after filtering stop words to obtain a first sentence vector. The first sentence vector includes attribute information of the characters included in the sentence after filtering stop words. The attribute information includes at least one of character shape, pronunciation, and stroke count.
[0120] The generation module 420 is further configured to process the sentence after filtering stop words and labeling entity tags, as well as the original sentence, to obtain a second sentence vector, wherein the second sentence vector includes the information of the entity tags;
[0121] The target vector of the original sentence includes the vector of the first sentence and the vector of the second sentence.
[0122] In one possible implementation, when the attribute information includes character shape, pronunciation, and stroke count, the generation module 420 is configured to: input the sentence after filtering stop words into the grid-CNN model and output a first sub-vector; input the sentence after filtering stop words into the stroke-phonetic model and output a second sub-vector; and perform weighted fusion of the first sub-vector and the second sub-vector to obtain the first sentence vector.
[0123] In one possible implementation, the generation module 420 is configured to: input the original sentence into a first ERNIE deep pre-trained model and output a third sub-vector; input the sentence after filtering stop words and labeling entity tags into a second ERNIE deep pre-trained model and output a fourth sub-vector; and perform weighted fusion of the third sub-vector and the fourth sub-vector to obtain the second sentence vector.
[0124] In one possible implementation, the preprocessing module 410 is configured to: segment the original sentence input using a word segmentation tool to obtain multiple words; filter words from the multiple words that belong to a preset stop word library to obtain a sentence with filtered stop words; input the sentence with filtered stop words into an entity tag recognition model to output entity tags for each word included in the sentence with filtered stop words; and reassemble the words including entity tags in their original order to obtain the sentence with filtered stop words and entity tags.
[0125] The sentence vector generation device 400 provided in this application embodiment has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0126] like Figure 4 As shown in the figure, this application embodiment also provides a matching device 500, which may include: a generation module 510, a calculation module 520 and a return module 530.
[0127] The generation module 510 is used to process the obtained question according to the sentence vector generation method to generate the target vector of the question;
[0128] The calculation module 520 is used to calculate the similarity between the target vector of the question and the target vector of the questions in the database, and to determine the target question based on the similarity; each question stored in the database has a corresponding answer;
[0129] The return module 530 is used to return the answer corresponding to the target question.
[0130] In one possible implementation, the computing module 520 is used for:
[0131] Calculate the similarity between the target vector of the question and the target vector of the candidate questions in the database;
[0132] The candidate problems are determined in the following manner:
[0133] Generate an initial vector for the question according to preset rules;
[0134] The initial vector is matched with the initial vector of the questions stored in the database to obtain the candidate questions.
[0135] In one possible implementation, the database stores sub-databases corresponding to different intentions; the apparatus further includes:
[0136] The determination module is used to perform intent recognition on the question and determine the intent of the question;
[0137] The matching module is used to perform similarity matching between the initial vector and the initial vector of the question in the sub-database corresponding to the intent in the database.
[0138] The matching device 500 provided in this application embodiment has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0139] Furthermore, embodiments of this application also provide a storage medium storing a computer program, which, when run by a computer, executes the steps included in the matching method described above.
[0140] In addition, please refer to Figure 5 This application also provides an electronic device 100 for implementing the matching method, apparatus and / or sentence vector generation method and apparatus of this application.
[0141] Optionally, the electronic device 100 may include, but is not limited to, personal computers (PCs), smartphones, tablets, mobile internet devices (MIDs), personal digital assistants, servers, etc. Among these, the server may include, but is not limited to, web servers, database servers, cloud servers, etc.
[0142] The electronic device 100 may include a processor 110 and a memory 120.
[0143] It should be noted that Figure 5 The components and structures of the electronic device 100 shown are merely exemplary and not limiting; the electronic device 100 may also have other components and structures as needed.
[0144] The processor 110, memory 120, and other components that may be present in the electronic device 100 are electrically connected to each other, directly or indirectly, to enable data transmission or interaction. For example, the processor 110, memory 120, and other components may be electrically connected to each other via one or more communication buses or signal lines.
[0145] The memory 120 is used to store programs, such as programs corresponding to the matching method or sentence vector generation method mentioned above, or matching devices or sentence vector generation devices mentioned above. Optionally, when the memory 120 stores a matching device or sentence vector generation device, the matching device or sentence vector generation device includes at least one software function module that can be stored in the memory 120 in the form of software or firmware.
[0146] Optionally, the software functional modules included in the matching device or sentence vector generation device may also be embedded in the operating system (OS) of the electronic device 100.
[0147] The processor 110 is used to execute executable modules stored in the memory 120, such as software functional modules or computer programs included in the matching device or sentence vector generation device. When the processor 110 receives an execution instruction, it can execute the computer program, for example, performing: preprocessing the received original sentence to obtain a sentence after filtering stop words and a sentence after filtering stop words and labeling entity tags; processing the sentence after filtering stop words to obtain a first sentence vector, the first sentence vector including attribute information of the characters included in the sentence after filtering stop words; the attribute information including at least one of character shape, pronunciation, and stroke count; processing the sentence after filtering stop words and labeling entity tags and the original sentence to obtain a second sentence vector, the second sentence vector including the information of the entity tags; the target vector of the original sentence includes the first sentence vector and the second sentence vector.
[0148] Alternatively, the following steps can be performed: process the obtained question according to the sentence vector generation method to generate the target vector of the question; calculate the similarity between the target vector of the question and the target vector of the questions in the database, and determine the target question based on the similarity; each question in the database has a corresponding answer; and return the answer corresponding to the target question.
[0149] Of course, the methods disclosed in any embodiment of this application can be applied to the processor 110, or implemented by the processor 110.
[0150] In summary, the sentence vector generation method and apparatus, matching method and apparatus, and storage medium proposed in this invention, after processing the original sentence through the embodiments of this application, produce a target vector that includes entity label information in the original sentence and attribute information of Chinese characters after removing stop words. Compared with the prior art method of extracting sentence vectors using text feature extraction, the target sentence vector generated by this solution contains more information and can fully express the meaning represented by the original sentence.
[0151] Furthermore, when the intelligent question-answering system matches answers to user-input questions using the matching method provided in this application embodiment, the amount of information contained in the vector used for comparison is far greater than that of the vectors used in the prior art. Therefore, the vectors in this application embodiment can more accurately represent the meaning expressed by the sentence, thereby improving the accuracy of the results output by the intelligent question-answering system.
[0152] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0153] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0154] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0155] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, laptop, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0156] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for generating sentence vectors, characterized in that, The method includes: The received original sentences are preprocessed to obtain sentences after filtering out stop words and sentences after filtering out stop words and labeling them with entity tags. The sentence after filtering out stop words is processed to obtain a first sentence vector, which includes attribute information of the characters in the sentence after filtering out stop words; the attribute information includes at least one of character shape, pronunciation, and stroke count. The sentence after filtering out stop words and labeling entity tags, as well as the original sentence, are processed to obtain a second sentence vector, which includes the information of the entity tags. The target vector of the original sentence includes the vector of the first sentence and the vector of the second sentence; When the attribute information includes character shape, pronunciation, and stroke count, the processing of the sentence after filtering stop words to obtain the first sentence vector includes: By inputting the sentence after filtering out stop words into the grid-CNN model, the first sub-vector is obtained as the output. The sentence after filtering out stop words is input into the stroke-phonetic model, and the second sub-vector is output. The stroke-phonetic model forms a word vector based on the strokes and pinyin of each Chinese character in the sentence, and the word vectors are combined to obtain the second sub-vector. The first sub-vector and the second sub-vector are weighted and fused to obtain the first sentence vector.
2. The method according to claim 1, characterized in that, The process of processing the sentence after filtering stop words and labeling entity tags, along with the original sentence, yields a second sentence vector, including: By inputting the original sentence into the first ERNIE deep pre-trained model, the third sub-vector is output. By inputting the sentence after filtering stop words and labeling entities into the second ERNIE deep pre-trained model, the fourth sub-vector is obtained as the output; The third sub-vector and the fourth sub-vector are weighted and fused to obtain the second sentence vector.
3. The method according to any one of claims 1 or 2, characterized in that, The preprocessing of the received original sentence includes: The original sentence input is segmented using a word segmentation tool to obtain multiple words. Filter the words that belong to the preset stop word library from the multiple words to obtain the sentence after filtering the stop words; The sentence after filtering out stop words is input into the entity label recognition model, and the entity labels of each word included in the sentence after filtering out stop words are output. The words, including the entity tags, are rearranged in their original order to obtain the sentence after filtering out stop words and annotating them with entity tags.
4. A matching method, characterized in that, The method includes: The sentence vector generation method according to any one of claims 1-3 is used to process the obtained question to generate the target vector of the question; Calculate the similarity between the target vector of the question and the target vector of the questions in the database, and determine the target question based on the similarity; each question stored in the database has a corresponding answer; Return the answer to the target question.
5. The method according to claim 4, characterized in that, The calculation of the similarity between the target vector of the question and the target vector of the questions in the database includes: Calculate the similarity between the target vector of the question and the target vector of the candidate questions in the database; The candidate problems are determined in the following manner: Generate an initial vector for the question according to preset rules; The initial vector is matched with the initial vector of the questions stored in the database to obtain the candidate questions.
6. The method according to claim 5, characterized in that, The database contains sub-databases corresponding to different intents; before performing similarity matching between the initial vector and the initial vectors of questions stored in the database, the method further includes: The intent of the question is determined by performing intent recognition. Accordingly, the step of performing similarity matching between the initial vector and the initial vector of the question stored in the database includes: The initial vector is matched with the initial vectors of questions in the sub-database corresponding to the intent in the database based on similarity.
7. A sentence vector generation device, characterized in that, The device includes: The preprocessing module is used to preprocess the received raw sentences to obtain sentences after filtering out stop words and sentences after filtering out stop words and tagging entity labels. The generation module is used to process the sentence after filtering stop words to obtain a first sentence vector. The first sentence vector includes attribute information of the characters included in the sentence after filtering stop words. The attribute information includes at least one of character shape, pronunciation, and stroke count. The generation module is further configured to process the sentence after filtering stop words and labeling entity tags, as well as the original sentence, to obtain a second sentence vector, wherein the second sentence vector includes the information of the entity tags; The target vector of the original sentence includes the vector of the first sentence and the vector of the second sentence; Where the attribute information includes character shape, pronunciation, and stroke count, the process of processing the sentence after filtering stop words to obtain the first sentence vector includes: By inputting the sentence after filtering out stop words into the grid-CNN model, the first sub-vector is obtained as the output. The sentence after filtering out stop words is input into the stroke-phonetic model, and the second sub-vector is output. The stroke-phonetic model forms a word vector based on the strokes and pinyin of each Chinese character in the sentence, and the word vectors are combined to obtain the second sub-vector. The first sub-vector and the second sub-vector are weighted and fused to obtain the first sentence vector.
8. A matching device, characterized in that, The device includes: A generation module is used to process the obtained question according to the sentence vector generation method according to any one of claims 1-3, and generate the target vector of the question; The calculation module is used to calculate the similarity between the target vector of the question and the target vector of the questions in the database, and to determine the target question based on the similarity; each question stored in the database has a corresponding answer; The return module is used to return the answer corresponding to the target question.
9. A storage medium, characterized in that, It stores a computer program, which is executed by a computer to perform the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Entity labeling method, intention identification method and corresponding device, and computer storage medium
CN109388793A
Multi-embedded named entity recognition method, device, equipment and storage medium
CN111597815A
Automatic question and answer processing method and device, computer equipment and storage medium
CN111858859A
Cited By
An entity-enhanced semantic similarity calculation method and system, an electronic device, and a storage medium
CN122366450A