Federated learning improves data privacy and efficiency in machine learning performed over networks of distributed devices, such as mobile phones, IoT and wearable devices, etc. Yet models trained with federated learning can still fail to generalize to new devices due to the problem of domain shift. Domain shift occurs when the labeled data collected by source nodes statistically differs from the target node's unlabeled data. In this work, we present a principled approach to the problem of federated domain adaptation, which aims to align the representations learned among the different nodes with the data distribution of the target node. Our approach extends adversarial adaptation techniques to the constraints of the federated setting. In addition, we devise a dynamic attention mechanism and leverage feature disentanglement to enhance knowledge transfer. Empirically, we perform extensive experiments on several image and text classification tasks and show promising under unsupervised federated domain adaptation setting. Data generated by networks of mobile and IoT devices poses unique challenges for training machine learning models. Due to the growing storage/computational power of these devices and concerns about data privacy, it is increasingly attractive to keep data and computation locally on the device . Federated Learning (FL) (; ;) provides a privacy-preserving mechanism to leverage such decen-tralized data and computation resources to train machine learning models. The main idea behind federated learning is to have each node learn on its own local data and not share either the data or the model parameters. While federated learning promises better privacy and efficiency, existing methods ignore the fact that the data on each node are collected in a non-i.i.d manner, leading to domain shift between nodes . For example, one device may take photos mostly indoors, while another mostly outdoors. In this paper, we address the problem of transferring knowledge from the decentralized nodes to a new node with a different data domain, without requiring any additional supervision from the user. We define this novel problem Unsupervised Federated Domain Adaptation (UFDA), as illustrated in Figure 1 (a). There is a large body of existing work on unsupervised domain adaptation (; ; ; ;), but the federated setting presents several additional challenges. First, the data are stored locally and cannot be shared, which hampers mainstream domain adaptation methods as they need to access both the labeled source and unlabeled target data (; ; ; ; ;). Second, the model parameters are trained separately for each node and converge at different speeds, while also offering different contributions to the target node depending on how close the two domains are. Finally, the knowledge learned from source nodes is highly entangled , which can possibly lead to negative transfer . In this paper, we propose a solution to the above problems called Federated Adversarial Domain Adaptation (FADA) which aims to tackle domain shift in a federated learning system through adversarial techniques. Our approach preserves data privacy by training one model per source node and updating the target model with the aggregation of source gradients, but does so in a way that reduces domain shift. First, we analyze the federated domain adaptation problem from a theoretical perspective and provide a generalization bound. Inspired by our theoretical , we propose an Figure 1: (a) We propose an approach for the UFDA setting, where data are not shareable between different domains. In our approach, models are trained separately on each source domain and their gradients are aggregated with dynamic attention mechanism to update the target model. (b) Our FADA model learns to extract domain-invariant features using adversarial domain alignment (red lines) and a feature disentangler (blue lines). efficient adaptation algorithm based on adversarial adaptation and representation disentanglement applied to the federated setting. We also devise a dynamic attention model to cope with the varying convergence rates in the federated learning system. We conduct extensive experiments on real-world datasets, including image recognition and natural language tasks. Compared to baseline methods, we improve adaptation performance on all tasks, demonstrating the effectiveness of our devised model. Unsupervised Domain Adaptation Unsupervised Domain Adaptation (UDA) aims to transfer the knowledge learned from a labeled source domain to an unlabeled target domain. Domain adaptation approaches proposed over the past decade include discrepancy-based methods (; ; ; ;, reconstructionbased UDA models (; ;), and adversary-based approaches (; ; a;). For example, propose a gradient reversal layer to perform adversarial training to a domain discriminator, inspired by the idea of adversarial learning. address unsupervised domain adaptation by adapting a deep CNN-based feature extractor/classifier across source and target domains via adversarial training. introduce an H∆H-divergence to evaluate the domain shift and provide a generalization error bound for domain adaptation. These methods assume the data are centralized on one server, limiting their applicability to the distributed learning system. Federated Learning Federated learning (; ; ;) is a decentralized learning approach which enables multiple clients to collaboratively learn a machine learning model while keeping the training data and model parameters on local devices. Inspired by Homomorphic Encryption , gilad2016cryptonets propose CryptoNets to enhance the efficiency of data encryption, achieving higher federated learning performance. introduce a secure aggregation scheme to update the machine learning models under their federated learning framework. propose SecureML to support privacy-preserving collaborative training in a multi-client federated learning system. However, these methods mainly aim to learn a single global model across the data and have no convergence guarantee, which limits their ability to deal with non-i.i.d. data. To address the non-i.i.d data, introduce federated multi-task learning, which learns a separate model for each node. Liu et al. (2018b) propose semi-supervised federated transfer learning in a privacy-preserving setting. However, their models involve full or semi-supervision. The work proposed here is, to our best knowledge, the first federated learning framework to consider unsupervised domain adaptation. Feature Disentanglement Deep neural networks are known to extract features where multiple hidden factors are highly entangled. Learning disentangled representations can help remove irrelevant and domain-specific features and model only the relevant factors of data variation. To this end, recent work (; ; a;) explores the learning of interpretable representations using generative adversarial networks (GANs) and variational autoencoders (VAEs) . Under the fully supervised setting, propose an auxiliary classifier GAN (AC-GAN) to achieve representation disentanglement. (a) introduce a unified feature disentanglement framework to learn domain-invariant features from data across different domains. also extend VAEs into the semi-supervised setting for representation disentanglement. propose to disentangle the features into a domain-invariant content space and a domainspecific attributes space, producing diverse outputs without paired training data. Inspired by these works, we propose a method to disentangle the domain-invariant features from domain-specific features, using an adversarial training process. In addition, we propose to minimize the mutual information between the domain-invariant features and domain-specific features to enhance the feature disentanglement. We first define the notation and review a typical theoretical error bound for single-source domain adaptation devised by Ben-David et al. Then we describe our derived error bound for unsupervised federated domain adaptation. We mainly focus on the high-level interpretation of the error bound here and refer our readers to the appendix (see supplementary material) for proof details. Notation. Let D S 1 and D T denote source and target distribution on input space X and a ground-truth labeling function g: X → {0, 1}. A hypothesis is a function h: X → {0, 1} with the error w.r.t the ground-truth labeling function g: We denote the risk and empirical risk of hypothesis h on D S as S (h) and S (h). Similarly, the risk and empirical risk of h on D T are denoted as T (h) and T (h). The H-divergence between two distributions D and D is defined as: where H is a hypothesis class for input space X, and A H denotes the collection of subsets of X that are the support of some hypothesis in H. The symmetric difference space H∆H is defined as: H∆H:= {h(x) ⊕ h (x))|h, h ∈ H}, (⊕: the XOR operation). We denote the optimal hypothesis that achieves the minimum risk on the source and the target as h *:= arg min h∈H S (h) + T (h) and the error of h * as λ:= S (h *) + T (h *). Blitzer et al. (2007b) prove the following error bound on the target domain. Theorem 1. Let H be a hypothesis space of V C-dimension d and D S, D T be the empirical distribution induced by samples of size m drawn from D S and D T. Then with probability at least 1 − δ over the choice of samples, for each h ∈ H,, and be N source domains and the target domain in a UFDA system, where. In federated domain adaptation system, D S is distributed on N nodes and the data are not shareable with each other in the training process. The classical domain adaptation algorithms aim to minimize the target risk T (h):= Pr (x,y)∼D T [h(x) = y]. However, in a UFDA system, one model cannot directly get access to data stored on different nodes for security and privacy reasons. To address this issue, we propose to learn separate models for each distributed. The target hypothesis h T is the aggregation of the parameters of h S, i.e. We can then derive the following error bound: Theorem 2. (Weighted error bound for federated domain adaptation). Let H be a hypothesis class with VC-dimension d and, D T be empirical distributions induced by a sample of size m from each source domain and target domain in a federated learning system, respectively. Then, ∀α ∈ R N +, N i=1 α i = 1, with probability at least 1 − δ over the choice of samples, for each h ∈ H, 1 In this literature, the calligraphic D denotes data distribution, and italic D denotes domain discriminator. where λ i is the risk of the optimal hypothesis on the mixture of D Si and T, andS is the mixture of source samples with size N m. d H∆H (D Si, D T) denotes the divergence between domain S i and T. Comparison with Existing Bounds The bound in is extended from and they are equivalent if only one source domain exists (N = 1). provide a generalization bound for multiple-source domain adaptation, assuming that the target domain is a mixture of the N source domains. In contrast, in our error bound, the target domain is assumed to be an novel domain, ing in a bound involving H∆H discrepancy and the VC-dimensional constraint . Blitzer et al. (2007b) propose a generalization bound for semisupervised multi-source domain adaptation, assuming that partial target labels are available. Our generalization bound is devised for unsupervised learning. introduce classification and regression error bounds for multi-source domain adaptation. However, these error bounds assume that the multiple source and target domains exactly share the same hypothesis. In contrast, our error bound involves multiple hypotheses. The error bound in Theorem demonstrates the importance of the weight α and the discrepancy Inspired by this, we propose dynamic attention model to learn the weight α and federated adversarial alignment to minimize the discrepancy between the source and target domains, as shown in Figure 1. In addition, we leverage representation disentanglement to extract domain-invariant representations to further enhance knowledge transfer. Dynamic Attention In a federated domain adaptation system, the models on different nodes have different convergence rates. In addition, the domain shifts between the source domains and target domain are different, leading to a phenomenon where some nodes may have no contribution or even negative transfer to the target domain. To address this issue, we propose dynamic attention, which is a mask on the gradients from source domains. The philosophy behind the dynamic attention is to increase the weight of those nodes whose gradients are beneficial to the target domain and limit the weight of those whose gradients are detrimental to the target domain. Specifically, we leverage the gap statistics to evaluate how well the target features f t can be clustered with unsupervised clustering algorithms (K-Means). Assuming we have k clusters, the gap statistics are computed as: where we have clusters C 1, C 2,..., C k, with C r denoting the indices of observations in cluster r, and n r =|C r |. Intuitively, a smaller gap statistics value indicates the feature distribution has smaller intraclass variance. We measure the contribution of each source domain by the gap statistics gain between two consecutive iterations: (p indicating training step), denoting how much the clusters can be improved before and after the target model is updated with the i-th source model's gradient. The mask on the gradients from source domains is defined as Sof tmax(I Federated Adversarial Alignment The performance of machine learning models degrades rapidly with the presence of domain discrepancy . To address this issue, existing work proposes to minimize the discrepancy with an adversarial training process. For example, proposes the domain confusion objective, under which the feature extractor is trained with a cross-entropy loss against a uniform distribution. However, these models require access to the source and target data simultaneously, which is prohibitive in UFDA. In the federated setting, we have multiple source domains and the data are locally stored in a privacy-preserving manner, which means we cannot train a single model which has access to the source domain and target domain simultaneously. To address this issue, we propose federated adversarial alignment that divides optimization into two independent steps, a domain-specific local feature extractor and a global discriminator. Specifically, for each domain, we train a local feature extractor, G i for D i and G t for D t, for each (D i, D t) source-target domain pair, we train an adversarial domain identifier DI to align the distributions in an adversarial manner: we first train DI to identify which domain are the features come from, then we train the generator (G i, G t) to confuse the DI. Note that D only gets access to the output vectors of G i and G t, without violating the UFDA Sample mini-batch from from {(x Compute gradient with cross-entropy classification loss, update Update with Eq. 4 and Eq. 5 respectively to align the domain distribution; 7: Domain Disentangle: 8: update Update .. Θ C N} respectively with the computed dynamic weight; 17: end while setting. Given the i-th source domain data X Si, target data X T, the objective for DI i is defined as follows: In the second step, L adv D remains unchanged, but L adv G is updated with the following objective: Representation Disentanglement We employ adversarial disentanglement to extract the domaininvariant features. The high-level intuition is to disentangle the features extracted by (G i, G t) into domain-invariant and domain-specific features. As shown in Figure 1(b), the disentangler D i separates the extracted features into two branches. Specifically, we first train the K-way classifier C i and K-way class identifier CI i to correctly predict the labels with a cross-entropy loss, based on f di and f ds features, respectively. The objective is: where ) denote the domain-invariant and domain-specific features respectively. In the next step, we freeze the class identifier CI i and only train the feature disentangler to confuse the class identifier CI i by generating the domain-specific features f ds, as shown in Figure 1. This can be achieved by minimizing the negative entropy loss of the predicted class distribution. The objective is as follows: Feature disentanglement facilitates the knowledge transfer by reserving f di and dispelling f ds. To enhance the disentanglement, we minimize the mutual information between domain-invariant features and domain-specific features, following. Specifically, the mutual information is The most gorgeous artwork in comic books. It contains the most extraordinary and finest artwork of Alex Ross. In my opinion it is the best American animated film ever released. It has a beautiful story with a ton of laughs, a lot of teachable moments. My advice is if you need a CD rack that holds a lot of CD's? Save your money and invest in something nicer and more sturdy. I absolutely love this product. my neighbor has four little yippers and my hepard/chow mix was antogonized on our side of the fence. defined as I(f di ; f ds) = P×Q log dP PQ dP P ⊗P Q dP PQ, where P PQ is the joint probability distribution of (f di, f ds), and P P = Q dP PQ, P Q = Q dP PQ are the marginals. Despite being a pivotal measure across different distributions, the mutual information is only tractable for discrete variables, for a limited family of problems where the probability distributions are unknown . , we adopt the Mutual Information Neural Estimator (MINE) to estimate the mutual information by leveraging a neural network. Practically, MINE can be calculated p,q,θ) ). To avoid computing the integrals, we leverage Monte-Carlo integration to calculate the estimation: where (p, q) are sampled from the joint distribution, q is sampled from the marginal distribution, and T (p, q, θ) is the neural network parameteralized by θ to estimate the mutual information between P and Q, we refer the reader to MINE for implementation details. The domain-invariant and domain-specific features are forwarded to a reconstructor with a L2 loss to reconstruct the original features, aming to keep the representation integrity, as shown in Figure 1(b). The balance of the L2 reconstruction and mutual information can be achieved by adjusting the hyper-parameters of the L2 loss and mutual information loss. Optimization Our model is trained in an end-to-end fashion. We train federated alignment and representation disentanglement component with Stochastic Gradient Descent . The federated adversarial alignment loss and representation disentanglement loss are minimized together with the task loss. The detailed training procedure is presented in Algorithm 1. We test our model on the following tasks: digit classification (Digit-Five), object recognition (OfficeCaltech10 , DomainNet ) and sentiment analysis (Amazon Review dataset (a) ). Figure 2 shows some data samples and Table 9 (see supplementary material) shows the number of data per domain we used in our experiments. We perform our experiments on a 10 Titan-Xp GPU cluster and simulate the federated system on a single machine (as the data communication is not the main focus of this paper). Our model is implemented with PyTorch. We repeat every experiment 10 times on the Digit-Five and Amazon Review datasets, and 5 times on the Office-Caltech10 and DomainNet datasets, reporting the mean and standard derivation of accuracy. To better explore the effectiveness of different components of our model, we propose three different ablations, i.e. model I: with dynamic attention; model II: I + adversarial alignment; and model III: II + representation disentanglement. and the rest as the distributed source domains, leading to five transfer tasks. The detailed architecture of our model can be found in Table 7 (see supplementary material). Since many DA models (; ;) require access to data from different domains, it is infeasible to directly compare our model to these baselines. Instead, we compare our model to the following popular domain adaptation baselines: Domain Adversarial Neural Network (DANN) , Deep Adaptation Network (DAN) , Automatic DomaIn Alignment Layers (AutoDIAL) , and Adaptive Batch Normalization (AdaBN). Specifically, DANN minimizes the domain gap between source domain and target domain with a gradient reversal layer. DAN applies multi-kernel MMD loss to align the source domain with the target domain in Reproducing Kernel Hilbert Space. AutoDIAL introduces domain alignment layer to deep models to match the source and target feature distributions to a reference one. AdaBN applies Batch Normalization layer to facilitate the knowledge transfer between the source and target domains. When conducting the baseline experiments, we use the code provided by the authors and modify the original settings to fit federated DA setting (i.e. each domain has its own model), denoted by f -DAN and f -DANN. In addition, to demonstrate the difficulty of UFDA where accessing all source data with a single model is prohibative, we also perform the corresponding multi-source DA experiments (shared source data). The experimental are shown in To dive deeper into the feature representation of our model versus other baselines, we plot in Figure 3 (a)-3(d) the t-SNE embeddings of the feature representations learned on mm,mt,sv,sy→up task with source-only features, f -DANN features, f -DAN features and FADA features, respectively. We observe that the feature embeddings of our model have smaller intra-class variance and larger inter-class variance than f -DANN and f -DAN, demonstrating that our model is capable of generating the desired feature embedding and can extract domain-invariant features across different domains. Office-Caltech10 This dataset contains 10 common categories shared by Office-31 and Caltech-256 datasets . It contains four domains: Caltech (C), which are sampled from Caltech-256 dataset, Amazon (A), which contains images collected from amazon.com, Webcam (W) and DSLR (D), which contains images taken by web camera and DSLR camera under office environment. We leverage two popular networks as the backbone of feature generator G, i.e. AlexNet and ResNet . Both the networks are pre-trained on ImageNet . Other components of our model are randomly initialized with the normal distribution. In the learning process, we set the learning rate of randomly initialized parameters to ten times of the pre-trained parameters as it will take more time for those parameters to converge. Details of our model are listed in Table 9 (supplementary material). The experimental on Office-Caltech10 datasets are shown in Table 2. We utilize the same backbones as the baselines and separately show the . We make the following observations from the : Our model achieves 86.5% accuracy with an AlexNet Table 3: Accuracy (%) on the DomainNet dataset dataset under UFDA protocol. The upper table shows the based on AlexNet backbone and the table below are the based on ResNet Table 4: Accuracy (%) on "Amazon Review" dataset with unsupervised federated domain adaptation protocol. backbone and 87.1% accuracy with a ResNet backbone, outperforming the compared baselines., we calculate the approximate A-distanced A = 2 (1 − 2) for C,D,W→A and A,C,W→D tasks, where is the generalization error of a two-sample classifier (e.g. kernel SVM) trained on the binary problem of distinguishing input samples between the source and target domains. In Figure 4 (a), we plot for tasks with raw ResNet features, f -DANN features, and FADA features, respectively. We observe that thed A on DADA features are smaller than ResNet features and f -DANN features, demonstrating that FADA features are harder to be distinguished between source and target. To show how the dynamic attention mechanism benefits the training process, we plot the training loss w/ or w/o dynamic weights for A,C,W→D task in Figure 4 (b). The figure shows the target model's training error is much smaller when dynamic attention is applied, which is consistent with the quantitative . In addition, in A,C,W→D setting, the weight of A decreases to the lower bound after first a few epochs and the weight of W increases during the training process, as photos in both D and W are taken in the same environment with different cameras. To better analyze the error mode, we plot the confusion matrices for f -DAN and FADA on A,C,D->W task in Figure 4 (c)-4(d). The figures show that f -DAN mainly confuses "calculator" vs. "keyboard", "backpack" with "headphones", while FADA is able to distinguish them with disentangled features. Table 5: The ablation study show that the dynamic attention module is essential for our model. (rel, photos and real world images; and Sketch (skt), sketches of specific objects. This dataset is very large-scale and contains rich and informative vision cues across different domains, providing a good testbed for unsupervised federated domain adaptation. Some sample images can be found in Figure 2. Results The experimental on DomainNet are shown in Table 3. Our model achieves 28.9% and 30.3% accuracy with AlexNet and ResNet backbone, respectively. In both scenarios, our model outperforms the baselines, demonstrating the effectiveness of our model on large-scale dataset. Note that this dataset contains about 0.6 million images, and so even a one-percent performance improvement is not trivial. From the experiment , we can observe that all the models deliver less desirable performance when infograph and quickdraw are selected as the target domains. This phenomenon is mainly caused by the large domain shift between inf /qdr domain and other domains. Amazon Review (a) This dataset provides a testbed for cross-domain sentimental analysis of text. The task is to identify whether the sentiment of the reviews is positive or negative. The dataset contains reviews from amazon.com users for four popular merchandise categories: Books (B), DVDs (D), Electronics (E), and Kitchen appliances (K). , we utilize 400-dimensional bag-of-words representation and leverage a fully connected deep neural network as the backbone. The detailed architecture of our model can be found in Table 8 (supplementary materials). The experimental on Amazon Review dataset are shown in Table 4. Our model achieves an accuracy of 78.9% and outperforms the compared baselines. We make two major observations from the : Our model is not only effective on vision tasks but also performs well on linguistic tasks under UFDA learning schema. From the of model I and II, we can observe the dynamic attention and federated adversarial alignment are beneficial to improve the performance. However, the performance boost from Model II to Model III is limited. This phenomenon shows that the linguistic features are harder to disentangle comparing to visual features. To demonstrate the effectiveness of dynamic attention, we perform the ablation study analysis. The Table 5 shows the on "Digit-Five", Office-Caltech10 and Amazon Review benchmark. We observe that the performance drops in most of the experiments when dynamic attention model is not applied. The dynamic attention model is devised to cope with the varying convergence rates in the federated learning system, i.e., different source domains have their own convergence rate. In addition, it will increase the weight of a specific domain when the domain shift between that domain and the target domain is small, and decrease the weight otherwise. In this paper, we first proposed a novel unsupervised federated domain adaptation (UFDA) problem and derived a theoretical generalization bound for UFDA. Inspired by the theoretical , we proposed a novel model called Federated Adversarial Domain Adaptation (FADA) to transfer the knowledge learned from distributed source domains to an unlabeled target domain with a novel dynamic attention schema. Empirically, we showed that feature disentanglement boosts the performance of FADA in UFDA tasks. An extensive empirical evaluation on UFDA vision and linguistic benchmarks demonstrated the efficacy of FADA against several domain adaptation baselines. We provide the explanations of notations occurred in this paper. Table 6: Notations occurred in the paper. We provide the detailed model architecture (Table 7 and Table 7 : Model architecture for digit recognition task ("Digit-Five" dataset). For each convolution layer, we list the input dimension, output dimension, kernel size, stride, and padding. For the fullyconnected layer, we provide the input and output dimensions. For drop-out layers, we provide the probability of an element to be zeroed. We provide the detailed information of datasets. For Digit-Five and DomainNet, we provide the train/test split for each domain. For Office-Caltech10, we provide the number of images in each domain. For Amazon review dataset, we show the detailed number of positive reviews and negative reviews for each merchandise category. Table 9: Model architecture for image recognition task (Office-Caltech10 and DomainNet ). For each convolution layer, we list the input dimension, output dimension, kernel size, stride, and padding. For the fully-connected layer, we provide the input and output dimensions. For drop-out layers, we provide the probability of an element to be zeroed. Remark. The equation in Theorem 2 provides a theoretical error bound for unsupervised federated domain adaptation as it assumes that the source data distributed on different nodes can form a mixture source domain. In fact, the data on different node can not be shared under the federated learning schema. The theoretical error bound is only valid when the weights of models on all the nodes are fully synchronized.
we present a principled approach to the problem of federated domain adaptation, which aims to align the representations learned among the different nodes with the data distribution of the target node.