Currently, deep learning is criticized because it is data hungry, has limited capacity for transfer, insufficiently integrates prior knowledge, and presumes a largely stable world (Marcus, 2018) . In particular, these problems appear after a domain shift, that is, a change of the input-target distribution. A domain shift forces deep learning models to adapt. The goal is to exploit models that were trained on the typically rich original data for solving tasks from the new domain with much less data. Examples for domain shifts are new users or customers, new products and product lines, new diseases (e.g. adapting from SARS to COVID19), new images from another field (e.g. from cats to dogs or from cats to bicycles), new social behaviors after societal change (e.g. introduction of cell phones, pandemic), self-driving cars in new cities or countries (e.g. from European countries to Arabic countries), and robot manipulation of new objects.
Domain shifts are often tackled by meta-learning (Schmidhuber, 1987; Bengio et al., 1990; Hochreiter et al., 2001) , since it exploits already acquired knowledge to adapt to new data. One prominent application of meta-learning dealing with domain shifts is few-shot learning, since, typically, from the new domain much less data is available than from the original domain. Meta-learning methods perform well on small domain shifts like new target classes with similar inputs. However, larger domain shifts are still challenging for current approaches. Large domain shifts lead to inputs, Related work. Representation fusion builds on learning a meaningful representation (Bengio et al., 2013; Girshick et al., 2014) at multiple levels of abstraction (LeCun et al., 2015; Schmidhuber, 2015) . The concept of using representations from different layers of abstraction has been used in CNN architectures (LeCun et al., 1998) such as ; Rumetshofer et al. (2018) ; Hofmarcher et al. (2019) , in CNNs for semantic segmentation in the form of multi-scale context pooling (Yu & Koltun, 2015; , and in the form of context capturing and symmetric upsampling (Ronneberger et al., 2015) . Work on domain shifts discusses the problem that new inputs are considerably different from the original inputs (Kouw & Loog, 2019; Wouter, 2018; Webb et al., 2018; Gama et al., 2014; Widmer & Kubat, 1996) . Domain adaptation (Pan & Yang, 2009; Ben-David et al., 2010) overcomes this problem by e.g. reweighting the original samples (Jiayuan et al., 2007) or learning a classifier in the new domain. Domain adaptation where only few data is available in the new domain (Ben-David et al., 2010; Lu et al., 2020) is called cross-domain few-shot learning Lu et al., 2020; Tseng et al., 2020) , which is an instance of the general few-shot learning setting (Fei-Fei et al., 2006) . Few-shot learning can be roughly divided into three approaches (Lu et al., 2020; Hospedales et al., 2020) : (i) augmentation, (ii) metric learning, and (iii) meta-learning. For (i), where the idea is to learn an augmentation to produce more than the few samples available, supervised (Dixit et al., 2017; Kwitt et al., 2016) and unsupervised (Hariharan & Girshick, 2017; Pahde et al., 2019; Gao et al., 2018) methods are considered. For (ii), approaches aim to learn a pairwise similarity metric under which similar samples obtain high similarity scores (Koch et al., 2015; Ye & Guo, 2018; Hertz et al., 2006) . For (iii), methods comprise embedding and nearest-neighbor approaches (Snell et al., 2017b; Sung et al., 2018; Vinyals et al., 2016) , finetuning approaches (Finn et al., 2017; Rajeswaran et al., 2019; Ravi & Larochelle, 2017; Andrychowicz et al., 2016) , and parametrized approaches (Gidaris & Komodakis, 2018; Ye et al., 2020; Yoon et al., 2019; Mishra et al., 2018; Hou et al., 2019; Rusu et al., 2018) . Few-shot classification under domain shifts for metric-based methods has been discussed in Tseng et al. (2020) . Ensemble methods for few-shot learning have been applied in Dvornik et al. (2019) , where an ensemble of distance-based classifiers is designed from different networks. In contrast, our method builds an ensemble of different layers from the same network. Hebbian learning as part of a few-shot learning method has been implemented in Munkhdalai & Trischler (2018) , where fast weights that are used for binding labels to representations are generated by a Hebbian learning rule.
Domain shifts. We assume to have data (x, y), where x ∈ X is the input data and y ∈ Y is the target data. A domain is a distribution p over X × Y assigning each pair (x, y) a probability p(x, y). A domain shift is a change from p(x, y) top(x, y). We measure the magnitude of the domain shift by a distance d(p,p) between the distributions p andp. We consider four types of domain shifts (Kouw & Loog, 2019; Wouter, 2018; Webb et al., 2018; Gama et al., 2014; Widmer & Kubat, 1996) :
• Prior shift (small domain shift): p(y) is changed top(y), while p(x | y) stays the same. For example, when new classes are considered (typical case in few-shot learning):
• Covariate shift (large domain shift): p(x) is changed top(x), while p(y | x) stays the same. For example, when new inputs are considered, which occurs when going from color to grayscale images, using a new measurement device, or looking at traffic data from different continents: p(x, y) = p(x)p(y | x) andp(x, y) =p(x)p(y | x).
• Concept shift: p(y | x) is changed top(y | x), while p(x) stays the same. For example, when including new aspects changes the decision boundaries: p(x, y) = p(x)p(y | x) and p(x, y) = p(x)p(y | x).
• General domain shift: domain shift between p(x, y) top(x, y). For example, going from Imagenet data to grayscale X-ray images (typical case in cross-domain datasets).
Domain shift for images. We consider the special case that the input x is an image. In general, domain shifts can be measured on the raw image distributions e.g. by using the H-divergence (Ben-David et al., 2010) . However, distances between raw image distributions were shown to be less meaningful in computer vision tasks than abstract representations of deep neural networks (Heusel et al., 2017; Salimans et al., 2016) . We approximate the distance between the joint distributions d(p(x, y),p(x, y)) by the distance between the marginals d(p(x),p(x)), which is exact in the case of the covariate shift for certain choices of d(·, ·), like e.g. the Jensen-Shannon divergence. For the distance between the marginals d(p(x),p(x)) we use the Fréchet Inception Distance (FID; Heusel et al., 2017) , which has proven reliable for measuring performance of Generative Adversarial Networks (Goodfellow et al., 2014) .
Cross-domain few-shot learning. Large domain shifts lead to inputs, which are considerably different from the original inputs. As a result, the model trained on the original domain will not work anymore on the new domain. To overcome this problem, domain adaptation techniques are applied (Pan & Yang, 2009; Ben-David et al., 2010) . Domain adaption can be achieved in several ways, e.g. by reweighting the original samples (Jiayuan et al., 2007) . Another possibility is to learn a classifier in the new domain. Domain adaptation where in the new domain only few data is available (Ben-David et al., 2010) which can be used for learning is called cross-domain few-shot learning Lu et al., 2020; Tseng et al., 2020) . In an N -shot K-way few-shot learning setting, the training set (in meta learning also called one episode) consists of N samples for each of the K classes. 
We propose a new cross-domain few-shot learning method, CHEF, that consists of an ensemble of Hebbian learners built on representation fusion. Figure 1 sketches our CHEF approach. In principle, any learning algorithm can be used for representation fusion. We choose a Hebbian learning rule because it is simple and fast while being robust and reliable.
Hebbian few-shot learning built on representation fusion. CHEF builds its ensemble of Hebbian learners using representation fusion. Deep learning models (LeCun et al., 2015) provide hierarchical representations that allow to fuse information from different layers of abstraction. In contrast to many other methods, CHEF does not require backpropagation of error signals through the entire backbone network. Only the parameters of the Hebbian learners that are obtained for the uppermost layers need adjustment. This makes CHEF extremely fast and versatile.
Obtaining one Hebbian Learner. We consider an N -shot K-way few-shot learning setting. Let z i ∈ R D be a feature vector obtained from activating a pre-trained backbone network with a sample x i up to a certain layer, where D is the number of units in that layer. We combine the N K feature vectors into a matrix Z ∈ R N K×D and initialize a weight matrix W ∈ R K×D . In accordance with Hebb (2005) ; Frégnac (2002) , we use the Hebbian learning rule
for a given number of steps, where α is a Hebbian learning rate and V ∈ R N K×K is the matrix of postsynaptic responses v i . We design the number of steps for which to run equation 1 as a hyperparameter of our method. Given a loss function L(·, ·) and few-shot labels y i , we choose the postsynaptic response
We initialize the weight matrix W with zeros. In principle, any other initialization is possible. However, the learning rule is designed for rather strong updates and, therefore, the initialization scheme is of minor importance.
Combining several Hebbian Learners. The closer a layer is to the network output the more specific are its features. Conversely, the closer a layer is to the input of the network, the more general are the features. In cross-domain few-shot learning, it is not a priori clear how specific or general the features should be because this depends on how close the target domain is to the training domain.
Therefore, we design our few-shot learning algorithm such that it can flexibly choose the specificity of the features depending on the current episode. We achieve this by representation fusion, where the Hebbian learning rule is applied to several layers at different levels of the backbone network in parallel. This yields a separate prediction for each level of abstraction. The final classification result is then obtained from the sum of logits arising from the respective Hebbian learners. A schematic view of CHEF is shown in Alg. 1.
Algorithm 1 CHEF algorithm. The data matrix X consists of input vectors x i and the label matrix Y consists of the corresponding label vectors y i . The function BB activates the backbone network up to a certain layer specified by an index l. L is the set of indices specifying the layers used in the ensemble, L is the loss function of the few-shot learning task at hand. The function HEBBRULE executes M steps of the Hebbian learning rule and yields a weight matrix W that maps the feature vectors in Z to vectors of length K, which are then used for K-fold classification. α is the Hebbian learning rate.
We apply CHEF to four cross-domain few-shot challenges, where we obtain state-of-the-art results in all categories. The four cross-domain few-shot challenges are characterized by domain shifts of different size, which we measure using the Fréchet-Inception-Distance (FID). We conduct ablation studies showing the influence of the different layer representations on the results. Further, we test CHEF on two standardized image-based few-shot classification benchmark datasets established in the field, which are characterized by a prior domain shift: miniImagenet (Vinyals et al., 2016) and tieredImagenet (Ren et al., 2018) . Finally, we illustrate the impact of our CHEF approach on two real-world applications in the field of drug discovery, which are characterized first by a small domain shift and second by a large domain shift.
Dataset and evaluation. The cross-domain few-shot learning challenge uses miniImagenet as training domain and then evaluates the trained models on four different test domains with increasing distance to the training domain: 1) CropDisease (Mohanty et al., 2016) consisting of plant disease images, 2) EuroSAT (Helber et al., 2019) , a collection of satellite images, 3) ISIC2018 (Tschandl et al., 2018; containing dermoscopic images of skin lesions, and 4) ChestX (Wang et al., 2017) containing a set of X-ray images. For evaluation, we measure the accuracy drawing 800 tasks (five test instances per class) from the cross-domain test set. Following prior work, we focus on 5-way/5-shot, 5-way/20-shot, and 5-way/50-shot tasks. We report the average accuracy and a 95 % confidence interval across all test images and tasks.
Measuring the domain shifts via FID. In , the four datasets of the new domain are characterized by their distance to the original domain using three criteria: whether images contain perspective distortion, the semantic content of images, and color depth. In Table 1 , we provide measurements of the domain shift of these four datasets with respect to the original miniImagenet dataset using the FID. The FID measurements confirm the characterization in Guo et al. ( except that the EuroSAT dataset is closer to the original domain than the CropDisease dataset. The difference in both FID measurements is mostly driven by the mean terms. This can be explained by the fact that the FID does not measure perspective distortion and satellite images might have a higher variety of shapes and colors than plant images.
CHEF implementation. We perform pre-training on the miniImagenet dataset similar but not identical to that in Ye et al. (2020) . We utilize a softmax output layer with as many units as classes are contained in the meta-training and the meta-validation sets combined. We make a validation split on the combination of these two sets for supervised learning, i.e. instead of separating whole classes into the validation set (vertical split) we move a randomly selected fraction of samples of each class into the validation set (horizontal split) as it is standard in supervised learning. We evaluate CHEF using the same ResNet-10 backbone architecture as in . For better representation fusion, we place two fully connected layers after the last convolutional layer. We perform model selection during training using the cross-entropy loss function on the horizontal data split, and perform hyperparameter selection for CHEF on the vertical data split.
Results and ablation study. CHEF achieves state-of-the-art performance in all 12 categories. Results are provided in Table 2 . To further study the influence and power of the representation fusion, we use a pre-trained PyTorch (Paszke et al., 2019) ResNet-18 network. 5-way 5-shot and 50-shot results are reported in Fig. 2 (5-way 20-shot results can be found in the appendix). Results are obtained by applying our Hebbian learning rule to the logits of the output layer and to the pre-activations of the blocks 4 through 8 individually and we also examine an ensemble of them. The results are considerably better than the above reported ResNet-10 results, which presumably arises from the fact that the power of representation fusion is larger since the ResNet-18 network is pretrained on the whole Imagenet dataset. This illustrates the power of CHEF considering better feature abstractions. Another interesting insight is that for the ChestX dataset, the dataset with the largest domain shift, the lower level features gain importance. In general, the farther the domain is away from the original domain the more important are features from lower layers, i.e. features that are less specific to the original domain. Since CHEF combines features of different specificity to the training domain, it is particularly powerful in cross-domain settings.
Datasets and evaluation. The miniImagenet dataset (Vinyals et al., 2016) consists of 100 randomly chosen classes from the ILSVRC-2012 dataset (Russakovsky et al., 2015) . We use the commonlyused class split proposed in Ravi & Larochelle (2017) . The tieredImagenet dataset (Ren et al., 2018) is a subset of ILSVRC-2012 (Russakovsky et al., 2015) , composed of 608 classes grouped in 34 high-level categories. For evaluation, we measure the accuracy drawing 800 tasks (five test instances per class) from the meta-test set. Following prior work, we focus on 5-way/1-shot and 5-way/5-shot tasks. We report the average accuracy and a 95 % confidence interval across all test images and tasks.
CHEF implementation and results. We perform pre-training of the respective backbone networks on the miniImagenet and the tieredImagenet dataset in the same way as described in Sec. 4.1. We evaluate CHEF using two different backbone architectures: a Conv-4 and a ResNet-12 network. We use the Conv-4 network described by Vinyals et al. (2016) . Following , we configure the ResNet-12 backbone as 4 residual blocks, which contain a max-pooling and a batch-norm layer and are regularized by DropBlock (Ghiasi et al., 2018) . Again, model selection and hyper-parameter tuning is performed as described in Sec. 4.1. CHEF achieves state-of-the-art performance in 5 Table 3 . An ablation study of the miniImagenet and tieredImagenet results can be found in the appendix.
In drug discovery, it is essential to know properties of drug candidates, such as biological activities or toxicity (Sturm et al., 2020; Mayr et al., 2018) . Since the measurements of these properties require time-and cost-intensive laboratory experiments, machine learning models are used to substitute such miniImagenet 5-way tieredImagenet 5-way Method Backbone 1-shot 5-shot 1-shot 5-shot MatchingNet (Vinyals et al., 2016) Conv-4 43.56 ± 0.84 55.31 ± 0.73 --Meta-LSTM (Ravi & Larochelle, 2017) Conv-4 43.44 ± 0.77 60.60 ± 0.71 --MAML (Finn et al., 2017) Conv measurements . However, due to the high experimental effort often only few high-quality measurements are available for training. Thus, few-shot learning is highly relevant for computational drug discovery.
Problem setting. We consider a 50-shot cross-domain few-shot learning setting in the field of toxicity prediction, utilizing the Tox21 Data Challenge dataset (Tox21) with twelve different toxic effects (Huang & Xia, 2017; Mayr et al., 2016) . Around 50 available measurements is a typical scenario when introducing a new high-quality assay in drug design. So far, the standard approach to deal with such few data points was to use machine learning methods like Support Vector Machines (SVMs; Cortes & Vapnik, 1995) or Random Forests (RFs; Breiman, 2001) . However, these methods do not exploit the rich data available, like the ChEMBL20 drug discovery benchmark (ChEMBL20) (Mayr et al., 2018; Gaulton et al., 2017) . Viewing the Tox21 data as a domain shift of the ChEMBL20 allows the application of cross-domain few-shot learning methods. In this setting, a domain shift can be observed both in the input data and in the target data. The molecules (input domain) are strongly shifted towards a specialized chemical space, with a Jaccard index of 0.01 between the two datasets, and the biological effects (output domain) are shifted towards toxicity without any overlap in this domain. A further shift is in the distribution of the target labels, which are now much more imbalanced in comparison to ChEMBL20. In order to mirror this distribution shift correctly, the number of toxic vs. non-toxic molecules in the training sets for each of the twelve few-shot tasks (twelve different toxic effects) are sub-sampled accordingly. For example, the 50-shot few-shot scenario (50-50 toxic/non-toxic) is adjusted to a 10-90 scenario. For the twelve few-shot learning tasks, training samples are drawn from the training set and test samples are drawn from the test set of the Tox21 data, respectively. We sample individually for each of the twelve tasks.
CHEF implementation for molecules. We first train a fully-connected deep neural network (FCN) for the prediction of bioactivities from the ChEMBL20 database (original domain). The network is trained in a massive multi-task setting, where 1,830 tasks are predicted at once, such that the network is forced to learn proficient representations that can be shared for multiple tasks Unterthiner et al., 2014) . The total number of 892,480 features of the ChEMBL20 database was reduced by a sparseness criterion on the molecules to 1,866 features. The neurons in the input layer of the FCN represent one of 1,866 ECFP6 (Rogers & Hahn, 2010) features, which are used as a feature representation for describing the raw structure of the molecules. Each neuron of the output layer represents one of the 1,830 prediction tasks. We use the pre-trained network and apply CHEF by representation fusion of the three bottleneck layers of the network for predicting the twelve different toxic effects of the new domain of the Tox21 Data Challenge.
Method ROC-AUC CHEF 0.76 ± 0.02 SVM 0.66 ± 0.03 RF 0.64± 0.03 Table 4 : ROC-AUC performance for few-shot drug discovery. CHEF is compared to conventional methods (SVM, RF) for the prediction of toxic effects. Mean and standard deviation are computed across twelve different effects and across 100 differently sampled training and test sets.
Experimental evaluation. We evaluate the performance of CHEF on the twelve tasks of the Tox21 Data Challenge and compare it to conventional methods, like SVMs and RFs, that are used in drug design when few data is available. We use SVMs with a MinMax kernel since it previously yielded the best results (Mayr et al., 2018) . For CHEF, only the 1,866 ECFP input features of ChEMBL20 pre-training network database are used where features with only few occurrences in the training set are discarded since they do not give enough learning signal for neural network training. For SVMs and RFs, all encountered ECFP features are used. ROC-AUC values are computed across the twelve tasks of the Tox21 Data Challenge and across 100 differently sampled training and test sets. CHEF achieves significantly better ROC-AUC values than SVMs and RFs. Table 4 shows the results (p-value < 10 −17 for both SVM and RF when using a paired Wilcoxon test). Results for the twelve individual tasks and a more detailed description is given in the appendix. CHEF significantly outperforms traditional methods in drug design, which demonstrates the great potential of cross-domain few-shot learning in this field.
We have introduced CHEF as new cross-domain few-shot learning method. CHEF builds on the concept of representation fusion, which unifies information from different levels of abstraction. Representation fusion allows one to successfully tackle various few-shot learning problems with large domain shifts across a wide range of different tasks. CHEF obtains new state-of-the-art results in all categories of the broader study of cross-domain few-shot learning benchmarks. Finally, we have tested the performance of CHEF in a real-world cross-domain application in drug discovery, i.e. toxicity prediction when a domain shift appears. CHEF significantly outperforms all traditional approaches demonstrating great potential for applications in computational drug discovery. Table 5 : Results of our few-shot learning method CHEF on four proposed cross-domain few-shot challenges CropDiseases, EuroSAT, ISIC, and ChestX. We compare the ResNet-10 architecture pre-trained on miniImagenet to the ResNet-18 architecture pre-trained on Imagenet. The average 5-way few-shot classification accuracies (%, top-1) along with 95% confidence intervals are reported on the test split of each dataset. layer and are regularized by DropBlock (Ghiasi et al., 2018) with block sizes of 1 × 1 for the first two blocks and 5 × 5 for the latter two blocks.
We pre-train these backbone models for 500 epochs with three different learning rates 0.1, 0.01, and 0.001. For this we use the PyTorch SGD module for stochastic gradient descent with a momentum term of 0.9, an L2 weight decay factor of 10 −4 , a mini-batchsize of 256, and a dropout probability of 0.1. This pre-training is performed on the horizontal training set of the miniImagenet and the tieredImagenet dataset, resulting in 3 trained models per dataset. We apply early stopping by selecting the model with the lowest loss on the horizontal validation set, while evaluating the model performance after each epoch.
Few-shot learning. For few-shot learning, we perform a grid search to determine the best hyperparameter setting for each of the datasets and each of the 1-shot and 5-shot settings, using the loss on the vertical validation set. We treat the 3 backbone models that were pre-trained with different learning rates, as described in the previous paragraph, as hyper-parameters. The hyper-parameters used for this grid-search are listed in table 6.
After determining the best hyper-parameter setting following this procedure, we perform 1-shot and 5-shot learning on the vertical test sets of miniImagenet and tieredImagenet using 10 different random seeds, respectively. The results are listed in Table 6 : Hyper-parameter search space for 1-shot and 5-shot learning on miniImagenet and tieredImagenet using Conv-4 and ResNet-12 backbone models. Best hyper-parameters were evaluated using a grid-search and the loss on the vertical validation set of miniImagenet or tieredImagenet.
Ensemble learning and performance of individual layers. To evaluate the performance of the Hebbian learning using only individual layers versus using the ensemble of layers, we additionally perform the few-shot learning on the vertical test sets using only individual layers as input to the Hebbian learning. As shown in figures 4 and 5, the performance using only the individual layers varies strongly throughout 1-shot and 5-shot learning and the miniImagenet and tieredImagenet dataset. This indicates that the usefulness of the representations provided by the individual layers strongly depends on the data and task setting. In contrast to this, the ensemble of layers reliably achieves either best or second best performance throughout all settings. : Ablation study of the ResNet-12 architecture on the miniImagenet and tieredImagenet datasets for 1-shot and 5-shot. The plots show the individual performances of Hebbian learners acting on single layers and their ensemble performance along with 95% confidence intervals. The labels on the x-axis indicate how far the respective layer is from the output layer.
Details on pre-training on the ChEMBL20 database For training a fully-connected deep neural network (FCN) on the ChEMBL20 database, the number of 892,480 features is reduced by a sparseness criterion on the molecules to 1,866 features. The FCN is trained on 1.1 million molecules for 1,000 epochs minimizing binary cross-entropy and masking out missing values by using an objective, as described in (Mayr et al., 2018) .
Details on the compared methods We use ECFP6 features for a raw molecule representation. Note that the number of possible distinct ECFP6 features is not predefined, since a new molecule may be structurally different from all previously seen ones, and it might therefore consist of new unseen ECFP6 features. For SVMs, a MinMax kernel (Mayr et al., 2016) is used, which operates directly on counts of ECFP6 features and used LIBSVM (Chang & Lin, 2011) as provided by scikit-learn (Pedregosa et al., 2011) . For RFs, the implementation of scikit-learn with 1000 trees and kept default values for the other hyperparameters is used.
Detailed results on the Tox21 dataset in a few-shot setup 0.77 ± 0.08 0.67 ± 0.10 0.63 ± 0.10 3.50e-13 8.86e-17 Table 7 : ROC-AUC performances for the twelve individual few-shot tasks (rows) of the Tox21 Data Challenge. CHEF is compared to conventional methods (SVM, RF). Averages and standard deviations are computed across 100 differently sampled training and test sets. The last two columns show the results of paired Wilcoxon tests with the null hypotheses given that SVM and RF perform better, respectively.