A multi-domain distribution out-of-context learning method and system based on domain discrimination enhancement

CN122433745APending Publication Date: 2026-07-21JILIN UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JILIN UNIVERSITY
Filing Date
2026-05-06
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing technologies suffer from negative transfer, domain noise interference, information redundancy, and sample homogenization in cross-domain transfer scenarios, which leads to a decrease in the inference performance of large language models in multi-domain distributed scenarios. Furthermore, existing methods are too complex to be applied in real time.

Method used

We extract semantic vectors by freezing the pre-trained language model, calculate domain generality and semantic confidence index by combining domain discriminator and task classifier, and filter context examples by multi-dimensional feature fusion and maximum marginal relevance algorithm to build a robust prompt.

Benefits of technology

It effectively avoids model overfitting, improves the inference accuracy and robustness of large language models in multi-domain distributed scenarios, ensures semantic clarity and diversity, and enhances cross-domain transfer capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122433745A_ABST
    Figure CN122433745A_ABST
Patent Text Reader

Abstract

The application discloses a multi-domain distribution out-of-context learning method and system based on domain discrimination enhancement, and belongs to the technical field of natural language processing. The application obtains a target test sample and a source domain training sample set, extracts a semantic vector by using a pre-training language model with frozen parameters and constructs an initial candidate sample pool, obtains a domain generality index of the sample by using a domain discriminator, obtains a semantic confidence index of the sample by using a task classifier, fuses the semantic similarity, the domain generality index and the semantic confidence index to obtain a comprehensive robustness score, screens the sample according to the comprehensive robustness score to construct a context example set, constructs a prompt, inputs the prompt into a large language model to obtain a prediction result. The application avoids negative transfer by freezing the main parameters of the pre-training language model, suppresses domain noise interference by joint evaluation of the domain discriminator and the task classifier, reduces information redundancy by multi-dimensional feature fusion and diversity screening, and enhances the inference performance and robustness of the large language model in a multi-domain distribution out-of-context scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of natural language processing, and in particular relates to a multi-domain distributed external context learning method and system based on domain discrimination enhancement. Background Technology

[0002] The development of Large Language Models (LLMs), represented by GPT-3, GPT-4, PaLM, and Llama, has driven a paradigm shift in natural language processing, with the traditional "pre-training-fine-tuning" paradigm gradually being replaced by the "pre-training-hint" paradigm. Among these, In-Context Learning (ICL), a technique that adapts to new tasks without parameter updates, guides large language models to complete specific tasks using knowledge accumulated during the pre-training phase by providing a small number of input-output examples in the input hints. This approach reduces model deployment costs and possesses few-shot learning capabilities. However, the inference performance of ICL is highly dependent on the quality of the selected context examples; the semantic relevance, label distribution, and arrangement order of the examples all affect the final inference result. In scenarios where the training and test data distributions are consistent, semantic similarity-based retrieval methods often achieve certain results. However, in real-world applications, models frequently face the challenge of out-of-domain (OOD) scenarios, where the target domain of the test sample differs significantly from the source domain of the retrieved example.

[0003] In cross-domain transfer OOD scenarios, existing ICL example selection techniques face multiple technical bottlenecks. First, negative transfer is a significant issue. To improve retrieval accuracy, existing techniques often attempt to fine-tune the retrieval engine or suggestion model on source domain data. However, source domain data typically possesses strong domain-specific characteristics, and fine-tuning can easily lead to overfitting the model to specific sentence structures, word distributions, or noise patterns within the source domain, thereby compromising the original general semantic representation capabilities of the pre-trained model. When facing an unknown target domain, this overfitting results in decreased model performance, and fine-tuning without decoupling domain-specific features often exacerbates contextual bias and optimization difficulties. Second, there are issues with domain noise interference and spurious relevance. Traditional cosine similarity-based retrieval primarily focuses on vector space distance, making it difficult to effectively identify and eliminate samples in the source domain that are literally similar but actually contain strong domain-specific noise (such as specific slang). This can cause large language models to incorrectly focus on specific styles rather than task logic, leading to inference bias, and existing techniques lack a mechanism for explicitly quantifying the "domain universality" of samples. Furthermore, there are issues of information redundancy and homogenization. Traditional methods often select highly similar samples that overlap significantly in the feature space, leading to redundant prompts and failing to provide the model with sufficiently rich decision boundary information. Especially in OOD scenarios, single-pattern examples result in diminishing marginal returns, while existing diversity algorithms have high computational complexity, making them difficult to apply in real-time for large-scale retrieval.

[0004] Existing solutions to the aforementioned problems still have limitations. While existing scientific question answering or multimodal decoupling methods propose feature decoupling approaches, their complex architectures typically require training dedicated encoders and decoders. Furthermore, they are primarily designed for full fine-tuning or task-specific training scenarios, making them unsuitable for direct application to parameter-frozen ICL frameworks or as lightweight post-processing selection mechanisms. In addition, existing techniques in the field of Retrieval Augmentation (RAG) largely focus on acquiring external knowledge through vector retrieval, neglecting the negative impact of sample quality and style on large-scale model inference during cross-domain transfer. They often assume that the retrieved content is of high quality, lacking fine-grained control over robustness evaluation and diversity re-ranking of retrieval results. Therefore, there is an urgent need for a new ICL example selection framework that can select candidate samples based on similarity, robustness (domain generality and semantic quality), and diversity without performing fine-tuning that could lead to negative transfer, thus adapting to multi-domain distribution scenarios. Summary of the Invention

[0005] To address the aforementioned technical problems, this invention provides a multi-domain distributed external context learning method based on domain discriminative enhancement, comprising the following steps: Obtain the target test sample and the training sample set containing data from multiple source domains; Based on the target test sample and the training sample set, semantic vectors are extracted using a pre-trained language model with frozen parameters, and semantic similarity is calculated based on the semantic vectors. Samples whose semantic similarity meets the preset conditions are selected to construct an initial candidate sample pool. Based on the initial candidate sample pool, the domain generality index of the sample is obtained using a domain discriminator, and the semantic confidence index of the sample is obtained using a task classifier. Based on the semantic similarity, the domain generality index, and the semantic confidence index, multi-dimensional feature fusion is performed to obtain the comprehensive robustness score of the sample. Based on the comprehensive robustness score, samples are selected from the initial candidate sample pool to construct a context example set; Based on the context example set and the target test sample, a prompt is constructed, and the prompt is input into a large language model to obtain the prediction result.

[0006] Optionally, the extraction of semantic vectors using the pre-trained language model with frozen parameters includes: Input the target test sample and each sample in the training sample set into the pre-trained language model, and obtain the vector corresponding to the last hidden state of the pre-trained language model as the semantic vector. The frozen parameters refer to the weight parameters of the pre-trained language model that are not updated during the extraction of semantic vectors.

[0007] Optionally, the method of obtaining the domain universality index of the sample using the domain discriminator includes: The samples in the initial candidate sample pool are input into the domain discriminator to obtain the probability distribution of the source domain to which the sample belongs; The information entropy is calculated based on the probability distribution, and the information entropy is used as a domain universality index.

[0008] Optionally, the semantic confidence index of the samples obtained using the task classifier includes: The samples in the initial candidate sample pool are input into the task classifier to obtain the predicted probability of the sample corresponding to the true label; The predicted probability is used as a semantic confidence index.

[0009] Optionally, the comprehensive robustness score of the acquired samples includes: The semantic similarity, the domain generality index, and the semantic confidence index are standardized to obtain standardized semantic similarity, standardized domain generality index, and standardized semantic confidence index. Based on preset quality weight parameters, the standardized semantic similarity, the standardized domain generality index, and the standardized semantic confidence index are weighted and fused to obtain a comprehensive robustness score.

[0010] Optionally, selecting samples from the initial candidate sample pool to build a context example set includes: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.

[0011] This invention also provides a multi-domain distributed external context learning system based on domain discrimination enhancement, comprising: The data interface module is used to acquire the target test sample; The general semantic recall module is used to extract semantic vectors using a pre-trained language model with frozen parameters based on the target test sample and a training sample set containing multiple source domain data, calculate semantic similarity based on the semantic vectors, and select samples whose semantic similarity meets preset conditions to construct an initial candidate sample pool. The robustness evaluation module is used to obtain the domain generality index of the samples using a domain discriminator and the semantic confidence index of the samples using a task classifier, based on the initial candidate sample pool. The multidimensional feature fusion module is used to perform multidimensional feature fusion based on the semantic similarity, the domain generality index and the semantic confidence index to obtain the comprehensive robustness score of the sample. A diversity selection module is used to select samples from the initial candidate sample pool to construct a context example set based on the comprehensive robustness score; The inference execution module is used to construct prompts based on the context example set and the target test sample, and input the prompts into the large language model to obtain prediction results.

[0012] Optionally, in the general semantic recall module, the pre-trained language model with frozen parameters is used to extract the semantic vector of each sample in the target test sample and the training sample set, and its weight parameters are not updated during the extraction process.

[0013] Optionally, the robustness evaluation module includes a domain discrimination unit and a task classification unit; The domain discrimination unit is used to input the samples in the initial candidate sample pool into the domain discriminator, obtain the probability distribution of the source domain to which the sample belongs, and calculate the information entropy as a domain universality index based on the probability distribution. The task classification unit is used to input the samples in the initial candidate sample pool into the task classifier and obtain the predicted probability of the sample corresponding to the real label as a semantic confidence index.

[0014] Optionally, the diversity selection module is specifically used for: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.

[0015] Compared with the prior art, the present invention has the following advantages and technical effects: The technical effects of the technical solution provided by the present invention are as follows: This invention extracts features by freezing the backbone parameters of a pre-trained language model, avoiding the overfitting risk caused by fine-tuning on source domain data. This preserves the general semantic representation capability of the pre-trained model and effectively solves the negative transfer problem in existing technologies, enabling the model to maintain robust inference performance when facing unknown target domains. By introducing a domain discriminator to calculate domain entropy, this invention can explicitly quantify and prioritize samples with strong domain invariance, effectively suppressing interference from source domain-specific noise. Simultaneously, by calculating semantic confidence through a task classifier, it can eliminate low-quality samples with semantic ambiguity or incorrect labeling, thus significantly improving the semantic clarity and domain generality of contextual examples. This invention uses a multi-dimensional feature fusion mechanism to adaptively weight and fuse semantic similarity, domain generality indicators, and semantic confidence indicators, achieving a multi-dimensional comprehensive evaluation of sample quality. Furthermore, by combining the maximum marginal relevance algorithm for diversity screening, it effectively avoids sample homogenization, maximizing the information difference between examples while ensuring semantic relevance, and constructing contextual cues with higher information density and broader feature coverage. Ultimately, this invention can significantly enhance the context learning performance of large language models in multi-domain distributed scenarios, and improve inference accuracy and robustness. Attached Figure Description

[0016] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings: Figure 1 This is a schematic diagram of the method flow according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the system structure according to an embodiment of the present invention. Detailed Implementation

[0017] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0018] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0019] Example 1 This embodiment provides a multi-domain distributed external context learning method based on domain discrimination enhancement, including the following steps: Obtain the target test sample and the training sample set containing data from multiple source domains; Based on the target test sample and the training sample set, semantic vectors are extracted using a pre-trained language model with frozen parameters, and semantic similarity is calculated based on the semantic vectors. Samples whose semantic similarity meets the preset conditions are selected to construct an initial candidate sample pool. Based on the initial candidate sample pool, the domain generality index of the sample is obtained using a domain discriminator, and the semantic confidence index of the sample is obtained using a task classifier. Based on the semantic similarity, the domain generality index, and the semantic confidence index, multi-dimensional feature fusion is performed to obtain the comprehensive robustness score of the sample. Based on the comprehensive robustness score, samples are selected from the initial candidate sample pool to construct a context example set; Based on the context example set and the target test sample, a prompt is constructed, and the prompt is input into a large language model to obtain the prediction result.

[0020] Specifically, it is divided into: Obtain the target test samples and the source domain training sample set; Using a pre-trained language model with frozen parameters as a feature extractor, global semantic vectors of the target test sample and the source domain training sample set are extracted; Calculate the cosine similarity between the target test sample and each sample in the source domain training sample set, and select the samples with the highest similarity to form an initial candidate sample pool; Construct and train a domain discriminator and a task classifier, wherein the domain discriminator is used to predict the source domain to which a sample belongs, and the task classifier is used to predict the task label of the sample; The domain entropy of each sample in the initial candidate sample pool is calculated using the domain discriminator, and the confidence score of each sample in the initial candidate sample pool is calculated using the task classifier. The cosine similarity, the domain entropy, and the confidence score are standardized respectively, and multi-dimensional feature weighted fusion is performed based on preset weight parameters to obtain the comprehensive score of each sample. Based on the comprehensive score, the initial candidate sample pool is reordered and filtered using the maximum marginal relevance algorithm to obtain the final context example set. The final set of context examples is used to construct prompts to guide the large language model in completing the reasoning task for the target test sample.

[0021] Furthermore, extracting semantic vectors using a pre-trained language model with frozen parameters includes: Input the target test sample and each sample in the training sample set into the pre-trained language model, and obtain the vector corresponding to the last hidden state of the pre-trained language model as the semantic vector. The frozen parameters refer to the weight parameters of the pre-trained language model that are not updated during the extraction of semantic vectors.

[0022] The backbone parameters of the pre-trained language model are frozen, and only the token representation of the output sample during its forward propagation process is used as the global semantic vector, thereby avoiding parameter updates on the source domain data.

[0023] Furthermore, the domain generality metrics of samples obtained using a domain discriminator include: The samples in the initial candidate sample pool are input into the domain discriminator to obtain the probability distribution of the source domain to which the sample belongs; The information entropy is calculated based on the probability distribution, and this information entropy is used as an index of domain universality. A higher entropy value indicates fewer domain-specific features of the sample, resulting in better domain invariance.

[0024] Furthermore, semantic confidence metrics for samples obtained using task classifiers include: The samples in the initial candidate sample pool are input into the task classifier to obtain the predicted probability of the sample corresponding to the true label; The predicted probability is used as a semantic confidence index.

[0025] Furthermore, the overall robustness score of the acquired samples includes: The semantic similarity, the domain generality index, and the semantic confidence index are standardized to obtain standardized semantic similarity, standardized domain generality index, and standardized semantic confidence index. Based on preset quality weight parameters, the standardized semantic similarity, the standardized domain generality index, and the standardized semantic confidence index are weighted and fused to obtain a comprehensive robustness score.

[0026] The standardization process employs the Z-Score standardization method, which maps the cosine similarity, the domain entropy, and the confidence score to a distribution interval with a mean of zero and a variance of one.

[0027] The calculation formula for multidimensional feature weighted fusion satisfies the following: the comprehensive score is equal to the standardized cosine similarity plus the quality weight parameter multiplied by the sum of the standardized domain entropy and the standardized confidence. The model's preference for sample robustness is controlled by adjusting the quality weight parameters.

[0028] Furthermore, the process of selecting samples from the initial candidate sample pool to construct a context example set includes: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.

[0029] Specifically, an iterative greedy strategy is adopted. In each step of the selection, samples with high comprehensive scores and low similarity to samples in the selected set are selected, and the relevance and information difference are balanced by the diversity weight parameter.

[0030] This embodiment also proposes a multi-domain distributed external context learning system based on domain discrimination enhancement, including: The data interface module is used to acquire the target test sample; The general semantic recall module is used to extract semantic vectors using a pre-trained language model with frozen parameters based on the target test sample and a training sample set containing multiple source domain data, calculate semantic similarity based on the semantic vectors, and select samples whose semantic similarity meets preset conditions to construct an initial candidate sample pool. The robustness evaluation module is used to obtain the domain generality index of the samples using a domain discriminator and the semantic confidence index of the samples using a task classifier, based on the initial candidate sample pool. The multidimensional feature fusion module is used to perform multidimensional feature fusion based on the semantic similarity, the domain generality index and the semantic confidence index to obtain the comprehensive robustness score of the sample. A diversity selection module is used to select samples from the initial candidate sample pool to construct a context example set based on the comprehensive robustness score; The inference execution module is used to construct prompts based on the context example set and the target test sample, and input the prompts into the large language model to obtain prediction results.

[0031] Furthermore, in the general semantic recall module, the pre-trained language model with frozen parameters is used to extract the semantic vector of each sample in the target test sample and the training sample set, and its weight parameters are not updated during the extraction process.

[0032] Furthermore, the robustness assessment module includes a domain discrimination unit and a task classification unit; The domain discrimination unit is used to input the samples in the initial candidate sample pool into the domain discriminator, obtain the probability distribution of the source domain to which the sample belongs, and calculate the information entropy as a domain universality index based on the probability distribution. The task classification unit is used to input the samples in the initial candidate sample pool into the task classifier and obtain the predicted probability of the sample corresponding to the real label as a semantic confidence index.

[0033] Furthermore, the diversity selection module is specifically used for: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.

[0034] Example 2 like Figure 1 As shown, this embodiment provides a multi-domain distributed external context learning method based on domain discrimination enhancement, including: S1. Obtain the target test sample and the training sample set containing data from multiple source domains; Specifically, obtain the target test samples that need to be used for context learning and reasoning. This sample typically belongs to the target domain, such as colloquial comments on social media. Simultaneously, a source domain training sample set is obtained to retrieve contextual examples (Demonstrations). ,in For text input, The corresponding task labels (such as sentiment polarity, classification category, etc.) are used. The source domain data may come from one or more domains with distributions significantly different from the target domain (e.g., canonical news reports or book reviews).

[0035] S2. Extract semantic features from the target test sample and the training sample set, and construct an initial candidate sample pool based on semantic similarity; Specifically, to avoid the model forgetting general language knowledge due to fine-tuning on specific source domain data (i.e., to avoid negative transfer), this step employs a frozen parameters strategy. A pre-trained language model (PLM) is used as the feature extractor. In this embodiment, the BERT-base-uncased model is used, and the weight parameters of all its layers are frozen, with no gradient updates performed. For the target test sample... Input it into the model Extract the last hidden state and label the corresponding vector as the global semantic representation. ,in For each sample in the training sample set Similarly, extract its semantic vector. .calculate With all source domain sample vectors Cosine similarity between them: ; All training samples are sorted in descending order based on similarity scores, and the top [samples] are selected. One sample (in this embodiment) ) to form the initial candidate sample pool This step ensures that the candidate samples maintain a basic semantic relevance to the target samples.

[0036] S3. Through the domain discrimination module, construct and use the domain discriminator to evaluate the domain universality of the samples in the initial candidate sample pool to obtain the domain entropy index; Specifically, this step aims to quantify the “domain universality” of a sample, i.e., whether the sample contains strong, source-domain-specific features that are difficult to transfer across domains.

[0037] Build a lightweight domain discriminator Its structure is a two-layer multilayer perceptron (MLP). The input is the semantic vector of the sample. The output is the sample belonging to The probability distribution of each source domain.

[0038] The forward computation process of the model is as follows: ; ; in, The discriminator is pre-trained on the source domain data by minimizing the domain classification cross-entropy loss. For the candidate sample pool... Each sample in Using the trained Inference is performed, and the information entropy of the predicted probability distribution is calculated as a domain entropy index. : ; Furthermore, domain entropy The higher the value, the more difficult it is for the discriminator to determine which specific source domain the sample belongs to (the more uniform the probability distribution). This means that the sample contains less "domain-specific noise," has stronger domain invariance, and is more suitable as a bridge for cross-domain migration.

[0039] S4. Through the task classification module, construct and use the task classifier to evaluate the semantic clarity of the samples in the initial candidate sample pool to obtain the semantic confidence index. Specifically, this step aims to quantify the "semantic quality" of the samples, that is, whether the samples are typical and whether the semantics are clear and unambiguous.

[0040] Build a lightweight task classifier It also employs a two-layer MLP structure. The input is the semantic vector of the sample. The output is the probability distribution of the sample belonging to each task category.

[0041] The forward computation process of the model is as follows: ; ; The classifier is pre-trained on source domain data by minimizing the task classification cross-entropy loss.

[0042] For candidate sample pool Each sample in Obtain its real tags The corresponding predicted probability value serves as a semantic confidence index. : ; Furthermore, confidence level The higher the value, the more significant the mapping relationship between the features and the label of the sample, indicating that it is a typical sample (Easy Sample) of the category, rather than a fuzzy sample located at the classification boundary or a noisy sample with incorrect labeling.

[0043] S5. Perform multi-dimensional feature fusion on the semantic similarity, domain entropy index and semantic confidence index to calculate the comprehensive robustness score; Specifically, since similarity (usually between 0.7 and 0.9), domain entropy (depending on the number of source domains) and confidence (0.5 to 1.0) are physical quantities of different natures and have huge differences in their numerical distributions, direct weighting is not feasible.

[0044] The three indicators were normalized using the Z-Score standardization method to map them to a standard normal distribution. ; ; ; in, and These are the indicators in the current candidate pool. The mean and standard deviation of the data.

[0045] Constructing a comprehensive robustness score The fusion formula: ; in, This represents the quality weight parameter. The formula dynamically balances the relevance of the sample to the target, the domain generality of the sample, and the semantic quality of the sample. In strongly out-of-distribution (OOD) scenarios, it can increase... The value is used to prioritize the selection of highly robust samples.

[0046] S6. Based on the comprehensive robustness score, use a diversity selection algorithm to filter context examples from the initial candidate sample pool; Specifically, to avoid semantic redundancy (homogeneity) in the selected Top-K samples, this step employs the Maximum Marginal Relevance (MMR) algorithm for final selection. Initialize the context example set. A greedy iterative strategy is adopted, which iterates through the remaining candidate pool each time. Select one sample join in The selection criterion is to maximize the following objective function: Among them: the first item This is used to ensure that the selected samples themselves are of high quality and high relevance; the second item Used for punishment and selected sets Candidates whose samples are too similar; For diversity weight parameters (in this embodiment) Repeat the selection process described above until a set is reached. The number of samples reached the preset value. (For example ).

[0047] S7. Based on the context example and the target test sample, construct prompts and input them into the large language model for inference and prediction.

[0048] Specifically, the selected Each context example is concatenated according to a predefined natural language template (PromptTemplate) to form a demonstration sequence containing "input-output" pairs. Finally, the input text of the target test sample is concatenated.

[0049] The completed prompts are input into a large language model (such as GPT-4, Llama-3), which will perform analogical reasoning based on contextual examples to generate prediction results for the target sample.

[0050] like Figure 2 As shown, this embodiment also provides a multi-domain distributed external context learning system based on domain discrimination enhancement, including: The input interface is used to receive the target test sample; Specifically, this interface is responsible for receiving the text data to be predicted submitted by the user (i.e., the target test sample). ) and related configuration parameters (such as the number of examples) Weight parameters and The interface is also responsible for basic preprocessing of the input text, such as truncating excessively long text and removing illegal characters.

[0051] A general semantic recall module is used to extract semantic features and build an initial candidate sample pool; Specifically, the core of this module includes a pre-trained language model (PLM) unit with frozen parameters and a vector retrieval unit. The PLM unit (such as BERT) is responsible for processing the input target test samples. The vector is converted into a high-dimensional semantic vector. The vector retrieval unit pre-stores the semantic vector indices of all samples in the source domain training set (such as the IVF index constructed using FAISS). Upon receiving the target vector, this unit performs an approximate nearest neighbor search to quickly retrieve the vector with the highest cosine similarity. Given samples, output the initial candidate sample pool. .

[0052] The domain discrimination module is used to construct and utilize a domain discriminator to evaluate the domain universality of samples in the initial candidate sample pool, thereby obtaining the domain entropy index. Specifically, this module is the first robustness evaluation core of the system. It loads a pre-trained domain discriminator. (MLP network). This module receives the semantic vector of the candidate sample and inputs it... The output sample is assigned a probability distribution belonging to each source domain. Subsequently, the information entropy of this probability distribution is calculated to generate a domain entropy index. This metric is used to quantify the domain invariance of samples and identify general samples that do not have a strong source domain style.

[0053] The task classification module is used to construct and utilize a task classifier to evaluate the semantic clarity of samples in the initial candidate sample pool and obtain a semantic confidence index. Specifically, this module is the second robustness evaluation core of the system. It loads a pre-trained task classifier. (MLP network). This module receives the semantic vector of the candidate sample and inputs it... This outputs the predicted probability of a sample corresponding to its true label. This probability value is directly used as a semantic confidence metric. This metric is used to remove low-quality samples that are semantically ambiguous, mislabeled, or located at the classification boundary.

[0054] The multi-dimensional feature fusion module is used to fuse the semantic similarity, domain entropy index and semantic confidence index into multi-dimensional features and calculate the comprehensive robustness score. Specifically, this module is responsible for integrating evaluation metrics from different sources. First, it performs statistical normalization: calculating the mean and standard deviation of each metric in the current candidate pool, and standardizing the similarity, domain entropy, and confidence of each sample using Z-Score. Then, it performs weighted fusion: according to a preset formula... Calculate the final score for each sample.

[0055] The diversity selection module is used to filter the final context examples based on a diversity algorithm; Specifically, this module implements the Maximum Marginal Relevance (MMR) algorithm. It maintains a list of selected examples and, in each round of selection, it iterates through the remaining candidate samples, calculates the weighted difference between their combined score and the "selected maximum similarity," and greedily selects the optimal sample to add to the list. This module ensures that the final output example set has good coverage in the feature space, reducing information redundancy.

[0056] The inference execution module is used to build prompts and perform inference on a large language model; Specifically, this module is responsible for processing the output of the diversity selection module. The optimal example and the target test sample are concatenated according to a predefined natural language template to generate the final Prompt. Then, the module calls the inference interface (API or local model) of the large language model, passes in the Prompt, retrieves the model's generated result, and parses the result to obtain the final predicted answer.

[0057] The model training module is used for offline training of auxiliary models; Specifically, although the model parameters are frozen during the inference phase, this module needs to use the source domain training data to test the domain discriminator during the system initialization phase. and task classifier Supervised training is performed. This module is responsible for defining the network structure, calculating the cross-entropy loss, and updating the parameters of the two lightweight networks through backpropagation until convergence.

[0058] The present invention has the following advantages: This invention extracts features by freezing the backbone parameters of the pre-trained language model, which solves the problem of negative transfer caused by source domain fine-tuning in existing technologies. It can completely avoid the risk of overfitting the model on source domain data with specific features, thereby preserving the model's generalization ability and making it more robust when facing unknown target domains.

[0059] This invention solves the problems of domain noise interference and pseudo-correlation in OOD scenarios by introducing a domain discriminator to calculate domain entropy and combining it with the confidence of the task classifier. It can explicitly quantify and prioritize those samples that are not sensitive to domain changes and have clear semantics, and remove noisy samples with strong source domain style, thereby enhancing the robustness of context examples.

[0060] This invention solves the problem of information homogenization caused by traditional Top-K retrieval by using multi-dimensional feature fusion and maximum marginal relevance (MMR) algorithm. It can maximize the information difference between examples while ensuring semantic relevance, and build prompts with higher information density and wider coverage of feature space, providing richer decision boundary information for large language models.

[0061] The above are merely preferred embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A multi-domain distributed out-of-context learning method based on domain discrimination enhancement, characterized in that, Includes the following steps: Obtain the target test sample and the training sample set containing data from multiple source domains; Based on the target test sample and the training sample set, semantic vectors are extracted using a pre-trained language model with frozen parameters, and semantic similarity is calculated based on the semantic vectors. Samples whose semantic similarity meets the preset conditions are selected to construct an initial candidate sample pool. Based on the initial candidate sample pool, the domain generality index of the samples is obtained using a domain discriminator, and the semantic confidence index of the samples is obtained using a task classifier. Based on the semantic similarity, the domain generality index, and the semantic confidence index, multi-dimensional feature fusion is performed to obtain the comprehensive robustness score of the sample. Based on the comprehensive robustness score, samples are selected from the initial candidate sample pool to construct a context example set; Based on the context example set and the target test sample, a prompt is constructed, and the prompt is input into a large language model to obtain the prediction result.

2. The method according to claim 1, characterized in that, The extraction of semantic vectors using the pre-trained language model with frozen parameters includes: Input the target test sample and each sample in the training sample set into the pre-trained language model, and obtain the vector corresponding to the last hidden state of the pre-trained language model as the semantic vector. The frozen parameters refer to the weight parameters of the pre-trained language model that are not updated during the extraction of semantic vectors.

3. The method according to claim 1, characterized in that, The domain universality index of the samples obtained using the domain discriminator includes: The samples in the initial candidate sample pool are input into the domain discriminator to obtain the probability distribution of the source domain to which the sample belongs; The information entropy is calculated based on the probability distribution, and the information entropy is used as a domain universality index.

4. The method according to claim 1, characterized in that, The semantic confidence metrics obtained from the sample using the task classifier include: The samples in the initial candidate sample pool are input into the task classifier to obtain the predicted probability of the sample corresponding to the true label; The predicted probability is used as a semantic confidence index.

5. The method according to claim 1, characterized in that, The overall robustness score of the acquired samples includes: The semantic similarity, the domain generality index, and the semantic confidence index are standardized to obtain standardized semantic similarity, standardized domain generality index, and standardized semantic confidence index. Based on preset quality weight parameters, the standardized semantic similarity, the standardized domain universality index, and the standardized semantic confidence index are weighted and fused to obtain a comprehensive robustness score.

6. The method according to claim 1, characterized in that, The sample construction context example set selected from the initial candidate sample pool includes: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.

7. A multi-domain distributed external context learning system based on domain discrimination enhancement, characterized in that, include: The data interface module is used to acquire the target test sample; The general semantic recall module is used to extract semantic vectors using a pre-trained language model with frozen parameters based on the target test sample and a training sample set containing multiple source domain data, calculate semantic similarity based on the semantic vectors, and select samples whose semantic similarity meets preset conditions to construct an initial candidate sample pool. The robustness evaluation module is used to obtain the domain generality index of the samples using a domain discriminator and the semantic confidence index of the samples using a task classifier, based on the initial candidate sample pool. The multidimensional feature fusion module is used to perform multidimensional feature fusion based on the semantic similarity, the domain generality index and the semantic confidence index to obtain the comprehensive robustness score of the sample. A diversity selection module is used to select samples from the initial candidate sample pool to construct a context example set based on the comprehensive robustness score; The inference execution module is used to construct prompts based on the context example set and the target test sample, and input the prompts into the large language model to obtain prediction results.

8. The system according to claim 7, characterized in that, In the general semantic recall module, the pre-trained language model with frozen parameters is used to extract the semantic vector of each sample in the target test sample and the training sample set, and its weight parameters are not updated during the extraction process.

9. The system according to claim 7, characterized in that, The robustness evaluation module includes a domain discrimination unit and a task classification unit; The domain discrimination unit is used to input the samples in the initial candidate sample pool into the domain discriminator, obtain the probability distribution of the source domain to which the sample belongs, and calculate the information entropy as a domain universality index based on the probability distribution. The task classification unit is used to input the samples in the initial candidate sample pool into the task classifier and obtain the predicted probability of the sample corresponding to the real label as a semantic confidence index.

10. The system according to claim 7, characterized in that, The diversity selection module is specifically used for: Initialize the context example collection to an empty set; Based on the maximum marginal relevance criterion, samples are iteratively selected from the initial candidate sample pool and added to the context example set; In each iteration, the candidate sample with the largest weighted difference is selected based on the comprehensive robustness score of the candidate sample and the maximum similarity between the candidate sample and the sample in the context example set, until the number of samples in the context example set reaches a preset value.