{'fraction_non_alphanumeric': 0.027624309392265192, 'fraction_numerical': 0.013749372174786539, 'mean_word_length': 4.719569120287253, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
End-to-End Language Identification using Multi-Head Self-Attention and 1D Convolutional Neural Networks

In this work, we propose a new approach for language identification using multi-head self-attention combined with raw waveform based 1D convolutional neural networks for Indian languages. Our approach uses an encoder, multi-head selfattention, and a statistics pooling layer. The encoder learns features directly from raw waveforms using 1D convolution kernels and an LSTM layer. The LSTM layer captures temporal information between the features extracted by the 1D convolutional layer. The multi-head self-attention layer takes outputs of the LSTM layer and applies self-attention mechanisms on these features with M different heads. This process helps the model give more weightage to the more useful features and less weightage to the less relevant features. Finally, the frame-level features are combined using a statistics pooling layer to extract the utterance-level feature vector label prediction. We conduct all our experiments on the 373 hrs of audio data for eight different Indian languages. Our experiments show that our approach outperforms the baseline model by an absolute 3.69% improvement in F1-score and achieves the best F1-score of 95.90%. Our approach also shows that using raw waveform models gets a 1.7% improvement in performance compared to the models built using handcrafted features.


INTRODUCTION
A recent development in the area of deep neural networks has shown tremendous improvements in speech systems, including speech recognition [1,2,3], emotion recognition [20], speaker identification [13]. Previously, the language identification field was dominated by i-vectors [5], which uses Gaussian mixture models traditionally. Even today, i-vectors are considered to be the best model in the case of low data regime. However, recent developments in the field of deep learning show that deep neural networks are one of the dominating approaches in language identification. Previously, W. Geng et al. [4] proposed to use deep features extracted from a neural network trained for speech recognition and showed that deep neural models are capable of obtaining excellent performance over the classical systems [7,9,10,15,19]. Recently, Time-delay neural networks(TDNN) have shown excellent performance for speech recognition tasks [21]. Xvector [13] built for speaker identification was used for language identification [14], and its shown to be one of the best methods for language identification. The recent trend in sequence to sequence mapping problems [18] involves the attention mechanism [16]. The attention mechanism is one of the very well known techniques being used in sequence mapping problems [17], and today's state of the art speech recognition models are built using the attention-based models. These models process sequential inputs by iteratively selecting relevant features using attention technique. Due to the efficiency of the attention technique for sequence mapping problems, A. Vaswani et al. [22] propose to use stacks of attention layers alone. They have shown remarkable results in machine translation. Motivated by the work [22], this paper proposes to use multi-head self-attention in combination with 1D convolutional neural network front-end processing for language identification. Ours proposed model takes raw waveform as input directly and extracts features that are useful for the LID task. The model consists of a sequence of Residual blocks [23] of 1D convolutional layers to extract features from the raw audio. Since the convolutional layer does not have the capability to capture temporal information, we use an LSTM layer on top of the convolutional network to capture time-varying information from the input. Finally, the LSTM output feature sequence is fed into a multi-head selfattention block consisting of multiple attention heads to select important features from different parts of the input feature sequence using attention weighting. Finally, an utterance level feature vector is generating using a statistics pooling layer, and we classify the utterance level feature to predict the class label.The organization of the paper is as follows. In section 2, we explain our proposed approach in detail. In section 3, we give a detailed analysis of the dataset collection and curation process, and in section 4, we explain our experimental setup in detail. Finally, in section 5, we describe our results.

PROPOSED METHOD
In this section, we explain our proposed approach in detail. The detailed model architecture is shown in Figure 1. Our model consists of 3 main stages, 1) An Encoder layer, which includes multiple 1D convolutional layers with residual connections, an LSTM layer, 2) Multi-head self-attention layer to select important features for language identification using attention weighting, and 3)statistic pooling layer to obtain utterance level feature vector for classification. The model takes raw audio waveform as input and applies initial 1D convolution operations along with 1D max-pooling, as shown in Figure 1. The initial convolutional layer features will go through a series of there 1D Residual blocks followed by an LSTM layer. We then use multi-head self-attention to extract relevant features from different parts of the input. The statistics pooling layer generates an utterance level feature vector containing language discriminative properties. The output of the statistics pooling layer gives us a single feature vector called the utterance level feature vector. This utterance level feature vector is fed into a projection layer followed by a softmax layer to predict the class label. We explain the details of each of these blocks in the following section.

Encoder
The encoder of our model consists of a series of three residual blocks combined with a single LSTM layer, as shown in Figure 1. The encoder takes a raw waveform signal and applies an initial 1D convolution operation consisting of 64 filters of 1x7 filter size followed by a max-pooling operation. The max-pooling is applied with a kernel size of 1x3 with stride 2. After the initial convolution and max-pooling operation, we send the output a sequence of residual blocks. The details of a single residual block is shown in Figure 1. Each residual blocks operate with 1D convolution kernels of size 1x3. Residual Block -1 consist of 2*64 convolution kernels of size 1x3, Residual Block -2 consist of 2*128 convolution kernels of size 1x3 and Residual Block -3 contains 2*256 convolution kernels of size 1x3. The output of Residual Block -2 and Residual Block -3 will go through a 1D max-pooling operation. Since LSTMs are known to capture long-range dependencies between frames in speech, we use LSTM at the end of the final residual block to capture temporal information. The output of the final residual block Residual Block -3 after the max-pooling operation is sent to a single unidirectional LSTM layer with a hidden size of 256. Let X n = [x 1 , x 2 ..x n , ...x N ] be raw audio sequence with N samples.
Where, Encoder is a mapping function which consists of initial 1D convolutional layer and max-pooling operation, sequence of there residual blocks Residual Block-1,Residual Block-2 and Residual Block-3 along with LSTM layer . After this operation, we obtain a feature sequence Typically after the convolution operation, H A can be looked at as a feature matrix whose x-axis is a time dimension, and the y-axis is a feature dimension. The feature dimension in our case is 256, as the hidden layer size of the LSTM is the same.

Multi-Head Self-Attention
In this section, we describe multi-head self-attention in detail. It consists of 3 different linear blocks, one for query, one for key, and another for value. Each linear block consists of M independent linear layers. Where M is the number of heads. The multi-head attention block takes features Where d q is the dimension of the query vector. We combine the attention output from all the heads using simple concatenation and feed into the feed-forward layer.
Where, A i is a d q xT dimensional matrix. Since the Concat operation is applied to the feature dimension of all the matrices, the final output attention matrix A from the multi-head attention block will have M d q xT matrix dimensions.
The multi-head attention layer helps in finding features that are more relevant for language identification. The scaled dot product attention achieves this by giving more weighting to the more relevant features and less weighting to less relevant features. Due to the presence of multiple heads in the attention layer, this process selects features from different parts of the input and helps in obtaining better language classification performance.

Statistics pooling
The idea of the statistics pooling layer is similar to max pooling. In the case of statistics pooling, we compute the mean and standard deviation from frame-level features. The mean and standard deviation features are concatenated to create the utterance level feature vector, as described in the equation below. Let A = [a 1 , a 2 .....a T ] is the output from multi-head attention block.
Where, a i is a feature vector of dimension M * d q and P is final pooled feature vector using statistics pooling layer. Since the dimension of the utterance level feature vector is P become bigger when M is large, we add a projection layer on top to the statistics pooling layer (Figure 1) in order to reduce the dimension of P . We take the output from this projection layer to visualize the utterance level embeddings for different languages.

DATASET
In this section, we describe our data collection process. We collect and curate videos from Youtube 1 using manual labeling. We ask annotators to look for videos for eight languages in Youtube and manually verify it make sure the video does not contain multiple Indian languages. Most of these videos contain background noise or music signals. Sometime the video may contain a mix of English and other Indian languages due to code-mixing. We use an in-house speech v/s non-speech detection model to detect only the speech segments. We clip only the speech segments from every video and discard the non-speech part of the video. After preprocessing, our total dataset contains 373.27 hrs of audio data for 8 Indian languages. Our dataset includes Hindi, English, Kannada,Tamil, Telugu, Malayalam, Gujarati and Marathi. These languages are officially spoken in the North and South regions of India. We split the dataset into training and evaluation part, and the statistics of the training and evaluation parts are shown in Table 1.

EXPERIMENTS
We conduct all our experiments on in house dataset collected for 8 Indian languages. Our proposed model consists of an encoder, multi-head self-attention block, and statistics pooling layer followed by projection and a softmax layer. We randomly select a 4sec audio signal from each audio file during training. Since our data has a sampling rate of 16KHz, we get 64000 samples from every file during training. We feed a 1x64000 dimensional signal into our encoder. We conduct multiple experiments to see the effectiveness of the 1  multi-head self-attention module for language identification. We first train a standalone 1D convolutional neural network model as the first baseline model. We refer this system as ResNet. We also train a 1D convolutional neural network in combination with a unidirectional LSTM as a second baseline, and we refer to it as ResNet-LSTM. Finally, our proposed model is built using a 1D convolutional neural network, LSTM, and multi-head self-attention. We refer to it as ResNet-LSTM-MHA-Raw. We conduct multiple experiments to see the effectiveness of our model on the duration of the audio during training. We train 3 different models ResNet-LSTM-MHA-2Sec, ResNet-LSTM-MHA-3Sec, ResNet-LSTM-MHA-4Sec which takes 2sec,3sec and 4sec audio data respectively during training. Our final experiments study the effectiveness of using raw waveform methods instead of handcrafted features. We set up an experiment to train the model using MFCC features as inputs instead of the raw waveform to our model. We extract 13 dimensional MFCC (with delta and doubledelta) feature for every 25ms using a 10ms frameshift for this experiment. The MFCC based model is referred to as ResNet-LSTM-MHA-MFCC while the raw waveform based model is referred to as ResNet-LSTM-MHA-Raw in this paper. We use Adam [24] optimizer to train all our models with a learning rate of 0.001 for up to 25 epochs. We use a batch size of 64 during training. We train all our models using Pytorch 2 toolkit.

RESULTS
In this section, we describe the evaluation of different models and their performances. We train 2 baseline models ResNet and ResNet-LSTM. The first baseline model ResNet consists fo a sequence of 3 Residual blocks made up of 1D convolution kernels. We can think of this model as a ResNet [23] with an average pooling layer replaced by a statistics pooling layer. This model takes 4sec raw audio data and predicts the language label. The ResNet model has an F1-score of 88.67% on the test dataset. The second baseline model ResNet-LSTM consists of the same setting as baseline-1, but it has an extra LSTM layer on top of CNN in order to capture long-range temporal information. The performance of this model is 92.21%, as shown in Table 2. We compare our baseline models with our proposed model ResNet-LSTM-MHA-RAW, which contains a multi-head attention layer and operates with the raw waveform as input. Table 2 shows that our model gets 3.69% absolute improvement in F1-score compared to the second baseline model. We also create a model that takes MFCC features as input instead of raw audio refer to as ResNet-LSTM-MHA-MFCC. We show that raw waveform based models can get 1.7% improvement over handcrafted feature-based models.  In order to see the effect of the input length during training, we conduct an experiment to train the model using 2Sec, 3Sec, and 4Sec audio data, and we refer to these models as ResNet-LSTM-MHA-2Sec, ResNet-LSTM-MHA-3Sec and ResNet-LSTM-MHA-4Sec respectively. The results of these experiments are shown in Table 3. It shows that longer audio data tends to improve the F1-score on the test data due to longer context signals. Finally, we visualize the utterance level embeddings extracted from the projection layer for all the languages. We extract embeddings for 6500 randomly selected test utterances for t-sne visualization. Each embedding has dimension. We reduce the dimension of the embeddings to 2 using the t-sne technique. The t-sne plot of the 2-D embeddings is shown in Figure 2. It can be clearly seen that the proposed model learns very good language discriminative features at the segment level.

CONCLUSION
In this work, we propose a new architecture for language identification using multi-head self-attention and 1D convolutional neural networks. We propose to use raw waveform directly as input instead of handcrafted features to learn language discriminative feature using 1D convolution operations. Our model uses multi-head self-attention to learn and select more important features for language identification task. We finally use a statistics pooling approach to extract utterance level language representation from framelevel features. We collect and curate 373hrs audio data for 8 Indian languages Hindi, English, Kannada,Tamil, Telugu, Malayalam, Gujarati and Marathi. Our experiments show that multi-head self-attention in combination with raw waveform based 1D convolutional neural network model obtains the best performance on our evaluation dataset. We extract the utterance level embeddings for our evaluation data and visualize the clustering effect using t-sne. The visualization clearly shows that the model learns very good language discriminative features.