Model training method and device, implicit reasoning retrieval method and device and related equipment
Through the methods of precoding and supervised training, the teacher model is used to generate semantic feature vectors and optimize the student model, which solves the delay problem of implicit reasoning retrieval methods in large-scale document libraries and realizes efficient implicit reasoning retrieval.
Patent Information
- Application Number
- CN202510739326.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-04
- Publication Date
- 2025-09-16
AI Technical Summary
Existing implicit reasoning retrieval methods have high single-inference latency in large-scale document libraries and highly concurrent queries, making it difficult to meet real-time service requirements.
The query statement and document library are pre-encoded by the pre-trained teacher model to generate semantic feature vectors, and the student model is supervised and trained using the mixture of experts (MoE) model. A loss function is constructed to optimize the parameters of the student model to achieve implicit reasoning retrieval capabilities.
It reduces the retrieval response delay, improves the real-time and efficiency of retrieval results, and meets the real-time needs of users.
Smart Images

Figure CN120654824A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and in particular relates to a model training method, an implicit reasoning retrieval method, an apparatus, and related equipment. Background Art
[0002] In many practical application scenarios, the relationship between a query word or sentence and related documents is not a simple semantic similarity match, but requires a connection established through reasoning, that is, an implicit reasoning relationship. Implicit reasoning retrieval is a more challenging retrieval task. Its core feature is that the query and the document may differ significantly in surface semantics and have no surface semantic similarity, but potential connections can be established through logical reasoning chains, empirical associations, or cross-modal inference. For example, in a medical diagnosis scenario, the patient's symptom description (query) and the relevant medical literature (document) may not directly contain the same terms or semantics, but the basis for diagnosis can be established through reasoning based on medical knowledge; in legal case retrieval, there may be a lack of explicit semantic overlap between the case facts (query) and the case law (document), but relevant precedents can be found through legal logical reasoning.
[0003] Current implicit inference retrieval methods require dynamically concatenating the original query and candidate documents into a complete input sequence for each request, and then invoking a large language model (LLM) with tens of billions of parameters to perform the entire inference process. Because the LLM's single-pass inference latency increases exponentially with the length of the input sequence, and because the model's forward computation must be repeated multiple times as the document library scales, system response times far exceed the real-time service threshold (>500ms), failing to meet real-time service requirements. Summary of the Invention
[0004] The embodiments of the present application provide a model training method, an implicit reasoning retrieval method, an apparatus, and related equipment, which can reduce the response delay of the retrieval and improve the real-time performance of the retrieval result output.
[0005] In a first aspect, an embodiment of the present application provides a model training method, the method comprising:
[0006] Get the first query statement;
[0007] splicing the first query statement with a preconfigured prompt word to obtain a first splicing sequence;
[0008] Inputting the first spliced sequence into a pre-trained teacher model to obtain a semantic feature vector of the first spliced sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0009] Splicing the semantic feature vector of the first splicing sequence with the semantic feature vector of each of the documents in the pre-acquired document library to obtain a plurality of second splicing sequences;
[0010] inputting each of the second spliced sequences into a student model to obtain a semantic feature vector of each of the second spliced sequences;
[0011] Constructing a loss function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences, where the semantic feature vectors of the third concatenated sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library;
[0012] The parameters of the student model are adjusted according to the loss function to obtain a target model.
[0013] In a second aspect, an embodiment of the present application provides an implicit reasoning retrieval method, the method comprising:
[0014] Get the target query statement;
[0015] Splicing the target query sentence with pre-configured prompt words to obtain a target splicing sequence;
[0016] Inputting the target splicing sequence into a pre-trained teacher model to obtain a semantic feature vector of the target splicing sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0017] Splicing the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain multiple target splicing sequences;
[0018] Each of the target concatenated sequences is input into a target model to obtain the correlation between the target query statement and each of the documents, wherein the target model is obtained according to the model training method described in the first aspect.
[0019] In a third aspect, an embodiment of the present application provides a model training device, comprising:
[0020] A first acquisition module, configured to acquire a first query statement;
[0021] a first concatenation module, configured to concatenate the first query statement with a preconfigured prompt word to obtain a first concatenation sequence;
[0022] a second acquisition module, configured to input the first spliced sequence into a pre-trained teacher model to obtain a semantic feature vector of the first spliced sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0023] A second splicing module is configured to splice the semantic feature vectors of the first splicing sequence with the semantic feature vectors of each of the documents in the pre-acquired document library to obtain a plurality of second splicing sequences;
[0024] a third acquisition module, configured to input each of the second spliced sequences into a student model to obtain a semantic feature vector of each of the second spliced sequences;
[0025] a construction module, configured to construct a loss function based on a plurality of semantic feature vectors of the second concatenated sequences and a plurality of semantic feature vectors of the third concatenated sequences, wherein the semantic feature vectors of the third concatenated sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library;
[0026] An adjustment module is used to adjust the parameters of the student model according to the loss function to obtain a target model.
[0027] In a fourth aspect, an embodiment of the present application provides an implicit reasoning retrieval device, the device comprising:
[0028] A first acquisition module is used to acquire a target query statement;
[0029] A second splicing module is used to splice the target query sentence with the preconfigured prompt words to obtain a target splicing sequence;
[0030] A second acquisition module is used to input the target splicing sequence into a pre-trained teacher model to obtain a semantic feature vector of the target splicing sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0031] A third splicing module is configured to splice the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain a plurality of target splicing sequences;
[0032] A third acquisition module is configured to input each target concatenated sequence into a target model to obtain the correlation between the target query statement and each document, wherein the target model is obtained according to the model training method described in the first aspect:
[0033] In a fifth aspect, an embodiment of the present application provides an electronic device comprising: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, it implements the model training method as described in the first aspect or the implicit reasoning retrieval method as described in the second aspect.
[0034] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implement the model training method as described in the first aspect or the implicit reasoning retrieval method as described in the second aspect.
[0035] In the seventh aspect, an embodiment of the present application provides a computer program product. When the instructions in the computer program product are executed by the processor of an electronic device, the electronic device executes the model training method described in the first aspect or the implicit reasoning retrieval method described in the second aspect.
[0036] In this embodiment, after obtaining the first query statement, it is only necessary to splice the first query statement with the prompt word and input it into the teacher model (which can be considered as the real-time encoding stage). In this way, the length of the sequence input into the teacher model can be shortened, the computational overhead can be reduced, and the efficiency of the teacher model outputting the semantic feature vector of the first spliced sequence can be improved. In addition, the semantic feature vector of the document can be determined in advance by the teacher model (which can be considered as the pre-coding stage). In this way, when training the student model, the time for constructing the semantic feature vector of the second spliced sequence can be greatly reduced, thereby improving the model training efficiency. The student model is supervised and trained by a teacher model with implicit reasoning retrieval capability, so that the student model performs distillation learning on the teacher model, so that the target model obtained by training also has implicit reasoning retrieval capability. When the target model is subsequently used for retrieval, the construction of the semantic feature vector input to the target model also adopts the construction method of the semantic feature vector of the second spliced sequence, thereby reducing the response delay of the retrieval and improving the real-time output of the retrieval result to meet the real-time requirements of the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0038] Figure 1 This is a flow chart of the model training method provided in the embodiment of the present application;
[0039] Figure 2 This is a flow chart of the implicit reasoning retrieval method provided in an embodiment of the present application;
[0040] Figure 3a This is another flowchart of the implicit reasoning retrieval method provided in an embodiment of the present application;
[0041] Figure 3b1 is a flow chart of implicit reasoning retrieval using a teacher model provided in an embodiment of the present application;
[0042] Figure 4 Schematic diagram of the structure of the model training device provided in the embodiment of the present application;
[0043] Figure 5 Schematic diagram of the structure of the implicit reasoning retrieval device provided in an embodiment of the present application;
[0044] Figure 6 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0045] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is merely to provide a better understanding of the present application by illustrating the examples of the present application.
[0046] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, the elements defined by the phrase "comprising..." do not exclude the presence of other identical elements in the process, method, article, or device comprising the elements.
[0047] In each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the user's identity or characteristics, such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of such data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0048] Retrieval-Augmented Generation (RAG) systems have demonstrated significant advantages in knowledge-intensive tasks. Traditional retrieval methods rely on the semantic similarity assumption, which relies on shallow semantic matching between queries and documents to achieve factual retrieval. These methods rely on a dual-tower encoder architecture to enable offline document pre-encoding. This allows online retrieval to only require a neural network model to process a single query, achieving efficient real-time query processing and avoiding repeated calls to the neural network encoder to encode the document.
[0049] However, in many practical application scenarios, the relationship between a query word or sentence and related documents is not a simple semantic similarity match, but requires a connection established through reasoning, that is, an implicit reasoning relationship. Implicit reasoning retrieval is a more challenging retrieval task. Its core feature is that the query and the document may differ significantly in surface semantics and have no surface semantic similarity, but potential connections can be established through logical reasoning chains, empirical associations, or cross-modal inference. For example, in a medical diagnosis scenario, the patient's symptom description (query) and the relevant medical literature (document) may not directly contain the same terms or semantics, but the diagnosis basis can be established through reasoning based on medical knowledge; in legal case retrieval, there may be a lack of explicit semantic overlap between the case facts (query) and the case law (document), but relevant precedents can be found through legal logical reasoning.
[0050] While implicit reasoning retrieval holds significant practical significance, its unique nature also presents new technical challenges. Existing implicit reasoning retrieval solutions typically employ instruction-based fine-tuning of a large language model (LLM). Specifically, instruction templates are used to reframe the retrieval task as a generative binary classification problem, prompting the language model to explicitly model the underlying reasoning relationship between query-document pairs. This involves concatenating the query and document into the model, and using prompts to guide the LLM in determining whether the two have an implicit reasoning relationship. For example, a prompt might be: "Based on the following query and document, determine whether they have an implicit reasoning relationship: yes / no?" The probability distribution of "yes" or "no" over the vocabulary is then normalized to its correlation ("similarity to similar queries"), resulting in a score for the document and query. This score is then used to retrieve the top-k most relevant documents from the document repository.
[0051] The advantage of implicit reasoning retrieval lies in its ability to transcend traditional retrieval methods' reliance on explicit semantic matching, establishing an inferential relationship between queries and documents through contextual understanding and logical reasoning. For example, in a multi-turn conversation scenario, when a user enters "I was late for work today and fell on the way," traditional retrieval methods (such as those based on keyword matching or vector similarity) might directly search for documents containing words like "late" and "fall." However, the text descriptions of "comfort strategies" in the policy library (which can be understood as a document library) often do not contain these keywords, making it impossible to effectively match them based solely on semantic similarity (such as cosine similarity). Implicit reasoning retrieval achieves deep correlation through multi-level processing: first, it analyzes emotional cues in the user's sentence (such as the frustration implied by "late" and "fall"). It then combines the conversation history to infer the user's current core need (such as emotional support rather than factual answers). Furthermore, it identifies the triggering conditions for the "comfort strategy" from the policy library (such as "the user expressed a negative experience and did not actively seek a solution"), ultimately completing the strategy matching. This process does not rely on the similarity of semantic representations, but instead explores potential associations through logical chain construction (emotion recognition → intent reasoning → strategy mapping). It is suitable for scenarios such as customer service conversations and psychological counseling that require dynamic understanding of contextual intent.
[0052] The implicit reasoning retrieval capability can use the text content entered by the user as a query statement, and then retrieve documents from the document library that are related to the query in an implicit reasoning relationship through prompt words. These documents may not be directly related to the query statement in terms of surface semantics, but potential connections can be established through logical reasoning chains, empirical associations, or cross-modal inference. Exemplarily, the implicit reasoning retrieval process includes: splicing the prompt words (the prompt words are binary categories, including "yes" or "no"), the query statement entered by the user, and the documents in the document library (exemplarily, the documents include response strategies). The spliced sequence is input into the LLM, which uses a generative binary classification task to determine whether there is an implicit reasoning relationship between the query statement and the document. By understanding the semantic information and logical relationships in the spliced sequence, the LLM generates a judgment result, usually "yes" or "no", indicating whether there is a potential connection between the query and the document. To better guide the LLM's judgment, we used instruction templates (prompts), such as "Based on the following query and document, determine whether they have an implicit reasoning relationship: yes / no?" This instruction template clearly tells the model what to do, improving its accuracy and consistency. The advantage of implicit reasoning retrieval lies in its ability to handle complex, indirect semantic relationships between queries and documents, discovering potential connections through implicit reasoning. This makes it suitable for scenarios requiring deep understanding and reasoning.
[0053] Because it performs online concatenation and reasoning, the process can flexibly respond to different query and document combinations, demonstrating high adaptability. Furthermore, the process leverages LLM's powerful language understanding and generation capabilities to more accurately determine the implicit reasoning relationships between queries and documents.
[0054] However, this process also faces some challenges. First, each query requires real-time concatenation and reasoning with the document repository, resulting in high latency for each inference. This is particularly problematic in large document repositories and highly concurrent queries, making it difficult to meet the real-time service requirements of large-scale online retrieval systems.
[0055] In order to solve the problems of the prior art, the embodiments of the present application provide a model training method, an implicit reasoning retrieval method, an apparatus and related equipment. The model training method provided by the embodiments of the present application is first introduced below.
[0056] Figure 1 FIG1 shows a flow chart of a model training method provided by an embodiment of the present application. Figure 1 As shown, the model training method provided in the embodiment of the present application includes the following steps 101 to 107, wherein:
[0057] Step 101: Obtain a first query statement.
[0058] The first query statement can be understood as query information. For example, in a medical diagnosis scenario, the first query statement refers to a description of a patient's symptoms; in legal case retrieval, the first query statement refers to the case facts. The first query statement can be a query statement obtained online. During the student model training phase, the query statement entered by the user can be used as the first query statement to train the student model.
[0059] Step 102: Concatenate the first query statement with pre-configured prompt words to obtain a first concatenated sequence.
[0060] Prompt words can be preconfigured. For example, a prompt word might be: "Based on the following query statement and document, determine whether they have an implicit inference relationship: yes / no?" Prompt words can be flexibly set based on actual circumstances and are not limited here. The first query statement and the prompt word are concatenated to produce a long sequence. For ease of description, this long sequence is referred to as the first concatenated sequence. For example, the first concatenated sequence is the sequence formed by concatenating "[prompt word] + [first query statement]."
[0061] Step 103: input the first concatenated sequence into a pre-trained teacher model to obtain a semantic feature vector of the first concatenated sequence, wherein the teacher model has implicit reasoning retrieval capability.
[0062] The teacher model can be pre-trained to provide implicit reasoning and retrieval capabilities. The first concatenated sequence is input into the teacher model to obtain a semantic feature vector for the first concatenated sequence. The teacher model can use an LLM, and the semantic feature vector uses the hidden state vector output by the last layer of the LLM.
[0063] Step 104 : splicing the semantic feature vector of the first splicing sequence with the semantic feature vector of each of the documents in the pre-acquired document library to obtain a plurality of second splicing sequences.
[0064] Each document in the document library is pre-processed using the teacher model to obtain a semantic feature vector for each document. This pre-processing improves the training efficiency of the student model. For example, if there are 100 documents in the document library, the semantic feature vectors of the first concatenated sequence are concatenated with the semantic feature vectors of the 100 documents to obtain 100 second concatenated sequences. Each second concatenated sequence is composed of the semantic feature vector of the first concatenated sequence and the semantic feature vector of one document.
[0065] Step 105: Input each of the second concatenated sequences into a student model to obtain a semantic feature vector of each of the second concatenated sequences.
[0066] The student model may include a Mixture of Experts (MoE) model, and the second spliced sequence is input into the MoE to obtain a semantic feature vector of the second spliced sequence.
[0067] Step 106: construct a loss function based on the semantic feature vectors of the plurality of second splicing sequences and the semantic feature vectors of the plurality of third splicing sequences, where the semantic feature vectors of the plurality of third splicing sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library.
[0068] For example, a KL divergence function can be constructed based on the semantic feature vectors of multiple second splicing sequences and the semantic feature vectors of multiple third splicing sequences to ensure that the semantic feature vector of the student model is as close as possible to the teacher model and retain the similarity at the semantic level.
[0069] Step 107, adjusting the parameters of the student model according to the loss function to obtain a target model, that is, the target model has the ability to determine the relevance between the input query statement and each of the documents in the document library.
[0070] The student model is trained in the above manner until the iteration stopping condition is met. The iteration stopping condition can be set according to the actual situation and is not limited here. For example, the value of the KL divergence function is less than a preset threshold.
[0071] In the above process, after obtaining the first query statement, it is only necessary to concatenate the first query statement with the prompt word and input it into the teacher model (which can be considered as the real-time encoding stage). In this way, the length of the sequence input into the teacher model can be shortened, the computational overhead can be reduced, and the efficiency of the teacher model outputting the semantic feature vector of the first concatenated sequence can be improved. In addition, the semantic feature vector of the document can be determined in advance by the teacher model (which can be considered as the pre-encoding stage). In this way, when training the student model, the time required to construct the semantic feature vector of the second concatenated sequence can be greatly reduced, thereby improving the model training efficiency. The student model is supervised by a teacher model with implicit reasoning retrieval capabilities, so that the student model performs distillation learning on the teacher model, so that the trained target model also has implicit reasoning retrieval capabilities. When the target model is subsequently used for retrieval, the semantic feature vector input to the target model is also constructed using the semantic feature vector construction method of the second concatenated sequence, thereby reducing the response delay of the retrieval and improving the real-time output of the retrieval results to meet the real-time requirements of the user.
[0072] In one embodiment of the present application, before constructing the loss function based on the semantic feature vectors of the plurality of second spliced sequences and the semantic feature vectors of the plurality of third spliced sequences, the method further includes:
[0073] Get the second query statement;
[0074] For each of the documents in the document library, concatenate the second query statement, the prompt word, and the document to obtain a third concatenated sequence corresponding to the document;
[0075] Each of the third concatenated sequences is input into the teacher model to obtain a semantic feature vector of each of the third concatenated sequences.
[0076] In the above, the second query statement is different from the first query statement. The second query statement may refer to a sample query statement, and the first query statement may be a query statement obtained online in real time during the student model training phase.
[0077] The second query statement, the prompt word, and a document in the document library are concatenated to obtain a long sequence. For ease of description, this long sequence is called the third concatenated sequence. For example, the third concatenated sequence is a sequence concatenated by "[prompt word] + [first query statement] + [document]".
[0078] Each of the third spliced sequences is input into the teacher model to obtain the semantic feature vector of each of the third spliced sequences. The process of obtaining the semantic feature vector of the third spliced sequence is performed in advance before training the student model, which can improve the training efficiency of the student model.
[0079] In one embodiment of the present application, the loss function includes a first loss sub-function and / or a second loss sub-function;
[0080] The constructing a loss function according to the semantic feature vectors of the plurality of second spliced sequences and the semantic feature vectors of the plurality of third spliced sequences includes:
[0081] constructing a KL divergence function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences to obtain the first loss sub-function;
[0082] and / or,
[0083] Performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of second splicing sequences to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence, wherein the first probability value corresponding to each second splicing sequence is used to represent the relevance between the first query statement and the document used by the second splicing sequence;
[0084] Performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of third splicing sequences to obtain a second probability value corresponding to the semantic feature vector of each third splicing sequence, wherein the second probability value corresponding to each third splicing sequence is used to characterize the relevance between the second query statement and the document used by the third splicing sequence;
[0085] A Euclidean distance function is constructed according to the plurality of first probability values and the plurality of second probability values to obtain the second loss sub-function.
[0086] In the above, the first loss sub-function can be expressed as follows:
[0087]
[0088] Among them, D KL (H student / / H teacher ) is the KL divergence (Kullback-Leibler Divergence) used in Knowledge Distillation (KD), which is used to measure the difference between the output distribution of the student model and the teacher model.
[0089] λ KL : Weight coefficient, used to adjust the importance of this part of the loss, with a value range of 0 to 1.
[0090] H student : The hidden state distribution of the student model, including the semantic feature vectors of multiple second splicing sequences.
[0091] Hteacher : The hidden state distribution of the teacher model, including the semantic feature vectors of multiple third splicing sequences.
[0092] H student (i) represents the semantic feature vector of the second concatenated sequence obtained based on the i-th document; H teacher (i) represents the semantic feature vector of the third concatenated sequence obtained based on the i-th document;
[0093] Optimization goal: minimize D KL (H student / / H teacher ), so that the distribution of the semantic feature vector output by the student model is close to that of the teacher model.
[0094] The second loss sub-function can be expressed as follows:
[0095]
[0096] In formula (2), ||S student -S teacher || 2 is the square of the L2 norm, that is, the square of the Euclidean distance, used to quantify S student and S teacher The difference between the two.
[0097] λ MSE : Weight coefficient, used to adjust the importance of this part of the loss, with a value range of 0 to 1.
[0098] S student : The relevance score (the relevance score can also be understood as a probability value) output by the student model includes the first probability values corresponding to the semantic feature vectors of the plurality of second splicing sequences.
[0099] S teacher : The relevance score output by the teacher model, including the second probability values corresponding to the semantic feature vectors of multiple third splicing sequences.
[0100] S student (j) represents the first probability value corresponding to the semantic feature vector of the second concatenated sequence obtained according to the j-th document;
[0101] S teacher (j) represents the second probability value corresponding to the semantic feature vector of the third concatenated sequence obtained according to the j-th document.
[0102] Optimization goal: Minimize the Euclidean distance so that the student model approaches the output distribution of the teacher model.
[0103] In the above, by constructing a loss function to continuously optimize the parameters of the student model, the final target model is close to the teacher model, and the target model also has implicit reasoning and retrieval capabilities.
[0104] In one embodiment of the present application, the student model includes MoE and language model head (Language Model Head, LLM-head or LM-head for short) modules;
[0105] Inputting each of the second spliced sequences into the student model to obtain a semantic feature vector of each of the second spliced sequences includes:
[0106] Inputting each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences;
[0107] The performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of second splicing sequences to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence includes:
[0108] Inputting the semantic feature vector of each second splicing sequence into the LLM-head module for vocabulary projection and probability calculation to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence;
[0109] The adjusting the parameters of the student model according to the loss function to obtain the target model includes:
[0110] According to the first loss sub-function and the second loss sub-function, the parameters of the MoE are adjusted to obtain the target model.
[0111] In this embodiment, the student model includes MoE and LLM-head modules. MoE is a sparsely activated modular architecture. MoE adopts a hybrid expert network, which consists of multiple expert networks and a gating network. Each expert network is responsible for processing different types of patterns and features and performing related reasoning tasks. The gating network dynamically and selectively activates the most suitable expert network based on the input features, thereby achieving sparse activation and efficient use of parameters. The core idea is to decouple the model parameters into multiple experts (Experts) and dynamically select and activate a small number of relevant experts (such as 2-4) according to the input semantics through the gating network (Gating Network), thereby achieving dual optimization of parameter efficiency and computational efficiency. Specifically, MoE achieves efficient reasoning through the following mechanisms:
[0112] Expert module: Each expert is an independent sub-network that focuses on a specific task or semantic domain (such as logical reasoning expert, common sense association expert).
[0113] Gated network: Calculates expert activation probabilities based on input features (such as query semantic vectors), selects only a few experts with the highest probabilities to participate in the calculation, and the rest remain dormant.
[0114] Sparse activation: Through the sparse design of the gating network (such as Top-K routing), only 5%-10% of the total model parameters are activated, significantly reducing computational overhead and memory usage. The MoE's dynamic selection mechanism uses the gating network (a linear mapping network from input to expert number) to analyze input data in real time, adaptively assign weights to different expert models, and sparsely activate the most relevant k expert models.
[0115] In LLM, LLM-head is the output layer component of LLM, which is responsible for mapping the final hidden state of the model (such as the last_hidden_state of Transformer) to the target space (such as the vocabulary probability distribution, classification label, etc.), that is, it is responsible for converting the hidden state into the final prediction result. In an embodiment of the present application, the LLM-head module further processes and outputs the semantic feature vector of the second splicing sequence output by MoE, designs a specific output layer or adapter, and converts the relevance score into a more intuitive and easy-to-use form, such as a binary classification result (yes / no), indicating whether there is an implicit reasoning relationship between the query and the document, by obtaining the probability distribution on the vocabulary of LLMs and extracting the probability value of "yes" as the relevance score (ie, the first probability value). It should be noted that the method for determining the second probability value can also be processed in the same way as obtaining the first probability value, that is, the semantic feature vector of each of the third splicing sequences is input into the LLM-head module for vocabulary projection and probability calculation to obtain the second probability value corresponding to the semantic feature vector of each of the third splicing sequences, which is not limited here.
[0116] In the above, the parameters of the MoE in the student model are continuously optimized by adjusting the loss function objective, so that the final target model approximates the teacher model. This means that the implicit reasoning knowledge and capabilities of the teacher model are distilled into the lightweight MoE. During the reasoning process, only a few experts (such as emotional support) are activated based on different inputs (i.e., the first query statement). This not only improves reasoning efficiency but also reduces computing resource consumption. This sparse activation mechanism makes the MoE model more scalable and real-time when processing large-scale document repositories, while maintaining reasoning accuracy.
[0117] In one embodiment of the present application, the student model includes MoE and LM-head modules;
[0118] Inputting each second spliced sequence into the student model to obtain a semantic feature vector of each second spliced sequence includes:
[0119] Inputting each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences;
[0120] The semantic feature vector of each second splicing sequence is input into the LLM-head module for vocabulary projection and probability calculation to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence. The first probability value corresponding to each second splicing sequence is used to characterize the correlation between the first query statement and the document used by the second splicing sequence; the first probability value corresponding to each second splicing sequence is used to participate in constructing the loss function.
[0121] Specifically, after obtaining the first probability value, the first probability value can be used to construct a loss function. Specifically, the semantic feature vectors of multiple third splicing sequences can be projected into a vocabulary and probability calculated to obtain a second probability value corresponding to the semantic feature vector of each third splicing sequence, and the second probability value corresponding to each third splicing sequence is used to characterize the relevance between the second query statement and the document used by the third splicing sequence; a Euclidean distance function is constructed based on the multiple first probability values and the multiple second probability values to obtain the second loss sub-function. For details, please refer to the relevant records above and will not be repeated here. The loss function includes the second loss sub-function.
[0122] In one embodiment of the present application, before respectively concatenating the semantic feature vector of the first concatenated sequence with the semantic feature vector of each of the documents in the pre-acquired document library to obtain a second concatenated sequence corresponding to each of the documents, the method further includes:
[0123] For each of the documents in the document library, the document is input into the teacher model to obtain a semantic feature vector of each of the documents.
[0124] In this embodiment, a teacher model is used to pre-encode each document in the document library to obtain a semantic feature vector for each document. This can achieve the purpose of encoding once and reusing multiple times. In addition, due to the pre-processing, the efficiency of subsequent training of the student model can also be improved, and when using the target model for reasoning, the response time of the target model can be shortened, thereby improving the real-time response.
[0125] In one embodiment of the present application, the teacher model is a large language model LLM, and the semantic feature vector of the first spliced sequence, the semantic feature vector of the document, and the semantic feature vector of the third spliced sequence all refer to the hidden state vector output by the last layer of the encoding module of the LLM;
[0126] The student model includes MoE, and the semantic feature vector of the second spliced sequence refers to the hidden state vector output by MoE.
[0127] In the above, the semantic feature vector of the first spliced sequence is the hidden state vector output by the last layer of the pre-trained LLM when the first spliced sequence is input; the semantic feature vector of the document is the hidden state vector output by the last layer of the LLM when the document is input into the pre-trained LLM; the semantic feature vector of the third spliced sequence is the hidden state vector output by the last layer of the LLM when the third spliced sequence is input into the pre-trained LLM.
[0128] Figure 2 The flowchart of the implicit reasoning retrieval method provided in the embodiment of the present application is shown in FIG. Figure 2 The implicit reasoning retrieval method provided in the embodiment of the present application includes the following steps 201 to 205, wherein:
[0129] Step 201: Obtain a target query statement. The target query statement may be a query statement input by a user.
[0130] Step 202: Concatenate the target query sentence with pre-configured prompt words to obtain a target concatenated sequence.
[0131] The prompt words are the same as those used in the above-mentioned model training method embodiment. For example, the prompt words may be: "Based on the following query statement and document, determine whether they have an implicit reasoning relationship: yes / no?". The prompt words can be flexibly set according to actual conditions and are not limited here. The target query statement and the prompt words are spliced together to obtain a long sequence. For ease of description, this long sequence is called the target spliced sequence. For example, the target spliced sequence is a sequence spliced together by "[prompt word] + [target query statement]".
[0132] Step 203: input the target concatenated sequence into a pre-trained teacher model to obtain a semantic feature vector of the target concatenated sequence, wherein the teacher model has implicit reasoning retrieval capability.
[0133] The teacher model is the same as the teacher model used in the above-mentioned model training method embodiment.
[0134] Step 204 : splicing the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain a plurality of target splicing sequences.
[0135] The semantic feature vector of each document is predetermined. For example, a teacher model is used to pre-encode each document in the document library to obtain the semantic feature vector of each document.
[0136] Step 205: Input each of the target concatenated sequences into a target model to obtain the correlation between the target query statement and each of the documents.
[0137] In this embodiment, after obtaining the target query statement, it is only necessary to splice the target query statement with the prompt word and input it into the teacher model. In this way, the length of the sequence input into the teacher model can be shortened, the computational overhead can be reduced, and the efficiency of the teacher model in outputting the semantic feature vector of the target spliced sequence can be improved. In addition, the semantic feature vector of the document can be determined in advance by the teacher model, which can reduce the amount of online calculation in the implicit reasoning retrieval process. The above-mentioned method of separate encoding of documents and target query statements (the process of determining the semantic feature vector can be understood as the encoding process) can reduce the response delay of the retrieval and improve the real-time output of the retrieval results to meet the real-time requirements of users.
[0138] The following is an example of the implicit reasoning retrieval method provided in the embodiments of the present application.
[0139] The overall architecture of the student model consists of two parts: the offline phase and the online phase. The offline phase pre-encodes and stores the documents to be queried (i.e., documents in the document library). The online phase receives and processes user input queries in real time, then encodes them and uses the MoE in the student model to perform relevance inference. The training process is described below.
[0140] 1.1 Distillation training framework and teacher-student framework:
[0141] This application employs a knowledge distillation architecture, guided by the reasoning capabilities of a fully interactive latent inference model (teacher model), using two loss functions: latent space distribution transfer and relevance score regression as a supervision strategy. The following sections describe the distillation learning framework and training process. The core of this process is the student model learning the output distribution of the teacher model by optimizing the MoE, ultimately achieving relevance reasoning and separate encoding of documents and queries through the MoE.
[0142] Figure 3a Another flowchart of the implicit reasoning retrieval method provided in the embodiment of the present application is shown in FIG. Figure 3a ,in:
[0143] 1) Teacher model reasoning and label generation (offline stage)
[0144] The training process uses LLM with implicit reasoning retrieval function as the teacher model. The implicit reasoning retrieval process of the teacher model is as follows: Figure 3b shown.
[0145] Input construction: The document (doc), user query (query), and prompt word (Prompt) are concatenated into a long sequence (format: "[Prompt]+[Query]+[Document]") and input into the teacher model (the teacher model is an instruction-fine-tuned LLM).
[0146] Label extraction:
[0147] Hidden state supervision: The hidden state vector (Last HiddenState) output by the last layer of LLMs of the teacher model is extracted as the semantic distribution label. The hidden state vector can also be called a semantic feature vector.
[0148] Relevance score supervision: Obtain the "yes / no" probability value output by the teacher model and use it as the relevance score label after Softmax normalization.
[0149] Offline storage: Apply the above process to all documents in the document library to obtain a distilled knowledge base containing hidden state vectors and relevance scores.
[0150] 2) Student model training (online stage)
[0151] The student model adopts a pre-coding-dynamic inference decoupling architecture:
[0152] Document pre-encoding (offline phase):
[0153] Use the teacher model to pre-encode the document library and generate the hidden state vector corresponding to each document.
[0154] Online Distillation Inference (Online Phase):
[0155] Dynamic query processing: Receive user queries online, concatenate prompts to obtain the first concatenated sequence, input the first concatenated sequence into the teacher model, and obtain the hidden state vector of the first concatenated sequence;
[0156] Cross-fusion of documents and first concatenated sequences: concatenate the hidden state vector of the first concatenated sequence with the hidden state vector of each document to obtain multiple second concatenated sequences, input each second concatenated sequence into the sparse MoE, and obtain the semantic feature vector of each second concatenated sequence;
[0157] Hierarchical Distillation Learning:
[0158] Latent space alignment: Minimize the difference between the hidden state distribution output by the student model MoE and the hidden state distribution output by the teacher model through KL divergence (using formula (1));
[0159] Score regression: By constraining the relevance score output by the student model to be consistent with the relevance score output by the teacher model (using formula (2)).
[0160] Formula (1) represents the difference in hidden state distribution between the student model and the teacher model, measured by KL divergence. This loss ensures that the hidden state distribution of the student model is as close as possible to the teacher model, preserving the similarity at the semantic level.
[0161] Formula (2) represents the difference in relevance scores between the student model and the teacher model. This loss function ensures that the relevance score output by the student model is as close as possible to the teacher model, preserving the accuracy at the task level.
[0162] Formula (1) and Formula (2) measure the difference between the student model and the teacher model from two dimensions: latent state distribution (which can also be understood as semantic distribution) and relevance score.
[0163] By optimizing these two loss functions, the student model can approach the teacher model at both the semantic and task levels, achieving efficient distillation learning.
[0164] MoE is a dynamic routing architecture whose core idea is to decouple model parameters into multiple experts and dynamically select and activate a small number of relevant experts (such as 2-4) based on the input semantics through a gating network, thereby achieving dual optimization of parameter efficiency and computational efficiency. Specifically, sparse MoE achieves efficient reasoning through the following mechanisms:
[0165] Expert module: Each expert is an independent sub-network that focuses on a specific task or semantic domain (such as logical reasoning expert, common sense association expert).
[0166] Gated network: Calculates expert activation probabilities based on input features (such as query semantic vectors), selects only a few experts with the highest probabilities to participate in the calculation, and the rest remain dormant.
[0167] Sparse activation: Through the sparse design of the gated network (such as Top-K routing), only 5%-10% of the total model parameters are activated, significantly reducing computational overhead and memory usage.
[0168] 1.2 Reasoning process:
[0169] Offline phase: Documents to be retrieved are pre-encoded and stored offline. First, the documents in the document repository are encoded using the Large Language Model (LLM) and stored in the document vector library. This avoids the need for repeated concatenation and LLM processing for different queries in implicit inference retrieval. When different queries are received, the MoE module handles the relevance inference between the documents and the queries.
[0170] Online Phase: The online phase consists of query input, LLM encoding, a vector concatenation module, a relevance inference module, and an LLM head module. The online query input module receives real-time query requests and concatenates binary classification prompts. LLM encoding is then used to generate a query vector. The vector concatenation module concatenates the query vector and the document vector. The MoE relevance inference module uses a hybrid expert model to perform relevance inference on the concatenated vectors. Finally, the LLM head module generates a relevance score, completing the retrieval. The LLM head is part of the LLM. Both the offline and online phases use the same LLM.
[0171] refer to Figure 3a :
[0172] 1Offline phase includes:
[0173] - Obtaining a document library: such as some response strategies, etc. The documents may not be directly related to the query in terms of surface semantics, but potential connections can be established through logical reasoning chains, empirical associations, or cross-modal inferences.
[0174] -LLM encoding: Use LLM (teacher model) to encode the processed document into a fixed-dimensional vector (i.e., latent state vector), capturing deep semantic and logical information and pre-storing it.
[0175] 2 online phases include:
[0176] -Query input: Receive real-time query requests and concatenate them into prompt as online query input.
[0177] -LLM encoding: LLM is also used to encode the query and generate a query vector, which is represented in the same semantic space as the document encoding to facilitate subsequent relevance analysis.
[0178] Vector stitching:
[0179] The query vector and document vector are concatenated in a fixed order to form a fusion vector, which represents the joint features of the query and document and provides input for the subsequent relevance reasoning module.
[0180] MoE relevance reasoning:
[0181] MoE uses a hybrid expert network consisting of multiple expert networks and a gating network. Each expert network is responsible for processing different types of patterns and features and performing related inference tasks. The gating network dynamically and selectively activates the most appropriate expert network based on input features, achieving sparse activation and efficient parameter utilization.
[0182] The dynamic selection mechanism of MoE analyzes the input data in real time through a gating network (a linear mapping network from input to expert number), adaptively assigns weights to different expert models and sparsely activates the most relevant top-k expert models.
[0183] The dynamic selection mechanism can be intuitively understood through an example of natural language processing: assuming the model needs to process the sentence "The pizza in this restaurant is great, but the service is too slow", the gating network first analyzes the keywords in the sentence (such as "great" and "too slow" involve sentiment polarity, and "restaurant" and "pizza" belong to entity categories), and then dynamically assigns weights - sentiment analysis experts receive the highest weight (0.7), followed by entity recognition experts (0.2), and other irrelevant experts (such as grammatical parsing) have weights close to zero; in the end, only the first two experts are activated, the sentiment expert outputs "positive evaluation of food, negative evaluation of service", and the entity expert marks "restaurant" as a location entity. The model combines the results of the two to generate an accurate semantic representation. The entire process only requires calling 20% of the model parameters, significantly improving efficiency.
[0184] Relevance reasoning process: The concatenated vector is input into the MoE model, the expert network performs correlation analysis and reasoning on different features, the gating network controls the activation degree of the expert network, and finally the LLM-head outputs the relevance score of the query and document in the implicit reasoning relationship.
[0185] In an implicit reasoning retrieval system, the user query, related documents, and prompt are first encoded using LLM to generate vector representations. These concatenated vectors are then fed into the MoE model, where an expert network performs relevance analysis and reasoning on these features. A gating network controls which expert networks are activated to process a specific query-document pair. Ultimately, the model outputs a relevance score, indicating the degree of match between the query and document based on the implicit reasoning relationship.
[0186] The advantage lies in its ability to partially distill the reasoning knowledge and capabilities implicit in documents and queries, implemented by the implicit reasoning model (teacher model) using the reasoning capabilities of the LLM, into a lightweight MoE. During the reasoning process, only a small number of experts are activated based on different inputs (such as emotional support), which not only improves reasoning efficiency but also reduces computing resource consumption. This sparse activation mechanism makes the MoE model more scalable and real-time when processing large document repositories, while maintaining reasoning accuracy.
[0187] Through this design of the MoE model, the implicit reasoning retrieval system can significantly improve retrieval efficiency and reduce computational costs while maintaining high accuracy, making it more suitable for deployment in resource-constrained environments.
[0188] How to determine the target expert network from multiple expert networks to perform a specific task, for example, how to determine the expert network that performs "characteristic correlation analysis and reasoning"?
[0189] For example, if the model needs to process the sentence "The pizza at this restaurant is great, but the service is too slow," the gating network first analyzes the keywords in the sentence (e.g., "great" and "too slow" involve sentiment polarity, and "restaurant" and "pizza" belong to entity categories), and then dynamically assigns weights (implemented by the gating network)—the sentiment analysis expert receives the highest weight (0.7), followed by the entity recognition expert (0.2), and the weights of other irrelevant experts (such as grammatical parsing) are close to zero; ultimately, only the first two experts are activated, the sentiment expert outputs "positive comments on the food, negative comments on the service," and the entity expert labels "restaurant" as a location entity. The model combines the results of the two to generate an accurate semantic representation. The entire process only requires calling 20% of the model parameters, significantly improving efficiency.
[0190] LLM head processing:
[0191] The MoE relevance reasoning module outputs scores that are further processed and output by designing specific output layers or adapters to convert the relevance scores into more intuitive and user-friendly forms, such as binary classification results (yes / no), indicating whether there is an implicit reasoning relationship between the query and the document. We obtain the probability distribution over the LLMs' vocabularies and extract the probability value of "yes" as the relevance score.
[0192] The method provided in the embodiment of the present application uses the distillation learning method, takes the LLM of implicit reasoning as the teacher model, and distills the key path of relevance reasoning from it through the teacher-supervised optimization MoE module, thereby realizing efficient collaboration between offline document precoding and online sparse activation reasoning.
[0193] Decouple the fully interactive computing into two parts: offline document pre-encoding and real-time query reasoning, avoiding repeated splicing of long text inputs and executing large model reasoning in the online stage.
[0194] Through offline document precoding, the sequence length that LLM needs to process is significantly reduced, the computational complexity and memory overhead are reduced, thereby alleviating high computing requirements and improving retrieval efficiency.
[0195] In the online stage, a sparsely activated mixture of experts (MoE) model is used to dynamically select reasoning paths based on query semantics, activating only a small number of experts, reducing the number of model parameters and computational complexity, significantly reducing reasoning latency, and improving online retrieval efficiency.
[0196] Combining offline document vector preloading with query-side MoE real-time computation (INT8 low-precision inference) allows for global optimization of memory and computing resources. This further reduces memory usage and computing overhead, meeting the performance requirements of large-scale real-time retrieval systems.
[0197] Using a task-adaptive distillation strategy, we decouple the complex reasoning capabilities of the Large Language Model (LLM) into offline reasoning on the document side (pre-encoded implicit relationship graph) and lightweight online reasoning on the query side, achieving efficient knowledge transfer. Through distillation technology, we migrate some of the LLM's reasoning capabilities to the lightweight MoE model, significantly improving retrieval efficiency while maintaining reasoning capabilities.
[0198] Figure 4 The schematic diagram of the structure of the model training device provided in the embodiment of the present application is shown. Figure 4 As shown, the model training device 400 includes:
[0199] A first acquisition module 401 is used to acquire a first query statement;
[0200] A first concatenation module 402 is configured to concatenate the first query statement with a preconfigured prompt word to obtain a first concatenation sequence;
[0201] A second acquisition module 403 is configured to input the first concatenated sequence into a pre-trained teacher model to obtain a semantic feature vector of the first concatenated sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0202] A second splicing module 404 is configured to splice the semantic feature vector of the first splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain a plurality of second splicing sequences;
[0203] A third acquisition module 405 is configured to input each of the second concatenated sequences into a student model to obtain a semantic feature vector of each of the second concatenated sequences;
[0204] A construction module 406 is configured to construct a loss function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences, where the semantic feature vectors of the third concatenated sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library.
[0205] The adjustment module 407 is used to adjust the parameters of the student model according to the loss function to obtain a target model.
[0206] In one embodiment of the present application, the model training device 400 further includes:
[0207] A fourth acquisition module, configured to acquire a second query statement;
[0208] a third splicing module, configured to splice the second query statement, the prompt word, and the document for each document in the document library to obtain a third splicing sequence corresponding to the document;
[0209] The fifth acquisition module is used to input each of the third splicing sequences into the teacher model to obtain a semantic feature vector of each of the third splicing sequences.
[0210] In one embodiment of the present application, the loss function includes a first loss sub-function and / or a second loss sub-function;
[0211] The building block 406 includes:
[0212] A first construction submodule is configured to construct a KL divergence function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences to obtain the first loss subfunction;
[0213] and / or,
[0214] a first acquisition submodule, configured to perform vocabulary projection and probability calculation on the semantic feature vectors of the plurality of second spliced sequences to obtain a first probability value corresponding to the semantic feature vector of each second spliced sequence, wherein the first probability value corresponding to each second spliced sequence is used to represent the relevance between the first query statement and the document used by the second spliced sequence;
[0215] a second acquisition submodule, configured to perform vocabulary projection and probability calculation on the semantic feature vectors of the plurality of third splicing sequences to obtain a second probability value corresponding to the semantic feature vector of each third splicing sequence, wherein the second probability value corresponding to each third splicing sequence is used to characterize the relevance between the second query statement and the document used by the third splicing sequence;
[0216] The second construction submodule is used to construct a Euclidean distance function according to multiple first probability values and multiple second probability values to obtain the second loss subfunction.
[0217] In one embodiment of the present application, the student model includes a hybrid expert system MoE and a language model head LLM-head module;
[0218] A third acquisition module 405 is specifically configured to input each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences;
[0219] Accordingly, the first acquisition submodule is specifically configured to input the semantic feature vector of each second splicing sequence into the LLM-head module for vocabulary projection and probability calculation, to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence;
[0220] Accordingly, the adjustment module 407 includes:
[0221] According to the first loss sub-function and the second loss sub-function, the parameters of the MoE are adjusted to obtain the target model.
[0222] In one embodiment of the present application, the model training device 400 further includes:
[0223] The sixth acquisition module is used to input each document in the document library into the teacher model to obtain a semantic feature vector of each document.
[0224] In one embodiment of the present application, the student model includes a hybrid expert system MoE and a language model head LLM-head module; the third acquisition module 405 includes:
[0225] a third acquisition submodule, configured to input each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences;
[0226] The fourth acquisition submodule is used to input the semantic feature vector of each second splicing sequence into the LLM-head module for vocabulary projection and probability calculation to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence. The first probability value corresponding to each second splicing sequence is used to characterize the correlation between the first query statement and the document used by the second splicing sequence; the first probability value corresponding to each second splicing sequence is used to participate in constructing the loss function.
[0227] The model training device 400 provided in the embodiment of the present application can implement each process implemented in the aforementioned model training method embodiment and achieve the same technical effect. To avoid repetition, it will not be described here.
[0228] Figure 5 FIG. 1 shows a schematic diagram of the structure of the implicit reasoning retrieval device provided in an embodiment of the present application. Figure 5 As shown, the implicit reasoning retrieval device 500 includes:
[0229] The seventh acquisition module 501 is used to acquire a target query statement;
[0230] A fourth splicing module 502 is configured to splice the target query statement with pre-configured prompt words to obtain a target splicing sequence;
[0231] An eighth acquisition module 503 is configured to input the target splicing sequence into a pre-trained teacher model to obtain a semantic feature vector of the target splicing sequence, wherein the teacher model has implicit reasoning retrieval capability;
[0232] A fifth splicing module 504 is configured to splice the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain a plurality of target splicing sequences;
[0233] The ninth acquisition module 505 is configured to input each of the target concatenated sequences into a target model to obtain the correlation between the target query statement and each of the documents.
[0234] The implicit reasoning retrieval device 500 provided in the embodiment of the present application can implement each process implemented in the aforementioned implicit reasoning retrieval method embodiment and achieve the same technical effect. To avoid repetition, it will not be described here.
[0235] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.
[0236] The electronic device may include a processor 601 and a memory 602 storing computer program instructions.
[0237] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0238] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 602 may include removable or non-removable (or fixed) media. Where appropriate, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0239] The memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to the first aspect or the second aspect of the present disclosure.
[0240] The processor 601 implements any one of the information auditing methods in the above embodiments by reading and executing computer program instructions stored in the memory 602 .
[0241] In one example, the electronic device may further include a communication interface 603 and a bus 610. Figure 6 As shown, the processor 601, the memory 602, and the communication interface 603 are connected via a bus 610 and communicate with each other.
[0242] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0243] Bus 610 comprises hardware, software or both, and the parts of information audit method or verification equipment are coupled to each other.For example, and not limitation, bus can comprise accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations.In suitable cases, bus 610 can comprise one or more buses.Although the present application embodiment describes and shows specific bus, the application considers any suitable bus or interconnection.
[0244] In addition, in conjunction with the model training method in the above embodiments, embodiments of the present application may provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the model training methods or implicit reasoning retrieval methods in the above embodiments is implemented.
[0245] An embodiment of the present application may provide a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes any one of the model training methods or implicit reasoning retrieval methods in the above embodiments.
[0246] An embodiment of the present application also provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes any one of the model training methods or implicit reasoning retrieval methods in the above embodiments.
[0247] It should be understood that the present application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, a detailed description of known methods is omitted here. In the above embodiments, several specific steps are described as examples. However, the method process of the present application is not limited to the specific steps described. Those skilled in the art can make various changes, modifications, and additions, or change the order of the steps after understanding the spirit of the present application.
[0248] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium that can store or transmit information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROMs, flash memories, erasable ROMs (EROMs), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0249] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps. In other words, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0250] Aspects of the present disclosure have been described above with reference to the flowcharts and / or block diagrams of the methods, devices (systems) according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It is also understood that each box in the block diagram and / or flowchart and the combination of the boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0251] The above description is only a specific embodiment of the present application. Those skilled in the art will clearly understand that for the convenience and brevity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the scope of protection of the present application.
Claims
1. A model training method, characterized in that: The method comprises: Get the first query statement; splicing the first query statement with a preconfigured prompt word to obtain a first splicing sequence; Inputting the first spliced sequence into a pre-trained teacher model to obtain a semantic feature vector of the first spliced sequence, wherein the teacher model has implicit reasoning retrieval capability; Splicing the semantic feature vector of the first splicing sequence with the semantic feature vector of each of the documents in the pre-acquired document library to obtain a plurality of second splicing sequences; inputting each of the second spliced sequences into a student model to obtain a semantic feature vector of each of the second spliced sequences; Constructing a loss function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences, where the semantic feature vectors of the third concatenated sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library; The parameters of the student model are adjusted according to the loss function to obtain a target model.
2. The model training method according to claim 1, characterized in that Before constructing the loss function based on the semantic feature vectors of the plurality of second spliced sequences and the semantic feature vectors of the plurality of third spliced sequences, the method further includes: Get the second query statement; For each of the documents in the document library, concatenate the second query statement, the prompt word, and the document to obtain a third concatenated sequence corresponding to the document; Each of the third concatenated sequences is input into the teacher model to obtain a semantic feature vector of each of the third concatenated sequences.
3. The model training method according to claim 1 or 2, characterized in that: The loss function includes a first loss sub-function and / or a second loss sub-function; The constructing a loss function according to the semantic feature vectors of the plurality of second spliced sequences and the semantic feature vectors of the plurality of third spliced sequences includes: constructing a KL divergence function based on the semantic feature vectors of the second concatenated sequences and the semantic feature vectors of the third concatenated sequences to obtain the first loss sub-function; and / or, Performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of second splicing sequences to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence, wherein the first probability value corresponding to each second splicing sequence is used to represent the relevance between the first query statement and the document used by the second splicing sequence; Performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of third splicing sequences to obtain a second probability value corresponding to the semantic feature vector of each third splicing sequence, wherein the second probability value corresponding to each third splicing sequence is used to characterize the relevance between the second query statement and the document used by the third splicing sequence; A Euclidean distance function is constructed according to the plurality of first probability values and the plurality of second probability values to obtain the second loss sub-function.
4. The model training method according to claim 3, characterized in that The student model includes a hybrid expert system MoE and a language model head LLM-head module; Inputting each of the second spliced sequences into the student model to obtain a semantic feature vector of each of the second spliced sequences includes: Inputting each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences; The performing vocabulary projection and probability calculation on the semantic feature vectors of the plurality of second splicing sequences to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence includes: The semantic feature vector of each second splicing sequence is input into the LLM-head module for vocabulary projection and probability calculation to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence.
5. The model training method according to claim 1, characterized in that The student model includes a hybrid expert system MoE and a language model head LLM-head module; Inputting each of the second spliced sequences into the student model to obtain a semantic feature vector of each of the second spliced sequences includes: Inputting each of the second spliced sequences into MoE to obtain a semantic feature vector of each of the second spliced sequences; The semantic feature vector of each second splicing sequence is input into the LLM-head module for vocabulary projection and probability calculation to obtain a first probability value corresponding to the semantic feature vector of each second splicing sequence. The first probability value corresponding to each second splicing sequence is used to characterize the correlation between the first query statement and the document used by the second splicing sequence; the first probability value corresponding to each second splicing sequence is used to participate in constructing the loss function.
6. The model training method according to claim 1, characterized in that Before respectively concatenating the semantic feature vector of the first concatenated sequence with the semantic feature vector of each of the documents in the pre-acquired document library to obtain a second concatenated sequence corresponding to each of the documents, the method further includes: For each of the documents in the document library, the document is input into the teacher model to obtain a semantic feature vector of each of the documents.
7. An implicit reasoning retrieval method, characterized in that: The method comprises: Get the target query statement; Splicing the target query sentence with pre-configured prompt words to obtain a target splicing sequence; Inputting the target splicing sequence into a pre-trained teacher model to obtain a semantic feature vector of the target splicing sequence, wherein the teacher model has implicit reasoning retrieval capability; Splicing the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain multiple target splicing sequences; Each of the target concatenated sequences is input into a target model to obtain the correlation between the target query statement and each of the documents, wherein the target model is obtained by the model training method according to any one of claims 1-6.
8. A model training device, characterized in that: The device comprises: A first acquisition module, configured to acquire a first query statement; a first concatenation module, configured to concatenate the first query statement with a preconfigured prompt word to obtain a first concatenation sequence; a second acquisition module, configured to input the first spliced sequence into a pre-trained teacher model to obtain a semantic feature vector of the first spliced sequence, wherein the teacher model has implicit reasoning retrieval capability; A second splicing module is configured to splice the semantic feature vectors of the first splicing sequence with the semantic feature vectors of each of the documents in the pre-acquired document library to obtain a plurality of second splicing sequences; a third acquisition module, configured to input each of the second spliced sequences into a student model to obtain a semantic feature vector of each of the second spliced sequences; a construction module, configured to construct a loss function based on a plurality of semantic feature vectors of the second concatenated sequences and a plurality of semantic feature vectors of the third concatenated sequences, wherein the semantic feature vectors of the third concatenated sequences are obtained by the teacher model based on the second query statement, the prompt word, and each of the documents in the document library; An adjustment module is used to adjust the parameters of the student model according to the loss function to obtain a target model.
9. An implicit reasoning retrieval device, characterized in that: The device comprises: A first acquisition module is used to acquire a target query statement; A second splicing module is used to splice the target query sentence with the preconfigured prompt words to obtain a target splicing sequence; A second acquisition module is used to input the target splicing sequence into a pre-trained teacher model to obtain a semantic feature vector of the target splicing sequence, wherein the teacher model has implicit reasoning retrieval capability; A third splicing module is configured to splice the semantic feature vector of the target splicing sequence with the semantic feature vector of each document in the pre-acquired document library to obtain a plurality of target splicing sequences; The third acquisition module is used to input each of the target splicing sequences into a target model to obtain the correlation between the target query statement and each of the documents, wherein the target model is obtained according to the model training method according to any one of claims 1-6.
10. An electronic device, characterized in that: include: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the model training method as described in any one of claims 1 to 6, or when the processor executes the computer program instructions, it implements the implicit reasoning retrieval method as described in claim 7.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the model training method according to any one of claims 1 to 6, or, when executed by a processor, implement the implicit reasoning retrieval method according to claim 7.
12. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the model training method as described in any one of claims 1 to 6 or the implicit reasoning retrieval method as described in claim 7.
Citation Information
Cited By
Mathematical problem solving method for small parameter large language model and its application
CN122366681A