MODEL TRAINING METHOD, INFERENCE METHOD, ELECTRONIC DEVICE, AND STORAGE MEDIUM

A model training method, an inference method, a device, and a medium. A specific implementation solution includes: inputting a sample data sequence into a model to be trained to obtain a target sample feature sequence, where the sample data sequence includes a plurality of sample data, and the target sample feature sequence includes respective target sample features of the plurality of sample data; determining at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data, where the positive sample feature set for the target sample data includes respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features; and training the model to be trained according to the at least one first loss information.

Skip to: Description  ·  Claims  · Patent History  ·  Patent History
Description
CROSS-REFERENCE TO RELATED APPLICATION(S)

This application claims the benefit of Chinese Patent Application No. 202511842020.8 filed on Dec. 8, 2025, the whole disclosure of which is incorporated herein by reference.

TECHNICAL FIELD

The present disclosure relates to the field of artificial intelligence technology, and in particular to the technical fields of large models, deep learning, Natural Language Processing (NLP), pretraining, and fine-tuning. More specifically, the present disclosure provides a model training method, an inference method, an electronic device, and a storage medium.

BACKGROUND

With the development of artificial intelligence technology, applications of large models are continuously increasing. A large model may generate a response result according to input data of a single modality or multiple modalities. During a training process of a large model, parameters of the large model may be adjusted based on a loss information determined from a cross-entropy loss function.

SUMMARY

The present disclosure provides a model training method, an inference method, an electronic device, and a storage medium.

According to an aspect of the present disclosure, a model training method is provided, including: inputting a sample data sequence into a model to be trained to obtain a target sample feature sequence, where the sample data sequence includes a plurality of sample data, and the target sample feature sequence includes respective target sample features of the plurality of sample data; determining at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data, where the target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data, and the positive sample feature set for the target sample data includes respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features; and training the model to be trained according to the at least one first loss information, where the sample data sequence is obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

According to another aspect of the present disclosure, an inference method is provided, including: inputting a data sequence to be processed into a target model to obtain a response result, where the target model is trained according to the model training method provided by the present disclosure, and the data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, or a video to be processed.

According to another aspect of the present disclosure, an electronic device is provided, including: at least one processor; and a memory communicatively connected to the at least one processor, where the memory stores instructions executable by the at least one processor, and the instructions are configured to, when executed by the at least one processor, cause the at least one processor to perform the methods provided by the present disclosure.

According to another aspect of the present disclosure, a non-transitory computer-readable storage medium having computer instructions stored thereon is provided, where the computer instructions are configured to cause a computer to perform the methods provided by the present disclosure.

It should be understood that the content described in this section is not intended to identify key or critical features of embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood from the following description.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings are provided for better understanding of the present solution and do not constitute any limitation to the present disclosure. In the accompanying drawings:

FIG. 1 is a flowchart of a model training method according to an embodiment of the present disclosure;

FIG. 2 is a schematic structural diagram of a model to be trained according to an embodiment of the present disclosure;

FIG. 3 is a schematic diagram illustrating an effect of a feature alignment loss information according to an embodiment of the present disclosure;

FIG. 4 is a schematic diagram of a plurality of processing layers and an output layer according to an embodiment of the present disclosure;

FIG. 5 is a schematic diagram illustrating a principle of model training according to an embodiment of the present disclosure;

FIG. 6 is a schematic flowchart of an inference method according to an embodiment of the present disclosure;

FIG. 7 is a block diagram of a model training apparatus according to an embodiment of the present disclosure;

FIG. 8 is a block diagram of an inference apparatus according to another embodiment of the present disclosure; and

FIG. 9 is a block diagram of an electronic device to which at least one of the model training method and the inference method may be applied according to an embodiment of the present disclosure.

DETAILED DESCRIPTION OF EMBODIMENTS

Exemplary embodiments of the present disclosure will be described below with reference to the accompanying drawings, which include various details of embodiments of the present disclosure to facilitate understanding and should be considered as merely exemplary. Accordingly, those of ordinary skill in the art will appreciate that various changes and modifications may be made to embodiments described herein without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and structures are omitted in the following description for clarity and conciseness.

Training of a large model may include pretraining of the large model and supervised fine-tuning of the large model. The large model may be a Large Language Model (LLM), a Large Vision Model (LVM), or a Multimodal Large Language Model (MLLM). The large model may process data of one or more modalities. The data of one or more modalities may include at least one of text, image, audio, or video.

Taking processing of text-modality data as an example, a training strategy for a large model may be an extension of a conventional autoregressive language model for classification tasks. However, unlike general classification tasks, language data exhibits the following two special characteristics: (1) data sources have an extremely long-tail distribution; and (2) feature spaces corresponding to each predicted word differ significantly from one another. Such differences cause the feature spaces corresponding to the predicted words and used for classification to be insufficiently compact, which in turn results in insufficient feature separation margins during the feature extraction stage, further reducing the speed and performance of pretraining.

To improve training efficiency of a large model and performance of the trained large model, feature regularization technologies may be introduced into the training process, so as to enhance generalization capability and semantic consistency of the model through external features, auxiliary signals, or structural constraints. The feature regularization technologies include cross-domain feature alignment, content feature alignment, sentence feature alignment, context alignment, attribute feature alignment, and the like.

Cross-domain feature alignment may include performing feature alignment on data of different modalities or different domains to achieve a unified semantic space. For example, in a Contrastive Language-Image Pre-training (CLIP) model, features are extracted separately from images and texts, and a contrastive loss is introduced such that related image-text pairs are close to one another in an embedding space, thereby achieving cross-modal semantic consistency. Cross-domain feature alignment utilizes domain differences or modality differences as constraint carriers to achieve cross-domain knowledge sharing and transfer.

Content feature alignment focuses on consistency of the same semantic content in different contexts. By extracting keywords or semantic summaries from different text segments and projecting the keywords or semantic summaries into a unified semantic vector space, the model is enabled to generate consistent representations when encountering semantically similar content. Content feature alignment is commonly used in tasks such as document-level understanding, retrieval-augmented pretraining, and semantic clustering.

Sentence feature alignment may include: parsing syntactic structures or salient semantic units in a sentence, and using the syntactic structures or salient semantic units as auxiliary features for training. For example, sentence structures may be aligned according to syntax trees or dependency relationships, enabling the model to possess stronger modeling capability for contextual dependency relationships at the syntactic level.

Context alignment may include imposing constraints on features consistency across adjacent segments, different sampling perspectives, or multi-round contexts during the pretraining process. As a result, robustness of the model in contextual reasoning and long-range dependency modeling may be improved, enabling the model to learn stable and semantically transferable representations.

Attribute feature alignment may include explicitly separating or constraining feature dimensions corresponding to specific attributes to strengthen controllability and interpretability of the model with respect to specific feature factors. For example, feature decoupling may be achieved through orthogonality constraints or mutual-information minimization, enabling the model to learn more discriminative internal representations.

The aforementioned feature regularization technologies employ coarse-grained feature constraints and are therefore difficult to capture word-level differences. These feature regularization technologies typically use sentence-level, paragraph-level, or modality-level features as basic units while ignoring semantic dynamics at the word level or subword level. As a result, the model may exhibit deficiencies in fine-grained semantic modeling, especially resulting in insufficient performance in tasks involving polysemous words or strong contextual dependencies.

Furthermore, regularization signals of the aforementioned feature regularization technologies are insufficiently coupled with objectives of primary tasks. These feature regularization technologies are generally imposed independently through contrastive learning or feature alignment, and are not sufficiently integrated with loss structures of primary tasks such as classification and generation. Consequently, regularization terms may be difficult to directly promote performance improvements of primary tasks during the optimization process and may even introduce optimization conflicts in certain scenarios.

Correlations across feature dimensions are not effectively modeled by the aforementioned feature regularization technologies. These feature regularization technologies generally treat feature regularization as independent constraints and lack mechanisms for modeling intrinsic correlations among different feature dimensions (e.g., semantics, syntax, context, position, etc.). Such independent modeling method limits the capability of the model to capture interaction relationships among multidimensional features in complex scenarios.

The aforementioned feature regularization technologies exhibit limited adaptability to downstream-task transfer. Some regularization schemes introduce fixed feature constraints during the pretraining stage but are difficult to flexibly adapt to task-specific feature spaces during the downstream fine-tuning stage. As a result, discrepancies may exist between pretrained representations and downstream objectives, thereby affecting the generalization performance.

To further improve the model training efficiency and the performance of a trained model, the present disclosure provides a model training method, which will be described below.

FIG. 1 is a flowchart of a model training method according to an embodiment of the present disclosure.

As shown in FIG. 1, a method 100 may include operation S110 to operation S130.

In operation S110, a sample data sequence is input into a model to be trained to obtain a target sample feature sequence.

According to embodiments of the present disclosure, the sample data sequence may include a plurality of sample data. The sample data sequence is obtained from at least one of a sample text, a sample image, a sample audio, or a sample video. For example, the sample text may include a plurality of sample tokens, which may serve as the sample data sequence. The sample token may serve as sample data. The sample text may be: “Here is a PDF file on how they are used and what they look like”. It should be understood that the sample text including English words is merely an example, and the present disclosure is not limited thereto. The sample text may be text in various languages and may include tokens from one or more languages.

The model to be trained may be the large model described above. The model to be trained may extract features at different levels to obtain a plurality of feature sequences, and one of the plurality of feature sequences may be selected as the target sample feature sequence.

During the model training stage, an expected output of the model to be trained may be consistent with the input. The plurality of sample data in the sample data sequence are sequentially provided to the model to be trained. The model to be trained may determine subsequent data based on preceding sample data. For example, upon receiving the sample token “PDF”, the model to be trained may determine a subsequent token. The subsequent token may be “file”, which is consistent with the token expected to be output by the model. It should be understood that, during an early stage of training, the subsequent token determined by the model may be inconsistent with the token expected to be output by the model. As the model is iteratively trained, the consistency between the subsequent token determined by the model and the token expected to be output by the model may continue to improve.

The target sample feature sequence may include respective target sample features of the plurality of sample data. For example, the target sample feature sequence may include a target sample feature of the sample token “here”, and may further include a target sample feature of the sample token “is”.

In operation S120, at least one first loss information for at least one target sample data is determined according to at least one positive sample feature set for the at least one target sample data.

According to embodiments of the present disclosure, the target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data. For example, taking a sample text as an example of the sample data sequence, the above sample text includes two identical sample tokens “they”. The sample token “they” may serve as the target sample data. When the sample data sequence is a sample text, a preset text similarity threshold may be, for example, 1.

The positive sample feature set for the target sample data includes respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features. The plurality of preceding sample data may each be adjacent to a target sample data. For example, in the above sample text, two preceding sample tokens adjacent to the sample token “they” include the sample token “how” and the sample token “what”. The target sample feature of the sample token “how” and the target sample feature of the sample token “what” may serve as two first target sample features directed to the sample token “they”. A sample feature set including the two first target sample features may serve as the positive sample feature set for the sample token “they”.

A similarity between the plurality of first target sample features in the positive sample feature set for the target sample data may be determined, so as to determine the first loss information. For example, after determining the similarity between the plurality of first target sample features, the similarity may be multiplied by a preset negative value to obtain the first loss information. It should be understood that the first loss information being a negative value is merely an example, and the present disclosure is not limited thereto.

In operation S130, the model to be trained is trained according to the at least one first loss information.

According to embodiments of the present disclosure, parameters of the model to be trained may be adjusted to reduce the first loss information, thereby obtaining a trained model. As mentioned above, the first loss information may be a negative value. Reducing the first loss information may increase the similarity between the first target sample features in the positive sample feature set, and reduce a distance between the target sample feature of the sample token “how” and the target sample feature of the sample token “what”. Accordingly, a subsequent token determined by the model according to the feature of the sample token “how” is more likely to be consistent with a subsequent token determined by the model according to the feature of the sample token “what”.

According to embodiments of the present disclosure, the plurality of preceding sample data of the target sample data may be different. The large model may determine subsequent data based on preceding sample data in the input sequence. The first loss information may be determined according to the features of different preceding data of the target sample data that appears multiple times in the sample data sequence, and the model may be trained according to the first loss information. As a result, semantically similar content may be concentrated more closely in the feature space while fully utilizing contextual information inherent in the data sequence (e.g., a sentence) input into the model. By determining the loss based on the features of the data in the sequence, it is possible to achieve finer-grained semantic constraints, and reduce model overfitting and gradient oscillation. This improves training efficiency and model stability, achieves controllable regularization and efficient training optimization at the feature level, and significantly improves feature representation capability and downstream-task performance of the model. At the product level, the above method may be integrated into a pretraining workflow or a fine-tuning workflow, which may significantly improve generalization capability and task transfer performance of the model. Furthermore, without introducing additional inference costs, the method may significantly improve representation consistency and robustness of the model in tasks such as classification and retrieval.

Furthermore, according to embodiments of the present disclosure, the corresponding first loss information is determined according to the positive sample feature set for the target sample data. From the perspective of feature space separability, convergence of intra-class features is enhanced, and feature separability is enhanced, thereby accelerating the pretraining process and improving the generalization performance on downstream tasks. Accordingly, taking a sample data sequence obtained from sample text as an example, the trained model's capability to generate user-desired content based on text may be improved, thereby enhancing user experience.

It should be understood that the method of the present disclosure has been described above. The model to be trained according to the present disclosure will be further described below.

FIG. 2 is a schematic structural diagram of a model to be trained according to an embodiment of the present disclosure.

As shown in FIG. 2, the model to be trained may include a plurality of cascaded processing layers. The plurality of processing layers may include n processing layers, where n is an integer greater than 1. The n processing layers may include an embedding layer 201, one or more decoder layers 210, and a final layer normalization (LayerNorm) layer 202. That is, the n-th processing layer is the final layer normalization layer 202.

In some embodiments, the plurality of cascaded processing layers may sequentially determine a plurality of candidate sample feature sequences of the sample data sequence. The candidate sample feature sequence may include respective candidate sample features of the plurality of sample data. For example, the embedding layer 201 may determine a candidate sample feature sequence; the one or more decoder layers 210 may determine one or more candidate sample feature sequences; and the layer normalization layer 202 may determine a candidate sample feature sequence.

The target sample feature sequence may be one of the plurality of candidate sample feature sequences. For example, the target sample feature sequence may be the candidate sample feature sequence determined by the final layer normalization layer. As shown in FIG. 2, the candidate sample feature sequence determined by the layer normalization layer 202 may serve as the target sample feature sequence. According to embodiments of the present disclosure, using the feature sequence determined by the final layer normalization layer as the target sample feature sequence may improve the efficiency of model training, enhance the content generation capability of the large model, and improve user experience.

In some embodiments, in some implementations of operation S110 described above, the sample data sequence may be input into the model to be trained. As shown in FIG. 2, a sample text t200 may be input into the model to be trained. The sample text t200 may include a plurality of sample tokens. The plurality of sample tokens may include sample token T1, sample token T2, . . . , and sample token T16. The sample text t200 may be: “Here is a PDF file on how they are used and what they look like”. The sample token T1 may be “Here”; the sample token T2 may be “is”; . . . the sample token T16 may be “.”

As shown in FIG. 2, the plurality of processing layers of the model to be trained may determine a target sample feature sequence e200. The target sample feature sequence e200 may include target sample feature e1, target sample feature e2, . . . , and target sample feature e16. The target sample feature e1 may be a feature of the sample token T1; the target sample feature e2 may be a feature of the sample token T2; . . . the target sample feature e16 may be a feature of the sample token T16.

As shown in FIG. 2, the model to be trained may further include an output layer 203. The candidate sample feature sequence determined by the n-th processing layer may be input into the output layer 203, and an output result may be obtained.

It should be understood that the model to be trained according to the present disclosure has been described above. A feature-level loss according to the present disclosure will be further described below.

In some embodiments, after the target sample feature sequence is obtained, operation S120 described above may be performed to determine one or more first loss information for one or more target sample data.

A first similarity between any two first target sample features in the positive sample feature set for the target sample data may be determined, so as to obtain at least one first similarity. For example, a cosine similarity or an inner product between the sample token “what” and the sample token “how” may be determined as a first similarity.

The first loss information for the target sample data may be determined according to the at least one first similarity. For example, a single first similarity may be used as the first loss information. Alternatively, a sum of a plurality of first similarities may be used as the first loss information. For another example, a logarithmic function may be applied to process a sum of a plurality of first similarities to obtain the first loss information. According to embodiments of the present disclosure, the loss information is determined according to the similarity between different features in the positive sample feature set, enabling the model to effectively reduce a distance between the features belonging to the same class and reduce a distance between the features of positive samples. This improves intra-class compactness and inter-class margins for corresponding data (e.g., tokens) in classification tasks, thereby achieving stronger feature separability.

It should be understood that several methods for determining the first loss information according to the positive sample feature set have been described above. However, the present disclosure is not limited thereto. Another loss information for the target sample data may also be determined according to a negative sample feature set for the target sample data.

In some embodiments, the method 100 may further include: determining at least one second loss information for the at least one target sample data according to at least one negative sample feature set for the at least one target sample data.

The negative sample feature set for the target sample data includes a plurality of second target sample features other than the plurality of first target sample features among the plurality of target sample features. As described above, the sample token “they” may serve as the target sample data. The sample token “how” and the sample token “what” are respectively adjacent to the sample token “they” and are preceding tokens of the sample token “they”. The target sample features of tokens in the sample text t200 other than the sample token “how” and the sample token “what” may serve as the second target sample features. For example, the respective target sample features of the sample token “Here”, the sample token “is”, the sample token “a”, the sample token “PDF”, the sample token “file”, the sample token “on”, the sample token “are”, the sample token “used”, the sample token “and”, the sample token “look”, the sample token “like”, and the sample token “.” may serve as the second target sample features. A set including these second target sample features may serve as the negative sample feature set for the sample token “they”. It should be understood that the target sample feature of the sample token “they” itself may also be added to the negative sample feature set. According to embodiments of the present disclosure, by using the target sample features other than those included in the positive sample feature set as the negative sample feature set, it is possible to provide rich and effective constraints at the feature granularity for model training, which helps to fully improve model performance.

A second similarity between any two second target sample features in the negative sample feature set for the target sample data may be determined, so as to obtain at least one second similarity. For example, a cosine similarity or an inner product between the sample token “here” and the sample token “is” may be determined as the second similarity.

The second loss information for the target sample data may be determined according to the at least one second similarity. For example, a single second similarity may be used as the second loss information. Alternatively, a plurality of second similarities may be added together, and the resulting sum may be used as the second loss information. For another example, a logarithmic function may be applied to process a sum of the plurality of second similarities to obtain the second loss information. According to embodiments of the present disclosure, the loss information is determined according to the similarity between different features in the negative sample feature set, which enables the model to effectively increase the distance between the features of different classes and increase the distance between the features of negative samples. This further enhances intra-class compactness and inter-class margins of the corresponding data (such as tokens) in classification tasks, thereby achieving stronger feature separability.

Subsequently, operation S130 described above may be performed. In some implementations of operation S130 described above, at least one feature similarity loss information may be determined according to the at least one first loss information and the at least one second loss information, a target loss information may be determined according to the at least one feature similarity loss information, and the model to be trained may be trained according to the target loss information.

The feature similarity loss information for the target sample data may be obtained by subtracting the first loss information for the target sample data from the second loss information for the target sample data. A feature alignment loss information may be determined according to one or more feature similarity loss information. For example, the feature alignment loss information may be determined according to Equation (1).


LSimReg=Average[log ΣNiφ(el,ej)−log ΣPiφ(el′,ej′)]  (1)

where LSimReg represents a feature alignment loss information, Ni represents a negative sample feature set for an i-th target sample data, Pi represents a positive sample feature set for the i-th target sample data; the negative sample feature set includes, for example, N second target sample features; the positive sample feature set includes, for example, P first target sample features; N is an integer greater than 1, P is an integer greater than 1; l is an integer greater than or equal to 1 and less than or equal to N, j is an integer greater than or equal to 1 and less than or equal to N; l′ is an integer greater than or equal to 1 and less than or equal to P, and j′ is an integer greater than or equal to 1 and less than or equal to P.

Log represents a logarithmic function, for example, a base-2 logarithmic function; ΣNiφ(el, ej) represents a sum of one or more second similarities in the negative sample feature set Ni; ΣPiφ(el′, ej′) represents a sum of one or more first similarities in the positive sample feature set Pi; log ΣPiφ(el′, ej′) represents a first loss information, and log ΣNiφ(el, ej) represents a second loss information; log ΣNiφ(el, ej)−log ΣPiφ(el′, ej′) may represent a feature similarity loss information for the target sample data; Average [ ] represents an averaging function. In Equation (1), the averaging function is used to determine an average value of a plurality of feature similarity loss information for a plurality of target sample data in a training iteration, and the average value is used as the feature alignment loss information. It should be understood that, when the model is trained according to the first loss information and the second loss information, the first similarity may be used as the first loss information without multiplying the first similarity by a preset negative value. It should also be understood that determining the feature alignment loss information by averaging is merely an example. Other methods (such as weighted averaging or median calculation) may alternatively be used to determine the feature alignment loss information according to one or more feature similarity loss information.

The target loss information may be determined according to the feature alignment loss information. For example, a cross-entropy loss information may be determined according to an output result and a label of the sample data sequence, and the target loss information may be determined according to the cross-entropy loss information and the feature alignment loss information. According to embodiments of the present disclosure, the feature alignment loss information is determined according to the first loss information and the second loss information, achieving joint optimization of the first loss information and the second loss information. Accordingly, the distance between the negative samples may be maximized while the distance between the positive samples may be minimized, thereby fully enhancing intra-class compactness and inter-class margins of corresponding tokens in classification tasks, and ultimately achieving stronger feature separability.

The effect of training the model based on the feature alignment loss information will be described below with reference to FIG. 3. FIG. 3 is a schematic diagram illustrating the effect of the feature alignment loss information according to an embodiment of the present disclosure.

As shown in FIG. 3, the model to be trained may be trained according to the cross-entropy loss information until the cross-entropy loss information converges. A sample text t300 may be input into the model trained according to the cross-entropy loss information, and a similarity matrix SM30 for the sample text t300 may be obtained. The sample text t300 may be the sample text t200 described above. The similarity in the similarity matrix SM30 may be a cosine similarity between first sample features of two sample tokens in the sample text t300. For example, similarity sim301 may represent a similarity between the first sample feature of the sample token “what” and the first sample feature of the sample token “how”.

As shown in FIG. 3, the model to be trained may alternatively be trained according to both the cross-entropy loss information and the feature alignment loss information until both the cross-entropy loss information and the feature alignment loss information converge. The sample text t300 may be input into the model trained according to both the cross-entropy loss information and the feature alignment loss information, and a similarity matrix SM31 for the sample text t300 may be obtained. The similarity in the similarity matrix SM31 may be a cosine similarity between second sample features of two sample tokens in the sample text t300. For example, similarity sim311 may represent a similarity between the second sample feature of the sample token “what” and the second sample feature of the sample token “how”.

It should be understood that, in the two similarity matrices shown in FIG. 3, both row labels and column labels are obtained by shifting the sample tokens in the sample text t300 forward (toward the beginning of the sentence) by one position. For example, the plurality of row labels in the similarity matrix SM30 may sequentially be: “is”, “a”, “PDF”, “file”, “on”, “how”, “they”, “are”, “used”, “and”, “what”, “they”, “look”, “like”, and “.” Accordingly, a matrix element indicated jointly by the row label “they” and the column label “they” represents a similarity between the features of different preceding tokens (“how” and “what”) of the sample token “they”.

In the similarity matrix SM30, the discrimination between features of different semantics is poor. For example, similarity sim302 may represent a similarity between the first sample feature of the sample token “what” and the first sample feature of the sample token “on”. Both similarity sim302 and similarity sim301 are values greater than 0.5, indicating that the discrimination between the respective features of the sample token “what”, the sample token “how”, and the sample token “on” is insufficient.

After introduction of the feature similarity alignment loss information, the discrimination between the features of different semantics is significantly improved, and the features of the same semantics become more concentrated. For example, similarity sim312 may represent a similarity between the second sample feature of the sample token “what” and the second sample feature of the sample token “on”. Similarity sim312 is a value less than 0.5, while similarity sim311 is a value greater than 0.5, indicating that the distance between the feature of the sample token “what” and the feature of the sample token “on” has increased, and that the feature of the sample token “what” and the feature of the sample token “how” have become more concentrated.

It should be understood that as described above, the target loss information is determined based on the loss information determined from one of the plurality of candidate sample feature sequences. However, the present disclosure is not limited thereto. It is also possible to determine a loss information based on a plurality of candidate sample feature sequences to determine the target loss information, which will be described below.

In some embodiments, the method 100 may further include: determining a plurality of third loss information respectively for the plurality of sample data according to a plurality of candidate sample features for each of the plurality of sample data. The third loss information for the sample data is determined according to the similarity between the plurality of candidate sample features of the sample data. This will be described below with reference to FIG. 4.

FIG. 4 is a schematic diagram of a plurality of processing layers and an output layer according to an embodiment of the present disclosure.

As shown in FIG. 4, the plurality of processing layers include a first processing layer to an n-th processing layer. The first processing layer 401 may be the embedding layer 201 described above, the second processing layer 411 may be one of the one or more decoder layers 210 described above, and the n-th processing layer 402 may be the final layer normalization layer 202. The output layer 403 may be the output layer 203 described above. The first processing layer 401 may determine a candidate sample feature sequence e401 according to a sample text t400. The second processing layer 411 may determine a candidate sample feature sequence e411 according to the candidate sample feature sequence e401. The n-th processing layer 402 may determine a candidate sample feature sequence e402. That is, any processing layer from the second processing layer to the n-th processing layer may determine the candidate sample feature sequence of the current processing layer according to the candidate sample feature sequence determined by a preceding processing layer. It should be understood that the sample text t400 may be the sample text t200 described above.

The candidate sample feature sequence e401 may include the respective candidate sample features of the plurality of sample tokens in the sample text t400 determined by the first processing layer. The candidate sample feature sequence e411 may include the respective candidate sample features of the plurality of sample tokens determined by the second processing layer. The candidate sample feature sequence e402 may include the respective candidate sample features of the plurality of sample tokens determined by the n-th processing layer.

In some embodiments, the third loss information for the sample data is determined according to the similarity between the plurality of candidate sample features of the sample data through the following operations: determining an m-th intermediate loss information according to n-m third similarities between the candidate sample feature determined by an m-th processing layer among the n processing layers and n-m subsequent sample features, where m is an integer greater than or equal to 1 and less than n, and the n-m subsequent sample features are n-m candidate sample features determined by the n-m processing layers subsequent to the m-th processing layer; and determining the third loss information for the sample data according to a first intermediate loss information to an (n−1)-th intermediate loss information.

For example, taking the sample token “Here” as an example and assuming m=1, the candidate sample feature sequence e401 may include the candidate sample feature of the sample token “Here” determined by the first processing layer. When m=1, the candidate sample feature of the sample token “Here” in the candidate sample feature sequence e411, . . . , and the candidate sample feature of the sample token “Here” in the candidate sample feature sequence e402 may serve as subsequent sample features of the candidate sample feature of the sample token “Here” determined by the first processing layer.

The n-m third similarities between the candidate sample feature determined by the m-th processing layer and the n-m subsequent sample features may be determined. For the candidate sample feature determined by the m-th processing layer, n-m intermediate loss sub-information may be obtained by subtracting the n-m third similarities respectively from a preset value. A sum of the n-m intermediate loss sub-information may be used as the m-th intermediate loss information. The n−1 intermediate loss information may be added together to obtain the third loss information for the sample data. The preset value may be 1.

An inter-layer similarity loss information may be determined according to the plurality of third loss information respectively for the plurality of sample data. For example, an expected value of the plurality of third loss information may be determined. The inter-layer similarity loss information LSimLayer may be determined according to Equation (2).

L SimLayer = E [ ∑ m = 1 n - 1 ⁢ ∑ k = m + 1 n ⁢ ( 1 - ϕ ⁡ ( e m , e k ) ) ] ( 2 )

where φ(em, ek) represents a feature similarity between a candidate sample feature em determined by the m-th processing layer and a candidate sample feature ek determined by the k-th processing layer, and k is an integer greater than or equal to m+1 and less than or equal to n; 1−φ(em, ek) represents an intermediate loss sub-information;

∑ k = m + 1 n ⁢ ( 1 - ϕ ⁡ ( e m , e k ) )

represents an m-th intermediate loss information;

∑ m = 1 n - 1 ⁢ ∑ k = m + 1 n ⁢ ( 1 - ϕ ⁡ ( e m , e k ) )

represents a third loss information for the sample data; and E[ ] represents an expectation function. In Equation (2), the expectation function is used to determine an expected value of one or more third loss information, and the expected value is used as the inter-layer similarity loss information. It should be understood that determining an expected value of one or more third loss information is merely an example. It is also possible to determine an average value of one or more third loss information as the inter-layer similarity loss information.

According to embodiments of the present disclosure, since the large model is a deep language model, the feature representation at each layer does not exist independently, but progressively evolve from local patterns in shallow layers to semantic features in deep layers. The features formed by each token during the entire forward propagation process of the model should exhibit a continuous, stable, and semantically consistent structure across different layers, and should gradually converge toward its final label semantics. Since each token may be associated with a corresponding label from the input stage, the token should maintain a semantically related feature direction and intra-class consistency across the shallow layers, middle layers, and deep layers. If cross-layer features shift or become inconsistent between layers during the evolution process, deep-layer features may fail to converge effectively, which disrupts the continuity of feature representations. By determining the inter-layer similarity loss information, the features of the same token at different network layers may be aligned such that the features exhibit an evolutionary trajectory in the feature space that progressively develops across layers without losing semantic attributes. By imposing consistency constraints on cross-layer features, stability of internal representations within the network may be effectively enhanced, thereby accelerating model training and significantly improving reliability of feature representations. As a result, the content generated by the model according to user input may exhibit a higher correlation with the user input, thereby effectively enhancing user experience.

It should be understood that the methods for determining the inter-layer similarity loss information have been described above. Several methods for training the model to be trained will be described below.

FIG. 5 is a schematic diagram illustrating a principle of model training according to an embodiment of the present disclosure.

As shown in FIG. 5, a sample data sequence 500 may be input into a model to be trained and processed by a plurality of processing layers P50 of the model to be trained, so as to obtain a plurality of candidate sample feature sequences sequentially determined by the plurality of processing layers. The plurality of processing layers P50 may include the embedding layer, the decoder layer(s), and the final layer normalization layer described above. Among the plurality of candidate sample feature sequences, the candidate sample feature sequence determined by the final layer normalization layer may serve as a target sample feature sequence e502. The sample data sequence 500 may be the sample text 200 described above and may include the sample token “they” serving as the target sample data.

At least one first loss information for at least one target sample data may be determined according to at least one positive sample feature set for the at least one target sample data. At least one second loss information for the at least one target sample data may be determined according to at least one negative sample feature set for the at least one target sample data. At least one feature similarity loss information L51 for the at least one target sample data may be determined according to the at least one first loss information and the at least one second loss information. A feature alignment loss information may be determined according to the at least one feature similarity loss information. It should be understood that the method for determining the feature alignment loss information may refer to the description of Equation (1) above and will not be repeated herein. Subsequently, the target loss information may be determined according to the feature alignment loss information, which will be described in detail below.

The candidate sample feature sequence includes the respective candidate sample features of the plurality of sample data in the sample data sequence. According to a plurality of candidate sample features for each of the plurality of sample data, an inter-layer similarity loss information L52 may be determined. It should be understood that the method for determining the inter-layer similarity loss information may refer to the description of Equation (2) above and will not be repeated herein.

In some embodiments, an output result of the model to be trained may be determined according to the target sample feature sequence. A cross-entropy loss information may be determined according to a label of the sample data sequence and the output result of the model to be trained. Weighted fusion may be performed on the cross-entropy loss information, the plurality of third loss information, and the at least one feature similarity loss information. During a training stage, the label of the sample data sequence may be the sample data sequence itself.

As shown in FIG. 5, the target sample feature sequence e502 is processed by an output layer 503 of the model to be trained, so as to obtain an output result o500. A cross-entropy loss information L53 may be determined according to the output result o500 and the sample data sequence 500. The target loss information may be obtained by performing weighted fusion on the cross-entropy loss information, the inter-layer loss information determined according to the plurality of third loss information, and the feature alignment loss information determined according to the at least one feature similarity loss information. For example, the target loss information LTotal may be determined according to Equation (3).


LTotal=LcrossEntropy+αLSimReg+βLSimLayer  (3)

where LcrossEntropy represents a cross-entropy loss information; LSimReg represents a feature alignment loss information; LSimLayer represents an inter-layer loss information; α may be a weight of the feature alignment loss information and may be a value greater than or equal to 0 and less than or equal to 1; and β may be a weight of the inter-layer loss information and may be a value greater than or equal to 0 and less than or equal to 1. In an example: α=β=1

The parameters of the plurality of processing layers may be adjusted according to the target loss information. The parameters of the output layer may be adjusted according to the cross-entropy loss information. According to embodiments of the present disclosure, the cross-entropy loss information may improve fundamental correctness of the language model on word prediction tasks and serves as an important supervisory signal throughout the entire training process. The feature alignment loss information imposes aggregation constraints on features of tokens belonging to the same class, thereby enhancing intra-class compactness and inter-class separability, and strengthening token-level semantic representation capability. The inter-layer similarity loss information may constrain the features of the same token across different processing layers to maintain consistent semantic directions, such that the representations are more stable, continuous, and structured during the layer-wise evolution, thereby preventing deep-layer features from deviating from their label semantics.

It should be understood that the present disclosure has been described above using examples in which the model to be trained is trained according to the first loss information and the second loss information, and examples in which the model to be trained is trained according to the first loss information, the second loss information, and the third loss information. However, the present disclosure is not limited thereto. In some embodiments, training the model to be trained according to the at least one first loss information may include: determining the target loss information according to the at least one first loss information and at least one of the at least one second loss information and the plurality of third loss information; and training the model to be trained according to the target loss information. That is, the model to be trained may alternatively be trained according to the first loss information and the third loss information. For example, when the model to be trained is trained according to the first loss information and the third loss information, the first loss information may be a negative value. It is possible to perform weighted fusion on the first loss information and the inter-layer loss information determined according to the plurality of third loss information so as to obtain the target loss information, which is used to train the model to be trained.

It should be understood that the present disclosure has been described above using examples in which the sample data sequence is a sample text. However, the present disclosure is not limited thereto. The sample data sequence may be obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

In some embodiments, a sample image may be divided into a plurality of sample image patches. A sample image patch sequence may be obtained according to the plurality of sample image patches and may serve as the sample data sequence. For example, the sample image may be divided into a 4×4 sample image patch array. Each row of the image patch array includes four sample image patches. The four rows of image patches may be sequentially concatenated to obtain a 1×16 sample image patch sequence, which serves as the sample data sequence. For any two sample image patches other than a first sample image patch, an image similarity between the two sample image patches may be determined. If the image similarity between two image patches is greater than a preset image similarity threshold, one of the two image patches may be selected as a target image patch. Two preceding image patches adjacent to the two image patches in the sample image patch sequence may be identified. Target image features of the two preceding image patches may serve as first target image features directed to the target image patch and may be added to a positive sample feature set for the target image patch. Image features other than the target image features of the two preceding image patches may serve as second target image features directed to the target image patch and may be added to a negative sample feature set for the target image patch. The preset image similarity threshold may be a value greater than 0.9 and less than or equal to 1.

In some embodiments, a sample audio may be converted into a sample audio sequence including a plurality of discrete sample audio segments, and the sample audio sequence may serve as the sample data sequence. An audio segment similarity (e.g., cosine similarity) between any two sample audio segments among the plurality of sample audio segments may be determined. If a similarity between two sample audio segments is greater than or equal to a preset audio segment similarity threshold, one of the two sample audio segments may be selected as a target audio segment. Two preceding audio segments adjacent to the two sample audio segments in the sample audio segment sequence may be identified. Target audio features of the two preceding audio segments may serve as first target audio features directed to the target audio segment and may be added to a positive sample feature set for the target audio segment. Audio features other than the target audio features of the two preceding audio segments may serve as second target audio features directed to the target audio segment and may be added to a negative sample feature set for the target audio segment.

In some embodiments, a sample video may be frame-sampled to obtain a plurality of video frames. Since video frames are image data, the video frames may be processed with reference to the processing method for the sample image described above, so as to obtain an image patch sequence for each video frame. A plurality of image patch sequences may be concatenated to obtain a video image patch sequence, which serves as the sample data sequence. It should be understood that the method for determining the target sample data, positive sample feature set, and negative sample feature set in the video image patch sequence is identical or similar to the method for determining the target sample data, positive sample feature set, and negative sample feature set in the sample image patch sequence, and thus will not be repeated herein.

It should be understood that the training method according to the present disclosure has been described above. An inference method of the model will be described below.

FIG. 6 is a schematic flowchart of an inference method according to an embodiment of the present disclosure.

As shown in FIG. 6, a method 600 may include operation S610.

In operation S610, a data sequence to be processed is input into a target model to obtain a response result.

The target model may be trained according to the method provided in the present disclosure. For example, the target model may be trained according to the method 100.

The data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, or a video to be processed.

It should be understood that the methods according to the present disclosure have been described above. Apparatuses according to the present disclosure will be described below.

FIG. 7 is a block diagram of a model training apparatus according to an embodiment of the present disclosure.

As shown in FIG. 7, an apparatus 700 may include a first obtaining module 710, a first determination module 720, and a training module 730.

The first obtaining module 710 is configured to input a sample data sequence into a model to be trained to obtain a target sample feature sequence. The sample data sequence includes a plurality of sample data, and the target sample feature sequence includes respective target sample features of the plurality of sample data.

The first determination module 720 is configured to determine at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data. The target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data, and the positive sample feature set for the target sample data includes the respective target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features.

The training module 730 is configured to train the model to be trained according to the at least one first loss information. The sample data sequence is obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

In some embodiments, the model to be trained includes a plurality of cascaded processing layers, the target sample feature sequence is one of a plurality of candidate sample feature sequences sequentially determined by the plurality of processing layers, and the candidate sample feature sequence includes respective candidate sample features of the plurality of sample data. The apparatus may further include at least one of: a second determination module configured to determine at least one second loss information for the at least one target sample data according to at least one negative sample feature set for the at least one target sample data, where the negative sample feature set for the target sample data includes a plurality of second target sample features other than the plurality of first target sample features among the plurality of target sample features; and a third determination module configured to determine a plurality of third loss information respectively for the plurality of sample data according to a plurality of candidate sample features for each of the plurality of sample data.

In some embodiments, the training module includes: a first determination submodule configured to determine a target loss information according to the at least one first loss information and at least one of the at least one second loss information and the plurality of third loss information; and a training submodule configured to train the model to be trained according to the target loss information, where the third loss information for the sample data is determined according to a similarity between the plurality of candidate sample features of the sample data.

In some embodiments, the first determination module includes: a second determination submodule configured to determine a first similarity between any two first target sample features in the positive sample feature set for the target sample data, so as to obtain at least one first similarity; and a third determination submodule configured to determine the first loss information for the target sample data according to the at least one first similarity.

In some embodiments, the second determination module includes: a fourth determination submodule configured to determine a second similarity between any two second target sample features in the negative sample feature set for the target sample data, so as to obtain at least one second similarity; and a fifth determination submodule configured to determine the second loss information for the target sample data according to the at least one second similarity.

In some embodiments, the plurality of processing layers include n processing layers, where n is an integer greater than 1. The third loss information for the sample data is determined according to the similarity between the plurality of candidate sample features of the sample data through operations performed by the following submodules: a sixth determination submodule configured to determine an m-th intermediate loss information according to n-m third similarities between the candidate sample feature determined by an m-th processing layer among the n processing layers and n-m subsequent sample features, where m is an integer greater than or equal to 1 and less than n, and the n-m subsequent sample features are n-m candidate sample features determined by n-m processing layers subsequent to the m-th processing layer; and a seventh determination submodule configured to determine the third loss information for the sample data according to a first intermediate loss information to an (n−1)-th intermediate loss information.

In some embodiments, the first determination submodule includes: a first determination unit configured to determine at least one feature similarity loss information for the at least one target sample data according to the at least one first loss information and the at least one second loss information; and a second determination unit configured to determine the target loss information according to the at least one feature similarity loss information.

In some embodiments, the first determination unit includes: a subtraction operation subunit configured to subtract the first loss information for the target sample data from the second loss information for the target sample data to obtain the feature similarity loss information for the target sample data.

In some embodiments, the second determination unit includes: a first determination subunit configured to determine an output result of the model to be trained according to the target sample feature sequence; a second determination subunit configured to determine a cross-entropy loss information according to a label of the sample data sequence and the output result of the model to be trained; and a fusion subunit configured to perform weighted fusion on the cross-entropy loss information, the plurality of third loss information, and the at least one feature similarity loss information to obtain the target loss information.

In some embodiments, the n-th processing layer is a final layer normalization layer of the model to be trained, and the target sample feature sequence is the candidate sample feature sequence determined by the n-th processing layer.

FIG. 8 is a block diagram of an inference apparatus according to another embodiment of the present disclosure.

As shown in FIG. 8, an apparatus 800 may include a second obtaining module 810.

The second obtaining module 810 is configured to input a data sequence to be processed into a target model to obtain a response result, where the target model is trained according to the model training apparatus provided in the present disclosure, and the data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, and a video to be processed.

In the technical solutions of the present disclosure, the collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved are all in compliance with relevant laws and regulations and do not violate public order and good morals.

According to embodiments of the present disclosure, the present disclosure further provides an electronic device, a readable storage medium, and a computer program product.

FIG. 9 shows a schematic block diagram of an exemplary electronic device 900 that may be used to implement embodiments of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as a laptop computer, a desktop computer, a workstation, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device may further represent various forms of mobile devices, such as a personal digital assistant, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components as illustrated herein, and connections, relationships, and functions thereof are merely examples, and are not intended to limit the implementation of the present disclosure described and/or required herein.

As shown in FIG. 9, the electronic device 900 includes a computing unit 901 which may perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data necessary for an operation of the electronic device 900 may also be stored. The computing unit 901, the ROM 902 and the RAM 903 are connected to each other through a bus 904. An input/output (I/O) interface 905 is also connected to the bus 904.

A plurality of components in the electronic device 900 are connected to the input/output (I/O) interface 905, including: an input unit 906, such as a keyboard, or a mouse; an output unit 907, such as displays or speakers of various types; a storage unit 908, such as a disk, or an optical disc; and a communication unit 909, such as a network card, a modem, or a wireless communication transceiver. The communication unit 909 allows the electronic device 900 to exchange information/data with other devices through a computer network such as Internet and/or various telecommunication networks.

The computing unit 901 may be various general-purpose and/or dedicated processing assemblies having processing and computing capabilities. Some examples of the computing units 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 901 executes various methods and processes described above, such as at least one of the model training method and the inference method. For example, in some embodiments, at least one of the model training method and the inference method may be implemented as a computer software program which is tangibly embodied in a machine-readable medium, such as the storage unit 908. In some embodiments, the computer program may be partially or entirely loaded and/or installed in the electronic device 900 via the ROM 902 and/or the communication unit 909. The computer program, when loaded in the RAM 903 and executed by the computing unit 901, may execute one or more steps in at least one of the model training method and the inference method described above. Alternatively, in other embodiments, the computing unit 901 may be used to perform at least one of the model training method and the inference method by any other suitable means (e.g., by means of firmware).

Various embodiments of the systems and technologies described herein may be implemented in a digital electronic circuit system, an integrated circuit system, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), an application specific standard product (ASSP), a system on chip (SOC), a complex programmable logic device (CPLD), a computer hardware, firmware, software, and/or combinations thereof. These various embodiments may be implemented by one or more computer programs executable and/or interpretable on a programmable system including at least one programmable processor. The programmable processor may be a dedicated or general-purpose programmable processor, which may receive data and instructions from a storage system, at least one input device and at least one output device, and may transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.

Program codes for implementing the data processing method of the present disclosure may be written in one programming language or any combination of more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a dedicated computer or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowcharts and/or block diagrams to be implemented. The program codes may be executed entirely on a machine, partially on a machine, partially on a machine and partially on a remote machine as a stand-alone software package or entirely on a remote machine or server.

In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with an instruction execution system, an apparatus or a device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any suitable combination of the above. More specific examples of the machine-readable storage medium may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory, a read only memory, an erasable programmable read-only memory (EPROM) or a flash memory, an optical fiber, a compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

In order to provide interaction with the user, the systems and technologies described here may be implemented on a computer including a display device (for example, a cathode ray tube (CRT) or liquid crystal display (LCD)) for displaying information to the user, and a keyboard and a pointing device (for example, a mouse or a trackball) through which the user may provide the input to the computer. Other types of devices may also be used to provide interaction with the user. For example, a feedback provided to the user may be any form of sensory feedback (for example, visual feedback, auditory feedback, or tactile feedback), and the input from the user may be received in any form (including acoustic input, voice input or tactile input).

The systems and technologies described herein may be implemented in a computing system including back-end components (for example, a data server), or a computing system including middleware components (for example, an application server), or a computing system including front-end components (for example, a user computer having a graphical user interface or web browser through which the user may interact with the implementation of the system and technology described herein), or a computing system including any combination of such back-end components, middleware components or front-end components. The components of the system may be connected to each other by digital data communication (for example, a communication network) in any form or through any medium. Examples of the communication network include a local area network (LAN), a wide area network (WAN), and the Internet.

The computer system may include a client and a server. The client and the server are generally far away from each other and usually interact through a communication network. A relationship between the client and the server is generated through computer programs running on the corresponding computers and having a client-server relationship with each other.

It should be understood that steps of the processes illustrated above may be reordered, added or deleted in various manners. For example, the steps described in the present disclosure may be performed in parallel, sequentially, or in a different order, as long as a desired result of the technical solution of the present disclosure may be achieved. This is not limited in the present disclosure.

The above-mentioned specific embodiments do not constitute a limitation on the scope of protection of the present disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions may be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present disclosure shall be contained in the scope of protection of the present disclosure.

Claims

1. A model training method, comprising:

inputting a sample data sequence into a model to be trained to obtain a target sample feature sequence, wherein the sample data sequence comprises a plurality of sample data, and the target sample feature sequence comprises respective target sample features of the plurality of sample data;
determining at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data, wherein the target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data, and the positive sample feature set for the target sample data comprises respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features; and
training the model to be trained according to the at least one first loss information, wherein the sample data sequence is obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

2. The method of claim 1, wherein the model to be trained comprises a plurality of cascaded processing layers, the target sample feature sequence is one of a plurality of candidate sample feature sequences sequentially determined by the plurality of processing layers, and the candidate sample feature sequence comprises respective candidate sample features of the plurality of sample data, and

the method further comprises at least one of:
determining at least one second loss information for the at least one target sample data according to at least one negative sample feature set for the at least one target sample data, wherein the negative sample feature set for the target sample data comprises a plurality of second target sample features other than the plurality of first target sample features among the plurality of target sample features; and
determining a plurality of third loss information respectively for the plurality of sample data according to a plurality of candidate sample features for each of the plurality of sample data.

3. The method of claim 2, wherein the training the model to be trained according to the at least one first loss information comprises:

determining a target loss information according to the at least one first loss information and at least one of the at least one second loss information and the plurality of third loss information; and
training the model to be trained according to the target loss information, wherein the third loss information for the sample data is determined according to a similarity between the plurality of candidate sample features of the sample data.

4. The method of claim 1, wherein the determining at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data comprises:

determining a first similarity between two first target sample features in the positive sample feature set for the target sample data, so as to obtain at least one first similarity; and
determining the first loss information for the target sample data according to the at least one first similarity.

5. The method of claim 2, wherein the determining at least one second loss information for the at least one target sample data according to at least one negative sample feature set for the at least one target sample data comprises:

determining a second similarity between two second target sample features in the negative sample feature set for the target sample data, so as to obtain at least one second similarity; and
determining the second loss information for the target sample data according to the at least one second similarity.

6. The method of claim 3, wherein the plurality of processing layers comprise n processing layers, n being an integer greater than 1, and

the third loss information for the sample data is determined according to the similarity between the plurality of candidate sample features of the sample data by:
determining an m-th intermediate loss information according to n-m third similarities between the candidate sample feature determined by an m-th processing layer among the n processing layers and n-m subsequent sample features, wherein m is an integer greater than or equal to 1 and less than n, and the n-m subsequent sample features are n-m candidate sample features determined by n-m processing layers subsequent to the m-th processing layer; and
determining the third loss information for the sample data according to a first intermediate loss information to an (n−1)-th intermediate loss information.

7. The method of claim 5, wherein the determining a target loss information according to the at least one first loss information and at least one of the at least one second loss information and the plurality of third loss information comprises:

determining at least one feature similarity loss information for the at least one target sample data according to the at least one first loss information and the at least one second loss information; and
determining the target loss information according to the at least one feature similarity loss information.

8. The method of claim 7, wherein the determining at least one feature similarity loss information for the at least one target sample data according to the at least one first loss information and the at least one second loss information comprises:

subtracting the first loss information for the target sample data from the second loss information for the target sample data to obtain the feature similarity loss information for the target sample data.

9. The method of claim 7, wherein the determining the target loss information according to the at least one feature similarity loss information comprises:

determining an output result of the model to be trained according to the target sample feature sequence;
determining a cross-entropy loss information according to a label of the sample data sequence and the output result of the model to be trained; and
performing weighted fusion on the cross-entropy loss information, the plurality of third loss information, and the at least one feature similarity loss information to obtain the target loss information.

10. The method of claim 6, wherein the n-th processing layer is a final layer normalization layer of the model to be trained, and the target sample feature sequence is the candidate sample feature sequence determined by the n-th processing layer.

11. An inference method, comprising:

inputting a data sequence to be processed into a target model to obtain a response result, wherein the target model is trained according to the method of claim 1, and the data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, or a video to be processed.

12. An electronic device, comprising:

at least one processor; and
a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are configured to, when executed by the at least one processor, cause the at least one processor to:
input a sample data sequence into a model to be trained to obtain a target sample feature sequence, wherein the sample data sequence comprises a plurality of sample data, and the target sample feature sequence comprises respective target sample features of the plurality of sample data;
determine at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data, wherein the target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data, and the positive sample feature set for the target sample data comprises respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features; and
train the model to be trained according to the at least one first loss information, wherein the sample data sequence is obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

13. The electronic device of claim 12, wherein the model to be trained comprises a plurality of cascaded processing layers, the target sample feature sequence is one of a plurality of candidate sample feature sequences sequentially determined by the plurality of processing layers, and the candidate sample feature sequence comprises respective candidate sample features of the plurality of sample data, and

the at least one processor is further configured to perform at least one of:
determining at least one second loss information for the at least one target sample data according to at least one negative sample feature set for the at least one target sample data, wherein the negative sample feature set for the target sample data comprises a plurality of second target sample features other than the plurality of first target sample features among the plurality of target sample features; and
determining a plurality of third loss information respectively for the plurality of sample data according to a plurality of candidate sample features for each of the plurality of sample data.

14. The electronic device of claim 13, wherein the at least one processor is further configured to:

determine a target loss information according to the at least one first loss information and at least one of the at least one second loss information and the plurality of third loss information; and
train the model to be trained according to the target loss information, wherein the third loss information for the sample data is determined according to a similarity between the plurality of candidate sample features of the sample data.

15. The electronic device of claim 12, wherein the at least one processor is further configured to:

determine a first similarity between two first target sample features in the positive sample feature set for the target sample data, so as to obtain at least one first similarity; and
determine the first loss information for the target sample data according to the at least one first similarity.

16. The electronic device of claim 13, wherein the at least one processor is further configured to:

determine a second similarity between two second target sample features in the negative sample feature set for the target sample data, so as to obtain at least one second similarity; and
determine the second loss information for the target sample data according to the at least one second similarity.

17. The electronic device of claim 14, wherein the plurality of processing layers comprise n processing layers, n being an integer greater than 1, and

the third loss information for the sample data is determined according to the similarity between the plurality of candidate sample features of the sample data by:
determining an m-th intermediate loss information according to n-m third similarities between the candidate sample feature determined by an m-th processing layer among the n processing layers and n-m subsequent sample features, wherein m is an integer greater than or equal to 1 and less than n, and the n-m subsequent sample features are n-m candidate sample features determined by n-m processing layers subsequent to the m-th processing layer; and
determining the third loss information for the sample data according to a first intermediate loss information to an (n−1)-th intermediate loss information.

18. An electronic device, comprising:

at least one processor; and
a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are configured to, when executed by the at least one processor, cause the at least one processor to:
input a data sequence to be processed into a target model to obtain a response result, wherein the target model is trained according to the electronic device of claim 12, and the data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, or a video to be processed.

19. A non-transitory computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, are configured to cause a computer to:

input a sample data sequence into a model to be trained to obtain a target sample feature sequence, wherein the sample data sequence comprises a plurality of sample data, and the target sample feature sequence comprises respective target sample features of the plurality of sample data;
determine at least one first loss information for at least one target sample data according to at least one positive sample feature set for the at least one target sample data, wherein the target sample data is determined according to at least two sample data having a data similarity greater than or equal to a preset data similarity threshold among the plurality of sample data, and the positive sample feature set for the target sample data comprises respective first target sample features of a plurality of preceding sample data of the target sample data among the plurality of target sample features; and
train the model to be trained according to the at least one first loss information, wherein the sample data sequence is obtained according to at least one of a sample text, a sample image, a sample audio, or a sample video.

20. A non-transitory computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, are configured to cause a computer to:

input a data sequence to be processed into a target model to obtain a response result, wherein the target model is trained according to the storage medium of claim 19, and the data sequence to be processed is obtained according to at least one of a text to be processed, an image to be processed, an audio to be processed, or a video to be processed.
Patent History
Publication number: 20260377769
Type: Application
Filed: Jul 28, 2026
Publication Date: Nov 26, 2026
Inventors: Dianhai YU (Beijing), Yan SUN (Beijing), Guoxia WANG (Beijing), Jiabin YANG (Beijing), Jinle ZENG (Beijing), Haifeng WANG (Beijing)
Application Number: 19/756,635
Classifications
International Classification: G06N 20/00 (20190101); G06N 5/04 (20230101);