Question and answer task processing method and device based on large language model

By creating a question-background cache library and vector space in a large language model, combining the correlation recognition model and external knowledge base, the problem of inefficient answer generation in question-answer tasks is solved, and efficient answer generation for similar questions and diversity answer provision is achieved.

CN120371965APending Publication Date: 2025-07-25BEIJING DP TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510467303.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The existing large language model needs to search massive information on the external knowledge base in question-and-answer tasks, which makes it difficult to improve the efficiency of answer generation, especially for questions that have been answered or similar questions.

Method used

Select a generative large language model and design a correlation recognition model, create a question-background cache library and vector space, improve answer generation efficiency through embedding encoding and correlation verification, and use a combination of cache library and external knowledge base to generate answers.

Benefits of technology

Improves the efficiency of answer generation of previously answered questions or similar questions and increases the diversity of answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371965A_ABST
    Figure CN120371965A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a question and answer task processing method and device based on a large language model, and the method comprises the steps: selecting a generative large language model as a working model, designing a correlation recognition model, and training the correlation recognition model; creating a question-background cache library by performing data acquisition on historical question and answer tasks of the working model, and creating a corresponding question-background vector space for the question-background cache library; then, carrying out embedded coding on a current question input by a user, and carrying out background sample retrieval according to an embedded vector, a vector space and a cache library; if the sample set is empty, the current context is obtained by retrieving an external knowledge base, and if the sample set is not empty, background documents are generated and verified through the working model and the correlation recognition model so as to obtain the current context, and a cache library and a vector space are updated according to the current problem and the context; and performing answer prediction by the working model according to the current question and the context. According to the invention, the answer generation efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and particularly to a method and device for processing question-and-answer tasks based on large language models. Background Art

[0002] Large Language Models (LLMs) can perform various Natural Language Processing (NLP) tasks, such as text generation tasks, question-and-answer tasks, etc. Under normal circumstances, when an LLM model processes a question-and-answer task, it will first retrieve several documents related to the current question from an external knowledge base as the context information (also known as background documents) for this task, and then predict the answer based on the current question and the background documents. The limitation of this conventional method is that even for questions that have been answered or new questions similar to historical questions, it still needs to perform a round of massive information retrieval on the external knowledge base, making it difficult to significantly improve the efficiency of answer generation. Summary of the Invention

[0003] The purpose of the present invention is to provide a method, device, electronic device, and computer-readable storage medium for processing question-and-answer tasks based on large language models in view of the defects of the prior art. The present invention first selects a pre-trained and NLP task-trained generative large language model as the working model, and designs a relevance recognition model for binary classification recognition of the relevance of the model input text and trains it; then creates a question-background cache library by collecting data on the questions and background documents of the historical question-and-answer tasks of the working model, and synchronously creates a corresponding question-background vector space based on the question-background cache library; then receives the question text input by the user as the current question, embeds and encodes the current question according to the embedding encoding rule of the working model, and performs background sample retrieval according to the embedding vector, the question-background vector space, and the question-background cache library. When the sample set is empty, the working model retrieves the external knowledge base based on the current question to obtain the current context. When the sample set is not empty, the working model generates background documents according to the current question and the sample set, and the relevance recognition model verifies the relevance between the generated document and the current question. When the verification passes, the generated document of this time is used as the current context, and the question-background cache library and the question-background vector space are updated according to the current question and the current context. The working model predicts the answer according to the current question and the current context and feeds back the prediction result to the current user. Through the present invention, on the one hand, the efficiency of answer generation can be improved when facing questions that have been answered or new questions similar to historical questions, and on the other hand, the diversity of the text can be improved when generating answers.

[0004] To achieve the above object, a first aspect of an embodiment of the present invention provides a method for processing question-answering tasks based on large language models, the method comprising:

[0005] Select a generative large language model that has completed pre-training and NLP task training as the working model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on a preset first data set; the NLP tasks include at least text generation tasks and question-answering tasks;

[0006] Create a question-background cache library by collecting data on the questions and background documents of the historical question-answering tasks of the working model; and synchronously create a corresponding question-background vector space based on the question-background cache library;

[0007] Receive the question text input by the user as the current question;

[0008] Perform embedding encoding on the current question according to the embedding encoding rule of the working model to obtain a corresponding first embedding vector; and perform background sample retrieval based on the first embedding vector, the question-background vector space, and the question-background cache library to obtain a corresponding first sample set;

[0009] Identify whether the first sample set is empty; if so, retrieve the corresponding current context from the external knowledge base by the working model based on the current question; if not, generate a background document by the working model according to the current question and the first sample set, and verify the relevance between the generated document and the current question by the relevance recognition model, and use the generated document of the current time as the corresponding current context when the verification passes;

[0010] Perform a first update on the question-background cache library and the question-background vector space according to the current question and the current context;

[0011] Have the working model predict an answer according to the current question and the current context and feedback the prediction result to the current user.

[0012] Preferably, the working model includes at least GPT series models, BERT series models, T5 series models, LLaMA series models, and Wenxin series models;

[0013] The relevance recognition model is used to perform binary classification recognition on the relevance between the input text T1 of the model and each text T in the text sequence {T 2,i} and output a corresponding recognition sequence {R 2,i}; 1 ≤ text index i ≤ N i}T , N T The total number of texts in the text sequence {T 2,i}}; The recognition sequence {R i}} includes multiple recognition states R i ; The recognition state R i corresponds one-to-one with the text T 2,i ; The recognition state R i includes two types of states: relevant and irrelevant;

[0014] The first data set includes a first training text set and a first label set; The first training text set includes multiple training texts x tr ; The total number of training texts in the first training text set is denoted as the total number N tr ; The first label set includes N tr × (N tr - 1) first relevance labels 1 ≤ index j ≤ N tr 、1 ≤ index k ≤ N tr 、k ≠ j; The label value of the first relevance label is 0 or 1; Each of the first relevance labels is used to mark the relevance between the j-th training text and the k-th training text , a label value of 0 indicates irrelevance, and a value of 1 indicates relevance;

[0015] The question-background cache library includes multiple first cache records; The first cache record includes a first question text, a first background document, a first question vector, a first background vector, and a first fusion vector; The first question text and the first background document are the question original text and background context of a Q&A task that the working model has processed; The first question vector is an embedded encoding vector obtained by embedding and encoding the first question text based on the embedded encoding rules of the working model; The first background vector is an embedded encoding vector obtained by embedding and encoding the first background document based on the embedded encoding rules of the working model; The first fusion vector is a fusion vector obtained by fusing the first question vector and the first background vector based on a preset feature fusion method, and the feature fusion method at least includes vector concatenation method, weighted summation method, element-wise multiplication method, cross-attention method; The vector feature dimensions of the first question vector, the first background vector, and the first fusion vector are all consistent with the embedded encoding vector feature dimensions specified by the embedded encoding rules of the working model;

[0016] The spatial dimension of the problem-background vector space is consistent with the feature dimension of the embedding encoding vector specified by the embedding encoding rule of the working model; the problem-background vector space includes multiple spatial point aggregation clusters; each of the spatial point aggregation clusters is aggregated by one or more vector space points; each spatial point aggregation cluster corresponds to a virtual aggregation cluster centroid point; the vector space points of the problem-background vector space correspond one-to-one with the first fusion vectors of the problem-background cache library; each aggregation cluster centroid point corresponds to the mean vector of all the first fusion vectors of all the vector space points of the current spatial point aggregation cluster.

[0017] Preferably, the model input end of the correlation recognition model is used to receive the text T1 and the text sequence {T 2,i}, and the model input end is used to output the corresponding recognition sequence {R i};

[0018] The correlation recognition model includes an embedding encoding module, a feature extraction network, an MLP model, a Softmax function layer, and a recognition output module;

[0019] The input end of the embedding encoding module is connected to the model input end, and the output end is connected to the input end of the feature extraction network; the output end of the feature extraction network is connected to the input end of the MLP model; the output end of the MLP model is connected to the input end of the Softmax function layer; the output end of the Softmax function layer is connected to the input end of the recognition output module; the output end of the recognition output module is connected to the model output end;

[0020] The embedding encoding module is used to perform word segmentation processing on the text T1 according to a preset word segmentation rule to obtain a corresponding word segmentation sequence S1, and perform word segmentation processing on each text T 2,i} in the text sequence {T 2,i} to obtain a corresponding word segmentation sequence S 2,i ; and perform sequence splicing on the word segmentation sequence S1 and each word segmentation sequence S 2,I to obtain a corresponding word segmentation sequence S 3,i ; and perform embedding encoding on each word segmentation sequence S 3,i according to a preset embedding encoding rule to obtain a corresponding embedding encoding vector e i ; and form a corresponding embedding encoding tensor E{e i} from all the obtained embedding encoding vectors e i and send it to the feature extraction network;

[0021] The feature extraction network is implemented based on the CNN network, the ResNet network, or the Encoder model of the Transformer framework; the feature extraction network is used to perform feature encoding processing on the embedded encoding tensor E{e i} to obtain the corresponding feature encoding tensor X{x i} and send it to the MLP model; the feature encoding tensor X{x i} is composed of multiple feature encoding vectors x i , and the feature encoding vector x i corresponds one-to-one with the embedded encoding vector e i ;

[0022] The MLP model is composed of multiple layers of linear activation layers connected together, and each layer of the linear activation layer consists of a linear layer and a non-linear activation function; the non-linear activation function at least includes the ReLU activation function; the MLP model is used to convert the feature encoding tensor X{x i} of high-dimensional features into a low-dimensional feature tensor Y{y i} with a feature dimension of 2 and send it to the Softmax function layer; the low-dimensional feature tensor Y{y i} includes multiple low-dimensional feature vectors y i , and the low-dimensional feature vector y i is composed of two vector data; the low-dimensional feature vector y i corresponds one-to-one with the feature encoding vector x i ;

[0023] The Softmax function layer uses the Softmax function to calculate the probability distribution of each low-dimensional feature vector y i of the low-dimensional feature tensor Y{y i} to obtain the corresponding probability distribution tensor P{p i} and send it to the recognition output module; the probability distribution tensor P{p i} includes multiple probability distribution vectors p i , and the probability distribution vector p i corresponds one-to-one with the low-dimensional feature vector y i ; the probability distribution vector p i is composed of two classification probabilities ρ i,1 , ρ i,2 , and the two classification types corresponding to the classification probabilities ρ i,1 , ρ i,2 are relevant and irrelevant respectively, and ρ i,1 + ρ i,2 = 1;

[0024] The recognition output module is used to output the probability distribution tensor P{pi each of the probability distribution vectors p i in is used as the corresponding recognition status R for the classification type corresponding to the maximum probability value i ; and all the obtained recognition statuses R i are used to form the corresponding recognition sequence {R i} and output it.

[0025] Preferably, training the correlation recognition model based on a preset first data set specifically includes:

[0026] Step 41, dividing the first label set of the first data set into two sub-data sets denoted as the corresponding first training set and first evaluation set based on a preset first division ratio;

[0027] Among them, both the first training set and the first evaluation set are composed of multiple first correlation labels ; the total number of labels in the first training set is denoted as N1, the total number of labels in the first evaluation set is denoted as N2, and N1 + N2 = N tr , and the ratio N1:N2 of the total number of labels N1 and N2 satisfies the first division ratio;

[0028] Step 42, denoting each of the first correlation labels in the first training set as the corresponding label and denoting the two training texts x corresponding to each label tr as the corresponding text and denoting the (N1 - 1) texts corresponding to each text as the text and forming a corresponding text sequence from the (N1 - 1) texts and setting a corresponding label probability vector for each label where 1 ≤ index j ≤ N1, 1 ≤ index k

[0029] ≤ N1, k * ≤ N1, k * ≠ j * ; the total number of the labels * is N1 × (N1 - 1); the label probability vector is composed of two classification label probabilities ; if the label is 0 then if the label is 1 then if the label

[0030] Step 43: Take each of the above texts and its corresponding text sequence as the corresponding text T1 and text sequence {T 2,i} and input them into the relevance recognition model for processing; and during this processing, record each probability distribution vector p i of the probability distribution tensor P{p i} output by the Softmax function layer of the relevance recognition model as the corresponding predicted probability vector And from each of the above predicted probability vectors and its corresponding label probability vector form a corresponding first prediction-label pair

[0031] wherein, the predicted probability vector is composed of two classification prediction probabilities ;

[0032] Step 44: Input the obtained N1×(N1 - 1) first prediction-label pairs into the preset model loss function L A ; and based on the preset model optimizer, modulate the model parameters of the relevance recognition model in the direction of minimizing the model loss function L A for one round;

[0033] wherein, the model loss function L A is implemented based on the binary cross-entropy loss function, specifically:

[0034]

[0035] The model optimizer includes at least the Adam optimizer and the SGD optimizer;

[0036] Step 45: Record each of the first relevance labels of the first evaluation set as the corresponding label and record the two training texts x corresponding to each of the above labels tr as the corresponding text and record the (N2 - 1) texts corresponding to each of the above texts as text and form a text sequence from the (N2 - 1) texts ; and set a corresponding label probability vector for each of the above labels and ​

[0037] Among them, 1 ≤ index j' ≤ N2, 1 ≤ index k' ≤ N2, and k' ≠ j'; the said label The total number is N2×(N2 - 1); the said label probability vector Consists of two corresponding classification label probabilities Composition, the said label If it is 0, then The said label If it is 1, then

[0038] Step 46, take each of the said texts And its corresponding said text sequence As the corresponding said text T1 and the text sequence {T 2,i} Input the relevance recognition model for processing; and during this processing, the probability distribution tensor P{p i} of each of the probability distribution vectors p i Is recorded as the corresponding predicted probability vector And by each of the said predicted probability vectors And its corresponding said label probability vector Form a corresponding second prediction-label pair

[0039] Among them, the said predicted probability vector Consists of two classification prediction probabilities Composition;

[0040] Step 47, bring the obtained N2×(N2 - 1) second prediction-label pairs Into the preset model evaluation function F A Perform calculations to obtain the corresponding first evaluation value;

[0041] Among them, the model evaluation function F A Is implemented based on the RMSE function, specifically:

[0042]

[0043] Step 48, identify whether the first evaluation value meets the preset first evaluation value range; if not, return to step 42 to continue training; if so, confirm that the model training of the relevance recognition model ends.

[0044] Preferably, synchronously create a corresponding question-background vector space based on the question-background cache library, specifically including:

[0045] Initialize a corresponding multi-dimensional vector space, denoted as the corresponding problem-background vector space, based on the embedding coding vector feature dimension specified by the embedding coding rule of the working model; and set a corresponding vector space point in the problem-background vector space for each of the first fusion vectors in the problem-background cache library; and perform a clustering operation on all the vector space points based on a preset spatial point clustering algorithm to obtain corresponding multiple spatial point aggregation clusters; and calculate a mean vector for all the first fusion vectors corresponding to each spatial point aggregation cluster to obtain a corresponding first mean vector, and use the corresponding point of the current first mean vector in the problem-background vector space as the centroid point of the corresponding spatial point aggregation cluster; the spatial point clustering algorithm includes at least k-means clustering algorithm, hierarchical clustering algorithm, and DBSCAN clustering algorithm.

[0046] Preferably, the retrieving the corresponding first sample set according to the first embedding vector, the problem-background vector space, and the problem-background cache library specifically includes:

[0047] Step 61, denote the corresponding point of the first embedding vector in the problem-background vector space as the current point; and calculate the point distance between the current point and the centroid points of each spatial point aggregation cluster to obtain corresponding first distances; and use the smallest of the first distances as the corresponding current minimum distance;

[0048] Step 62, identify whether the current minimum distance exceeds a preset distance threshold;

[0049] Step 63, if the current minimum distance exceeds the distance threshold, set the corresponding first sample set to be empty;

[0050] Step 64, if the current minimum distance does not exceed the distance threshold, denote the spatial point aggregation cluster corresponding to the current minimum distance as the matching aggregation cluster; and randomly select a specified number M of vector space points from within the matching aggregation cluster to form a corresponding sample point set; and extract the first background documents of the first cache records corresponding to each vector space point in the sample point set from the problem-background cache library as a corresponding first sample document, and form the corresponding first sample set with all the obtained first sample documents; the specified number M is a preset positive integer;

[0051] Step 65, output the obtained first sample set as the result of this background sample retrieval.

[0052] Preferably, the current context corresponding to the external knowledge base retrieved by the working model based on the current problem specifically includes:

[0053] Step 71, set the first problem configuration parameter of the preset first instruction template to the current problem, and use the first instruction template set this time as the corresponding first instruction text;

[0054] The first instruction template is a formatted instruction text template; the configurable parameters of the first instruction template include the first problem configuration parameter; the first instruction template is used to use the first problem configuration parameter as the corresponding current problem, and prompt the target model to generate a background document for answering the current problem by retrieving the external knowledge base;

[0055] Step 72, input the first instruction text into the working model for processing, and use the generated text output by the model this time as the corresponding current context.

[0056] Preferably, the background document is generated by the working model according to the current problem and the first sample set, and the relevance identification model verifies the relevance between the generated document and the current problem, and when the verification passes, use the generated document of the current time as the corresponding current context, specifically including:

[0057] Step 81, set the second problem configuration parameter and the sample set configuration parameter of the preset second instruction template to the corresponding current problem and the first sample set, and use the second instruction template set this time as the corresponding second instruction text;

[0058] The second instruction template is a formatted instruction text template; the configurable parameters of the second instruction template include the second problem configuration parameter and the sample set configuration parameter; the second instruction template is used to use the second problem configuration parameter as the corresponding current problem, use the sample set configuration parameter as the corresponding current sample set, and prompt the target model to generate a background document for answering the current problem with the background document of the current sample set as the reference sample;

[0059] Step 82, input the second instruction text into the working model for processing, and use the generated text output by the model this time as the corresponding first generated document; and form a current text sequence containing only a single document text from the current first generated document;

[0060] Step 83, input the current problem and the current text sequence as the corresponding text T1 and the text sequence {T 2,i} into the relevance identification model for processing, and use the identification sequence {R output by the model this timei the only recognition status R in {...} i as the corresponding current recognition status;

[0061] Step 84, determine whether the current recognition status is relevant; if so, go to Step 85; if not, return to Step 82;

[0062] Step 85, take the latest first generated document as the corresponding current context.

[0063] Preferably, the problem-background cache library and the problem-background vector space are updated once according to the current problem and the current context, specifically including:

[0064] Step 91, take the current problem and the current context as a group of corresponding first problem text and first background document; and perform embedding encoding on the current first problem text based on the embedding encoding rule of the working model to obtain the corresponding first problem vector; and perform embedding encoding on the current first background document based on the embedding encoding rule of the working model to obtain the corresponding first background vector; and perform feature fusion processing on the current first problem vector and the first background vector based on the feature fusion method to obtain the corresponding first fusion vector; and form a corresponding first cache record composed of the first problem text, the first background document, the first problem vector, the first background vector and the first fusion vector obtained this time and store it in the problem-background cache library;

[0065] Step 92, and add a corresponding vector space point in the problem-background vector space based on the current first fusion vector; and perform clustering operation on all the vector space points in the current problem-background vector space based on the preset space point clustering algorithm to obtain a new plurality of space point aggregation clusters; and calculate the mean vector of all the first fusion vectors corresponding to each space point aggregation cluster to obtain a corresponding second mean vector, and take the corresponding point of the current second mean vector in the problem-background vector space as the aggregation cluster centroid point corresponding to the current space point aggregation cluster.

[0066] Preferably, the working model predicts an answer according to the current problem and the current context and feeds back the prediction result to the current user, specifically including:

[0067] Step 101, set the third problem configuration parameter and the background context configuration parameter of the preset third instruction template as the corresponding current problem and the current context, and take the third instruction template set this time as the corresponding third instruction text;

[0068] The third instruction template is a formatted instruction text template; the configurable parameters of the third instruction template include the third question configuration parameter and the background context configuration parameter; the third instruction template is used to use the third question configuration parameter as the corresponding question for the current time, use the background context configuration parameter as the corresponding context for the current time, and prompt the target model to generate an answer text for answering the question for the current time with the context for the current time as a prompt;

[0069] Step 102, input the third instruction text into the working model for processing and use the generated text output by the model this time as the corresponding current answer text to feedback to the current user.

[0070] A second aspect of the embodiments of the present invention provides an apparatus for implementing the method for processing a question-and-answer task based on a large language model described in the first aspect above. The apparatus includes: a model preparation module, a cache library and vector space preparation module, a question receiving module, a cache library sample retrieval module, a context generation module, a cache library and vector space update module, and an answer generation module;

[0071] The model preparation module is used to select a pre-trained and NLP task-trained generative large language model as the working model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on a preset first data set; the NLP tasks at least include a text generation task and a question-and-answer task;

[0072] The cache library and vector space preparation module is used to create a question-background cache library by collecting data on the questions and background documents of the historical question-and-answer tasks of the working model; and synchronously create a corresponding question-background vector space based on the question-background cache library;

[0073] The question receiving module is used to receive the question text input by the user and record it as the current question;

[0074] The cache library sample retrieval module is used to perform embedding encoding on the current question according to the embedding encoding rule of the working model to obtain a corresponding first embedding vector; and perform background sample retrieval according to the first embedding vector, the question-background vector space, and the question-background cache library to obtain a corresponding first sample set;

[0075] The context generation module is used to identify whether the first sample set is empty; if so, the working model retrieves the corresponding current context from the external knowledge base based on the current problem; if not, the working model generates a background document according to the current problem and the first sample set, and the relevance recognition model verifies the relevance between the generated document and the current problem, and when the verification passes, the generated document of this time is used as the corresponding current context;

[0076] The cache library and vector space update module is used to update the problem-background cache library and the problem-background vector space once according to the current problem and the current context;

[0077] The answer generation module is used to predict an answer by the working model according to the current problem and the current context and feedback the prediction result to the current user.

[0078] A third aspect of the embodiments of the present invention provides an electronic device, including: a memory, a processor, and a transceiver;

[0079] The processor is used to be coupled with the memory, read and execute the instructions in the memory to implement the method steps described in the first aspect above;

[0080] The transceiver is coupled with the processor, and the processor controls the transceiver to perform message sending and receiving.

[0081] A fourth aspect of the embodiments of the present invention provides a computer-readable storage medium, and the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is enabled to execute the instructions of the method described in the first aspect above.

[0082] An embodiment of the present invention provides a method, device, electronic device, and computer-readable storage medium for processing question-and-answer tasks based on a large language model. As can be seen from the above content, in the embodiment of the present invention, a pre-trained and NLP task-trained generative large language model is first selected as the working model, and a relevance recognition model for binary classification recognition of the relevance of the model input text is designed and trained; then, a question-background cache library is created by collecting data on the questions and background documents of the historical question-and-answer tasks of the working model, and a corresponding question-background vector space is synchronously created based on the question-background cache library; then, the question text input by the user is received and recorded as the current question, and the current question is embedded and encoded according to the embedding encoding rules of the working model, and background sample retrieval is performed according to the embedding vector, the question-background vector space, and the question-background cache library. When the sample set is empty, the working model retrieves the external knowledge base based on the current question to obtain the current context. When the sample set is not empty, the working model generates a background document according to the current question and the sample set, and the relevance recognition model verifies the relevance between the generated document and the current question. When the verification passes, the generated document of the current time is used as the current context, and the question-background cache library and the question-background vector space are updated according to the current question and the current context. Then, the working model predicts the answer according to the current question and the current context and feeds back the prediction result to the current user. The embodiment of the present invention effectively improves the answer generation efficiency when facing questions that have been answered or new questions similar to historical questions, and improves the text diversity when generating answers. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] Figure 1 FIG. is a schematic diagram of a method for processing question-and-answer tasks based on a large language model provided in Embodiment 1 of the present invention;

[0084] Figure 2 FIG. is a schematic diagram of the modules of the relevance recognition model provided in Embodiment 1 of the present invention;

[0085] Figure 3 FIG. is a module structure diagram of a device for processing question-and-answer tasks based on a large language model provided in Embodiment 2 of the present invention;

[0086] Figure 4 FIG. is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0087] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of them. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.

[0088] Embodiment 1 of the present invention provides a method for processing question-and-answer tasks based on a large language model, as Figure 1 shown in the schematic diagram of a method for processing question-and-answer tasks based on a large language model provided in Embodiment 1 of the present invention. This method mainly includes the following steps:

[0089] Step 1: Select a generative large language model that has completed pre-training and NLP task training as the working model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on a preset first dataset;

[0090] Among them, the NLP tasks at least include text generation tasks and question-and-answer tasks.

[0091] The working model of the embodiment of the present invention is any generative large language model that has completed pre-training and NLP task training. At least those that meet this condition include GPT series models, BERT series models, T5 series models, LLaMA series models, and Wenxin series models.

[0092] The relevance recognition model of the embodiment of the present invention is used to perform binary classification recognition on the relevance between the input text T1 of the model and each text T in the text sequence {T 2,i} and output the corresponding recognition sequence {R 2,i}. Among them, 1 ≤ text index i ≤ N i , N T is the total number of texts in the text sequence {T T}; the recognition sequence {R 2,i} includes multiple recognition states R i ; the recognition state R i corresponds one-to-one with the text T i ; the recognition state R 2,i includes two types of states: relevant and irrelevant. i includes two types of states: relevant and irrelevant.

[0093] As Figure 2 shown in the module schematic diagram of the relevance recognition model provided in Embodiment 1 of the present invention, the model input end of this relevance recognition model is used to receive the text T1 and the text sequence {T 2,i}, and the model input end is used to output the corresponding recognition sequence {Ri}。 Its internal model components include: an embedding encoding module, a feature extraction network, an MLP model, a Softmax function layer, and an identification output module.

[0094] The connection relationship of the internal components of the relevance identification model is as follows: the input end of the embedding encoding module is connected to the model input end, and the output end is connected to the input end of the feature extraction network; the output end of the feature extraction network is connected to the input end of the MLP model; the output end of the MLP model is connected to the input end of the Softmax function layer; the output end of the Softmax function layer is connected to the input end of the identification output module; the output end of the identification output module is connected to the model output end.

[0095] The function descriptions of the internal components of the relevance identification model are as follows.

[0096] 1) Embedding encoding module:

[0097] The embedding encoding module in the embodiment of the present invention is used to perform word segmentation on the text T1 according to a preset word segmentation rule to obtain a corresponding word segmentation sequence S1, and perform word segmentation on each text T in the text sequence {T 2,i} to obtain a corresponding word segmentation sequence S 2,i ; and perform sequence splicing on the word segmentation sequence S1 and each word segmentation sequence S 2,i to obtain a corresponding word segmentation sequence S 2,I ; and perform embedding encoding on each word segmentation sequence S 3,i according to a preset embedding encoding rule to obtain a corresponding embedding encoding vector e 3,i ; and form a corresponding embedding encoding tensor E{e i} composed of all the obtained embedding encoding vectors e i and send it to the feature extraction network. i}

[0098] Here, the word segmentation rule used by the embedding encoding module can be the word segmentation rule used by the working model; it can also be other conventional word segmentation rules, such as word segmentation rules based on spaces / punctuation marks / special characters / combinations of numbers and letters / acronyms and initialisms, word segmentation rules based on word lists / dictionaries, etc.; it can also be a word segmentation rule customized according to application requirements. The embedding encoding rule used by the embedding encoding module can be the embedding encoding rule used by the working model; it can be other conventional word embedding encoding rules, such as embedding encoding rules based on the bag of words, Word2Vec encoding rules, etc.; it can also be a word embedding encoding rule customized according to application requirements.

[0099] 2) Feature extraction network:

[0100] The feature extraction network of the embodiment of the present invention is implemented based on the CNN network, the ResNet network or the Encoder model of the Transformer framework.

[0101] This feature extraction network is used to perform feature encoding processing on the embedded encoding tensor E{e i} to obtain the corresponding feature encoding tensor X{x i} and send it to the MLP model. Here, the feature encoding tensor X{x i} is composed of multiple feature encoding vectors x i , and the feature encoding vector x i corresponds one-to-one with the embedded encoding vector e i .

[0102] 3) MLP model:

[0103] The MLP model of the embodiment of the present invention is connected by multiple layers of linear activation layers. Each layer of linear activation layer is composed of a linear layer and a non-linear activation function, and the non-linear activation function includes at least the ReLU activation function.

[0104] This MLP model is used to convert the feature encoding tensor X{x i} of high-dimensional features into a low-dimensional feature tensor Y{y i} and send it to the Softmax function layer.

[0105] Here, the low-dimensional feature tensor Y{y i} output by the MLP model includes multiple low-dimensional feature vectors y i , and the low-dimensional feature vector y i is composed of two vector data; the low-dimensional feature vector y i corresponds one-to-one with the feature encoding vector x i .

[0106] 4) Softmax function layer:

[0107] The Softmax function layer of the embodiment of the present invention uses the Softmax function to calculate the probability distribution of each low-dimensional feature vector y i of the low-dimensional feature tensor Y{y i} to obtain the corresponding probability distribution tensor P{p i} and send it to the recognition output module.

[0108] Here, the probability distribution tensor P{p i} includes multiple probability distribution vectors p i , and the probability distribution vector p i corresponds one-to-one with the low-dimensional feature vector y i ;

[0109] Probability distribution vector p i consists of two classification probabilities ρ i,1 , ρ i,2 . The classification probabilities ρ i,1 , ρ i,2 correspond to two classification types of relevant and irrelevant respectively, and ρ i,1 + ρ i,2 = 1.

[0110] 5) Recognition output module:

[0111] The recognition output module of the embodiment of the present invention is used to use the classification type corresponding to the maximum probability value in each probability distribution vector p i of the probability distribution tensor P{p i} as the corresponding recognition status R i ; and the obtained recognition statuses R i form a corresponding recognition sequence {R i} and output it.

[0112] In the current step 1, the first data set is a pre-prepared data set. The first data set includes a first training text set and a first label set; wherein, the first training text set includes multiple training texts x tr ; the total number of training texts in the first training text set is denoted as the total number N tr ; the first label set includes N tr × (N tr - 1) first correlation labels 1 ≤ index j ≤ N tr , 1 ≤ index k ≤ N tr , k ≠ j; the label value of the first correlation label is 0 or 1; each first correlation label is used to mark the correlation between the j-th training text and the k-th training text , and the label value of 0 indicates irrelevant and 1 indicates relevant.

[0113] In the current step 1, training the correlation recognition model based on the preset first data set specifically includes:

[0114] Step A1, splitting the first label set of the first data set into two sub-data sets denoted as the corresponding first training set and first evaluation set based on the preset first splitting ratio;

[0115] Here, the first splitting ratio of the embodiment of the present invention is a preset ratio parameter, such as 8:2; both the first training set and the first evaluation set consist of multiple first correlation labels Composition; the total number of labels in the first training set is denoted as N1, the total number of labels in the first evaluation set is denoted as N2, and N1 + N2 = N tr , and the ratio N1:N2 of the total number of labels N1 and N2 satisfies the first segmentation ratio;

[0116] Step A2: Denote each first correlation label in the first training set as the corresponding label and denote the two training texts x corresponding to each label tr as the corresponding text and denote the (N1 - 1) texts corresponding to each text as text and form a corresponding text sequence from the (N1 - 1) texts and set a corresponding label probability vector for each label and where 1 ≤ index j

[0117] ≤ N1, 1 ≤ index k * ≤ N1, k * ≤ N1, k * ≠ j * ;

[0118] The total number of labels is N1 × (N1 - 1);

[0119] The label probability vector consists of two classification label probabilities ;

[0120] For label if it is 0, then

[0121] For label if it is 1, then

[0122] Step A3: Input each text and its corresponding text sequence as the corresponding text T1 and text sequence {T2,i} into the correlation recognition model for processing; and in this processing, denote each probability distribution vector pi of the probability distribution tensor P{pi} output by the Softmax function layer of the correlation recognition model as the corresponding prediction probability vector and form a corresponding first prediction-label pair from each prediction probability vector and its corresponding label probability vector ​

[0123] Among them, the predicted probability vector is composed of two classification predicted probabilities ;

[0124] Step A4: Bring the obtained N1×(N1 - 1) first prediction-label pairs into the preset model loss function L A ; and based on the preset model optimizer, modulate the model parameters of the correlation recognition model in one round in the direction of minimizing the model loss function L A ;

[0125] Here, the model loss function L of the embodiment of the present invention A is implemented based on the binary cross-entropy loss function, specifically as follows:

[0126]

[0127] The model optimizer of the embodiment of the present invention includes at least the Adam optimizer and the SGD optimizer;

[0128] Step A5: Denote each first correlation label in the first evaluation set as the corresponding label and denote the two training texts x corresponding to each label tr as text and denote the (N2 - 1) texts corresponding to each text as text and form a text sequence from the (N2 - 1) texts ; and set a corresponding label probability vector for each label and where 1 ≤ index j' ≤ N2, 1 ≤ index k' ≤ N2, and k' ≠ j';

[0129] where 1 ≤ index j' ≤ N2, 1 ≤ index k' ≤ N2, and k' ≠ j';

[0130] The label The total number of is N2×(N2 - 1);

[0131] The label probability vector is composed of two corresponding classification label probabilities ;

[0132] The label if it is 0 then

[0133] The label if it is 1 then

[0134] Step A6: Take each text and its corresponding text sequence as the corresponding text T1 and text sequence {T 2,i} and input them into the relevance recognition model for processing; and during this processing, the probability distribution tensor P{p i} output by the Softmax function layer of the relevance recognition model i is denoted as the corresponding predicted probability vector and each predicted probability vector and its corresponding label probability vector form a corresponding second prediction-label pair

[0135] wherein, the predicted probability vector is composed of two classification predicted probabilities ;

[0136] Step A7: Input the obtained N2×(N2 - 1) second prediction-label pairs into the preset model evaluation function F A for calculation to obtain the corresponding first evaluation value;

[0137] Here, the model evaluation function F A of the embodiment of the present invention is implemented based on the RMSE function, specifically:

[0138]

[0139] Step A8: Identify whether the first evaluation value meets the preset first evaluation value range; if not, return to Step A2 to continue training; if so, confirm that the model training of the relevance recognition model ends;

[0140] Here, the first evaluation value range of the embodiment of the present invention is a preset numerical range.

[0141] Step 2: Create a question-background cache library by collecting data on the questions and background documents of the historical Q&A tasks of the working model; and synchronously create a corresponding question-background vector space based on the question-background cache library;

[0142] Specifically, it includes: Step 21: Create a question-background cache library by collecting data on the questions and background documents of the historical Q&A tasks of the working model;

[0143] Here, the problem-background cache library of the embodiments of the present invention includes multiple first cache records; the first cache record includes a first problem text, a first background document, a first problem vector, a first background vector, and a first fusion vector; the first problem text and the first background document are the original problem text and background context of a Q&A task that the working model has processed; the first problem vector is an embedded encoding vector obtained by performing embedded encoding on the first problem text based on the embedded encoding rule of the working model; the first background vector is an embedded encoding vector obtained by performing embedded encoding on the first background document based on the embedded encoding rule of the working model; the first fusion vector is a fusion vector obtained by performing feature fusion on the first problem vector and the first background vector based on a preset feature fusion method; the vector feature dimensions of the first problem vector, the first background vector, and the first fusion vector are all consistent with the embedded encoding vector feature dimension specified by the embedded encoding rule of the working model; the feature fusion methods of the embodiments of the present invention at least include a vector splicing method, a weighted summation method, an element-wise multiplication method, and a cross-attention method;

[0144] Step 22, and synchronously create a corresponding problem-background vector space based on the problem-background cache library;

[0145] Among them, the space dimension of the problem-background vector space is consistent with the embedded encoding vector feature dimension specified by the embedded encoding rule of the working model; the problem-background vector space includes multiple space point aggregation clusters; each space point aggregation cluster is aggregated by one or more vector space points; each space point aggregation cluster corresponds to a virtual aggregation cluster centroid point; the vector space points of the problem-background vector space correspond one-to-one with the first fusion vectors of the problem-background cache library; each aggregation cluster centroid point corresponds to the mean vector of all the first fusion vectors of all the vector space points in the current space point aggregation cluster;

[0146] Specifically, it includes: initializing a corresponding multi-dimensional vector space denoted as the corresponding problem-background vector space based on the embedded encoding vector feature dimension specified by the embedded encoding rule of the working model; setting a corresponding vector space point in the problem-background vector space based on each first fusion vector of the problem-background cache library; performing a clustering operation on all vector space points based on a preset space point clustering algorithm to obtain corresponding multiple space point aggregation clusters; calculating the mean vector of all the first fusion vectors corresponding to each space point aggregation cluster to obtain a corresponding first mean vector, and using the corresponding point of the current first mean vector in the problem-background vector space as the aggregation cluster centroid point corresponding to the current space point aggregation cluster;

[0147] Here, the space point clustering algorithms of the embodiments of the present invention at least include a k-means clustering algorithm, a hierarchical clustering algorithm, and a DBSCAN clustering algorithm.

[0148] Step 3: Receive the problem text input by the user and denote it as the current problem.

[0149] Step 4: Perform embedding encoding on the current problem according to the embedding encoding rule of the working model to obtain the corresponding first embedding vector; and perform background sample retrieval based on the first embedding vector, the problem-background vector space, and the problem-background cache library to obtain the corresponding first sample set.

[0150] Specifically, it includes: Step 41: Perform embedding encoding on the current problem according to the embedding encoding rule of the working model to obtain the corresponding first embedding vector.

[0151] Step 42: Perform background sample retrieval based on the first embedding vector, the problem-background vector space, and the problem-background cache library to obtain the corresponding first sample set.

[0152] Specifically, it includes: Step 421: Denote the corresponding point of the first embedding vector in the problem-background vector space as the current point; calculate the point distances from the current point to the centroid points of each spatial point aggregation cluster to obtain the corresponding first distances; and take the smallest first distance as the corresponding current minimum distance.

[0153] Step 422: Identify whether the current minimum distance exceeds a preset distance threshold.

[0154] Here, the distance threshold in the embodiment of the present invention is a preset threshold parameter.

[0155] Step 423: If the current minimum distance exceeds the distance threshold, set the corresponding first sample set to be empty.

[0156] Step 424: If the current minimum distance does not exceed the distance threshold, denote the spatial point aggregation cluster corresponding to the current minimum distance as the matching aggregation cluster; randomly select a specified number M of vector space points from the matching aggregation cluster to form the corresponding sample point set; and extract the first background documents of the first cache records corresponding to each vector space point in the sample point set from the problem-background cache library as a corresponding first sample document, and form the corresponding first sample set with all the obtained first sample documents.

[0157] Here, the specified number M in the embodiment of the present invention is a preset positive integer.

[0158] Step 425: Output the obtained first sample set as the result of this background sample retrieval.

[0159] Step 5, identify whether the first sample set is empty; if the first sample set is empty, the working model retrieves the corresponding current context from the external knowledge base based on the current problem; if the first sample set is not empty, the working model generates a background document according to the current problem and the first sample set, and the relevance recognition model verifies the relevance between the generated document and the current problem, and when the verification passes, the generated document of this time is used as the corresponding current context;

[0160] Specifically, it includes: Step 51, identify whether the first sample set is empty;

[0161] Step 52, if the first sample set is empty, the working model retrieves the corresponding current context from the external knowledge base based on the current problem;

[0162] Specifically, it includes: Step 521, set the first problem configuration parameter of the preset first instruction template to the current problem, and use the first instruction template set this time as the corresponding first instruction text;

[0163] Here, the first instruction template of the embodiment of the present invention is a formatted instruction text template; the configurable parameters of the first instruction template include the first problem configuration parameter; the first instruction template is used to use the first problem configuration parameter as the corresponding current problem, and prompt the target model to generate a background document for answering the current problem by retrieving the external knowledge base;

[0164] Step 522, input the first instruction text into the working model for processing, and use the generated text output by the model this time as the corresponding current context;

[0165] Step 53, if the first sample set is not empty, the working model generates a background document according to the current problem and the first sample set, and the relevance recognition model verifies the relevance between the generated document and the current problem, and when the verification passes, the generated document of this time is used as the corresponding current context;

[0166] Specifically, it includes: Step 531, set the second problem configuration parameter and the sample set configuration parameter of the preset second instruction template to the corresponding current problem and the first sample set, and use the second instruction template set this time as the corresponding second instruction text;

[0167] Here, the second instruction template of the embodiment of the present invention is a formatted instruction text template; the configurable parameters of the second instruction template include the second problem configuration parameter and the sample set configuration parameter; the second instruction template is used to use the second problem configuration parameter as the corresponding current problem, use the sample set configuration parameter as the corresponding current sample set, and prompt the target model to generate a background document for answering the current problem with the background document of the current sample set as the reference sample;

[0168] Step 532: Input the second instruction text into the working model for processing, and use the generated text output by the model this time as the corresponding first generated document; and form a current text sequence containing only a single document text from the current first generated document;

[0169] Step 533: Use the current problem and the current text sequence as the corresponding text T1 and text sequence {T 2,i} to input into the relevance recognition model for processing, and use the recognition sequence {R i} with the only recognition status R i as the corresponding current recognition status;

[0170] Step 534: Judge whether the current recognition status is relevant; if so, go to Step 535; if not, return to Step 532;

[0171] Step 535: Use the latest first generated document as the corresponding current context.

[0172] Step 6: Update the question-background cache library and the question-background vector space once according to the current problem and the current context;

[0173] Specifically, it includes: Step 61: Use the current problem and the current context as a group of corresponding first question text and first background document; and perform embedding encoding on the current first question text based on the embedding encoding rules of the working model to obtain the corresponding first question vector; and perform embedding encoding on the current first background document based on the embedding encoding rules of the working model to obtain the corresponding first background vector; and perform feature fusion processing on the current first question vector and first background vector based on the feature fusion method to obtain the corresponding first fusion vector; and form a corresponding first cache record composed of the first question text, first background document, first question vector, first background vector, and first fusion vector obtained this time and store it in the question-background cache library;

[0174] Step 62: And add a corresponding vector space point in the question-background vector space based on the current first fusion vector; and perform clustering operations on all vector space points in the current question-background vector space based on the preset space point clustering algorithm to obtain a new multiple space point aggregation clusters; and calculate the mean vector for all first fusion vectors corresponding to each space point aggregation cluster to obtain a corresponding second mean vector, and use the corresponding point of the current second mean vector in the question-background vector space as the aggregation cluster centroid point corresponding to the current space point aggregation cluster.

[0175] Step 7: Have the working model predict an answer according to the current problem and the current context and feedback the prediction result to the current user;

[0176] Specifically, it includes: Step 71, setting the third question configuration parameter and the background context configuration parameter of the preset third instruction template as the corresponding current question and current context, and using the third instruction template set this time as the corresponding third instruction text;

[0177] Here, the third instruction template of the embodiment of the present invention is a formatted instruction text template; the configurable parameters of the third instruction template include the third question configuration parameter and the background context configuration parameter; the third instruction template is used to use the third question configuration parameter as the corresponding current question, the background context configuration parameter as the corresponding current context, and prompt the target model to generate an answer text for answering the current question with the current context as a prompt;

[0178] Step 72, inputting the third instruction text into the working model for processing and feeding back the generated text output by the model this time as the corresponding current answer text to the current user.

[0179] Figure 3 FIG. 10 is a module structure diagram of a question-and-answer task processing device based on a large language model provided in the second embodiment of the present invention. The device is a terminal device or a server for implementing the foregoing method embodiment, or may be a device that enables the foregoing terminal device or server to implement the foregoing method embodiment. For example, the device may be a device or a chip system of the foregoing terminal device or server. As Figure 3 shown, the device includes: a model preparation module 201, a cache library and vector space preparation module 202, a question receiving module 203, a cache library sample retrieval module 204, a context generation module 205, a cache library and vector space update module 206, and an answer generation module 207.

[0180] The model preparation module 201 is used to select a pre-trained and NLP task-trained generative large language model as the working model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on the preset first data set. The NLP tasks include at least text generation tasks and question-and-answer tasks.

[0181] The cache library and vector space preparation module 202 is used to create a question-background cache library by collecting data on the questions and background documents of the historical question-and-answer tasks of the working model; and synchronously create a corresponding question-background vector space based on the question-background cache library.

[0182] The question receiving module 203 is used to receive the question text input by the user and record it as the current question.

[0183] The cache library sample retrieval module 204 is used to perform embedded encoding on the current problem according to the embedded encoding rule of the working model to obtain a corresponding first embedded vector; and perform background sample retrieval based on the first embedded vector, the question-background vector space, and the question-background cache library to obtain a corresponding first sample set.

[0184] The context generation module 205 is used to identify whether the first sample set is empty; if the first sample set is empty, the working model retrieves the external knowledge base based on the current problem to obtain a corresponding current context; if the first sample set is not empty, the working model generates a background document based on the current problem and the first sample set, and the relevance recognition model verifies the relevance between the generated document and the current problem, and when the verification passes, the generated document of the current time is used as the corresponding current context.

[0185] The cache library and vector space update module 206 is used to perform a first update on the question-background cache library and the question-background vector space according to the current problem and the current context.

[0186] The answer generation module 207 is used to predict an answer by the working model according to the current problem and the current context and feedback the prediction result to the current user.

[0187] A question-answering task processing device provided by an embodiment of the present invention can execute the method steps in the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.

[0188] It should be noted that it should be understood that the division of each module of the above device is only a logical function division. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. And these modules can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the model preparation module can be a separately established processing element, or can be integrated in a certain chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a certain processing element of the above device to perform the functions of the above determined modules. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together or independently implemented. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed by the integrated logic circuit in the processor element or the instruction in the form of software.

[0189] For example, the above-mentioned modules can be one or more integrated circuits configured to implement the above methods. For example: one or more Application Specific Integrated Circuits (ASICs), or one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Again, these modules can be integrated together and implemented in the form of a System-on-a-chip (SOC).

[0190] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the foregoing method embodiments are generated in whole or in part. The above computer can be a general-purpose computer, a dedicated computer, a computer network, or other programmable devices. The above computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another. For example, the above computer instructions can be transmitted from a website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, Digital Subscriber Line (DSL)) or wireless (such as infrared, wireless, Bluetooth, microwave, etc.). The above computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The above available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, solid state disk (SSD)), etc.

[0191] Figure 4 The structural schematic diagram of an electronic device provided in Embodiment 3 of the present invention. The electronic device can be a terminal device or a server that implements the method of the foregoing embodiments, or a terminal device or a server that is connected to the foregoing terminal device or server and implements the method of the foregoing embodiments. As Figure 4As shown, the electronic device may include: a processor 301 (such as a CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transceiver operations of the transceiver 303. Various instructions may be stored in the memory 302 for completing various processing functions and implementing the processing steps described in the methods of the foregoing embodiments. Preferably, the electronic device according to the embodiments of the present invention further includes: a power supply 304, a system bus 305, and a communication port 306. The system bus 305 is used to implement communication connections between components. The above-mentioned communication port 306 is used for the electronic device to connect and communicate with other peripherals.

[0192] As mentioned in Figure 4 the system bus 305 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The system bus may be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, only a 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 is used to implement communication between the database access device and other devices (such as clients, read-write libraries, and read-only libraries). The memory may include a Random Access Memory (RAM), and may also include a non-volatile memory, such as at least one disk memory.

[0193] The above-mentioned processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), a Graphics Processing Unit (GPU), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0194] It should be noted that the embodiments of the present invention further provide a computer-readable storage medium, in which instructions are stored, and when they run on a computer, the computer is caused to execute the methods and processing procedures provided in the above embodiments.

[0195] An embodiment of the present invention provides a method, device, electronic device, and computer-readable storage medium for processing question-and-answer tasks based on a large language model. As can be seen from the above, in the embodiment of the present invention, a pre-trained and NLP task-trained generative large language model is first selected as the working model, and a relevance recognition model for binary classification recognition of the relevance of the model input text is designed and trained; then, a question-background cache library is created by collecting data on the questions and background documents of the historical question-and-answer tasks of the working model, and a corresponding question-background vector space is synchronously created based on the question-background cache library; then, the question text input by the user is received and recorded as the current question, and the current question is embedded and encoded according to the embedding encoding rule of the working model, and background sample retrieval is performed according to the embedding vector, the question-background vector space, and the question-background cache library. When the sample set is empty, the working model retrieves the external knowledge base based on the current question to obtain the current context. When the sample set is not empty, the working model generates a background document according to the current question and the sample set, and the relevance recognition model verifies the relevance between the generated document and the current question. When the verification passes, the generated document of the current time is used as the current context, and the question-background cache library and the question-background vector space are updated according to the current question and the current context. Then, the working model predicts the answer according to the current question and the current context and feeds back the prediction result to the current user. The embodiment of the present invention effectively improves the answer generation efficiency when facing questions that have been answered or new questions similar to historical questions, and improves the text diversity when generating answers.

[0196] The steps of the methods or algorithms described in connection with the embodiments disclosed herein may be implemented in hardware, software modules executed by a processor, or a combination thereof. The software modules may be placed in random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0197] The specific embodiments described above have further elaborated on the purpose, technical solutions, and beneficial effects of the present invention. It should be understood that the above description is only the specific embodiments of the present invention and is not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for processing question-answering tasks based on large language models, characterized in that, The method includes: Select a pre-trained and NLP-task-trained generative large language model as the working model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on a preset first data set; the NLP tasks include at least text generation tasks and question-answering tasks; Create a question-background cache library by collecting data on the questions and background documents of the historical question-answering tasks of the working model; and synchronously create a corresponding question-background vector space based on the question-background cache library; Receive the question text input by the user and denote it as the current question; Perform embedding encoding on the current question according to the embedding encoding rule of the working model to obtain a corresponding first embedding vector; and perform background sample retrieval based on the first embedding vector, the question-background vector space, and the question-background cache library to obtain a corresponding first sample set; Identify whether the first sample set is empty; if so, retrieve the corresponding current context from the external knowledge base by the working model based on the current question; if not, generate a background document by the working model according to the current question and the first sample set, and verify the relevance between the generated document and the current question by the relevance recognition model, and use the generated document of this time as the corresponding current context when the verification passes; Perform a first update on the question-background cache library and the question-background vector space according to the current question and the current context; Predict an answer by the working model according to the current question and the current context and feedback the prediction result to the current user.

2. The method for processing question-answering tasks based on a large language model according to claim 1, wherein The working model includes at least GPT series models, BERT series models, T5 series models, LLaMA series models, and Wenxin series models; The correlation recognition model is used to identify the text T1 input to the model and the text sequence {T 2,i } each text T 2,i The correlation is used for binary classification and the corresponding recognition sequence {R i }; 1≤text index i≤N T , N T Text sequence {T 2,i }; the recognition sequence {R i } includes multiple recognition states R i ; The identification state R i With the text T 2,i One-to-one correspondence; the identification state R i Includes two types of states: related and unrelated; The first data set includes a first training text set and a first label set; the first training text set includes a plurality of training texts x tr ; The total number of training texts in the first training text set is denoted as the total number N tr ; the first label set includes N tr ×(N tr -1) first correlation labels 1 ≤ index k ≤ N tr , k ≠ j; the label value of the first correlation label is 0 or 1; each of the first correlation labels is used to mark the correlation between the j-th training text and the k-th training text , where a label value of 0 indicates no correlation and a label value of 1 indicates correlation; The problem-background cache library includes multiple first cache records; the first cache records include a first problem text, a first background document, a first problem vector, a first background vector, and a first fusion vector; the first problem text and the first background document are the original problem text and background context of a Q&A task that the working model has processed; the first problem vector is an embedded encoding vector obtained by performing embedded encoding on the first problem text based on the embedded encoding rules of the working model; the first background vector is an embedded encoding vector obtained by performing embedded encoding on the first background document based on the embedded encoding rules of the working model; the first fusion vector is a fusion vector obtained by performing feature fusion on the first problem vector and the first background vector based on a preset feature fusion method, and the feature fusion method at least includes a vector concatenation method, a weighted summation method, an element-wise multiplication method, and a cross-attention method; the vector feature dimensions of the first problem vector, the first background vector, and the first fusion vector are all consistent with the embedded encoding vector feature dimensions specified by the embedded encoding rules of the working model; The spatial dimension of the problem-background vector space is consistent with the embedded encoding vector feature dimensions specified by the embedded encoding rules of the working model; the problem-background vector space includes multiple spatial point aggregation clusters; each of the spatial point aggregation clusters is aggregated by one or more vector space points; each spatial point aggregation cluster corresponds to a virtual aggregation cluster centroid point; the vector space points of the problem-background vector space correspond one-to-one with the first fusion vectors of the problem-background cache library; each aggregation cluster centroid point corresponds to the mean vector of all the first fusion vectors of all the vector space points of the current spatial point aggregation cluster.

3. The method for processing a Q&A task based on a large language model according to claim 2, wherein The model input end of the correlation recognition model is used to receive the text T1 and the text sequence {T 2,i}, and the model input end is used to output the corresponding recognition sequence {R i}; The relevance recognition model includes an embedded encoding module, a feature extraction network, an MLP model, a Softmax function layer, and a recognition output module; The input end of the embedded encoding module is connected to the model input end, and the output end is connected to the input end of the feature extraction network; the output end of the feature extraction network is connected to the input end of the MLP model; the output end of the MLP model is connected to the input end of the Softmax function layer; the output end of the Softmax function layer is connected to the input end of the recognition output module; the output end of the recognition output module is connected to the model output end; The embedding encoding module is used to tokenize the text T1 according to a preset tokenization rule to obtain a corresponding token sequence S1, and tokenize each text T 2,i in the text sequence {T 2,i} to obtain a corresponding token sequence S 2,i ; and splice the token sequence S1 and each token sequence S 2,I to obtain a corresponding token sequence S 3,i ; and perform embedding encoding on each token sequence S 3,i according to a preset embedding encoding rule to obtain a corresponding embedding encoding vector e i ; and form a corresponding embedding encoding tensor E{e i} composed of all the obtained embedding encoding vectors e i and send it to the feature extraction network; The feature extraction network is implemented based on the CNN network, the ResNet network or the Encoder model of the Transformer framework; the feature extraction network is used to perform feature encoding processing on the embedded encoding tensor E{e i} to obtain the corresponding feature encoding tensor X{x i} and send it to the MLP model; the feature encoding tensor X{x i} is composed of multiple feature encoding vectors x i ; the feature encoding vectors x i and the embedded encoding vectors e i are in one-to-one correspondence; The MLP model is composed of multiple layers of linear activation layers connected in series. Each layer of the linear activation layer consists of a linear layer and a non-linear activation function. The non-linear activation function includes at least the ReLU activation function. The MLP model is used to convert the feature encoding tensor X{x i} of high-dimensional features into a low-dimensional feature tensor Y{y i} and send it to the Softmax function layer. The low-dimensional feature tensor Y{y i} includes multiple low-dimensional feature vectors y i , and each low-dimensional feature vector y i is composed of two vector data. The low-dimensional feature vector y i corresponds one-to-one with the feature encoding vector x i . The Softmax function layer uses the Softmax function to perform probability distribution calculation on each of the low-dimensional feature vectors y i of the low-dimensional feature tensor Y{y i} to obtain the corresponding probability distribution tensor P{p i} and send it to the recognition output module; The probability distribution tensor P{p i} includes a plurality of probability distribution vectors p i , and the probability distribution vectors p i are in one-to-one correspondence with the low-dimensional feature vectors y i ; the probability distribution vectors p i are composed of two classification probabilities ρ i,1 , ρ i,2 . The two classification types corresponding to the classification probabilities ρ i,1 , ρ i,2 are relevant and irrelevant respectively, and ρ i,1 + ρ i,2 = 1; The recognition output module is used to use each of the probability distribution vectors p i} in the probability distribution tensor P{p i} as the corresponding recognition status R i corresponding to the maximum probability value; and all the obtained recognition statuses R i are used to form the corresponding recognition sequence {R i} and output it.

4. The method for processing question-and-answer tasks based on large language models according to claim 2, wherein, Training the relevance recognition model based on a preset first data set specifically includes: Step 41, dividing the first label set of the first data set into two sub-data sets denoted as corresponding first training set and first evaluation set based on a preset first segmentation ratio; Among them, both the first training set and the first evaluation set are composed of a plurality of the first correlation tags ; the total number of tags in the first training set is denoted as N1, the total number of tags in the first evaluation set is denoted as N2, and N1 + N2 = N tr , and the ratio N1:N2 of the total number of tags N1 and N2 satisfies the first segmentation ratio; Step 42, for each of the first correlation tags in the first training set denote them as corresponding tags and for each of these tags the two corresponding training texts x tr denote them as corresponding texts and for each of these texts the corresponding (N1 - 1) texts denote them as texts and from the (N1 - 1) texts form a corresponding text sequence and for each of these tags set a corresponding tag probability vector where 1 ≤ index j * ≤ N1, 1 ≤ index k * ≤ N1, k * ≠ j * ; the total number of the labels is N1 × (N1 - 1); the label probability vector consists of two categorical label probabilities ; if the label is 0, then if the label is 1, then Step 43, for each of the said texts and its corresponding text sequence as the corresponding text T1 and text sequence {T 2,i} are input into the relevance recognition model for processing; and during this processing, the probability distribution tensor P{p i} output by the Softmax function layer of the relevance recognition model i is denoted as the corresponding predicted probability vector and a corresponding first prediction-label pair is formed by each of the said predicted probability vectors and its corresponding label probability vector Among them, the predicted probability vector is composed of two classification prediction probabilities ; Step 44, bringing the obtained N1×(N1-1) first prediction-label pairs into a preset model loss function L A ; and based on a preset model optimizer, modulating the model parameters of the correlation recognition model in one round in the direction of minimizing the model loss function L A to reach the minimum value; Among them, the model loss function L A is implemented based on the binary cross-entropy loss function, specifically as follows: The model optimizer at least includes an Adam optimizer and an SGD optimizer; Step 45, for each of the first relevance tags in the first evaluation set denote it as the corresponding tag and for each of the tags the two corresponding training texts x tr denote them as the corresponding texts and for each of the texts the corresponding (N2 - 1) texts denote them as texts and from the (N2 - 1) texts form a text sequence and for each of the tags set a corresponding tag probability vector where 1 ≤ index j ’ ≤ N2, 1 ≤ index k ’ ≤ N2, k ’ ≠ j ’ ; the total number of the labels is N2 × (N2 - 1); the label probability vector is composed of two corresponding classification label probabilities ; if the label is 0, then if the label is 1, then Step 46, for each of the texts and its corresponding text sequence as the corresponding text T1 and text sequence {T 2,i} are input into the relevance recognition model for processing; and during this processing, each of the probability distribution vectors p i of the probability distribution tensor P{p i} output by the Softmax function layer of the relevance recognition model is denoted as the corresponding predicted probability vector and a corresponding second prediction-label pair is formed by each of the predicted probability vectors and its corresponding label probability vector ​ Among them, the predicted probability vector consists of two classification predicted probabilities ; Step 47: Bring the obtained N2×(N2 - 1) second prediction-label pairs into a preset model evaluation function F A for calculation to obtain corresponding first evaluation values; Among them, the model evaluation function F A is implemented based on the RMSE function, specifically as follows: Step 48: Identify whether the first evaluation value meets a preset first evaluation value range; if it does not meet, return to Step 42 to continue training; if it meets, confirm that the model training of the relevance identification model ends.

5. The method for processing question-and-answer tasks based on a large language model according to claim 2, wherein Synchronously creating a corresponding question-background vector space based on the question-background cache library specifically includes: Initializing a corresponding multi-dimensional vector space denoted as the corresponding question-background vector space based on the embedding coding vector feature dimension specified by the embedding coding rule of the working model; setting a corresponding vector space point in the question-background vector space based on each of the first fusion vectors in the question-background cache library; performing a clustering operation on all the vector space points based on a preset spatial point clustering algorithm to obtain corresponding multiple spatial point aggregation clusters; calculating a mean vector for all the first fusion vectors corresponding to each spatial point aggregation cluster to obtain a corresponding first mean vector, and taking the corresponding point of the current first mean vector in the question-background vector space as the centroid point of the corresponding spatial point aggregation cluster; the spatial point clustering algorithm at least includes the k-means clustering algorithm, hierarchical clustering algorithm, and DBSCAN clustering algorithm.

6. The method for processing question-and-answer tasks based on large language models according to claim 2, wherein Retrieving background samples according to the first embedding vector, the question-background vector space, and the question-background cache library to obtain a corresponding first sample set specifically includes: Step 61: Denote the corresponding point of the first embedding vector in the question-background vector space as the current point; calculate the point distances from the current point to the centroid points of each spatial point aggregation cluster to obtain corresponding first distances; and take the smallest of the first distances as the corresponding current minimum distance. Step 62: Identify whether the current minimum distance exceeds a preset distance threshold. Step 63: If the current minimum distance exceeds the distance threshold, set the corresponding first sample set to be empty. Step 64: If the current minimum distance does not exceed the distance threshold, denote the spatial point aggregation cluster corresponding to the current minimum distance as the matching aggregation cluster; randomly select a specified number M of vector space points from within the matching aggregation cluster to form a corresponding sample point set; and extract the first background documents of the first cache records corresponding to each vector space point in the sample point set from the question-background cache library as a corresponding first sample document, and form the corresponding first sample set from all the obtained first sample documents; the specified number M is a preset positive integer. Step 65: Output the obtained first sample set as the result of this background sample retrieval.

7. The method for processing question-and-answer tasks based on large language models according to claim 2, wherein, The working model retrieves the external knowledge base based on the current question to obtain a corresponding current context specifically includes: Step 71: Set the first question configuration parameter of a preset first instruction template to the current question, and use the first instruction template set this time as the corresponding first instruction text. The first instruction template is a formatted instruction text template; the configurable parameters of the first instruction template include the first question configuration parameter; the first instruction template is used to use the first question configuration parameter as the corresponding question for the current time, and prompt the target model to generate a background document for answering the question for the current time by retrieving an external knowledge base; Step 72, input the first instruction text into the working model for processing and use the generated text output by the model this time as the corresponding current context.

8. The method for processing question-and-answer tasks based on a large language model according to claim 2, wherein The working model generates a background document according to the current question and the first sample set, and the relevance recognition model verifies the relevance between the generated document and the current question, and when the verification passes, uses the generated document for the current time as the corresponding current context, specifically including: Step 81, set the second question configuration parameter and the sample set configuration parameter of the preset second instruction template as the corresponding current question and the first sample set, and use the second instruction template set this time as the corresponding second instruction text; The second instruction template is a formatted instruction text template; the configurable parameters of the second instruction template include the second question configuration parameter and the sample set configuration parameter; the second instruction template is used to use the second question configuration parameter as the corresponding question for the current time, use the sample set configuration parameter as the corresponding sample set for the current time, and prompt the target model to generate a background document for answering the question for the current time with the background document of the sample set for the current time as a reference sample; Step 82, input the second instruction text into the working model for processing and use the generated text output by the model this time as the corresponding first generated document; and form a current text sequence containing only a single document text from the current first generated document; Step 83, use the current problem and the current text sequence as the corresponding text T1 and text sequence {T 2,i} and input them into the relevance recognition model for processing, and use the only recognition status R in the recognition sequence {R i} output by the model this time i as the corresponding current recognition status; Step 84, judge whether the current recognition status is relevant; if so, go to Step 85; if not, return to Step 82; Step 85, use the latest first generated document as the corresponding current context.

9. The method for processing question-and-answer tasks based on large language models according to claim 2, wherein The one-time update of the question-background cache library and the question-background vector space according to the current question and the current context specifically includes: Step 91, use the current question and the current context as a group of corresponding first question text and first background document; and perform embedding encoding on the current first question text based on the embedding encoding rule of the working model to obtain the corresponding first question vector; and perform embedding encoding on the current first background document based on the embedding encoding rule of the working model to obtain the corresponding first question vector; and perform feature fusion processing on the current first question vector and the first background vector based on the feature fusion method to obtain the corresponding first fusion vector; and form a corresponding first cache record from the first question text, the first background document, the first question vector, the first background vector and the first fusion vector obtained this time and store it in the question-background cache library; Step 92, and add a corresponding vector space point in the problem-background vector space based on the current first fusion vector; and perform clustering operations on all the vector space points in the current problem-background vector space based on a preset spatial point clustering algorithm to obtain multiple new spatial point aggregation clusters; and calculate the mean vector for all the first fusion vectors corresponding to each spatial point aggregation cluster to obtain a corresponding second mean vector, and use the corresponding point of the current second mean vector in the problem-background vector space as the centroid point corresponding to the current spatial point aggregation cluster.

10. The method for processing question-and-answer tasks based on large language models according to claim 2, wherein, The work model predicts an answer according to the current problem and the current context and feeds back the prediction result to the current user, which specifically includes: Step 101, set the third question configuration parameter and the background context configuration parameter of a preset third instruction template to the corresponding current problem and the current context, and use the set third instruction template as the corresponding third instruction text. The third instruction template is a formatted instruction text template; the configurable parameters of the third instruction template include the third question configuration parameter and the background context configuration parameter; the third instruction template is used to use the third question configuration parameter as the corresponding question for the current time and the background context configuration parameter as the corresponding context for the current time, and prompt the target model to generate an answer text for answering the question for the current time with the context for the current time as a prompt. Step 102, input the third instruction text into the work model for processing and feed back the generated text output by the model this time as the corresponding current answer text to the current user.

11. An apparatus for performing the method for processing question-and-answer tasks based on a large language model according to any one of claims 1-10, characterized in that, The device includes: a model preparation module, a cache library and vector space preparation module, a question receiving module, a cache library sample retrieval module, a context generation module, a cache library and vector space update module, and an answer generation module. The model preparation module is used to select a pre-trained and NLP task-trained generative large language model as the work model; design a deep learning model for binary classification recognition of the relevance of the model input text as the relevance recognition model; and train the relevance recognition model based on a preset first data set; the NLP tasks at least include a text generation task and a question-answering task. The cache library and vector space preparation module is used to create a question-background cache library by collecting data on the questions and background documents of the historical question-answering tasks of the work model; and synchronously create a corresponding question-background vector space based on the question-background cache library. The question receiving module is used to receive the question text input by the user and record it as the current question. The cache library sample retrieval module is used to perform embedding encoding on the current question according to the embedding encoding rule of the work model to obtain a corresponding first embedding vector; and perform background sample retrieval according to the first embedding vector, the question-background vector space and the question-background cache library to obtain a corresponding first sample set. The context generation module is used to identify whether the first sample set is empty; if so, the working model retrieves the corresponding current context from the external knowledge base based on the current question; if not, the working model generates a background document according to the current question and the first sample set, and the relevance identification model verifies the relevance between the generated document and the current question, and when the verification passes, the generated document of this time is used as the corresponding current context; The cache library and vector space update module are used to perform a first update on the question-background cache library and the question-background vector space according to the current question and the current context; The answer generation module is used to predict an answer by the working model according to the current question and the current context and feedback the prediction result to the current user.

12. An electronic device, characterized in that, Comprising: A memory, a processor and a transceiver; The processor is used to be coupled with the memory, read and execute the instructions in the memory to implement the method according to any one of claims 1-10; The transceiver is coupled with the processor, and the processor controls the transceiver to perform message sending and receiving.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is caused to execute the method according to any one of claims 1-10.