Text processing method, model training method and system
By performing client-side clustering and global model parameter generation based on model gradient similarity in federated learning, the performance degradation caused by heterogeneity is resolved, resulting in better natural language processing performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ALIBABA (CHINA) CO LTD
- Filing Date
- 2022-12-05
- Publication Date
- 2026-07-14
Smart Images

Figure CN116245086B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing, and more specifically, to a text processing method, a model training method, and a system. Background Technology
[0002] Federated learning is a paradigm that can train data from multiple sources while protecting data privacy, and it has been widely applied in fields such as finance, healthcare, and natural sciences. In the federated learning process, each client uses its local data for local concatenation and uploads the updated model parameters to the server. The server then performs federated aggregation of these model parameters to update the global model, and finally sends the new model parameters to the clients.
[0003] However, in heterogeneous scenarios, when there are heterogeneities between different clients participating in federated learning, that is, when there are significant differences in data domains, task types, model architectures, etc. among different clients participating in federated learning, simply jointly training these clients will produce serious gradient update conflicts and damage the model performance of each client, which greatly limits the application of federated learning.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This application provides a text processing method, a model training method, and a system to at least address the technical problem that federated learning has a significant impact on the model performance of clients in heterogeneous scenarios, thus limiting the application of federated learning.
[0006] According to one aspect of the embodiments of this application, a text processing method is provided, comprising: a target client acquiring text data to be processed; the target client performing natural language processing on the text data to be processed using a text processing model to obtain a text processing result of the text data to be processed; wherein, the text processing model is deployed locally on the target client, the model parameters of the text processing model are target model parameters sent by the server, and the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client.
[0007] According to another aspect of the embodiments of this application, a model training method is also provided, comprising: a target client receiving original model parameters corresponding to the target client sent by a server; the target client training a locally deployed processing model using locally stored training samples and the corresponding original model parameters to obtain a first model gradient corresponding to the target client; the target client sending the first model gradient corresponding to the target client to the server and receiving target model parameters corresponding to the target client sent by the server, wherein the target model parameters are obtained by aggregating the original model parameters and the first model gradient uploaded by the first client; and the target client updating the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client to obtain a text processing model, wherein the text processing model is used for natural language processing of the text data to be processed.
[0008] According to another aspect of the embodiments of this application, a model training method is also provided, comprising: a server sending original model parameters corresponding to multiple clients to multiple clients, and receiving first model gradients uploaded by multiple clients; the server aggregating the first model gradients uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain target model parameters corresponding to each client; the server sending the target model parameters corresponding to multiple clients to multiple clients, wherein the target model parameters are used to update the model parameters of the locally deployed processing model.
[0009] According to another aspect of the embodiments of this application, a model training system is also provided, including: multiple clients; a server connected to the multiple clients, used to generate original model parameters corresponding to the multiple clients to the multiple clients; the multiple clients are used to train a locally deployed processing model using locally stored training text and corresponding original model parameters to obtain a first model gradient corresponding to the multiple clients; the server is also used to cluster the multiple clients based on the first model gradient corresponding to the multiple clients to obtain a first client corresponding to each client, and to aggregate the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain target model parameters corresponding to each client; the multiple clients are also used to update the model parameters of the locally deployed processing model based on the corresponding target model parameters.
[0010] According to another aspect of the embodiments of this application, an image processing method is also provided, comprising: a target client acquiring an image to be processed; the target client using an image processing model to process the image to be processed, thereby obtaining an image processing result of the image to be processed; wherein, the image processing model is deployed locally on the target client, the model parameters of the image processing model are target model parameters sent by the server, the target model parameters are obtained by the server aggregating the original model parameters corresponding to the target client based on the first model gradient uploaded by the first client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
[0011] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein, when the program is running, it controls the device where the computer-readable storage medium is located to execute any of the text processing methods in the above embodiments.
[0012] According to another aspect of the embodiments of this application, a computer terminal is also provided, including: a memory storing an executable program; and a processor for running the program, wherein the program executes any of the text processing methods described in the above embodiments when it runs.
[0013] In this embodiment, the server clusters at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client to obtain a first client. The server aggregates the first model gradient uploaded by the first client and the original model parameters corresponding to the target client to obtain template model parameters. The server sends the target model parameters to the target client as model parameters for the text processing model to train the text processing model. Then, during the model inference process, the target client obtains the text data to be processed and uses the text processing model to perform natural language processing on the text data to obtain the text processing result. It is worth noting that a unique global model is set for different clients, that is, unique original model parameters are given to different clients, and the model parameters are aggregated based on the similar client set of different clients to achieve the purpose of federated learning. On the one hand, it improves the correlation between different clients and ensures the accuracy of the processing results. On the other hand, it also improves the personalization of each client, making federated learning more flexible in natural language processing and achieving better federated learning results. This solves the technical problem that federated learning has a large impact on the model performance of clients in heterogeneous scenarios, which limits the application of federated learning.
[0014] It is worth noting that the general description above and the detailed description that follow are merely for illustrative purposes and do not constitute a limitation on this application. Attached Figure Description
[0015] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0016] Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a text processing method is shown.
[0017] Figure 2 This is a structural block diagram of a computing environment for a text processing method according to an embodiment of this application;
[0018] Figure 3 This is a flowchart of a text processing method according to Embodiment 1 of this application;
[0019] Figure 4 This is a schematic diagram of a clustering federated learning framework according to Embodiment 1 of this application;
[0020] Figure 5 This is a schematic diagram of a cluster contrastive learning framework according to Embodiment 1 of this application;
[0021] Figure 6 This is a flowchart of a model training method according to Embodiment 2 of this application;
[0022] Figure 7 This is a flowchart of a model training method according to Embodiment 3 of this application;
[0023] Figure 8 This is a structural block diagram of a model training system according to Embodiment 4 of this application;
[0024] Figure 9 This is a flowchart of an image processing method according to Embodiment 5 of this application;
[0025] Figure 10 This is a schematic diagram of a model training device according to Embodiment 6 of this application;
[0026] Figure 11 This is a schematic diagram of a model training device according to Embodiment 7 of this application;
[0027] Figure 12 This is a schematic diagram of a model training device according to Embodiment 8 of this application;
[0028] Figure 13This is a schematic diagram of an image processing apparatus according to Embodiment 9 of this application;
[0029] Figure 14 This is a structural block diagram of a computer terminal according to Embodiment 10 of this application. Detailed Implementation
[0030] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0033] Natural Language Processing (NLP) refers to the research field that processes natural text, such as classifying text sentiment, finding answers to questions in documents, and generating news summaries.
[0034] Contrastive learning: a self-supervised training algorithm that constructs positive and negative samples and a contrastive loss to enable the model to better distinguish the characteristics of positive and negative samples, thereby improving the model's expressive power and task performance.
[0035] Clustering: The process of dividing multiple clients into multiple classes composed of similar clients.
[0036] Aggregation: It can generate a single model parameter based on multiple different model parameters.
[0037] Encoder: can be a structure in a neural network model used to map raw data, such as images or text, into hidden layers.
[0038] Decoder: can be a structure in a neural network model used to map hidden layers into reconstructed data.
[0039] Model gradient: can be the direction of updating model parameters.
[0040] Currently, with the gradual introduction of data protection laws and regulations, the privacy protection of users' local data is receiving increasing attention. Federated learning, as a privacy-preserving machine learning framework, can effectively help multiple organizations to use data and perform machine learning modeling while meeting the requirements of user privacy protection, data security, and laws and regulations. It is widely used in the fields of finance, healthcare, and natural sciences by academia and industry.
[0041] However, in fields such as natural language processing and computer vision, due to the heterogeneity between different clients, the local data possessed by each client may come from multiple different domains, and their corresponding training objectives and trained model structures may also differ. For example, in the field of natural language processing, the training objective of client A is to understand natural language, and its model structure may be an encoder structure in the understanding task, while the training objective of client B is to generate natural language, and its model structure may be an encoder-decoder structure in the generation task. Therefore, if multiple different clients are directly trained together, serious gradient update conflicts may occur, and even the performance of the models of each client may be impaired. This means that multiple different clients cannot be directly trained together, which greatly limits the application of federated learning in the field of natural language processing.
[0042] To address the aforementioned issues, this application provides a federated learning method for heterogeneous scenarios. While introducing federated pre-training, it proposes a coarse-to-fine granular cluster federated algorithm and a cluster comparative learning algorithm, which greatly enriches the practical application scenarios of federated learning and enables different clients to train local models with superior performance.
[0043] Example 1
[0044] According to an embodiment of this application, a method embodiment for text processing is also provided. 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. Furthermore, 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.
[0045] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1A hardware block diagram of a computer terminal (or mobile device) for implementing a text processing method is shown. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0046] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0047] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the text processing method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-mentioned text processing method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0048] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0049] The display can be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0050] Figure 1 The hardware structure block diagram shown can serve not only as an exemplary block diagram of the aforementioned computer terminal 10 (or mobile device), but also as an exemplary block diagram of the aforementioned server. In one optional embodiment, Figure 2 The use of the above is illustrated in a block diagram. Figure 1 The computer terminal 10 (or mobile device) shown is an example of a client. Figure 2 This is a structural block diagram of a computing environment for a text processing method according to an embodiment of this application, such as... Figure 2 As shown, computer terminal 10 (or mobile device) can be connected to one or more servers, such as cloud servers, via a data network connection or electronically. In an alternative embodiment, the computer terminal 10 (or mobile device) can be any mobile computing device, etc. The data network connection can be a local area network connection, a wide area network connection, an Internet connection, or other types of data network connection. Computer terminal 10 (or mobile device) can perform network services to connect to a network service performed by a server or a group of servers 20. The network server is a network-based user service, such as model training.
[0051] Under the aforementioned operating environment, this application provides the following: Figure 3 The text processing method shown. Figure 3 This is a flowchart of a text processing method according to Embodiment 1 of this application. For example... Figure 3 As shown, the method may include the following steps:
[0052] Step S302: The target client obtains the text data to be processed.
[0053] The target client mentioned above can refer to any client that performs natural language tasks and participates in the cluster federated learning provided in this application. The cluster federated algorithm is used to eliminate heterogeneity between different clients. The specific training method is described in detail later.
[0054] The aforementioned text data to be processed can refer to text data that requires natural language processing, such as online comments or pre-selected articles. The corresponding natural language processing tasks could be sentiment analysis of online comments or summary extraction of pre-selected articles. The text data to be processed here can be text data manually entered by the user, or text data obtained through speech recognition of the user's speech, but it is not limited to these.
[0055] In the process of establishing connections between multiple different clients using federated learning to achieve natural language processing, we can first obtain different task data in the text to be processed based on the natural language task that each client needs to process.
[0056] For example, when the natural processing task that the client needs to perform is to perform sentiment analysis on a piece of text, the text data to be processed can be the content of the text, specifically text entity data, text attribute data, text opinion data, text holder status data, text time data, etc.
[0057] When the natural processing task that the client needs to perform is to extract a summary from a document, the text data to be processed can be the content of the article, specifically paragraph data, symbol data, word frequency data, word score data, etc.
[0058] It should be noted that the two text data examples above are for illustrative purposes only and are not intended to limit the specific data. The specific text data to be processed obtained by the target client can be determined according to the actual situation, which will not be elaborated here.
[0059] Step S304: The target client uses a text processing model to perform natural language processing on the text data to be processed, and obtains the text processing result of the text data to be processed.
[0060] The text processing model is deployed locally on the target client. The model parameters of the text processing model are the target model parameters sent by the server. The target model parameters are obtained by the server aggregating the gradient of the first model uploaded by the first client and the original model parameters corresponding to the target client.
[0061] The aforementioned text processing model can refer to a model used in the target client to process natural language tasks, such as a text sentiment analysis model or a text summarization extraction model. It is generally deployed on the local device corresponding to the target client. After the client obtains the aforementioned text data to be processed, it can use the text processing model to process the data.
[0062] The aforementioned server can refer to a server used for federated learning that connects multiple different clients, or it can refer to a cloud server.
[0063] The target model parameters mentioned above can refer to the parameters issued by the cloud server to update the processing model (the untrained model) deployed locally on the client. The model structure, training tasks and sample types of the processing models deployed locally on different clients are different. For the target client, the updated processing model is the text processing model mentioned above.
[0064] The first client mentioned above can refer to a cluster of clients that has the highest similarity to the target client after clustering other clients among multiple different clients for the target client. For example, clients that process natural language understanding can be clustered into one cluster, and clients that process natural language generation can be clustered into another cluster.
[0065] The first model gradient mentioned above can be obtained by each client training the locally deployed processing model using its locally stored training samples and corresponding original model parameters.
[0066] Once the target client obtains the text data to be processed, it can use the locally deployed text processing model to perform natural language processing on the text data to obtain the final text processing result.
[0067] In an optional embodiment, since traditional cluster federated learning requires pre-dividing multiple different clients into multiple client clusters when training clients, and the server maintains a global model for each cluster, the correlation between different clients cannot be fully utilized when training clients using this global model, resulting in poor personalized performance of the trained clients. Therefore, in order to improve the correlation and personalized performance between different clients, a unique global model can be maintained for each client, and similar clients of each client can be clustered to obtain the aforementioned first client. Then, the model parameters of clients in the same cluster are aggregated only, thereby optimizing the processing model deployed locally on each client and obtaining their respective text processing models.
[0068] In one optional embodiment, the first model gradient uploaded by the first client and the original model parameters corresponding to the target client can be aggregated in the cloud server to determine the updated model parameters of the unique global model. The updated model parameters are then used as the target model parameters. Based on the target model parameters, the original model parameters of the processing model in the client are updated to obtain the final processing model.
[0069] In this embodiment, the server clusters at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client to obtain a first client. The server aggregates the first model gradient uploaded by the first client and the original model parameters corresponding to the target client to obtain template model parameters. The server sends the target model parameters to the target client as model parameters for the text processing model to train the text processing model. Then, during the model inference process, the target client obtains the text data to be processed and uses the text processing model to perform natural language processing on the text data to obtain the text processing result. It is worth noting that a unique global model is set for different clients, that is, unique original model parameters are given to different clients, and the model parameters are aggregated based on the similar client set of different clients to achieve the purpose of federated learning. On the one hand, it improves the correlation between different clients and ensures the accuracy of the processing results. On the other hand, it also improves the personalization of each client, making federated learning more flexible in natural language processing and achieving better federated learning results. This solves the technical problem that federated learning has a large impact on the model performance of clients in heterogeneous scenarios, which limits the application of federated learning.
[0070] In the above embodiments of this application, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client. The first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
[0071] In one optional embodiment, multiple clients can be clustered to obtain the aforementioned first client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by other clients.
[0072] Specifically, for each client (including the target client), the locally stored training samples and original model parameters can be used to perform downstream federated learning on the locally deployed processing model to obtain the corresponding first model gradient, which is then uploaded to the cloud server. After receiving the first model gradients uploaded by all clients, the cloud server can calculate the similarity between the first model gradients uploaded by each client and other clients, and cluster the other clients based on the calculated similarity results to determine the first client similar to the target client.
[0073] In the above embodiments of this application, the first client is a preset number of clients that rank first among the at least one sorted clients. The at least one sorted clients are obtained by sorting the at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client.
[0074] The preset number mentioned above can be a fixed value, such as 3, or a variable value. The specific value can be determined based on the total number of multiple clients or the difference between similarities. No limitation is made here.
[0075] In one optional embodiment, when clustering multiple clients, the clients can be clustered based on the similarity of the target client to the first model gradient of other clients. It should be noted that the target client can refer to any one of the multiple clients, and clustering multiple clients can mean performing a clustering process for each client individually.
[0076] Specifically, the server can use fine-grained clustering to first obtain the first model gradient of the processing model stored locally on all clients. Then, it calculates the similarity between the first model gradient of the target client and the first model gradient of other clients pairwise. Based on the calculated similarity, the other clients are sorted. Based on the sorting results, the Top-K (i.e., the preset number of clients with the highest ranking) clients are selected as the client cluster with the highest similarity to the target client, i.e., the first client mentioned above.
[0077] In an alternative embodiment, the similarity can be calculated based on the distance between each gradient vector, such as Minkian distance, Euclidean distance, etc., and the specific similarity calculation method is not limited.
[0078] In the above embodiments of this application, the target model parameters are the sum of the original model parameters corresponding to the target client and the updated parameters corresponding to the target client. The updated parameters are determined by the amount of data corresponding to the first client and the first model gradient uploaded by the first client. The amount of data is used to characterize the amount of training samples stored locally on the first client.
[0079] The parameters of the target model can be determined using the following formula:
[0080]
[0081] Where i can refer to the target client's ID among multiple clients, and N... i This can refer to the aforementioned first client, n can refer to the nth client in the first client, and t can refer to the tth round of training for multiple clients. This could refer to the aforementioned target model parameters. This could refer to the original model parameters corresponding to the aforementioned target client, D. n It can refer to the amount of training sample data stored locally on the nth client, D i This could refer to the total amount of training samples stored locally on all clients within the first client. This could refer to the first model gradient uploaded by the nth client in the aforementioned first client.
[0082] In an optional embodiment, the aforementioned target model parameters can also continue to serve as the original model parameters in the next downstream federated learning process of the target client, participating in the training process of the processing model deployed locally on the target client, until the model structures of all clients are fully trained and the processing efficiency and accuracy of the model meet the expected requirements.
[0083] In the above embodiments of this application, the text processing model includes an encoder and a decoder. The method further includes: performing natural language processing on preset data using the original model parameters corresponding to the target client and the decoder to obtain prototype features corresponding to the target client; uploading the prototype features corresponding to the target client to the server, wherein the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client, the second model gradient uploaded by the second client, and the original model parameters corresponding to the target client, and the second client is obtained by the server clustering at least one client based on the prototype features uploaded by the target client and the prototype features uploaded by at least one client.
[0084] The aforementioned preset data can refer to a public dataset provided additionally for multiple clients, a dataset shared by multiple clients, or a dataset generated based on the local data of multiple clients.
[0085] The aforementioned prototype features can refer to model features that contain heterogeneous client information. Based on these prototype features, the heterogeneity between different clients can be identified, thereby improving the comparative features for client personalization performance.
[0086] The aforementioned second client can refer to a cluster of clients similar to the target client obtained by clustering multiple clients based on the prototype characteristics of each client.
[0087] In one alternative embodiment, due to privacy concerns, clients cannot upload the original model parameters and gradients of their private model architecture to the server during federated learning. This results in insufficient training of the client's private model architecture, leading to a decrease in model performance. Therefore, to avoid this problem, an additional public dataset, namely the aforementioned preset data, can be generated first to simulate training for multiple clients. This improves the clustering results when clustering clients, thereby enhancing the personalized performance of each client.
[0088] Since different clients may have different private model structures, clustering based solely on the gradient of the common model is unlikely to yield good results. Therefore, the target client can first perform natural language processing on the aforementioned preset data based on the original model parameters corresponding to the target client and a preset decoder to obtain the prototype features corresponding to the target client. Specifically, the preset data can be fed into a locally deployed decoder and a multilayer perceptron, and the average output features of the decoder and perceptron at each position can be used as the prototype features. These prototype features are then introduced into the entire clustering and aggregation process to better distinguish clients with different tasks and model architectures, thereby improving the effect of the determined target model parameters on the locally deployed processing model on the client, and thus improving the processing effect of the text to be processed. In an optional embodiment, the target model parameters can be determined by the following formula:
[0089]
[0090] Among them, the above-mentioned and These can be the first client and the second client, respectively; as mentioned above. This could refer to the gradient of the first model uploaded by the j-th client in the first client; as mentioned above. This could refer to the gradient of the second model uploaded by the k-th client in the second client; the aforementioned D j This could be the amount of training samples stored locally on the j-th client; as mentioned above. It can be the total amount of training samples stored locally on all clients in the first client; the aforementioned D k This could be the amount of training samples stored locally on the k-th client; as mentioned above. It can be the total amount of training samples stored locally on all clients in the second client; the γ mentioned above can refer to a hyperparameter, which is generally used to control the intensity of aggregation based on prototype features.
[0091] In an optional embodiment, the process of clustering multiple clients based on prototype features can refer to the aforementioned clustering of multiple clients based on the gradient of the first model, and will not be repeated here.
[0092] In the above embodiments of this application, the text processing model includes an encoder. The method further includes: using the encoder to encode features of locally stored training samples to obtain encoded features corresponding to the target client; sending the encoded features corresponding to the target client to the server; and receiving preset data returned by the server, wherein the preset data is generated by the server based on mixed features and the processing results corresponding to the mixed features. The mixed features are obtained by the server mixing the encoded features uploaded by the target client and the encoded features uploaded by at least one client. The processing results are obtained by the server processing the mixed features using a locally deployed preset processing model.
[0093] The aforementioned hybrid features can refer to features obtained by mixing encoded features generated by multiple clients according to preset weights.
[0094] The aforementioned pre-defined processing model can be a global mask language modeling predictor deployed on a server. It is mainly designed for natural language understanding tasks. Its function is to randomly mask a certain proportion of words in the input sentence in each training round, and then use a linear predictor to predict words based on the features of the corresponding mask positions of the encoder. The goal is to predict the original masked words, so that the model can better capture the dependency relationship between each word in the input sentence and the context, and can better understand the input context.
[0095] The processing result corresponding to the above-mentioned hybrid features can be the word obtained by word prediction using the global mask language modeling predictor mentioned above.
[0096] In one optional embodiment, considering the different data distributions of different clients, arbitrarily generated public datasets may not be suitable for training the processing models of all clients. For example, if client A's processing model mainly processes text data, while client B's processing model mainly processes image data, the aforementioned public data may not be suitable for training models A and B simultaneously. Therefore, each client can first use a locally deployed encoder to encode the locally stored training samples to obtain the aforementioned encoded features, and then upload them to the server. The server can then mix the multiple encoded features uploaded by all clients to obtain the aforementioned mixed features. These mixed features are then fed into a preset processing model to generate synthetic input words, i.e., the aforementioned preset data. This preset data includes both mixed features and synthetic input words, thereby improving the performance of the trained model while ensuring client privacy and security.
[0097] In an optional embodiment, in order to avoid the multiple preset data being too smooth, resulting in the generation of multiple identical input words and affecting the processing effect of the trained model, when processing multiple encoded features, the multiple encoded features can be mixed with randomly distributed weights to generate multiple synthetic input words with large differences.
[0098] Specifically, one client can be randomly selected from multiple clients as the subject, and the mixing weight corresponding to that client can be set to a larger value. Then, the weights of the other clients can be set to smaller values. Finally, the multiple encoded features can be mixed according to the weights to obtain the above-mentioned mixed features.
[0099] In the above embodiments of this application, the method further includes: obtaining a weighted sum of prototype features corresponding to the first client to obtain positive features, and obtaining a weighted sum of prototype features corresponding to the second client to obtain negative features; constructing a first loss function of the text processing model based on the prototype features, positive features, and negative features corresponding to the target client; constructing a second loss function of the text processing model based on the text processing results corresponding to the prototype features and the preset processing results corresponding to the locally stored training samples; and obtaining a weighted sum of the first loss function and the second loss function to obtain the total loss function of the text processing model.
[0100] The aforementioned positive features can refer to features related to the client's personalization performance, such as sentiment analysis features in natural language understanding performance.
[0101] The aforementioned negative features can refer to features that are unrelated to the client's personalization performance, such as summary extraction features in natural language understanding performance.
[0102] In one alternative embodiment, to further improve the personalization performance of each client and thus improve the overall federated learning effect, contrastive learning can be used to guide the prototype features of each client to be closer to or further away from those of clients inside or outside the cluster, thereby optimizing the personalization performance of the client.
[0103] Specifically, based on the clustering results obtained by clustering multiple clients according to the model gradient, the prototype features of all clients in the first client are first summed with weights to obtain a positive feature closely related to the personalization direction of the target client. At the same time, the prototype features of multiple clients in the second client are also summed with weights to obtain a negative feature unrelated to the personalization direction of the target client. Then, the positive and negative features are used to optimize the target client.
[0104] After obtaining the positive and negative features, supervised learning can be further introduced to optimize the training results for the target client. Specifically, the contrastive learning loss (the first loss function mentioned above) and the supervised learning loss (the second loss function mentioned above) can be used to determine the total loss function of the text processing model corresponding to the target client. When the total loss function meets a preset condition, such as being less than a preset value or not decreasing, the training is considered successful.
[0105] In an optional embodiment, the first loss function described above can be constructed based on the prototype features, positive features, and negative features of the target client. The first loss function can be calculated using the following formula:
[0106]
[0107] Among them, the above-mentioned This could refer to the first loss function mentioned above, and h mentioned above. i h j and h k It can refer to the prototype features of clients i, j, and k. The sim mentioned above is the cosine similarity, and the τ mentioned above is the temperature coefficient.
[0108] In an optional embodiment, the second loss function described above can be constructed based on the processing results of the prototype features and the preprocessing results of the training samples stored locally on the target client. Here, the preprocessing results can refer to the actual processing results determined by labeling the training samples. It should be noted that the construction process of the second loss function can be implemented using relevant technologies, which will not be elaborated upon here.
[0109] In an optional embodiment, the first loss function and the second loss function described above can be weighted and summed to obtain the total loss function in the family.
[0110] In the above embodiments of this application, the method further includes: receiving a preset training task and initial model parameters sent by a server; executing the preset training task using locally stored training samples and initial model parameters to obtain a second model gradient corresponding to the target client; uploading the second model gradient corresponding to the target client to the server; and receiving the original model parameters corresponding to the target client sent by the server, wherein the original model parameters are obtained by aggregating the second model gradient uploaded by a third client and the initial model parameters, the third client being a client in the client set to which the target client belongs, the client set being obtained by the server clustering multiple clients based on the second model gradients uploaded by multiple clients, and the multiple clients including the target client and at least one client.
[0111] The aforementioned pre-training tasks can refer to tasks used to eliminate the heterogeneity of corresponding tasks and processing models for different clients, such as masked language modeling tasks and denoising pre-training tasks. Among them, masked language modeling is mainly for training tasks related to natural language understanding, while denoising pre-training tasks are mainly for training tasks related to natural language generation. It should be noted that the above two pre-training tasks are only illustrative examples, and the specific settings of pre-training tasks can be determined according to the actual situation, without specific limitations here.
[0112] Specifically, the above-mentioned masked language modeling task can be to randomly mask a certain proportion of words in the text data in each training round, and use a preset linear predictor to predict the original masked words based on the corresponding encoding features. This allows the model to better capture the dependency relationship between each word in the text data and the context, and thus better perform natural language understanding.
[0113] The aforementioned denoising pre-training task can involve randomly shuffling or deleting multiple sentences in the text data in each training round, and then generating the original text data in an autoregressive manner through an encoder-decoder structure. This allows the model to better learn the contextual dependencies of multiple sentences in the text data, thereby improving natural language generation.
[0114] The initial model parameters mentioned above may refer to the model parameters used by the server when setting a unique global model for all clients. These parameters can be randomly generated or manually modified by the user.
[0115] The second model gradient mentioned above can refer to the gradient generated by the client during the preset training task.
[0116] The aforementioned third client can refer to other clients in the cluster set corresponding to the target client.
[0117] In one optional embodiment, during training, the server can assign a pre-training task to each client in each training round. The client can first receive the preset training task and initial model parameters sent by the server, and execute the preset training task based on its locally stored training samples and initial model parameters, thereby obtaining the model gradient (i.e., the second model gradient) of each client during the pre-training process. The server can then perform coarse-grained clustering on multiple clients based on the second model gradients uploaded by all clients, thereby determining a client cluster with high similarity to the target client. The server then aggregates the second model gradients and initial model parameters of other clients in the client cluster to obtain the original model parameters corresponding to the global model. Finally, the server uses these original model parameters to continue pre-training all client models to ensure that the model structure of each client is the same, thereby initially solving the heterogeneity between different clients and strengthening the flow and integration of common knowledge contained in the data of different clients performing various downstream tasks.
[0118] Specifically, a pre-set training task can be randomly selected from multiple pre-defined training tasks and sent to multiple clients, ensuring that all clients perform the same pre-training task in each training round. Then, based on the pre-training results, such as the model gradients of the trained clients, clustering is performed on the multiple clients to construct the original model parameters used to optimize the client model structure. This makes the model structures of the multiple clients more consistent, thus initially solving the problems of client task heterogeneity and model heterogeneity. Clustering the processed multiple clients according to gradient similarity can significantly improve the optimization efficiency of the model for multiple clients.
[0119] In one alternative embodiment, after identifying data domains with the same distribution, different data domains can be distinguished hierarchically using agglomerative clustering algorithms and the principle of model gradient cosine similarity. The clustering process proceeds from bottom to top. In the initial layer, each client gradient is treated as a different cluster. In subsequent layers, the pairwise similarity of all client gradients is calculated, and the two most similar clusters are merged. This process is repeated until the total number of clusters reaches a set value. Specifically, firstly, multiple second model gradients can be divided into multiple different data domains according to their magnitude. Then, different model gradients in different data domains are processed to improve the efficiency of clustering multiple clients. After dividing into multiple data domains, a target gradient can be selected from the multiple first model gradients in each data domain in ascending order of data domain size. The similarity between the target gradient and other model gradients in the data domain is calculated. Two model gradients with high similarity are merged until the number of merged model gradients in the data domain reaches a preset value. At this point, the coarse-grained classification process for multiple clients is completed.
[0120] In the above embodiments of this application, the method further includes: when the processing model deployed locally by the target client does not contain a preset structure, receiving a preset parameter model sent by the server; and the target client constructing a preset structure locally based on the preset parameter model.
[0121] The aforementioned preset structure may refer to a model structure not included in the processing model deployed locally on the client, such as a decoder.
[0122] In an optional embodiment, in order to enable the pre-training process to be better scaled to different numbers and categories of pre-training tasks, the server may first determine whether the processing model deployed locally on the client contains the above-mentioned preset structure, so as to improve the efficiency of federated learning for multiple clients.
[0123] If it is included, it means that the client can directly execute the preset training task for processing; if it is not included, the server can send the model parameters corresponding to the preset structure to the client, and the client can then build the above preset structure locally according to the preset parameter model, so as to keep the model structure of all clients consistent and eliminate the model heterogeneity problem.
[0124] In the above embodiments of this application, the first client is obtained by the server by clustering at least one client based on a target training strategy. The target training strategy is determined by the server from multiple training strategies based on the difference type between the text processing model and the processing model deployed on the at least one client. Different training strategies are used to train models with different difference types.
[0125] The aforementioned at least one client can refer to the target client mentioned above, or it can be any one of multiple clients.
[0126] The first client mentioned above can refer to a set of clients that are highly similar to the target client. As mentioned earlier, multiple clients can be clustered by the similarity between the model gradients of the target client and other clients.
[0127] The aforementioned target training strategy can refer to a targeted training strategy implemented when there are different types of heterogeneous problems among multiple clients.
[0128] In one optional embodiment, since there may be multiple different difference types between different clients, in order to effectively solve the heterogeneity problem corresponding to different difference types, a training strategy can be preset for each different difference type.
[0129] In one optional embodiment, since there may be various different types of differences between different clients, such as differences in training data stored locally on the client, differences in training tasks, differences in model structure, etc., and different types of differences can be independent, for example, clients A and B only have differences in training data, and clients C and D only have differences in model structure, when clustering multiple clients, the target training strategy can be determined from multiple preset training strategies based on the specific type of difference between the target client and other clients, so as to train the processing model deployed locally on the target client in a targeted manner.
[0130] In an optional embodiment, if the only difference between clients A and B is in the training data, the target training strategy mentioned above may refer to the aforementioned coarse-grained clustering strategy; if the only difference between clients A and B is in the training task, the target training strategy mentioned above may refer to the aforementioned fine-grained clustering strategy; if the only difference between clients A and B is in the model structure, the target training strategy mentioned above may refer to the aforementioned prototype feature clustering strategy.
[0131] In the above embodiments of this application, the difference types include at least one of the following: differences in training samples, differences in training tasks, and differences in model structure. The multiple training strategies include: a first granularity clustering strategy, a second granularity clustering strategy, and a prototype feature clustering strategy. The clustering granularity used by the first granularity clustering strategy is greater than the clustering granularity used by the second granularity clustering strategy.
[0132] The aforementioned differences in training samples may refer to the fact that the data types of training samples stored locally by different clients may differ.
[0133] The aforementioned differences in training tasks may refer to the fact that different training tasks used to train the personalized performance of different clients may differ.
[0134] The aforementioned differences in model structure may refer to the fact that the model structure of the processing model deployed locally by different clients may differ.
[0135] The first-level clustering strategy mentioned above can refer to a clustering strategy performed to identify clients with the same distribution and data domain. For example, the aforementioned clustering strategy that uses agglomerative clustering algorithms and the principle of model gradient cosine similarity to distinguish different data domains in a hierarchical manner, and merges the gradients of each client in different data domains.
[0136] The second-level clustering strategy mentioned above can refer to a clustering strategy implemented to obtain clients with the same task type. For example, the clustering strategy mentioned earlier that clusters multiple clients based on the similarity of the target client to the first model gradient of other clients.
[0137] It should be noted that, since there are often differences in training data and training tasks between different clients during the downstream federated learning process, a smaller clustering granularity can be used to cluster multiple clients in order to improve the clustering effect. That is, the clustering granularity used in the second granularity clustering strategy is smaller than that used in the first granularity clustering strategy.
[0138] The aforementioned prototype feature clustering strategy can refer to a clustering strategy implemented to distinguish clients with different model architectures, thereby improving the clustering effect for multiple clients. For example, the aforementioned clustering strategy that incorporates the prototype features corresponding to the target client into the clustering and aggregation process for multiple clients.
[0139] In an alternative embodiment, the first granularity clustering strategy described above can be used to process the differences in training samples among multiple clients, such as using a coarse-grained clustering strategy to cluster multiple clients as described above.
[0140] Because training samples from different clients may vary significantly—for example, client A might store text data while client B stores image data—clustering multiple clients would fail to group clients A and B together. Therefore, to avoid clustering errors, preliminary clustering can be performed based on each client's locally stored training data. Clients with identical training data are initially grouped into one class, eliminating the differences in training samples between clients and improving the efficiency of subsequent accurate clustering. The process of partitioning the data domain for multiple clients is as described above and will not be repeated here.
[0141] At this point, the corresponding clustering granularity can refer to the type of training data.
[0142] In an alternative embodiment, the second granularity clustering strategy described above can be used to process the differences in training tasks among multiple clients, such as using a fine-grained clustering strategy to cluster multiple clients as described above.
[0143] Since different clients may have different processing tasks, the training tasks used to train the locally deployed processing models on those clients will also differ. For example, client A's training objective might be natural language understanding, while client B's objective might be natural language generation. Therefore, clients A and B cannot be trained using the same task, and thus need to be clustered into different client clusters. To avoid clustering errors, multiple clients can be clustered based on the model gradients for each client, thus eliminating the differences in training tasks between different clients. The process of obtaining the model gradients for each client is as described above and will not be repeated here.
[0144] At this point, the corresponding clustering granularity can refer to the similarity between clients.
[0145] In an optional embodiment, the above-described prototype feature clustering strategy can be used to process the model structure differences between multiple clients, such as using the aforementioned prototype feature clustering strategy to cluster multiple clients.
[0146] Since the private model structures of different clients may differ, it is difficult to achieve good clustering results by simply using the public model gradient to classify multiple clients. For example, client A has both an encoder and a decoder, while client B only has an encoder. If clients A and B are clustered based on their model gradients, the different model structures may lead to different processing results, affecting the performance of downstream federated learning. Therefore, to avoid clustering errors, multiple clients can be clustered based on the prototype features corresponding to each client to eliminate the differences in model structure between different clients.
[0147] The process of obtaining the prototype features corresponding to the client is as described above and will not be repeated here.
[0148] To facilitate understanding of the above text processing methods, the following is based on... Figure 4 and Figure 5 The above methods will be briefly explained.
[0149] Figure 4 This is a schematic diagram of a clustering federated learning framework according to Embodiment 1 of this application. Figure 4As shown, the entire clustering federated learning process involves a server and multiple clients. When optimizing the model for multiple clients, the optimization process can be divided into two parts: the pre-training process shown on the left and the downstream federated learning process shown on the right. During pre-training, the server assigns the same pre-training task to each client in each training round to eliminate task heterogeneity and model heterogeneity between different clients. After training, each client can determine its own first model gradient based on the locally stored training samples and upload it to the server. The server performs coarse-fine clustering on multiple clients based on the first model gradient, then aggregates the parameters of clients in the same cluster, and finally sends the aggregated model parameters back to the clients for a new round of training. After pre-training, downstream federated learning can be executed. In the downstream federated learning process, the server performs personalized clustering for each client individually based on the gradient information during the parameter aggregation phase. Each client selects multiple clients whose updated gradients are closest to its own for parameter aggregation. The specific clustering and aggregation are as described above.
[0150] Figure 5 This is a schematic diagram of a cluster contrastive learning framework according to Embodiment 1 of this application. Figure 5 As shown, before training models for multiple clients, the preset data generation steps shown on the left can be performed first. This involves extracting the encoding features of each client based on the encoder trained in the pre-training stage and fusing these features to obtain synthetic encoding features. Then, a masked language modeling predictor is used to predict words from the synthetic features, generating synthetic input words, which is the preset data mentioned above. After generating the preset data, clustered contrastive learning shown on the right can be performed. The preset data is fed into the decoders of each client to obtain the decoding features corresponding to each client. Based on the previously obtained fine-grained clustering results, the client decoding features in the same cluster are fused as positive samples, and the remaining features are used as negative samples. Through contrastive learning, the feature distance between the current client's decoding features and positive samples is narrowed, while the distance between it and negative samples is widened, thereby improving the personalized performance of each client.
[0151] The above approach addresses task and model heterogeneity through pre-training, enhancing the flow and integration of common knowledge contained in different client data executing various downstream tasks, and thus initially resolving the task and model heterogeneity issue. By progressively addressing the three heterogeneous challenges of data, tasks, and models through coarse-to-fine granular clustering and cluster contrastive learning, it achieves better joint model training results, significantly enriching the practical application scenarios of federated learning.
[0152] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0154] Example 2
[0155] According to an embodiment of this application, a model training method is also provided. 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. Furthermore, 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.
[0156] Figure 6 This is a flowchart of a model training method according to Embodiment 2 of this application, as follows: Figure 6 As shown, the method may include the following steps:
[0157] Step S602: The target client receives the original model parameters corresponding to the target client sent by the server.
[0158] The original model parameters mentioned above can refer to the parameters used to train the processing model for the client.
[0159] When training the processing model for the target client, the client can first obtain the original model parameters sent by the server to train the processing model in the client, as shown in the following text.
[0160] In step S604, the target client uses the locally stored training samples and the corresponding original model parameters to train the locally deployed processing model and obtain the first model gradient corresponding to the target client.
[0161] After the initial processing model is built, the target client can use its locally stored training samples and the received original model parameters to perform preliminary training on the deployed processing model, obtain the first model gradient that reflects the direction of model parameter updates, and upload the model gradient to the server to improve the accuracy of the parameters subsequently determined for training the processing model.
[0162] In step S606, the target client sends the first model gradient corresponding to the target client to the server and receives the target model parameters corresponding to the target client sent by the server.
[0163] The target model parameters are obtained by aggregating the original model parameters and the gradient of the first model uploaded by the first client.
[0164] To improve the correlation between different clients and enhance the application of federated learning, the server can cluster multiple clients and then use the first clustered client to perform aggregate calculations on the target model parameters corresponding to the target client.
[0165] Specifically, multiple first model gradients for clients other than the target client can be identified and uploaded to the server. The server can then calculate the similarity between the first model uploaded by the target client and the gradients of the other multiple first models, and cluster the clients with high similarity to obtain the aforementioned first client.
[0166] After identifying the first client, the server can aggregate the multiple first model gradients uploaded by the first client and the original model parameters of the target client to obtain the final target model parameters.
[0167] In step S608, the target client updates the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client, thereby obtaining the text processing model.
[0168] Among them, the text processing model is used to perform natural language processing on the text data to be processed.
[0169] After the server determines the target model parameters that can be used to train the target client's processing model, the target model parameters can be sent to the target client. The target client can then update the parameters of its own processing model based on the target model parameters to obtain the text processing model described above.
[0170] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0171] Example 3
[0172] According to an embodiment of this application, a model training method is also provided. 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. Furthermore, 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.
[0173] Figure 7 This is a flowchart of a model training method according to Embodiment 3 of this application, as follows: Figure 7 As shown, the method may include the following steps:
[0174] In step S702, the server sends the original model parameters corresponding to multiple clients to multiple clients, and receives the first model gradient uploaded by multiple clients.
[0175] When training the processing model for the target client, in order to improve the correlation between multiple clients, the server can first perform clustering processing on multiple clients.
[0176] In one alternative embodiment, the server can cluster multiple clients based on the model gradients corresponding to each client. Therefore, the server can first send the original model parameters used to initially train the processing model of the client to the client. The client then determines its corresponding first model gradient based on its locally stored training data and the original model parameters. Finally, the server can receive the first model gradient uploaded by the client.
[0177] When clustering multiple clients based on the first model gradient uploaded by multiple clients, the first model gradient corresponding to the target client can be determined first. Then, the similarity between the first model gradient and the model gradients corresponding to other clients can be calculated. Finally, the clients with the highest similarity can be clustered to obtain a client cluster with high similarity to the target client, i.e., the first client mentioned above.
[0178] In step S704, the server aggregates the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client.
[0179] After clustering multiple clients to obtain the first client, the server can further aggregate the gradients of multiple first models in the first client and the original model parameters of the target client to obtain the target model parameters corresponding to the target client, thereby training the processing model of the target client.
[0180] It should be noted that the target client can refer to any one of multiple clients.
[0181] Step S706: The server sends the target model parameters corresponding to multiple clients to multiple clients.
[0182] The target model parameters are used to update the model parameters of the locally deployed processing model.
[0183] After determining the target model parameters for multiple clients, the server can send these parameters to their respective clients. The clients can then update the parameters of their locally deployed processing models based on these parameters, thereby obtaining the final text processing model.
[0184] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0185] In this embodiment of the application, before aggregating the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client, the method further includes: outputting confirmation information, wherein the confirmation information includes: the first client corresponding to each client; receiving feedback information corresponding to the confirmation information, wherein the feedback information includes: the feedback client corresponding to each client; aggregating the first model gradient uploaded by the feedback client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client.
[0186] The aforementioned information to be confirmed may refer to the clustering information sent by the server to the target client and the first client.
[0187] In one optional embodiment, after clustering multiple clients, the server can further output the first client information corresponding to the target client. At the same time, after receiving the confirmation information, the target client and the first client can re-upload their respective first model gradients and original model parameters, thereby avoiding the situation where the server directly obtains the model gradients and original model parameters incorrectly.
[0188] After obtaining the first model gradient and original model parameters for each client, the server can aggregate these parameters to obtain the target model parameters used to train the processing model deployed locally on the target client.
[0189] In this embodiment of the application, the method further includes: sending a preset training task and initial model parameters to multiple clients, and receiving second model gradients uploaded by multiple clients, wherein the second model gradients are obtained by each client performing a preset training task using locally stored training samples and initial model parameters; clustering multiple clients based on multiple second model gradients to obtain a client set to which each client belongs; and aggregating the initial model parameters based on the second model gradients uploaded by each client's client set to obtain the original model parameters corresponding to each client.
[0190] The aforementioned pre-training task can refer to a task used to eliminate the heterogeneity of different client-side corresponding tasks and processing models.
[0191] In one optional embodiment, the server can assign a pre-training task to each client in each training round. The client can first receive the preset training task and initial model parameters sent by the server, and execute the preset training task based on its locally stored training samples and initial model parameters, thereby obtaining the model gradient (i.e., the second model gradient) of each client during the pre-training process. The server can cluster multiple clients based on the second model gradients uploaded by all clients to obtain the client set for each client. Then, the server can use the multiple second model gradients uploaded by the client set to aggregate the initial model parameters to obtain the original model parameters used for the initial training of the client model, so as to ensure that the model structure of each client is the same, thereby initially solving the heterogeneity between different clients and strengthening the flow and integration of common knowledge contained in the data of different clients performing various downstream tasks.
[0192] In this embodiment of the application, the method further includes: outputting multiple training tasks; receiving a selection operation performed on the multiple training tasks; and determining the training task corresponding to the selection operation as a preset training task.
[0193] The aforementioned selection operation can refer to the operation of selecting a target training task from multiple training tasks according to preset conditions. For example, the preset conditions can be selected based on the processing task direction of the target client (natural language understanding, natural language generation, etc.), or the preset conditions can be randomly selected, but are not limited to these.
[0194] In an alternative embodiment, in order to improve the accuracy of the determined original model parameters and eliminate the task heterogeneity problem between different clients, the server can randomly select one from multiple training tasks and send it to multiple clients, so that the pre-training tasks executed by multiple clients in each round of training are the same.
[0195] Example 4
[0196] According to an embodiment of this application, a model training system is also provided. Figure 8 This is a structural block diagram of a model training system according to Embodiment 4 of this application, as follows: Figure 8 As shown, the system 800 may include: multiple clients 802; a server 804, connected to the multiple clients, used to generate original model parameters corresponding to the multiple clients and send them to the multiple clients; the multiple clients are used to train the locally deployed processing model using locally stored training text and the corresponding original model parameters to obtain the first model gradients corresponding to the multiple clients; the server is also used to cluster the multiple clients based on the first model gradients corresponding to the multiple clients to obtain the first client corresponding to each client, and to aggregate the first model gradients uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client; the multiple clients are also used to update the model parameters of the locally deployed processing model based on the corresponding target model parameters.
[0197] In the model training system, the server can aggregate the gradient of the first model uploaded by the first client and the original model parameters corresponding to the target client to obtain template model parameters. The server then sends the target model parameters to the target client as model parameters for the text processing model to train the text processing model. During the model inference process, the target client obtains the text data to be processed and uses the text processing model to perform natural language processing on the text data to obtain the text processing result. It is worth noting that a unique global model is set for different clients, that is, unique original model parameters are given to different clients, and the model parameters are aggregated based on a set of similar clients to achieve the purpose of federated learning.
[0198] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0199] Example 5
[0200] According to an embodiment of this application, an image processing method is also provided. 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. Furthermore, 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.
[0201] Figure 9 This is a flowchart of an image processing method according to Embodiment 5 of this application, as follows: Figure 9As shown, the method may include the following steps
[0202] Step S902: The target client acquires the image to be processed.
[0203] The aforementioned image to be processed can refer to an image that requires natural language processing, such as analyzing the emotional state of a task in the image, or extracting keyword information from multiple textual pieces of information in the image. The image to be processed here can be an image manually input by the user, or an image captured by a camera device, but it is not limited to these.
[0204] Step S904: The target client uses the image processing model to process the image to be processed and obtains the image processing result of the image to be processed.
[0205] The image processing model is deployed locally on the target client. The model parameters of the image processing model are the target model parameters sent by the server. The target model parameters are obtained by the server aggregating the original model parameters corresponding to the target client based on the first model gradient uploaded by the first client. The first client is obtained by the server clustering at least one client based on the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client. The first model gradient is obtained by each client processing the locally deployed processing model using the locally stored training samples and the corresponding original model parameters.
[0206] Similar to the processing and analysis of text data in Example 1, when processing an image, the image processing model deployed on the client can be used to process the image.
[0207] The corresponding image processing model training process can begin by calculating the gradient similarity between the processing models of the target client and several other clients. This similarity is then used to cluster the clients, resulting in a client cluster with high similarity to the target client—the first client mentioned above. Finally, the multiple first gradient models uploaded by the first client, along with the original model parameters of the target client, can be aggregated to obtain the target training parameters for training the processing model of the target client. This process trains the processing model in the client into the aforementioned image processing model.
[0208] Example 6
[0209] According to an embodiment of this application, a text processing apparatus for implementing the above-described text processing method is also provided, which can be deployed in a target client. Figure 10 This is a schematic diagram of a text processing device according to Embodiment 6 of this application, as shown below. Figure 10 As shown, the device 1000 includes: an acquisition module 1002 and a processing module 1004.
[0210] The acquisition module is used to acquire the text data to be processed; the processing module is used to perform natural language processing on the text data to be processed using the text processing model to obtain the text processing result of the text data to be processed. The text processing model is deployed locally on the target client, and the model parameters of the text processing model are the target model parameters sent by the server. The target model parameters are obtained by the server aggregating the gradient of the first model uploaded by the first client and the original model parameters corresponding to the target client.
[0211] It should be noted that the acquisition module 1002 and processing module 1006 mentioned above correspond to steps S302 to S304 in Embodiment 1. The two modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should also be noted that the above modules, as part of the device, can run on the computer terminal provided in Embodiment 1.
[0212] In the above embodiments of this application, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client. The first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
[0213] In the above embodiments of this application, the first client is a preset number of clients that rank first among the at least one sorted clients. The at least one sorted clients are obtained by sorting the at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client.
[0214] In the above embodiments of this application, the target model parameters are the sum of the original model parameters corresponding to the target client and the updated parameters corresponding to the target client. The updated parameters are determined by the amount of data corresponding to the first client and the first model gradient uploaded by the first client. The amount of data is used to characterize the amount of training samples stored locally on the first client.
[0215] In the above embodiments of this application, the text processing model includes an encoder and a decoder. The device further includes: a natural language processing module, used to perform natural language processing on preset data using the original model parameters corresponding to the target client and the decoder to obtain prototype features corresponding to the target client; and an upload module, used to upload the prototype features corresponding to the target client to a server, wherein the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client, the second model gradient uploaded by the second client, and the original model parameters corresponding to the target client, and the second client is obtained by the server clustering at least one client based on the prototype features uploaded by the target client and the prototype features uploaded by at least one client.
[0216] In the above embodiments of this application, the text processing model includes an encoder. The device further includes: a feature encoding module, used to encode features of locally stored training samples using the encoder to obtain encoded features corresponding to the target client; a feature sending module, used to send the encoded features corresponding to the target client to the server; and a data receiving module, used to receive preset data returned by the server, wherein the preset data is generated by the server based on mixed features and the processing results corresponding to the mixed features. The mixed features are obtained by the server mixing the encoded features uploaded by the target client and at least one encoded feature uploaded by a client, and the processing results are obtained by the server processing the mixed features using a locally deployed preset processing model.
[0217] In the above embodiments of this application, the device further includes: a positive feature determination module, used to obtain a weighted sum of prototype features corresponding to the first client to obtain positive features, and to obtain a weighted sum of prototype features corresponding to the second client to obtain negative features; a first construction module, used to construct a first loss function of the text processing model based on the prototype features, positive features, and negative features corresponding to the target client; a second construction module, used to construct a second loss function of the text processing model based on the text processing results corresponding to the prototype features and the preset processing results corresponding to the locally stored training samples; and a loss function determination module, used to obtain a weighted sum of the first loss function and the second loss function to obtain the total loss function of the text processing model.
[0218] In the above embodiments of this application, the device further includes: a data receiving module for receiving a preset training task and initial model parameters sent by a server; a gradient determination module for executing the preset training task using locally stored training samples and initial model parameters to obtain a second model gradient corresponding to the target client; a gradient uploading module for uploading the second model gradient corresponding to the target client to the server; and a raw parameter receiving module for receiving raw model parameters corresponding to the target client sent by the server, wherein the raw model parameters are obtained by aggregating the second model gradient uploaded by a third client and the initial model parameters, the third client being a client in the client set to which the target client belongs, the client set being obtained by the server clustering multiple clients based on the second model gradients uploaded by multiple clients, and the multiple clients including the target client and at least one client.
[0219] In the above embodiments of this application, the device further includes: a model receiving module, used to receive a preset parameter model sent by a server when the locally deployed processing model does not contain a preset structure; and a structural component module, used to construct a preset structure locally based on the preset parameter model.
[0220] In the above embodiments of this application, the first client is obtained by the server by clustering at least one client based on the target training strategy. The target training strategy is determined by the server from multiple training strategies based on the difference type between the text processing model and the processing model deployed on at least one client. Different training strategies are used to train models with different difference types.
[0221] In the above embodiments of this application, the difference types include at least one of the following: differences in training samples, differences in training tasks, and differences in model structure. The multiple training strategies include: a first-granularity clustering strategy, a second-granularity clustering strategy, and a prototype feature clustering strategy. The clustering granularity used by the first-granularity clustering strategy is greater than the clustering granularity used by the second-granularity clustering strategy.
[0222] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0223] Example 7
[0224] According to an embodiment of this application, a model training apparatus for implementing the above-described model training method is also provided, the apparatus being deployed in a target client. Figure 11 This is a schematic diagram of a model training device according to Embodiment 7 of this application, as shown below. Figure 11 As shown, the device 1100 includes: a receiving module 1102, a training module 1104, a data transceiver module 1106, and a model update module 1108.
[0225] The system comprises the following modules: a receiving module for receiving the original model parameters corresponding to the target client sent by the server; a training module for training the locally deployed processing model using locally stored training samples and the corresponding original model parameters to obtain the first model gradient corresponding to the target client; a data transceiver module for sending the first model gradient corresponding to the target client to the server and receiving the target model parameters corresponding to the target client sent by the server, wherein the target model parameters are obtained by aggregating the original model parameters and the first model gradient uploaded by the first client; and a model update module for updating the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client to obtain a text processing model, wherein the text processing model is used for natural language processing of the text data to be processed.
[0226] It should be noted that the receiving module 1102, training module 1104, data transceiver module 1106, and model update module 1108 mentioned above correspond to steps S602 to S608 in Embodiment 2. The four modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules, as part of the device, can run on the computer terminal provided in Embodiment 1.
[0227] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0228] Example 8
[0229] According to an embodiment of this application, a model training apparatus for implementing the above-described model training method is also provided, the apparatus being deployed in a server. Figure 12 This is a schematic diagram of a model training device according to Embodiment 8 of this application, as shown below. Figure 12 As shown, the device 1200 includes: a data transceiver module 1202, an aggregation module 1204, and a parameter sending module 1206.
[0230] The data transceiver module is used to send the original model parameters corresponding to multiple clients to multiple clients and receive the first model gradient uploaded by multiple clients; the aggregation module is used to aggregate the first model gradient uploaded by the first client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client; the parameter sending module is used to send the target model parameters corresponding to multiple clients to multiple clients, wherein the target model parameters are used to update the model parameters of the locally deployed processing model.
[0231] It should be noted that the data transceiver module 1202, aggregation module 1204, and parameter sending module 1206 mentioned above correspond to steps S702 to S706 in Embodiment 3. The four modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules, as part of the device, can run in the computer terminal provided in Embodiment 1.
[0232] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0233] Example 9
[0234] According to an embodiment of this application, an image processing apparatus for implementing the above-described image processing method is also provided, the apparatus being deployed in a target client. Figure 13 This is a schematic diagram of an image processing apparatus according to Embodiment 7 of this application, as shown below. Figure 13 As shown, the device 1300 includes: an acquisition module 1302 and a processing module 1304.
[0235] The acquisition module is used to acquire the image to be processed; the processing module is used to process the image to be processed using the image processing model to obtain the image processing result of the image to be processed; wherein, the image processing model is deployed locally on the target client, the model parameters of the image processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the original model parameters corresponding to the target client based on the first model gradient uploaded by the first client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using the locally stored training samples and the corresponding original model parameters.
[0236] It should be noted that the acquisition module 1302 and processing module 1304 mentioned above correspond to steps S902 to S908 in Embodiment 5. The four modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should also be noted that the above modules, as part of the device, can run on the computer terminal provided in Embodiment 1.
[0237] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0238] Example 10
[0239] Embodiments of this application may provide a computer terminal, which may be any one of a group of computer terminals. Optionally, in this embodiment, the computer terminal may also be replaced by a mobile terminal or other terminal device.
[0240] Optionally, in this embodiment, the computer terminal may be located in at least one of a plurality of network devices in a computer network.
[0241] In this embodiment, the computer terminal described above can execute the program code for the following steps in the text processing method: the target client obtains the text data to be processed; the target client uses the text processing model to perform natural language processing on the text data to be processed, and obtains the text processing result of the text data to be processed; wherein, the text processing model is deployed locally on the target client, the model parameters of the text processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using the locally stored training samples and the corresponding original model parameters.
[0242] Optionally, Figure 14 This is a structural block diagram of a computer terminal according to Embodiment 10 of this application. Figure 14 As shown, the computer terminal may include: one or more (only one is shown in the figure) processors 1402 and memory 1404.
[0243] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the text processing method and apparatus in this application embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned text processing method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to terminal A via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0244] The processor can invoke information and applications stored in the memory via a transmission device to perform the following steps: the target client obtains text data to be processed; the target client uses a text processing model to perform natural language processing on the text data to be processed to obtain the text processing result; wherein, the text processing model is deployed locally on the target client, the model parameters of the text processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and the corresponding original model parameters.
[0245] Optionally, the first client is a preset number of clients that rank first among the at least one sorted clients. The at least one sorted clients are obtained by sorting the at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client.
[0246] Optionally, the target model parameters are the sum of the original model parameters corresponding to the target client and the updated parameters corresponding to the target client. The updated parameters are determined by the amount of data corresponding to the first client and the gradient of the first model uploaded by the first client. The amount of data is used to represent the amount of training samples stored locally on the first client.
[0247] Optionally, the text processing model includes an encoder and a decoder. The processor can also execute program code for the following steps: performing natural language processing on preset data using the original model parameters corresponding to the target client and the decoder to obtain prototype features corresponding to the target client; uploading the prototype features corresponding to the target client to the server, wherein the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client, the second model gradient uploaded by the second client, and the original model parameters corresponding to the target client, and the second client is obtained by the server clustering at least one client based on the prototype features uploaded by the target client and the prototype features uploaded by at least one client.
[0248] Optionally, the text processing model includes an encoder. The processor can also execute program code for the following steps: using the encoder to encode features of locally stored training samples to obtain encoded features corresponding to the target client; sending the encoded features corresponding to the target client to the server; receiving preset data returned by the server, wherein the preset data is generated by the server based on mixed features and the processing results corresponding to the mixed features, the mixed features are obtained by the server mixing the encoded features uploaded by the target client and at least one encoded feature uploaded by a client, and the processing results are obtained by the server processing the mixed features using a locally deployed preset processing model.
[0249] Optionally, the processor may also execute program code that performs the following steps: obtaining a weighted sum of the prototype features corresponding to the first client to obtain positive features, and obtaining a weighted sum of the prototype features corresponding to the second client to obtain negative features; constructing a first loss function for the text processing model based on the prototype features, positive features, and negative features corresponding to the target client; constructing a second loss function for the text processing model based on the text processing results corresponding to the prototype features and the preset processing results corresponding to the locally stored training samples; and obtaining a weighted sum of the first loss function and the second loss function to obtain the total loss function of the text processing model.
[0250] Optionally, the processor may also execute program code for the following steps: receiving a preset training task and initial model parameters sent by the server; executing the preset training task using locally stored training samples and initial model parameters to obtain the second model gradient corresponding to the target client; uploading the second model gradient corresponding to the target client to the server; receiving the original model parameters corresponding to the target client sent by the server, wherein the original model parameters are obtained by aggregating the second model gradient uploaded by the third client and the initial model parameters, the third client being a client in the client set to which the target client belongs, the client set being obtained by the server clustering multiple clients based on the second model gradients uploaded by multiple clients, the multiple clients including the target client and at least one client.
[0251] Optionally, the processor may also execute program code that performs the following steps: if the target client's locally deployed processing model does not contain a preset structure, it receives a preset parameter model sent by the server; the target client builds a preset structure locally based on the preset parameter model.
[0252] The processor can invoke information and applications stored in the memory via a transmission device to perform the following steps: the target client receives the original model parameters corresponding to the target client sent by the server; the target client trains the locally deployed processing model using locally stored training samples and the corresponding original model parameters to obtain the first model gradient corresponding to the target client; the target client sends the first model gradient corresponding to the target client to the server and receives the target model parameters corresponding to the target client sent by the server, wherein the target model parameters are obtained by aggregating the original model parameters and the first model gradient uploaded by the first client, the first client being a client in the first client set corresponding to the target client, and the first client set being obtained by clustering multiple clients based on multiple first model gradients sent by multiple clients; the target client updates the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client to obtain a text processing model, wherein the text processing model is used to perform natural language processing on the text data to be processed.
[0253] The processor can invoke information and applications stored in the memory via the transmission device to perform the following steps: The server sends the original model parameters corresponding to multiple clients to multiple clients and receives the first model gradient uploaded by multiple clients, wherein the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters; The server clusters the multiple clients based on the first model gradients uploaded by multiple clients to obtain the first client corresponding to each client; The server aggregates the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client; The server sends the target model parameters corresponding to multiple clients to multiple clients, wherein the target model parameters are used to update the model parameters of the locally deployed processing model.
[0254] The processor can invoke information and applications stored in the memory through the transmission device to perform the following steps: the target client acquires the image to be processed; the target client uses an image processing model to process the image to be processed and obtains the image processing result of the image to be processed; wherein, the image processing model is deployed locally on the target client, the model parameters of the image processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the original model parameters corresponding to the target client based on the first model gradient uploaded by the first client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
[0255] In this embodiment, the server clusters at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client to obtain a first client. The server aggregates the first model gradient uploaded by the first client and the original model parameters corresponding to the target client to obtain template model parameters. The server sends the target model parameters to the target client as model parameters for the text processing model to train the text processing model. Then, during the model inference process, the target client obtains the text data to be processed and uses the text processing model to perform natural language processing on the text data to obtain the text processing result. It is worth noting that a unique global model is set for different clients, that is, unique original model parameters are given to different clients, and the model parameters are aggregated based on the similar client set of different clients to achieve the purpose of federated learning. On the one hand, it improves the correlation between different clients and ensures the accuracy of the processing results. On the other hand, it also improves the personalization of each client, making federated learning more flexible in natural language processing and achieving better federated learning results. This solves the technical problem that federated learning has a large impact on the model performance of clients in heterogeneous scenarios, which limits the application of federated learning.
[0256] Example 11
[0257] Embodiments of this application also provide a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium can be used to store the program code executed by the text processing method provided in Embodiment 1.
[0258] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer terminal network, or in any mobile terminal in a group of mobile terminals.
[0259] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: the target client acquires text data to be processed; the target client uses a text processing model to perform natural language processing on the text data to be processed, and obtains the text processing result of the text data to be processed; wherein, the text processing model is deployed locally on the target client, the model parameters of the text processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and the corresponding original model parameters.
[0260] Optionally, the aforementioned storage medium is further configured to store program code for performing the following steps: the target client acquires text data to be processed; the target client uses a text processing model to perform natural language processing on the text data to be processed, and obtains the text processing result of the text data to be processed; wherein, the text processing model is deployed locally on the target client, the model parameters of the text processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and the corresponding original model parameters.
[0261] Optionally, the first client is a preset number of clients that rank first among the at least one sorted clients. The at least one sorted clients are obtained by sorting the at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client.
[0262] Optionally, the target model parameters are the sum of the original model parameters corresponding to the target client and the updated parameters corresponding to the target client. The updated parameters are determined by the amount of data corresponding to the first client and the gradient of the first model uploaded by the first client. The amount of data is used to represent the amount of training samples stored locally on the first client.
[0263] Optionally, the text processing model includes an encoder and a decoder, and the aforementioned storage medium is further configured to store program code for performing the following steps: performing natural language processing on preset data using the original model parameters corresponding to the target client and the decoder to obtain prototype features corresponding to the target client; uploading the prototype features corresponding to the target client to the server, wherein the target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client, the second model gradient uploaded by the second client, and the original model parameters corresponding to the target client, and the second client is obtained by the server clustering at least one client based on the prototype features uploaded by the target client and the prototype features uploaded by at least one client.
[0264] Optionally, the text processing model includes an encoder, and the aforementioned storage medium is further configured to store program code for performing the following steps: using the encoder to encode features of locally stored training samples to obtain encoded features corresponding to the target client; sending the encoded features corresponding to the target client to the server; receiving preset data returned by the server, wherein the preset data is generated by the server based on mixed features and the processing results corresponding to the mixed features, the mixed features are obtained by the server mixing the encoded features uploaded by the target client and at least one encoded feature uploaded by a client, and the processing results are obtained by the server processing the mixed features using a locally deployed preset processing model.
[0265] Optionally, the aforementioned storage medium is further configured to store program code for performing the following steps: obtaining a weighted sum of prototype features corresponding to the first client to obtain positive features, and obtaining a weighted sum of prototype features corresponding to the second client to obtain negative features; constructing a first loss function for the text processing model based on the prototype features, positive features, and negative features corresponding to the target client; constructing a second loss function for the text processing model based on the text processing results corresponding to the prototype features and the preset processing results corresponding to the locally stored training samples; and obtaining a weighted sum of the first loss function and the second loss function to obtain the total loss function of the text processing model.
[0266] Optionally, the aforementioned storage medium is further configured to store program code for performing the following steps: receiving a preset training task and initial model parameters sent by the server; executing the preset training task using locally stored training samples and initial model parameters to obtain the second model gradient corresponding to the target client; uploading the second model gradient corresponding to the target client to the server; receiving the original model parameters corresponding to the target client sent by the server, wherein the original model parameters are obtained by aggregating the second model gradient uploaded by the third client and the initial model parameters, the third client being a client in the client set to which the target client belongs, the client set being obtained by the server clustering multiple clients based on the second model gradients uploaded by multiple clients, the multiple clients including the target client and at least one client.
[0267] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: if the processing model deployed locally by the target client does not contain a preset structure, the target client receives a preset parameter model sent by the server; the target client constructs a preset structure locally based on the preset parameter model.
[0268] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: the target client receives the original model parameters corresponding to the target client sent by the server; the target client trains the locally deployed processing model using locally stored training samples and the corresponding original model parameters to obtain the first model gradient corresponding to the target client; the target client sends the first model gradient corresponding to the target client to the server and receives the target model parameters corresponding to the target client sent by the server, wherein the target model parameters are obtained by aggregating the original model parameters and the first model gradient uploaded by the first client, the first client being a client in the first client set corresponding to the target client, and the first client set being obtained by clustering multiple clients based on multiple first model gradients sent by multiple clients; the target client updates the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client to obtain a text processing model, wherein the text processing model is used to perform natural language processing on the text data to be processed.
[0269] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: the server sends the original model parameters corresponding to multiple clients to multiple clients, and receives the first model gradient uploaded by multiple clients, wherein the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters; the server clusters the multiple clients based on the first model gradient uploaded by multiple clients to obtain a first client corresponding to each client; the server aggregates the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client; the server sends the target model parameters corresponding to multiple clients to multiple clients, wherein the target model parameters are used to update the model parameters of the locally deployed processing model.
[0270] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: the target client acquires an image to be processed; the target client uses an image processing model to process the image to be processed, and obtains the image processing result of the image to be processed; wherein, the image processing model is deployed locally on the target client, the model parameters of the image processing model are the target model parameters sent by the server, the target model parameters are obtained by the server aggregating the original model parameters corresponding to the target client based on the first model gradient uploaded by the first client, the first client is obtained by the server clustering at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client, and the first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
[0271] In this embodiment, the server clusters at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by at least one client to obtain a first client. The server aggregates the first model gradient uploaded by the first client and the original model parameters corresponding to the target client to obtain template model parameters. The server sends the target model parameters to the target client as model parameters for the text processing model to train the text processing model. Then, during the model inference process, the target client obtains the text data to be processed and uses the text processing model to perform natural language processing on the text data to obtain the text processing result. It is worth noting that a unique global model is set for different clients, that is, unique original model parameters are given to different clients, and the model parameters are aggregated based on the similar client set of different clients to achieve the purpose of federated learning. On the one hand, it improves the correlation between different clients and ensures the accuracy of the processing results. On the other hand, it also improves the personalization of each client, making federated learning more flexible in natural language processing and achieving better federated learning results. This solves the technical problem that federated learning has a large impact on the model performance of clients in heterogeneous scenarios, which limits the application of federated learning.
[0272] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0273] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0274] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of units or modules may be electrical or other forms.
[0275] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0276] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0277] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0278] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A text processing method, characterized in that, include: The target client obtains the text data to be processed; The target client uses a text processing model to perform natural language processing on the text data to be processed, and obtains the text processing result of the text data to be processed. The text processing model is deployed locally on the target client. The model parameters of the text processing model are the target model parameters sent by the server. The target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client and the original model parameters corresponding to the target client. The first client is used to represent the similarity between the processing model deployed locally on the target client and the processing model deployed locally on at least one client. The clients in the client cluster obtained by clustering the at least one client have different model structures, training tasks, and sample types. The at least one client is a client other than the target client among multiple clients. The processing models deployed locally on multiple clients are obtained by pre-training with the same pre-training task assigned.
2. The method according to claim 1, characterized in that, The first client is obtained by the server clustering the at least one client based on the similarity between the first model gradient uploaded by the target client and the first model gradient uploaded by the at least one client. The first model gradient is obtained by each client processing the locally deployed processing model using locally stored training samples and corresponding original model parameters.
3. The method according to claim 1, characterized in that, The text processing model includes an encoder and a decoder, and the method further includes: Using the original model parameters corresponding to the target client and the decoder, natural language processing is performed on the preset data to obtain the prototype features corresponding to the target client; The prototype features corresponding to the target client are uploaded to the server. The target model parameters are obtained by the server aggregating the first model gradient uploaded by the first client, the second model gradient uploaded by the second client, and the original model parameters corresponding to the target client. The second client is obtained by the server clustering the at least one client based on the prototype features uploaded by the target client and the prototype features uploaded by the at least one client.
4. The method according to claim 3, characterized in that, The text processing model includes an encoder, and the method further includes: The encoder is used to encode the features of the locally stored training samples to obtain the encoded features corresponding to the target client; Send the encoded features corresponding to the target client to the server; The server receives the preset data returned by the server, wherein the preset data is generated by the server based on the hybrid features and the processing results corresponding to the hybrid features, the hybrid features are obtained by the server mixing the encoded features uploaded by the target client and the encoded features uploaded by at least one client, and the processing results are obtained by the server processing the hybrid features using a locally deployed preset processing model.
5. The method according to claim 3, characterized in that, The method further includes: Obtain the weighted sum of the prototype features corresponding to the first client to obtain the positive features, and obtain the weighted sum of the prototype features corresponding to the second client to obtain the negative features; Based on the prototype features, positive features, and negative features corresponding to the target client, a first loss function for the text processing model is constructed. Based on the text processing results corresponding to the prototype features and the preset processing results corresponding to the locally stored training samples, a second loss function for the text processing model is constructed. The total loss function of the text processing model is obtained by weighting the first loss function and the second loss function.
6. The method according to claim 1, characterized in that, The method further includes: Receive the preset training task and initial model parameters sent by the server; The preset training task is executed using locally stored training samples and the initial model parameters to obtain the second model gradient corresponding to the target client; Upload the second model gradient corresponding to the target client to the server; The server receives the original model parameters corresponding to the target client, wherein the original model parameters are obtained by aggregating the second model gradient uploaded by the third client and the initial model parameters. The third client is a client in the client set to which the target client belongs. The client set is obtained by the server clustering the multiple clients based on the second model gradient uploaded by the multiple clients.
7. The method according to claim 1, characterized in that, The first client is obtained by the server by clustering the at least one client based on a target training strategy. The target training strategy is determined by the server from multiple training strategies based on the difference type between the text processing model and the processing model deployed on the at least one client. Different training strategies are used to train models with different difference types.
8. The method according to claim 7, characterized in that, The difference types include at least one of the following: differences in training samples, differences in training tasks, and differences in model structure. The multiple training strategies include: a first granularity clustering strategy, a second granularity clustering strategy, and a prototype feature clustering strategy. The first granularity clustering strategy uses a larger clustering granularity than the second granularity clustering strategy.
9. A model training method, characterized in that, include: The target client receives the original model parameters corresponding to the target client sent by the server; The target client uses locally stored training samples and corresponding original model parameters to train the locally deployed processing model, thereby obtaining the first model gradient corresponding to the target client. The target client sends the first model gradient corresponding to the target client to the server and receives the target model parameters corresponding to the target client sent by the server. The target model parameters are obtained by aggregating the original model parameters and the first model gradient uploaded by the first client. The first client is used to characterize the similarity between the processing model deployed locally on the target client and the processing model deployed locally on at least one client. The clients in the client cluster obtained by clustering the at least one client have different model structures, training tasks and sample types. The at least one client is a client other than the target client among multiple clients. The processing models deployed locally on multiple clients are obtained by pre-training with the same pre-training task assigned. The target client updates the model parameters of the locally deployed processing model based on the target model parameters corresponding to the target client to obtain a text processing model, wherein the text processing model is used to perform natural language processing on the text data to be processed.
10. A model training method, characterized in that, include: The server sends the original model parameters corresponding to multiple clients to the multiple clients, and receives the first model gradient uploaded by the multiple clients; The server aggregates the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client. The first client is used to characterize the similarity between the processing model deployed locally on the target client and the processing model deployed locally on at least one client. The clients in the client cluster obtained by clustering the at least one client have different model structures, training tasks and sample types for the processing models deployed locally on different clients. The at least one client is a client other than the target client among the multiple clients. The processing models deployed locally on the multiple clients are obtained by pre-training by assigning the same pre-training task. The server sends target model parameters corresponding to the multiple clients to the multiple clients, wherein the target model parameters are used to update the model parameters of the locally deployed processing model.
11. The method according to claim 10, characterized in that, Before aggregating the first model gradient uploaded by the first client corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client, the method further includes: Output confirmation information, wherein the confirmation information includes: the first client corresponding to each client; Receive feedback information corresponding to the information to be confirmed, wherein the feedback information includes: the feedback client corresponding to each client; The first model gradient uploaded by the feedback client corresponding to each client and the original model parameters corresponding to each client are aggregated to obtain the target model parameters corresponding to each client.
12. The method according to claim 10, characterized in that, The method further includes: Send a preset training task and initial model parameters to the plurality of clients, and receive the second model gradient uploaded by the plurality of clients, wherein the second model gradient is obtained by each client using locally stored training samples and the initial model parameters to execute the preset training task; Clustering is performed on the multiple clients based on multiple second model gradients to obtain the client set to which each client belongs; The initial model parameters are aggregated based on the second model gradient uploaded by each client to the client set to obtain the original model parameters corresponding to each client.
13. The method according to claim 12, characterized in that, The method further includes: Output multiple training tasks; Receive a selection operation performed on the plurality of training tasks; The training task corresponding to the selection operation is determined to be the preset training task.
14. A model training system, characterized in that, include: Multiple clients; The server is connected to the multiple clients and is used to generate the original model parameters corresponding to the multiple clients to the multiple clients. The multiple clients are used to train the locally deployed processing model using locally stored training text and corresponding original model parameters to obtain the first model gradient corresponding to the multiple clients. The server is further configured to cluster the multiple clients based on the first model gradients corresponding to the multiple clients, to obtain a first client corresponding to each client, and to aggregate the first model gradients uploaded by the first clients corresponding to each client and the original model parameters corresponding to each client to obtain the target model parameters corresponding to each client. The first client is used to characterize the similarity between the processing model deployed locally on the target client and the processing model deployed locally on at least one client. The clients in the client cluster obtained by clustering the at least one client have different model structures, training tasks and sample types for the processing models deployed locally on different clients. The processing models deployed locally on multiple clients are obtained by pre-training by assigning the same pre-training task. The multiple clients are also used to update the model parameters of the locally deployed processing model based on the corresponding target model parameters.