Text Classification Research with Attention-based Recurrent Neural Networks

Changshun Du, Lei HuangInternational Journal of Computers Communications & Control 2018 · DOI

Abstract

Text classification is one of the principal tasks of machine learning. It aims to design proper algorithms to enable computers to extract features and classify texts automatically. In the past, this has been mainly based on the classification of keywords and neural network semantic synthesis classification. The former emphasizes the role of keywords, while the latter focuses on the combination of words between roles. The method proposed in this paper considers the advantages of both methods. It uses an attention mechanism to learn weighting for each word. Under the setting, key words will have a higher weight, and common words will have lower weight. Therefore, the representation of texts not only considers all words, but also pays more attention to key words. Then we feed the feature vector to a softmax classifier. At last, we conduct experiments on two news classification datasets published by NLPCC2014 and Reuters, respectively. The proposed model achieves F-values by 88.5% and 51.8% on the two datasets. The experimental results show that our method outperforms all the traditional baseline systems.

Introduction

Text classification serves as a cornerstone for numerous natural language processing (NLP) applications, ranging from sentiment analysis to automated news categorization. Historically, two primary paradigms have dominated the field. Keyword-based methods prioritize specific high-signal terms but often fail to capture the nuanced semantic relationships within a sentence. Conversely, neural semantic methods, particularly standard Recurrent Neural Networks (RNNs), excel at sequence modeling but can suffer from "feature dilution," where the impact of critical keywords is lost in the overall document representation.

This research proposes a hybrid approach that bridges these methodologies. By integrating an attention mechanism into a bidirectional RNN framework, the model can synthesize global semantic context while dynamically identifying and weighting the most informative words for a given classification task.

Methodology

The core of the proposed system is a Bidirectional RNN augmented with an attention layer. This architecture allows the model to capture dependencies from both directions of the text sequence while explicitly modeling word importance.

1. Contextualized Input and Bidirectional Backbone

The model begins with a contextualized input layer that utilizes a sliding window approach to provide initial local context for each word vector. This sequence is then processed by a bidirectional RNN, which can be implemented using either Long Short-Term Memory (LSTM) or Gated Recurrent Unit (GRU) cells.

Comparison of LSTM and GRU internal structures used in the bidirectional backbone.

The bidirectional structure processes the text from "Head to Tail" and "Tail to Head," ensuring that the hidden state at any given position incorporates information from both the preceding and succeeding context.

2. Attention Mechanism

The attention mechanism is the pivotal innovation of this architecture. It calculates a weight ($\alpha$) for each word's hidden state based on its relevance to the target categories. By learning a "category vector," the model determines which words are most indicative of specific classes. This results in a weighted feature vector where "signal" words are amplified and "noise" or filler words are suppressed.

The complete architecture of the Attention-based Bidirectional RNN, showing the flow from input to attention-weighted classification.

The final representation is passed through a dropout layer to mitigate overfitting and then into a softmax classifier to generate category probabilities.

Experimental Setup and Results

The model was evaluated on two large-scale news datasets: the Xinhua News Agency corpus (NLPCC 2014) for Chinese and the Reuters RCV1-v2 for English. Word vectors were pre-trained using the Skip-gram model on domain-relevant corpora (Baidu Encyclopedia and the New York Times).

The experimental results demonstrate that the attention-based models significantly outperform traditional baselines, such as TF-IDF combined with Support Vector Machines (SVM).

Dataset Model F-Value
Xinhua (Chinese) Attention-GRU Bi-RNN 88.5%
Xinhua (Chinese) TF-IDF + SVM 79.5%
Reuters (English) Attention-LSTM Bi-RNN 51.8%
Reuters (English) TF-IDF + SVM 37.5%

Notably, the GRU variant showed superior performance on the Chinese dataset, while the LSTM variant was more effective for the English corpus. This suggests that the choice of recurrent unit may be sensitive to the linguistic properties or the specific structure of the dataset.

Discussion and Conclusion

The success of the proposed model lies in its ability to perform "dynamic keyword extraction." Unlike static keyword lists, the attention mechanism learns importance weights in the context of the entire document's semantics.

However, challenges remain. The performance discrepancy between the Chinese and English datasets suggests that flat classification architectures may struggle with the highly hierarchical nature of datasets like Reuters. Furthermore, while bidirectional RNNs are powerful, they introduce higher computational costs compared to simpler linear models. Future research will explore the integration of self-attention mechanisms and hierarchical classification strategies to further refine these results.

Summary updated

Abstract

Text classification is one of the principal tasks of machine learning. It aims to design proper algorithms to enable computers to extract features and classify texts automatically. In the past, this has been mainly based on the classification of keywords and neural network semantic synthesis classification. The former emphasizes the role of keywords, while the latter focuses on the combination of words between roles. The method proposed in this paper considers the advantages of both methods. It uses an attention mechanism to learn weighting for each word. Under the setting, key words will have a higher weight, and common words will have lower weight. Therefore, the representation of texts not only considers all words, but also pays more attention to key words. Then we feed the feature vector to a softmax classifier. At last, we conduct experiments on two news classification datasets published by NLPCC2014 and Reuters, respectively. The proposed model achieves F-values by 88.5% and 51.8% on the two datasets. The experimental results show that our method outperforms all the traditional baseline systems.
BibTeX
@article{du2018text,
  author = {Changshun Du and Lei Huang},
  title = {{Text Classification Research with Attention-based Recurrent Neural Networks}},
  journal = {International Journal of Computers Communications \& Control},
  year = {2018},
  doi = {10.15837/ijccc.2018.1.3142},
}
Figure