Topic guidance method, device, electronic device and storage medium
By constructing a semantic correlation model, the problem of relying on knowledge graphs and entity recognition in topic guidance is solved, efficient and accurate topic guidance is achieved, and user experience is improved.
Patent Information
- Application Number
- CN202210295617.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-23
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-03-23
AI Technical Summary
In the prior art, topic guidance methods rely on the construction of knowledge graphs and entity recognition, resulting in high costs and semantic contradictions. The method based on word frequency has inaccurate relevance, affecting user experience.
A semantic correlation model is constructed, and the target corpus vector with the highest similarity to the dialogue vector is determined through topic corpus pool encoding, and a guided reply corpus is generated, which avoids the dependence of topic map construction and entity recognition, and improves the accuracy of correlation determination.
Reduces the labor cost of pre-tasks, improves the accuracy and user experience of topic guidance, and ensures that the generated replies are related to the user topic semantics.
Smart Images

Figure CN114997173B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a topic guidance method, device, electronic device and storage medium. Background Art
[0002] In related technologies, common topic guidance methods, on the one hand, introduce new knowledge based on the connections between entities. This requires building a comprehensive knowledge graph, then identifying the entities mentioned in the user's question. Then, using the relationships between entities as a divergence, topic-guided replies are generated based on the original entities. However, building a knowledge graph is costly, identifying entities in user questions is significantly limited by the algorithm's capabilities, and generating topic-guided replies based on the original entities can overlook the semantics of the user's question itself, leading to semantic contradictions. Summary of the Invention
[0003] In view of this, the purpose of this application is to propose a topic guiding method, device, electronic device and storage medium.
[0004] Based on the above objectives, in a first aspect, the present application provides a topic guiding method, comprising:
[0005] Build semantic relevance models;
[0006] Get the topic corpus and conversation vectors;
[0007] Encoding the topic corpus pool using the semantic relevance model to determine a corpus vector;
[0008] Determining a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors;
[0009] Determining whether a correlation between the dialogue vector and the target corpus vector is greater than or equal to a preset correlation threshold;
[0010] In response to the relevance between the dialogue vector and the target corpus vector being greater than or equal to the preset relevance threshold, a guiding reply corpus is generated according to the target corpus vector to guide the topic.
[0011] In a possible implementation, constructing the semantic relevance model further includes:
[0012] Construct information pairs of topics and corpus;
[0013] A semantic relevance model is constructed based on the information pairs.
[0014] In a possible implementation, constructing the information pair of topic and corpus includes:
[0015] Acquire question and answer text data; wherein the question and answer text data includes: a question text, an answer text, and an evidence text used to prove the matching degree between the question text and the answer text;
[0016] Dividing the question-and-answer text data into a plurality of text paragraphs according to a preset division rule;
[0017] Using an open source search framework, determining a target text paragraph from the plurality of text paragraphs that has the highest relevance to the evidence text and meets a preset number;
[0018] The information pair is constructed according to the question-answer text data and the target text paragraph.
[0019] In a possible implementation, dividing the question-and-answer text data into a plurality of text paragraphs according to a preset division rule includes:
[0020] The question-and-answer text is divided into a plurality of text paragraphs by a preset number of characters. In a possible implementation, the question-and-answer text is divided into a plurality of text paragraphs by a preset number of bytes, including:
[0021] The question and answer text is divided starting from the first character in units of a preset number of characters. If the last character of the initial text paragraph obtained by division is not the ending character, the next character is obtained and added to the initial text paragraph until the ending character is obtained, and the ending character is added to the initial text paragraph to obtain a text paragraph.
[0022] In a possible implementation, the corpus includes: positive sample corpus and negative sample corpus;
[0023] The step of constructing the information pair according to the question-answer text data and the target text paragraph includes:
[0024] determining the topic according to the question text;
[0025] Determining the positive sample corpus according to the target text paragraph containing the answer text in the target text paragraph;
[0026] Determining the negative sample corpus according to the target text paragraph that does not contain the answer text in the target text paragraph;
[0027] The topic and the positive sample corpus are paired with the negative sample corpus to determine the information pair.
[0028] In a possible implementation, constructing a semantic relevance model based on the information pair includes:
[0029] Obtain a basic model, a first word vector and a first position vector of the topic, and a second word vector and a second position vector of the corpus;
[0030] Encoding the first word vector and the first position vector using the base model to determine a topic paragraph vector;
[0031] Encoding the second word vector and the second position vector using the base model to determine a corpus paragraph vector;
[0032] Determining the similarity between the topic and the corpus based on the inner product of the topic paragraph vector and the expected paragraph vector;
[0033] In response to the similarity satisfying the target value, the semantic relevance model is constructed according to the information pair based on the double-tower model.
[0034] In a possible implementation, obtaining the conversation vector further includes:
[0035] In response to receiving the user topic, obtaining the user's historical conversation record;
[0036] The user topic and the historical conversation record are encoded using the semantic relevance model to determine the conversation vector.
[0037] In a possible implementation, determining the target corpus vector having the highest similarity to the dialogue vector from the corpus vectors further includes:
[0038] Storing the corpus vectors in a search tool to create an online index;
[0039] The conversation vector is input into the search tool to perform the online indexing to determine the target corpus vector having the highest similarity to the conversation vector.
[0040] In a possible implementation, the method further includes:
[0041] In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, it is determined not to guide the topic.
[0042] In a possible implementation, the method further includes:
[0043] In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, guiding the topic according to preset guiding reply corpus.
[0044] In a second aspect, the present application provides a topic guiding device, comprising:
[0045] A building module, configured to build a semantic relevance model;
[0046] An acquisition module is configured to acquire a topic corpus and a conversation vector;
[0047] an encoding module configured to encode the topic corpus pool using the semantic relevance model to determine a corpus vector;
[0048] A first determining module is configured to determine a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors;
[0049] A second determination module is configured to determine whether the relevance between the dialogue vector and the target corpus vector is greater than or equal to a preset relevance threshold;
[0050] The guiding module is configured to generate a guiding reply corpus according to the target corpus vector to guide the topic in response to the relevance between the dialogue vector and the target corpus vector being greater than or equal to the preset relevance threshold.
[0051] In a third aspect, the present application provides 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 topic guiding method as described in the first aspect is implemented.
[0052] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the topic guiding method as described in the first aspect.
[0053] As can be seen from the foregoing, the present application provides a topic guidance method, apparatus, electronic device, and storage medium that constructs a semantic relevance model and uses it to encode a pool of acquired topic corpora. This avoids the problems of relying on topic graph construction and entity word recognition in related technologies, reduces the labor cost of pre-tasks, and further improves the accuracy of relevance determination compared to relevance determination based on word frequency. Furthermore, a target corpus vector with the highest similarity to the conversation vector is determined from the corpus vectors. By determining whether the correlation between the conversation vector and the target corpus vector is greater than or equal to a preset relevance threshold, a guiding reply corpus is generated based on the target corpus vector if the correlation between the conversation vector and the target corpus vector is greater than or equal to the preset relevance threshold. This method does not rely on the capabilities of the recognition algorithm. Furthermore, the target corpus vector obtained through encoding with the semantic relevance model is semantically relevant to the topic, enabling the generation of guiding reply corpus based on a correct understanding of the user's topic semantics, thereby guiding the user's topic. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the technical solutions in this application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are merely embodiments of this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0055] Figure 1 A schematic diagram illustrating an exemplary flow chart of a topic guiding method provided in an embodiment of the present application is shown.
[0056] Figure 2 A schematic diagram showing information pairs of topics and corpora according to an embodiment of the present application is shown.
[0057] Figure 3 A schematic diagram of the semantic relevance model structure in an embodiment of the present application is shown.
[0058] Figure 4 A schematic diagram of a guided reply generation process according to an embodiment of the present application is shown.
[0059] Figure 5 A schematic diagram showing a specific topic guidance example according to an embodiment of the present application.
[0060] Figure 6 A schematic diagram of an exemplary structure of a topic guiding device provided in an embodiment of the present application is shown.
[0061] Figure 7 A schematic diagram of an exemplary structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0062] In order to make the objectives, technical solutions and advantages of this application more clear, this application is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0063] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should have the usual meanings understood by people with ordinary skills in the field to which this application belongs. The "first", "second" and similar words used in the embodiments of the present application do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0064] As mentioned in the background section, in casual conversations, "proactive guidance" is a key metric for evaluating whether an AI (artificial intelligence) possesses human-like conversational skills. Proactive guidance refers to the ability to introduce new topics, knowledge, perspectives, content, and emotional expressions in responses. The rapid development of large-scale pre-trained language models in recent years has made AI responses increasingly fluent and reasonable, but pre-trained AI still lacks the ability to proactively control the topic. For example, when a user says, "I read Romance of the Three Kingdoms today," an AI without relevant knowledge might respond with "What was it about?", while an AI capable of proactive guidance might reply, "My favorite part was the Battle of Red Cliffs." Users expect bots to offer insightful conversations, meaning they possess specialized knowledge in a specific field and can promptly incorporate this knowledge into the conversation, enriching the conversation.
[0065] In related technologies, most current casual conversation systems use generation methods based on large-scale language models (such as GPT-2). Adding control text before the conversation allows the model to focus on this control information during generation and generate responses based on the provided information. Therefore, existing topic guidance methods primarily follow this approach: analyze the current conversation, retrieve context-relevant "topic knowledge," and use this "topic knowledge" as control information for further model generation.
[0066] One related technique first creates a topic entity graph, establishing triples of entities and relationships. For example, in the sentences "Cao Cao," "participated in," and "The Battle of Red Cliffs," the entity is "Cao Cao" and the relationship is participating in the "Battle of Red Cliffs." For user questions within the relevant topic domain, NER (also known as named entity recognition) technology is used to find the entity words, such as "Cao Cao," and then link them to other related entities, such as "The Battle of Red Cliffs," through the topic graph. The relevant description of the "Battle of Red Cliffs" is then used as control information for the next step, ensuring that the reply contains relevant new knowledge. In other words, generating guided replies for a given topic in related techniques requires building a graph and defining a search strategy.
[0067] The applicant found through research that this solution introduces new knowledge based on the connection between entities. First, it is necessary to establish a complete knowledge graph, and the establishment of a topic graph requires high labor costs. Secondly, it is necessary to identify the entities mentioned in the user's question. This step is often limited by the capabilities of the NER (named entity recognition) algorithm. In spoken language scenarios, an entity often has multiple aliases, such as "Zhuge Liang", which can also be called "Kong Ming" or "Wu Hou". If the entity information in the knowledge base is incomplete, the entity is often not recognized, and further controlled retrieval cannot be performed. Finally, through the relationship between entities as a divergence, it can only be based on the original entity, thus ignoring the semantics of the sentence itself. For example, if the user inputs "Cao Cao is also a hero", if the defeat of the "Battle of Chibi" is associated as control information, the generated result may be semantically contradictory.
[0068] Another related technique first constructs a corpus of topic data. Using a word frequency search method, the data with the highest overlap with the user's question is found. The entire sentence serves as control information for the next step. The open source search tool (Elasticsearch) uses an algorithm to evaluate the relevance between search terms and documents.
[0069] Through research, the applicant discovered that although this solution does not require the construction of a large number of graphs, it only needs to collect corpus as data and does not rely on entities, thus avoiding some of the shortcomings of the solution in the first related technology. However, the keyword-based retrieval algorithm only uses word frequency co-occurrence to determine relevance, which can lead to the following two situations: the retrieved corpus has a high degree of word repetition, but the actual relevance is not high, such as "I like to eat braised pork" retrieved "Su Dongpo likes to eat braised pork"; and some corpus with high actual relevance has a low degree of word repetition and therefore cannot be retrieved. For example, if a user says "I respect Zhuge Liang very much", the key corpus in the corpus pool "Zhuge Kongming was the prime minister of Shu Han, who devoted his life to his work and died without regrets" has a word repetition of only the two words "Zhuge", so the calculated relevance score is also low, resulting in the problem that the generated topic-guided replies are less relevant to the user's topic, which reduces the user experience.
[0070] For this reason, the present application provides a topic guidance method, device, electronic device, and storage medium that construct a semantic relevance model and use it to encode the acquired topic corpus. This avoids the problems of relying on topic graph construction and entity word recognition in related technologies, reduces the labor cost of pre-tasks, and further improves the accuracy of relevance determination compared to relevance determination based on word frequency. Furthermore, a target corpus vector with the highest similarity to the conversation vector is determined from the corpus vectors. By determining whether the correlation between the conversation vector and the target corpus vector is greater than or equal to a preset relevance threshold, a guiding reply corpus is generated based on the target corpus vector if the correlation between the conversation vector and the target corpus vector is greater than or equal to the preset relevance threshold. This method does not rely on the capabilities of the recognition algorithm. Furthermore, the target corpus vector obtained through encoding with the semantic relevance model is semantically relevant to the topic, enabling the generation of guiding reply corpus based on a correct understanding of the user's topic semantics, thereby guiding the user's topic.
[0071] The following is a detailed description of the topic guidance method provided in the embodiments of the present application through specific examples.
[0072] Figure 1 A schematic diagram illustrating an exemplary flow chart of a topic guiding method provided in an embodiment of the present application is shown.
[0073] refer to Figure 1 The topic guiding method provided in the embodiment of the present application specifically includes the following steps:
[0074] S102: Build a semantic relevance model.
[0075] S104: Obtain the topic corpus and conversation vector.
[0076] S106: Encode the topic corpus pool using the semantic relevance model to determine a corpus vector.
[0077] S108: Determine a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors.
[0078] S110: Determine whether the relevance between the dialogue vector and the target corpus vector is not less than a preset relevance threshold.
[0079] S112: In response to the relevance between the dialogue vector and the target corpus vector being no less than the preset relevance threshold, generating a guiding reply corpus according to the target corpus vector to guide the topic.
[0080] Regarding step S102, in order to avoid the problem of low relevance between topic-guided replies and user topics in related technologies, a semantic relevance model may be constructed.
[0081] In some embodiments, constructing a semantic relevance model may include the following steps: constructing information pairs of topics and corpora; and constructing a semantic relevance model based on the information pairs. Specifically, based on topic-guided usage scenarios, training corpora for an open-domain semantic relevance model, i.e., information pairs of topics and corpora, may be constructed.
[0082] It should be noted that to ensure the generalizability and universality of topic-guided responses when responding to user topics, the corpus in the information pair cannot be limited to a single topic. For example, only corpus related to the "Three Kingdoms" topic is required. This is because once the user's topic involves other topics, such as food, using topic-guided responses determined based on the "Three Kingdoms" topic corpus to guide the user will lead to semantic contradictions, making it impossible for the user and the AI to discuss the same topic, resulting in a poor user experience. Therefore, in order to obtain a wider range of topic corpora, the open domain Wikipedia Chinese data can be selected as the corpus pool (also called context) in the information pair.
[0083] Furthermore, to ensure semantic relevance between user-entered topics and the corpus in the corpus, semantically related user topic-to-corpus information pairs, also known as utterance-context pairs, can be constructed. Furthermore, the process of constructing information pairs cannot rely on word frequency contributions, as this would reduce the semantic relevance model to a simple word frequency statistical model. As a countermeasure, the relevance of question-and-answer data can be used to construct information pairs.
[0084] In some embodiments, to construct information pairs of topics and corpora, question-answer text data can be first obtained; wherein, the question-answer text data includes: question text, answer text and evidence text for proving the matching degree between the question text and the answer text. Specifically, in the field of question-answering, the general standard data set contains a large number of question-answer pairs built based on Wikipedia, that is, QA pairs (question-answer pairs), such as WebQA (a question-answering data set). Taking the Chinese version as an example, it contains a total of 36,000 question-answer text data, and each question-answer text data contains three parts: query, evidence, and answer, wherein query is the question text asked by the user, answer is the answer corresponding to the question asked by the user, that is, answer text, and evidence is the Wikipedia text used to prove that the answer text can answer the question text, that is, evidence text for proving the matching degree between the question text and the answer text.
[0085] Referring to Table 1, further, the Q&A text data can be divided into multiple text paragraphs according to a preset division rule. Specifically, the Q&A text data can be segmented every byte corresponding to the preset interval number m to determine multiple text paragraphs. For example, all the Q&A text data of Wikipedia can be downloaded and segmented every 100 bytes to obtain a text paragraph. According to the Q&A text data in Wikipedia, a total of 4,200,000 text paragraphs can be segmented.
[0086] Table 1 Example of Text Paragraph
[0087]
[0088] It should be noted that when it is determined that the m-th byte in the current text paragraph is not the end of a sentence, for example, the m-th byte is a non-ending field. The non-ending field can be a non-ending punctuation mark, such as a quotation mark, a colon, a comma or a dash, etc. It can also be a certain character. For example, in the sentence "Ganning reported an emergency to Zhou Yu, and Zhou Yu used Lu Meng's plan", the m-th byte happens to be "之". Obviously, at this time, "之" is not the end of the sentence. If the text paragraph is divided at the byte of "之", two text paragraphs with a doubtful end and a doubtful start will be obtained.
[0089] To avoid this kind of text paragraph division that will cause semantic contradictions, after it is determined that the m-th byte in the current text paragraph is a non-ending field, the Q&A text data can be segmented according to the next ending punctuation mark, so as to re-determine the current text paragraph. For example, in the same sentence "Ganning reported an emergency to Zhou Yu, and Zhou Yu used Lu Meng's plan", the m-th byte happens to be "之". Since "之" is not the end of the sentence, the Q&A text data will be segmented according to the next ending punctuation mark, that is, ",". The ending punctuation mark can be a comma, a period, an exclamation mark, a question mark or an ellipsis, etc.
[0090] Furthermore, after dividing the Q&A text data into multiple text paragraphs, an open-source search framework can be used to determine the target text paragraphs with the highest relevance to the evidence text and meeting the preset quantity in multiple text paragraphs. Specifically, for each WebQA data, the question text query is used as the utterance in the information pair, and the evidence text evidence can be used as the seed of the positive sample. Using the open-source search framework Elasticsearch, multiple target paragraphs most relevant to the evidence text evidence can be found in 4,200,000 text paragraphs.
[0091] It should be noted that the process of determining the multiple target paragraphs most relevant to the evidence text can include the following steps: first, based on the Elasticsearch open source search framework, calculate the relevance score of the evidence text and the remaining text paragraphs, and return the text paragraph with the highest score. The relevance score in Elasticsearch can be based on the BM25 algorithm, and the general formula can be written as
[0092]
[0093] Among them, W i represents the weight of the i-th text paragraph, q i represents the i-th evidence text, Q represents the question text, R() represents the relevance score, and d represents the remaining text paragraphs.
[0094] In some embodiments, the preset number is generally 1 to 5, and only one positive and negative sample is retained for each evidence text for training the semantic relevance model.
[0095] Figure 2 A schematic diagram showing information pairs of topics and corpora according to an embodiment of the present application is shown.
[0096] refer to Figure 2 It should be noted that in order to eliminate the bias introduced by the frequency-based search of open-source search frameworks and ensure that the target text paragraphs found are truly relevant, after determining the target text paragraphs, information pairs can be constructed based on the question-answer text data and the target text paragraphs. Specifically, the corpus can include positive sample corpus and negative sample corpus. The topic can be determined based on the question text, and the positive sample corpus can be further determined based on the text paragraphs containing the answer text. The negative sample corpus can then be determined based on the target text paragraphs that do not contain the answer text. The topic and the positive sample corpus are then paired with the negative sample corpus to determine the information pair.
[0097] Specifically, only target text paragraphs containing answer text are selected as positive sample corpus, and target text paragraphs with high relevance but not containing answer text are selected as negative sample corpus. Figure 2Suppose the question text is "When did Arbor Day begin?" The question text is used as the user topic input, the answer text is "1979," and the evidence text is "This year is the 33rd Arbor Day. my country began having Arbor Day in 1979. Counting 1979, this year is exactly the 33rd Arbor Day." Using the answer text as the filtering condition, the positive sample corpus containing the answer text is "National Mandatory Tree Planting Campaign: The National Mandatory Tree Planting Campaign refers to a policy enacted in the 1980s to promote tree planting and increase green coverage. On February 23, 1979, it was announced that March 12th of each year would be designated Arbor Day." The negative sample corpus with a high relevance but not containing the answer text is "Arbor Day: The state adopted Morton's proposal and designated the third Wednesday of April as Arbor Day. In 1932, the world's first Arbor Day stamp was issued, depicting two children planting trees." By analyzing the correlation of question and answer text data, we can construct the information pairs required for open domain semantic search.
[0098] In some embodiments, constructing a semantic relevance model based on the information pairs constructed in the above steps can further include the following steps: first, obtaining a basic model, the first word vector and the first position vector of the topic, and the second word vector and the second position vector of the corpus; then using the basic model to encode the first word vector and the first position vector, as well as the second word vector and the second position vector, respectively, to determine the topic paragraph vector and the corpus paragraph vector; then determining the similarity based on the inner product of the topic paragraph vector and the expected paragraph vector; when the similarity meets the target value, a semantic relevance model can be constructed based on the information pair based on the double-tower model.
[0099] Figure 3 A schematic diagram of the semantic relevance model structure in an embodiment of the present application is shown.
[0100] refer to Figure 3It should be noted that the semantic relevance model can adopt a dual-tower model structure. Each tower uses the pre-trained language model BERT-WWM as its base model. BERT-WWM is fully pre-trained and has advantages over typical deep models in terms of initial semantics. One tower is the utterance encoder, also known as the user-topic encoder, which takes as input topic-related word embeddings and position embeddings; the other tower is the context encoder, also known as the corpus encoder, which takes as input corpus-related word embeddings and position embeddings. The outputs of the two towers are applied to a similarity function to determine semantic relevance. These two towers are BERT-WWM models with unshared parameters. The semantic relevance model is a pre-trained model consisting of 12 transformer model encoders connected end-to-end. The detailed structure of the transformer model encoder includes, from top to bottom, a multi-head attention layer, a normalization layer, a fully connected layer, and a normalization layer.
[0101] Among them, the input of the semantic relevance model can be the word vector and position vector of each word, and the output layer takes the vector of the 0th word as the encoding of the entire text paragraph. Therefore, it is necessary to obtain the first word vector and the first position vector of the topic, as well as the second word vector and the second position vector of the corpus. Furthermore, the first word vector and the first position vector are encoded using the basic model BERT-WWM model to determine the topic paragraph vector, and the second word vector and the second position vector are encoded using the basic model BERT-WWM model to determine the corpus paragraph vector. The inner product of the topic paragraph vector and the corpus paragraph vector can be calculated in the loss layer as the similarity between the topic and the corpus. For the similarity between the two, there is a corresponding target value. When the similarity meets the target value, the construction of the semantic relevance model can be completed based on the dual-tower model and the information pair.
[0102] In some embodiments, to enhance generalization, in-batch negative sampling is used, using data from other topics within the same batch as negative samples. Because Wikipedia topics are mostly encyclopedic questions, which differ from the grammar of actual casual conversation, a two-stage approach is employed for training: first, training with constructed open-domain information pairs until convergence, then selecting approximately 100 online user logs to construct utterance-context pairs for fine-tuning.
[0103] Regarding step S104, the topic corpus pool is very extensive. Compared with the structured solution of knowledge graph, this solution does not restrict the form of corpus. Therefore, the knowledge corpus of each topic can be collected from multiple channels for online real-time retrieval. For topics with entity lists (such as historical figures), you can search through Baidu Encyclopedia, for example, to obtain knowledge introductions of the entities; for topics without entity lists, you can use user answers on Baidu Zhidao, for example, or obtain corpus from designated topic websites (such as Food Network). Ultimately, each corpus is in the form of natural language text, which facilitates rapid and low-cost expansion.
[0104] When obtaining a corpus pool of food-related topics, for example, if the title is a recipe, corpus such as hot dry noodles, lamb or hot winter fruit can be obtained to expand the content of the topic corpus pool.
[0105] The sample code section is as follows:
[0106]
[0107] With regard to obtaining a conversation vector, in some embodiments, it is possible to receive an online user request, receive a user topic in the user request, obtain the user's historical conversation record, concatenate the user's historical conversation record and the currently input user topic, and then input the concatenated content into a semantic relevance model. The topic encoder in the semantic relevance model is used for real-time calculation to encode the user topic and the historical conversation record, thereby determining the conversation vector.
[0108] Figure 4 A schematic diagram of a guided reply generation process according to an embodiment of the present application is shown.
[0109] refer to Figure 4 Regarding step S106, after determining the conversation vector, the corpus encoder in the semantic relevance model can be used to pre-encode the corpus in each topic corpus pool to determine the corpus vector. The corpus vector is then stored in a vector retrieval tool, thereby establishing an online index. Specifically, the user's historical conversations and current conversations can be input into the topic encoder, the topic corpus can be input into the corpus encoder, the corpus vectors can be stored in the vector retrieval tool, and an online index can be established. A similarity search can then be performed using a similarity function to calculate and find the corpus vector with the highest similarity that meets a threshold. The generation of the reply statement is guided by this corpus vector. If the corpus vector with the highest similarity does not meet the threshold, it is placed in the topic corpus pool for use as corpus and does not directly participate in guiding the generation of the reply.
[0110] Furthermore, the conversation vector can be put into a vector search tool for retrieval, online indexing can be performed, and the target corpus vector with the highest similarity can be calculated.
[0111] In some embodiments, the vector search tool may be the faiss vector search tool, which can be used for online search. The faiss index can control the search of massive vectors in milliseconds, and supports real-time addition and deletion of indexes, which can flexibly control the scope of the search corpus.
[0112] For steps S108-S112, it can be determined whether the correlation between the conversation vector and the target corpus vector is no less than a preset correlation threshold. The correlation threshold can be measured based on the inner product of the conversation vector and the target corpus vector. If the correlation between the conversation vector and the target corpus vector is no less than the preset correlation threshold, a guided response corpus can be generated based on the target corpus vector. The guided response corpus can then be output to the user by artificial intelligence to guide the user's topic.
[0113] In some embodiments, if the correlation between the conversation vector and the target corpus vector is less than a preset correlation threshold, user topic guidance may not be performed. For example, if the correlation of all corpora in the topic pool does not reach the preset correlation threshold, it indicates that there is no relevant topic corpus at the moment, and it is determined that topic guidance is not necessary for the current conversation content.
[0114] In some embodiments, if the correlation between the response and the conversation vector and the target corpus vector is less than a preset correlation threshold, the user's topic can be guided based on a preset guiding reply corpus. Specifically, when there is no target corpus vector available, the current conversation history can be focused on, and the preset guiding reply corpus can be added before the user's historical conversation. During decoding, the attention layer will also include the preset guiding reply corpus in the attention matrix calculation, thereby guiding the user's topic based on the preset guiding reply corpus.
[0115] Figure 5 A schematic diagram showing a specific topic guidance example according to an embodiment of the present application.
[0116] refer to Figure 5As a specific example, when a user enters the topic "Do you know Liu Bei?", the semantic relevance model can be used to search the topic corpus, identify the conversation entity as "Liu Bei," and extract relevant information. For example, "Liu Bei is a figure from the Three Kingdoms period who conquered the two Sichuan provinces, founded Shu Han, and fought against Cao Cao." The answer text is "Liu Bei," and the found topic corpus contains the answer text. This allows the AI to output the conversation "Liu Bei founded Shu Han, how capable was he?" This answer perfectly matches the user's interests, and the user conversation is "I love Shu Han the most!" The semantic relevance model is then used to search the topic corpus. Based on the entity "Shu Han," the AI can identify relevant topic corpus. For example, "Zhuge Liang, courtesy name Kongming, nickname Wulong, was the Prime Minister of Shu Han during the Three Kingdoms period, an outstanding politician, military strategist, essayist, and calligrapher." The answer text is "Shu Han," and the found topic corpus contains the answer text. This allows the AI to output the conversation "Zhuge Liang, Prime Minister of Shu Han, had excellent calligraphy and excellent prose." This guides the user's conversation and improves the user experience.
[0117] As can be seen from the foregoing, the present application provides a topic guidance method, apparatus, electronic device, and storage medium that constructs a semantic relevance model and uses it to encode a pool of acquired topic corpora. This avoids the problems of relying on topic graph construction and entity word recognition in related technologies, reduces the labor cost of pre-tasks, and further improves the accuracy of relevance determination compared to relevance determination based on word frequency. Furthermore, a target corpus vector with the highest similarity to the conversation vector is determined from the corpus vectors. By determining whether the correlation between the conversation vector and the target corpus vector is greater than or equal to a preset relevance threshold, a guiding reply corpus is generated based on the target corpus vector if the correlation between the conversation vector and the target corpus vector is greater than or equal to the preset relevance threshold. This method does not rely on the capabilities of the recognition algorithm. Furthermore, the target corpus vector obtained through encoding with the semantic relevance model is semantically relevant to the topic, enabling the generation of guiding reply corpus based on a correct understanding of the user's topic semantics, thereby guiding the user's topic.
[0118] It should be noted that the method of the embodiment of the present application can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied in a distributed scenario and performed by multiple devices working together. In such a distributed scenario, one of the multiple devices may only perform one or more steps of the method of the embodiment of the present application, and the multiple devices will interact with each other to complete the method.
[0119] It should be noted that the above description is limited to some embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in an order different from that described in the above embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0120] Figure 6 A schematic diagram of an exemplary structure of a topic guiding device provided in an embodiment of the present application is shown.
[0121] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a topic guiding device.
[0122] refer to Figure 6 The topic guiding device includes: a construction module, an acquisition module, an encoding module, a first determination module, a second determination module and a guiding module; wherein,
[0123] A building module, configured to build a semantic relevance model;
[0124] An acquisition module is configured to acquire a topic corpus and a conversation vector;
[0125] an encoding module configured to encode the topic corpus pool using the semantic relevance model to determine a corpus vector;
[0126] A first determining module is configured to determine a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors;
[0127] A second determination module is configured to determine whether the relevance between the dialogue vector and the target corpus vector is greater than or equal to a preset relevance threshold;
[0128] The guiding module is configured to generate a guiding reply corpus according to the target corpus vector to guide the topic in response to the relevance between the dialogue vector and the target corpus vector being greater than or equal to the preset relevance threshold.
[0129] In a possible implementation, the building block is further configured to:
[0130] Construct information pairs of topics and corpus;
[0131] A semantic relevance model is constructed based on the information pairs.
[0132] In a possible implementation, the building block is further configured to:
[0133] Acquire question and answer text data; wherein the question and answer text data includes: a question text, an answer text, and an evidence text used to prove the matching degree between the question text and the answer text;
[0134] Dividing the question-and-answer text data into a plurality of text paragraphs according to a preset division rule;
[0135] Using an open source search framework, determining a target text paragraph from the plurality of text paragraphs that has the highest relevance to the evidence text and meets a preset number;
[0136] The information pair is constructed according to the question-answer text data and the target text paragraph.
[0137] In a possible implementation, the building block is further configured to:
[0138] The question and answer text is divided into units of a preset number of characters to obtain a plurality of text paragraphs.
[0139] In a possible implementation, the building block is further configured to:
[0140] The question and answer text is divided starting from the first character in units of a preset number of characters. If the last character of the initial text paragraph obtained by division is not the ending character, the next character is obtained and added to the initial text paragraph until the ending character is obtained, and the ending character is added to the initial text paragraph to obtain a text paragraph.
[0141] In a possible implementation, the corpus includes: positive sample corpus and negative sample corpus;
[0142] The building blocks are further configured to:
[0143] determining the topic according to the question text;
[0144] Determining the positive sample corpus according to the target text paragraph containing the answer text in the target text paragraph;
[0145] Determining the negative sample corpus according to the target text paragraph that does not contain the answer text in the target text paragraph;
[0146] The topic and the positive sample corpus are paired with the negative sample corpus to determine the information pair.
[0147] In a possible implementation, the building block is further configured to:
[0148] Obtain a basic model, a first word vector and a first position vector of the topic, and a second word vector and a second position vector of the corpus;
[0149] Encoding the first word vector and the first position vector using the base model to determine a topic paragraph vector;
[0150] Encoding the second word vector and the second position vector using the base model to determine a corpus paragraph vector;
[0151] Determining the similarity between the topic and the corpus based on the inner product of the topic paragraph vector and the expected paragraph vector;
[0152] In response to the similarity satisfying the target value, the semantic relevance model is constructed according to the information pair based on the double-tower model.
[0153] In a possible implementation, the acquisition module is further configured to:
[0154] In response to receiving the user topic, obtaining the user's historical conversation record;
[0155] The user topic and the historical conversation record are encoded using the semantic relevance model to determine the conversation vector.
[0156] In one possible implementation,
[0157] The first determining module is further configured to:
[0158] Storing the corpus vectors in a search tool to create an online index;
[0159] The conversation vector is input into the search tool to perform the online indexing to determine the target corpus vector having the highest similarity to the conversation vector.
[0160] In a possible implementation, the guiding module is further configured to:
[0161] In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, it is determined not to guide the topic.
[0162] In a possible implementation, the guiding module is further configured to:
[0163] In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, guiding the topic according to preset guiding reply corpus.
[0164] For the convenience of description, the above devices are described as being divided into various modules according to their functions. Of course, when implementing this application, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0165] The device of the above embodiment is used to implement the corresponding topic guidance method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0166] Figure 7 A schematic diagram of an exemplary structure of an electronic device provided in an embodiment of the present application is shown.
[0167] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the program, the topic guidance method described in any of the above embodiments is implemented. Figure 7 7 shows a more specific hardware structure diagram of an electronic device provided in this embodiment. The device may include: a processor 710, a memory 720, an input / output interface 730, a communication interface 740, and a bus 750. The processor 710, the memory 720, the input / output interface 730, and the communication interface 740 are connected to each other within the device via the bus 750.
[0168] The processor 710 can be implemented using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0169] The memory 720 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage devices, dynamic storage devices, etc. The memory 720 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 720 and called and executed by the processor 710.
[0170] The input / output interface 730 is used to connect an input / output module to implement information input and output. The input / output module can be configured as a component in the device (not shown in the figure) or can be externally connected to the device to provide corresponding functions. Input devices may include a keyboard, mouse, touch screen, microphone, various sensors, etc., and output devices may include a display, speaker, vibrator, indicator light, etc.
[0171] The communication interface 740 is used to connect to a communication module (not shown) to enable communication between the device and other devices. The communication module can communicate via a wired method (such as USB, network cable, etc.) or a wireless method (such as mobile network, WiFi, Bluetooth, etc.).
[0172] The bus 750 comprises a pathway for transmitting information between the various components of the device (eg, the processor 710 , the memory 720 , the input / output interface 730 , and the communication interface 740 ).
[0173] It should be noted that although the above device only shows the processor 710, memory 720, input / output interface 730, communication interface 740, and bus 750, in a specific implementation, the device may also include other components necessary for normal operation. In addition, those skilled in the art will understand that the above device may only include the components necessary to implement the embodiments of this specification, and does not necessarily include all the components shown in the figures.
[0174] The electronic device of the above embodiment is used to implement the corresponding topic guiding method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0175] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the topic guidance method described in any of the above embodiments.
[0176] The computer-readable media of this embodiment include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0177] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the topic guiding method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0178] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. Within the scope of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.
[0179] In addition, for simplicity of description and discussion, and in order not to make the embodiment of the application difficult to understand, the known power supply / ground connection with integrated circuit (IC) chip and other components may or may not be shown in the accompanying drawings provided. In addition, the device can be shown in the form of a block diagram to avoid making the embodiment of the application difficult to understand, and this also takes into account the following fact, that is, the details of the embodiment of these block diagram devices are highly dependent on the platform to be implemented in the embodiment of the application (that is, these details should be fully within the scope of understanding of those skilled in the art). When specific details (for example, circuit) are set forth to describe exemplary embodiments of the application, it will be apparent to those skilled in the art that the embodiment of the application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.
[0180] Although the present invention has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those skilled in the art based on the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may utilize the embodiments discussed.
[0181] The embodiments of the present application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of this application.
Claims
1. A topic guiding method, characterized in that: include: Acquire question-and-answer text data; wherein the question-and-answer text data includes: a question text, an answer text, and evidence text used to prove the matching degree between the question text and the answer text; divide the question-and-answer text data into multiple text paragraphs according to a preset division rule; use an open source search framework to determine, among the multiple text paragraphs, a target text paragraph that has the highest relevance to the evidence text and meets a preset number; construct information pairs of topics and corpora based on the question-and-answer text data and the target text paragraphs; and construct a semantic relevance model based on the information pairs; Get the topic corpus and conversation vectors; Encoding the topic corpus pool using the semantic relevance model to determine a corpus vector; Determining a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors; Determining whether a correlation between the dialogue vector and the target corpus vector is greater than or equal to a preset correlation threshold; In response to the relevance between the dialogue vector and the target corpus vector being greater than or equal to the preset relevance threshold, a guiding reply corpus is generated according to the target corpus vector to guide the topic.
2. The method according to claim 1, characterized in that The step of dividing the question-answer text data into a plurality of text paragraphs according to a preset division rule includes: The question and answer text is divided into units of a preset number of characters to obtain a plurality of text paragraphs.
3. The method according to claim 2, characterized in that The question-and-answer text is divided into units of a preset number of characters to obtain a plurality of text paragraphs, including: The question and answer text is divided starting from the first character in units of a preset number of characters. If the last character of the initial text paragraph obtained by division is not the ending character, the next character is obtained and added to the initial text paragraph until the ending character is obtained, and the ending character is added to the initial text paragraph to obtain a text paragraph.
4. The method according to claim 1, wherein The corpus includes: positive sample corpus and negative sample corpus; The step of constructing the information pair according to the question-answer text data and the target text paragraph includes: determining the topic according to the question text; Determining the positive sample corpus according to the target text paragraph containing the answer text in the target text paragraph; Determining the negative sample corpus according to the target text paragraph that does not contain the answer text in the target text paragraph; The topic and the positive sample corpus are paired with the negative sample corpus to determine the information pair.
5. The method according to claim 1, characterized in that The step of constructing a semantic relevance model based on the information includes: Obtain a basic model, a first word vector and a first position vector of the topic, and a second word vector and a second position vector of the corpus; Encoding the first word vector and the first position vector using the base model to determine a topic paragraph vector; Encoding the second word vector and the second position vector using the base model to determine a corpus paragraph vector; Determining the similarity between the topic and the corpus based on the inner product of the topic paragraph vector and the corpus paragraph vector; In response to the similarity satisfying the target value, the semantic relevance model is constructed according to the information pair based on the double-tower model.
6. The method according to claim 1, characterized in that Obtaining the conversation vector includes: In response to receiving the user topic, obtaining the user's historical conversation record; The user topic and the historical conversation record are encoded using the semantic relevance model to determine the conversation vector.
7. The method according to claim 1, characterized in that The step of determining a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors further includes: Storing the corpus vectors in a search tool to create an online index; The conversation vector is input into the search tool to perform the online indexing to determine the target corpus vector having the highest similarity to the conversation vector.
8. The method according to claim 1, characterized in that The method further comprises: In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, it is determined not to guide the topic.
9. The method according to claim 1, further comprising: In response to the relevance between the dialogue vector and the target corpus vector being less than the preset relevance threshold, guiding the topic according to preset guiding reply corpus.
10. A topic guiding device, characterized in that: include: A construction module is configured to obtain question-and-answer text data; wherein the question-and-answer text data includes: a question text, an answer text, and evidence text used to prove the matching degree between the question text and the answer text; divide the question-and-answer text data into multiple text paragraphs according to a preset division rule; determine, using an open source search framework, a target text paragraph with the highest relevance to the evidence text and meeting a preset number of target text paragraphs among the multiple text paragraphs; construct information pairs of topics and corpora based on the question-and-answer text data and the target text paragraphs; and construct a semantic relevance model based on the information pairs; An acquisition module is configured to acquire a topic corpus and a conversation vector; an encoding module configured to encode the topic corpus pool using the semantic relevance model to determine a corpus vector; A first determining module is configured to determine a target corpus vector having the highest similarity to the dialogue vector from the corpus vectors; A second determination module is configured to determine whether the relevance between the dialogue vector and the target corpus vector is greater than or equal to a preset relevance threshold; The guiding module is configured to generate a guiding reply corpus according to the target corpus vector to guide the topic in response to the relevance between the dialogue vector and the target corpus vector being greater than or equal to the preset relevance threshold.
11. 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 method according to any one of claims 1 to 9 is implemented.
12. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to implement the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Retrieval model training method and device, equipment and computer storage medium
CN112148895A
Man-machine conversation method and device based on AI and storage medium
CN113946658A