{'fraction_non_alphanumeric': 0.029613719938820008, 'fraction_numerical': 0.006866477919880243, 'mean_word_length': 4.785015060240964, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Few-Shot Learning-Based Human Activity Recognition

Few-shot learning is a technique to learn a model with a very small amount of labeled training data by transferring knowledge from relevant tasks. In this paper, we propose a few-shot learning method for wearable sensor based human activity recognition, a technique that seeks high-level human activity knowledge from low-level sensor inputs. Due to the high costs to obtain human generated activity data and the ubiquitous similarities between activity modes, it can be more efficient to borrow information from existing activity recognition models than to collect more data to train a new model from scratch when only a few data are available for model training. The proposed few-shot human activity recognition method leverages a deep learning model for feature extraction and classification while knowledge transfer is performed in the manner of model parameter transfer. In order to alleviate negative transfer, we propose a metric to measure cross-domain class-wise relevance so that knowledge of higher relevance is assigned larger weights during knowledge transfer. Promising results in extensive experiments show the advantages of the proposed approach.


Introduction
Studies in human activity recognition (HAR) have been attracting increasing attentions in recent years due to their potential in applications such as human health care [1], indoor localization [2], smart hospital [3], and smart home [4].
HAR is a technique that aims at predicting participants' activities from the lowlevel sensor inputs. In recent years, the use of wearable devices such as smart wristbands and smart phones has significantly facilitated HAR research due to their small sizes and low power consumption [5] as well as their capability of real-time information capturing [6].
Traditional machine learning (ML) methods such as support vector machines and decision trees have significantly promoted the development of HAR studies during the past few decades. However, limitations such as heavy reliance on human domain knowledge [7] and shallow feature extraction impede these ML methods from providing satisfactory results in most daily HAR tasks [8].
More recently, deep learning (DL) methods have been continuously providing marvelous performance in many areas such as computer vision and natural language processing [9]. The capability to automatically extract high-level features makes DL methods largely alleviated from the drawbacks of conventional ML methods. There have been many DL-based HAR works proposed in recent years [10,11,12,13]. However, the training time and the amount of data required for DL systems are always much larger than that of traditional ML systems, and the large time and labor costs makes it difficult to build a large-scale labeled human activity dataset with high quality. Therefore, it is necessary to find a way to alleviate these problems of DL-based HAR.
Few-shot learning (FSL) [14,15,16,17,18,19] is a type of transfer learning technique [20] aiming at learning a classifier to recognize unseen classes (target domain 1 ) with only a small amount of labeled training samples by reusing knowledge from existing models on relevant classes (source domain), which makes it 1 The definition of domain is introduced in Section 2 easier to train deep learning models with only a few training samples from each class. FSL has promising potential in many HAR applications. For example, after a health care system is installed, the system should be able to be retrained as the training data used in the previous system may not be representative of the new environment (e.g. new activity types, different people, etc.). Furthermore, the retraining should only require a small amount of new data, as users are generally not able to provide large amounts of data for training, especially for elderly or disabled people. Nonetheless, it may be helpful to keep some of the previously existing knowledge if we can discern between knowledge that is relevant or helpful to learning the new tasks from the knowledge that is not relevant, or that may even harm the learning performance if used during training, a phenomenon known as negative transfer.
In this paper, we propose a novel FSL-based HAR method that we dub fewshot human activity recognition (FSHAR). The framework of FSHAR includes three steps. We first train a deep learning model with source domain samples, where the model parameters are randomly initialized. After that, we calculate the cross-domain class-wise relevance based on embeddings of both source domain samples and target training samples obtained from the source feature extractor. By leveraging the parameters from the source feature extractor and the classifier, as well as the obtained cross-domain class-wise relevance, we initialize the parameters for a target model. Fine-tuning is then performed on the initialized target model for final optimization. To the best of our knowledge, this is the first application of deep learning-based few-shot learning to human activity recognition.
The key contributions of this paper are as follows: • We propose a novel parameter transfer-based few-shot learning scheme for human activity recognition.
• We propose a general framework to measure cross-domain class-wise relevance for human activity recognition to alleviate negative transfer.
• We design a deep learning framework to transform the low-level sensor input of human activity signals to the high-level semantic information for human activity recognition.
• We provide multiple experimental results to demonstrate the performance improvements achieved by the proposed method compared with relevant techniques from the state of the art.
The rest of this paper is organized as follows. Section 2 introduces notations used in this paper and overviews relevant techniques. Details of the proposed framework are presented in Section 3. Experimental results and the corresponding analysis are provided in Section 4. Section 5 concludes this work with suggestions for future work.

Related Work
In this section, we introduce the papers notations and definitions and provide a review of techniques relevant to our proposed method.
Vectors are denoted by bold lowercase letters while matrices are denoted by bold uppercase letters. The superscript T of a matrix denotes the transposition operation. For a matrix A, A (q) denotes the q th column and A (p) denotes the p th row, while A (p,q) denotes the entry at the p th row and q th column. The r,p -norm for a matrix W ∈ R a×b is denoted as We use X = [X (1) ; X (2) ; · · · ; X (n) ] ∈ R n×d to denote sample sets, where X (i) ∈ R d is the i th sample in X for i = 1, 2, · · · , n, and where d and n denote data dimensionality and number of samples in X, respectively.
For notations of transfer learning, we use D to denote a domain and T for a task. A domain D consists of a feature space X and a marginal probability distribution P (X) over a sample set X. A task T consists of a label space Y and an objective predictive function f (X, Y) to predict the corresponding labels Y of a sample set X. We use D src = {X src , P (X src )} and T src = {Y src , f (X src , Y src )} to denote the source domain and task, and use D trg = {X trg , P (X trg )} and T trg = {Y trg , f (X trg , Y trg )} for the target domain and task.

Human Activity Recognition
Human activity recognition (HAR) is a technique that aims at learning highlevel knowledge about human activities from the low-level sensor inputs [8]. In recent years, the growing ubiquity of sensor-equipped wearables such as smart wristbands and smartphones have significantly promoted researches regarding HAR in the field of pervasive computing [21].
Machine learning (ML) algorithms have been widely used in HAR. In the last decade, traditional ML tools such as Markov models [22,23] and decision trees [24,25] have yielded tremendous progress in HAR. However, most traditional ML algorithms applied in HAR use manually designed features, which are shallow and heavily rely on human domain knowledge and experience; furthermore, they are specific to particular tasks. Therefore, traditional ML algorithms cannot handle complex HAR scenarios, and they require one specifically designed model for each task, which increases the time and labor cost to build HAR systems in terms of both labeled data collection and model construction.
In recent years, the application of deep learning (DL) methods to HAR has significantly alleviated the drawbacks of traditional ML based HAR methods.
First, DL models can extract high-level features with little or no human design.

Few-Shot Learning
Few-shot learning (FSL) is a transfer learning technique that applies knowledge from existing data to data from unseen classes which do not have sufficient labeled training data for model training. In this paper we focus on the scenario The first work for FSL is [14], in which a variational Bayesian framework is proposed to represent visual object categories as probabilistic models where existing object categories are used as the prior knowledge, while the model for unseen categories is obtained by updating the prior with one or more observations. Lim et al. [15] propose a sample-borrowing method for multiclass object detection that adds selected samples from similar categories to the training set in order to increase the number of training data.
In recent years, deep learning based FSL [16,17,18,19] has become the mainstream of FSL due to their unparalleled performance. Koch et al. [16] proposed a double-network structure based on the deep convolutional siamese network to extract features from image pairs and generates a similarity score between inputs. Vinyals et al. [17] proposed matching networks to map a small labelled support set from unseen classes and an unlabelled example to its label.
Snell et al. [18] proposed prototypical networks that learn a metric space to perform classification by computing distances to prototype representations of each class. Qi et al. [19] proposed a weight imprinting schedule to add a weight for each new class into a softmax classifier.
During our literature search, we found that FSL is widely used in computer vision studies, motivated by the fact that human beings are able to recognize previously unseen objects with only a few training samples. By contrast, the application of FSL in HAR has been much more limited, especially when combined with DL. During our literature review, we did not find any DL based FSL method that is used in HAR.

Long Short-Term Memory Network
A long-short term memory (LSTM) network [33] is a type of recurrent neural network (RNN) which processes time series signals by taking as their input not just the current inputs but also what they have processed earlier in time. Each RNN contains a loop (repeating modules) inside the network structure that allows information to be passed from one step of the network to the next.
LSTMs are famous for their capabilities to capture long-term dependencies.
Compared with the simple repeating modules of most RNNs, which sometimes only contains a single tanh layer, the repeating modules of LSTMs include more complicated interacting layers in their structures. The workflow of LSTM can be briefly described as follows. The first step is to determine the importance of previous information, which is to decide a status between "completely forget about this" and "completely keep this".

Basic Framework
The basic framework for FSHAR is illustrated in Fig. 1. We first train a source network, which consists of a feature extractor and a classifier, with source domain samples as training data and parameters being randomly ini- for the target classifier. In this paper we use the same network structure for both source and target domains. The network structure is illustrated in Fig. 2.

Source Network Training
We first train a source network with source domain samples to get a source feature extractor f src (·, Θ src ) with parameters Θ src , 3 and a source classifier C(·, W src ) with parameters W src . The source classifier parameters can be represented as a matrix W src ∈ R csrc×d , where c src is the number of source classes and d is the dimensionality of the encoded features f src (X src ) ∈ R nsrc×d , which is used as the feature for classification, where n src denotes the number of source domain samples. We empirically use a stacked LSTM with two hidden layers followed by two fully connected layers as our feature extractor. By using LSTM, we can take advantage of the temporal dependencies within the HAR data, as the layout of an LSTM layer forms a directed cycle where the states of the network in current timestep depends on those of the network in the previous timestep. We use a softmax classifier due to its simplicity of training by gradient descent.

Knowledge Transfer
We consider the information from the source feature extractor as "generic information", as information from lower layers are believed to be more compatible between related tasks than that from higher layers 4 [35]. To transfer the information from the source feature extractor, we copy the source feature extractor parameters Θ src and use those as the initialization for the target feature extractor parameters, which means that the initialization of target feature extractor parameters Θ 0 trg = Θ src . Since the information in a classifier is highly task-specific, it is necessary to pick information that is relevant to the target classes for knowledge transfer so that negative transfer can be alleviated. In our problem scenario, we focus on the class-wise relevance between the source and target training samples, which is referred as cross-domain class-wise relevance in the sequel. We propose two different cross-domain class-wise relevance measures: one based on statistical relevance and another based on semantic relevance.
The statistical scheme to measure cross-domain class-wise relevance includes two steps. First, we calculate the cross-domain sample-wise relevance, which measures the similarity between each pair of source domain sample and target training sample. Second, we calculate the cross-domain class-wise relevance based on the obtained cross-domain sample-wise relevance. Multiple distance metrics can be used to calculate cross-domain sample-wise relevance; we focus on two options for this work. The cross-domain sample-wise relevance values are stored in a matrix A ∈ R nsrc×ntrg , where n trg denotes the number of target training samples.
• Cosine Similarity, which uses the exponential value of the cosine similarity [17] to measure cross-domain sample-wise relevance. To be more specific, the relevance between the i th source domain sample and the j th target training sample is measured through for i = 1, 2, · · · , n src and j = 1, 2, · · · , n trg , wheref src (·) = f src (·)/ f src (·) 2 denotes the normalized encoded feature. The exponential operation makes all relevance values positive to facilitate subsequent steps.
• Sparse Reconstruction, which uses the magnitudes of the reconstruction coefficients to measure cross-domain sample-wise relevance under the assumption that there exists a linear mapping between source and target embeddings provided by the source feature extractor. That is, where A acts as a reconstruction matrix with element values indicating cross-domain sample-wise relevance. We first solve the following minimization problem to get a reconstruction matrix A: where λ is a balance parameter. Since each row of A indicates the impor- for p = 1, 2, · · · , c src and q = 1, 2, · · · , c trg , where s p and s q corresponds to the set of sample indices in the p th class and the q th class. We refer to the scheme with cosine similarity used for cross-domain sample-wise relevance measure as The semantic scheme to measure cross-domain class-wise relevance is based on the textual description of activity classes, in which multiple distance metrics can be used. In this paper, we employ the normalized Google distance (NGD) [36] as the distance metric. NGD is a semantic similarity measure based on the number of hits returned by the Google search engine for a given pair of keywords. The NGD between keywords P and Q is calculated by N GD(P, Q) = max{log g(P ), log g(Q)} − log g(P, Q) log N − min{log g(P ), log g(Q)} , where N is the total number of web pages searched by Google multiplied by the average number of search terms on each page, which is estimated by the number of hits by searching the word "the"; g(P ) and g(Q) are the number of hits for search terms P and Q, respectively; and g(P, Q) is the number of web pages on which both P and Q occur. Assume P and Q are the textual descriptions of the p th source class and the q th target class, respectively; then the cross-domain class-wise relevance matrix O is obtained through This scheme is referred to as FSHAR with normalized Google distance (FSHAR-NGD) in the sequel.
In order to facilitate classifier parameter transfer, we need to normalize the obtained cross-domain class-wise relevance matrix O such that for each target class the relevance values from all source classes sum to 1. We propose two normalization schemes for comparison. The normalized cross-domain class-wise relevance values are stored in a matrix W ∈ R csrc×ctrg .
• Scheme A: Soft normalization • Scheme B: Hard normalization The initial value of target classifier weights is a linear combination of the trained source classifier weights based on the normalized class-wise relevance matrix W.
That is, where W 0 trg denotes the initialization of target classifier parameters. Compared with hard normalization, soft normalization may help improve knowledge transfer performance since it is able to capture the relationship between each single target class and multiple source classes instead of one. This is important for HAR tasks since there sometimes exists commonalities between activity categories.

Algorithm 1 FSHAR
Inputs: Source domain samples X src ; target training samples X trg ; Outputs: Target feature extractor parameters Θ trg ; target classifier parameters W trg .
1: Train a source network with source domain samples X src to obtain the source feature extractor parameters Θ src and the source classifier parameters W src ; 2: Initialize the target feature extractor parameters Θ 0 trg using the source feature extractor parameters Θ src ; 3: Calculate the normalized cross-domain class-wise relevance matrix W by following one of the schemes proposed in Section 3.3; 4: Initialize the target classifier parameters W 0 trg by following Eq. (9); 5: Fine-tune the initialized target network to get the target feature extractor parameters Θ trg and the target classifier parameters W trg .

Fine-Tuning
As mentioned earlier, both Θ 0 trg and W 0 trg are used as the initialization for the feature extractor and the classifier parameters in the target network, respectively. The final target feature extractor parameter Θ trg and classifier parameter W trg are obtained through backpropagation based fine-tuning with target training samples. The rationale behind fine-tuning is that not every target class has an unimodal distribution in the embedding space created by the source feature extractor as it could be biased towards features that are salient and discriminative among source classes, while fine-tuning is likely to move the embedding space so that each target class may have an unimodal distribution [19]. FSHAR is summarized in Algorithm 1.

Implementation
We used PyTorch [37] to implement the described framework. Network parameter optimization was performed via Adam [38]. We employ the method proposed in [39] 5 to solve the optimization problem (3) , which efficiently solves an 2,1 -norm optimization problem by reformulating it as two equivalent smooth convex optimization problems.

Limitation
As described in Section 3.3, FSHAR uses a linear combination of source classifier parameters to get an initialization of classifier weights for target classes based on a normalized cross-domain class-wise relevance matrix W. Although the matrix W only characterizes the relative relevance of source classes to each target class within the given source domain, it is also possible that none of the source classes is sufficiently relevant to a certain target class. In that case, FSHAR does not consider the domain-wise relevance for knowledge transfer.
This limitation of FSHAR will be considered in our future work.

Extension
As mentioned in Section 1, there would be a practical impact if the knowledge extracted from new environments can be merged into the previously trained

Experiments
In this section, we evaluate the knowledge transfer performance of FSHAR.
Experiments are conducted on two benchmark human activity datasets. We also compare FSHAR with other relevant state-of-the-art techniques. The classification rates on target testing samples are used as the metric to evaluate knowledge transfer performance. We do not include experimental results of merged network as introduced in Section 3.7 as we only focus on the knowledge transfer performance that is reflected by classification accuracy on target testing data instead of a merged system.

Dataset Information
We first provide the overall information of each dataset and introduce the source/target domain setup. We perform experiments on two benchmark datasets: the Opportunity activity recognition dataset (OPP) [40] and the PAMAP2 physical activity monitoring dataset (PAMAP2) [41]. OPP consists of common kitchen activities from 4 participants with wearable sensors. Data from 5 different runs are recorded for each participant with activities being annotated with 18 mid-level gesture annotations. Following [13], we only keep data from sensors without any packet-loss, which includes accelerometer data from the upper limbs and the back, and complete IMU data from both feet. The resulting dataset has 77 dimensions. PAMAP2 consists of 12 household and exercise activities from 9 participants with wearable sensors. The dataset has 53 dimensions. For frame-by-frame analysis, a sliding window with a one-second duration and 50% overlap is performed and the resulting data are used as inputs to the system for both datasets. In order to eliminate the side effects caused by imbalanced classes, we set the number of samples from each class to be the same within each dataset through random selection. We keep 202 samples and 129 samples for each class of OPP and PAMAP2 when used as source data, respectively.

Source/Target Split
In PAMAP2, the small number of samples for each participant may negatively affect the knowledge transfer performance when used as the source data. Therefore, the 9 participants are partitioned into 3 groups with the purpose of alleviating potential negative influences caused by the small number of samples in each class. To be more specific, the first three participants are in the first group, the second three participants are in the second group, and the remaining three participants are in the third group.
For each dataset, we select a portion of the classes as the source classes and the remaining as the target classes. Details on the source/target class split are listed in Table 1. 6 We test the knowledge transfer performance in two scenarios: i) the source data come from the same participant/group of participants as those of the target data; ii) the source data come from different participants/groups of participants from those of the target data. In the first scenario, the target domain includes target activity classes of one participant for OPP or one group of participants for PAMAP2, and the source domain includes source activity classes of the same participant for OPP or the same group of participants for PAMAP2. In the second scenario, the target domain includes target activity classes of one participant for OPP or one group of participants for PAMAP2, and the source domain includes source activity classes of the remaining participants for OPP or the remaining groups of participants for PAMAP2.

Baselines
We compare our proposed FSHAR methods with the following four baselines. 7 Note that all baselines are performed with the network structure described in Section 3.1. The parameters for neural networks are listed in Table   2.
• Random Initialization (RandInit), which trains the designed network with target training data from scratch and network parameters are ran- 6 For OPP, Doors 1-2 denote two different doors and Drawers 1-3 denote three different drawers. When using NGD to calculate cross-domain class-wise relevance, we considered the same activity mode affecting on different objects as the same class. For example, we used "Open Door" for both "Open Door 1" and "Open Door 2" when computing NGD. 7 We do not compare FSHAR with meta-learning-based FSL methods such as [17,18]   • Feature Extractor Transfer + Softmax Classifier (FeTr+Softmax), which only transfers the source feature extractor parameters as the initialization for target feature extractor. The softmax is used as classifier and fine-tuning is performed on the whole network.
• Feature Extractor Transfer + Nearest Neighbor Classifier (FeTr+NN), which uses a copy of the source feature extractor parameters as that for the target feature extractor. Then a nearest neighbor classifier is applied on the embeddings extracted from both target training and testing samples.
Following [17], we first calculated the similarity between a given encoded target testing sample x TrgTe and different encoded target training samples X trg(i) for i = 1, 2, · · · , n trg through whereṽ = v/ v is a normalization of vector v.
• Imprinting: Qi et al. [19] proposed a weight imprinting approach that adds classifier weights in the final softmax layer for unseen categories by using a copy of the mean of the embedding layer activations extracted from the correponding training samples. Following [19],we computed the classifier weights for a target class c j by averaging the embeddings W trg(j) = 1 tj tj i=1 f src (X trg(i) ), where t j is the number of samples in the j th target class. The obtained classifier weights were used as the initialization for the target classifier. Fine-tuning was then applied on the weights for optimization purposes.     Classification accuracy (%) on target testing samples is used as the evaluation metric.

Performance Comparison
We present the classification accuracy results of FSHAR and baselines on both datasets in Tables 3-6 we highlight the best performance in each column as well as the classification accuracy values with a difference less than 1% from the best one, since such a difference can be considered trivial.
It is obvious that the best performances are almost always achieved by FSHAR methods. More detailed analysis on different aspects is provided as below.
• Transfer Learning and Negative Transfer: We can find that most transfer learning based methods perform bettern than "RandInit". However, we also see negative transfer when only the source feature extractor weights are transferred. We conjecture that the possible reason is that the weights we transferred are generated from all source domain samples without any regard for similarity measure and selection. Therefore, source domain samples with different relevance to the target domain make equal contributions to the weights and those with weak relevance may provide harmful information during training. The consistent poor performance of "FeTr+NN" is possibly due to the unfeasibility for fine-tuning, which results in sub-optimal network parameter choices.
• Number of Training Samples: Increasing the number of training samples for each target class from 1 to 5 can bring an increase of about 10% to 15% in performance for each method. It is also obvious that gap between "RandInit", the baseline without knowledge transfer, and other transfer learning methods shrinks. We believe that by as the number of target training samples increase, the gap between performance of "RandInit" and transfer learning based methods will keep shrinking, which decreases the necessity of transfer learning.
• Therefore, we argue that the advantages of FSHAR-NGD over FSHAR-Cos and FSHAR-SR can be a coincidence based on the source/target class split scheme and the way each activity class being described. But it is also noticeable that using statistical methods to calculate cross-domain class-wise relevance may suffer from insufficient training data, while the performance of semantic methods is independent of that.

Effects of Fine-Tuning
We illustrate the effects of fine-tuning on the scenario of OPP with source and target data coming from the same participant in Fig. 3. It is obvious that fine-tuning improves classification performance in almost all cases except for the two of Participant 3 with the setup of 1-shot learning and soft normalization on the cross-domain class-wise relevance matrix for both FSHAR-Cos and FSHAR-SR. Additionally, the improvements become larger with the increase of number of training samples. We conjecture that with only one training sample from each target class, fine-tuning is more likely to lead to overfitting that degrade the generalization capability of the learned model. Results from other scenarios (i.e. PAMAP2, source and target data from different participant/group of participants) are not included due to the fact that they perform similar patterns and the purpose of saving space.

Conclusion
We propose a few-shot learning framework for human activity recognition.
The main contributions in this proposed approach is two-fold. First, we propose a method to transfer the parameters for a feature extractor and classifier from the source network to the target network based on cross-domain class-wise rele- Future work includes four aspects: 1) we will study and try to overcome the problem of cross-domain relevance; 2) a merged model after knowledge transfer is also worth exploring; 3) we may combine statistical ways and semantic ways to measure cross-domain class-wise relevance instead of separating them; 4) it is worth trying to find a way to combine source data from both same and different participants from the target participant to see if knowledge transfer performance can be improved. Top row: FSHAR-NGD. Middle row: FSHAR-Cos. Bottom row: FSHAR-SR. In all subfigures, "noFT" means without fine-tuning being performed on the initialized target network, and "Soft"/"Hard" refer to soft/hard normalization scheme on the cross-domain class-wise relevance matrix O as described in Section 3.3.