{'fraction_non_alphanumeric': 0.03837505621346125, 'fraction_numerical': 0.010230849947534103, 'mean_word_length': 4.830238147258029, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deep Attention-based Representation Learning for Heart Sound Classification

Cardiovascular diseases are the leading cause of deaths and severely threaten human health in daily life. On the one hand, there have been dramatically increasing demands from both the clinical practice and the smart home application for monitoring the heart status of subjects suffering from chronic cardiovascular diseases. On the other hand, experienced physicians who can perform an efficient auscultation are still lacking in terms of number. Automatic heart sound classification leveraging the power of advanced signal processing and machine learning technologies has shown encouraging results. Nevertheless, human hand-crafted features are expensive and time-consuming. To this end, we propose a novel deep representation learning method with an attention mechanism for heart sound classification. In this paradigm, high-level representations are learnt automatically from the recorded heart sound data. Particularly, a global attention pooling layer improves the performance of the learnt representations by estimating the contribution of each unit in feature maps. The Heart Sounds Shenzhen (HSS) corpus (170 subjects involved) is used to validate the proposed method. Experimental results validate that, our approach can achieve an unweighted average recall of 51.2% for classifying three categories of heart sounds, i. e., normal, mild, and moderate/severe annotated by cardiologists with the help of Echocardiography.


I. INTRODUCTION
A S reported by the World Health Organisation (WHO), Cardiovascular diseases (CVDs) are the first leading cause of death globally, which made 17.9 million people dead in 2016 (representing 31 % of all global deaths) [1]. More seriously, this number is predicted to be around 23 million per year by 2030 [2]. Early-stage diagnosis and proper management of CVDs can be very beneficial to mitigate the high costs and social burdens by coping with serious CVDs [3], [4]. Auscultation of the heart sounds, as a cheap, convenient, and non-invasive method, has been successfully used by physicians for over a century [5]. However, this clinical skill needs tremendous training and is still difficult for more than 20 % of the less experienced medical interns to efficiently use [6]. Therefore, developing an automatic auscultation framework can facilitate the early cost-effective screening of CVDs, and at the same time, to manage the progression of its condition [5].
Computer audition (CA) and its applications in healthcare [7] have yielded encouraging results in the past decades. Due to its non-invasive and ubiquitous characteristic, CAbased methods can facilitate automatic heart sound analysis studies, which have already attracted a plethora of efforts [5]. Additionally, benefited from the fast development of machine learning (ML), particularly, its subsets, i. e., deep learning (DL), and the prevalent smart sensors, wearables, devices, etc., intelligent healthcare can be implemented feasibly in this era of AIoT (artificial intelligence enabled internet of things). A systematical and comprehensive review of the existing literature on heart sound analysis via ML was provided in [5]. In the early works, designing efficient features ranging from classic Fourier transformation to multi-resolution analysis (e. g., wavelet transformation) dominated the well-documented literature in this field. To the recent years, using DL models for analysing and extracting high-level representations from heart sounds automatically has increasingly been studied [8]. Furthermore, as indicated in [9], the current trend is to classify the heart sounds from the whole audio recording without any segmentation step. On the one hand, the state-of-the-art DL methods aim to build a deep end-to-end architecture that can learn high-level representations from the heart sound itself without any human hand-crafted features. On the other hand, the DL models are restrained by the generalisation of the learnt representations from a limited data set. However, with the DLbased systems of heart sounds analysis, black-box DL models cannot produce transparent and understandable decisions for physicians to provide the next physical examination and an appropriate treatment. Making explainable decisions via DLbased systems is a trend to enhance the trust of physicians in the systems and promote their application in the medical area [10]. In the recent study [11], a promising attention mechanism was proposed to explain the DL models via visualising the internal layers.
To this end, we propose a novel attention-based deep  representation learning method for heart sound classification in this study (Fig. 1). The main contributions of the work are: First, to the best of our knowledge, it is the first time to introduce an attention mechanism to heart sound classification. By leveraging the power of a global attention pooling layer, the DL models can learn more robust and generalised highlevel representations from the heart sound. Second, we make a comprehensive investigation and comparison of the topologies of DL models, i, e., convolutional neural networks (CNNs) and recurrent neural networks (RNNs), and validate them on an open access database, i. e., HSS, hence rendering our studies reproducible and sustainable. Third, we compare the proposed method with other state-of-the-art approaches using the same database and standard processing. In addition, we explore the visualisation of the learnt high-level representations of our proposed DL models using an attention mechanism, which can contribute to an explainable AI (XAI) [12]. Last but not least, we indicate the current limitations and give our perspectives in this domain, which can be a good guidance for future work.
The remainder of this paper will be structured as follows: First, a brief description of related work will be given in Section II. Then, we introduce the database and methods used in Section III. The experimental results and discussion are illustrated in Section IV and Section V, respectively. Finally, we summarise our work in Section VI.

II. RELATED WORK
In the classic ML paradigm, human hand-crafted feature extraction is a prerequisite, which aims to design a series of efficient and robust features from the signals for specific tasks, e. g., heart sound classification. Among the features, wavelet transformation (WT) based representations showed efficient and excellent performance. For instance, wavelet features fed into a least square support vector machine (LSSVM) can enable to recognise the cases of normal, aortic insufficiency, aortic stenosis, atrial septal defect, themitral regurgitation, and themitral stenosis [13]. Moreover, Uguz designed entropy features of sub-bands by using discrete wavelet transformation (DWT) for classifying heart sounds [14]. Similarly, tunable-Q wavelet transformation (TQWT) based features that characterise the various types of murmurs in cardiac sound signals were introduced in [15]. Wavelet packet transformation (WPT) based features were used in [16], by which a full decomposition tree can be generated in one-level decomposition process. Besides using the directly extracted low-level descriptors (LLDs) of the wavelet features, some high-level representations can also be derived. For example, auto-correlation features can be extracted from the sub-band envelopes that are calculated from the sub-band coefficients of the heart sound by DWT [17]. A combination of WT and WPT energy-based features combined with a deep RNN model was proposed in [18]. Compared with the conventional short-time Fourier transformation (STFT) based features used for heart sound classification (cf. [19]), wavelet features can provide a multiresolution analysis of the non-stationary signals (heart sounds). This capacity helps to optimise the Heisenberg-alike timefrequency trade-off in time-frequency transformations [20].
Nevertheless, wavelet transformation still has its own drawbacks. In particular, designing a suitable wavelet function is not an easy job, which demands tremendous empirical experiments for specific tasks. Benefited from the fast development of DL, the heart sound feature extraction can be realised without a domain knowledge. The higher representations of the heart sounds can be automatically extracted from (pretrained) CNNs and be fed, e. g., into an SVM classifier [21]. Amiriparian et al. introduced an unsupervised representation learning method using an auto-encoder-based recurrent neural network in the paradigm of sequence-to-sequence (Seq2Seq) learning [22]. In a most recent work, Fernando et al. introduced the attention based deep learning model for the heart sound segmentation task, and indicated that their model outperformed the state-of-the-art baseline methods [23].
With the generated high-level representations, most end-toend deep representation learning methods, particularly CNNs and RNNs, use a global pooling layer to summarise the highdimensional representations into one-dimensional vectors for later classification [24], [25]. For example, global max-pooling selects the maximum value from each two-dimensional feature map in CNNs [25]. Yet, our previous study has shown that global max-pooling loses the contribution of the other smaller values [26]. Global attention pooling was proposed in [25] to improve the performance of CNNs through estimating the contribution of each unit in the feature maps to the classification task. An attention mechanism was also employed to explain the decisions via visualising the internal layers of DL models in [11], [26]. With the inspiration of global attention pooling [11], we will show the effectiveness of CNNs with attention at the time-frequency level, and RNNs with attention at the time level, respectively. The input of the deep learning models is thereby the log Mel spectrograms of heart sound signals.

III. MATERIALS AND METHODS
In this section, the HSS corpus, which was collected for heart sound classification, will be firstly introduced. Afterwards, two DL topologies, including a CNN and an RNN, are presented, and the attention mechanisms applied to each of them are described in details. Finally, the evaluation metrics for the task of heart sound classification will be given.

A. HSS Corpus
The HSS corpus was established by Shenzhen University General Hospital, Shenzhen, P. R. China [9]. Please note that the study [9] was approved by the ethic committee of the Shenzhen University General Hospital. During the data collection, 170 participants (Female: 55, Male: 115, Age: 65.4 ± 13.2 years) were involved. Specifically, the heart sound signals were recorded from four positions on the body of each subject, including auscultatory mitral, aortic valve auscultation, pulmonary valve auscultation, and auscultatory areas of the tricuspid valve, through an electronic stethoscope (Eko CORE, USA) using Bluetooth 4.0 and 4 kHz sampling rate. Then, experienced cardiologists annotated the data into three categories: normal, mild, and moderate/severe by using Echocardiography as the golden standard. Finally, 845 audio recordings, each of which has around 30 s, were obtained, i. e., approximately 7 hours. Considering subject-independency, and balanced age and gender distribution, the HSS corpus was split into three data sets: train, dev(elopment), and test sets (cf. Table I). For more details on the HSS collection and further information, interested readers are suggested to refer to [9].

B. Deep Learning Models
In essence, DL is a series of non-linear transformations of the inputs, resulting in the highly abstract representations which have shown effectiveness in audio classification tasks [21], [27]. For this study, two typical DL topologies, i. e., a CNN (with a strong feature extraction capacity) and an RNN (which can capture the context information from timeseries data), will be investigated.
1) Convolutional Neural Network: With a strong capability of feature extraction, CNN models have been applied to heart sound classification in previous research [28], [29]. As shown in Fig. 2, a CNN model generally contains a stack of convolutional layers and local max-pooling layers to extract highlevel representations. Convolutional layers capture abstract features using a set of convolutional kernels, which achieve convolution operations on the input or the feature maps from the intermediate layers. At the -th layer, = 1, ..., , where is the total number of layers, an × × feature map h is produced, where is the number of channels, and × stands for the size of h at each channel. While the ( + 1)th layer is a convolutional layer, the -th channel of h +1 is calculated by where h is the -th channel of h , w +1 denotes the ( , )th convolutional kernel, * is the convolutional operation, and +1 is the bias. Each two-dimensional convolutional kernel works on the feature maps at each channel, therefore the convolutional layers can learn the representations at the timefrequency level. Notably, batch normalisation and an activation function of rectified linear unit (ReLU) are utilised to deal with the output of each convolutional layer, as batch normalisation usually improves the stability of CNNs, and both of them can accelerate the convergence speed [30].
Convolutional layers with batch normalisation and a ReLU activation function are mostly followed by local pooling layers, which reduce the computational cost via downsampling the feature maps [31]. Through local pooling layers, the robustness of CNNs is also improved against the input variation [31]. Since local max-pooling has been successfully employed in our previous study [25], we use local max-pooling layers following each convolutional layer.
2) Recurrent Neural Network: RNNs can extract sequential representations from time-series data using a set of recurrent layers (cf. Fig. 3). Each recurrent layer contains a sequence of recurrent units, each of which is used to process the corresponding time step of the input data. The hidden states, output from each recurrent layer, are fed into the next recurrent layer. Finally, the hidden states of the final recurrent layer are used to predict the classes of the samples.
We define the number of the total time steps by . At the -th time step, = 1, ..., , a traditional recurrent unit computes its output via a weighted sum of the input and the hidden state ℎ −1 . Due to the vanishing gradient problem caused by the traditional recurrent unit [32], in particular, two recurrent units were proposed in the literature: Long Short-Term Memory (LSTM) cells [33], and Gated Recurrent Units (GRUs) [34].
At the -th time step, an LSTM unit consists of an input gate , an output gate , a forget gate , and a cell state . The procedure of an LSTM unit is defined by where w and u are the weight matrices, denotes the bias, stands for a logistic sigmoid function, and means the element-wise multiplication. Compared to the traditional recurrent unit, an LSTM cell can control what information to remember using an input gate, and what to forget using a forget gate.
Different from an LSTM cell, a GRU contains a reset gate and an update gate at the time step. The procedure of a GRU is defined by = (w z + u z ℎ −1 + ), With two gates inside one unit, a GRU has less parameters than an LSTM cell. As both LSTM-RNN and GRU-RNN have been employed in audio classification tasks [9], [35], the effectiveness of them are explored in this study.
In a similar way to CNNs, a layer normalisation [36] and an activation function of scaled exponential linear unit (SELU) [37] are set to follow each recurrent layer, since layer normalisation can stabilise the hidden state dynamics in RNNs [36], and the SELU activation function has been successfully applied in the previous study [37].

C. Attention Mechanism
It is essential to interpret the key parts of the input inside a deep learning model, especially in the applications of medical diagnosis. As aforementioned in Section II, global attention pooling can evaluate the contribution of each unit in a representation. We will now introduce the attention mechanisms in CNNs and RNNs, respectively.
1) Attention in a CNN: While a log Mel spectrogram is fed into a CNN model, the feature map h output by the final layer before the attention mechanism has three dimensions × × , where is the number of channels, and × denotes the feature map size at the time-frequency level. To achieve the heart sound classification, the dimensions of h are reduced from three into one. During this procedure of dimension reduction, the global attention pooling evaluates that how much each time-frequency bin in h devotes to the final predictions by estimating a weight value for each bin. As shown in Fig. 2 where * is the output of the bottom component. Next, the feature map from the top component is multiplied with * , leading to an element-wise product, which is then summed to a vector with the length equalling the number of classes. Finally, log softmax is employed to fit the chosen negative log-likelihood (NLL) loss function.

2) Attention in RNN:
The representation from the recurrent layers has two dimensions × , where denotes the length of feature at each time frame. While summarising the representation to a vector for classification, it would be worth to explain the essential time frames using global attention pooling in RNNs. As the length of the time frames is equal to that of the original log Mel spectrogram, an attention mechanism can show more details at the frame level in RNNs than in CNNs.
As shown in Fig. 3, the global attention pooling in RNNs also includes two components as the attention mechanism in CNNs. In a similar way to the attention mechanism in CNNs, the left component (corresponding to the top one in Fig.2) here contains a one-dimensional convolutional layer, in which the kernel size is 1 and the output channel number is equal to the class number, leading to a classification tensor of size × . The right component (corresponding to the bottom one in Fig.2) consists of a convolutional layer with the same setting as that in the left component, and a normalisation procedure. In the right component, the convolutional layer is also followed by an activation function (softmax or sigmoid) to rectify the values of the representation. Then, a normalisation is applied to the rectified representation using * = =1 , (11) where * is the normalised feature in the right component. The element-wise product of * and is then followed by a log softmax layer for the heart sound classification.

D. Evaluation Metrics
To evaluate the performance of the proposed models, the unweighted average recall (UAR) is employed as the main evaluation metric by taking the imbalanced characteristic of the HSS database and the inherent phenomena into account. Compared to another popular evaluation metric, weighted average recall (WAR), aka accuracy, UAR shows more reasonable in measuring the performance of a model trained by imbalanced data [38]. The value of UAR is defined as: where is the recall achieved for the -th class, and denotes the number of classes ( = 3 in this study).
Additionally, when comparing two methods' performances, we use a one-tailed -test [39] by checking if a finding is significant ( < 0.05) or not.

IV. EXPERIMENTAL RESULTS
We give a brief description of our experimental setup at first. Then, we present and discuss the results achieved in this study.

A. Setup
First, a series of 936×64 log Mel spectrograms are extracted from the audio signals in the HSS corpus using a Hamming window of 256 samples width with 50 % overlap and 64 Mel frequency bins. During training, all models are learnt with an Adam optimiser and a batch size of 32. The initial learning rate is empirically set to 0.0001, and is reduced into 90 % at each 100-th iteration with the aim of stabilising the training process. Finally, the learnt models at the 3 000-th iteration are used to predict the audio samples in the development/test set.
All models employ a flattening layer or a global pooling layer before the final log softmax layer for classification. The structures before the flattening or global pooling layer in the deep neural networks are empirically set as follows.
• The CNN models consist of four convlutional layers with output channels 64, 128, 256, and 256. Each convolutional layer is followed by a local max-pooling layer with 2 × 2 kernels. • Both LSTM-RNN and GRU-RNN models contain three recurrent layers with output channels 256, 1 024, and 256. To investigate the effect of balanced training set to the DL models, we compare the results on the original imbalanced HSS data and balanced HSS training data produced by a random upsampling strategy aiming at class-balance [40].

B. Results
The experimental results (UARs in [%]) of all three DL topologies (CNN, LSTM-RNN, and GRU-RNN) are shown in Table II. The best result (a UAR of 51.2 %) is achieved by the CNN model with attention mechanism (using a sigmoid function). The best results for LSTM-RNN and GRU-RNN are 42.6 % UAR and 46.8 % UAR, respectively. We can see that, an attention-based mechanism can significantly improve the corresponding DL models in recognising heart sound. For instance, CNN with sigmoid-attention (a UAR of 51.2 %) performs better than a CNN with flattening (UAR of 37.6 %), and a CNN with max-pooling (an UAR of 38.4 %) (in a onetailed z-test, < 0.01), and a GRU-RNN with softmaxattention (a UAR of 46.8 %) outperforms GRU-RNNs without attention (UARs of 36.1 % and 35.2 %) (in a one-tailed z-test, < 0.05). The upsampling strategy can slightly improve the performances of the best RNN models. Compared to other state-of-the-art studies, our proposed method can perform better than most performances achieved by single models (cf .  Table III).
When looking at the confusion matrices (cf. Fig. 4), we find that the best CNN and GRU-RNN models outperform the best LSTM-RNN model in recognising the 'Mild' type of heart sounds. For all the three models, both the 'Normal' and 'Mod./Sev.' types of heart sounds are incorrectly recognised as the 'Mild' type of heart sounds. Fig. 5 and Fig. 6 present the macro-averaged receiver operating characteristic (ROC) curves and the visualisation of the best three proposed attention-based DL models on each class, respectively.

V. DISCUSSION
In this section, we summarise the findings from this study. Afterwards, we indicate the limitations and future work by providing our perspectives.

A. Findings of this Study
In this study, simple data augmentation (upsampling) cannot yield significantly better results than using the original data set (cf . Table II). We may think that the upsampling technique cannot generate sufficiently informative instances for improving the models' performances. A CNN is found to be superior to an RNN in recognising heart sounds in this study. As shown in Fig. 5, the ROC curve of the considered CNN and GRU-RNN can yield a higher true positive rate at a given false positive rate compared to the LSTM-RNN, and the true positive rate of the CNN is superior to or comparable to that of our GRU-RNN. Finally, the area under the ROC curve (AUC) of the CNN is the highest in those of the three models.
As depicted in Fig. 6, compared to 'Normal' or 'Mild' types of heart sounds, the 'Mod./Sev.' type shows more irregular waveforms and spectrograms. In addition, by checking the learnt high-level representations of the CNN models, the 'Mod./Sev.' types of heart sounds can have a higher number of higher energy components than the other two types at the similar frequency bands.
Such irregular changes in frequency bands via the time axis of the heart sound might be caused by the pathological changes in the heart. When looking at the learnt representations of the RNN models (cf. Fig. 6), we can see the periodic signal's characteristics in the 'Normal' types of heart sound. It is worth exploring the fundamental mechanism of CVDs and their corresponding properties in heart sound's changes.

B. Limitations and Perspectives
Data size limitation is the biggest challenge in the current study. Moreover, similar as other clinical data studies, e. g., snore sound [44], asking experienced medical experts to annotate massive data is expensive, time-consuming, and even unavailable in practice. Even though the data augmentation did not show excellent performance in this study, it is a necessary step in improving the DL models' generalisation and robustness. More recently, some advanced data augmentation technologies, e. g., the generative adversarial networks (GANs) [45] can be considered. In future work, we should explore using more sophisticated data augmentation technologies for heart sound classification. Moreover, (labelled) data scarcity is a challenging issue for almost all of the biomedical areas including heart sound. One should consider using unsupervised learning, semi-supervised learning, active learning, and cooperative learning paradigms in future studies.
The best model's result is encouraging but modest. In a future effort, one should consider using hybrid network architectures [46] or model fusion strategies [47]. On the one hand, we can find the promising results achieved by the deep attention-based models. On the other hand, the inherited mechanism is still unclear. We tried to visualise the learnt representations of the hidden layers, but it failed to make any consolidate conclusion. Another direction is to explore the learnt representations by DL models, which aims to present the interpretations between the model architectures and the pathological meaning of the heart sound. An explainable AI is essential for intelligent medical applications.

VI. CONCLUSION
In this work, we proposed a novel attention-based deep representation learning method for heart sound classification. We also investigated and compared different topologies of the DL models and found the considered CNN model as the best option in this study. The efficacy of the proposed method was successfully validated by the publicly accessible HSS corpus. We also compared the results with other state-of-the-art work and pointed out the current limitations and future directions. For a three-category classification task, the proposed approach achieved an unweighted average recall of 51.2 %, which outperformed the other models trained by traditional human hand-crafted features or other deep learning approaches. In future work, we will improve our model's generalisation and explainability for the heart sound classification task.