Question and answer method and device based on large model
By standardizing and rewriting the questions to be answered and concatenating the text, the accuracy of question answering in a specific domain was improved by using a pre-trained large model, thus solving the problem of low accuracy of large models in specific domains.
Patent Information
- Application Number
- CN202410870481.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-11-01
AI Technical Summary
Large models have low accuracy in question answering in specific domains, and existing technologies are unable to effectively improve this.
The first model, pre-trained for the target domain, standardizes and rewrites the question to be answered. It then combines the target candidate text and the prompt text from the knowledge base to perform text concatenation and inputs it into the second model for analysis to obtain the answer information.
It improved the accuracy of large models in specific domains and enhanced the quality and relevance of the response information.
Smart Images

Figure CN118885579A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a question-answering method and device based on a large model. Background Art
[0002] At present, large models can mostly communicate and converse normally in general fields, but in specific fields, large models may have hallucination problems, and their knowledge performance is often poor and unsatisfactory.
[0003] Therefore, how to improve the accuracy of question answering in specific fields with large models has become an urgent problem to be solved. Summary of the invention
[0004] The embodiments of the present application provide a large-model-based question-answering method and device to solve the problem of low accuracy of large-model question-answering in specific fields in the prior art.
[0005] In a first aspect, the present application provides a question-answering method based on a large model, the method comprising:
[0006] Standardize and rewrite the question to be answered based on the first model pre-trained for the target field to obtain a standard question corresponding to the question to be answered;
[0007] Searching for target candidate text matching the standard question in the knowledge base;
[0008] The target candidate text, the standard question and the prompt text are concatenated to obtain input data, and the input data is input into the second largest model to obtain reply information, which is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
[0009] In a second aspect, the present application provides a question-answering device based on a large model, the device comprising:
[0010] A rewriting module, used for rewriting the question to be answered in a standardized manner based on a first large model pre-trained for the target field, to obtain a standard question corresponding to the question to be answered;
[0011] A retrieval module, used for searching the knowledge base for target candidate texts matching the standard question;
[0012] The reply module is used to perform text splicing on the target candidate text, the standard question and the prompt text to obtain input data, and input the input data into the second largest model to obtain reply information, wherein the reply information is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
[0013] In a third aspect, the present application also provides an electronic device, comprising a processor, wherein the processor is used to implement the steps of any of the above-mentioned large model-based question-answering methods when executing a computer program stored in a memory.
[0014] In a fourth aspect, the present application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned large model-based question-answering methods.
[0015] In the embodiment of the present application, the first large model pre-trained for the target field is used to perform standardized rewriting of the question to be answered, so as to obtain the standard question corresponding to the question to be answered, and the target candidate text matching the standard question is searched in the knowledge base, so as to obtain input data by text splicing the target candidate text, the standard question and the prompt text, and input the input data into the second large model, so that the second large model can acquire the knowledge of the target field, and obtain the answer information after analyzing the target candidate text and the standard question according to the requirements of the prompt text, thereby improving the accuracy of the large model in question and answering in specific fields. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only 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.
[0017] Figure 1 A schematic diagram of a RAG model in the prior art provided in an embodiment of the present application;
[0018] Figure 2 A flowchart of a question-answering process based on a large model provided in an embodiment of the present application;
[0019] Figure 3 A schematic diagram of a LoRA fine-tuning process provided in an embodiment of the present application;
[0020] Figure 4 A schematic diagram of a reward model provided in an embodiment of the present application;
[0021] Figure 5 A schematic diagram of word vector encoding provided in an embodiment of the present application;
[0022] Figure 6 A schematic diagram of a hybrid search process provided in an embodiment of the present application;
[0023] Figure 7A schematic diagram of a classification model structure provided in an embodiment of the present application;
[0024] Figure 8 A schematic diagram of word vector encoding of input data of a classification model provided in an embodiment of the present application;
[0025] Fig. 9 A schematic diagram of a target candidate text determination process provided in an embodiment of the present application;
[0026] Fig.10 A schematic diagram of a reply information determination process provided in an embodiment of the present application;
[0027] Fig.11 A schematic diagram of response information quality evaluation provided in an embodiment of the present application;
[0028] Fig.12 A schematic diagram of response information quality evaluation provided in an embodiment of the present application;
[0029] Fig.13 A schematic diagram of a question-answering process based on a large model provided in an embodiment of the present application;
[0030] Fig.14 A schematic diagram of the structure of a question-answering device based on a large model provided in an embodiment of the present application;
[0031] Fig.15 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the embodiment of the present application will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiment is only a part of the embodiment of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of this application.
[0033] Knowledge retrieval is the core process of the Retrieval-augmented Generation (RAG) model and the most important part of an enterprise knowledge management system. Its purpose is to ensure that users can find the information they need quickly and accurately. Figure 1 A schematic diagram of a RAG model in the prior art provided in an embodiment of the present application is shown in FIG. Figure 1As shown in the figure, the text is pre-divided into small segments, and then the Transformer encoder model, i.e., the embedding model, is used to convert these text segments into vector form, and the vectors are stored in the memory, and all the vectors are gathered into an index. Finally, a prompt word is formulated for the large language model (LLM), which will guide the LLM to answer the user's query based on the context information (context) searched in the database (Database). In the process of searching for context information, i.e., the process of knowledge retrieval, it generally includes basic retrieval processes and complex retrieval processes. Among them, the typical complex retrieval process includes steps such as pre-retrieval processing, knowledge retrieval, post-retrieval processing, and answer generation. Each retrieval step involves many technical details, and the basic retrieval process often omits the pre-retrieval processing and post-processing links, and the retrieval accuracy is not high. In order to improve the accuracy of question and answer, the embodiments of the present application provide a question and answer method, apparatus, device and medium based on a large model, in which the question to be answered is standardized and rewritten based on a first large model pre-trained for the target field to obtain a standard question corresponding to the question to be answered; a target candidate text matching the standard question is searched in the knowledge base; the target candidate text, the standard question and the prompt text are concatenated to obtain input data, and the input data is input into the second large model to obtain reply information, which is the text obtained by the second large model after analyzing the target candidate text and the standard question according to the requirements of the prompt text.
[0034] Figure 2 A flowchart of a question-answering process based on a large model is provided in an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:
[0035] S201: Standardize and rewrite the question to be answered based on the first largest model pre-trained for the target field to obtain a standard question corresponding to the question to be answered.
[0036] The large model-based question-answering method provided in this application is applied to an electronic device, which may be a server, a PC, a mobile terminal, etc.
[0037] The questions asked by the user may be too colloquial, and colloquial questions will reduce the accuracy of the retrieval. In this regard, the embodiment of the present application generalizes the user's questions to be answered, so that the user's questions to be answered are expressed more professionally. For example, the user's question to be answered is "How to repair the TV if the picture suddenly stops showing?" The standard question after standardizing and rewriting it can be "How to deal with the black screen of the TV?" or "How to repair the TV screen if it does not show the picture?" etc. The user's question to be answered is "How to repair the TV and computer if the picture suddenly stops showing?" The standard question after standardizing and rewriting it can be "How to deal with the black screen of the TV?", "How to deal with the black screen of the computer?", "How to repair the TV screen if it does not show the picture?", "How to repair the computer if it does not show the picture?".
[0038] When rewriting questions to be answered in a standardized manner, the simplest method is to maintain a synonym table and perform synonym replacement based on the synonym table. Generally, the search engine can identify common synonyms by calculating vector values. However, when the user's question contains professional vocabulary and synonyms in certain special fields, the search engine will not be able to accurately find relevant content from the synonym table. For example, the synonym of "flower screen" is "LCD screen failure". When the user's question to be answered is "What should I do if my TV has a flower screen?", the expected text matching in the knowledge base is related to the LCD screen failure. However, in the actual matching process, because "flower screen" and "LCD screen failure" belong to vocabulary in a specific field, when analyzing similarity, the search engine will not understand their relevance and may not match. Therefore, when there are synonyms in a question to be answered that cannot be identified by semantics, a synonym database can be maintained to ensure that the search engine can accurately retrieve relevant knowledge content.
[0039] Based on the above problems, although the synonym matching solution can quickly solve the problem, the user's questions to be answered are usually diverse, and it is usually impossible to enumerate them when building a synonym list. Therefore, in an embodiment of the present application, when the questions to be answered are standardized and rewritten, they can be standardized and rewritten based on the first large model. However, the current open source large models are all trained on wide-area data sets, lack knowledge in specific fields, and cannot achieve good results in specific fields. Therefore, in an embodiment of the present application, the general model can be trained in advance for the target field to obtain the first large model. Thereby, in the question-answering process based on the large model, the questions to be answered are standardized and rewritten based on the first large model to obtain the standard questions corresponding to the questions to be answered.
[0040] In the embodiments of the present application, the standardized rewriting of the question to be answered may include anaphora resolution, sub-query decomposition, and query rewriting. Among them, sub-query decomposition can be understood as splitting a question to be answered into multiple sub-questions, and query rewriting can be understood as performing standardized rewriting on the question to be answered.
[0041] S202: Search for the target candidate text that matches the standard question in the knowledge base.
[0042] After obtaining the standard question corresponding to the question to be answered, the target candidate text that matches the standard question can be searched for in the knowledge base. The target candidate text can be understood as the text related to the content included in the standard question. Among them, the knowledge base can be a database pre-stored for the target field, or an online network database. The knowledge base can include information such as documents and news.
[0043] S203: Concatenate the target candidate text, the standard question, and the prompt text to obtain the input data, and input the input data into the second large model to obtain the response information, where the response information is the text obtained by the second large model analyzing the target candidate text and the standard question according to the requirements of the prompt text.
[0044] After obtaining the target candidate text, the target candidate text, the standard question, and the prompt text can be concatenated to obtain the input data, and the input data can be input into the second large model, so that the second large model analyzes the target candidate text and the standard question according to the requirements of the prompt text to determine the response information.
[0045] In the embodiments of the present application, the input data obtained by concatenation may be in the following format:
[0046] '<Instruction>You are a Q&A assistant. Your current task is to use your expertise to answer questions based on the known information. If you cannot get the answer from it, please say "The question cannot be answered based on the known information",'
[0047] 'Do not allow fabricating content in the answer, and the answer should be in Chinese.< / Instruction>\n'
[0048] '<Known information>{{top-k_context}}< / Known information>\n'
[0049] '<Question>{{question}}< / Question>\n'.
[0050] In the above input data, "<instruction>... < / instruction>\n" represents the prompt text, "<known information>{{top-k_context}}< / known information>\n" represents the target candidate text, where {{top-k_context}} represents the specific content included in the target candidate text, and "<question>{{question}}< / question>\n" represents the standard question, where {{question}} represents the specific content included in the standard question.
[0051] During the experiment, it was learned that the attention characteristics of the large model for sentences are as follows: the large model pays more attention to the content at the head of the input to the model, and the model has a better understanding ability for the starting part of the paragraph. Therefore, in the embodiments of the present application, the input data can also be in the following format:
[0052] '<known information>{{top-k_context}}< / known information>\n'
[0053] '<question>{{question}}< / question>\n'
[0054] '<instruction>You are a Q&A assistant, and your current task is to answer questions based on the known information using your expertise. If you cannot obtain an answer from it, please say "The question cannot be answered based on the known information",'
[0055] 'Do not allow fabricated content in the answer, and the answer should be in Chinese.< / instruction>\n'.
[0056] According to the above content, it can be seen that in the embodiments of the present application, when performing text splicing, the splicing is performed in the order of the target candidate text, the standard question, and the prompt text to ensure that important information is located at the head of the data.
[0057] Since in the embodiments of the present application, a first large model pre-trained for the target domain is used to perform standardized rewriting on the question to be answered to obtain the standard question corresponding to the question to be answered, and the target candidate text matching the standard question is searched in the knowledge base, so as to splice the target candidate text, the standard question, and the prompt text to obtain the input data, and input the input data into the second large model, so that the second large model can obtain the knowledge of the target domain, and analyze the target candidate text and the standard question according to the requirements of the prompt text to obtain the answer information, improving the accuracy of the large model in answering questions in a specific domain.
[0058] The fine-tuning training process of the first large model trained for the target domain will be described below with a specific embodiment. In order to obtain the first large model trained for the target domain, in the embodiments of the present application, the general large model can be fine-tuned, and then the fine-tuned large model is evaluated using the reward model, and finally reinforcement learning fine-tuning is performed.
[0059] In an embodiment of the present application, supervised fine-tuning (SFT) training can be performed on an open source large model based on LoRA, such as the Qianwen large model. Figure 3 A schematic diagram of a LoRA fine-tuning process provided in an embodiment of the present application, in which the original weight (Pretrained Weights) parameter W is frozen during the LoRA fine-tuning process, and an additional ΔW is trained, where ΔW is composed of two matrices A and B. Initially, A is a random matrix and B is a matrix of all 0s. The LoRA fine-tuning process is training ΔW, which can be expressed as:
[0060] Y=(W+ΔW)X=(W+AB)X
[0061] According to the above formula, the parameters of LoRA fine-tuning training are matrix A and matrix B, and the original weight parameter W remains unchanged.
[0062] After the large model completes SFT training, the next stage is to build a reward model to score the question-answer pairs. In this stage, you can build a dataset as follows:
[0063] Eg: What should I do if the TV screen suddenly turns black?
[0064] Response1: What are the reasons and solutions for the TV to fail to display images and turn into a black screen?
[0065] Response2: What is the solution when TV cannot play?
[0066] The task of the reward model is to train a model with a pair of (prompt, response) and a reward score, which can be regarded as a classification or regression task. The reward model scores each text pair to evaluate the performance of the fine-tuned trained model. Compared with the model trained by SFT, the reward model adds a value head (Valuehead) at the end. The Value head can be regarded as a linear layer (Linear). The input dimension is the hidden_dim of the model, the output dimension is 1, and the output represents the score predicted by the model for each character. In other words, the input of the reward model is the question and the corresponding answer, and the output is a scalar score.
[0067] Figure 4 A schematic diagram of a reward model provided in an embodiment of the present application is shown in FIG. Figure 4As shown in the figure, the question-answer pair is input into the reward model, which adds a Value head based on the original model, and the final output is the score.
[0068] For example, x: question to be answered (What should I do if the TV screen suddenly turns black?)
[0069] y best : Output to get high reward standard problem (the reason why the TV cannot display the picture and turns black screen and the solution)
[0070] y worse : Output rewards are low (solution for TV not playing)
[0071] For each training sample (x,y best ,y worse ) can get the score best and score worse Among them, score best =r θ (x,y best ), which can be understood as the reward model for y best score worse =r θ (x,y worse ), which can be understood as the reward model for y worse 's scoring.
[0072] In the embodiment of the present application, it is only necessary to maximize the top-ranked outputs and the bottom-ranked outputs so that the model can distinguish good and bad outputs as much as possible. Training the Reward Model is actually a sorting task, and the loss function is:
[0073] loss = -log(σ(r θ (x,y best )-r θ (x,y worse )))
[0074] Among them, loss represents the loss value, σ represents the parameter to be optimized, and r θ (x,y best ) represents the reward model for y best Rating, r θ (x,y worse ) represents the reward model for y worse 's scoring.
[0075] It should be noted that the embodiment of the present application first completes the first step of SFT training, and then completes the training of this step of the reward model.
[0076] For example, assuming that the reward model has a maximum score of 5 points, when the reward model is scoring, y best =5,y worse = 1 is normalized to 0.8, and the loss is -log(0.8); when y best =5,y worse =4 is normalized to 0.2, and the loss is -log(0.2).
[0077] In the embodiment of the present application, the purpose of the loss function is to allow the model to distinguish between the top-ranked and bottom-ranked outputs as much as possible. In the third step of reinforcement learning, the reward model will play the role of the environment and give reward scores for the characters predicted by the model.
[0078] In the reinforcement learning fine-tuning stage, reinforcement learning helps train the large model so that it can generate more appropriate responses based on user prompts. In order to prevent the model from going astray during training updates, a reference model is set for correction. When fine-tuning reinforcement learning, the question to be answered X can be input into the initial large model and the currently fine-tuned large model, and the output texts y1 and y2 are obtained respectively. The text from the current strategy is passed to the reward model to obtain a scalar score rθ. The generated texts of the two models are compared to calculate the penalty term for the difference, which is usually designed as a scaling of the relative entropy (Kullback–Leibler, KL) between the output word distribution sequences. The reinforcement stage continuously optimizes parameter iterations to maximize the scoring function and minimize the data distribution of the two models. The specific loss function is as follows:
[0079]
[0080] Among them, objective(φ) represents the loss value, x represents the model input, y represents the model output, RL represents the reference model, which has no actual parameter meaning and is only used as a label. SFT represents the fine-tuning model, which also only serves to distinguish the model name. β is the data distribution modulation parameter between the two models, which can be set manually based on experience. r represents the reward model, and θ is the parameter that the reward model needs to be trained. E(x,y) represents the maximum expected value. Represents the probability that question x will get answer y through the reference model; π SFT (y|x) represents the probability of getting answer y for question x by fine-tuning the model.
[0081] It should be noted that the above-mentioned fine-tuning training process for the large model in the embodiment of the present application is only for ease of understanding. How to fine-tune the large model is a prior art and will not be described in detail in the embodiment of the present application.
[0082] In order to improve the efficiency of question answering, based on the above embodiment, in the embodiment of the present application, after obtaining the standard question corresponding to the question to be answered and before searching the knowledge base for the target candidate text matching the standard question, the method further includes:
[0083] Determining the target intent corresponding to the standard question based on the classification model;
[0084] The step of searching the knowledge base for target candidate text matching the standard question includes:
[0085] Search the target knowledge base corresponding to the target intent for target candidate texts that match the standard question.
[0086] Since the data stored in the knowledge base is generally large, in an embodiment of the present application, different knowledge bases can be saved in advance for different intentions. After determining the corresponding standard question to be answered, before searching the corresponding target candidate text in the knowledge base, the target intention corresponding to the standard question can be determined based on the classification model. When the target candidate text is determined, only the target knowledge base corresponding to the target intention is searched. In an embodiment of the present application, the classification model can be any model with classification capabilities, and the embodiment of the present application is not limited to this. The target intention can be to consult the weather, consult the policy, consult the vehicle, etc., and the embodiment of the present application is not limited to this. In addition, how to determine the target intention based on the classification model that has been trained is a prior art, and the embodiment of the present application will not go into details.
[0087] In order to obtain a classification model with higher accuracy, based on the above embodiments, in the embodiment of the present application, the classification model includes a feature extraction layer and a linear layer, and the training process of the classification model includes:
[0088] Obtain a word vector encoding and a label corresponding to the sample text, wherein the label is used to identify the standard intent of the sample text, and the word vector encoding includes a part-of-speech identifier for each character;
[0089] The word vector code and the label are input into the feature extraction layer, and the feature extraction layer determines the feature extraction focus according to the part-of-speech mark when extracting semantic features to obtain predicted semantic features;
[0090] Inputting the predicted semantic features into the linear layer to perform intent prediction, and obtaining a prediction probability corresponding to each preset intent;
[0091] Determine the target prediction probability corresponding to the standard intention according to the prediction probability corresponding to each preset intention;
[0092] A first loss value is determined according to the target prediction probability and preset control parameters, and the parameters of the classification model are adjusted according to the first loss value.
[0093] In an embodiment of the present application, in order to obtain a classification model with a higher accuracy, a sample set is pre-configured, and the classification model can be trained according to the sample text included in the sample set. In order to facilitate the subsequent training of the classification model, in addition to each sample, the sample set also includes the word vector encoding and label corresponding to each sample, wherein the word vector encoding is to convert the text content into a vector representation that is easy for electronic devices to recognize. The label is used to represent the standard intent of the corresponding sample text.
[0094] In the classification model, it is often the content words with practical meaning that determine the text category, while invalid words such as adjectives and stop words are often not decisive. Therefore, in the embodiment of the present application, the word vector encoding also includes the part-of-speech mark of each character. In order to improve the model's attention to content words and classification accuracy, the embodiment of the present application records the characters that may appear in the sample set in advance. The part-of-speech mark of the recorded characters that are not stop words or adjectives is 1, and the part-of-speech mark of the unrecorded characters is marked as 0, to prevent the classification model from paying too much attention to some useless words. Figure 5 A word vector encoding schematic diagram provided in an embodiment of the present application, such as Figure 5 As shown in , the word vector encoding includes position encoding, context encoding, character encoding and prominent importance encoding. Among them, the position encoding is used to identify the position of the corresponding character in the text. The context encoding is used to identify which text the corresponding character belongs to. The prior importance encoding is the part-of-speech identifier of the corresponding character. Figure 5 As shown, the part-of-speech tags corresponding to "TV black screen" and "processing" are both 1, which means that these two words are relatively important and need to be paid special attention to.
[0095] After obtaining the word vector code and label corresponding to the sample text, the word vector code and label can be input into the feature extraction layer of the classification model, and the feature extraction layer performs feature extraction on the received word vector code. Since the word vector code includes the part-of-speech mark of each character, the feature extraction layer can determine the focus of feature extraction according to the part-of-speech mark when extracting semantic features. For example, in the feature extraction process, based on the attention mechanism, more attention is paid to the semantics of the characters with the part-of-speech mark of 1, so as to obtain predicted semantic features. In an embodiment of the present application, the feature extraction layer can be regarded as a bidirectional encoder representation from Transformer (Bidirectional Encoder Representations from Transformers, BERT) model, of course, it can also be another model, and technicians in this field can configure it as needed.
[0096] After obtaining the predicted semantic features of the sample text, the predicted semantic features can be input into the linear layer for intent prediction. Since the classification includes several preset intents that are known, in an embodiment of the present application, the predicted probability corresponding to each preset intent can be obtained based on the linear layer.
[0097] In order to facilitate the determination of the loss value and thus adjust the parameters of the classification model, in the embodiment of the present application, the target prediction probability corresponding to the standard intent in the label of the sample text can be determined according to the prediction probability corresponding to each preset intent. In other words, it is determined what the classification model predicts the probability of the standard intent corresponding to the sample text during the intent recognition process.
[0098] After the target prediction probability is determined, a first loss value may be determined according to the target prediction probability and preset control parameters, and the parameters of the classification model may be adjusted according to the first loss value.
[0099] Specifically, there is often a sample imbalance problem in private datasets. At the same time, users’ statements are diverse, and there may be difficult examples such as Chinese inversion sentences. Therefore, in this case, the positive and negative samples and the difficult and easy classification samples are controlled in the loss function of this part. The first loss value can be calculated based on the following formula:
[0100] L obj =-a t ·(1-p t ) γ log(p t )
[0101] Among them, L obj represents the first loss value; p t represents the target prediction probability; a trepresents the control parameter of positive and negative samples. By setting α, the contribution of positive and negative samples to loss can be controlled; γ is the modulation coefficient, (1-p t ) γ To control how easy it is to distinguish each sample.
[0102] Among them, p t The calculation method of is as follows,
[0103]
[0104] p represents the probability value of the positive sample, and y=1 represents the label value of the positive sample.
[0105] In the embodiment of the present application, the predicted intent of the sample text can be determined according to the prediction probability corresponding to each preset intent. Figure 1 If the sample is the same as the sample, it can be determined as a positive sample, that is, y = 1. Then, at this time P t is the target prediction probability corresponding to the standard intent. If the predicted intent is inconsistent with the standard intent, it can be determined as a negative sample, that is, it belongs to the otherwise case. At this time, P t Then it is 1-the target prediction probability corresponding to the standard intention, that is, 1-p.
[0106] Among them, a t The calculation method is as follows:
[0107]
[0108] When the label y = 1, αt = α; when the label y = otherwise, αt = 1-α. The range of a is 0 to 1. At this time, we can control the contribution of positive and negative samples to the first loss value by setting α.
[0109] In order to further improve the accuracy of question answering, based on the above embodiments, in the embodiment of the present application, searching the knowledge base for a target candidate text matching the standard question includes:
[0110] Determining the similarity between the standard question and each text according to the first feature vector of the standard question and the second feature vector of each text in the knowledge base;
[0111] Determining a relevance score between the standard question and each text in the knowledge base based on a keyword search algorithm;
[0112] According to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question is determined.
[0113] In order to further improve the accuracy of question and answer, when retrieving target candidate texts, in an embodiment of the present application, a hybrid search can be performed.
[0114] The advantages of vector retrieval mainly include: high accuracy in searching for texts with complex semantics, high accuracy in understanding similar semantics, and multi-language understanding, i.e., cross-language understanding. For example, the accuracy of matching Chinese input with English is high, and it has high fault tolerance and can handle spelling errors and ambiguous descriptions.
[0115] Although vector search has obvious advantages in the above scenarios, it does not work well in some cases. For example: the accuracy of searching for the name of a person or object is not high, for example, the accuracy of searching for the name Zhang San is not high, the accuracy of searching for abbreviations or phrases is not high, and the accuracy of searching for IDs is not high, for example, the accuracy of searching for gpt-3.5-turbo and titan-xlarge-v1.01 is not high. The above shortcomings are precisely the advantages of traditional keyword search. For example, the traditional keyword search algorithm BM25 (Best Matching25) algorithm can achieve precise matching, such as precise matching of product names, names, product numbers, etc.; it can also achieve matching of a small number of characters. For example, the effect of vector search using a small number of characters is very poor, but many users are accustomed to only entering a few keywords.
[0116] Vector-based retrieval and keyword search have more advantages and disadvantages. Therefore, in the embodiment of the present application, when matching the target candidate text, the similarity between the standard question and each text is determined based on the first feature vector of the standard question and the second feature vector of each text in the knowledge base, that is, a vector search is performed in the knowledge base. At the same time, based on the keyword search algorithm, the correlation score between the standard question and each text in the knowledge base is determined, that is, a keyword search is performed in the knowledge base.
[0117] After obtaining the similarity and relevance score corresponding to each text in the knowledge base, the target candidate text in the knowledge base that matches the standard question can be determined. In the embodiment set of the present application, the text with the highest similarity and the text with the highest relevance score can be determined as the target candidate text that matches the standard question. The top-k texts with a similarity higher than a threshold value 1 and the top-k texts with a relevance score higher than a threshold value 2 can also be determined as target candidate texts.
[0118] Figure 6 A schematic diagram of a hybrid search process provided in an embodiment of the present application is shown in FIG. Figure 6As shown, when determining the target candidate text, after obtaining the user question, the feature vector of the user question can be determined based on the pre-trained embedding model, and the similarity between the feature vector and each feature vector in the vector database corresponding to the knowledge base can be determined, so as to obtain the top-K texts above the threshold. Among them, the vector database stores the feature vector corresponding to each text in the class knowledge base. At the same time, keyword retrieval is performed based on the user question and the text in the knowledge base. When performing keyword retrieval, the relevance score corresponding to each text can be determined based on the BM25 algorithm, so as to obtain the top-K texts above the threshold. The obtained top-K*2 texts are determined as the target candidate texts.
[0119] It should be noted that, since this stage is a rough sorting, the threshold set in the embodiment of the present application may be a low threshold.
[0120] In order to further improve the accuracy of question answering, based on the above embodiments, in the embodiment of the present application, determining the target candidate text matching the standard question in the knowledge base according to each similarity and each relevance score includes:
[0121] For each text in the knowledge base, determine a target score corresponding to the text according to the similarity, relevance score and preset weight corresponding to the text;
[0122] According to each of the target scores, target candidate texts are determined.
[0123] When determining the target candidate texts matching the standard question in the knowledge base according to each similarity and each relevance score, the target score corresponding to each text in the knowledge base can be determined according to the similarity, relevance score and preset weight corresponding to the text. And the target candidate text is determined according to each obtained target score.
[0124] Specifically, the target score corresponding to any text can be determined based on the following formula:
[0125] score result =α*score(BM25)+b*score(Embedding)
[0126] Among them, score result represents the target score; score(BM25) represents the relevance score, which is calculated based on the BM25 algorithm; score(Embedding) represents the similarity; α and b represent the preset weights, where α+b=1.
[0127] After determining the target score of each text in the knowledge base, all target scores can be sorted, and the top_k target score texts with the highest scores are selected as target candidate texts, which can be expressed as the following formula:
[0128] res = top_k(score result )
[0129] Among them, res represents the set of determined target candidate texts; top_k (score result ) means selecting the k texts with the highest scores among all target scores.
[0130] In order to further improve the accuracy of question answering, based on the above embodiments, in the embodiment of the present application, determining the target candidate text matching the standard question in the knowledge base according to each similarity and each relevance score includes:
[0131] Determining a first preset number of first candidate texts according to each of the similarities;
[0132] Determining a second preset number of second candidate texts according to each of the relevance scores;
[0133] The first candidate text and the second candidate text are deduplicated to obtain the target candidate text.
[0134] When determining the target candidate texts matching the standard question in the knowledge base according to each similarity and each relevance score, in an embodiment of the present application, a first preset number of first candidate texts can be determined according to each similarity. Specifically, according to each similarity, the top-K texts above the threshold θ are obtained as the first candidate texts, where K is the first preset number.
[0135] At the same time, according to each relevance score, a second preset number of second candidate texts is determined. Specifically, according to each relevance score, top-K texts above a threshold λ can be selected as second candidate texts, where K is the second preset number.
[0136] In the embodiment of the present application, the first preset number and the second preset number may be the same or different.
[0137] After the first candidate text and the second candidate text are acquired, these texts may be determined as target candidate texts.
[0138] However, since the first candidate text and the second candidate text usually contain the same text, in an embodiment of the present application, the first candidate text and the second candidate text can be deduplicated to obtain the target candidate text. In order to improve the efficiency of deduplication, in an embodiment of the present application, when each text is saved in the knowledge base, an identifier can be added to each text, and the identifier is used to uniquely identify the corresponding text. During deduplication, the text with the same identifier can be deduplicated without recalculating the text similarity, which improves the efficiency of deduplication.
[0139] Specifically, the target candidate text can be determined based on the following formula:
[0140] res=set(top k(score(BM25)) +top k(score(Embedding)) )
[0141] Among them, res represents the set of determined target candidate texts; top k(score(BM25)) Indicates the first candidate text; top k(score(Embedding)) Represents the second candidate text; set() performs deduplication processing on the first candidate text and the second candidate text.
[0142] In order to further improve the accuracy of question answering, based on the above embodiments, in the embodiment of the present application, after searching the knowledge base for a target candidate text matching the standard question, and before text splicing the target candidate text, the standard question and the prompt text, the method further includes:
[0143] Searching for target questions and target answer information matching the standard questions in a pre-collected error accumulation knowledge base;
[0144] Determine the candidate answer information corresponding to the target question in the error accumulation knowledge base and the target answer information as a third candidate text;
[0145] The target candidate text and the third candidate text are deduplicated to obtain a fourth candidate text, and the target candidate text is updated using the fourth candidate text.
[0146] Research has found that for some special questions, even through vector retrieval and keyword retrieval, it is impossible to retrieve matching candidate texts. Therefore, in an embodiment of the present application, an error accumulation knowledge base can be maintained in advance, and the error accumulation knowledge base stores question-answer pairs that often make mistakes. After determining the target candidate text, the error accumulation knowledge base can also be used to search for target questions and target answer information that match the standard questions. In other words, the standard question is compared with each question and answer in the error accumulation knowledge base to find matching target questions and target answer information. In an embodiment of the present application, matching can be based on vector retrieval, matching can be based on keyword retrieval, and matching can also be based on vector retrieval and keyword retrieval.
[0147] Since the purpose in the embodiment of the present application is to find candidate texts that can be used for reference related to the standard question, and the useful knowledge included in the question is usually less, therefore, in the embodiment of the present application, after determining the target question, the candidate answer information corresponding to the target question in the error accumulation knowledge base can be obtained. The content included in the candidate answer information may be questions related to the standard question. In the embodiment of the present application, the candidate answer information and the target answer information found in the error accumulation knowledge base can be determined as the third candidate text.
[0148] After the third candidate text is determined, the third candidate text can also be determined as the target candidate text, but since there may be duplicate texts in the existing target candidate text and the third candidate text, in the embodiment of the present application, the target candidate text and the third candidate text can be deduplicated to obtain a fourth candidate text, and the target candidate text can be updated using the fourth candidate text.
[0149] In order to further improve the accuracy of question answering, based on the above embodiments, in the embodiment of the present application, if there are multiple target candidate texts, after searching the knowledge base for the target candidate text matching the standard question, and before text splicing the target candidate text, the standard question and the prompt text, the method further includes:
[0150] Determining a similarity score between the standard question and each of the target candidate texts;
[0151] The target candidate texts are screened according to the similarity scores.
[0152] When there are multiple target candidate texts determined, since these target candidate texts may be determined based on different retrieval methods, the retrieval scoring criteria between different target candidate texts may be different, and all the target candidate texts cannot be directly combined and sorted based on the similarity score during retrieval. In an embodiment of the present application, it is necessary to combine and re-sort all the acquired target candidate texts based on a new sorting method, and screen them again during the re-sorting process to obtain target candidate texts with higher quality. In other words, after determining the target candidate texts, a refined screening is performed again before determining the input data. This method can reduce the number of characters in the input data, thereby improving the accuracy of the second largest model reply.
[0153] When performing refined screening, the similarity score between the standard question and each target candidate text may be determined, thereby screening the target candidate text according to each similarity score.
[0154] In a possible implementation, the score of whether the standard question matches the target candidate text can be calculated based on the rearrangement model, and all the calculated target candidate texts are sorted, and the target candidate texts with the lowest ranking are deleted, and only K target candidate texts are retained. Optionally, the rearrangement model can be BGE Re-Ranker, BGE Re-Ranker v2-M3, BGE Re-Ranker v2-Gemma-2B, etc., and those skilled in the art can configure it as needed.
[0155] In a possible implementation, it is also possible to determine whether the standard question is similar to each target candidate text based on a pre-trained classification model, thereby ranking the target candidate texts according to the degree of similarity. In an embodiment of the present application, the semantic features of each text can be extracted based on the BERT model, thereby predicting the relevance of the text based on the extracted semantic features. Figure 7 A schematic diagram of a classification model structure provided in an embodiment of the present application is shown in FIG. Figure 7 As shown in Figure 2, when training a classification model, the standard question and any target candidate text can be used as the input of the classification model. Figure 7 In the above, w1 and w2 represent the first text, such as the word feature vector corresponding to the standard question, and w3, w4, and w5 represent the word feature vector corresponding to the second text, such as the word feature vector corresponding to the target candidate text. "[CLS]" and "[SEP]" are used to identify and distinguish different texts. Figure 8 A schematic diagram of word vector encoding of input data of a classification model provided in an embodiment of the present application, such as Figure 8 As shown in , the input data of the classification model includes position encoding, context encoding and word encoding, such as Figure 8As shown in , the word encoding corresponds to the word encoding of two sentences, sentence 1 and sentence 2. The subsequent classification model can determine whether sentence 1 and sentence 2 are similar. In order for the classification model to know which word encodings belong to the same sentence, the input data also includes the upper and lower sentence encodings, such as Figure 8 As shown, the characters belonging to sentence 1 and the corresponding sentences are coded as 1, and the characters belonging to sentence 2 and the corresponding sentences are coded as 2.
[0156] The above input data is input into the BERT model to obtain the full-text semantic features output by the BERT model, and the full-text semantic features are input into the linear layer, which performs a binary classification judgment of "similar" or "dissimilar" based on the full-text semantic features. In order to further determine the similarity between the two corresponding texts, the Sigmoid activation function is used after the linear layer for mapping to determine the similarity between the two texts, and the output result is between 0 and 1.
[0157] When calculating the loss value, it can be calculated based on the following formula:
[0158]
[0159] Among them, NLL(x, y) and J CE represents the loss value; yi represents the label value, when two sentences are similar, yi=1, when they are not similar, yi=0; Represents the result value predicted by the classification model when two sentences are determined to be similar When not similar
[0160] The parameters of the classification model can then be adjusted based on the calculated loss value.
[0161] The process of determining the target candidate text is described below with reference to a specific embodiment. Fig. 9 A schematic diagram of a target candidate text determination process provided in an embodiment of the present application is shown in FIG. Fig. 9 As shown, when determining the target candidate text corresponding to the standard question, the candidate text set 1 matching the standard question can be queried in the knowledge base by hybrid retrieval, and the candidate text set 2 matching the standard question can be queried in the error accumulation knowledge base by hybrid retrieval. After obtaining the candidate text set 1 and the candidate text set 2, the texts included in the set can be deduplicated, and the remaining texts can be screened twice to obtain high-quality K texts as target candidate texts.
[0162] The following describes the process of determining the reply information in conjunction with another specific embodiment. Fig.10 A schematic diagram of a reply information determination process provided in an embodiment of the present application, such as Fig.10 As shown in FIG. 1 , after the target candidate texts are determined, the target candidate texts can be screened according to the similarity score between the standard question and each target candidate text to obtain the K target candidate texts with the highest similarity score. The K target candidate texts, the standard question and the designed prompt text are input into the LLM to obtain the reply information.
[0163] In order to further improve the accuracy of question and answer, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0164] Based on the third model, determine whether the reply information meets the quality requirements. If so, determine that the reply information passes the verification and outputs it; if not, determine that the reply information fails the verification and performs manual evaluation;
[0165] The quality requirement includes at least one of the following: the standard question matches the answer information, the answer information comes from the target candidate text, and the wording of the answer information is appropriate.
[0166] In order to further improve the accuracy of questions and answers, after obtaining the reply information, the quality of the obtained reply information can be verified. In the embodiment of the present application, it can be determined based on the third largest model whether the obtained reply information meets the quality requirements. If so, it is determined that the reply information verification is passed and output; if not, it is determined that the reply information verification fails and manual evaluation is required. In the embodiment of the present application, the quality requirements may include one or more of the following: the standard question matches the reply information, the reply information comes from the target candidate text, and the wording of the reply information is appropriate. That is to say, the third largest model is used to determine whether the user's standard question matches the reply information, the third largest model is used to determine whether the reply information output by the second largest model comes from the target candidate text, and the third largest model is used to determine whether the wording of the reply information output by the second largest model is reasonable, such as determining whether the reply information is harmless and positive, and determining whether the sentence of the reply information is fluent.
[0167] Specifically, the reply information can be obtained based on asynchronous or multi-threaded calls, and the reply information can be analyzed. When the large model is determined to have passed the verification, manual evaluation will no longer be performed, otherwise it will enter manual evaluation. Fig.11 A schematic diagram of a reply information quality evaluation provided in an embodiment of the present application is as follows: Fig.11As shown, after obtaining the reply information Out, the quality of the reply information can be evaluated based on the three large models GPT (Generative Pre-Trained) 1, GPT2 and GPT3. The reply information and the target candidate text can be input into GPT1 to determine whether the reply information comes from the target candidate text. The reply information and the standard question are input into GPT2 to determine whether the reply information matches the standard question. The reply information is input into GPT3 to determine whether the words in the reply information are appropriate. Fig.11 As shown, the verification results of GPT1, GPT2 and GPT3 are all 1, indicating that the verification is passed and the reply information can be directly output.
[0168] Fig.12 A schematic diagram of a reply information quality evaluation provided in an embodiment of the present application is as follows: Fig.12 As shown in Figure 2, the quality of the reply information Out is also evaluated based on the three GPT models. The input data of the three GPT models are Fig.11 The contents shown are consistent, and the embodiments of this application will not be repeated. Fig.12 As shown, the verification results of GPT1 and GPT3 are both 1, indicating that the verification is passed, while the verification result of GPT2 is 0, indicating that the verification is not passed. Then it can be determined that the final verification result of the reply information is not passed, and manual access is required for evaluation.
[0169] The following is a specific example to illustrate the question-answering process based on a large model. Fig.13 A schematic diagram of a question-answering process based on a large model provided in an embodiment of the present application is shown in FIG. Fig.13 As shown, the process mainly includes pre-processing, intent classification, hybrid retrieval and post-processing parts.
[0170] After obtaining the user's question, that is, obtaining the user's unanswered question, pre-processing can be performed. In the pre-processing stage, the unanswered question can be processed by reference resolution, sub-query decomposition, query rewriting, etc. based on the big model to obtain a standard question.
[0171] After obtaining the standard question, the classification model can be used to classify the intent of the standard question to obtain the target intent.
[0172] After the target intent is obtained, hybrid retrieval is performed. In the hybrid retrieval process, vector retrieval and keyword retrieval can be performed in the target knowledge base corresponding to the target intent to obtain the target candidate text.
[0173] After the target candidate texts are obtained, the target candidate texts are rearranged, and then secondary screening is performed according to the rearranged order to obtain the remaining target candidate texts.
[0174] After the final target candidate text is determined, the corresponding reply information can be generated based on the large model.
[0175] After receiving the reply information, it can be determined whether the reply information meets the quality requirements based on the third model.
[0176] The embodiment of the present application uses multiple means such as question rewriting, multi-way recall, hybrid retrieval, etc. to improve the accuracy of the RAG model, which can bring a 10% improvement in the accuracy of the query results.
[0177] Based on the same inventive concept, the embodiment of the present application also provides a question-answering device based on a large model. Fig.14 A schematic diagram of the structure of a question-answering device based on a large model provided in an embodiment of the present application, the device comprising:
[0178] A rewriting module 1401 is used to perform standardized rewriting of the question to be answered based on a first large model pre-trained for the target field, to obtain a standard question corresponding to the question to be answered;
[0179] A retrieval module 1402 is used to search for target candidate texts matching the standard question in the knowledge base;
[0180] The reply module 1403 is used to perform text splicing on the target candidate text, the standard question and the prompt text to obtain input data, and input the input data into the second largest model to obtain reply information, which is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
[0181] In a possible implementation, the retrieval module 1402 is specifically configured to determine a target intent corresponding to the standard question based on a classification model; and search for a target candidate text matching the standard question in a target knowledge base corresponding to the target intent.
[0182] In a possible implementation, the classification model includes a feature extraction layer and a linear layer, and the device further includes:
[0183] Training module 1404 is used to obtain the word vector code and label corresponding to the sample text, the label is used to identify the standard intent of the sample text, and the word vector code includes the part-of-speech identifier of each character; the word vector code and the label are input into the feature extraction layer, and the feature extraction layer determines the feature extraction focus according to the part-of-speech identifier when extracting semantic features to obtain predicted semantic features; the predicted semantic features are input into the linear layer for intent prediction to obtain the prediction probability corresponding to each preset intent; according to the prediction probability corresponding to each preset intent, the target prediction probability corresponding to the standard intent is determined; according to the target prediction probability and the preset control parameters, a first loss value is determined, and the parameters of the classification model are adjusted according to the first loss value.
[0184] In a possible implementation, the retrieval module 1402 is specifically used to determine the similarity between the standard question and each text based on the first feature vector of the standard question and the second feature vector of each text in the knowledge base; determine the relevance score between the standard question and each text in the knowledge base based on a keyword retrieval algorithm; and determine the target candidate text in the knowledge base that matches the standard question based on each similarity and each relevance score.
[0185] In a possible implementation, the retrieval module 1402 is specifically used to determine, for each text in the knowledge base, a target score corresponding to the text according to the similarity, relevance score and preset weight corresponding to the text; and determine a target candidate text according to each of the target scores.
[0186] In a possible implementation, the retrieval module 1402 is specifically used to determine a first preset number of first candidate texts based on each of the similarities; determine a second preset number of second candidate texts based on each of the relevance scores; and perform deduplication processing on the first candidate texts and the second candidate texts to obtain the target candidate text.
[0187] In a possible implementation, the retrieval module 1402 is also used to search for a target question and target answer information that match the standard question in a pre-collected error accumulation knowledge base; determine the candidate answer information corresponding to the target question in the error accumulation knowledge base, and the target answer information, as a third candidate text; deduplicate the target candidate text and the third candidate text to obtain a fourth candidate text, and use the fourth candidate text to update the target candidate text.
[0188] In a possible implementation, if there are multiple target candidate texts, the retrieval module 1402 is further configured to determine a similarity score between the standard question and each of the target candidate texts; and screen the target candidate texts according to the similarity score.
[0189] In a possible implementation, the device further includes:
[0190] The quality inspection module 1405 is used to determine whether the reply information meets the quality requirements based on the third model. If so, it is determined that the reply information has passed the verification and is output; if not, it is determined that the reply information has failed the verification and is manually evaluated; the quality requirements include at least one of the following: the standard question matches the reply information, the reply information comes from the target candidate text, and the wording of the reply information is appropriate.
[0191] Based on the same inventive concept, an embodiment of the present application further provides an electronic device, Fig.15 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Fig.15 As shown, it includes: a processor 1501, a communication interface 1502, a memory 1503 and a communication bus 1504, wherein the processor 1501, the communication interface 1502, and the memory 1503 communicate with each other through the communication bus 1504;
[0192] The memory 1503 stores a computer program. When the program is executed by the processor 1501, the processor 1501 performs the following steps:
[0193] Standardize and rewrite the question to be answered based on the first model pre-trained for the target field to obtain a standard question corresponding to the question to be answered;
[0194] Searching for target candidate text matching the standard question in the knowledge base;
[0195] The target candidate text, the standard question and the prompt text are concatenated to obtain input data, and the input data is input into the second largest model to obtain reply information, which is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
[0196] In a possible implementation, after obtaining the standard question corresponding to the question to be answered and before searching the knowledge base for target candidate text matching the standard question, the method further includes:
[0197] Determining the target intent corresponding to the standard question based on the classification model;
[0198] The step of searching the knowledge base for a target candidate text that matches the standard question includes:
[0199] Search the target knowledge base corresponding to the target intent for target candidate texts that match the standard question.
[0200] In a possible implementation, the classification model includes a feature extraction layer and a linear layer, and the training process of the classification model includes:
[0201] Obtain a word vector encoding and a label corresponding to the sample text, wherein the label is used to identify the standard intent of the sample text, and the word vector encoding includes a part-of-speech identifier for each character;
[0202] The word vector code and the label are input into the feature extraction layer, and the feature extraction layer determines the feature extraction focus according to the part-of-speech mark when extracting semantic features to obtain predicted semantic features;
[0203] Inputting the predicted semantic features into the linear layer to perform intent prediction, and obtaining a prediction probability corresponding to each preset intent;
[0204] Determine the target prediction probability corresponding to the standard intention according to the prediction probability corresponding to each preset intention;
[0205] A first loss value is determined according to the target prediction probability and preset control parameters, and the parameters of the classification model are adjusted according to the first loss value.
[0206] In a possible implementation, searching the knowledge base for a target candidate text matching the standard question includes:
[0207] Determining the similarity between the standard question and each text according to the first feature vector of the standard question and the second feature vector of each text in the knowledge base;
[0208] Determining a relevance score between the standard question and each text in the knowledge base based on a keyword search algorithm;
[0209] According to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question is determined.
[0210] In a possible implementation, determining the target candidate text matching the standard question in the knowledge base according to each of the similarities and each of the relevance scores includes:
[0211] For each text in the knowledge base, determine a target score corresponding to the text according to the similarity, relevance score and preset weight corresponding to the text;
[0212] According to each of the target scores, target candidate texts are determined.
[0213] In a possible implementation, determining the target candidate text matching the standard question in the knowledge base according to each of the similarities and each of the relevance scores includes:
[0214] Determining a first preset number of first candidate texts according to each of the similarities;
[0215] Determining a second preset number of second candidate texts according to each of the relevance scores;
[0216] The first candidate text and the second candidate text are deduplicated to obtain the target candidate text.
[0217] In a possible implementation, after searching the knowledge base for a target candidate text that matches the standard question and before text splicing the target candidate text, the standard question, and the prompt text, the method further includes:
[0218] Searching for target questions and target answer information matching the standard questions in a pre-collected error accumulation knowledge base;
[0219] Determine the candidate answer information corresponding to the target question in the error accumulation knowledge base and the target answer information as a third candidate text;
[0220] The target candidate text and the third candidate text are deduplicated to obtain a fourth candidate text, and the target candidate text is updated using the fourth candidate text.
[0221] In a possible implementation manner, if there are multiple target candidate texts, after searching the knowledge base for a target candidate text matching the standard question and before text splicing the target candidate text, the standard question, and the prompt text, the method further includes:
[0222] Determining a similarity score between the standard question and each of the target candidate texts;
[0223] The target candidate texts are screened according to the similarity scores.
[0224] In a possible implementation, the method further includes:
[0225] Based on the third model, determine whether the reply information meets the quality requirements. If so, determine that the reply information passes the verification and outputs it; if not, determine that the reply information fails the verification and performs manual evaluation;
[0226] The quality requirement includes at least one of the following: the standard question matches the answer information, the answer information comes from the target candidate text, and the wording of the answer information is appropriate.
[0227] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 1502 is used for communication between the above electronic device and other devices. The memory may include a random access memory (RAM) and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0228] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0229] On the basis of the above embodiments, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program executable by a processor is stored. When the program runs on the processor, the processor implements the following steps when executing:
[0230] Standardize and rewrite the question to be answered based on the first model pre-trained for the target field to obtain a standard question corresponding to the question to be answered;
[0231] Searching for target candidate text matching the standard question in the knowledge base;
[0232] The target candidate text, the standard question and the prompt text are concatenated to obtain input data, and the input data is input into the second largest model to obtain reply information, which is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
[0233] In a possible implementation, after obtaining the standard question corresponding to the question to be answered and before searching the knowledge base for target candidate text matching the standard question, the method further includes:
[0234] Determining the target intent corresponding to the standard question based on the classification model;
[0235] The step of searching the knowledge base for a target candidate text that matches the standard question includes:
[0236] Search the target knowledge base corresponding to the target intent for target candidate texts that match the standard question.
[0237] In a possible implementation, the classification model includes a feature extraction layer and a linear layer, and the training process of the classification model includes:
[0238] Obtain a word vector encoding and a label corresponding to the sample text, wherein the label is used to identify the standard intent of the sample text, and the word vector encoding includes a part-of-speech identifier for each character;
[0239] The word vector code and the label are input into the feature extraction layer, and the feature extraction layer determines the feature extraction focus according to the part-of-speech mark when extracting semantic features to obtain predicted semantic features;
[0240] Inputting the predicted semantic features into the linear layer to perform intent prediction, and obtaining a prediction probability corresponding to each preset intent;
[0241] Determine the target prediction probability corresponding to the standard intention according to the prediction probability corresponding to each preset intention;
[0242] A first loss value is determined according to the target prediction probability and preset control parameters, and the parameters of the classification model are adjusted according to the first loss value.
[0243] In a possible implementation, searching the knowledge base for a target candidate text matching the standard question includes:
[0244] Determining the similarity between the standard question and each text according to the first feature vector of the standard question and the second feature vector of each text in the knowledge base;
[0245] Determining a relevance score between the standard question and each text in the knowledge base based on a keyword search algorithm;
[0246] According to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question is determined.
[0247] In a possible implementation, determining the target candidate text matching the standard question in the knowledge base according to each of the similarities and each of the relevance scores includes:
[0248] For each text in the knowledge base, determine a target score corresponding to the text according to the similarity, relevance score and preset weight corresponding to the text;
[0249] According to each of the target scores, target candidate texts are determined.
[0250] In a possible implementation, determining the target candidate text matching the standard question in the knowledge base according to each of the similarities and each of the relevance scores includes:
[0251] Determining a first preset number of first candidate texts according to each of the similarities;
[0252] Determining a second preset number of second candidate texts according to each of the relevance scores;
[0253] The first candidate text and the second candidate text are deduplicated to obtain the target candidate text.
[0254] In a possible implementation, after searching the knowledge base for a target candidate text that matches the standard question and before text splicing the target candidate text, the standard question, and the prompt text, the method further includes:
[0255] Searching for target questions and target answer information matching the standard questions in a pre-collected error accumulation knowledge base;
[0256] Determine the candidate answer information corresponding to the target question in the error accumulation knowledge base and the target answer information as a third candidate text;
[0257] The target candidate text and the third candidate text are deduplicated to obtain a fourth candidate text, and the target candidate text is updated using the fourth candidate text.
[0258] In a possible implementation manner, if there are multiple target candidate texts, after searching the knowledge base for a target candidate text matching the standard question and before text splicing the target candidate text, the standard question, and the prompt text, the method further includes:
[0259] Determining a similarity score between the standard question and each of the target candidate texts;
[0260] The target candidate texts are screened according to the similarity scores.
[0261] In a possible implementation, the method further includes:
[0262] Based on the third model, determine whether the reply information meets the quality requirements. If so, determine that the reply information passes the verification and outputs it; if not, determine that the reply information fails the verification and performs manual evaluation;
[0263] The quality requirement includes at least one of the following: the standard question matches the answer information, the answer information comes from the target candidate text, and the wording of the answer information is appropriate.
[0264] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0265] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0266] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0267] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0268] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A question-answering method based on a large model, characterized in that: The method comprises: Standardize and rewrite the question to be answered based on the first model pre-trained for the target field to obtain a standard question corresponding to the question to be answered; Searching for target candidate text matching the standard question in the knowledge base; The target candidate text, the standard question and the prompt text are concatenated to obtain input data, and the input data is input into the second largest model to obtain reply information, which is the text obtained after the second largest model analyzes the target candidate text and the standard question according to the requirements of the prompt text.
2. The method according to claim 1, characterized in that: After obtaining the standard question corresponding to the question to be answered and before searching the knowledge base for target candidate text matching the standard question, the method further includes: Determining the target intent corresponding to the standard question based on the classification model; The step of searching the knowledge base for a target candidate text that matches the standard question includes: Search the target knowledge base corresponding to the target intent for target candidate texts that match the standard question.
3. The method according to claim 2, characterized in that The classification model includes a feature extraction layer and a linear layer, and the training process of the classification model includes: Obtain a word vector encoding and a label corresponding to the sample text, wherein the label is used to identify the standard intent of the sample text, and the word vector encoding includes a part-of-speech identifier for each character; The word vector code and the label are input into the feature extraction layer, and the feature extraction layer determines the feature extraction focus according to the part-of-speech mark when extracting semantic features to obtain predicted semantic features; Inputting the predicted semantic features into the linear layer to perform intent prediction, and obtaining a prediction probability corresponding to each preset intent; Determine the target prediction probability corresponding to the standard intention according to the prediction probability corresponding to each preset intention; A first loss value is determined according to the target prediction probability and preset control parameters, and the parameters of the classification model are adjusted according to the first loss value.
4. The method according to claim 1 or 2, characterized in that: The step of searching the knowledge base for a target candidate text that matches the standard question includes: Determining the similarity between the standard question and each text according to the first feature vector of the standard question and the second feature vector of each text in the knowledge base; Determining a relevance score between the standard question and each text in the knowledge base based on a keyword search algorithm; According to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question is determined.
5. The method according to claim 4, characterized in that The step of determining, according to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question comprises: For each text in the knowledge base, determine a target score corresponding to the text according to the similarity, relevance score and preset weight corresponding to the text; According to each of the target scores, target candidate texts are determined.
6. The method according to claim 4, characterized in that The step of determining, according to each of the similarities and each of the relevance scores, a target candidate text in the knowledge base that matches the standard question comprises: Determining a first preset number of first candidate texts according to each of the similarities; Determining a second preset number of second candidate texts according to each of the relevance scores; The first candidate text and the second candidate text are deduplicated to obtain the target candidate text.
7. The method according to claim 1, characterized in that After searching the knowledge base for a target candidate text that matches the standard question and before text splicing the target candidate text, the standard question, and the prompt text, the method further includes: Searching for target questions and target answer information matching the standard questions in a pre-collected error accumulation knowledge base; Determine the candidate answer information corresponding to the target question in the error accumulation knowledge base and the target answer information as a third candidate text; The target candidate text and the third candidate text are deduplicated to obtain a fourth candidate text, and the target candidate text is updated using the fourth candidate text.
8. The method according to claim 1, characterized in that If there are multiple target candidate texts, after searching the knowledge base for target candidate texts matching the standard question and before text splicing the target candidate texts, the standard question and the prompt text, the method further includes: Determining a similarity score between the standard question and each of the target candidate texts; The target candidate texts are screened according to the similarity scores.
9. The method according to claim 1, characterized in that: The method further comprises: Based on the third model, determine whether the reply information meets the quality requirements. If so, determine that the reply information passes the verification and outputs it; if not, determine that the reply information fails the verification and performs manual evaluation; The quality requirement includes at least one of the following: the standard question matches the answer information, the answer information comes from the target candidate text, and the wording of the answer information is appropriate.
10. An electronic device, characterized in that: The electronic device comprises a processor, and the processor is used to implement the steps of the large model-based question-answering method as described in any one of claims 1 to 9 when executing a computer program stored in a memory.
Citation Information
Patent Citations
Online intelligent question answering method and device based on instruction fine tuning and retrieval enhancement generation
CN117688163A
Government affair intelligent response device and method based on intention recognition and large language model
CN118035419A
Steel industry intelligent question and answer method and device based on large model and medium
CN118051587A
Question and answer method and device, equipment and storage medium
CN118051592A
Cited By
Question and answer method and system based on large model, computer equipment and storage medium
CN119474278A
Question and answer method and device based on large model, storage medium and electronic equipment
CN119848222A
A Question Answering Method, Device, Storage Medium and Electronic Device Based on a Large Model
CN119848222B
Event content proofreading method and device based on large model and storage medium
CN120145075A
Event content verification method, apparatus and storage medium based on large model
CN120145075B
