Question and answer reply generation method and device, computer equipment and storage medium

By using the Q&A reply generation method in the chatbot, using input analysis network, style recognition network, and retrieval to enhance the collaborative work of generating networks and reply selection networks, the existing chatbot cannot provide personalization, relevance and context coherence. The replies content issues have achieved more efficient personalized replies generation and user experience improvement.

CN119474306APending Publication Date: 2025-02-18PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411536262.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

Existing chatbots lack in-depth understanding and effective utilization of user historical dialogue data when generating content, resulting in the generated reply being too general and difficult to match individual users' personalized preferences, and perform poorly in multiple rounds of dialogue scenarios, resulting in content The correlation and context coherence of the relationship are reduced.

Method used

A question-and-answer replies generation method is used to analyze and process the user's query text through a trained replies generation model. The model includes input parsing networks, style recognition networks, search enhancement generation networks, and reply selection networks. Through the collaborative work of these networks, the model can preprocess and word segmentation process query text, identify the style and emotions in the user's historical dialogue data, generate personalized replies in combination with the preset knowledge base, and select the final replies through the probability distribution.

Benefits of technology

It improves the personalization and real-time nature of the reply content, enhances the naturalness and user experience of the conversation, and improves the relevance and coherence of the reply content in multiple rounds of conversations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119474306A_ABST
    Figure CN119474306A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of artificial intelligence and financial science and technology, and relates to a question and answer reply generation method which comprises the steps that a query text is input into a reply generation model, and the reply generation model comprises an input analysis network, a style recognition network, a retrieval enhancement generation network and a reply selection network; processing the query text through the input analysis network to obtain a text input vector; inputting the user historical dialogue data and the text input vector into a style recognition network to generate a style recognition result; inputting the text input vector and the style recognition result into a retrieval enhancement generation network, and generating a plurality of candidate replies in combination with related document fragments retrieved by a preset knowledge base; a final reply is selected from the plurality of candidate replies through the reply selection network. The invention further provides a question and answer reply generation device, computer equipment and a storage medium. In addition, the invention also relates to a block chain technology, and the final reply can be stored in the block chain. According to the method, the content meeting the long-term preference and personalized requirements of the user can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of artificial intelligence and financial technology, and in particular to a method, apparatus, computer device and storage medium for generating responses to questions and answers. Background Art

[0002] With the rapid development of information technology, chatbots have become an important part of the human-computer interaction field and are widely used in customer service, entertainment interaction, financial consulting and other scenarios. At present, the core technology of chatbots mainly relies on generative language models (such as GPT-3) or information retrieval technology (such as Dense Passage Retrieval, DPR) to generate or retrieve content related to user queries. Generative language models can generate coherent and logical texts by learning from large-scale corpora, while information retrieval technology focuses on quickly locating the specific information required by users from massive data.

[0003] However, although these technologies have made significant progress in improving the performance of chatbots, there are still many shortcomings. Specifically, due to the lack of in-depth understanding and effective use of users' historical conversation data, current chatbots are often too general when generating content, and it is difficult to accurately match the personalized preferences of individual users in terms of tone, style, expression, etc. This has limited the improvement of user experience and failed to meet the growing personalized needs.

[0004] In addition, the performance of existing models in multi-round dialogue scenarios is also unsatisfactory. Due to the lack of an effective mechanism to dynamically adjust the generation strategy based on user feedback, the relevance and contextual coherence of the content tend to gradually decrease as the number of dialogue rounds increases. This problem is particularly prominent in applications that handle complex financial dialogues and track user needs over the long term. Summary of the invention

[0005] The purpose of the embodiments of the present application is to propose a method, apparatus, computer device and storage medium for generating responses to questions and answers, so as to solve the technical problem that existing question and answer systems cannot provide personalized, relevant and contextually coherent response content.

[0006] In order to solve the above technical problems, the present application embodiment provides a method for generating a reply to a question and answer, which adopts the following technical solution:

[0007] Obtaining a query text input by a user, and inputting the query text into a trained response generation model, wherein the response generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network, and a response selection network;

[0008] Preprocessing and word segmentation processing are performed on the query text through the input parsing network to obtain word segmentation units, and the word segmentation units are embedded and converted into text input vectors;

[0009] Acquire historical conversation data of the user, input the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generate a style recognition result of the user;

[0010] Inputting the text input vector and the style recognition result into the retrieval enhancement generation network, and generating multiple candidate responses in combination with relevant document fragments retrieved from a preset knowledge base;

[0011] The plurality of candidate replies and the related document fragments are input into the reply selection network, the probability distribution of each candidate reply is predicted, and the candidate reply with the highest probability value is selected as the final reply output based on the probability distribution.

[0012] In order to solve the above technical problems, the embodiment of the present application further provides a question-answer reply generation device, which adopts the following technical solution:

[0013] An input module, used to obtain a query text input by a user, and input the query text into a trained reply generation model, wherein the reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network, and a reply selection network;

[0014] A parsing module, used for preprocessing and word segmentation processing the query text through the input parsing network to obtain word segmentation units, and embedding the word segmentation units to convert them into text input vectors;

[0015] A classification module, used to obtain the historical conversation data of the user, input the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generate a style recognition result for the user;

[0016] A retrieval generation module, used to input the text input vector and the style recognition result into the retrieval enhancement generation network, and generate multiple candidate responses in combination with relevant document fragments retrieved from a preset knowledge base;

[0017] The selection module is used to input the multiple candidate replies and the related document fragments into the reply selection network, predict the probability distribution of each candidate reply, and select the candidate reply with the highest probability value as the final reply output based on the probability distribution.

[0018] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0019] The computer device includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the question-and-answer reply generation method as described above when executing the computer-readable instructions.

[0020] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0021] The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the method for generating responses to questions and answers as described above.

[0022] Compared with the prior art, this application has the following beneficial effects:

[0023] The present application provides a method for generating responses to questions and answers. The response generation model analyzes and processes a user's query text through a response generation model. The response generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network, and a response selection network. The input parsing network preprocesses and vectorizes the query text, and can convert the input text into structured data that can be processed by the model, thereby improving the retrievability and comprehensibility of the text, improving processing efficiency, and reducing data processing costs. The style recognition network performs in-depth analysis on the user's historical conversation data, and can automatically extract the user's personalized language style and emotional tendency, so that the model can generate content that meets the user's long-term preferences and personalized needs, thereby improving the naturalness of the conversation and the user experience. The retrieval enhancement generation network combines a preset knowledge base to generate response content, and can fully understand the historical conversation data and the current input query text, accurately utilize the user's personalized preferences, and improve the efficiency and accuracy of personalized response generation. The response selection network selects candidate responses, so that content generation is more in line with the user's personalized preferences and real-time needs, thereby improving the relevance and coherence of the response content in multiple rounds of conversations. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0025] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0026] Figure 2 is a flow chart of an embodiment of a method for generating a reply to a question and answer according to the present application;

[0027] Figure 3 is a structural schematic diagram of an embodiment of a question-and-answer reply generating device according to the present application;

[0028] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0029] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0030] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0031] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0032] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.

[0033] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0034] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.

[0035] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .

[0036] It should be noted that the question and answer reply generation method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the question and answer reply generation device is generally set in the server / terminal device.

[0037] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0038] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for generating a reply to a question and answer according to the present application, comprising the following steps:

[0039] Step S201, obtaining the query text input by the user, and inputting the query text into a trained response generation model, wherein the response generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a response selection network.

[0040] In this embodiment, the query text is the consulting text content input by the user according to his / her own needs, including but not limited to basic information query of financial products, investment advice consultation, complex financial problem consultation, etc.

[0041] In this embodiment, the question-answer reply generation method is executed on an electronic device (eg Figure 1 The server / terminal device shown in the figure can obtain the query text input by the user through a wired connection method or a wireless connection method. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.

[0042] The reply generation model is a trained content generation model based on deep learning, including input parsing network, style recognition network, retrieval enhancement generation network and reply selection network. Through the collaborative work of multiple modules such as input parsing network, style recognition network, retrieval enhancement generation network and reply selection network, a complete feedback loop is formed. The output of each network module affects the input of the next network module, so that the final generated content is greatly optimized in terms of personalization and real-time information fusion.

[0043] Step S202, preprocessing and word segmentation processing are performed on the query text through the input parsing network to obtain word segmentation units, and the word segmentation units are embedded and converted into text input vectors.

[0044] In this embodiment, the input parsing network is mainly responsible for preprocessing the natural language input query text into a format that can be processed by the model, including preprocessing, word segmentation and embedding conversion, and converting the query text into a vector for model processing.

[0045] In some optional implementations, the input parsing network includes a preprocessing layer, a word segmentation layer, and an input embedding layer. The input parsing network performs preprocessing and word segmentation on the query text to obtain word segmentation units, and embeds the word segmentation units. The steps of converting the word segmentation units into text input vectors include:

[0046] Preprocessing the query text through the preprocessing layer to obtain a preprocessed text;

[0047] Through the word segmentation layer, the preprocessed text is segmented and tokenized according to the word segmentation algorithm to obtain a sequence of word segmentation units;

[0048] The word segmentation unit sequence is converted into a vector through the input embedding layer to generate a text input vector.

[0049] Among them, the preprocessing layer can use regular expressions to remove irrelevant spaces, special characters, punctuation marks, etc. in the input query text. For example, the input "Which %technology^ stocks are suitable for me to buy now?" is processed to "Which technology stocks are suitable for me to buy now?"

[0050] The word segmentation layer uses the BERT word segmenter to segment and tokenize the preprocessed text. The BERT word segmenter WordPiece algorithm segments the preprocessed text to obtain the optimal word segmentation unit, and tokenizes the word segmentation unit. Tokenization is Tokenier processing. The segmented word segmentation units are mapped to corresponding identifiers (such as ID) through Tokenier processing to generate a vocabulary, which is a sequence of word segmentation units. Each word segmentation unit in the vocabulary is assigned a unique identifier. For example, the word segmentation layer is used to segment and tokenize the question "Which technology stocks are suitable for me to buy now?" and output: ["I", "now", "suitable", "buy", "which", "technology", "stocks", "?"].

[0051] The word segmentation unit sequence is embedded into words through the input embedding layer, including Token Embeddings, Segment Embeddings and Position Embeddings, and the word unit vector, sentence vector and position vector are obtained respectively. The word unit vector, sentence vector and position vector are concatenated to form the final embedded text input vector, which can be used as T u Indicates that T u ∈R L×Dtoken , where L is the number of subwords, that is, the number of word segmentation units.

[0052] By converting the input query text into a text input vector that can be processed by the model, the retrievability and comprehensibility of the text can be improved, the model processing efficiency can be improved, and the data processing cost can be reduced.

[0053] Step S203, obtaining the user's historical conversation data, inputting the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generating the user's style recognition result.

[0054] In this embodiment, the style recognition network is responsible for analyzing the user's historical conversation data and the currently input text input vector to identify the user's historical style, current style and emotional tendency, and predict the user's expected output style.

[0055] In some optional implementations, the style recognition network includes a BERT encoding layer, a historical preference classification layer, a style classification linear layer, a sentiment classification linear layer, and an expected style classifier. The steps of inputting the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification to generate a user's style recognition result include:

[0056] The historical conversation data and text input vector are embedded and encoded respectively through the BERT encoding layer to obtain the historical conversation embedding vector and the current input embedding vector;

[0057] Input the historical conversation embedding vector into the historical preference classification layer for classification to obtain the historical conversation style category;

[0058] Input the current input embedding vector into the style classification linear layer and the sentiment classification linear layer respectively;

[0059] Perform style classification on the current input embedding vector through the style classification linear layer to obtain the current dialogue style category;

[0060] Perform sentiment classification on the current input embedding vector through the sentiment classification linear layer to obtain the sentiment style category;

[0061] The historical conversation style category, the current conversation style category, and the emotional style category are concatenated into vectors, and classified using the expected style classifier to generate the expected style category.

[0062] The historical dialogue style category, current dialogue style category, emotional style category and expected style category are output as style recognition results.

[0063] In this embodiment, the user's historical conversation data is obtained. n is the number of historical conversations, L hist is the number of subwords in the longest historical dialogue, and h i After concatenation, it is encoded through the BERT encoding layer to generate the context-related embedding representation of each historical conversation. The embedding representations of all historical conversations are aggregated to obtain the output vector of the [CLS] tag, that is, the historical conversation embedding vector.

[0064] The text input vector is passed through the BERT encoding layer for the same embedding encoding, capturing the contextual information of the current input query text and converting it into the current input embedding vector.

[0065] In this embodiment, the historical conversation embedding vector is classified by the historical preference classification layer. Specifically, the historical preference classification layer can use a fully connected layer for classification, and the historical conversation embedding vector is mapped to a predefined style category by the fully connected layer. For example, two fully connected layers of different dimensions are used for feature mapping, and then a softmax function is used for classification to output the historical conversation style category U hist , where the conversation style categories include robust, radical, innovative, etc.

[0066] In this embodiment, the current input embedding vector is input into the style classification linear layer and the emotion classification linear layer for style recognition and emotion recognition. Specifically, the style classification linear layer and the emotion classification linear layer use two independent fully connected layers for classification. The style classification linear layer maps the current input embedding vector to a predefined style category and then performs classification, outputting the current dialogue style category S u , the style classification labels are "formal", "informal", "casual", "business", "academic", etc.; the current input embedding vector is mapped to the predefined emotional state through the sentiment classification linear layer and then classified, and the emotional style category E is output. u ,Sentiment classification labels include positive, negative, neutral, etc.

[0067] The historical conversation style category, current conversation style category, and emotional style category are converted into corresponding vectors through the word vector table and then spliced ​​to obtain the style preference splicing vector, which is classified by the expected style classifier and the expected style category S is output. exp , but not limited to "formal", "informal", "casual", "business", "academic", etc. Among them, the expected style classifier uses the ExpNet network. The structure of the ExpNet network is designed as an input layer, two hidden layers and an output layer. The dimensions of each layer are different. For example, the dimension of the input layer is 2304, the dimensions of the two hidden layers are 1024 and 512 respectively, and the dimension of the output layer is 5. The style preference concatenation vector is classified through the ExpNet network to finally generate the user's expected style category S exp .

[0068] For example, suppose the system currently generates historical dialogue style category U hist is “robust”, the generated current dialogue style category S u Formal, emotional style category E u is "neutral". hist ,S u ,E u After being embedded into 768-dimensional vectors through embedding and concatenated, the user’s expected style category S is classified through ExpNet. exp For "formal".

[0069] In some optional implementations, the training process of the history preference classification layer includes:

[0070] 1) Determine the optimization goal: Extract the user's personalized language style, emotional tendency and other preferences through historical conversation data, and generate the user's historical style category U hist ;

[0071] 2) Input: user historical conversation dataset H;

[0072] 3) Output: User historical style category U hist ;

[0073] 4) Loss function: Use cross-entropy loss to measure the generated U' hist (U' hist is probability) and the real user style U true The difference between them is calculated as follows:

[0074]

[0075] Where N represents the number of data in the user's historical conversation dataset;

[0076] 5) Training algorithm: Use Adam optimizer to optimize the parameters of the historical preference classification layer.

[0077] In some optional implementations, the training process of the style classification linear layer and the sentiment classification linear layer includes:

[0078] 1) Optimization goal: Identify the user’s language style and emotional tendency through the current text input vector;

[0079] 2) Input: text input vector;

[0080] 3) Output: Current dialogue style category S u , Emotional style category E u ;

[0081] 4) Loss function: Cross-Entropy Loss is used to train the style and sentiment classifiers. The loss function calculation formula is the same as the loss function of the historical preference classification layer.

[0082] 5) Training algorithm: Use stochastic gradient descent (SGD) for optimization.

[0083] In some optional implementations, the training process of the desired style classifier is as follows:

[0084] 1) Optimization goal: Predict the user's expected response style S by combining the user's historical conversation style category, current conversation style category, and emotional style category exp ;

[0085] 2) Input: Current dialogue style category S u , Emotional style category E u 、Historical style category U hist ;

[0086] 3) Output: expected style category S exp;

[0087] 4) Loss function: Cross-Entropy Loss is used to train the style and sentiment classifiers. The loss function calculation formula is the same as the loss function of the historical preference classification layer.

[0088] 5) Training algorithm: Use stochastic gradient descent (SGD) for optimization.

[0089] By using the style recognition network to perform style classification and sentiment classification, it is not only possible to identify the language style and emotional state of the user's current conversation, but also to predict the user's expected style in a specific context based on the historical conversation style, so that the model can better adjust the generated conversation content, making the response not only semantically relevant, but also in line with the user's expectations in style, meeting the user's personalized needs.

[0090] Step S204, inputting the text input vector and the style recognition result into the retrieval enhancement generation network, and generating a plurality of candidate responses in combination with relevant document fragments retrieved from a preset knowledge base.

[0091] The Retrieval-Augmented Generation Network generates informative and contextually relevant personalized responses by combining information retrieval and generation models, ensuring that the generated responses are both informative and highly relevant to the user input.

[0092] In this embodiment, the retrieval enhancement generation network includes a document retrieval layer and a content generation layer, which are mainly used for document retrieval and content generation. The document retrieval is implemented through the document retrieval layer, and the content generation is implemented through the content generation layer. Specifically, the document retrieval layer retrieves relevant document fragments related to the text input vector from the preset knowledge base; according to the text input vector, the relevant document fragments, the historical dialogue style category, the current dialogue style category, the emotional style category and the expected style category, the content generation prompt instruction is constructed; through the content generation layer, multiple candidate replies are generated according to the content generation prompt instruction.

[0093] Among them, the preset knowledge base is a pre-built system that stores a large amount of text data, which usually includes professional domain knowledge, general knowledge, proprietary internal data of some application scenarios, etc. The knowledge base serves as an external data source to provide additional information support for the model.

[0094] In some optional implementations of this embodiment, the document retrieval layer includes a query encoder and a document encoder, and the step of retrieving relevant document fragments related to the text input vector from a preset knowledge base through the document retrieval layer includes:

[0095] Encode the text input vector through the query encoder to obtain a query vector;

[0096] Encode each document fragment in the preset knowledge base into a document vector through a document encoder;

[0097] The similarity score between the query vector and the document vector is calculated, and based on the similarity score, a preset number of document segments with the best similarity are selected to form related document segments.

[0098] In this embodiment, the document retrieval layer uses the DPR model to retrieve document fragments D related to the text input vector from the knowledge base. u Among them, the DPR model uses a dual-tower model structure, including two independent BERT encoders, namely the query encoder and the document encoder, which encode the text input vector and the document fragment respectively, so that the query text and the document fragment are represented in the same vector space and retrieved by the similarity between the vectors.

[0099] Specifically, the query encoder encodes the text input vector into a query vector q, and the dimension of the query vector q is Among them, D token Represents the vector length; similarly, the document encoder encodes each document fragment in the knowledge base into a document vector d, Calculate the similarity score between the query vector q and the document vector d through cosine similarity, and select the top-k related document fragments D u , the similarity score calculation formula is as follows:

[0100]

[0101] By retrieving relevant document fragments from the preset knowledge base through the document retrieval layer, it is possible to utilize external knowledge, have a stronger ability to understand the context, improve the accuracy of response content generation, and reduce hallucinations.

[0102] In the content generation layer, the text input vector, related document fragments, historical conversation style categories, current conversation style categories, emotional style categories, and expected style categories are combined to generate personalized responses using a large language model. The large language model can be GPT-2, GPT-3, GPT-4, BERT, or BART, without limitation.

[0103] First, construct a content generation prompt instruction Prompt. Specifically, fill the text input vector, relevant document fragments, historical conversation style categories, current conversation style categories, emotional style categories and expected style categories into the pre-built Prompt template to form the content generation prompt instruction Prompt.

[0104] For example, the prompt template is as follows:

[0105] “Given the following user query and retrieved documents, as well as the user’s style and sentiment preferences, please generate a response that matches the user’s expected style and preferences:

[0106] User query: [query text]

[0107] Retrieved documents:

[0108] 1.[Document 1]

[0109] 2.[Document 2]

[0110] …

[0111] User history style: [historical conversation style category]

[0112] User style: [Current conversation style category]

[0113] User sentiment: [emotional style category]

[0114] Desired response style: [desired style category]

[0115] Please generate a response:"

[0116] The large language model generates text based on the filled prompt through autoregression, and obtains m replies R through different generation strategies. g , R g ∈R m , m is a positive integer. Among them, the relevant document fragment is used as strategy one, the historical dialogue style category is used as strategy two, the current dialogue style category is used as strategy three, the emotional style category is used as strategy four, and the expected style category is used as strategy five. The generation strategy is to generate personalized reply content by combining the text input vector with one or more of strategies one to five.

[0117] Through the retrieval-enhanced generation network, the text input vector, related document fragments, historical conversation style categories, current conversation style categories, emotional style categories and expected style categories are combined to generate personalized responses that are informative and contextually relevant, ensuring that the generated responses are both informative and highly relevant to the user input, thereby improving the personalization and real-time nature of the generated content.

[0118] Step S205, multiple candidate replies and related document fragments are input into the reply selection network, the probability distribution of each candidate reply is predicted, and the candidate reply with the highest probability value is selected as the final reply output based on the probability distribution.

[0119] The goal of the reply selection network is to select the reply that best meets the user's personalized needs from multiple candidate replies generated by the retrieval enhancement generation network.

[0120] In this embodiment, the reply selection network includes an encoding embedding layer and a multi-layer perceptron. Specifically, multiple candidate replies and related document fragments are respectively input into the encoding embedding layer for encoding to obtain candidate reply vectors and document fragment vectors; the relevance score of each candidate reply is calculated based on the candidate reply vector and the document fragment vector; the candidate replies and the corresponding relevance scores are concatenated and input into the multi-layer perceptron for probability prediction to obtain the probability distribution of each candidate reply.

[0121] For example, the M candidate responses R g =[R 1 ,…,R M ], each candidate reply is BERT encoded through the encoding embedding layer, and the vector corresponding to the head [cls] token is taken, that is, Among them, 768 is the dimension of the encoding embedding layer, and the retrieved relevant document fragment D u Similarly, the relevance of each candidate reply to the retrieved relevant document fragment is measured. Specifically, the semantic similarity between each candidate reply and the relevant document fragment is calculated by cosine similarity, and the formula is as follows:

[0122]

[0123] in, is the vector representation of the i-th candidate response, is the vector representation of the retrieved relevant document fragments, and K is the number of retrieved document fragments.

[0124] The content relevance score of each candidate response to the relevant document fragment is: R xontent =[R content1 ,…,R contentN ]∈R N×1 , R g With R content Splicing, we get R∈R N×769 , R∈R N×769 Input the multilayer perceptron for probability prediction and select the response with the highest probability value as the final response R rl Output.

[0125] It should be emphasized that in order to further ensure the privacy and security of the final response, the above final response can also be stored in a blockchain node.

[0126] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.

[0127] In some optional implementations, the multilayer perceptron includes an input layer, two hidden layers, and an output layer, where the dimensions of each layer are 769, 512, 256, and 1, respectively, and outputs a probability distribution π θ (R g )∈R N×1 , which is used to represent the probability distribution of each candidate response being selected in the current state.

[0128] In some optional implementations, the training process of the reply selection network includes:

[0129] 1) Determine the optimization goal: Dynamically adjust the response selection strategy based on user feedback information, so that the generated responses gradually meet the user's personalized needs and improve the relevance and satisfaction of the conversation;

[0130] 2) Input: R g =[R 1 ,…,R M ], the retrieved document fragment D u ;

[0131] 3) Output: The optimal response R finally selected rl , as a response that meets the user's preferences and needs;

[0132] 4) Loss function: The policy network loss function is based on user feedback F∈R 1×N , the system starts from R g Select a reply from the list and show it to the user, who then gives feedback on the selected reply. If the reply allows the user to continue the conversation or give a thumbs-up, the reply will receive a positive reward (F=1), and the F value of the unselected reply will be set to 0; if the user does not take any action, the F value of all replies will be set to 0.5; if the user gives a bad review to the reply, the F value of the reply will be set to 0, and the F value of the unselected reply will be set to 1; the cross entropy loss is used to measure the accuracy of the generated reply selection:

[0133]

[0134] Among them, π θ (Rg,i ) is the probability distribution of the i-th candidate response being selected, F i is the user's feedback on the i-th candidate response;

[0135] 5) Training algorithm: The policy gradient optimization algorithm is used to iteratively update the network through user feedback, so that the system can dynamically adapt to the personalized needs of users.

[0136] By screening multiple candidate replies through the reply selection network, content generation can be made more in line with the user's personalized preferences, and the generated content can be continuously optimized in real time during multiple rounds of conversations, ensuring that the system can adaptively meet the user's long-term needs.

[0137] The present application analyzes and processes the user's query text through a reply generation model. The reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a reply selection network. The input parsing network preprocesses and vectorizes the query text, and can convert the input text into structured data that can be processed by the model, which can improve the retrievability and comprehensibility of the text, improve processing efficiency, and reduce data processing costs; through the style recognition network, in-depth analysis of the user's historical conversation data can be performed, and the user's personalized language style and emotional tendency can be automatically extracted, so that the model can generate content that meets the user's long-term preferences and personalized needs, and improve the naturalness of the conversation and user experience; through the retrieval enhancement generation network combined with a preset knowledge base to generate reply content, it can fully understand the historical conversation data and the current input query text, accurately use the user's personalized preferences, and improve the efficiency and accuracy of personalized reply generation; through the reply selection network, candidate replies are selected, so that content generation is more in line with the user's personalized preferences and real-time needs, thereby improving the relevance and coherence of the reply content in multiple rounds of conversations.

[0138] In some optional implementations, after the step of selecting the candidate reply with the highest probability value as the final reply output based on the probability distribution, the following step is further included:

[0139] Obtain the user's feedback on the final response, and use the policy gradient algorithm to calculate the gradient of the policy network parameters based on the feedback information;

[0140] Restore the network parameters of the selected network based on the gradient update.

[0141] Specifically, the system receives user feedback on the final reply, such as positive rewards, negative rewards, or no action taken, and uses the policy gradient algorithm REINFORCE to calculate the gradient of the policy network parameters based on the feedback information. The network parameters of the reply selection network are updated based on the calculated gradient. Based on the updated network parameters, the generation strategy of the reply selection network is dynamically adjusted. For example, when the user prefers humorous replies, the probability of generating such replies is increased, while the probability of generating serious replies is reduced. When new user input is received, the optimized reply selection network is used to generate a personalized final reply in combination with factors such as the user's historical preferences and the current conversation context. While returning the generated reply to the user, the user's feedback score on the reply is also recorded for the next round of model optimization iterations to continuously improve the quality of the system's replies and make them more in line with user needs and preferences.

[0142] The network is continuously updated through user feedback and the dialogue strategy is dynamically adjusted so that the generated responses can gradually adapt to the user's personalized preferences and real-time needs, and improve the relevance and coherence of the response content in multiple rounds of dialogue.

[0143] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0144] The question-and-answer reply generation method of the present application can be applied to Ping An Technology's chatbot, so that Ping An Technology's chatbot can show excellent results in practical applications. For example, in terms of generating personalized investment advice, the system can combine the user's historical investment behavior and current market conditions to generate advice that meets the user's investment style and risk preference, and optimize the content in real time through the reinforcement learning module in multiple rounds of conversations. In the financial product introduction and recommendation scenario, the system uses RAG (retrieval enhanced generation) technology to retrieve relevant information, and generates personalized product introductions and recommendations based on the user's language style. Through continuous optimization of reinforcement learning, the system can dynamically adjust the recommendation strategy, thereby improving the user's willingness to buy and satisfaction. These improvements significantly enhance the personalization and dynamic adaptability of financial chatbots, providing users with more targeted financial services.

[0145] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0146] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0147] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0148] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a question-answer reply generation device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0149] like Figure 3 As shown, the question-answer reply generating device 300 described in this embodiment includes: an input module 301, a parsing module 302, a classification module 303, a search generating module 304 and a selection module 305. Among them:

[0150] The input module 301 is used to obtain the query text input by the user, and input the query text into the trained reply generation model, wherein the reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a reply selection network;

[0151] The parsing module 302 is used to perform preprocessing and word segmentation processing on the query text through the input parsing network to obtain word segmentation units, and embed the word segmentation units to convert them into text input vectors;

[0152] The classification module 303 is used to obtain the historical conversation data of the user, input the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generate a style recognition result of the user;

[0153] The retrieval generation module 304 is used to input the text input vector and the style recognition result into the retrieval enhancement generation network, and generate multiple candidate responses in combination with relevant document fragments retrieved from a preset knowledge base;

[0154] The selection module 305 is used to input the multiple candidate replies and the related document fragments into the reply selection network, predict the probability distribution of each candidate reply, and select the candidate reply with the highest probability value as the final reply output based on the probability distribution.

[0155] It should be emphasized that in order to further ensure the privacy and security of the final response, the above final response can also be stored in a blockchain node.

[0156] The reply generation device 300 based on the above-mentioned question and answer analyzes and processes the user's query text through a reply generation model. The reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a reply selection network. The input parsing network preprocesses and vectorizes the query text, and can convert the input text into structured data that can be processed by the model, which can improve the retrievability and comprehensibility of the text, improve processing efficiency, and reduce data processing costs; through the style recognition network, the historical conversation data of the user is deeply analyzed, and the user's personalized language style and emotional tendency can be automatically extracted, so that the model can generate content that meets the user's long-term preferences and personalized needs, and improve the naturalness of the conversation and user experience; through the retrieval enhancement generation network combined with the preset knowledge base to generate reply content, it can fully understand the historical conversation data and the current input query text, accurately use the user's personalized preferences, and improve the efficiency and accuracy of personalized reply generation; through the reply selection network, candidate replies are selected, so that the content generation is more in line with the user's personalized preferences and real-time needs, thereby improving the relevance and coherence of the reply content in multiple rounds of conversations.

[0157] In some optional implementations of this embodiment, the input parsing network includes a preprocessing layer, a word segmentation layer and an input embedding layer, and the parsing module 302 includes:

[0158] A preprocessing submodule, used for preprocessing the query text through the preprocessing layer to obtain a preprocessed text;

[0159] A word segmentation submodule, used for performing word segmentation and tokenization on the preprocessed text according to the word segmentation algorithm through the word segmentation layer to obtain a word segmentation unit sequence;

[0160] The embedding submodule is used to perform vector conversion on the word segmentation unit sequence through the input embedding layer to generate a text input vector.

[0161] By converting the input query text into a text input vector that can be processed by the model, the retrievability and comprehensibility of the text can be improved, the model processing efficiency can be improved, and the data processing cost can be reduced.

[0162] In some optional implementations, the style recognition network includes a BERT encoding layer, a historical preference classification layer, a style classification linear layer, a sentiment classification linear layer, and an expected style classifier, and the classification module 303 is further used to:

[0163] The historical conversation data and the text input vector are respectively embedded and encoded by the BERT encoding layer to obtain a historical conversation embedding vector and a current input embedding vector;

[0164] Inputting the historical conversation embedding vector into the historical preference classification layer for classification to obtain a historical conversation style category;

[0165] Inputting the current input embedding vector into the style classification linear layer and the sentiment classification linear layer respectively;

[0166] Performing style classification on the current input embedding vector through the style classification linear layer to obtain a current dialogue style category;

[0167] Performing sentiment classification on the current input embedding vector through the sentiment classification linear layer to obtain a sentiment style category;

[0168] Performing vector concatenation on the historical conversation style category, the current conversation style category, and the emotional style category, and classifying them through the expected style classifier to generate an expected style category;

[0169] The historical dialogue style category, the current dialogue style category, the emotional style category and the expected style category are output as the style recognition result.

[0170] By using the style recognition network to perform style classification and sentiment classification, it is not only possible to identify the language style and emotional state of the user's current conversation, but also to predict the user's expected style in a specific context based on the historical conversation style, so that the model can better adjust the generated conversation content, making the response not only semantically relevant, but also in line with the user's expectations in style, meeting the user's personalized needs.

[0171] In some optional implementations, the retrieval enhancement generation network includes a document retrieval layer and a content generation layer, and the retrieval generation module 304 includes:

[0172] A retrieval submodule, configured to retrieve relevant document fragments related to the text input vector from the preset knowledge base through the document retrieval layer;

[0173] A construction submodule, configured to construct a content generation prompt instruction according to the text input vector, the relevant document fragment, the historical dialogue style category, the current dialogue style category, the emotional style category and the expected style category;

[0174] A generation submodule is used to generate multiple candidate replies according to the content generation prompt instruction through the content generation layer.

[0175] Through the retrieval-enhanced generation network, the text input vector, related document fragments, historical conversation style categories, current conversation style categories, emotional style categories and expected style categories are combined to generate personalized responses that are informative and contextually relevant, ensuring that the generated responses are both informative and highly relevant to the user input, thereby improving the personalization and real-time nature of the generated content.

[0176] In some optional implementations of this embodiment, the document retrieval layer includes a query encoder and a document encoder, and the retrieval submodule is further used to:

[0177] Encoding the text input vector by the query encoder to obtain a query vector;

[0178] Encoding each document segment in the preset knowledge base into a document vector by the document encoder;

[0179] A similarity score between the query vector and the document vector is calculated, and a preset number of document segments with the best similarity are selected based on the similarity score to form related document segments.

[0180] By retrieving relevant document fragments from the preset knowledge base through the document retrieval layer, it is possible to utilize external knowledge, have a stronger ability to understand the context, improve the accuracy of response content generation, and reduce hallucinations.

[0181] In some optional implementations, the response selection network includes a coding embedding layer and a multi-layer perceptron, and the selection module 305 includes:

[0182] An encoding submodule, used for inputting the plurality of candidate replies and the relevant document fragments into the encoding embedding layer for encoding, to obtain a candidate reply vector and a document fragment vector;

[0183] A relevance calculation submodule, used to calculate a relevance score of each candidate reply according to the candidate reply vector and the document fragment vector;

[0184] The probability prediction submodule is used to concatenate the candidate responses and the corresponding relevance scores and input them into the multi-layer perceptron for probability prediction to obtain the probability distribution of each candidate response.

[0185] By screening multiple candidate replies through the reply selection network, content generation can be made more in line with the user's personalized preferences, and the generated content can be continuously optimized in real time during multiple rounds of conversations, ensuring that the system can adaptively meet the user's long-term needs.

[0186] In some optional implementations, the question-answer response generating device 300 further includes a real-time optimization module for:

[0187] Obtaining feedback information of the user on the final reply, and calculating the gradient of the policy network parameters using a policy gradient algorithm according to the feedback information;

[0188] The network parameters of the response selection network are updated based on the gradient.

[0189] The network is continuously updated through user feedback and the dialogue strategy is dynamically adjusted so that the generated responses can gradually adapt to the user's personalized preferences and real-time needs, and improve the relevance and coherence of the response content in multiple rounds of dialogue.

[0190] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.

[0191] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 4 with a memory 41, a processor 42, and a network interface 43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0192] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0193] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 4. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the question-answer reply generation method, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.

[0194] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run computer-readable instructions stored in the memory 41 or process data, such as computer-readable instructions for running the question-answer response generation method.

[0195] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.

[0196] The user's query text is analyzed and processed through the reply generation model. The reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a reply selection network. The input parsing network preprocesses and vectorizes the query text, and can convert the input text into structured data that can be processed by the model, which can improve the retrieval and comprehensibility of the text, improve processing efficiency, and reduce data processing costs; through the style recognition network, the user's historical conversation data is deeply analyzed, and the user's personalized language style and emotional tendency can be automatically extracted, so that the model can generate content that meets the user's long-term preferences and personalized needs, and improve the naturalness of the conversation and user experience; through the retrieval enhancement generation network combined with the preset knowledge base to generate reply content, it can fully understand the historical conversation data and the current input query text, accurately use the user's personalized preferences, and improve the efficiency and accuracy of personalized reply generation; through the reply selection network, candidate replies are selected, so that content generation is more in line with the user's personalized preferences and real-time needs, thereby improving the relevance and coherence of the reply content in multiple rounds of conversations.

[0197] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the question and answer response generation method as described above.

[0198] The user's query text is analyzed and processed through the reply generation model. The reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network and a reply selection network. The input parsing network preprocesses and vectorizes the query text, and can convert the input text into structured data that can be processed by the model, which can improve the retrieval and comprehensibility of the text, improve processing efficiency, and reduce data processing costs; through the style recognition network, the user's historical conversation data is deeply analyzed, and the user's personalized language style and emotional tendency can be automatically extracted, so that the model can generate content that meets the user's long-term preferences and personalized needs, and improve the naturalness of the conversation and user experience; through the retrieval enhancement generation network combined with the preset knowledge base to generate reply content, it can fully understand the historical conversation data and the current input query text, accurately use the user's personalized preferences, and improve the efficiency and accuracy of personalized reply generation; through the reply selection network, candidate replies are selected, so that content generation is more in line with the user's personalized preferences and real-time needs, thereby improving the relevance and coherence of the reply content in multiple rounds of conversations.

[0199] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0200] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A method for generating a response to a question and answer, characterized in that: The steps include: Obtaining a query text input by a user, and inputting the query text into a trained response generation model, wherein the response generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network, and a response selection network; Preprocessing and word segmentation processing are performed on the query text through the input parsing network to obtain word segmentation units, and the word segmentation units are embedded and converted into text input vectors; Acquire historical conversation data of the user, input the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generate a style recognition result of the user; Inputting the text input vector and the style recognition result into the retrieval enhancement generation network, and generating multiple candidate responses in combination with relevant document fragments retrieved from a preset knowledge base; The plurality of candidate replies and the related document fragments are input into the reply selection network, the probability distribution of each candidate reply is predicted, and the candidate reply with the highest probability value is selected as the final reply output based on the probability distribution.

2. The method for generating a reply to a question and answer according to claim 1, characterized in that: The input parsing network includes a preprocessing layer, a word segmentation layer and an input embedding layer; the steps of preprocessing and word segmentation processing the query text through the input parsing network to obtain word segmentation units, embedding the word segmentation units, and converting them into text input vectors include: Preprocessing the query text by the preprocessing layer to obtain a preprocessed text; Through the word segmentation layer, the preprocessed text is segmented and tokenized according to the word segmentation algorithm to obtain a word segmentation unit sequence; The word segmentation unit sequence is vectorized through the input embedding layer to generate a text input vector.

3. The method for generating a reply to a question and answer according to claim 1, characterized in that: The style recognition network includes a BERT encoding layer, a historical preference classification layer, a style classification linear layer, a sentiment classification linear layer and an expected style classifier. The step of inputting the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification to generate the style recognition result of the user includes: The historical conversation data and the text input vector are respectively embedded and encoded by the BERT encoding layer to obtain a historical conversation embedding vector and a current input embedding vector; Inputting the historical conversation embedding vector into the historical preference classification layer for classification to obtain a historical conversation style category; Inputting the current input embedding vector into the style classification linear layer and the sentiment classification linear layer respectively; Performing style classification on the current input embedding vector through the style classification linear layer to obtain a current dialogue style category; Performing sentiment classification on the current input embedding vector through the sentiment classification linear layer to obtain a sentiment style category; Performing vector concatenation on the historical conversation style category, the current conversation style category, and the emotional style category, and classifying them using the expected style classifier to generate an expected style category; The historical dialogue style category, the current dialogue style category, the emotional style category and the expected style category are output as the style recognition result.

4. The method for generating a reply to a question and answer according to claim 3, characterized in that: The retrieval enhancement generation network includes a document retrieval layer and a content generation layer. The step of inputting the text input vector and the style recognition result into the retrieval enhancement generation network and generating a plurality of candidate responses in combination with relevant document fragments retrieved from a preset knowledge base includes: Retrieving relevant document fragments related to the text input vector from the preset knowledge base through the document retrieval layer; Constructing a content generation prompt instruction according to the text input vector, the relevant document fragment, the historical conversation style category, the current conversation style category, the emotional style category, and the expected style category; Through the content generation layer, a plurality of candidate responses are generated according to the content generation prompt instruction.

5. The method for generating a reply to a question and answer according to claim 4, characterized in that: The document retrieval layer includes a query encoder and a document encoder, and the step of retrieving relevant document fragments related to the text input vector from the preset knowledge base through the document retrieval layer includes: Encoding the text input vector by the query encoder to obtain a query vector; Encoding each document segment in the preset knowledge base into a document vector by the document encoder; A similarity score between the query vector and the document vector is calculated, and a preset number of document segments with the best similarity are selected based on the similarity score to form related document segments.

6. The method for generating a reply to a question and answer according to claim 1, characterized in that: The response selection network includes an encoding embedding layer and a multi-layer perceptron. The step of inputting a plurality of candidate responses and the related document fragments into the response selection network and predicting the probability distribution of each candidate response includes: Inputting the plurality of candidate replies and the relevant document fragments into the encoding embedding layer for encoding respectively, to obtain a candidate reply vector and a document fragment vector; Calculating a relevance score for each candidate reply based on the candidate reply vector and the document fragment vector; The candidate responses and the corresponding relevance scores are concatenated and input into the multi-layer perceptron for probability prediction to obtain the probability distribution of each candidate response.

7. The method for generating a reply to a question and answer according to any one of claims 1 to 6, characterized in that: After the step of selecting the candidate reply with the highest probability value as the final reply output based on the probability distribution, the method further includes: Obtaining feedback information of the user on the final reply, and calculating the gradient of the policy network parameters using a policy gradient algorithm according to the feedback information; The network parameters of the response selection network are updated based on the gradient.

8. A question-answer response generating device, characterized in that: include: An input module, used to obtain a query text input by a user, and input the query text into a trained reply generation model, wherein the reply generation model includes an input parsing network, a style recognition network, a retrieval enhancement generation network, and a reply selection network; A parsing module, used for preprocessing and word segmentation processing the query text through the input parsing network to obtain word segmentation units, and embedding the word segmentation units to convert them into text input vectors; A classification module, used to obtain the historical conversation data of the user, input the historical conversation data and the text input vector into the style recognition network for style classification and sentiment classification, and generate a style recognition result for the user; A retrieval generation module, used to input the text input vector and the style recognition result into the retrieval enhancement generation network, and generate multiple candidate responses in combination with relevant document fragments retrieved from a preset knowledge base; The selection module is used to input the multiple candidate replies and the related document fragments into the reply selection network, predict the probability distribution of each candidate reply, and select the candidate reply with the highest probability value as the final reply output based on the probability distribution.

9. A computer device, characterized in that: It includes a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, it implements the steps of the method for generating responses to questions and answers as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the method for generating a reply to a question and answer as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Stylized intelligent dialogue method based on retrieval enhancement generation

    CN121029933A

  • Personality-driven role large model multi-modal digital duplication interaction method and system

    CN121745256A