# Text Sentiment Analysis of German Multilevel Features Based on Self-Attention Mechanism

Authors: Xiang Li
Journal: Security and Communication Networks
 (2021)

---

## Abstract

In this paper, we propose a multilevel feature representation method that combines word-level features, such as German morphology and slang, and sentence-level features, such as special symbols and English-translated sentiment information, and build a deep learning model for German sentiment classification based on the self-attentive mechanism, in order to address the characteristics of German social media texts that are colloquial, irregular, and diverse. Compared with the existing studies, this model not only has the most obvious improvement effect but also has better feature extraction and classification ability for German emotion.


---

## Body

## 1. Introduction

Big data in the context of the Internet has become an important force in promoting digital humanities research, and the analysis of sentiment tendencies in social media texts such as Twitter has been a hot topic of research in natural language processing [1]. German, one of the official languages of the United Nations and the eighth most spoken language in the world, is widely spoken in 17 countries in the Eastern European and Central Asian regions, and the total number of people who speak it as a native or second language is about 258 million [2]. As one of the main ways for people to communicate and express their emotions, social media generates a large amount of short texts in German with subjective emotions every day, and it is beneficial to summarize, analyze, and reason about the emotional information contained in them for making business decisions, analyzing political opinions, and predicting social trends in related countries [3]. It is of great value to prevent precise political marketing, build harmonious and stable international relations, promote transnational and interregional economic and trade, and carry out the “Belt and Road” strategy of win-win cooperation. However, most of the current studies in this area focus on English, which has a strong position, and most of the analysis tools are designed and implemented for the characteristics of English, but there are not many studies that specifically focus on cross-domain German sentiment analysis [4]. Some studies have attempted to obtain the results of sentiment analysis of German English translations with the help of English-related tools [5]. However, the results are not satisfactory because of the loss of emotional and even semantics in the translation phase and the neglect of the German language’s own characteristics in the analysis phase. There are two major difficulties in the sentiment analysis of German social media texts. (1) The German language has its own linguistic characteristics, which often include free order, multiple meanings, complex morphology, and nonprojective relations [6]. (2) Social media texts are characterized by colloquialism, slang, irregular language, and lack of obvious contextual information when conveying information, evaluating objects, or expressing opinions, which makes it difficult to obtain satisfactory results by using common sentiment analysis methods [7].To address the above difficulties and the characteristics of the German network language, this paper uses deep learning methods to accomplish the following work. Section2 compares, analyzes, and compares recent research results on German sentiment analysis. Section 3 analyzes, filters, and processes word-level and sentence-level sentiment features extracted from multiple perspectives. Section 4 combines various deep learning techniques, such as CNN, RNN, and self-attention. In Section 5, we explore the feasibility of using a sentiment analysis scheme for English translations based on the experimental results of sentiment classification of German tweets (hereafter referred to as tweets). The results before and after the addition of various word-level and sentence-level features are compared, and the sample analysis proves that the model in this paper can effectively improve the sentiment analysis results of German tweets.


## 2. Related Work

Sentiment analysis (SA) aims to identify subjective attitudes in unstructured texts, and one of the main tasks is to classify the opinions and tendencies of the authors concerned [8]. At present, there is a paucity of research on sentiment analysis for the German language, which usually draws on the analysis methods of English and other languages [9], and there is a clear lack of research that incorporates the characteristics of German itself. Existing sentiment analysis of social media texts mainly uses lexicon-based, machine learning or deep learning methods, and in particular deep learning methods have been prominent in many tasks in recent years [10, 11].


### 2.1. Lexicon-Based Sentiment Analysis of German

The core model of the lexicon-based approach is to extract sentiment discrimination rules and construct sentiment dictionaries, that is, to formulate and aggregate judgment rules designed based on words, phrases, and syntactic structures and to use sentiment dictionaries as the main basis for judging sentiment polarity. Reference [12] implemented a rule set-based classifier for the textual features of German in the field of telecommunications, and its F1 is higher than that of SVM and maximum entropy classifier, but the method is more dependent on the experience and personal ability of language or domain experts, and not only the maintenance and expansion cost of the rule set is high, but also it is difficult; this method relies more on the experience and personal ability of language or domain experts, and it is not only expensive to maintain and expand the rule set, but also difficult to develop rule sets suitable for multiple languages and cross-domains. Reference [13] constructed Ru Senti Lex, a German universal sentiment dictionary with four sentiment levels per word, for the cross-domain problem, and achieved good results in the SentiRuEval-2016 Twitter reputation monitoring task based on this dictionary. In the same year, [14] automatically extended the sentiment dictionary for the target-oriented text classification task in SentiRuEval-2015 based on the statistical results of target-oriented N-gram features and lexical sentiment values, and the maximum entropy classifier of this method was higher than the manually constructed dictionary in terms of accuracy, recall, and F1.Although lexicon-based sentiment analysis methods can reflect the unstructured features of text, they depend on the quality of the judgment rules and sentiment dictionaries, and their degree of merit basically depends on manual design and a priori knowledge, which is difficult to cover the endless new words and complex and diverse forms of German language on the Internet.


### 2.2. German Sentiment Analysis Based on Machine Learning

Feature engineering is the key to the success or failure of machine learning-based algorithms for processing sentiment classification tasks, and the features commonly used in experiments include N-gram features, TF-IDF features, syntactic features, and lexical features. Reference [15] compared various machine learning models for German bank loan review texts and finally found that all models were more than 85% accurate, and the SVM outperformed the NB (Naive Bayes). Reference [16] created their own corpus (331 cross-domain German news articles) and found that the SVM algorithm outperformed the NB. However, [17] found that the NB algorithm outperformed the SVM algorithm in terms of F1 for sentiment classification in three domains, namely, economy, society, and sports, in a comparison experiment on a self-developed corpus (331 cross-domain German news articles). It can be seen that the suitability of feature selection is a major factor affecting the effectiveness of machine learning classification, and the features that perform well in a particular domain may not necessarily perform well in other domains.


### 2.3. Deep Learning-Based Sentiment Analysis of German

The rise of deep learning has greatly influenced the current state of research in sentiment analysis. Reference [18] compared various deep learning models on 30,000 German news corpus, in which a two-layer stacked LSTM network successfully overcame the shortcomings of gradient explosion and gradient disappearance of ordinary RNNs with strong sequence memory capability and obtained the best accuracy of 86.3 percent. Reference [19] used character-level embedded CNNs to extract local features of text and expand the training corpus by replacing synonyms for restaurant and product German reviews and improved the accuracy by 2.4%. Although all the above studies attempted to build a deep model with multiple hidden layers, the network structure was relatively simple and homogeneous, which not only failed to effectively combine local and sequence features of the text to extract deeper sentiment information but also was limited by the black-box nature of the deep learning model, which made it difficult to make full use of the characteristics of the German language and common sense sentiment.


## 2.1. Lexicon-Based Sentiment Analysis of German

The core model of the lexicon-based approach is to extract sentiment discrimination rules and construct sentiment dictionaries, that is, to formulate and aggregate judgment rules designed based on words, phrases, and syntactic structures and to use sentiment dictionaries as the main basis for judging sentiment polarity. Reference [12] implemented a rule set-based classifier for the textual features of German in the field of telecommunications, and its F1 is higher than that of SVM and maximum entropy classifier, but the method is more dependent on the experience and personal ability of language or domain experts, and not only the maintenance and expansion cost of the rule set is high, but also it is difficult; this method relies more on the experience and personal ability of language or domain experts, and it is not only expensive to maintain and expand the rule set, but also difficult to develop rule sets suitable for multiple languages and cross-domains. Reference [13] constructed Ru Senti Lex, a German universal sentiment dictionary with four sentiment levels per word, for the cross-domain problem, and achieved good results in the SentiRuEval-2016 Twitter reputation monitoring task based on this dictionary. In the same year, [14] automatically extended the sentiment dictionary for the target-oriented text classification task in SentiRuEval-2015 based on the statistical results of target-oriented N-gram features and lexical sentiment values, and the maximum entropy classifier of this method was higher than the manually constructed dictionary in terms of accuracy, recall, and F1.Although lexicon-based sentiment analysis methods can reflect the unstructured features of text, they depend on the quality of the judgment rules and sentiment dictionaries, and their degree of merit basically depends on manual design and a priori knowledge, which is difficult to cover the endless new words and complex and diverse forms of German language on the Internet.


## 2.2. German Sentiment Analysis Based on Machine Learning

Feature engineering is the key to the success or failure of machine learning-based algorithms for processing sentiment classification tasks, and the features commonly used in experiments include N-gram features, TF-IDF features, syntactic features, and lexical features. Reference [15] compared various machine learning models for German bank loan review texts and finally found that all models were more than 85% accurate, and the SVM outperformed the NB (Naive Bayes). Reference [16] created their own corpus (331 cross-domain German news articles) and found that the SVM algorithm outperformed the NB. However, [17] found that the NB algorithm outperformed the SVM algorithm in terms of F1 for sentiment classification in three domains, namely, economy, society, and sports, in a comparison experiment on a self-developed corpus (331 cross-domain German news articles). It can be seen that the suitability of feature selection is a major factor affecting the effectiveness of machine learning classification, and the features that perform well in a particular domain may not necessarily perform well in other domains.


## 2.3. Deep Learning-Based Sentiment Analysis of German

The rise of deep learning has greatly influenced the current state of research in sentiment analysis. Reference [18] compared various deep learning models on 30,000 German news corpus, in which a two-layer stacked LSTM network successfully overcame the shortcomings of gradient explosion and gradient disappearance of ordinary RNNs with strong sequence memory capability and obtained the best accuracy of 86.3 percent. Reference [19] used character-level embedded CNNs to extract local features of text and expand the training corpus by replacing synonyms for restaurant and product German reviews and improved the accuracy by 2.4%. Although all the above studies attempted to build a deep model with multiple hidden layers, the network structure was relatively simple and homogeneous, which not only failed to effectively combine local and sequence features of the text to extract deeper sentiment information but also was limited by the black-box nature of the deep learning model, which made it difficult to make full use of the characteristics of the German language and common sense sentiment.


## 3. Multilevel Emotional Characteristics of German Tweets

This paper develops a systematic feature extraction rule for German social texts that are “colloquial, irregular, multisense, and diverse” and is able to extract different granularity and types of sentiment features in German tweets from multiple perspectives [20]. This approach incorporates a multilevel representation of German sentiment features, focusing on word-level features that contain local sentiment information and sentence-level features that express overall sentiment information.


### 3.1. Word-Level Emotional Features

#### 3.1.1. Lexical and Morphological Features

German social comments tend to use adjectives and verbs to express emotions [21]. In order to focus the model on the more emotionally informative real words, the lexical features of each word are automatically obtained with the help of lexical annotation tools to distinguish the weight of emotion information of different words. In this paper, for each word, we first use Google Translate, NLTK, and the German morphological analysis tool. In this paper, for each word, the lexical properties of “adjective, adverb, verb, noun, exclamation, Emoji, or other” are firstly labeled by Google Translate, NLTK, Py-Mystem1, and PyMorphy22 and then aggregated by the above four results and obtained by majority voting method [22].In order to investigate the influence of various complex morphological forms on the expression of emotions in German, the tools PyMystem and PyMorphy2 are used to label each word into 28 morphological forms belonging to 10 categories (e.g., morphological “tense” is divided into two categories: imperative and declarative), and some of the important German morphological forms are listed in Table1. Since PyMystem not only uses a lexical and rule-based algorithm but also takes into account contextual information, it is more reliable than the latter. Therefore, the results obtained by PyMystem are preferred as the baseline morphological features of words, while the results obtained by PyM or-phy2 are used as supplementary morphological features.Table 1
German morphology of PyMorphy2 and PyMystem markers.
FormTypePyMorphy 2PyMystemPersonFirst person1 per1-nSecond person2 per2-nThird person3 per3-nTypeImperativeimprIndicative moodindeBodyperfect aspectperfImperfective aspectimpfTimepastpastPresent tensepresFuturefutrStateActive voiceactvBe dynamicpssvTransitivityTransitivityintrInferior to physical propertytran


#### 3.1.2. Emotional Score Characteristics

Compared to English, fewer studies have been conducted on German sentiment dictionaries, and the existing work either focuses on topics related to fixed domains [9] or applies only to target-oriented sentiment classification [23], which has limitations when analyzing German social media texts. The dictionary [24] contains 16,057 sentiment entries in the general domain, but it is still difficult to cover the complex German language morphology and new words on the Internet and only coarsely classifies words into 4 levels based on sentiment intensity, without precisely distinguishing the detailed sentiment differences between entries. Compared with the existing German sentiment dictionaries, the widely used English sentiment dictionary Sentiwordnet [25] and multilingual sentiment dictionary Senticnet [17] both have large scale coverage and precise sentiment intensity. Therefore, in this paper, we use Sentiwordnet to obtain the sentiment score of each word based on its lexical nature and English interpretation and then use Senticnet to obtain the sentiment score of each original German word and its English interpretation, respectively. These three sentiment scores are continuous data from −1 to +1, which have the ability to describe the sentiment tendency and intensity of words more finely, so they are used as word-level sentiment score features to provide clearer and more accurate sentiment information for the model.


#### 3.1.3. Expletive Slang Features

Social media users use indecent words to express strong emotions, vent their frustrations, express derogatory attitudes, or curse the object of their dislike. In German tweets, there are also a variety of swear words and slang words, which, together with many nondirective expressions, increase the granularity of the sentiment factor affecting the sentence, and traditional sentiment dictionaries alone cannot meet the demand. In this paper, we refer to the literature [18, 19] and construct a dictionary of expletive slang containing three types of words or phrases, including words that compare each other to animals or filthy and useless objects (e.g., Deine Mutter ist tot), expletives related to sexuality or sexual organs (e.g., Fick dich!), and various words used for insults, curses, or blasphemy (e.g., Du bist ein Narr). In this paper, we use the presence or absence of a word in the dictionary as a criterion for judging each German word into two categories, dirty words and nondirty words, and use this result as a word-level characteristic of dirty slang.


#### 3.1.4. Alphabetic Characteristics

In order to express strong emotions, users on social networks often consciously violate the rules of the German language [26]. For example, the initial or final letter, vowel, or loud consonant of a word (Ä ä, Ö ö;, ü) is repeated several times; therefore, the number of capital letters and repeated letters in each word is used as an alphabetic emotional feature at the word level in this paper.


### 3.2. Sentence-Level Emotional Features

#### 3.2.1. English Translation Emotional Characteristics

Among all languages, English has the largest share of research in sentiment analysis, and a large number of professional and convenient analysis tools have been developed. Despite the loss of some emotional features and the introduction of some noise in the German English translation stage, the translation engine is able to obtain a relatively standardized and linguistically modeled English translation compared to the disordered and poorly standardized German original on social media. If the English sentiment analysis tool is chosen wisely, its results can provide a reliable reference for German sentiment analysis [5]. Among many mature English sentiment analysis tools, Vader [27] and TextBlob3 are not only applicable to a wide range of domains but are also particularly good at analyzing short social media texts and obtaining several floating-point values expressing sentiment polarity without training. Therefore, in this paper, we first use Google and Baidu translation engines to obtain English translations, then use Vader and TextBlob to obtain sentiment polarity values for English translations, and finally integrate them into the depth model as sentence-level sentiment features of English translations.


#### 3.2.2. Emoticon Characteristics

Similar to other languages, German social media users often use combinations of punctuation marks to simulate facial expressions or emotion-related things and thus express positive or negative emotions, for example, “ ^_^ ” for a smiley face and “3)” for heart and love. In this paper, we refer to the literature [22, 23], count the number of each type of emoticon with Table 2 as the polarity classification criterion, and use the number of emoticons of each type of polarity in a sentence as the emoticon characteristics of German texts to reflect the strength of positive and negative emotion polarity in German texts.Table 2
Classification of emoticons.
Emotional polarityEmoticonJust′3) ′, ′: ∗ ′, ′ > 3′, ′ С: ′, ′}: -> ′, ′∗ ^_^∗ ′, ′ ^_^ ′, ′ =D′, ′ 8 ) ′, ′ (: ′, ′ ^ _ _ _ ^ ′, ′ ^ w ^ ′, ′: D′, ′∗ -∗ ′, ′: -) ′, ′) ) ′, ′: ) ′, ′: 3′, ′ ^ ^ ′, ′ = ) ′, ′: ∗ ′, ′ ∗ _∗ ′, ′-. -′, ′ XD′, ′: -D′, ′; ) ′, ′ ∗ о ∗ ′, ′ = 3 = ′, ′ о _о′, ′∗ О∗ ′, ′: В ′, ′ < 3′, ′ > D′Negative′ < = ′, ′ > > ′, ′ > . < ′, ′ > < ′, ′: < ′, ′: с′, ′: \ ′ с′, ′:С′, ′: ( ( ′, ′-_-′, ′-_ _ _-′, ′ ( _! _ ) ′, ′-_ _ _ _-′, ′:\ \ ′, ′. _. ′, ′: ( ′, ′( ( ( ′, ′; ( ′In′O_o′, ′0_0′, ′: @ ′, ′ = #′


#### 3.2.3. Self-Attentive Depth Model for German Sentiment Analysis

In order to effectively combine the ability of CNN model to capture local features of multidimensional data, the advantage of RNN model to extract long-term dependencies in sequences, and the feature of self-attentive mechanism to focus on important information, and thus improve the German sentiment classification, this paper proposes a hybrid CNN-BiLSTM deep learning model ACBM based on self-attentive mechanism. As shown in Figure1, the model consists of six submodules [28]. The model consists of six submodules. First, the word-level feature encoding layer transforms each word and its corresponding sentiment features into a sentimental word vector containing semantic and sentiment information based on the word vector and various word-level sentiment features. Then, the local feature extraction layer is responsible for extracting the local contextual features of each word from the adjacent information. Then, the sequence feature extraction layer, which is responsible for extracting the sequence features of the whole text, and the attention layer, which is responsible for generating the sentiment weight of each element in the sequence, work in concert. Finally, the sentiment classification layer combines the previously generated attentional sequence features and the output of the sentence-level feature encoding layer to generate the determination results of the sentiment classification of the whole model.Figure 1
CNN-BiLSTM hybrid model in this paper.First, we have attention advantage: compared with CNN and RNN, the model has less complexity and fewer parameters. Therefore, the requirements for computational power are smaller.Then, we have fast speed: attention solves the problem that RNN cannot perform parallel computing. Each step of the attention mechanism does not depend on the calculation results of the previous step, so it can be processed in parallel with CNN.Next, we have good effect: before the introduction of the attention mechanism, there was a problem that everyone had been distressed: long-distance information would be weakened, just as people with weak memory could not remember the past.


#### 3.2.4. Word-Level Feature Encoding Layer

In order to convert textual information into digital vectors that can be processed by neural networks, this paper uses fastText [25] based on the pretrained word vectors obtained from Wikipedia and massive public website texts, and the dimension of word vector wi for each word is 300. Because of the large size of the vocabulary, which contains 1,888,423 German words, and the use of N-gram character features to generate word vectors, fastText is not only effective in reducing the probability of OOV (out of vocabulary), but also applicable to the morphologically rich German.Although fastText word vectors are semantically rich, they contain limited sentiment information, and some words with close contexts and opposite sentiment tend to have similar word vectors. To solve this problem, this paper makes full use of existing resources, such as word formation rules, sentiment dictionaries, slang dictionaries, and German morphological analysis tools to add sentiment information to the existing word vectors and then from sentimental word vectors. In the experiments, all the continuous features with similar sentiment score are first clustered byK-means and other methods, so that the number of categories of each word-level feature is limited. Then, the jth word-level feature (1≤j ≤ m) of the ith word is mapped into a q-dimensional sentiment vector that can be self-learnt in the deep model wifi. Finally, wifj containing sentiment information is merged with the original word vector xi=wi⊕wif1⊕…⊕wifi⊕…⊕wifm to obtain the sentiment word vector containing rich word-level sentiment features, which is calculated as xi, where the symbol represents the merging operation of the vector, and the dimension of the vector 555 d is equal to 300 + q × m.


#### 3.2.5. Local Feature Extraction Layer

The German vocabulary is not only morphologically rich, but also highly polysemous. А.Будагов’s study of large dictionaries shows that the proportion of polysemous words in German is as high as 80%, and many words not only have a wide range of meanings but also contain opposite emotional messages [26]. For example, one of the most basic and active verbs in German, “идти,” contains even more than 20 meanings, while the verb “следить” has the meanings “to watch,” “to care,” “to monitor,” and “to follow.” The verb “следить” has different emotional meanings such as “watch,” “care,” “watch,” and “follow,” and the semantic meaning and the emotional information it contains are not only determined by itself but also influenced by other words in the context [27]. For example, when the adjective “зелёная” is followed by “трава,” “молодёжь,” and “скука,” the meanings are “green grass” and “childish youth,” and the meanings of the words “green grass,” “childish youth,” and “embarrassing boredom” not only are different but also do not correspond to the polarity of the emotions expressed.In order to extract more objective and accurate local features of the words, this paper uses CNN to extract the local contextual features of each word for the sentiment vector matrix output from the word-level feature encoding layer, and its structure is shown in Figure2. Assuming that the text contains n words and the dimension of emotional word vector is D, the initial shape of emotional feature matrix X is n × d. In order to make the sequence length of CNN input and output consistent, this paper changes the shape of matrix X to (n + (2) by filling pad × d. The convolution layer contains T pieces with a size of 3 × D. When the J (1 ≤ J ≤ T) th convolution kernel Wj convolutes xi in matrix X, the local eigenvalue gij1≤i≤n will be obtained. The calculation process is as follows:(1)gij=fWjΘXi:i+2+b,vi=gi1,gi2,gi3,⋯,giT.Figure 2
Local feature extraction layer.In1, xi:i+2 is the sentiment eigenvector from row i to row i + 2 of matrix X, ⊙ represents the convolution product, b is the bias, and f is the nonlinear activation function (Re LU is chosen as the activation function in this paper to speed up the convergence). In 2, vi consists of the 3-gram local eigenvalues extracted around the ith word by the convolutional kernel W in the convolutional layer T respectively. Compared with the sentiment word vector xi, the local sentiment feature vector vi contains not only the features of the i-word itself, but also the contextual features of the adjacent regions of the word, which contains more comprehensive and objective semantic and sentiment information.


#### 3.2.6. Sequence Feature Extraction Layer

CNNs are limited by the fixed size of the convolutional kernel window, which makes it difficult to model long-distance sequence information. In order to extract longer distance and deeper hidden sentiment information, this paper feeds the local feature vectorv1,v2,…vn into the sequence feature extraction layer sequentially. Although the standard RNN is good at processing sequential data, it has two drawbacks: (1) the gradient disappearance or explosion problem in long-sequence training reduces its ability to perceive important node information at longer distances; (2) the unidirectional state information transmission prevents it from capturing the influence of the later text on the target word. Therefore, this paper adopts a bidirectional LSTM [13] to extract sequence features, on the one hand, by controlling the transmission state with the gate structure in the LSTM, thus limiting the filtering of invalid information and memory retention of long-distance sentiment features, and on the other hand, by capturing the contextual sequence features at the current position simultaneously through two independent and opposite direction LSTMs. On the other hand, two independent LSTMs with opposite directions capture the contextual sequence of features at the current location simultaneously and then consider the sentiment and semantic information of past and future directions of each location comprehensively:(2)h1F,c1F=LSTMFvn,h0F,c0F;⋯;hnF,cnF=LSTMFv1,hn−1F,cn−1F,h1B,c1B=LSTMBv1,h0B,c0B;⋯;hnB,cnB=LSTMBvn,hn−1B,cn−1Bhi=hn−i+1F⊕hiB1≤i≤n.In (3), LSTMF and LSTMB represent the forward and backward LSTM models, ciF and ciB correspond to the cell states of the two models, h1F and hiB correspond to the implied layer outputs of the two models, and the initial states h0F,c0F and h0B,c0B of the two directional LSTMs are zero. Equation (4) splices the output of LSTMF and LSTMB, which is the final output of the sequence feature extraction layer.


#### 3.2.7. Attention Layer

The brain always allocates more attention to the relatively important elements when reading, thus improving the efficiency of acquiring key information. The attention layer in this section adopts a similar attention mechanism, and before fusing the information and sending it to the emotion classification layer, the attention sequence features that accurately reflect the important emotion information in the German text are obtained by calculating the emotion weight of each word and highlighting the elements that contain key features and weakening the non-emotion information or unimportant elements, thus improving the effectiveness of the model. Deep learning models based on the self-attention mechanism in many studies [28] have directly used the implicit layer hi of the LSTM to generate the attention weight values of different elements ai, which is calculated as shown in the following:(3)si=tanhWThi+b;ai=softmaxsiA,where siA is automatically learned by the model from the corpus as the scoring system, A and W are both weight matrices, and b is the bias. However, the disadvantage of this algorithm is that the hidden vector hi generated by Bi-LSTM needs to represent both the emotional and semantic information of each word and also needs to contain the weight of the word in the emotional expression. As shown in Figure 3, in this paper, the attention layer is supplemented by BiLSTMattention, which is dedicated to generating weights based on the implicit layer hi′ of the local feature vector V output, instead of hi, and generates the weight ai corresponding to the ith word:(4)si=tanhWThi′+b;ai=softmaxsiA,∑i=1nai=1;ASF=∑i=1nai∗hi.Figure 3
Structure of the attention layer.


#### 3.2.8. Sentence-Level Feature Encoding Layer and Sentiment Classification Layer

Similar to the function and principle of the word-level feature coding layer, the sentence-level feature coding layer is responsible for extracting the sentence-level emotional feature vector SF. The module first selectsl reserved sentence-level emotional features and then transforms its jth sentence-level feature (1 ≤ J ≤ L) into a p-dimensional emotional feature vector sfj that can self-learn in the depth model through polynomial expansion. Finally, the sentence-level feature vector sfi containing rich emotional information is obtained by merging. The calculation formula is SF=sf1⊕⋯⊕sfi⊕⋯⊕s/l, and the dimension of vector SF is equal to p∗l.Sentiment classification layer is responsible for the final classification results of the whole model. As shown in Figure4, firstly, in order to prevent the model from overfitting, the sentiment classification layer applies dropout and L2 regularization strategies to the attention sequence feature ASF, which reduces the interaction between the nodes in the hidden layer by randomly discarding some parameters of the model and controlling the complexity of the model, so as to reduce the generalization error of the whole deep neural network. Then, results of the processed ASF are merged with the sentence-level sentiment feature SF and sent to the sentiment classification layer together. In order to make the model more stable and speed up the convergence, we perform the dimensionality reduction operation step by step through two fully connected layers and add the normalization operation between the two layers to avoid ignoring the features with small values in some dimensions. Finally, the surtax regression is used to obtain the triple classification results with the sentiment polarity of “positive, negative, and medium.”Figure 4
Emotion classification layer.


### 3.3. Experiments and Results Analysis

#### 3.3.1. Experimental Data and Evaluation Index

The data set used in this paper is provided by [5], which contains 3968 German tweets with classification tags, including 1145 positive sentiments and 1188 negative sentiments, and the rest are marked as neutral. In order to improve the classification accuracy, the corpus was preprocessed and words with the same root were mapped into a uniform form by stemming (e.g., removing interference from singular and plural, person, feminine and masculine, nominative case, verb with multiple tenses, forms, etc.). After preprocessing, there are 13,943 words or symbols left in the corpus, of which 12,485 can be mapped to the pretrained word vector provided by fastText, and the OOV ratio decreases from 14.78% to 10.46%. To enable the model to find the global optimal solution quickly, the Mini-Batch gradient descent method is used to train the model, and the performance of the final model is checked using the 5-fold cross-validation method, while F1_macro is used as the main evaluation criterion and accuracy is used as the secondary evaluation criterion to balance the relationship between accuracy and recall, both of which are abbreviated as F1 and Acc in the later paper.


### 3.4. Comparative Experiments and Analysis of Results

#### 3.4.1. Comparison of Multiple Classification Schemes Based on English Translations

Because of the small amount of German corpus and the limited capability of German sentiment analysis tools, the literature [5] combined a translation engine with an English sentiment analysis tool to obtain the classification results. sentiment140.com) obtained the highest F1 value of 61%. The results of the combination of two translation engines and two analysis tools were designed in this paper, based on the premise that the Cov reaches 100% and the performance of the four combinations ranges from 47.85% to 53.64%, among which the combination of Baidu Translate and Vader [20] has the best result, as shown in Figure 5. It is found that for the German corpus [5], Baidu Translate is slightly better than Google Translate in the case of using the same English analysis tool, which also proves that the translation quality will have some influence on the analysis results.Figure 5
Comparing the effect of various English translation emotional features.In this paper, the feature vectors extracted by the Bert pretraining model are directly fed into the fully connected layer for sentiment classification, and it is found that theF1 of the Bert English pretraining model is 7.25% higher than that of the multilingual pretraining model. Through comparison experiments, it is found that the results of the ACBM model are better than all the above schemes, which indicates that the sentiment classification based on the English translation is less effective than that based on the direct analysis of the German original due to the information loss of semantic, emotional, and linguistic features caused by translation. This indicates that the effect of sentiment classification based on English translation is not as good as the analysis of the original German text directly, and it is recommended to be used as an interim solution or an auxiliary solution in migration learning until further breakthroughs in machine translation technology are achieved.


#### 3.4.2. Comparison of Various Sentence-Level Features

In order to deeply explore the sentiment information in German tweets and make full use of relevant knowledge and linguistic features, this paper adds various sentence-level sentiment features to the LSTM and ACBM models, respectively, and compares three correlation indices between these features and sentiment classification labels, Kendall, Pearson, and Spearman, and finds that the absolute value of the indices correlates with the absolute value of the corresponding features after adding them. The absolute values of the indices were found to be positively correlated with the experimental results after adding the corresponding features, as shown in Table3.Table 3
Comparison of results for various sentence-level features.
FeaturesKendallPearsonSpearmanF1LSTMF1ACBMNothing———62.1163.28Bert vector———63.8565.18English translation Vader affective value0.38360.47270.468363.1664.77Number of forward emoticons0.34930.34720.372962.9864.55End bracket direction0.32070.34100.341162.9064.53Lentil 40 emotional value0.26280.29740.293162.5864.16Number of negative emoticons−0.0651−0.1739−0.174962.3563.94Total exclamation marks0.0523−0.0260−0.026062.2463.78Total number of question marks−0.0246——62.2463.51Among the selected sentence-level features, the English translation Bert vector, the English translation Vader sentimental value, the number of positive expressions, and the direction of closing brackets have the best effect. In contrast, the sentence-level features improve the LSTM more significantly, which indicates that ACBM is more capable of extracting sentimental features for the original text, so the effect of sentence-level features is limited to assist and complement it. The best results for the two English-translated emotional features indicate that although the effect of relying on the English translation alone is not ideal. It can be used as an effective aid in German emotional analysis. Emoticons also work relatively well (the parentheses at the end are also similar to emoticons), suggesting that social media language prefers to use distinctive emoticons to express one’s emotional tendencies. Exclamation marks and question marks are less effective because they mainly express the presence or absence of emotions but do not contain positive or negative information about emotions.


#### 3.4.3. Comparison of Various Word-Level Features

In order to investigate the effect of various word-level features on the sentiment analysis of German, we also added various word-level sentiment features to the LSTM and ACBM models, respectively, as shown in Figure6. Among these features, sentimental score, expletive slang, and sentiment score + lexically is the most effective, with the F1 of LSTM increasing by 0.83%, 1.31%, and 0.77%, respectively, and the F1 of ACBM increasing by 0.97%, 1.56%, and 1.57%, respectively, before and after adding the features. In contrast to the sentence-level features, the word-level features obviously improve the ACBM more significantly, which indicates that the ACBM is more sensitive to word contextual sentimental features and local information after introducing the CNN module and the self-attentive mechanism. In addition, F1 value of ACBM is 1.46–2.51 higher than that of LSTM with or without features, and with or without features. It is worth noting that the effect of adding word-level features alone is relatively poor, but when both sentimental score and word-level features are added, the F1 is 0.6% higher than that of sentiment score features alone. This is due to the fact that the self-attentive mechanism of ACBM can effectively extract the weight of each element of the lexical features, and thus the model can focus more on the sentimental score features of important elements.Figure 6
Comparison of results for various word-level features.In order to verify the role of German morphological information in sentiment analysis, various German morphological forms were added to the two models in turn, as shown in Tables3 and 4. The experimental results show that six morphological forms have an enhancing effect on the original model, among which the morphological forms “tense” and “person” have a relatively significant enhancing effect. This may be due to the fact that in German expressions, imperatives tend to express strong subjective emotions more than declarative forms and first person than other forms, while the rest of the morphological forms are less effective in expressing emotions in German.Table 4
Comparison of classification results of different methods.
ModelF1w/ofAccw/ofF1w−fAccw−fF1↑Acc↑Dostoevsky53.4055.45————SVM54.2354.8058.4558.624.224.01CNN62.5162.6466.5466.654.034.01LSTM62.1162.1965.9566.033.853.84Bi-LSTM62.4762.4766.4866.504.014.03BiLSTM-2layers62.8563.0266.3967.014.083.99BiLSTM-ATT62.5962.5766.5666.633.974.06BiLSTM-ATT263.463.3667.8567.964.454.6BiLSTM-CNN63.3563.2867.5167.694.164.41CNN-Bi-LSTM63.4763.5167.8367.984.364.47ACBM63.8263.9068.7568.875.035.07


#### 3.4.4. Comparison of Results of Multiple Models

In order to verify the sentiment analysis ability of this model ACBM on German social media texts, Table4 compares it with the German sentiment analysis tool Dostoevsky4, traditional machine learning methods (SVM), common deep learning models (CNN, LSTM, and Bi-LSTM), and various deep learning combination models. The first group analyzes the original text directly without introducing any features, and the corresponding experimental results are F1w/of and Accw/of. In group 2, several word-level features (emotion score + part of speech + dirty slang) and sentence-level features (emoticon + English translation emotion) are added at the same time. The corresponding experimental results are F1w−f and accw-f. F1 ↑ and ACC ↑ represent the corresponding improvement of F1 and ACC in group 2 experimental results of each model compared with group 1 experimental results except Dostoevsky. The calculation formulas are as follows: F1 ↑ = F1w−f − F1w/of and ACC ↑ = Accw−f − Accw/of. Obviously, the higher F1 ↑ and ACC ↑ means that the effect of emotion classification is more obvious after adding emotion features at all levels to the corresponding model. The description for each model is as follows: Dostoevsky is a German emotion analysis depth model trained based on Ru sentiment [29], and the F1 value on its test set is 0.71; BiLSTM-2layers reproduce the two-layer stacked bidirectional LSTM proposed in document [13]; Bilstm-att and bilstm-att2 add self-attention mechanism based on formulas (5) and (6), respectively, on the basis of BiLSTM; BiLSTM-CNN is a deep learning combination model of BiLSTM before CNN; CNN-BiLSTM is a deep learning combination model of CNN before BiLSTM.The results of the comparison experiments illustrate that the performance of all models improves significantly after introducing all levels of sentiment features, among which ACBM improves the most, withF1 and Acc improving by 5.03 and 5.07, respectively. Due to not retraining on the data [5], Dostoevsky performs poorly and is close to the performance of SVM without adding features, while all depth models outperform SVM with or without adding features. With the addition of features at all levels, the difference between CNN and BiLSTM results is not significant, but both results are significantly better than LSTM, which demonstrates the ability of CNN to efficiently extract local features of text and the sensitivity of BiLSTM to capture features before and after sequence history. If the number of model layers F1 added to BiLSTM will improve by 0.51, 0.13, and 1.46 [30], respectively, this proves that increasing the number of network layers or the self-attention module can effectively improve the performance of BiLSTM, and the improved self-attention mechanism is more effective. The results of CNN-BiLSTM are slightly stronger than those of BiLSTM-CNN, which indicates that it is more reasonable to use CNN to extract local features and then BiLSTM to extract global sequence features for German tweets. This indicates that by optimizing the combination of CNN and BiLSTM with a clear self-attentive mechanism, we can capture local features, summarize global information, and improve sentiment analysis in a more detailed way.


#### 3.4.5. Attention Analysis

The ACBM model is able to assign higher sentiment weight to important elements based on the self-attentive mechanism and various multilevel sentimental features of the text, thus enhancing the extraction and analysis of sentiment information, the heat map of token weights generated by ACBM self-attentive layer [31] as shown in Figure 7, for example, whether they are positive or negative emoticons like “: D” and “: (,” or real words with obvious sentiment tendency, such as “glücklich” (pleasant), “wie” (like), “gute Arbeit” (good), “Grob” (rough), “Böse” (evil), “Abfälle” (wasted), and “Mist. The real words with obvious emotional tendencies, such as “Böse,” “Abfälle,” and “Mist,” are given high emotional weight. In sentences 1–5, the highest weight is 3.1–5.7 times the average value of the remaining weight. In sentences 6 and 7, the two highest weights are 10.9 and 15.3 times the average of the remaining weight. Analyzing example 8, we can also see that when there are multiple expressions of opposite polarity in the sentence, ACBM assigns a higher weight to the relatively important expression “: (” based on the meaning of the text and the position of each token.Figure 7
Heat map of Token weights generated by ACBM self-attentive layer.


## 3.1. Word-Level Emotional Features

### 3.1.1. Lexical and Morphological Features

German social comments tend to use adjectives and verbs to express emotions [21]. In order to focus the model on the more emotionally informative real words, the lexical features of each word are automatically obtained with the help of lexical annotation tools to distinguish the weight of emotion information of different words. In this paper, for each word, we first use Google Translate, NLTK, and the German morphological analysis tool. In this paper, for each word, the lexical properties of “adjective, adverb, verb, noun, exclamation, Emoji, or other” are firstly labeled by Google Translate, NLTK, Py-Mystem1, and PyMorphy22 and then aggregated by the above four results and obtained by majority voting method [22].In order to investigate the influence of various complex morphological forms on the expression of emotions in German, the tools PyMystem and PyMorphy2 are used to label each word into 28 morphological forms belonging to 10 categories (e.g., morphological “tense” is divided into two categories: imperative and declarative), and some of the important German morphological forms are listed in Table1. Since PyMystem not only uses a lexical and rule-based algorithm but also takes into account contextual information, it is more reliable than the latter. Therefore, the results obtained by PyMystem are preferred as the baseline morphological features of words, while the results obtained by PyM or-phy2 are used as supplementary morphological features.Table 1
German morphology of PyMorphy2 and PyMystem markers.
FormTypePyMorphy 2PyMystemPersonFirst person1 per1-nSecond person2 per2-nThird person3 per3-nTypeImperativeimprIndicative moodindeBodyperfect aspectperfImperfective aspectimpfTimepastpastPresent tensepresFuturefutrStateActive voiceactvBe dynamicpssvTransitivityTransitivityintrInferior to physical propertytran


### 3.1.2. Emotional Score Characteristics

Compared to English, fewer studies have been conducted on German sentiment dictionaries, and the existing work either focuses on topics related to fixed domains [9] or applies only to target-oriented sentiment classification [23], which has limitations when analyzing German social media texts. The dictionary [24] contains 16,057 sentiment entries in the general domain, but it is still difficult to cover the complex German language morphology and new words on the Internet and only coarsely classifies words into 4 levels based on sentiment intensity, without precisely distinguishing the detailed sentiment differences between entries. Compared with the existing German sentiment dictionaries, the widely used English sentiment dictionary Sentiwordnet [25] and multilingual sentiment dictionary Senticnet [17] both have large scale coverage and precise sentiment intensity. Therefore, in this paper, we use Sentiwordnet to obtain the sentiment score of each word based on its lexical nature and English interpretation and then use Senticnet to obtain the sentiment score of each original German word and its English interpretation, respectively. These three sentiment scores are continuous data from −1 to +1, which have the ability to describe the sentiment tendency and intensity of words more finely, so they are used as word-level sentiment score features to provide clearer and more accurate sentiment information for the model.


### 3.1.3. Expletive Slang Features

Social media users use indecent words to express strong emotions, vent their frustrations, express derogatory attitudes, or curse the object of their dislike. In German tweets, there are also a variety of swear words and slang words, which, together with many nondirective expressions, increase the granularity of the sentiment factor affecting the sentence, and traditional sentiment dictionaries alone cannot meet the demand. In this paper, we refer to the literature [18, 19] and construct a dictionary of expletive slang containing three types of words or phrases, including words that compare each other to animals or filthy and useless objects (e.g., Deine Mutter ist tot), expletives related to sexuality or sexual organs (e.g., Fick dich!), and various words used for insults, curses, or blasphemy (e.g., Du bist ein Narr). In this paper, we use the presence or absence of a word in the dictionary as a criterion for judging each German word into two categories, dirty words and nondirty words, and use this result as a word-level characteristic of dirty slang.


### 3.1.4. Alphabetic Characteristics

In order to express strong emotions, users on social networks often consciously violate the rules of the German language [26]. For example, the initial or final letter, vowel, or loud consonant of a word (Ä ä, Ö ö;, ü) is repeated several times; therefore, the number of capital letters and repeated letters in each word is used as an alphabetic emotional feature at the word level in this paper.


## 3.1.1. Lexical and Morphological Features

German social comments tend to use adjectives and verbs to express emotions [21]. In order to focus the model on the more emotionally informative real words, the lexical features of each word are automatically obtained with the help of lexical annotation tools to distinguish the weight of emotion information of different words. In this paper, for each word, we first use Google Translate, NLTK, and the German morphological analysis tool. In this paper, for each word, the lexical properties of “adjective, adverb, verb, noun, exclamation, Emoji, or other” are firstly labeled by Google Translate, NLTK, Py-Mystem1, and PyMorphy22 and then aggregated by the above four results and obtained by majority voting method [22].In order to investigate the influence of various complex morphological forms on the expression of emotions in German, the tools PyMystem and PyMorphy2 are used to label each word into 28 morphological forms belonging to 10 categories (e.g., morphological “tense” is divided into two categories: imperative and declarative), and some of the important German morphological forms are listed in Table1. Since PyMystem not only uses a lexical and rule-based algorithm but also takes into account contextual information, it is more reliable than the latter. Therefore, the results obtained by PyMystem are preferred as the baseline morphological features of words, while the results obtained by PyM or-phy2 are used as supplementary morphological features.Table 1
German morphology of PyMorphy2 and PyMystem markers.
FormTypePyMorphy 2PyMystemPersonFirst person1 per1-nSecond person2 per2-nThird person3 per3-nTypeImperativeimprIndicative moodindeBodyperfect aspectperfImperfective aspectimpfTimepastpastPresent tensepresFuturefutrStateActive voiceactvBe dynamicpssvTransitivityTransitivityintrInferior to physical propertytran


## 3.1.2. Emotional Score Characteristics

Compared to English, fewer studies have been conducted on German sentiment dictionaries, and the existing work either focuses on topics related to fixed domains [9] or applies only to target-oriented sentiment classification [23], which has limitations when analyzing German social media texts. The dictionary [24] contains 16,057 sentiment entries in the general domain, but it is still difficult to cover the complex German language morphology and new words on the Internet and only coarsely classifies words into 4 levels based on sentiment intensity, without precisely distinguishing the detailed sentiment differences between entries. Compared with the existing German sentiment dictionaries, the widely used English sentiment dictionary Sentiwordnet [25] and multilingual sentiment dictionary Senticnet [17] both have large scale coverage and precise sentiment intensity. Therefore, in this paper, we use Sentiwordnet to obtain the sentiment score of each word based on its lexical nature and English interpretation and then use Senticnet to obtain the sentiment score of each original German word and its English interpretation, respectively. These three sentiment scores are continuous data from −1 to +1, which have the ability to describe the sentiment tendency and intensity of words more finely, so they are used as word-level sentiment score features to provide clearer and more accurate sentiment information for the model.


## 3.1.3. Expletive Slang Features

Social media users use indecent words to express strong emotions, vent their frustrations, express derogatory attitudes, or curse the object of their dislike. In German tweets, there are also a variety of swear words and slang words, which, together with many nondirective expressions, increase the granularity of the sentiment factor affecting the sentence, and traditional sentiment dictionaries alone cannot meet the demand. In this paper, we refer to the literature [18, 19] and construct a dictionary of expletive slang containing three types of words or phrases, including words that compare each other to animals or filthy and useless objects (e.g., Deine Mutter ist tot), expletives related to sexuality or sexual organs (e.g., Fick dich!), and various words used for insults, curses, or blasphemy (e.g., Du bist ein Narr). In this paper, we use the presence or absence of a word in the dictionary as a criterion for judging each German word into two categories, dirty words and nondirty words, and use this result as a word-level characteristic of dirty slang.


## 3.1.4. Alphabetic Characteristics

In order to express strong emotions, users on social networks often consciously violate the rules of the German language [26]. For example, the initial or final letter, vowel, or loud consonant of a word (Ä ä, Ö ö;, ü) is repeated several times; therefore, the number of capital letters and repeated letters in each word is used as an alphabetic emotional feature at the word level in this paper.


## 3.2. Sentence-Level Emotional Features

### 3.2.1. English Translation Emotional Characteristics

Among all languages, English has the largest share of research in sentiment analysis, and a large number of professional and convenient analysis tools have been developed. Despite the loss of some emotional features and the introduction of some noise in the German English translation stage, the translation engine is able to obtain a relatively standardized and linguistically modeled English translation compared to the disordered and poorly standardized German original on social media. If the English sentiment analysis tool is chosen wisely, its results can provide a reliable reference for German sentiment analysis [5]. Among many mature English sentiment analysis tools, Vader [27] and TextBlob3 are not only applicable to a wide range of domains but are also particularly good at analyzing short social media texts and obtaining several floating-point values expressing sentiment polarity without training. Therefore, in this paper, we first use Google and Baidu translation engines to obtain English translations, then use Vader and TextBlob to obtain sentiment polarity values for English translations, and finally integrate them into the depth model as sentence-level sentiment features of English translations.


### 3.2.2. Emoticon Characteristics

Similar to other languages, German social media users often use combinations of punctuation marks to simulate facial expressions or emotion-related things and thus express positive or negative emotions, for example, “ ^_^ ” for a smiley face and “3)” for heart and love. In this paper, we refer to the literature [22, 23], count the number of each type of emoticon with Table 2 as the polarity classification criterion, and use the number of emoticons of each type of polarity in a sentence as the emoticon characteristics of German texts to reflect the strength of positive and negative emotion polarity in German texts.Table 2
Classification of emoticons.
Emotional polarityEmoticonJust′3) ′, ′: ∗ ′, ′ > 3′, ′ С: ′, ′}: -> ′, ′∗ ^_^∗ ′, ′ ^_^ ′, ′ =D′, ′ 8 ) ′, ′ (: ′, ′ ^ _ _ _ ^ ′, ′ ^ w ^ ′, ′: D′, ′∗ -∗ ′, ′: -) ′, ′) ) ′, ′: ) ′, ′: 3′, ′ ^ ^ ′, ′ = ) ′, ′: ∗ ′, ′ ∗ _∗ ′, ′-. -′, ′ XD′, ′: -D′, ′; ) ′, ′ ∗ о ∗ ′, ′ = 3 = ′, ′ о _о′, ′∗ О∗ ′, ′: В ′, ′ < 3′, ′ > D′Negative′ < = ′, ′ > > ′, ′ > . < ′, ′ > < ′, ′: < ′, ′: с′, ′: \ ′ с′, ′:С′, ′: ( ( ′, ′-_-′, ′-_ _ _-′, ′ ( _! _ ) ′, ′-_ _ _ _-′, ′:\ \ ′, ′. _. ′, ′: ( ′, ′( ( ( ′, ′; ( ′In′O_o′, ′0_0′, ′: @ ′, ′ = #′


### 3.2.3. Self-Attentive Depth Model for German Sentiment Analysis

In order to effectively combine the ability of CNN model to capture local features of multidimensional data, the advantage of RNN model to extract long-term dependencies in sequences, and the feature of self-attentive mechanism to focus on important information, and thus improve the German sentiment classification, this paper proposes a hybrid CNN-BiLSTM deep learning model ACBM based on self-attentive mechanism. As shown in Figure1, the model consists of six submodules [28]. The model consists of six submodules. First, the word-level feature encoding layer transforms each word and its corresponding sentiment features into a sentimental word vector containing semantic and sentiment information based on the word vector and various word-level sentiment features. Then, the local feature extraction layer is responsible for extracting the local contextual features of each word from the adjacent information. Then, the sequence feature extraction layer, which is responsible for extracting the sequence features of the whole text, and the attention layer, which is responsible for generating the sentiment weight of each element in the sequence, work in concert. Finally, the sentiment classification layer combines the previously generated attentional sequence features and the output of the sentence-level feature encoding layer to generate the determination results of the sentiment classification of the whole model.Figure 1
CNN-BiLSTM hybrid model in this paper.First, we have attention advantage: compared with CNN and RNN, the model has less complexity and fewer parameters. Therefore, the requirements for computational power are smaller.Then, we have fast speed: attention solves the problem that RNN cannot perform parallel computing. Each step of the attention mechanism does not depend on the calculation results of the previous step, so it can be processed in parallel with CNN.Next, we have good effect: before the introduction of the attention mechanism, there was a problem that everyone had been distressed: long-distance information would be weakened, just as people with weak memory could not remember the past.


### 3.2.4. Word-Level Feature Encoding Layer

In order to convert textual information into digital vectors that can be processed by neural networks, this paper uses fastText [25] based on the pretrained word vectors obtained from Wikipedia and massive public website texts, and the dimension of word vector wi for each word is 300. Because of the large size of the vocabulary, which contains 1,888,423 German words, and the use of N-gram character features to generate word vectors, fastText is not only effective in reducing the probability of OOV (out of vocabulary), but also applicable to the morphologically rich German.Although fastText word vectors are semantically rich, they contain limited sentiment information, and some words with close contexts and opposite sentiment tend to have similar word vectors. To solve this problem, this paper makes full use of existing resources, such as word formation rules, sentiment dictionaries, slang dictionaries, and German morphological analysis tools to add sentiment information to the existing word vectors and then from sentimental word vectors. In the experiments, all the continuous features with similar sentiment score are first clustered byK-means and other methods, so that the number of categories of each word-level feature is limited. Then, the jth word-level feature (1≤j ≤ m) of the ith word is mapped into a q-dimensional sentiment vector that can be self-learnt in the deep model wifi. Finally, wifj containing sentiment information is merged with the original word vector xi=wi⊕wif1⊕…⊕wifi⊕…⊕wifm to obtain the sentiment word vector containing rich word-level sentiment features, which is calculated as xi, where the symbol represents the merging operation of the vector, and the dimension of the vector 555 d is equal to 300 + q × m.


### 3.2.5. Local Feature Extraction Layer

The German vocabulary is not only morphologically rich, but also highly polysemous. А.Будагов’s study of large dictionaries shows that the proportion of polysemous words in German is as high as 80%, and many words not only have a wide range of meanings but also contain opposite emotional messages [26]. For example, one of the most basic and active verbs in German, “идти,” contains even more than 20 meanings, while the verb “следить” has the meanings “to watch,” “to care,” “to monitor,” and “to follow.” The verb “следить” has different emotional meanings such as “watch,” “care,” “watch,” and “follow,” and the semantic meaning and the emotional information it contains are not only determined by itself but also influenced by other words in the context [27]. For example, when the adjective “зелёная” is followed by “трава,” “молодёжь,” and “скука,” the meanings are “green grass” and “childish youth,” and the meanings of the words “green grass,” “childish youth,” and “embarrassing boredom” not only are different but also do not correspond to the polarity of the emotions expressed.In order to extract more objective and accurate local features of the words, this paper uses CNN to extract the local contextual features of each word for the sentiment vector matrix output from the word-level feature encoding layer, and its structure is shown in Figure2. Assuming that the text contains n words and the dimension of emotional word vector is D, the initial shape of emotional feature matrix X is n × d. In order to make the sequence length of CNN input and output consistent, this paper changes the shape of matrix X to (n + (2) by filling pad × d. The convolution layer contains T pieces with a size of 3 × D. When the J (1 ≤ J ≤ T) th convolution kernel Wj convolutes xi in matrix X, the local eigenvalue gij1≤i≤n will be obtained. The calculation process is as follows:(1)gij=fWjΘXi:i+2+b,vi=gi1,gi2,gi3,⋯,giT.Figure 2
Local feature extraction layer.In1, xi:i+2 is the sentiment eigenvector from row i to row i + 2 of matrix X, ⊙ represents the convolution product, b is the bias, and f is the nonlinear activation function (Re LU is chosen as the activation function in this paper to speed up the convergence). In 2, vi consists of the 3-gram local eigenvalues extracted around the ith word by the convolutional kernel W in the convolutional layer T respectively. Compared with the sentiment word vector xi, the local sentiment feature vector vi contains not only the features of the i-word itself, but also the contextual features of the adjacent regions of the word, which contains more comprehensive and objective semantic and sentiment information.


### 3.2.6. Sequence Feature Extraction Layer

CNNs are limited by the fixed size of the convolutional kernel window, which makes it difficult to model long-distance sequence information. In order to extract longer distance and deeper hidden sentiment information, this paper feeds the local feature vectorv1,v2,…vn into the sequence feature extraction layer sequentially. Although the standard RNN is good at processing sequential data, it has two drawbacks: (1) the gradient disappearance or explosion problem in long-sequence training reduces its ability to perceive important node information at longer distances; (2) the unidirectional state information transmission prevents it from capturing the influence of the later text on the target word. Therefore, this paper adopts a bidirectional LSTM [13] to extract sequence features, on the one hand, by controlling the transmission state with the gate structure in the LSTM, thus limiting the filtering of invalid information and memory retention of long-distance sentiment features, and on the other hand, by capturing the contextual sequence features at the current position simultaneously through two independent and opposite direction LSTMs. On the other hand, two independent LSTMs with opposite directions capture the contextual sequence of features at the current location simultaneously and then consider the sentiment and semantic information of past and future directions of each location comprehensively:(2)h1F,c1F=LSTMFvn,h0F,c0F;⋯;hnF,cnF=LSTMFv1,hn−1F,cn−1F,h1B,c1B=LSTMBv1,h0B,c0B;⋯;hnB,cnB=LSTMBvn,hn−1B,cn−1Bhi=hn−i+1F⊕hiB1≤i≤n.In (3), LSTMF and LSTMB represent the forward and backward LSTM models, ciF and ciB correspond to the cell states of the two models, h1F and hiB correspond to the implied layer outputs of the two models, and the initial states h0F,c0F and h0B,c0B of the two directional LSTMs are zero. Equation (4) splices the output of LSTMF and LSTMB, which is the final output of the sequence feature extraction layer.


### 3.2.7. Attention Layer

The brain always allocates more attention to the relatively important elements when reading, thus improving the efficiency of acquiring key information. The attention layer in this section adopts a similar attention mechanism, and before fusing the information and sending it to the emotion classification layer, the attention sequence features that accurately reflect the important emotion information in the German text are obtained by calculating the emotion weight of each word and highlighting the elements that contain key features and weakening the non-emotion information or unimportant elements, thus improving the effectiveness of the model. Deep learning models based on the self-attention mechanism in many studies [28] have directly used the implicit layer hi of the LSTM to generate the attention weight values of different elements ai, which is calculated as shown in the following:(3)si=tanhWThi+b;ai=softmaxsiA,where siA is automatically learned by the model from the corpus as the scoring system, A and W are both weight matrices, and b is the bias. However, the disadvantage of this algorithm is that the hidden vector hi generated by Bi-LSTM needs to represent both the emotional and semantic information of each word and also needs to contain the weight of the word in the emotional expression. As shown in Figure 3, in this paper, the attention layer is supplemented by BiLSTMattention, which is dedicated to generating weights based on the implicit layer hi′ of the local feature vector V output, instead of hi, and generates the weight ai corresponding to the ith word:(4)si=tanhWThi′+b;ai=softmaxsiA,∑i=1nai=1;ASF=∑i=1nai∗hi.Figure 3
Structure of the attention layer.


### 3.2.8. Sentence-Level Feature Encoding Layer and Sentiment Classification Layer

Similar to the function and principle of the word-level feature coding layer, the sentence-level feature coding layer is responsible for extracting the sentence-level emotional feature vector SF. The module first selectsl reserved sentence-level emotional features and then transforms its jth sentence-level feature (1 ≤ J ≤ L) into a p-dimensional emotional feature vector sfj that can self-learn in the depth model through polynomial expansion. Finally, the sentence-level feature vector sfi containing rich emotional information is obtained by merging. The calculation formula is SF=sf1⊕⋯⊕sfi⊕⋯⊕s/l, and the dimension of vector SF is equal to p∗l.Sentiment classification layer is responsible for the final classification results of the whole model. As shown in Figure4, firstly, in order to prevent the model from overfitting, the sentiment classification layer applies dropout and L2 regularization strategies to the attention sequence feature ASF, which reduces the interaction between the nodes in the hidden layer by randomly discarding some parameters of the model and controlling the complexity of the model, so as to reduce the generalization error of the whole deep neural network. Then, results of the processed ASF are merged with the sentence-level sentiment feature SF and sent to the sentiment classification layer together. In order to make the model more stable and speed up the convergence, we perform the dimensionality reduction operation step by step through two fully connected layers and add the normalization operation between the two layers to avoid ignoring the features with small values in some dimensions. Finally, the surtax regression is used to obtain the triple classification results with the sentiment polarity of “positive, negative, and medium.”Figure 4
Emotion classification layer.


## 3.2.1. English Translation Emotional Characteristics

Among all languages, English has the largest share of research in sentiment analysis, and a large number of professional and convenient analysis tools have been developed. Despite the loss of some emotional features and the introduction of some noise in the German English translation stage, the translation engine is able to obtain a relatively standardized and linguistically modeled English translation compared to the disordered and poorly standardized German original on social media. If the English sentiment analysis tool is chosen wisely, its results can provide a reliable reference for German sentiment analysis [5]. Among many mature English sentiment analysis tools, Vader [27] and TextBlob3 are not only applicable to a wide range of domains but are also particularly good at analyzing short social media texts and obtaining several floating-point values expressing sentiment polarity without training. Therefore, in this paper, we first use Google and Baidu translation engines to obtain English translations, then use Vader and TextBlob to obtain sentiment polarity values for English translations, and finally integrate them into the depth model as sentence-level sentiment features of English translations.


## 3.2.2. Emoticon Characteristics

Similar to other languages, German social media users often use combinations of punctuation marks to simulate facial expressions or emotion-related things and thus express positive or negative emotions, for example, “ ^_^ ” for a smiley face and “3)” for heart and love. In this paper, we refer to the literature [22, 23], count the number of each type of emoticon with Table 2 as the polarity classification criterion, and use the number of emoticons of each type of polarity in a sentence as the emoticon characteristics of German texts to reflect the strength of positive and negative emotion polarity in German texts.Table 2
Classification of emoticons.
Emotional polarityEmoticonJust′3) ′, ′: ∗ ′, ′ > 3′, ′ С: ′, ′}: -> ′, ′∗ ^_^∗ ′, ′ ^_^ ′, ′ =D′, ′ 8 ) ′, ′ (: ′, ′ ^ _ _ _ ^ ′, ′ ^ w ^ ′, ′: D′, ′∗ -∗ ′, ′: -) ′, ′) ) ′, ′: ) ′, ′: 3′, ′ ^ ^ ′, ′ = ) ′, ′: ∗ ′, ′ ∗ _∗ ′, ′-. -′, ′ XD′, ′: -D′, ′; ) ′, ′ ∗ о ∗ ′, ′ = 3 = ′, ′ о _о′, ′∗ О∗ ′, ′: В ′, ′ < 3′, ′ > D′Negative′ < = ′, ′ > > ′, ′ > . < ′, ′ > < ′, ′: < ′, ′: с′, ′: \ ′ с′, ′:С′, ′: ( ( ′, ′-_-′, ′-_ _ _-′, ′ ( _! _ ) ′, ′-_ _ _ _-′, ′:\ \ ′, ′. _. ′, ′: ( ′, ′( ( ( ′, ′; ( ′In′O_o′, ′0_0′, ′: @ ′, ′ = #′


## 3.2.3. Self-Attentive Depth Model for German Sentiment Analysis

In order to effectively combine the ability of CNN model to capture local features of multidimensional data, the advantage of RNN model to extract long-term dependencies in sequences, and the feature of self-attentive mechanism to focus on important information, and thus improve the German sentiment classification, this paper proposes a hybrid CNN-BiLSTM deep learning model ACBM based on self-attentive mechanism. As shown in Figure1, the model consists of six submodules [28]. The model consists of six submodules. First, the word-level feature encoding layer transforms each word and its corresponding sentiment features into a sentimental word vector containing semantic and sentiment information based on the word vector and various word-level sentiment features. Then, the local feature extraction layer is responsible for extracting the local contextual features of each word from the adjacent information. Then, the sequence feature extraction layer, which is responsible for extracting the sequence features of the whole text, and the attention layer, which is responsible for generating the sentiment weight of each element in the sequence, work in concert. Finally, the sentiment classification layer combines the previously generated attentional sequence features and the output of the sentence-level feature encoding layer to generate the determination results of the sentiment classification of the whole model.Figure 1
CNN-BiLSTM hybrid model in this paper.First, we have attention advantage: compared with CNN and RNN, the model has less complexity and fewer parameters. Therefore, the requirements for computational power are smaller.Then, we have fast speed: attention solves the problem that RNN cannot perform parallel computing. Each step of the attention mechanism does not depend on the calculation results of the previous step, so it can be processed in parallel with CNN.Next, we have good effect: before the introduction of the attention mechanism, there was a problem that everyone had been distressed: long-distance information would be weakened, just as people with weak memory could not remember the past.


## 3.2.4. Word-Level Feature Encoding Layer

In order to convert textual information into digital vectors that can be processed by neural networks, this paper uses fastText [25] based on the pretrained word vectors obtained from Wikipedia and massive public website texts, and the dimension of word vector wi for each word is 300. Because of the large size of the vocabulary, which contains 1,888,423 German words, and the use of N-gram character features to generate word vectors, fastText is not only effective in reducing the probability of OOV (out of vocabulary), but also applicable to the morphologically rich German.Although fastText word vectors are semantically rich, they contain limited sentiment information, and some words with close contexts and opposite sentiment tend to have similar word vectors. To solve this problem, this paper makes full use of existing resources, such as word formation rules, sentiment dictionaries, slang dictionaries, and German morphological analysis tools to add sentiment information to the existing word vectors and then from sentimental word vectors. In the experiments, all the continuous features with similar sentiment score are first clustered byK-means and other methods, so that the number of categories of each word-level feature is limited. Then, the jth word-level feature (1≤j ≤ m) of the ith word is mapped into a q-dimensional sentiment vector that can be self-learnt in the deep model wifi. Finally, wifj containing sentiment information is merged with the original word vector xi=wi⊕wif1⊕…⊕wifi⊕…⊕wifm to obtain the sentiment word vector containing rich word-level sentiment features, which is calculated as xi, where the symbol represents the merging operation of the vector, and the dimension of the vector 555 d is equal to 300 + q × m.


## 3.2.5. Local Feature Extraction Layer

The German vocabulary is not only morphologically rich, but also highly polysemous. А.Будагов’s study of large dictionaries shows that the proportion of polysemous words in German is as high as 80%, and many words not only have a wide range of meanings but also contain opposite emotional messages [26]. For example, one of the most basic and active verbs in German, “идти,” contains even more than 20 meanings, while the verb “следить” has the meanings “to watch,” “to care,” “to monitor,” and “to follow.” The verb “следить” has different emotional meanings such as “watch,” “care,” “watch,” and “follow,” and the semantic meaning and the emotional information it contains are not only determined by itself but also influenced by other words in the context [27]. For example, when the adjective “зелёная” is followed by “трава,” “молодёжь,” and “скука,” the meanings are “green grass” and “childish youth,” and the meanings of the words “green grass,” “childish youth,” and “embarrassing boredom” not only are different but also do not correspond to the polarity of the emotions expressed.In order to extract more objective and accurate local features of the words, this paper uses CNN to extract the local contextual features of each word for the sentiment vector matrix output from the word-level feature encoding layer, and its structure is shown in Figure2. Assuming that the text contains n words and the dimension of emotional word vector is D, the initial shape of emotional feature matrix X is n × d. In order to make the sequence length of CNN input and output consistent, this paper changes the shape of matrix X to (n + (2) by filling pad × d. The convolution layer contains T pieces with a size of 3 × D. When the J (1 ≤ J ≤ T) th convolution kernel Wj convolutes xi in matrix X, the local eigenvalue gij1≤i≤n will be obtained. The calculation process is as follows:(1)gij=fWjΘXi:i+2+b,vi=gi1,gi2,gi3,⋯,giT.Figure 2
Local feature extraction layer.In1, xi:i+2 is the sentiment eigenvector from row i to row i + 2 of matrix X, ⊙ represents the convolution product, b is the bias, and f is the nonlinear activation function (Re LU is chosen as the activation function in this paper to speed up the convergence). In 2, vi consists of the 3-gram local eigenvalues extracted around the ith word by the convolutional kernel W in the convolutional layer T respectively. Compared with the sentiment word vector xi, the local sentiment feature vector vi contains not only the features of the i-word itself, but also the contextual features of the adjacent regions of the word, which contains more comprehensive and objective semantic and sentiment information.


## 3.2.6. Sequence Feature Extraction Layer

CNNs are limited by the fixed size of the convolutional kernel window, which makes it difficult to model long-distance sequence information. In order to extract longer distance and deeper hidden sentiment information, this paper feeds the local feature vectorv1,v2,…vn into the sequence feature extraction layer sequentially. Although the standard RNN is good at processing sequential data, it has two drawbacks: (1) the gradient disappearance or explosion problem in long-sequence training reduces its ability to perceive important node information at longer distances; (2) the unidirectional state information transmission prevents it from capturing the influence of the later text on the target word. Therefore, this paper adopts a bidirectional LSTM [13] to extract sequence features, on the one hand, by controlling the transmission state with the gate structure in the LSTM, thus limiting the filtering of invalid information and memory retention of long-distance sentiment features, and on the other hand, by capturing the contextual sequence features at the current position simultaneously through two independent and opposite direction LSTMs. On the other hand, two independent LSTMs with opposite directions capture the contextual sequence of features at the current location simultaneously and then consider the sentiment and semantic information of past and future directions of each location comprehensively:(2)h1F,c1F=LSTMFvn,h0F,c0F;⋯;hnF,cnF=LSTMFv1,hn−1F,cn−1F,h1B,c1B=LSTMBv1,h0B,c0B;⋯;hnB,cnB=LSTMBvn,hn−1B,cn−1Bhi=hn−i+1F⊕hiB1≤i≤n.In (3), LSTMF and LSTMB represent the forward and backward LSTM models, ciF and ciB correspond to the cell states of the two models, h1F and hiB correspond to the implied layer outputs of the two models, and the initial states h0F,c0F and h0B,c0B of the two directional LSTMs are zero. Equation (4) splices the output of LSTMF and LSTMB, which is the final output of the sequence feature extraction layer.


## 3.2.7. Attention Layer

The brain always allocates more attention to the relatively important elements when reading, thus improving the efficiency of acquiring key information. The attention layer in this section adopts a similar attention mechanism, and before fusing the information and sending it to the emotion classification layer, the attention sequence features that accurately reflect the important emotion information in the German text are obtained by calculating the emotion weight of each word and highlighting the elements that contain key features and weakening the non-emotion information or unimportant elements, thus improving the effectiveness of the model. Deep learning models based on the self-attention mechanism in many studies [28] have directly used the implicit layer hi of the LSTM to generate the attention weight values of different elements ai, which is calculated as shown in the following:(3)si=tanhWThi+b;ai=softmaxsiA,where siA is automatically learned by the model from the corpus as the scoring system, A and W are both weight matrices, and b is the bias. However, the disadvantage of this algorithm is that the hidden vector hi generated by Bi-LSTM needs to represent both the emotional and semantic information of each word and also needs to contain the weight of the word in the emotional expression. As shown in Figure 3, in this paper, the attention layer is supplemented by BiLSTMattention, which is dedicated to generating weights based on the implicit layer hi′ of the local feature vector V output, instead of hi, and generates the weight ai corresponding to the ith word:(4)si=tanhWThi′+b;ai=softmaxsiA,∑i=1nai=1;ASF=∑i=1nai∗hi.Figure 3
Structure of the attention layer.


## 3.2.8. Sentence-Level Feature Encoding Layer and Sentiment Classification Layer

Similar to the function and principle of the word-level feature coding layer, the sentence-level feature coding layer is responsible for extracting the sentence-level emotional feature vector SF. The module first selectsl reserved sentence-level emotional features and then transforms its jth sentence-level feature (1 ≤ J ≤ L) into a p-dimensional emotional feature vector sfj that can self-learn in the depth model through polynomial expansion. Finally, the sentence-level feature vector sfi containing rich emotional information is obtained by merging. The calculation formula is SF=sf1⊕⋯⊕sfi⊕⋯⊕s/l, and the dimension of vector SF is equal to p∗l.Sentiment classification layer is responsible for the final classification results of the whole model. As shown in Figure4, firstly, in order to prevent the model from overfitting, the sentiment classification layer applies dropout and L2 regularization strategies to the attention sequence feature ASF, which reduces the interaction between the nodes in the hidden layer by randomly discarding some parameters of the model and controlling the complexity of the model, so as to reduce the generalization error of the whole deep neural network. Then, results of the processed ASF are merged with the sentence-level sentiment feature SF and sent to the sentiment classification layer together. In order to make the model more stable and speed up the convergence, we perform the dimensionality reduction operation step by step through two fully connected layers and add the normalization operation between the two layers to avoid ignoring the features with small values in some dimensions. Finally, the surtax regression is used to obtain the triple classification results with the sentiment polarity of “positive, negative, and medium.”Figure 4
Emotion classification layer.


## 3.3. Experiments and Results Analysis

### 3.3.1. Experimental Data and Evaluation Index

The data set used in this paper is provided by [5], which contains 3968 German tweets with classification tags, including 1145 positive sentiments and 1188 negative sentiments, and the rest are marked as neutral. In order to improve the classification accuracy, the corpus was preprocessed and words with the same root were mapped into a uniform form by stemming (e.g., removing interference from singular and plural, person, feminine and masculine, nominative case, verb with multiple tenses, forms, etc.). After preprocessing, there are 13,943 words or symbols left in the corpus, of which 12,485 can be mapped to the pretrained word vector provided by fastText, and the OOV ratio decreases from 14.78% to 10.46%. To enable the model to find the global optimal solution quickly, the Mini-Batch gradient descent method is used to train the model, and the performance of the final model is checked using the 5-fold cross-validation method, while F1_macro is used as the main evaluation criterion and accuracy is used as the secondary evaluation criterion to balance the relationship between accuracy and recall, both of which are abbreviated as F1 and Acc in the later paper.


## 3.3.1. Experimental Data and Evaluation Index

The data set used in this paper is provided by [5], which contains 3968 German tweets with classification tags, including 1145 positive sentiments and 1188 negative sentiments, and the rest are marked as neutral. In order to improve the classification accuracy, the corpus was preprocessed and words with the same root were mapped into a uniform form by stemming (e.g., removing interference from singular and plural, person, feminine and masculine, nominative case, verb with multiple tenses, forms, etc.). After preprocessing, there are 13,943 words or symbols left in the corpus, of which 12,485 can be mapped to the pretrained word vector provided by fastText, and the OOV ratio decreases from 14.78% to 10.46%. To enable the model to find the global optimal solution quickly, the Mini-Batch gradient descent method is used to train the model, and the performance of the final model is checked using the 5-fold cross-validation method, while F1_macro is used as the main evaluation criterion and accuracy is used as the secondary evaluation criterion to balance the relationship between accuracy and recall, both of which are abbreviated as F1 and Acc in the later paper.


## 3.4. Comparative Experiments and Analysis of Results

### 3.4.1. Comparison of Multiple Classification Schemes Based on English Translations

Because of the small amount of German corpus and the limited capability of German sentiment analysis tools, the literature [5] combined a translation engine with an English sentiment analysis tool to obtain the classification results. sentiment140.com) obtained the highest F1 value of 61%. The results of the combination of two translation engines and two analysis tools were designed in this paper, based on the premise that the Cov reaches 100% and the performance of the four combinations ranges from 47.85% to 53.64%, among which the combination of Baidu Translate and Vader [20] has the best result, as shown in Figure 5. It is found that for the German corpus [5], Baidu Translate is slightly better than Google Translate in the case of using the same English analysis tool, which also proves that the translation quality will have some influence on the analysis results.Figure 5
Comparing the effect of various English translation emotional features.In this paper, the feature vectors extracted by the Bert pretraining model are directly fed into the fully connected layer for sentiment classification, and it is found that theF1 of the Bert English pretraining model is 7.25% higher than that of the multilingual pretraining model. Through comparison experiments, it is found that the results of the ACBM model are better than all the above schemes, which indicates that the sentiment classification based on the English translation is less effective than that based on the direct analysis of the German original due to the information loss of semantic, emotional, and linguistic features caused by translation. This indicates that the effect of sentiment classification based on English translation is not as good as the analysis of the original German text directly, and it is recommended to be used as an interim solution or an auxiliary solution in migration learning until further breakthroughs in machine translation technology are achieved.


### 3.4.2. Comparison of Various Sentence-Level Features

In order to deeply explore the sentiment information in German tweets and make full use of relevant knowledge and linguistic features, this paper adds various sentence-level sentiment features to the LSTM and ACBM models, respectively, and compares three correlation indices between these features and sentiment classification labels, Kendall, Pearson, and Spearman, and finds that the absolute value of the indices correlates with the absolute value of the corresponding features after adding them. The absolute values of the indices were found to be positively correlated with the experimental results after adding the corresponding features, as shown in Table3.Table 3
Comparison of results for various sentence-level features.
FeaturesKendallPearsonSpearmanF1LSTMF1ACBMNothing———62.1163.28Bert vector———63.8565.18English translation Vader affective value0.38360.47270.468363.1664.77Number of forward emoticons0.34930.34720.372962.9864.55End bracket direction0.32070.34100.341162.9064.53Lentil 40 emotional value0.26280.29740.293162.5864.16Number of negative emoticons−0.0651−0.1739−0.174962.3563.94Total exclamation marks0.0523−0.0260−0.026062.2463.78Total number of question marks−0.0246——62.2463.51Among the selected sentence-level features, the English translation Bert vector, the English translation Vader sentimental value, the number of positive expressions, and the direction of closing brackets have the best effect. In contrast, the sentence-level features improve the LSTM more significantly, which indicates that ACBM is more capable of extracting sentimental features for the original text, so the effect of sentence-level features is limited to assist and complement it. The best results for the two English-translated emotional features indicate that although the effect of relying on the English translation alone is not ideal. It can be used as an effective aid in German emotional analysis. Emoticons also work relatively well (the parentheses at the end are also similar to emoticons), suggesting that social media language prefers to use distinctive emoticons to express one’s emotional tendencies. Exclamation marks and question marks are less effective because they mainly express the presence or absence of emotions but do not contain positive or negative information about emotions.


### 3.4.3. Comparison of Various Word-Level Features

In order to investigate the effect of various word-level features on the sentiment analysis of German, we also added various word-level sentiment features to the LSTM and ACBM models, respectively, as shown in Figure6. Among these features, sentimental score, expletive slang, and sentiment score + lexically is the most effective, with the F1 of LSTM increasing by 0.83%, 1.31%, and 0.77%, respectively, and the F1 of ACBM increasing by 0.97%, 1.56%, and 1.57%, respectively, before and after adding the features. In contrast to the sentence-level features, the word-level features obviously improve the ACBM more significantly, which indicates that the ACBM is more sensitive to word contextual sentimental features and local information after introducing the CNN module and the self-attentive mechanism. In addition, F1 value of ACBM is 1.46–2.51 higher than that of LSTM with or without features, and with or without features. It is worth noting that the effect of adding word-level features alone is relatively poor, but when both sentimental score and word-level features are added, the F1 is 0.6% higher than that of sentiment score features alone. This is due to the fact that the self-attentive mechanism of ACBM can effectively extract the weight of each element of the lexical features, and thus the model can focus more on the sentimental score features of important elements.Figure 6
Comparison of results for various word-level features.In order to verify the role of German morphological information in sentiment analysis, various German morphological forms were added to the two models in turn, as shown in Tables3 and 4. The experimental results show that six morphological forms have an enhancing effect on the original model, among which the morphological forms “tense” and “person” have a relatively significant enhancing effect. This may be due to the fact that in German expressions, imperatives tend to express strong subjective emotions more than declarative forms and first person than other forms, while the rest of the morphological forms are less effective in expressing emotions in German.Table 4
Comparison of classification results of different methods.
ModelF1w/ofAccw/ofF1w−fAccw−fF1↑Acc↑Dostoevsky53.4055.45————SVM54.2354.8058.4558.624.224.01CNN62.5162.6466.5466.654.034.01LSTM62.1162.1965.9566.033.853.84Bi-LSTM62.4762.4766.4866.504.014.03BiLSTM-2layers62.8563.0266.3967.014.083.99BiLSTM-ATT62.5962.5766.5666.633.974.06BiLSTM-ATT263.463.3667.8567.964.454.6BiLSTM-CNN63.3563.2867.5167.694.164.41CNN-Bi-LSTM63.4763.5167.8367.984.364.47ACBM63.8263.9068.7568.875.035.07


### 3.4.4. Comparison of Results of Multiple Models

In order to verify the sentiment analysis ability of this model ACBM on German social media texts, Table4 compares it with the German sentiment analysis tool Dostoevsky4, traditional machine learning methods (SVM), common deep learning models (CNN, LSTM, and Bi-LSTM), and various deep learning combination models. The first group analyzes the original text directly without introducing any features, and the corresponding experimental results are F1w/of and Accw/of. In group 2, several word-level features (emotion score + part of speech + dirty slang) and sentence-level features (emoticon + English translation emotion) are added at the same time. The corresponding experimental results are F1w−f and accw-f. F1 ↑ and ACC ↑ represent the corresponding improvement of F1 and ACC in group 2 experimental results of each model compared with group 1 experimental results except Dostoevsky. The calculation formulas are as follows: F1 ↑ = F1w−f − F1w/of and ACC ↑ = Accw−f − Accw/of. Obviously, the higher F1 ↑ and ACC ↑ means that the effect of emotion classification is more obvious after adding emotion features at all levels to the corresponding model. The description for each model is as follows: Dostoevsky is a German emotion analysis depth model trained based on Ru sentiment [29], and the F1 value on its test set is 0.71; BiLSTM-2layers reproduce the two-layer stacked bidirectional LSTM proposed in document [13]; Bilstm-att and bilstm-att2 add self-attention mechanism based on formulas (5) and (6), respectively, on the basis of BiLSTM; BiLSTM-CNN is a deep learning combination model of BiLSTM before CNN; CNN-BiLSTM is a deep learning combination model of CNN before BiLSTM.The results of the comparison experiments illustrate that the performance of all models improves significantly after introducing all levels of sentiment features, among which ACBM improves the most, withF1 and Acc improving by 5.03 and 5.07, respectively. Due to not retraining on the data [5], Dostoevsky performs poorly and is close to the performance of SVM without adding features, while all depth models outperform SVM with or without adding features. With the addition of features at all levels, the difference between CNN and BiLSTM results is not significant, but both results are significantly better than LSTM, which demonstrates the ability of CNN to efficiently extract local features of text and the sensitivity of BiLSTM to capture features before and after sequence history. If the number of model layers F1 added to BiLSTM will improve by 0.51, 0.13, and 1.46 [30], respectively, this proves that increasing the number of network layers or the self-attention module can effectively improve the performance of BiLSTM, and the improved self-attention mechanism is more effective. The results of CNN-BiLSTM are slightly stronger than those of BiLSTM-CNN, which indicates that it is more reasonable to use CNN to extract local features and then BiLSTM to extract global sequence features for German tweets. This indicates that by optimizing the combination of CNN and BiLSTM with a clear self-attentive mechanism, we can capture local features, summarize global information, and improve sentiment analysis in a more detailed way.


### 3.4.5. Attention Analysis

The ACBM model is able to assign higher sentiment weight to important elements based on the self-attentive mechanism and various multilevel sentimental features of the text, thus enhancing the extraction and analysis of sentiment information, the heat map of token weights generated by ACBM self-attentive layer [31] as shown in Figure 7, for example, whether they are positive or negative emoticons like “: D” and “: (,” or real words with obvious sentiment tendency, such as “glücklich” (pleasant), “wie” (like), “gute Arbeit” (good), “Grob” (rough), “Böse” (evil), “Abfälle” (wasted), and “Mist. The real words with obvious emotional tendencies, such as “Böse,” “Abfälle,” and “Mist,” are given high emotional weight. In sentences 1–5, the highest weight is 3.1–5.7 times the average value of the remaining weight. In sentences 6 and 7, the two highest weights are 10.9 and 15.3 times the average of the remaining weight. Analyzing example 8, we can also see that when there are multiple expressions of opposite polarity in the sentence, ACBM assigns a higher weight to the relatively important expression “: (” based on the meaning of the text and the position of each token.Figure 7
Heat map of Token weights generated by ACBM self-attentive layer.


## 3.4.1. Comparison of Multiple Classification Schemes Based on English Translations

Because of the small amount of German corpus and the limited capability of German sentiment analysis tools, the literature [5] combined a translation engine with an English sentiment analysis tool to obtain the classification results. sentiment140.com) obtained the highest F1 value of 61%. The results of the combination of two translation engines and two analysis tools were designed in this paper, based on the premise that the Cov reaches 100% and the performance of the four combinations ranges from 47.85% to 53.64%, among which the combination of Baidu Translate and Vader [20] has the best result, as shown in Figure 5. It is found that for the German corpus [5], Baidu Translate is slightly better than Google Translate in the case of using the same English analysis tool, which also proves that the translation quality will have some influence on the analysis results.Figure 5
Comparing the effect of various English translation emotional features.In this paper, the feature vectors extracted by the Bert pretraining model are directly fed into the fully connected layer for sentiment classification, and it is found that theF1 of the Bert English pretraining model is 7.25% higher than that of the multilingual pretraining model. Through comparison experiments, it is found that the results of the ACBM model are better than all the above schemes, which indicates that the sentiment classification based on the English translation is less effective than that based on the direct analysis of the German original due to the information loss of semantic, emotional, and linguistic features caused by translation. This indicates that the effect of sentiment classification based on English translation is not as good as the analysis of the original German text directly, and it is recommended to be used as an interim solution or an auxiliary solution in migration learning until further breakthroughs in machine translation technology are achieved.


## 3.4.2. Comparison of Various Sentence-Level Features

In order to deeply explore the sentiment information in German tweets and make full use of relevant knowledge and linguistic features, this paper adds various sentence-level sentiment features to the LSTM and ACBM models, respectively, and compares three correlation indices between these features and sentiment classification labels, Kendall, Pearson, and Spearman, and finds that the absolute value of the indices correlates with the absolute value of the corresponding features after adding them. The absolute values of the indices were found to be positively correlated with the experimental results after adding the corresponding features, as shown in Table3.Table 3
Comparison of results for various sentence-level features.
FeaturesKendallPearsonSpearmanF1LSTMF1ACBMNothing———62.1163.28Bert vector———63.8565.18English translation Vader affective value0.38360.47270.468363.1664.77Number of forward emoticons0.34930.34720.372962.9864.55End bracket direction0.32070.34100.341162.9064.53Lentil 40 emotional value0.26280.29740.293162.5864.16Number of negative emoticons−0.0651−0.1739−0.174962.3563.94Total exclamation marks0.0523−0.0260−0.026062.2463.78Total number of question marks−0.0246——62.2463.51Among the selected sentence-level features, the English translation Bert vector, the English translation Vader sentimental value, the number of positive expressions, and the direction of closing brackets have the best effect. In contrast, the sentence-level features improve the LSTM more significantly, which indicates that ACBM is more capable of extracting sentimental features for the original text, so the effect of sentence-level features is limited to assist and complement it. The best results for the two English-translated emotional features indicate that although the effect of relying on the English translation alone is not ideal. It can be used as an effective aid in German emotional analysis. Emoticons also work relatively well (the parentheses at the end are also similar to emoticons), suggesting that social media language prefers to use distinctive emoticons to express one’s emotional tendencies. Exclamation marks and question marks are less effective because they mainly express the presence or absence of emotions but do not contain positive or negative information about emotions.


## 3.4.3. Comparison of Various Word-Level Features

In order to investigate the effect of various word-level features on the sentiment analysis of German, we also added various word-level sentiment features to the LSTM and ACBM models, respectively, as shown in Figure6. Among these features, sentimental score, expletive slang, and sentiment score + lexically is the most effective, with the F1 of LSTM increasing by 0.83%, 1.31%, and 0.77%, respectively, and the F1 of ACBM increasing by 0.97%, 1.56%, and 1.57%, respectively, before and after adding the features. In contrast to the sentence-level features, the word-level features obviously improve the ACBM more significantly, which indicates that the ACBM is more sensitive to word contextual sentimental features and local information after introducing the CNN module and the self-attentive mechanism. In addition, F1 value of ACBM is 1.46–2.51 higher than that of LSTM with or without features, and with or without features. It is worth noting that the effect of adding word-level features alone is relatively poor, but when both sentimental score and word-level features are added, the F1 is 0.6% higher than that of sentiment score features alone. This is due to the fact that the self-attentive mechanism of ACBM can effectively extract the weight of each element of the lexical features, and thus the model can focus more on the sentimental score features of important elements.Figure 6
Comparison of results for various word-level features.In order to verify the role of German morphological information in sentiment analysis, various German morphological forms were added to the two models in turn, as shown in Tables3 and 4. The experimental results show that six morphological forms have an enhancing effect on the original model, among which the morphological forms “tense” and “person” have a relatively significant enhancing effect. This may be due to the fact that in German expressions, imperatives tend to express strong subjective emotions more than declarative forms and first person than other forms, while the rest of the morphological forms are less effective in expressing emotions in German.Table 4
Comparison of classification results of different methods.
ModelF1w/ofAccw/ofF1w−fAccw−fF1↑Acc↑Dostoevsky53.4055.45————SVM54.2354.8058.4558.624.224.01CNN62.5162.6466.5466.654.034.01LSTM62.1162.1965.9566.033.853.84Bi-LSTM62.4762.4766.4866.504.014.03BiLSTM-2layers62.8563.0266.3967.014.083.99BiLSTM-ATT62.5962.5766.5666.633.974.06BiLSTM-ATT263.463.3667.8567.964.454.6BiLSTM-CNN63.3563.2867.5167.694.164.41CNN-Bi-LSTM63.4763.5167.8367.984.364.47ACBM63.8263.9068.7568.875.035.07


## 3.4.4. Comparison of Results of Multiple Models

In order to verify the sentiment analysis ability of this model ACBM on German social media texts, Table4 compares it with the German sentiment analysis tool Dostoevsky4, traditional machine learning methods (SVM), common deep learning models (CNN, LSTM, and Bi-LSTM), and various deep learning combination models. The first group analyzes the original text directly without introducing any features, and the corresponding experimental results are F1w/of and Accw/of. In group 2, several word-level features (emotion score + part of speech + dirty slang) and sentence-level features (emoticon + English translation emotion) are added at the same time. The corresponding experimental results are F1w−f and accw-f. F1 ↑ and ACC ↑ represent the corresponding improvement of F1 and ACC in group 2 experimental results of each model compared with group 1 experimental results except Dostoevsky. The calculation formulas are as follows: F1 ↑ = F1w−f − F1w/of and ACC ↑ = Accw−f − Accw/of. Obviously, the higher F1 ↑ and ACC ↑ means that the effect of emotion classification is more obvious after adding emotion features at all levels to the corresponding model. The description for each model is as follows: Dostoevsky is a German emotion analysis depth model trained based on Ru sentiment [29], and the F1 value on its test set is 0.71; BiLSTM-2layers reproduce the two-layer stacked bidirectional LSTM proposed in document [13]; Bilstm-att and bilstm-att2 add self-attention mechanism based on formulas (5) and (6), respectively, on the basis of BiLSTM; BiLSTM-CNN is a deep learning combination model of BiLSTM before CNN; CNN-BiLSTM is a deep learning combination model of CNN before BiLSTM.The results of the comparison experiments illustrate that the performance of all models improves significantly after introducing all levels of sentiment features, among which ACBM improves the most, withF1 and Acc improving by 5.03 and 5.07, respectively. Due to not retraining on the data [5], Dostoevsky performs poorly and is close to the performance of SVM without adding features, while all depth models outperform SVM with or without adding features. With the addition of features at all levels, the difference between CNN and BiLSTM results is not significant, but both results are significantly better than LSTM, which demonstrates the ability of CNN to efficiently extract local features of text and the sensitivity of BiLSTM to capture features before and after sequence history. If the number of model layers F1 added to BiLSTM will improve by 0.51, 0.13, and 1.46 [30], respectively, this proves that increasing the number of network layers or the self-attention module can effectively improve the performance of BiLSTM, and the improved self-attention mechanism is more effective. The results of CNN-BiLSTM are slightly stronger than those of BiLSTM-CNN, which indicates that it is more reasonable to use CNN to extract local features and then BiLSTM to extract global sequence features for German tweets. This indicates that by optimizing the combination of CNN and BiLSTM with a clear self-attentive mechanism, we can capture local features, summarize global information, and improve sentiment analysis in a more detailed way.


## 3.4.5. Attention Analysis

The ACBM model is able to assign higher sentiment weight to important elements based on the self-attentive mechanism and various multilevel sentimental features of the text, thus enhancing the extraction and analysis of sentiment information, the heat map of token weights generated by ACBM self-attentive layer [31] as shown in Figure 7, for example, whether they are positive or negative emoticons like “: D” and “: (,” or real words with obvious sentiment tendency, such as “glücklich” (pleasant), “wie” (like), “gute Arbeit” (good), “Grob” (rough), “Böse” (evil), “Abfälle” (wasted), and “Mist. The real words with obvious emotional tendencies, such as “Böse,” “Abfälle,” and “Mist,” are given high emotional weight. In sentences 1–5, the highest weight is 3.1–5.7 times the average value of the remaining weight. In sentences 6 and 7, the two highest weights are 10.9 and 15.3 times the average of the remaining weight. Analyzing example 8, we can also see that when there are multiple expressions of opposite polarity in the sentence, ACBM assigns a higher weight to the relatively important expression “: (” based on the meaning of the text and the position of each token.Figure 7
Heat map of Token weights generated by ACBM self-attentive layer.


## 4. Conclusions

This paper constructs a deep learning model based on self-attention mechanism based on the fusion of word-level features such as slang, German morphology, emotion score, and word nature, and sentence-level features, such as emoticons and English-translated emotion values, and achieves good results in the analysis of German tweets’ emotion. The study shows that although the effect of direct analysis of English translation is not satisfactory, it can be used as an important auxiliary tool for deep learning models; the fusion of multilevel features is beneficial to improve the effect of various models, among which the sentence-level features are more obvious for simple models and the word-level features are more obvious for complex models; compared with single depth models and common combined depth models, the fusion of the advantages of CNN and LSTM and so on and the improved self-attentive mechanism can be used to improve the effect of deep learning models. The ACBM designed in this paper can significantly improve the results of sentiment classification for German social media texts by combining the advantages of CNN and LSTM models with an improved self-attentive mechanism.This paper still has the following shortcomings and room for improvement: due to the limited German corpus, comparison experiments were only conducted on the German tweet corpus [5] and how to build a larger and richer type of German sentiment corpus is the focus of the next stage of research; after incorporating the letter, punctuation, and some morphological features, the model failed to achieve the expected results, to more reasonably integrate these features into the deep learning model, and to explore the role of these features on different corpus. Exploring the role of these features on different corpora also deserves further research.



---

*Source: 8309586-2021-11-17.xml*