Model training method, model illusion processing method, equipment, medium and product
By using hallucination processing models to reconstruct and adjust internal representations in large language models, the hallucination problem when the model generates response is solved, and higher output reliability and autonomy are achieved, and maintenance costs are reduced.
Patent Information
- Application Number
- CN202510076445.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-17
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, large language models are prone to ‘illusion’ problems when generating responses, resulting in a decrease in output inaccuracy and credibility. They rely on plug-in knowledge bases and incompletely mature text vectorization technology, increasing maintenance costs and errors.
By entering triple data (including sample text, real replies and non-real replies) into the text language model, the hallucination processing model to be trained is spatially encoded and decoded, internal representation is reconstructed, and model parameters are adjusted according to the target loss, and a model that can recognize and correct hallucinations is trained.
This method does not require an external knowledge base, and analyzes the potential semantics of text through multi-space presentation, which improves the accuracy of hallucination recognition and correction, reduces maintenance costs and errors, and improves the reliability of model output.
Smart Images

Figure CN119886252A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a model training method, a model hallucination processing method, a device, a medium and a product. Background Art
[0002] In the field of Natural Language Processing (NLP), Large Language Models (LLMs) have emerged with the help of deep learning technology, demonstrating their outstanding ability to handle complex language tasks. LLM models can not only understand the meaning of natural language texts, but also generate coherent and fluent text content, and thus perform well in many application scenarios such as machine translation, text summarization, and sentiment analysis, with remarkable results. However, LLM models still face the problem of "hallucination" when generating responses. The so-called "hallucination" means that the responses generated by the model are fluent and natural, seemingly reasonable, but in fact do not match the actual situation, thus affecting the credibility of the model output. The causes of the hallucination problem are complex and may involve blindly following instructions, noise in training data, incomplete knowledge bases, and inherent uncertainties in the model generation process. Therefore, even if the LLM model has the correct knowledge, it may not always be able to generate true and accurate answers.
[0003] In the related art, the common large model hallucination mitigation method uses a vector embedding model and a search engine to perform similarity retrieval and score retrieval on the question to obtain a text paragraph array, which is combined with the question to form a prompt text (Prompt), which is input into the large model to obtain the answer. However, this method requires continuous updating of the knowledge base, which increases maintenance costs and workload, and relies on text vectorization technology that is not yet fully mature, resulting in errors in retrieval knowledge. Therefore, there is an urgent need to provide a new method for alleviating large model hallucinations. Summary of the invention
[0004] One of the purposes of this application is to provide a model training method, a method, device, medium and product for processing model hallucinations, so as to solve the problem in related technologies that the knowledge base needs to be continuously updated, maintenance costs and workload are increased, and errors exist in retrieving knowledge due to reliance on text vectorization technology that is not yet fully mature.
[0005] In order to solve the above problems, the technical solution of the embodiment of the present application is implemented as follows:
[0006] In a first aspect, the present application provides a model training method, the method comprising:
[0007] Inputting the constructed triple data into a text language model to obtain a sample internal representation of the triple data by a target module when the text language model is stimulated by the triple data; wherein the triple data includes a sample text, a sample true reply text corresponding to the sample text, and a sample non-true reply text;
[0008] Using each spatial encoding module in the hallucination processing model to be trained, the internal representation of the sample is mapped into different spaces to obtain a real potential representation of the sample in a real space and a semantic potential representation of the sample in a semantic space;
[0009] Based on the sample real potential representation and the sample semantic potential representation, reconstruct the internal representation of the target module using the decoding module in the hallucination processing model to be trained to obtain the sample reconstructed internal representation;
[0010] Determining a target loss of the hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true latent representation, and the sample semantic latent representation;
[0011] Based on the target loss, the parameters of the hallucination processing model to be trained are adjusted to obtain a trained hallucination processing model; wherein the trained hallucination processing model meets a preset convergence condition.
[0012] According to the above technical means, the embodiment of the present application inputs the triple data including the sample text, the sample real reply text and the sample non-real reply text into the text language model to obtain the internal representation of the sample by the target module, which can capture the text-related feature information from multiple dimensions. It helps the model to be more sensitive to the differences in text features that may cause hallucinations and improve the recognition accuracy of hallucination phenomena. Using each spatial encoding module in the hallucination processing model to be trained, the internal representation of the sample is mapped to different spaces to obtain the real potential representation of the sample in the real space and the semantic potential representation of the sample in the semantic space. The embodiment of the present application does not need to rely on an external knowledge base. Through the multi-space presentation method, the potential semantics and real associations of the text are analyzed from different angles, and more obscure clues related to hallucinations can be excavated, so that the model can more comprehensively identify the hallucination features existing in different reply texts, and further enhance the recognition ability of hallucinations. Based on the sample's true potential representation and the sample's semantic potential representation, the internal representation of the target module is reconstructed with the help of a decoding module to obtain the sample's reconstructed internal representation, so that the internal representation that may have deviations can be reasonably adjusted according to the mined text's true and semantic information, thereby providing strong support for the subsequent accurate correction of erroneous replies caused by hallucinations, enabling the model to have more accurate correction capabilities, and making the output replies closer to the real situation. The target loss of the hallucination processing model to be trained is determined based on at least part of the sample's reconstructed internal representation, the sample's internal representation, the sample's true potential representation, and the sample's semantic potential representation, which helps guide the model to adjust parameters in the right direction, avoid defects caused by one-sided training, and ensure the rationality and effectiveness of the training process. The parameters of the hallucination processing model to be trained are adjusted according to the determined target loss until the preset convergence conditions are met to obtain a trained hallucination processing model, thereby improving the overall ability of the model to deal with hallucination problems and outputting high-quality reply content.
[0013] In a second aspect, the present application provides a method for processing model hallucination, the method comprising:
[0014] Obtaining a first internal representation of the input text by the target module when the text language model performs model reasoning on the input text;
[0015] Using each spatial encoding module in the hallucination processing model, spatial mapping is performed on the first internal representation to obtain a real potential representation in a real space and a semantic potential representation in a semantic space, and based on the real potential representation and the semantic potential representation, a detection result of whether hallucination occurs when the text language model performs model inference is obtained;
[0016] If the detection result indicates that the text language model has hallucinations when performing model inference, the real potential representation is subjected to authenticity editing processing in the real space to obtain a processed real potential representation; based on the processed real potential representation and the semantic potential representation, a second internal representation is obtained through a decoding module in the hallucination processing model;
[0017] The second internal representation is placed back into the target module to obtain a true response text of the text language model to the input text; wherein the hallucination processing model is trained based on the model training method described in any one of the first aspects.
[0018] According to the above technical means, the embodiment of the present application utilizes the internal modules of the trained hallucination processing model to perform corresponding processing on the internal representation generated by the text language model, without investing a lot of manpower and material resources to continuously update the knowledge base, greatly reducing the cost and workload caused by knowledge base maintenance, making the entire large model hallucination processing process more economical and efficient, and convenient for long-term stable operation. The present application performs spatial mapping based on different spatial encoding modules in the trained hallucination processing model, analyzes and processes the potential representation of the text from the perspective of real space and semantic space, thereby determining whether hallucinations occur and performing subsequent operations, without relying on text vectorization technology to retrieve knowledge, thereby effectively avoiding retrieval errors caused by imperfections in the technology, ensuring the accuracy of large model hallucination judgment and processing, and improving the reliability of the entire large model output content. When it is detected that the text language model has hallucinations during model inference, it can quickly perform authenticity editing on the real latent representation in the real space, and obtain the second internal representation through operations such as the decoding module in combination with the semantic latent representation, and then put it back into the target module to obtain the real reply text. The whole process forms a highly targeted closed-loop processing mechanism, which can correct the hallucination problems in time, so that the large model can quickly output realistic, accurate and reasonable reply content, which significantly improves the timeliness and effectiveness of dealing with hallucination problems.
[0019] Furthermore, the real potential representation is subjected to authenticity editing in the real space to obtain a processed real potential representation, including: obtaining a first real editing direction determined by a real space encoding module for the real potential representation, wherein the space encoding module includes the real space encoding module; based on the first real editing direction, the real potential representation is subjected to authenticity editing in different directions to obtain a first real potential representation and a second real potential representation, wherein the processed real potential representation includes the first real potential representation and the second real potential representation.
[0020] According to the above-mentioned technical means, the true latent representation is edited in different directions to obtain editing effects with different degrees of bias, thereby distinguishing the first true latent representation from the second true latent representation; therefore, when dealing with the large model hallucination problem, according to the specific severity of the hallucination or the expected correction effect, the first true latent representation with a stronger degree of bias and the second true latent representation with a relatively weaker degree of bias can be used to generate the true editing direction of the internal representation of the text, which helps to eliminate hallucinations more accurately, optimize the quality of the final output text, and make the large model response more in line with the actual situation.
[0021] Furthermore, based on the processed real latent representation and the semantic latent representation, a second internal representation is obtained through a decoding module in the hallucination processing model, including: based on the first real latent representation and the semantic latent representation, the internal representation of the target module is reconstructed by the decoding module to obtain a first reconstructed internal representation; based on the second real latent representation and the semantic latent representation, the internal representation of the target module is reconstructed by the decoding module to obtain a second reconstructed internal representation; based on the first reconstructed internal representation and the second reconstructed internal representation, a second real editing direction of the first internal representation is determined; an editing weight of the second real editing direction is obtained, and based on the second real editing direction and the editing weight, the first internal representation is authenticity edited to obtain the second internal representation.
[0022] According to the above technical means, the embodiment of the present application obtains the first real editing direction of the real potential representation given by the hallucination processing module and obtained by training in the real space, and converts the first real editing direction of the real potential representation into the second real editing direction in the space where the first internal representation is located by reconstructing the internal representation of the target module based on the first real potential representation and the second real potential representation and the semantic potential representation, so that the influence of different potential representations in the reconstruction process is fully considered, so as to accurately locate the appropriate editing direction and control the editing strength, so that the authenticity editing of the first internal representation is more in line with actual needs, and is more helpful to accurately correct the possible large model hallucination problem and improve the accuracy of the processing. Further, after determining the direction of the second real editing direction, the editing weight corresponding to the first internal representation is introduced, and the editing weight is used to perform authenticity editing on the first internal representation along the second real editing direction, so as to ensure that the authenticity editing of the first internal representation can effectively respond to various changes, thereby increasing the authenticity of the text language model; at the same time, the entire large model hallucination processing mechanism can play a stable role in a variety of application scenarios, with stronger adaptability and flexibility.
[0023] Further, the text language model includes multiple layers, and the authenticity editing of the first internal representation based on the second true editing direction and the editing weight to obtain the second internal representation includes: obtaining the detection accuracy of target modules located in different layers; selecting a target module whose detection accuracy is greater than a detection accuracy threshold from the target modules included in each layer; and authenticity editing the first internal representation of the selected target module based on the second true editing direction and the editing weight to obtain the second internal representation.
[0024] According to the above technical means, by obtaining the detection accuracy of target modules located at different layers, and selecting target modules with detection accuracy greater than the detection accuracy threshold for subsequent operations, it is possible to accurately locate those target modules that are more critical and more valuable for processing large model hallucinations. On this basis, authenticity editing is carried out according to the second true editing direction and editing weight to obtain the second internal representation, so that the entire editing process focuses on the module parts that are more likely to have problems and deserve more attention, avoiding the situation of indiscriminate treatment of all target modules, greatly enhancing the pertinence of the processing, and improving the accuracy of editing the internal representation, which helps to more accurately correct the adverse effects of large model hallucinations and reduce computing resources.
[0025] In a third aspect, the present application provides a model training device, the device comprising:
[0026] A first acquisition module is used to input the constructed triple data into a text language model to obtain a sample internal representation of the triple data by a target module when the text language model is stimulated by the triple data; wherein the triple data includes a sample text, a sample true reply text corresponding to the sample text, and a sample non-true reply text;
[0027] A first processing module is used to use each spatial encoding module in the hallucination processing model to be trained to perform different spatial mappings on the internal representation of the sample to obtain a real potential representation of the sample in a real space and a semantic potential representation of the sample in a semantic space;
[0028] A second processing module is used to reconstruct the internal representation of the target module by using a decoding module in the hallucination processing model to be trained based on the real potential representation of the sample and the semantic potential representation of the sample to obtain a reconstructed internal representation of the sample;
[0029] A first determination module is used to determine the target loss of the hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample real potential representation and the sample semantic potential representation;
[0030] The third processing module is used to adjust the parameters of the hallucination processing model to be trained based on the target loss to obtain a trained hallucination processing model; wherein the trained hallucination processing model satisfies a preset convergence condition. .
[0031] In a fourth aspect, the present application provides a device for processing model hallucination, the device comprising:
[0032] A second obtaining module is used to obtain a first internal representation of the input text by the target module when the text language model performs model reasoning on the input text;
[0033] a fourth processing module, configured to use each spatial encoding module in the hallucination processing model to perform spatial mapping on the first internal representation respectively, to obtain a real potential representation in a real space and a semantic potential representation in a semantic space, and to obtain a detection result of whether hallucination occurs when the text language model performs model inference based on the real potential representation and the semantic potential representation;
[0034] A fifth processing module is configured to, if the detection result indicates that the text language model has hallucinations when performing model inference, perform authenticity editing processing on the real potential representation in the real space to obtain a processed real potential representation; and obtain a second internal representation through a decoding module in the hallucination processing model based on the processed real potential representation and the semantic potential representation;
[0035] A third acquisition module is used to put the second internal representation back into the target module to obtain the true response text of the text language model to the input text; wherein the hallucination processing model is trained based on the model training method described in any one of the first aspects.
[0036] In a fifth aspect, the present application provides a computer device, the computer device comprising: a memory and a processor,
[0037] The memory stores a computer program executable on the processor;
[0038] When the processor executes the computer program, it implements part or all of the steps in the model training method described in any one of the first aspects, or part or all of the steps in the model hallucination processing method described in any one of the second aspects.
[0039] In the sixth aspect, the present application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores one or more computer programs, and the one or more computer programs can be executed by one or more processors to implement part or all of the steps in the model training method described in any one of the first aspect, or part or all of the steps in the model hallucination processing method described in any one of the second aspect.
[0040] In the seventh aspect, the present application provides a computer program product, including a computer program or instructions, characterized in that when the computer program or instructions are executed by a processor, part or all of the steps in the model training method described in any one of the first aspects, or part or all of the steps in the model hallucination processing method described in any one of the second aspects are implemented.
[0041] Beneficial effects of this application:
[0042] 1) This application edits the internal representation of the LLM to guide it to generate real responses in the real space, reducing the reliance on external knowledge bases and improving the autonomy and flexibility of the method. This method uses comparative learning to move the large model towards real or unreal output, which increases the fun and creativity and provides more possibilities for the application of large models.
[0043] 2) This application can mine the knowledge that has been learned inside the LLM, improve the utilization rate of the model, and avoid the tedious process of constantly adding new knowledge to the knowledge base. This method has good portability and can be directly applied to different large models, improving the versatility and scalability of the technology.
[0044] 3) This application can significantly reduce the cost of manually collecting knowledge bases, reduce the cost of large model applications, and improve economic benefits. This method improves the credibility and effectiveness of LLM in practical applications, and helps promote the widespread application and commercial development of large model technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0046] Figure 1 A schematic diagram of an implementation flow of an optional model training method provided in an embodiment of the present application;
[0047] Figure 2 A structural block diagram of a part of target modules in an optional text language model provided in an embodiment of the present application;
[0048] Figure 3 A schematic diagram of the structure of an optional hallucination processing model provided in an embodiment of the present application;
[0049] Figure 4 A schematic diagram of an implementation flow of an optional model training method provided in an embodiment of the present application;
[0050] Figure 5A schematic diagram of an implementation flow of an optional method for processing model hallucination provided in an embodiment of the present application;
[0051] Figure 6 A schematic diagram of an implementation flow of an optional method for processing model hallucination provided in an embodiment of the present application;
[0052] Figure 7 A schematic diagram of a processing process of an optional method for processing model hallucination provided in an embodiment of the present application;
[0053] Figure 8 A structural block diagram of an optional model training and hallucination processing provided in an embodiment of the present application;
[0054] Fig. 9 A schematic diagram of the structure of an optional model training device provided in an embodiment of the present application;
[0055] Fig.10 A schematic diagram of the structure of an optional model illusion processing device provided in an embodiment of the present application;
[0056] Fig.11 A schematic diagram of the structure of an optional computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions of the present application are further elaborated in detail below in conjunction with the drawings and embodiments. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0058] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. The terms "first / second / third" involved are merely used to distinguish similar objects and do not represent a specific order for the objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing this application and are not intended to limit this application.
[0060] Reference Figure 1 , Figure 1A schematic diagram of a model training method provided in an embodiment of the present application, which can be executed by a processor of a computer device, is shown in FIG. Figure 1 The steps shown are explained,
[0061] Step 101: Input the constructed triple data into the text language model to obtain the sample internal representation of the triple data by the target module when the text language model is stimulated by the triple data.
[0062] The triplet data includes sample text, sample true reply text corresponding to the sample text, and sample false reply text.
[0063] In the embodiment of the present application, the triple data is sample data, and the triple data includes sample text, sample real reply text corresponding to the sample text, and sample non-real reply text. Here, the sample text can be a question text, the sample real reply text can be a real answer text for replying to the question text, and the sample non-real reply text can be a non-real answer text for replying to the question text. For example, the triple data D = {(Q, A pos ,A neg )}, where Q represents the sample question text, A pos represents the sample true answer text, A neg Indicates sample non-real answer text.
[0064] In the embodiment of the present application, the text language model may be an LLM model, which is used to generate a reply text based on an input question text. The LLM model can be applied in the field of natural language processing and can process natural language.
[0065] In an embodiment of the present application, the target module is a module in the text language model that has a high degree of influence on the authenticity of the text content of the reply. The target module can be an attention module (ATTN) and / or a feed forward neural network module (FFN). The ATTN module and / or the FFN module can extract information from the context and parameters and add it to the residual network. The hallucination should logically originate from the representation generated by the ATTN module and the FFN module.
[0066] In some embodiments, the target module is an attention module and / or a feed-forward neural network module; wherein,
[0067] If the target module is an attention module, the internal representation of the sample is the internal representation of the output of the attention module;
[0068] If the target module is a feedforward neural network module, the internal representation of the sample is the internal representation of the output of the feedforward neural network module;
[0069] If the target module is an attention module and a feedforward neural network module, the internal representation of the sample is the internal representation obtained by fusing the internal representation output by the attention module and the internal representation output by the feedforward neural network module.
[0070] In one possible implementation, referring to Figure 2 As shown, the target module includes the attention module and the feedforward neural network module in the transform block in the text language model. The triple data is input into the text language model, and the output representation of the triple data by the attention module and the FFN module is automatically detected when the text language model is stimulated by the triple data. The internal representation of the output of the attention module and the FFN module is fused through the residual network to obtain the sample internal representation corresponding to the triple data. In this way, the sample real reply text and the sample non-real reply text are used to stimulate the text language model, and the internal representation of the target module is extracted when generating content of opposite authenticity.
[0071] In the embodiment of the present application, the internal representation of the sample is the feature output by the target module when processing the triple data when the text language model is stimulated by the input triple data. The internal representation of the sample includes the true internal representation of the sample and the non-true internal representation of the sample.
[0072] In some embodiments, obtaining a sample internal representation of triple data by a target module when a text language model is stimulated by triple data includes:
[0073] The target module obtains sample true internal representations of text tokens of the sample text when the text language model is stimulated by the sample text and the sample true response text; the target module obtains sample non-true internal representations of text tokens of the sample text when the text language model is stimulated by the sample text and the sample non-true response text.
[0074] It can be understood that, given the triple data D, the triple data D is input into the text language model, and the sample question text Q and the sample real answer text A are used to calculate the language model. pos Stimulate the text language model and extract the sample true internal representation output by the target module in the text language model; through the sample question text Q and the sample non-real answer text A neg Stimulate the text language model and extract the sample non-true internal representation output by the target module in the text language model.
[0075] In one possible scenario, refer to Figure 3 As shown, the sample true internal representation X output by the attention module in each layer of the text language model and the sample true answer text in the FFN module can be extracted when it is stimulated pos(can be used as a positive sample), and extract the sample non-real internal representation X output by the attention module and FFN module in each layer of the text language model when the sample non-real answer text is stimulated neg (can be used as negative samples), so as to obtain the internal representation of the sample X∈{X pos , X neg}. Among them, X pos ={x pos}, X neg ={x neg},here, The internal representation of the text token of the same question text under the stimulation of the real answer text and the non-real answer text, d model is the dimension of the hidden state of the text language model. In this way, the text language model is stimulated by using sample true answer text and sample non-true answer text. Since the hallucination should logically originate from the target module, the internal representation of the target module is extracted when generating content of opposite authenticity, and the internal representation of the target module that produces the hallucination can be precisely adjusted.
[0076] Step 102: Use each spatial encoding module in the hallucination processing model to be trained to perform different spatial mappings on the internal representation of the sample to obtain a real potential representation of the sample in the real space and a semantic potential representation of the sample in the semantic space.
[0077] In the embodiment of the present application, the hallucination processing model is used to perform hallucination detection and authenticity editing on the internal representation of the extracted target module. The hallucination processing module includes a spatial encoding module and a decoding module. The spatial encoding module includes a real space encoding module and a semantic space encoding module. It should be noted that each module is implemented by a multilayer perceptron (MLP). In practical applications, the hallucination processing module can be understood as an automatic encoder.
[0078] Here, the spatial encoding module is used to perform spatial mapping on the internal representation of the extracted target module to obtain the potential representation under the space; the real space encoding module is used to perform real space mapping on the internal representation of the extracted target module to obtain the real potential representation under the real space, and the semantic space encoding module is used to perform semantic space mapping on the internal representation of the extracted target module to obtain the semantic potential representation under the semantic space. The decoding module is used to reconstruct based on the potential representations of different spaces to obtain the reconstructed internal representation.
[0079] In some embodiments, using each spatial encoding module in the hallucination processing model to be trained, different spatial mappings are performed on the internal representation of the sample to obtain the real potential representation of the sample in the real space and the semantic potential representation of the sample in the semantic space, including:
[0080] The real space encoding module in the hallucination processing model is used to perform real space mapping on the internal representation of the sample to obtain the real potential representation of the sample in the real space; the semantic space encoding module in the hallucination processing model is used to perform semantic space mapping on the internal representation of the sample to obtain the semantic potential representation of the sample in the semantic space.
[0081] In the embodiment of the present application, a real space encoding module is used to perform real space mapping on the real internal representation of the sample and the non-real internal representation of the sample, respectively, to obtain the real potential representation of the sample corresponding to the real internal representation of the sample in the real space, and the real potential representation of the sample corresponding to the non-real internal representation of the sample. Similarly, a semantic space encoding module is used to perform semantic space mapping on the real internal representation of the sample and the non-real internal representation of the sample, respectively, to obtain the sample semantic potential representation corresponding to the real internal representation of the sample in the semantic space, and the sample semantic potential representation corresponding to the non-real internal representation of the sample.
[0082] In a feasible scenario, continue to refer to Figure 3 , the spatial encoding module (also called spatial encoder) includes a real encoder and a real encoder. Through the real encoder (Truthful Encoder) TruthEnc(·) in the hallucination processing model, the sample internal representation of the target module of the extracted text language model is mapped to the real space (TruthfulSpace), and through the semantic encoder (Semantic Encoder) SemEnc(·) in the hallucination processing model, the sample internal representation of the target module of the extracted text language model is mapped to the semantic space (Semantic Space), which can be achieved by the following formula (1),
[0083] h truth =TruthEnc(X),h sem =SemEnc(X) (1)
[0084] Among them, X is the internal representation of the sample, h truth is the real potential representation of the sample in the real space, h sem is the potential semantic representation of the sample in the semantic space, Its dimension is d latent .
[0085] Step 103: Based on the real potential representation of the sample and the semantic potential representation of the sample, the decoding module in the hallucination processing model to be trained is used to reconstruct the internal representation of the target module to obtain the reconstructed internal representation of the sample.
[0086] It can be understood that the decoding module is used to reconstruct the internal representation of the target module from the true potential representation of the sample and the semantic potential representation of the sample to obtain the reconstructed internal representation of the sample.
[0087] In one possible implementation, the decoding module (also called decoder) reconstructs the internal representation of the target module, and the sample reconstructed internal representation can be implemented by the following formula (2):
[0088] X′=Dec(h sem +Attn(h sem ,h truth )) (2)
[0089] Among them, X′ is the internal representation of sample reconstruction, Dec(·) is the decoding module, and h sem is the potential semantic representation of the sample in the semantic space, h truth is the real potential representation of the sample in the real space, and Attn is the attention operation.
[0090] Step 104: Determine a target loss of a hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true latent representation, and the sample semantic latent representation.
[0091] Step 105: Based on the target loss, the parameters of the hallucination processing model to be trained are adjusted to obtain a trained hallucination processing model.
[0092] Among them, the trained hallucination processing model meets the preset convergence conditions.
[0093] In an embodiment of the present application, the preset convergence conditions include: the number of iterations of the hallucination processing model reaches a preset number of iterations, or the target loss is less than a preset loss, wherein the preset number of iterations and the preset loss can be determined based on empirical values.
[0094] In an embodiment of the present application, after reconstructing the internal representation of the target module from the sample true potential representation and the sample semantic potential representation using the decoding module to obtain the sample reconstructed internal representation, the target loss of the hallucination processing model to be trained is determined based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true potential representation and the sample semantic potential representation; further, based on the target loss, the parameters of the hallucination processing model to be trained are adjusted once or multiple times so that the trained hallucination processing model meets the preset convergence conditions.
[0095] As can be seen from the above, the embodiment of the present application can capture text-related feature information from multiple dimensions by inputting triple data including sample text, sample real reply text and sample non-real reply text into the text language model to obtain the target module's internal representation of the sample. It helps the model to be more sensitive to the differences in text features that may cause hallucinations and improve the accuracy of identifying hallucination phenomena. Using each spatial encoding module in the hallucination processing model to be trained, the internal representation of the sample is mapped to different spaces to obtain the real potential representation of the sample in the real space and the semantic potential representation of the sample in the semantic space. The embodiment of the present application does not need to rely on an external knowledge base. Through the multi-space presentation method, the potential semantics and real associations of the text are analyzed from different angles, and more obscure clues related to hallucinations can be excavated, so that the model can more comprehensively identify the hallucination features present in different reply texts, and further enhance the recognition ability of hallucinations. Based on the sample's true potential representation and the sample's semantic potential representation, the internal representation of the target module is reconstructed with the help of a decoding module to obtain the sample's reconstructed internal representation, so that the internal representation that may have deviations can be reasonably adjusted according to the mined text's true and semantic information, thereby providing strong support for the subsequent accurate correction of erroneous replies caused by hallucinations, enabling the model to have more accurate correction capabilities, and making the output replies closer to the real situation. The target loss of the hallucination processing model to be trained is determined based on at least part of the sample's reconstructed internal representation, the sample's internal representation, the sample's true potential representation, and the sample's semantic potential representation, which helps guide the model to adjust parameters in the right direction, avoid defects caused by one-sided training, and ensure the rationality and effectiveness of the training process. The parameters of the hallucination processing model to be trained are adjusted according to the determined target loss until the preset convergence conditions are met to obtain a trained hallucination processing model, thereby improving the overall ability of the model to deal with hallucination problems and outputting high-quality reply content.
[0096] In some embodiments, step 104 combines the process of determining the target loss of the hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true potential representation, and the sample semantic potential representation. Figure 4 To further explain,
[0097] Step 401: Obtain a reconstruction loss of a hallucination processing model based on the sample reconstructed internal representation and the sample internal representation.
[0098] In an embodiment of the present application, after using the decoding module to reconstruct the internal representation of the target module from the sample's true potential representation and the sample's semantic potential representation to obtain the sample's reconstructed internal representation, the mean square error between the sample's reconstructed internal representation and the sample's internal representation is calculated to obtain the reconstruction loss of the hallucination processing model.
[0099] Here, the hallucination processing model can be optimized based on the reconstruction loss between the internal representation of the sample and the internal representation of the sample reconstruction. The reconstruction loss of the hallucination processing model can be obtained by the following formula (3):
[0100] L recon =MSE(X,X′) (3)
[0101] Among them, L recon is the reconstruction loss of the hallucination processing model, X is the internal representation of the sample, X′ is the internal representation of the sample reconstruction, and MSE(·) is the mean square error loss function.
[0102] Step 402: Based on the true latent representation of the sample, the semantic latent representation of the sample, and the internal representation of the sample, a contrastive learning loss and an editing loss of the hallucination processing model are obtained.
[0103] It is understandable that in order to encourage the real space and semantic space to capture real features and semantic features respectively, contrastive learning is used for the potential representations in these two spaces. Here, the goal of contrastive learning is briefly explained. For the representation S in the space, a sample set S with the same category as the representation S is constructed. + , and the sample sets S representing S come from different categories - Contrastive learning is achieved by minimizing S and S + The distance between them, while maximizing S and S - The distance between them is used to align the representations in the space. The training objective can be expressed by the following formula (4):
[0104]
[0105] where sim(·,·) refers to the cosine similarity between two representations and τ is the temperature, which can be calculated based on S and S + The distance between S and S - The condition is performed based on the distance between them. For example, the initial τ=0.1.
[0106] In the embodiment of the present application, real features and semantic features are captured in the real space and the semantic space respectively, and contrastive learning can be used to create a clear boundary between real samples (i.e., real internal representation of samples) and non-real samples (i.e., non-real internal representation of samples) in the real space, and to create a clear boundary between samples with different semantics (real internal representation of samples and non-real internal representation of samples) in the semantic space. Therefore, positive and negative samples corresponding to different spaces are constructed, and the contrastive learning loss of the hallucination processing model is obtained based on the real potential representation of samples, the semantic potential representation of samples, and the internal representation of samples using the contrastive learning goal.
[0107] It can be understood that after mapping the sample internal representation of the text language model to the real space and the semantic space, the purpose is to edit the sample real potential representation in the real space for authenticity and reconstruct the corresponding representation. Therefore, in order to improve the ability to reconstruct the edited sample real potential representation in the real space, an editing loss is introduced. With the help of the editing loss, the authenticity can be adjusted by editing the sample real potential representation in the real space. Therefore, the present application can exchange the sample real potential representation corresponding to the sample internal representation with opposite authenticity according to the sample real potential representation, the sample semantic potential representation and the sample internal representation, so as to obtain the editing loss of the authenticity of the hallucination processing model based on the exchanged sample real potential representation, the sample internal representation and the sample semantic potential representation.
[0108] Step 403: Determine a target loss based on one or more of the reconstruction loss, the contrastive learning loss, and the editing loss.
[0109] In an embodiment of the present application, after obtaining the reconstruction loss, contrastive learning loss and editing loss, the target loss of the hallucination processing model can be determined according to part or all of the reconstruction loss, contrastive learning loss and editing loss, and then based on the target loss, the parameters of the hallucination processing model are adjusted once or multiple times so that the trained hallucination processing model meets the preset convergence conditions.
[0110] In some embodiments, step 402 combines the process of obtaining the contrastive learning loss and the editing loss of the hallucination processing model based on the sample real potential representation, the sample semantic potential representation and the sample internal representation. Figure 5 To further explain,
[0111] Step 501: for a given sample latent representation, based on the sample real latent representation and the sample semantic latent representation, construct a positive sample latent representation set and a negative sample latent representation set corresponding to the sample latent representation in the target space.
[0112] The target space includes a real space and a semantic space, and a given sample potential representation is one of the sample real potential representation and the sample semantic potential representation.
[0113] In the embodiment of the present application, the given sample latent representation can be a given sample true latent representation or a given sample semantic latent representation. It should be noted that the given sample true latent representation is one of the sample true latent representations corresponding to all sample internal representations, that is, the given sample true latent representation is one of the sample true latent representations corresponding to the sample true internal representation in any sample internal representation and the sample true latent representation corresponding to the sample non-true internal representation among all sample internal representations. Similarly, the given sample semantic latent representation is one of the sample semantic latent representations corresponding to all sample internal representations, that is, the given sample semantic latent representation is one of the sample semantic latent representations corresponding to the sample true internal representation in any sample internal representation and the sample semantic latent representation corresponding to the sample non-true internal representation among all sample internal representations.
[0114] In the embodiment of the present application, if the given sample potential representation is the given sample real potential representation, based on all the sample real potential representations, a positive sample potential representation set and a negative sample potential representation set corresponding to the given sample real potential representation in the real space are constructed. If the given sample potential representation is the given sample semantic potential representation, based on all the sample semantic potential representations, a positive sample potential representation set and a negative sample potential representation set corresponding to the given sample semantic potential representation in the semantic space are constructed.
[0115] In some embodiments, the target space is a real space, and the given sample potential representation is a given sample real potential representation; for the given sample potential representation, based on the sample real potential representation and the sample semantic potential representation, constructing a positive sample potential representation set and a negative sample potential representation set corresponding to the sample potential representation in the target space, including:
[0116] For a given sample true latent representation, the sample true latent representations with the same authenticity as the given sample true latent representation in the real space are constructed as the positive sample latent representation set; the sample true latent representations with the opposite authenticity as the given sample true latent representation in the real space are constructed as the negative sample latent representation set.
[0117] In one possible implementation, continue to refer to Figure 3 , since contrastive learning is performed on the entire dataset, the true internal representation of all samples in the real space (also known as all positive samples or real samples) x pos ∈X pos The set of corresponding sample true potential representations is determined as the first sample true potential representation set Similarly, all samples in the real space are not real internal representations (also known as all negative samples or non-real samples) x neg ∈X negThe set of corresponding sample true potential representations is determined as the second sample true potential representation set
[0118] It should be noted that in the real space, the real potential representation of real samples and non-real samples should be different. Therefore, for a given sample real potential representation (or ), will be compared with the true potential representation of the given sample (or ) The first sample true potential representation set with the same authenticity (or the second sample true potential representation set ), which is determined as the potential representation set S of positive samples in the real space + ; Similarly, it will be compared with the true potential representation of the given sample (or ) The second sample true potential representation set with opposite authenticity (or the first sample true potential representation set ), which is determined as the potential representation set S of negative samples in the real space - Thus, by introducing contrastive learning, since the real potential representations of samples corresponding to real samples and non-real samples are different in the real space, a clear boundary between real samples and non-real samples is created in the real space, which can capture the real features and detect real or false representations.
[0119] In some embodiments, the target space is a semantic space, and the given sample potential representation is a given sample semantic potential representation; for the given sample potential representation, based on the sample real potential representation and the sample semantic potential representation, a positive sample potential representation set and a negative sample potential representation set corresponding to the sample potential representation in the target space are constructed, including:
[0120] For a given sample semantic latent representation, the sample true latent representation with the same authenticity as the given sample semantic latent representation in the semantic space is determined as the sample semantic latent representation set; the sample semantic latent representation with the same text token and opposite authenticity as the given sample semantic latent representation is determined as the positive sample latent representation set; the remaining sample semantic latent representations in the sample semantic latent representation set except the given sample semantic latent representation are determined as the negative sample latent representation set.
[0121] In one possible implementation, continue to refer to Figure 3 , since contrastive learning is performed on the entire dataset, the true internal representation of all samples in the semantic space (also known as all positive samples or real samples) x pos ∈X posThe set of corresponding sample semantic latent representations is determined as the first sample semantic latent representation set Similarly, all samples in the semantic space are not real internal representations (also known as all negative samples or non-real samples) x neg ∈X neg The set of corresponding sample semantic latent representations is determined as the second sample semantic latent representation set
[0122] It should be noted that in the semantic space, the sample semantic latent representations corresponding to the sample internal representations with different sample text token meanings should be different. Therefore, for a given sample semantic latent representation (or ), will be combined with the given sample semantic potential representation (or ) Sample semantic latent representations from the same text token with opposite authenticity (or ), which is determined as the potential representation set S of positive samples in the semantic space + . Will be combined with the given sample semantic latent representation (or ) The first sample semantic latent representation set with the same authenticity (or the second sample semantic potential representation set ), remove the given sample semantic potential representation (or ), and obtain the potential representation of the sample semantics (or ) is a set of latent semantic representations of samples with the same authenticity but different meanings. (or ), and the collection (or ) is determined as the potential representation set S of negative samples - Thus, by introducing contrastive learning, since the semantic potential representations of samples corresponding to real samples and non-real samples are different in the semantic space, a clear boundary between samples with different semantics is created in the semantic space, which can capture semantic features.
[0123] Step 502: Based on the potential representation set of positive samples and the potential representation set of negative samples, contrastive learning is performed on the given sample potential representation to obtain the contrastive learning loss in the target space, and the sum of the contrastive learning losses in all target spaces is determined as the contrastive learning loss of the hallucination processing model.
[0124] In the embodiment of the present application, when the target space is the real space and the given sample potential representation is the given sample real potential representation; for the given sample real potential representation, based on the positive sample potential representation set and the negative sample potential representation set corresponding to the given sample real potential representation, the given sample real potential representation can be subjected to comparative learning by the following formula (5) to obtain the comparative learning loss in the real space.
[0125]
[0126] Among them, L truth is the contrastive learning loss in real space, and is the true potential representation of a given sample, is the true potential representation set of the first sample, is the true potential representation set of the second sample.
[0127] In an embodiment of the present application, when the target space is a semantic space and the given sample latent representation is a given sample semantic latent representation; for the given sample semantic latent representation, based on the positive sample latent representation set and the negative sample latent representation set corresponding to the given sample semantic latent representation, the given sample semantic latent representation can be contrastively learned by the following formula (6) to obtain the contrastive learning loss in the semantic space.
[0128]
[0129] Among them, L sem is the contrastive learning loss in semantic space, and is the semantic potential representation of a given sample, is the semantic potential representation of a given sample The latent semantic representations of samples from the same text token with opposite authenticity, is the first sample semantic potential representation set, is the semantic potential representation set from the first sample Remove the given sample semantic potential representation is the semantic potential representation of a given sample The latent semantic representations of samples from the same text token with opposite authenticity, is the second sample semantic potential representation set, is the semantic potential representation set from the second sample Remove the given sample semantic potential representation
[0130] Furthermore, we obtain the contrastive learning loss L in the real space truthAnd the contrastive learning loss L in semantic space sem , the contrastive learning loss of the hallucination processing model can be obtained by the following formula (7).
[0131] L ctr =L truth +L sem (7)
[0132] Among them, L ctr Contrastive learning loss for hallucination handling models.
[0133] Step 503: Obtain the sample real potential representation corresponding to the sample internal representation of the text token of the same sample text in the real space.
[0134] The internal representation of the sample includes the true internal representation of the sample and the non-true internal representation of the sample.
[0135] It can be understood that the sample internal representation x of the text token of the same sample text can be obtained firstly. pos , x neg ), and then obtain the internal representation of the sample x = (x pos , x neg ) corresponds to the real potential representation of the sample in the real space That is, obtain the true internal representation x of the sample in the sample internal representation pos The corresponding sample true potential representation in real space And the sample's non-real internal representation x neg The corresponding sample true potential representation in real space
[0136] Step 504: exchange the sample true latent representation corresponding to the sample true internal representation and the sample true latent representation corresponding to the sample non-true internal representation, and determine the editing loss based on the exchanged sample true latent representation, sample semantic latent representation, sample true internal representation and sample non-true internal representation.
[0137] It can be understood that after obtaining the sample real potential representation corresponding to the sample internal representation of the text token of the same sample text in the real space, the sample real internal representation x pos The corresponding sample true potential representation With the sample non-real internal representation x neg The corresponding sample true potential representation Exchange to obtain the true internal representation x of the sample pos The corresponding exchanged sample true potential representation And the sample's non-real internal representation x neg The corresponding exchanged sample true potential representation Furthermore, based on the exchanged sample true latent representation, sample semantic latent representation, sample true internal representation and sample non-true internal representation, the editing loss is determined, so that the authenticity of the internal representation extracted by the text language model can be adjusted by editing the true latent representation in the real space.
[0138] In some embodiments, in step 504, based on the exchanged sample real potential representation, sample semantic potential representation, sample real internal representation, and sample non-real internal representation, determining the editing loss may be achieved by the following process:
[0139] For the sample true internal representation, based on the sample semantic potential representation and the sample true potential representation corresponding to the sample non-true internal representation, a decoding module is used to reconstruct the internal representation of the target module to obtain a first sample exchanged reconstructed internal representation, wherein the exchanged sample true potential representation includes the sample true potential representation corresponding to the sample non-true internal representation; for the sample non-true internal representation, based on the sample semantic potential representation and the sample true potential representation corresponding to the sample true internal representation, a decoding module is used to reconstruct the internal representation of the target module to obtain a second sample exchanged reconstructed internal representation, wherein the exchanged sample true potential representation includes the sample true potential representation corresponding to the sample true internal representation; based on the first sample exchanged reconstructed internal representation, the sample true internal representation, the second sample exchanged reconstructed internal representation and the sample non-true internal representation, an editing loss is obtained.
[0140] In one possible implementation, after exchanging the sample's true latent representation corresponding to the sample's true internal representation and the sample's true latent representation corresponding to the sample's non-true internal representation,
[0141] For the true internal representation of the sample x pos , based on the true internal representation of the sample x pos Corresponding sample semantic latent representation And the sample's non-real internal representation x neg The corresponding sample true potential representation The decoding module is used to reconstruct the internal representation of the target module through the following formula (8), and the first sample exchange reconstructed internal representation x is obtained. pos→neg Similarly, for the sample's non-real internal representation x neg , based on the sample's non-real internal representation x neg Corresponding sample semantic latent representation And the true internal representation of the sample x pos The corresponding sample true potential representation The decoding module is used to reconstruct the internal representation of the target module through the following formula (9), and the second sample exchange reconstructed internal representation x is obtained.neg→pos .
[0142]
[0143] It should be noted that the first sample exchange reconstructs the internal representation x pos→neg is the true internal representation of the sample x pos Corresponding sample semantic latent representation And the sample's non-real internal representation x neg The corresponding sample true potential representation The reconstruction is obtained, which means that the truth changes from positive to negative. Therefore, the first sample exchange reconstructs the internal representation x pos→neg It is expected to be close to the sample's non-true internal representation x neg Similarly, the second sample exchange reconstructs the internal representation x neg→pos is the non-true internal representation x of the sample neg Corresponding sample semantic latent representation And the true internal representation of the sample x pos The corresponding sample true potential representation The reconstruction is obtained, which means that the truth changes from negative to positive. Therefore, the second sample exchange reconstructs the internal representation x neg →pos It is expected to be close to the true internal representation of the sample x pos .
[0144] Further, the internal representation x is reconstructed based on the first sample exchange pos→neg , the true internal representation of the sample x pos , the second sample exchange reconstructs the internal representation x neg→pos and the sample's non-real internal representation x neg , the editing loss of the hallucination mitigation model is obtained through the following formula (10).
[0145] L edit =MSE(x neg ,x pos→neg )+MSE(x pos ,x neg→pos ) (10)
[0146] Among them, L edit Loss for editing.
[0147] Here, with the help of editing loss, the authenticity of the internal representation of the target module of the text language model can be adjusted by editing the real potential representation in the real space. The target loss can be composed of reconstruction loss, contrastive learning loss and editing loss, as expressed by the following formula (11):
[0148] L=L recon +L ctr+L edit (11)
[0149] It should be noted that after the hallucination processing model is trained, the sample's true latent representation corresponding to the sample's true internal representation and the sample's true latent representation corresponding to the sample's non-true internal representation will show different distributions in the real space. In order to determine a true editing direction in this space, it points from the center of the sample's true latent representation corresponding to the sample's non-true internal representation to the center of the sample's true latent representation corresponding to the sample's true internal representation. Here, the true editing direction It can be expressed by the following formula (12):
[0150]
[0151] in, It is the average true potential representation of the sample true potential representation corresponding to the true internal representation of all samples in the entire dataset in the real space, It is the average true potential representation of the sample true potential representation corresponding to the non-true internal representation of all samples in the entire dataset in the real space. It should be noted that since the entire dataset can be dynamically changing, the hallucination processing model can dynamically adjust the true editing direction based on the obtained internal representation, thus improving the generalization ability of the model.
[0152] Reference Figure 6 , Figure 6 A schematic diagram of a process flow for processing a model illusion provided in an embodiment of the present application, the method can be executed by a processor of a computer device, and here, the method is combined with Figure 6 The steps shown are explained,
[0153] Step 601: Obtain a first internal representation of the input text by a target module when the text language model performs model inference on the input text.
[0154] In the embodiment of the present application, the input text refers to the input of the text language model, and the input text can be a question in text form, such as "Are you a human?".
[0155] In an embodiment of the present application, the target module is a module in the text language model that has a high degree of influence on the authenticity of the text content of the reply. The target module may be an ATTN module and / or an FFN module. The ATTN module and / or the FFN module may extract information from the context and parameters and add it to the residual network. The hallucination should logically originate from the representations generated by the ATTN module and the FFN module.
[0156] In some embodiments, the target module is an attention module and / or a feed-forward neural network module; wherein,
[0157] If the target module is an attention module, the first internal representation is the internal representation of the output of the attention module;
[0158] If the target module is a feedforward neural network module, the first internal representation is an internal representation of the output of the feedforward neural network module;
[0159] If the target module is an attention module and a feedforward neural network module, the first internal representation is an internal representation obtained by fusing the internal representation output by the attention module and the internal representation output by the feedforward neural network module.
[0160] In the embodiment of the present application, the first internal representation is the feature output by the target module when the input text is input into the text language model.
[0161] In one possible scenario, refer to Figure 7 As shown, taking the text language model 71 having N layers as an example, each layer contains two target modules (i.e., attention module + FFN module), the computer device can obtain a large amount of input text, and in the process of inputting each input text (i.e., Question) into the text language model 71 for model inference to obtain inference results, the computer device can extract the first internal representation x of the input text by the target module (i.e., ATTN module and FFN module) of each layer in the text language model 71.
[0162] Step 602: Use each spatial encoding module in the hallucination processing model to perform spatial mapping on the first internal representation to obtain a real latent representation in the real space and a semantic latent representation in the semantic space, and obtain a detection result of whether hallucination occurs in the text language model when performing model inference based on the real latent representation and the semantic latent representation.
[0163] Understandable, continue to refer to Figure 7 As shown, after obtaining the first internal representation of the input text by the target module when the text language model performs model inference on the input text, the first internal representation x output by the target module of the text language model is mapped to the real space and the semantic space through the real encoding module and the semantic space encoding module in the hallucination processing model 72, respectively, to obtain the real potential representation h in the real space. truth and the semantic latent representation h in the semantic space sem ; Further, based on the real latent representation and the semantic latent representation, through the real space encoding module and the semantic space encoding module, it is determined whether the text language model has hallucinations when performing model reasoning, so as to obtain the detection result; wherein, the space encoding module includes the real space encoding module and the semantic space encoding module.
[0164] Step 603: If the detection result indicates that the text language model has hallucinations when performing model inference, the real latent representation is subjected to authenticity editing in the real space to obtain a processed real latent representation; based on the processed real latent representation and the semantic latent representation, a second internal representation is obtained through a decoding module in the hallucination processing model.
[0165] It can be understood that if the detection result indicates that the text language model has hallucinations when performing model inference, the real latent representation is edited for authenticity in the real space so that the processed real latent representation is closer to the real direction; further, based on the processed real latent representation and the semantic latent representation, the internal representation of the target module of the text language model is reconstructed through the decoding module in the hallucination processing model, so as to obtain the reconstructed internal representation, that is, the second internal representation.
[0166] It can be understood that if the detection result indicates that the text language model does not hallucinate when performing model reasoning, there is no need to edit the first internal representation of the target module for authenticity. At this time, the first internal representation of the target module is put back into the text language model, so that the text language model outputs a reply text.
[0167] In some embodiments, if the detection result in step 603 indicates that the text language model has hallucinations when performing model inference, the real potential representation is subjected to authenticity editing in the real space to obtain the processed real potential representation, including:
[0168] A first real editing direction determined by a real space encoding module for a real latent representation is obtained, wherein the space encoding module includes a real space encoding module; based on the first real editing direction, authenticity editing processing is performed on the real latent representation in different directions to obtain a first real latent representation and a second real latent representation, wherein the processed real latent representation includes the first real latent representation and the second real latent representation.
[0169] In the embodiment of the present application, the real potential representations corresponding to different input texts have different first real editing directions determined by the real space encoding module for different real potential representations.
[0170] In one possible implementation, continue to refer to Figure 7 As shown, the real space encoding module is obtained for the real potential representation h truth Determine the first true editing direction δ, where Furthermore, based on the first true editing direction δ, the true potential representation h truth Perform authenticity editing in different directions to obtain the first true potential representation (h truth +δ and the second true latent representation (h truth-δ); wherein the first real potential representation is greater than the second real potential representation. In this way, the real potential representation is edited in different directions to obtain editing effects with different degrees of bias, thereby distinguishing the first real potential representation from the second real potential representation; therefore, when dealing with the large model hallucination problem, according to the specific severity of the hallucination or the desired correction effect, the first real potential representation with a stronger degree of bias and the second real potential representation with a relatively weaker degree of bias can be used to generate the real editing direction of the internal representation of the text, which helps to eliminate hallucinations more accurately, optimize the quality of the final output text, and make the large model response more in line with the actual situation.
[0171] In some embodiments, in step 503, based on the processed real potential representation and semantic potential representation, a second internal representation is obtained through a decoding module in the hallucination processing model, including:
[0172] Based on the first real latent representation and the semantic latent representation, a decoding module is used to reconstruct the internal representation of the target module to obtain a first reconstructed internal representation; based on the second real latent representation and the semantic latent representation, a decoding module is used to reconstruct the internal representation of the target module to obtain a second reconstructed internal representation; based on the first reconstructed internal representation and the second reconstructed internal representation, a second real editing direction of the first internal representation is determined; the editing weight of the second real editing direction is obtained, and based on the second real editing direction and the editing weight, the first internal representation is authenticity edited to obtain a second internal representation.
[0173] In one possible implementation, continue to refer to Figure 7 As shown, based on the first true potential representation (h truth +δ) and the semantic latent representation h sem , the decoding module (also called decoder) is used to reconstruct the internal representation of the target module to obtain the first reconstructed internal representation; based on the second real potential representation (h truth -δ) and semantic latent representation h sem , the decoding module is used to reconstruct the internal representation of the target module to obtain a second reconstructed internal representation; based on the first reconstructed internal representation and the second reconstructed internal representation, the second true editing direction Δ of the first internal representation is determined by the following formula (13), where,
[0174] Δ=Dec(h sem +Attn(h sem ,h truth +δ))-Dec(h sem +Attn(h sem ,h truth -δ)) (13)
[0175] Further, the editing weight α of the second true editing direction Δ is obtained. Based on the second true editing direction Δ and the editing weight α, the first internal representation x is authenticity edited by the following formula (14) to obtain the second internal representation
[0176]
[0177] It should be noted that the editing weight may be a scalar indicating the editing strength.
[0178] As can be seen from the above, the embodiment of the present application obtains the first real editing direction of the real potential representation given by the hallucination processing module and obtained by training in the real space, and converts the first real editing direction of the real potential representation into the second real editing direction in the space where the first internal representation is located by reconstructing the internal representation of the target module based on the first real potential representation and the second real potential representation and the semantic potential representation, so that the influence of different potential representations in the reconstruction process is fully considered, so as to accurately locate the appropriate editing direction and control the editing strength, so that the authenticity editing of the first internal representation is more in line with actual needs, and is more helpful to accurately correct the possible large model hallucination problem and improve the accuracy of the processing. Further, after determining the direction of the second real editing direction, the editing weight corresponding to the first internal representation is introduced, and the editing weight is used to perform authenticity editing on the first internal representation along the second real editing direction, so as to ensure that the authenticity editing of the first internal representation can effectively respond to various changes, thereby increasing the authenticity of the text language model; at the same time, the entire large model hallucination processing mechanism can play a stable role in a variety of application scenarios, with stronger adaptability and flexibility.
[0179] In some embodiments, the text language model includes multiple layers, and based on the second true editing direction and the editing weight, the first internal representation is truthfully edited to obtain the second internal representation, including:
[0180] The detection accuracy of target modules located in different layers is obtained; from the target modules included in each layer, a target module whose detection accuracy is greater than a detection accuracy threshold is selected; based on a second true editing direction and an editing weight, the first internal representation of the selected target module is authenticity edited to obtain a second internal representation.
[0181] In an embodiment of the present application, the text language model includes multiple layers, such as the text language model is a model with 32 layers.
[0182] In the embodiment of the present application, the target module may be located at different layers of the text language model, and the detection accuracy represents the degree of association of the authenticity of the response of the target module of the layer to the input text.
[0183] In a possible implementation, according to the obtained validation data set, the detection accuracy of the target modules located at different layers of the text language model is obtained, and from the target modules contained in each layer, the target modules whose detection accuracy is greater than the detection accuracy threshold are selected, such as the target modules whose detection accuracy is in the TOPN; further, based on the second true editing direction and the editing weight, the first internal representation of the target module whose detection accuracy is in the TOPN is authenticity edited to obtain the second internal representation. Exemplarily, taking the text language model with 32 layers, N=10 as an example, each layer has two target modules (i.e., attention module + FFN module), it can be obtained that the text language model has a total of 64 target modules (i.e., 32 attention modules + 32 FFN modules). Further, the top 10 target modules with the highest detection accuracy are selected from the 64 target modules, and the first internal representations of the 10 target modules are authenticity edited. In this way, by obtaining the detection accuracy of the target modules located at different layers, and selecting the target modules whose detection accuracy is greater than the detection accuracy threshold for subsequent operations, it is possible to accurately locate those target modules that are more critical and more valuable for processing large model hallucinations. On this basis, authenticity editing is carried out according to the second true editing direction and editing weight to obtain the second internal representation, so that the entire editing process focuses on the module parts that are more likely to have problems and deserve more attention, avoiding the indiscriminate treatment of all target modules, greatly enhancing the targeted processing, and improving the accuracy of editing the internal representation, which helps to more accurately correct the adverse effects of large model hallucinations and reduce computing resources.
[0184] Step 604: put the second internal representation back into the target module to obtain the true response text of the text language model to the input text.
[0185] The hallucination processing model is trained based on the model training method in the above embodiment.
[0186] In the embodiment of the present application, based on the processed real potential representation and semantic potential representation, after obtaining the second internal representation through the decoding module in the hallucination processing model, the second internal representation is put back into the target module. During reasoning, the target module moves closer to the real direction based on the second internal representation, thereby obtaining the real response text of the text language model to the input text, such as Figure 7The real reply text in the text language model is "No, I'm an AI assistant." In this way, by editing the internal representation of the target module of the text language model in the real space, this application can deeply mine and utilize the knowledge resources inside the large model, guide it to generate real responses in the real space, and thus significantly reduce the time and cost required for manual collection and organization of the knowledge base. This method not only avoids dependence on external knowledge bases, but also effectively reduces the illusion phenomenon without sacrificing model performance, enhances the authenticity of the model, and keeps its generation ability unaffected. At the same time, it can also achieve efficient training and application of large models, improve credibility and effectiveness in practical applications, and reduce the need for manual intervention.
[0187] From the above, it can be seen that the embodiment of the present application utilizes the internal modules of the trained hallucination processing model to perform corresponding processing on the internal representation generated by the text language model, without investing a lot of manpower and material resources to continuously update the knowledge base, greatly reducing the cost and workload caused by knowledge base maintenance, making the entire large model hallucination processing process more economical and efficient, and convenient for long-term stable operation. The present application performs spatial mapping based on different spatial encoding modules in the trained hallucination processing model, analyzes and processes the potential representation of the text from the perspective of real space and semantic space, thereby determining whether hallucinations occur and performing subsequent operations, without relying on text vectorization technology to retrieve knowledge, thereby effectively avoiding retrieval errors caused by imperfections in the technology, ensuring the accuracy of large model hallucination judgment and processing, and improving the reliability of the entire large model output content. When it is detected that the text language model has hallucinations during model inference, it can quickly perform authenticity editing on the real latent representation in the real space, and obtain the second internal representation through operations such as the decoding module in combination with the semantic latent representation, and then put it back into the target module to obtain the real reply text. The whole process forms a highly targeted closed-loop processing mechanism, which can correct the hallucination problems in time, so that the large model can quickly output realistic, accurate and reasonable reply content, which significantly improves the timeliness and effectiveness of dealing with hallucination problems.
[0188] The following is an exemplary description of the model training method through a specific embodiment, see Figure 8 , Figure 8 This is a general structural block diagram of a model training method and a model hallucination processing method shown in an exemplary embodiment of the present application, which can solve the situation where the large model has correct knowledge but may also produce hallucinations. By editing the internal representation of the large model (corresponding to the above-mentioned text language model) in the real space to introduce the authenticity of the large model, the hallucination is alleviated to a certain extent, giving users a better user experience. The method is reusable and can be quickly iterated to each base large model. Among them, the process of the model hallucination processing method based on real space editing provided in the embodiment of the present application is as follows:
[0189] First, the triple data 801 is input into the large model, the large model is stimulated with real answers and non-real answers, and when generating content with opposite authenticity, the internal representation of the ATTN module and FFN module of the large model is extracted through the internal representation extractor 802. It should be noted that the internal representation is extracted by constructing triple data, which includes questions, real answers, and non-real answers. We send the question + real answer and the question + non-real answer as input to the internal representation extraction module (also called the internal representation extractor), where the internal representation extraction module uses the stacked Transformer block.
[0190] Then, an autoencoder (corresponding to the spatial encoding module in the above-mentioned hallucination processing model) 803 is used to map the extracted internal representation to the real space and the semantic space respectively, so as to obtain the latent representation in the real space and the latent representation in the semantic space; further, based on the latent representation in the real space and the latent representation in the semantic space, contrastive learning is used to capture the real and semantic features in the real space and the semantic space. After capturing the real and semantic features in the real space and the semantic space, the latent representation in the real space is edited by the authenticity editing module 804 and the corresponding representation is reconstructed. Then, the model weights and loss functions that need to be updated are determined to obtain a trained hallucination processing model.
[0191] Finally, the trained model is embedded into the reasoning process of the large model, the user input question 805 is input into the large model 806, the internal representation of the ATTN module and the FFN module of the large model is extracted, and the internal representation is mapped to different spaces by the autoencoder of the trained model to obtain the latent representation in the real space and the semantic space. Through comparative learning, the latent representation in the real space and the semantic space is used to detect the authenticity of the internal representation. If it is not authentic, the authenticity of the internal representation is edited to obtain the edited internal representation, and then the large model outputs the authenticity answer 807 based on the edited internal representation; if it is authentic, the large model outputs the authenticity answer 807 based on the extracted internal representation.
[0192] From the above, it can be seen that the embodiment of the present application provides an innovative method that does not require the support of an external knowledge base to effectively alleviate the illusion phenomenon that occurs in large models, that is, to avoid relying on an external knowledge base to alleviate the illusion phenomenon of large models, which requires a large amount of manual collection and organization of the knowledge base, which is time-consuming and costly. The embodiment of the present application performs editing operations directly in the real space, deeply explores and utilizes the knowledge resources inside the large model, thereby significantly reducing the time and cost required for manual collection and organization of the knowledge base. At the same time, it can also effectively alleviate the illusion phenomenon without sacrificing model performance. Through the technical means of the present invention, efficient training and application of large models can be achieved, while reducing the need for manual intervention.
[0193] The embodiment of the present application has a wide range of application prospects and is applicable to various large-scale models without the need to adjust for specific models. Its excellent portability makes the embodiment of the present application highly flexible and adaptable in practical applications. The embodiment of the present application further introduces an innovative contrastive learning mechanism, which improves the output quality of large-scale models by simulating the human learning process. At the same time, contrastive learning can also prevent the model output from being too real. For example, through contrastive learning, the large model can also move in the direction of unrealistic output, increasing the fun and creativity of the output. This unique learning method enables large models to maintain accuracy while also having higher entertainment and practicality.
[0194] The present application embodiment provides a model training device, referring to Fig. 9 As shown, Fig. 9 A schematic diagram of the structure of a model training device provided in an embodiment of the present application, the model training device 9 comprises:
[0195] The first acquisition module 901 is used to input the constructed triple data into the text language model to obtain the sample internal representation of the triple data by the target module when the text language model is stimulated by the triple data; wherein the triple data includes the sample text, the sample real reply text corresponding to the sample text, and the sample non-real reply text;
[0196] The first processing module 902 is used to use each spatial encoding module in the hallucination processing model to be trained to perform different spatial mappings on the internal representation of the sample to obtain a real potential representation of the sample in the real space and a semantic potential representation of the sample in the semantic space;
[0197] The second processing module 903 is used to reconstruct the internal representation of the target module by using the decoding module in the hallucination processing model to be trained based on the real potential representation of the sample and the semantic potential representation of the sample to obtain the reconstructed internal representation of the sample;
[0198] A first determination module 904 is used to determine a target loss of a hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true potential representation, and the sample semantic potential representation;
[0199] The third processing module 905 is used to adjust the parameters of the hallucination processing model to be trained based on the target loss to obtain a trained hallucination processing model; wherein the trained hallucination processing model satisfies a preset convergence condition. .
[0200] The present application embodiment provides a device for processing model hallucination, referring to Fig.10 As shown, Fig.10 A schematic diagram of the structure of a model hallucination processing device provided in an embodiment of the present application, the model hallucination processing device 10 includes:
[0201] The second obtaining module 1001 is used to obtain a first internal representation of the input text by the target module when the text language model performs model reasoning on the input text;
[0202] The fourth processing module 1002 is used to use each spatial encoding module in the hallucination processing model to perform spatial mapping on the first internal representation, obtain a real potential representation in the real space and a semantic potential representation in the semantic space, and obtain a detection result of whether hallucination occurs when the text language model performs model inference based on the real potential representation and the semantic potential representation;
[0203] A fifth processing module 1003 is used for, if the detection result indicates that the text language model has hallucinations when performing model inference, performing authenticity editing processing on the real potential representation in the real space to obtain a processed real potential representation; based on the processed real potential representation and the semantic potential representation, obtaining a second internal representation through a decoding module in the hallucination processing model;
[0204] The third acquisition module 1004 is used to put the second internal representation back into the target module to obtain the real response text of the text language model to the input text; wherein the hallucination processing model is trained by the model training method of any one of the above embodiments.
[0205] An embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.
[0206] The embodiment of the present application provides a storage medium, which stores one or more computer programs, and the one or more computer programs can be executed by one or more processors to implement some or all of the steps in the above method. The storage medium can be transient or non-transient.
[0207] An embodiment of the present application provides a computer program, including a computer-readable code. When the computer-readable code is run in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.
[0208] The embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be implemented specifically by hardware, software or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium, and in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK) and the like.
[0209] It should be noted here that the description of the various embodiments above tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. The description of the above device, storage medium, computer program and computer program product embodiments is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the embodiments of the device, storage medium, computer program and computer program product of this application, please refer to the description of the method embodiment of this application for understanding.
[0210] Fig.11 A hardware entity diagram of a computer device provided in an embodiment of the present application is shown in FIG. Fig.11 As shown, the hardware entity of the computer device 11 includes: a processor 1101 and a memory 1102, wherein the memory 1102 stores a computer program that can be run on the processor 1101, and the processor 1101 implements the following steps when executing the program:
[0211] Input the constructed triple data into the text language model to obtain the sample internal representation of the triple data by the target module when the text language model is stimulated by the triple data; wherein the triple data includes the sample text, the sample true reply text corresponding to the sample text, and the sample non-true reply text;
[0212] Using the spatial encoding modules in the hallucination processing model to be trained, the internal representation of the sample is mapped into different spaces to obtain the real potential representation of the sample in the real space and the semantic potential representation of the sample in the semantic space;
[0213] Based on the real potential representation of the sample and the semantic potential representation of the sample, the decoding module in the hallucination processing model to be trained is used to reconstruct the internal representation of the target module to obtain the reconstructed internal representation of the sample;
[0214] determining a target loss for a hallucination processing model to be trained based on at least a portion of the sample reconstructed internal representation, the sample internal representation, the sample true latent representation, and the sample semantic latent representation;
[0215] Based on the target loss, the parameters of the hallucination processing model to be trained are adjusted to obtain a trained hallucination processing model; wherein the trained hallucination processing model satisfies a preset convergence condition.
[0216] Among them, the memory 1102 stores a computer program that can be run on the processor. The memory 1102 is configured to store instructions and applications executable by the processor 1101. It can also cache data to be processed or processed by the processor 1101 and various modules in the computer device 11 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0217] The processor 1101 executes the program to implement the steps of any of the above-mentioned model training execution methods or model hallucination processing methods. The processor 1101 generally controls the overall operation of the computer device 11.
[0218] An embodiment of the present application provides a storage medium, which stores one or more computer programs, which can be executed by one or more processors to implement the steps of the model training method or the model hallucination processing method in any of the above embodiments. It should be pointed out here that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0219] The processor may be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It is understandable that the electronic device that implements the functions of the processor may also be other, and the embodiments of the present application are not specifically limited.
[0220] The above-mentioned computer storage medium / memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory (Flash Memory), a magnetic surface memory, an optical disk, or a compact disc read-only memory (CD-ROM) and the like; it can also be various terminals including one or any combination of the above-mentioned memories, such as mobile phones, computers, tablet devices, personal digital assistants, etc.
[0221] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the serial number of each step / process mentioned above does not mean the order of execution, and the execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. The serial numbers of the embodiments of the present application mentioned above are for description only and do not represent the advantages and disadvantages of the embodiments.
[0222] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0223] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0224] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0225] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0226] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0227] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a vehicle-mounted terminal (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0228] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A model training method, characterized in that: The method comprises: Inputting the constructed triple data into a text language model to obtain a sample internal representation of the triple data by a target module when the text language model is stimulated by the triple data; wherein the triple data includes a sample text, a sample true reply text corresponding to the sample text, and a sample non-true reply text; Using each spatial encoding module in the hallucination processing model to be trained, the internal representation of the sample is mapped into different spaces to obtain a real potential representation of the sample in a real space and a semantic potential representation of the sample in a semantic space; Based on the sample real potential representation and the sample semantic potential representation, reconstruct the internal representation of the target module using the decoding module in the hallucination processing model to be trained to obtain the sample reconstructed internal representation; Determining a target loss of the hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample true latent representation, and the sample semantic latent representation; Based on the target loss, the parameters of the hallucination processing model to be trained are adjusted to obtain a trained hallucination processing model; wherein the trained hallucination processing model meets a preset convergence condition.
2. The model training method according to claim 1, characterized in that: The method uses each spatial encoding module in the hallucination processing model to be trained to perform different spatial mappings on the internal representation of the sample to obtain a real potential representation of the sample in a real space and a semantic potential representation of the sample in a semantic space, including: Using the real space encoding module in the hallucination processing model, the internal representation of the sample is mapped into the real space to obtain the real potential representation of the sample in the real space; The semantic space encoding module in the hallucination processing model is used to perform semantic space mapping on the internal representation of the sample to obtain the semantic potential representation of the sample in the semantic space.
3. The model training method according to claim 1 or 2, characterized in that: The determining the target loss of the hallucination processing model to be trained based on at least part of the sample reconstructed internal representation, the sample internal representation, the sample real potential representation and the sample semantic potential representation comprises: Obtaining a reconstruction loss of the hallucination processing model based on the sample reconstructed internal representation and the sample internal representation; Based on the true potential representation of the sample, the semantic potential representation of the sample and the internal representation of the sample, a contrastive learning loss and an editing loss of the hallucination processing model are obtained; The target loss is determined based on one or more of the reconstruction loss, the contrastive learning loss, and the editing loss.
4. The model training method according to claim 3, characterized in that: The step of obtaining the contrastive learning loss and the editing loss of the hallucination processing model based on the real potential representation of the sample, the semantic potential representation of the sample and the internal representation of the sample includes: For a given sample potential representation, based on the sample real potential representation and the sample semantic potential representation, construct a positive sample potential representation set and a negative sample potential representation set corresponding to the given sample potential representation in a target space; wherein the target space includes the real space and the semantic space, and the given sample potential representation is one of the sample real potential representation and the sample semantic potential representation; Based on the positive sample potential representation set and the negative sample potential representation set, performing contrastive learning on the given sample potential representation to obtain a contrastive learning loss in the target space, and determining the sum of the contrastive learning losses in all target spaces as the contrastive learning loss of the hallucination processing model; Obtaining a sample real potential representation corresponding to a sample internal representation of a text token of the same sample text in the real space; wherein the sample internal representation includes a sample real internal representation and a sample non-real internal representation; The sample true latent representation corresponding to the sample true internal representation and the sample true latent representation corresponding to the sample non-true internal representation are exchanged, and the editing loss is determined based on the exchanged sample true latent representation, the sample semantic latent representation, the sample true internal representation and the sample non-true internal representation.
5. The model training method according to claim 4, characterized in that: The target space is the real space, the given sample potential representation is the given sample real potential representation; for the given sample potential representation, based on the sample real potential representation and the sample semantic potential representation, constructing a positive sample potential representation set and a negative sample potential representation set corresponding to the sample potential representation in the target space, including: For the given sample true potential representation, constructing the sample true potential representations having the same authenticity as the given sample true potential representation in the real space as the positive sample potential representation set; The true potential representations of the samples in the real space that have opposite authenticity to the given true potential representations of the samples are constructed as the negative sample potential representation set.
6. The model training method according to claim 4, characterized in that: The target space is the semantic space, the given sample potential representation is a given sample semantic potential representation; for the given sample potential representation, based on the sample real potential representation and the sample semantic potential representation, constructing a positive sample potential representation set and a negative sample potential representation set corresponding to the sample potential representation in the target space, including: For the given sample semantic latent representation, determining the sample true latent representations having the same authenticity as the given sample semantic latent representation in the semantic space as a sample semantic latent representation set; Determine the sample semantic latent representations having the same text tokens and opposite authenticity as the given sample semantic latent representation as the positive sample latent representation set; The remaining sample semantic latent representations in the sample semantic latent representation set except the given sample semantic latent representation are determined as the negative sample latent representation set.
7. The model training method according to claim 4, characterized in that: The determining the editing loss based on the exchanged sample real potential representation, the sample semantic potential representation, the sample real internal representation and the sample non-real internal representation comprises: For the sample real internal representation, based on the sample semantic potential representation and the sample real potential representation corresponding to the sample non-real internal representation, the decoding module is used to reconstruct the internal representation of the target module to obtain a first sample exchanged reconstructed internal representation, wherein the exchanged sample real potential representation includes the sample real potential representation corresponding to the sample non-real internal representation; For the sample non-true internal representation, based on the sample semantic potential representation and the sample true potential representation corresponding to the sample true internal representation, the decoding module is used to reconstruct the internal representation of the target module to obtain a second sample exchanged reconstructed internal representation, wherein the exchanged sample true potential representation includes the sample true potential representation corresponding to the sample true internal representation; The editing loss is obtained based on the first sample exchanged and reconstructed internal representation, the sample true internal representation, the second sample exchanged and reconstructed internal representation and the sample untrue internal representation.
8. The model training method according to claim 1 or 2, characterized in that: The target module is an attention module and / or a feedforward neural network module; wherein, If the target module is the attention module, the internal representation of the sample is the internal representation output by the attention module; If the target module is the feedforward neural network module, the sample internal representation is the internal representation of the output of the feedforward neural network module; If the target module is an attention module and a feedforward neural network module, the internal representation of the sample is an internal representation obtained by fusing the internal representation output by the attention module and the internal representation output by the feedforward neural network module.
9. A method for processing model hallucination, characterized in that: The method comprises: Obtaining a first internal representation of the input text by the target module when the text language model performs model reasoning on the input text; Using each spatial encoding module in the hallucination processing model, spatial mapping is performed on the first internal representation to obtain a real potential representation in a real space and a semantic potential representation in a semantic space, and based on the real potential representation and the semantic potential representation, a detection result of whether hallucination occurs when the text language model performs model inference is obtained; If the detection result indicates that the text language model has hallucinations when performing model inference, the real potential representation is subjected to authenticity editing processing in the real space to obtain a processed real potential representation; based on the processed real potential representation and the semantic potential representation, a second internal representation is obtained through a decoding module in the hallucination processing model; The second internal representation is put back into the target module to obtain the true response text of the text language model to the input text; wherein the hallucination processing model is trained based on the model training method according to any one of claims 1 to 7.
10. The method for processing model illusion according to claim 9, characterized in that: The performing authenticity editing processing on the real potential representation in the real space to obtain the processed real potential representation includes: Obtaining a first real editing direction determined by a real spatial encoding module for the real latent representation, wherein the spatial encoding module includes the real spatial encoding module; Based on the first real editing direction, the real latent representation is subjected to authenticity editing processing in different directions to obtain a first real latent representation and a second real latent representation, wherein the processed real latent representation includes the first real latent representation and the second real latent representation.
11. The method for processing model illusion according to claim 10, characterized in that: The step of obtaining a second internal representation based on the processed real potential representation and the semantic potential representation through a decoding module in the hallucination processing model comprises: Based on the first real potential representation and the semantic potential representation, reconstructing the internal representation of the target module using the decoding module to obtain a first reconstructed internal representation; Based on the second real potential representation and the semantic potential representation, reconstructing the internal representation of the target module using the decoding module to obtain a second reconstructed internal representation; determining a second true editing direction of the first internal representation based on the first reconstructed internal representation and the second reconstructed internal representation; An editing weight of the second real editing direction is obtained, and based on the second real editing direction and the editing weight, authenticity editing is performed on the first internal representation to obtain the second internal representation.
12. The method for processing model illusion according to any one of claims 9 to 11, characterized in that: The text language model includes multiple layers, and the authenticity editing of the first internal representation based on the second true editing direction and the editing weight to obtain the second internal representation includes: Obtain the detection accuracy of target modules located at different layers; From the target modules included in each layer, select a target module whose detection accuracy is greater than a detection accuracy threshold; Based on the second true editing direction and the editing weight, authenticity editing is performed on the first internal representation of the selected target module to obtain the second internal representation.
13. A computer device, characterized in that: The computer device comprises: a memory and a processor, The memory stores a computer program executable on the processor; When the processor executes the computer program, the model training method according to any one of claims 1 to 8, or the model hallucination processing method according to claims 9 to 12 is implemented.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more computer programs, and the one or more computer programs can be executed by one or more processors to implement the model training method as described in any one of claims 1 to 8, or the model hallucination processing method as described in claims 9-12.
15. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the model training method according to any one of claims 1 to 8, or the model hallucination processing method according to claims 9 to 12 is implemented.