ShapeWordNet: An Interpretable Shapelet Neural Network for Physiological
  Signal Classification
Physiological signals are high-dimensional time series of great practical
values in medical and healthcare applications. However, previous works on its
classification fail to obtain promising results due to the intractable data
characteristics and the severe label sparsity issues. In this paper, we try to
address these challenges by proposing a more effective and interpretable scheme
tailored for the physiological signal classification task. Specifically, we
exploit the time series shapelets to extract prominent local patterns and
perform interpretable sequence discretization to distill the whole-series
information. By doing so, the long and continuous raw signals are compressed
into short and discrete token sequences, where both local patterns and global
contexts are well preserved. Moreover, to alleviate the label sparsity issue, a
multi-scale transformation strategy is adaptively designed to augment data and
a cross-scale contrastive learning mechanism is accordingly devised to guide
the model training. We name our method as ShapeWordNet and conduct extensive
experiments on three real-world datasets to investigate its effectiveness.
Comparative results show that our proposed scheme remarkably outperforms four
categories of cutting-edge approaches. Visualization analysis further witnesses
the good interpretability of the sequence discretization idea based on
shapelets.
Wenqiang He, Mingyue Cheng, Qi Liu, Zhi Li
# ShapeWordNet: An Interpretable Shapelet Neural Network for Physiological Signal Classification

###### Abstract

Physiological signals are high-dimensional time series of great practical values in medical and healthcare applications. However, previous works on its classification fail to obtain promising results due to the intractable data characteristics and the severe label sparsity issues. In this paper, we try to address these challenges by proposing a more effective and interpretable scheme tailored for the physiological signal classification task. Specifically, we exploit the time series shapelets to extract prominent local patterns and perform interpretable sequence discretization to distill the whole-series information. By doing so, the long and continuous raw signals are compressed into short and discrete token sequences, where both local patterns and global contexts are well preserved. Moreover, to alleviate the label sparsity issue, a multi-scale transformation strategy is adaptively designed to augment data and a cross-scale contrastive learning mechanism is accordingly devised to guide the model training. We name our method as ShapeWordNet and conduct extensive experiments on three real-world datasets to investigate its effectiveness. Comparative results show that our proposed scheme remarkably outperforms four categories of cutting-edge approaches. Visualization analysis further witnesses the good interpretability of the sequence discretization idea based on shapelets.

Keywords:Physiological Signal Classification Shapelet-based Sequence Discretization Interpretability Contrastive Learning

## 1 Introduction

Physiological signal is an invaluable type of medical time series, which has broad applications in the healthcare domains, such as emotion recognition, seizure detection and heartbeat classification [11]. To effectively indicate the health state of human body, relevant information is often recorded simultaneously by multiple sensors through high-frequency and long-time sampling. For example, an electrocardiogram (ECG) signal recording can be sampled in 12 channels at a
frequency of 500 HZ for at least 10 seconds to be used for diagnosing the cardiovascular condition of a patient. Nowadays, the fast progress of IoT spurs an explosive increase of physiological signals, making the traditional way of manually classifying such high-dimensional data not only costly but also inefficient [21]. Hence, recent research has turned to artificial intelligence and machine learning for technical assistance [6].

Given the temporal data property, the physiological signal classification (PSC) task is often viewed as a typical time series classification (TSC) problem in the machine learning field, where a plentitude of TSC methods have been proposed and can be roughly grouped into two categories: the classical algorithms and the deep learning (DL) based approaches [3, 17]. Classical TSC methods focus on explainable feature engineering, where distinguishable features are designed and extracted from various perspectives. For instance, the "golden standard" 1-NN Dynamic Time Warping (DTW) paradigm [10, 22] concentrates on comparing the similarity of global patterns, while the shapelet-based approaches [33, 14, 23] aim at mining discriminative subsequences that maximally represent a class. Nevertheless, despite effective on small-scale and univariate datasets, classical methods do not scale well to the PSC task due to the difficulty of large-space feature selection and the inability to capture multi-variate interaction [31].

In the past few years, deep learning based methods have reported incredible advancements in the TSC field, which avoid handcraft feature design and laborious feature selection by directly learning informative and low-dimensional representations from raw data [34, 17]. However, DL approaches require a large amount of labelled data to supervise model training, which is quite limited in the PSC scenario and may lead to performance degeneration. Besides, DL models provide little insight into the decisive factors and such black-box natures would impair their credibility in the healthcare field [1, 24]. To overcome the above challenges and better adapt to the PSC task, one natural idea is to make full use of the strengths of both the classical and the deep learning based methods [34].

In this article, we propose a two-stage model named ShapeWordNet to provide a more effective and interpretable solution to the PSC problem. To be specific, we novelly take advantage of the time series shapelets to extract discriminative local patterns as elementary "words" that contain certain class-relevant "semantics" of the original data. Then, based on these explainable words, we discretize the point-wise raw signal into a word-wise token sequence dubbed ShapeSentence for the whole-series information distillation, where we believe both significant local patterns and global contexts are well preserved. Moreover, in order to alleviate the label sparsity issue, the large shapelet candidate space is adaptively leveraged to augment the raw data in a multi-scale transformation way, and a cross-scale contrastive learning mechanism is accordingly constructed as an auxiliary objective to capture the data invariance. Finally, a scale-aware feature integrator is devised to fuse the representations of multi-scale ShapeSentences for class label prediction.

In summary, the main contributions of our work are as follows:
* We propose an effective and interpretable scheme named ShapeWordNet tailored to the physiological signal classification task, which integrates the representation learning strengths of deep neural networks with the interpretability advantages of time series shapelets.
* We design a ShapeWord Discretization strategy to deal with the intractable data properties of physiological signals and devise a cross-scale contrastive learning mechanism to alleviate the label sparsity issues. To the best of our knowledge, this is the first work to utilize shapelets for explainable sequence discretization and deep learning's representational ability promotion.
* We conduct extensive experiments on three real-world datasets to investigate the effectiveness of ShapeWordNet. The comparative results validate the model's outperformance over four categories of TSC methods and the visualization analysis illustrates the good interpretability of the sequence discretization idea based on shapelets.

## 2 Preliminaries

### Problem Formulation

Given a group of physiological signals \(\mathcal{T}=\{T_{1},T_{2},...,T_{m}\}\in\mathcal{R}^{m\times d\times n}\) and the corresponding label set \(\mathcal{Y}=\{y_{1},y_{2},...,y_{m}\}\in\mathcal{R}^{m}\), where each sample \(T_{i}\in\mathcal{R}^{d\times n}\) is a \(d\)-dimensional sequence of \(n\) time steps associated with a label \(y_{i}\), the goal of physiological signal classification is to train a model \(f_{\Theta}:T\mapsto y\) to predict the class label for a target instance.

### Definitions

**Definition 1: Shapelet.** A shapelet \(\tilde{S}\in\mathcal{R}^{l}\) (\(1\leq l\leq n\)) is a type of subsequence that well discriminates classes [33]. A good shapelet is supposed to have small \(sDist\), i.e. the shapelet distance [4], to instances of one class and have large \(sDist\) to those of another. The \(sDist\) is defined as the minimum euclidean distance between \(\tilde{S}\) and any subseries \(w\in W^{l}\) of a given time series \(T\in\mathcal{R}^{n}\) :

\[sDist(\tilde{S},T)=\min_{w\in W^{l}}(dist(\tilde{S},w)). \tag{1}\]

**Definition 2: ShapeWord.** A ShapeWord is defined as the cluster centroid of a set of similar shapelets, which represents the abstract prototype [20] of their shared local pattern and can be referred to by the cluster label token \(SW\):

\[ShapeWord =ClusterCentroid(\tilde{S}_{1},...,\tilde{S}_{v}), \tag{2}\] \[SW =ClusterLabel(\tilde{S}_{1},...,\tilde{S}_{v}).\]

**Definition 3: ShapeSentence.** A ShapeSentence \(SS\) is the discretized token sequence of the continuous raw series \(T\), where each token \(SW_{i}\) refers to a ShapeWord and \(s\) is the length of this ShapeSentence:

\[T=[t_{1},...,t_{n}]\in\mathcal{R}^{d\times n}\to SS=[SW_{1},...,SW_{s}]\in \mathcal{R}^{d\times s}. \tag{3}\]
ShapeWordNet

The overall architecture of our proposed ShapeWordNet is shown in Figure 1, which consists of two stages: the **ShapeWord Discretization** stage and the **Cross-scale Contrastive Learning Assisted Classification** stage.

### ShapeWord Discretization

The first stage includes three steps: (1) **Shapelet Selection**, (2) **ShapeWord Generation** and (3) **Muti-scale ShapeSentence Transformation**.

**Shapelet Selection.** Shapelets are discriminative subsequences that can offer explanatory insights into the problem domain [33]. In this paper, we seize on such advantages of shapelets to extract interpretable and prominent local patterns. Traditional way of selecting shapelets is to evaluate the maximum information gain among all possible splits for each shapelet candidate, which would be extremely time-consuming in the physiological signal classification (PSC) scenario. To fast select shapelets, we combine the single-scan shapelet discovery algorithm [23] with a random sampling strategy. Specifically, we first select 10 samples from each class at random. Then we generate shapelet candidates with a sliding window and evaluate each candidate's discrimination ability with the F-statistic measure that assesses the mean \(sDist\) distribution differences between classes:

\[F\left(S\right)=\frac{\sum_{v=1}^{V}\left(\bar{d}_{S,v}-\bar{d}_{S}\right)^{2} \Big{/}(V-1)}{\sum_{v=1}^{V}\sum_{j=1}^{N_{v}}\left(d_{S,v,j}-\bar{d}_{S,v} \right)^{2}\Big{/}(N-V)}, \tag{4}\]

where \(V\) is the class number, \(N\) is the total sample number, \(N_{v}\) is the number of class \(v\), \(S\) is the shapelet candidate to be assessed, \(\bar{d}_{S}\) is the mean value of its \(sDist\) vector \(D_{S}\), and \(d_{S,v,j}\) is its \(sDist\) with the \(j\)-th sample of class \(v\).

Figure 1: An overview of the ShapeWordNet model.
ShapeWord Generation.Although plenty of shapelets can be easily found, many of them are similar to each other, which brings about feature redundancy and increases computational complexity. To alleviate this issue, we propose to generate the prototypes [20] that contain the key information shared by similar shapelets as the elementary units for sequence discretization. Toward this end, we cluster the selected shapelets with K-means and define the cluster centroids as their prototypes [28], as is suggested in Equation 2. Those prototypes are named ShapeWord and assigned with numeric cluster label tokens for reference. For the multivariate case, we simply repeat the aforementioned algorithm and generate ShapeWords for each variable. In doing so, we establish a _vocabulary_ of ShapeWords which encompasses the significant local patterns over all variable dimensions, as is illustrated in Figure 1.

Moreover, to validate the discriminative edges of ShapeWords, we conduct a comparison experiment between the selected shapelets and the generated ShapeWords on the Sleep dataset [19]. In our experiment, we first generate shapelet candidates of different lengths from 5 to 200. For each scale, we select the top-100 shapelets to produce corresponding ShapeWords via K-means, where the cluster number is set equal to the class number, i.e. \(N_{SW}=8\). Then, we establish a validation set containing 10 random samples of each class to compare the average F-statistic qualities of the ShapeWords with that of top-100 shapelets. The results in Figure 2 show that the mean F-statistic scores of the ShapeWords are competitively higher regardless of scales, which concretely demonstrate the effectiveness of ShapeWords in representing the prototypes of similar shapelets.

Multi-scale ShapeSentence Transformation.Traditional shapelet-based methods focus on extracting local patterns for classification, while in the PSC scenario, the global contextual information such as the periodicity and variation of local patterns is also of critical importance. For example, the sinus arrhythmia can be more effectively diagnosed from a periodic perspective. Hence, based on the extracted local patterns represented by ShapeWords, we discretize the entire sequence to further distill the global contexts. Firstly, we segment the original signals into non-overlapping subsequences via a sliding window of the

Figure 2: Results of the average F-statistic quality comparison between ShapeWords and the top-100 Shapelets w.r.t. the shapelet lengths, which is the higher the better.
ShapeWord size. Then, we assign each segment the cluster label token that refers to its nearest ShapeWord according to the Euclidean Distance. In doing so, a long and complex point-wise time series can be interpretably compressed into a much shorter and simpler word-wise token sequence, which preserve the key features both locally and globally and can be more robust to noise disturbance [30]. We call such a token sequence ShapeSentence to suggest it is like a meaningful sentence in the natural language, where the whole sentence and its constituent words contain information at different semantic levels.

In addition, the ShapeSentence is quite scalable and can be adaptively extended as a data augmentation strategy to mitigate data sparsity issue. To be specific, we make the best of the large shapelet candidate space to generate different sizes of ShapeWords and transform each sample into multiple scales of ShapeSentences, which are further utilized to construct self-supervised signals in the contrastive learning mechanism. We dub this data augmentation technique as the **M**ulti-scale **S**hapeSentence **T**ransformation (MST) strategy and summarize its procedure in Algorithm 1. When \(max=min+1\), it is the simplest single-scale ShapeSentence transformation version mentioned above.

```
1:Input: sample set \(T\), ShapeWord scale range \([min,max]\), ShapeWord vocabulary \(SWList\)
2:\(AugmentedData\leftarrow\emptyset\)
3:for\(T_{i}\) in \(T\)do
4:\(MShapeSentences\leftarrow\emptyset\)
5:for\(l\gets min\) to \(max\)do
6:\(W_{i}^{l}\gets segmentSequences\left(T_{i},l\right)\)
7:for subsequence \(S\) in \(W_{i}^{l}\)do
8:\(SW_{h}\gets findClosest\left(S,SWList\right)\)
9:\(MShapeSentences.append\left(SW_{h}\right)\)
10:endfor
11:\(AugmentedData.append\left(MShapeSentences\right)\)
12:endfor
13:endfor
14:return\(AugmentedData\)
```

**Algorithm 1****M**ulti-scale **S**hapeSentence **T**ransformation (MST)

### Cross-scale Contrastive Learning Assisted Classification

The second stage adopts the paradigm of multi-task learning, where the model training is assisted by the **Cross-scale Contrastive Learning** and the learnt representations are fused through **Scale-aware Feature Integration** before final classification.

**Cross-scale Contrastive Learning.** Self-supervised learning has emerged as an alternative paradigm to overcome deep learning's heavy dependence on manual labels by leveraging the input data itself as supervision [25]. In recent years, great breakthroughs in this field has been achieved by the contrastive learning [7], which aims at "learning to compare" through the Noise Contrastive
Estimation (NCE) [15] or the InfoNCE objectives [27]. In this work, we adaptively design a cross-scale contrastive learning mechanism to alleviate the label sparsity issues of PSC by constructing the self-supervised signals based on the multi-scale transformed ShapeSentences. Since a pair of large-scale and small-scale ShapeSentences of the same sample can be regarded as its observations from multi-scale perspectives, it is safe to hypothesize that there exists latent invariance behind them which we can enable the feature encoders to capture [16]. With this intuition, we encode each scale of ShapeSentence into fixed-size representations and compute the InfoNCE loss by comparing their similarities.

As is illustrated in Figure 1, for instance, \(h\) scales of sample \(i\)'s ShapeSentences, i.e. \(SS_{i}^{1}\), \(SS_{i}^{2}\), \(...\), \(SS_{i}^{h}\), are first fed into a set of encoders \(En^{1}\left(\cdot\right),...,En^{h}\left(\cdot\right)\) to obtain their representations, i.e. \(e_{i}^{1}=En^{1}\left(SS_{i}^{1}\right),...,e_{i}^{h}=En^{h}\left(SS_{i}^{h}\right)\) (one encoder corresponds to one scale). Then, in order to make the encoders capable of capturing the invariance shared by different scales of ShapeSentences, we define the cross-scale contrastive loss \(L_{sc}^{h}\) as:

\[L_{sc}^{h}=\frac{1}{\binom{h}{2}}\sum\limits_{u=1}^{h-1}\sum\limits_{v=u+1}^{ h}L_{u,v}^{sc}, \tag{5}\]

\[L_{u,v}^{sc}=E_{\left(e_{i}^{u},e_{i}^{v}\right)\sim P_{u,v}^{i}}\left[- \log\frac{f\left(e_{i}^{u},e_{i}^{v}\right)}{f\left(e_{i}^{u},e_{i}^{v}\right) +\sum\limits_{i\neq j}f\left(e_{i}^{u},e_{j}^{v}\right)}\right], \tag{6}\]

\[f\left(e_{i}^{u},e_{i}^{v}\right)=\left(e_{i}^{u}\right)^{T}e_{i}^{v}\Big{/} \tau, \tag{7}\]

where \(L_{u,v}^{sc}\) is the contrastive loss between the representations of the \(u\)-scale ShapeSentences and the \(v\)-scale ShapeSentences, with \(P_{u,v}^{i}\) as their joint sample distribution and \(f\left(\cdot\right)\) being the representation similarity measure. In this article, we simply apply the vector inner product to compute representation similarities, view representation pair \(\left(e_{i}^{u},e_{i}^{v}\right)\) from the same sample as positive, and randomly select \(N-1\) different samples from the marginal distributions of other samples within the same one mini-batch as negative, e.g. the negative \(e_{j}^{v}\) from the \(v\)-scale marginal distribution of another sample \(j\), as is suggested by InfoNCE [27].

In our scheme, we choose the deep dilated causal convolutional neural network [12] as the encoder backbone given its high efficiency and outstanding excellence in capturing long-range dependencies [5]. Besides, to learn the multivariate interactions, we input different variable's ShapeSentence into different channels of the encoder to obtain the representation feature vectors [35].

**Scale-aware Feature Integration for Classification.** Before classification, we need to integrate the learned representations from different scales of ShapeSentences at first. In terms of multi-scale feature fusion, general methods like average pooling, maxpooling and direct concatenation [8] are all model-agnostic that do not take the domain particularities into consideration. To adaptively make full use of the multi-scale information in our method, we regard each scale's representation as complementary to the raw data's invariant features and
concatenate them by channel. We then input the concatenated representation tensor into the the **S**cale-aware **F**eature **I**ntegrator (SFI) for feature fusion:

\[C_{i}=SFI\left(E_{i}\right), \tag{8}\]

where SFI is a single one-dimensional convolution layer with different channels catering to different scales of ShapeSentence representations, \(E_{i}=\left[e_{i}^{1},...,e_{i}^{h}\right]\in\mathcal{R}^{p\times h}\) is sample \(i\)'s concatenated representation tensor, and \(C_{i}\in\mathcal{R}^{q}\) is the integrated feature vector.

Finally, we input the fused feature representation \(C_{i}\) into a single linear classifier to obtain the classification outcome \(\hat{y}_{i}\):

\[\hat{y}_{i}={W_{c}}^{\top}C_{i}+W_{0}, \tag{9}\]

where \(W_{c}\in\mathcal{R}^{c\times q}\) and \(W_{0}\in\mathcal{R}^{c}\) are learnable parameters.

**Multi-task Optimization.** To optimize the whole network, we combine the cross-entropy loss for classification with the cross-scale contrastive loss for self-supervision as a multi-task goal [29] for joint training:

\[\begin{split} L&=L_{ce}+\lambda L_{sc}^{h}\\ &=-\sum_{c}^{|C|}y_{c}\log\left(\hat{y}_{c}\right)+\frac{\lambda }{\binom{h}{2}}\sum_{u=1}^{h-1}\sum_{v=u+1}^{h}L_{u,v}^{sc},\end{split} \tag{10}\]

where \(\lambda\) is used to balance different losses and \(h\) is the number of scales.

## 4 Experiments

### Experimental Setup

**Datasets.** We conduct experiments on three real-world public datasets from PhysioNet [13], where two datasets are ECG signals used for cardiac disease classification in the 2020 Physionet/Computing Cardiology Challenge [2] and one dataset contains EEG signals popular in sleep-stage classification [19]. In our experiment, we pick out part of the single-label samples and randomly split them into 80%-20% train-test datasets. The statistics of these datasets are summarized in Table 1, where Trainsize/Testsize means the sample number of the training/testing dataset, Dim/Len refers to the variable number and time steps, and Ratio stands for the ratio of one class number to all.

**Baselines and Variants.** We compare three variants of our ShapeWordNet (SWN) scheme with four categories of time series classification (TSC) baselines:

**(1) Shapelet-based:** We employ the Shapelet Transformation (**ST**) [23] and Learning Shapelets (**LS**) [14] for the first baseline group. ST searches the shapelets and transforms the original data into distance vectors, while LS learns the shapelets directly by optimizing the goal function of classification.
**(2) Dictionary-based:** We pick out the classical **SAX-VSM**[32] and the recent **WEASEL+MUSE**[31] for sequence discretization comparison, which respectively utilize the SAX words and SFA words for time series discretization and build classifiers based on their frequency patterns.

**(3) SOTA:** This group contains two state-of-the-art TSC methods, including the the non-DL model MiniRocket [9] and the DL model TapNet [34].

**(4) CNN-based:** Considering the noticeable achievements of convolutional neural networks (CNN) in sequence modeling [5], we adopt four different architectures of CNN-based TSC approaches as the deep learning baselines, which are **MCNN**[8], **LSTM-FCN**[18], **ResCNN**[36] and **TCN**[5].

**(5) Variants:** We put forward three variants of our method for ablation study: (1) **SWN w/o SD** stands for the ShapeWordNet without ShapeWord Discretization, i.e. the encoder backbone and the **TCN** baseline, (2) **SWN w/o CCLM** represents the ShapeWordNet without the Cross-scale Contrastive Learning Mechanism, and (3) **SWN w/o SFI** means the ShapeWordNet without the Scale-aware Feature Integrator.

**Implementation Details.** We set the \(layer\_depth=3\), \(kernel\_size=3\), and \(out\_channels=50\) as the default parameters for each of the dilated causal convolutional encoders. In terms of the ShapeWord/shapelet/word number parameters in three SWN variants, Dictionary-based and Shapelet-based baselines, we set them equal to the task class number times the variable dimensions of each dataset, i.e. 8*2 for Sleep and 9*12 for CPSC and Georgia. As for the ShapeWord/shapelet/word lengths, we set 10 for SWN w/o CCLM, SAX-VSM, WEASEL+MUSE, ST and LS, and set [10,25,50] for SWN w/o SFI and SWN. In SWN w/o SFI and SWN, the \(\lambda\) in Equation 10 to balance loss is set to be 0.5. Besides, we set the \(batch\_size=30\), \(training\_epochs=50\) and use Adam optimizer with \(learning\_rate=0.001\) for all methods.

We evaluate the classification performance with two metrics: **Accuracy (ACC)** and **Macro F1-score (MAF1)**. ACC can measure the overall perfor

\begin{table}
\begin{tabular}{c c c c} \hline \hline \multirow{2}{*}{Property} & \multicolumn{3}{c}{Datasets} \\ \cline{2-4}  & CPSC & Georgia & Sleep \\ \hline Triansize & 5,123 & 2,676 & 12,787 \\ Testsize & 1,268 & 668 & 1,421 \\ Dim/Len & 12/5,000 & 12/5,000 & 2/3,000 \\ Category & ECG & ECG & EEG \\ \hline \multirow{3}{*}{Multi-class Ratio (\%)} & [14.07, 24.24, & [52.73, 12.97, & [48.42, 3.65, \\  & 15.42, 9.53, & 7.47, 6.50, & 21.40, 4.25, \\  & 12.26, 10.85, & 6.69, 3.81, & 4.40, 9.93, \\  & 3.03, 2.69, 7.91] & 3.77, 3.51, 2.54] & 0.08, 7.86] \\ \hline Binary Ratio (\%) & [14.07, 85.93] & [52.73, 47.27] & [48.42, 51.58] \\ \hline \hline \end{tabular}
\end{table}
Table 1: Descriptive statistics of three datasets.
mance by calculating how many samples are correctly classified in total, while MAF1 can avoid the measurement bias caused by class imbalance and assess a model's discrimination ability more fairly.

We have implemented the proposed method in python 3.7 and run all the experiments on a machine of CentOS 7.9.2009 with 4 Tesla V100 and 2 Intel Xeon Gold 5218 @2.30GHz.

### Performance Comparison

To comprehensively evaluate the performance of our method, we conduct two experimental tasks of binary classification (BC) and multi-class classification (MC) on each dataset, where all the labels in MC other than the positive ones constitute the negative labels in BC. According to Table 1, the BC class ratios of Georgia and Sleep are more balanced than their MC class ratios, which enables BC tasks to serve as the control experiments concerning the label sparsity issue. Although the BC class ratio of CPSC is less balanced than MC class ratio, CPSC has a more balanced MC ratio than Georgia and Sleep, making it a control dataset to indicate the influence of class balance on model performance. Table 2 reports the ACC and MAF1 of different methods on two tasks times three datasets and denotes the best ACC and MAF1 for each task with boldface. Consistent with our intuition, the major observations are summarized as follows:

(1) We can see that our SWN variants significantly outperform four categories of TSC methods on three datasets with an average improvement of 9.28% on BC tasks and 31.40% on MC tasks. These results strongly testi

\begin{table}
\begin{tabular}{c c c c c c c c c c c c} \hline \hline  & \multicolumn{4}{c}{CPSC} & \multicolumn{4}{c}{Georgia} & \multicolumn{4}{c}{Sleep} \\ \cline{2-13} Method & \multicolumn{2}{c}{2 Classes} & \multicolumn{2}{c}{9 Classes} & \multicolumn{2}{c}{2 Classes} & \multicolumn{2}{c}{9 Classes} & \multicolumn{2}{c}{2 Classes} & \multicolumn{2}{c}{8 Classes} \\ \cline{2-13}  & ACC & MAF1 & ACC & MAF1 & ACC & MAF1 & ACC & MAF1 & ACC & MAF1 & ACC & MAF1 \\ \hline LS & 0.8400 & 0.4579 & 0.1554 & 0.0299 & 0.4970 & 0.4970 & 0.2814 & 0.1112 & 0.7847 & 0.7843 & 0.6946 & 0.3244 \\ ST & 0.6500 & 0.5911 & 0.6900 & 0.1331 & 0.5100 & 0.4516 & 0.2500 & 0.2319 & 0.8300 & 0.8311 & 0.5600 & 0.2839 \\ \hline SAX-VSM & 0.1617 & 0.1426 & 0.1483 & 0.1141 & 0.5973 & 0.5904 & 0.1272 & 0.1106 & 0.6868 & 0.6666 & 0.5771 & 0.2994 \\ WEASEL+MUSE & 0.8303 & 0.4987 & 0.2505 & 0.3850 & 0.6102 & 0.5561 & 0.5653 & 0.1567 & 0.7136 & 0.7126 & 0.5517 & 0.3334 \\ \hline MiniRocket & 0.8450 & 0.4646 & 0.0935 & 0.0220 & 0.5308 & 0.3802 & 0.0793 & 0.0164 & 0.9369 & 0.9363 & 0.6864 & 0.4211 \\ TapNet & 0.7167 & 0.5366 & 0.1372 & 0.1148 & 0.5132 & 0.5123 & 0.2695 & 0.1180 & 0.7910 & 0.7904 & 0.5742 & 0.2775 \\ \hline MCNN & 0.8564 & 0.4613 & 0.1044 & 0.0210 & 0.4850 & 0.3266 & 0.4850 & 0.0726 & 0.5011 & 0.3338 & 0.5039 & 0.0838 \\ LSTM-FCN & 0.8967 & 0.7865 & 0.6727 & 0.6134 & 0.5150 & 0.3399 & 0.1617 & 0.0607 & 0.7607 & 0.7566 & 0.6144 & 0.2489 \\ ResCNN & 0.8431 & 0.4574 & 0.1300 & 0.0489 & 0.5225 & 0.4976 & 0.1766 & 0.0417 & 0.7741 & 0.7575 & 0.1323 & 0.0535 \\ TCN (SWN w/o SD) & 0.8904 & 0.7734 & 0.6491 & 0.5423 & 0.5928 & 0.5883 & 0.5045 & 0.1740 & 0.8951 & 0.8946 & 0.7241 & 0.4645 \\ \hline SWN w/o CLM & 0.9014 & 0.7893 & 0.6924 & 0.6395 & **0.7590** & **0.7590** & 0.7246 & 0.3650 & 0.9198 & 0.9192 & 0.76425 & 0.5210 \\ SWN w/o SFI & 0.9085 & 0.8059 & 0.7397 & 0.6778 & 0.7350 & 0.7325 & 0.7156 & **0.4538** & 0.9346 & 0.9343 & 0.8023 & 0.5638 \\ SWN & **0.9101** & **0.8212** & **0.7516** & **0.7156** & 0.7096 & 0.7094 & **0.7365** & 0.4256 & **0.9374** & **0.9370** & **0.8093** & **0.5645** \\ \hline Improv (\%) & 1.49 & 4.41 & 8.93 & 16.66 & 19.70 & 20.58 & 45.99 & 83.53 & 4.73 & 4.74 & 11.77 & 21.53 \\ \hline \hline \end{tabular}
\end{table}
Table 2: The performance comparison between different methods on BC and MC tasks of three datasets with ACC and MAF1 metrics. The best performing methods are boldfaced and the best beaselines are underlined. Improv (%) measures the relative improvements of SWN variants over the best baselines. Note that the improvements are statistically significant with a two-sided t-test \(p\)\(<\)0.01.
of our method in dealing with the PSC problem especially on the condition of severe label sparsity issues.

(2) Our proposed ShapeWordNet surpasses the classical Shapelet-based ST and LS methods by a large margin, which underlines the significance of utilizing deep learning models to capture multivariate interaction and distilling both the local and global information for time series classification.

(3) Compared with SAX-VSM and WEASEL+MUSE, our method wins overwhelmingly on all tasks. We believe this phenomenon concretely demonstrates the advantages of ShapeWords in representing discriminative local patterns over the SAX words and SFA words. Besides, it also indicates learning abstract feature representations is more effective than relying on discrete statistical patterns.

(4) In contrast to the CNN-based methods that rank the second in 5 tasks (3 for LSTM-FCN and 2 for TCN), our method works particularly better on three MC tasks by obtaining an average of 19.09% rise in MAF1. Such a noticeable improvement soundly validates the effectiveness of leveraging ShapeWord Discretization and Cross-scale Contrastive Learning in label sparsity mitigation and invariant feature extraction.

### Ablation Study

To evaluate the effectiveness of each component, we investigate the performance of three variants. Firstly, we observe that SWN w/o CCLM substantially surpasses the SWN w/o SD by approximately 17.92% on CPSC MC, 12.16% on Sleep MC and 109.77% on Georgia MC in MAF1, which substantiates the effectiveness of ShapeWord Discretization in reducing noise disturbance and distilling prominent features. In addition, the fact that SWN and SWN w/o SFI defeat SWN w/o CCLM on 10 tasks with at least 5.99% rise of MC MAF1 tellingly verifies the remarkable progress made by the CCLM component in relieving the label sparsity. Moreover, the slight edges of SWN over SWN w/o SFI on 9 tasks indicate that SFI may contribute to promoting performance more or less.

### ShapeWord Discretization Analysis

As the results in Table 2 imply, ShapeWord Discretization plays the most critical role in boosting the model's generalization. Therefore, it is necessary to explain how it really takes effect. To investigate the interpretability and effectiveness of ShapeWord Discretization, we take a close look at its characteristics through two visualization experiments.

First, we conduct a case study to intuitively explore the interpretability of the ShapeWord Discretization. Figure 3 illustrates a case of two atrial fibrillation (AF) samples and two sinus rhythm (NSR) samples, where the four raw signals in blue lines are discretized into four ShapeSentences (\([1,1,8,8,1]\), \([8,8,1,1,1]\), \([1,1,1,3,1]\) and \([1,1,3,1,1]\)) in red lines respectively. It can be noticed that the pattern of AF, i.e. the disease of sustained tachyarrhythmia commonly seen in clinical practice, seems to be captured by the violently fluctuated ShapeWord \(SW_{8}\) presented below. In contrast, the peculiarities of NSR, i.e. the normal state,
seem to be represented by the combination of the ShapeWord \(SW_{1}\) and \(SW_{3}\). Hence, it is reasonable to believe that both the discriminative local patterns and their coherence can be well preserved via ShapeWord Discretization.

Second, to vindicate the contributions of ShapeWord Discretization to DL model's representation learning, we conduct the t-SNE analysis [26] to compare the representations output by SWN w/o CCLM and SWN w/o SD respectively on the Georgia BC task. In Figure 4(a) and 4(b), the sample representations output by SWN w/o CCLM (i.e. the variant with the ShapeWord Discretization) are more closely grouped with a clearer clustering boundary than those output by the SWN w/o SD, which defensibly testifies the effect of ShapeWord Discretization on relieving the influence of data noise and promoting the representational ability of deep neural networks.

### Hyper-parameter Sensitivity

In this section, we discuss the impact of several key hyper-parameters on the performance of our method, which includ the Scale Number \(N_{s}\), the Loss Balance Factor \(\lambda\), the ShapeWord Number \(N_{SW}\) and the ShapeWord Length \(L_{SW}\).

Figure 3: A case of two AF samples and two NSR samples transformed by ShapeWord Discretization with \(window\_size=50\). The raw signals are in blue lines and their ShapeSentences are in red ones, where each token refers to a ShapeWord shown below.
**Performance w.r.t. Scale Number.** We display the model performance w.r.t. the scale number \(N_{s}\) in Figure 5, where the scales for MST are successively picked from the range [5, 10, 25, 50, 100], e.g. 2 for [5, 10] and 3 for [5, 10, 25]. Figure 5(a) and Figure 5(b) show that for different datasets the impact of scale number is different and an ideal interval of this parameter shared by three datasets seems to be around [2, 3]. Based on this observation, we implement 3 scales of MST for SWN in our experiments.

**Performance w.r.t. Loss Balance Factor.** The parameter \(\lambda\) in Equation 10 is to balance the loss between classification training and contrastive learning. As is illustrated in Figure 5(c) and 5(d), the performance of SWN seems more likely to be affected by \(\lambda\) on MC tasks than on BC tasks, and the overlapping optimal interval of \(\lambda\) for three datasets is suggested to be \([0.3,0.7]\). In our experiment, we adopt \(\lambda=0.5\) as default given the fact that SWN obtains the best performance on two datasets under this condition.

**Performance w.r.t. ShapeWord Number.** Since ShapeWord is defined as the centroid of a cluster of similar shapelets, its number hence depends on the cluster number. In this article, we leverage K-means to generate ShapeWords. To exclude the impact of contrastive learning, we adopt the variant SWN w/o

Figure 4: T-SNE visualization of representations produced by (a) SWN w/o SD and (b) SWN w/o CCLM on Georgia BC task (0 indicates positive and 1 means negative).

Figure 5: SWN’s performance of MAF1 w.r.t. the number of scales \(N_{s}\) and the loss balance factor \(\lambda\) on three datasets over BC task and MC task.
CCLM to conduct the sensitivity experiment regarding the parameter of ShapeWord Number \(N_{SW}\). Graphs in Figure 6 show that despite the influence of ShapeWord Length \(L_{SW}\), the overlapping optimal interval of three datasets for \(N_{SW}\) is approximately \([5,12]\). In our experiment, we choose the class number as this parameter's default setting for each dataset (i.e. 8 for Sleep, 9 for CPSC and Georgia), which is also consistent with the original definition of shapelets.

**Performance w.r.t. ShapeWord Length.** It can be observed from Figure 6 that the performance curve of each dataset shows a trend of first moving up and then going down as \(L_{SW}\) increases, which indicates short ShapeWords are more suitable for physiological signal discretization. And the overlapping optimal interval of ShapeWord Length among three datasets is about \([10,50]\), which is why we choose the three scales \([10,25,50]\) for SWN.

## 5 Conclusion

In this paper, we proposed ShapeWordNet to deal with physiological signal classification. The uniqueness of our model is to generate prototypes of discriminative local patterns via shapelets and to discretize point-wise raw signals into token sequences of subseries. Given the label sparsity issue, we designed a cross-scale contrastive learning mechanism to assist model optimization, where a multi-scale ShapeSentence transformation strategy was adaptively utilized to augment the data. The experimental results demonstrated both the effectiveness and the interpretability of our method, paving the way for its extension to general time series analysis in the future.

**Acknowledgement.** This research was partially supported by grant from the National Natural Science Foundation of China (Grant No. 61922073). This work also thanks the support of fundings MAI2022C007 and WK5290000003.

Figure 6: Performance of SWN w/o CCLM w.r.t. ShapeWord Number in MC tasks under five different settings of ShapeWord Length.