CharBERT: Character-aware Pre-trained Language Model

Wentao Ma, Yiming Cui, Chenglei Si, Ting Liu, Shijin Wang, Guoping Hu

Abstract

Modern pre-trained language models (PLMs) like BERT and RoBERTa primarily utilize subword-based tokenization, which can lead to the loss of fine-grained morphological information and a lack of robustness against character-level noise. We present CharBERT, a dual-channel architecture that integrates character-level representations alongside standard subword units. By employing a bidirectional GRU character encoder and a heterogeneous interaction module for deep fusion across all Transformer layers, CharBERT captures richer linguistic features. Furthermore, we introduce a Noisy Language Modeling (NLM) pre-training task to enhance the model's resilience to misspellings. Experimental results on standard benchmarks and adversarial datasets show that CharBERT consistently outperforms its subword-only counterparts, particularly in noisy environments.

Introduction

The success of models like BERT is largely attributed to subword tokenization methods such as Byte-Pair Encoding (BPE) or WordPiece. These techniques allow models to handle large vocabularies by decomposing rare words into frequent sub-units. However, this approach has significant drawbacks. First, it often fails to capture the internal morphological structure of words. Second, subword-based models are notoriously fragile; a single typo can result in a completely different set of tokens, causing performance to degrade sharply.

CharBERT is designed to bridge this gap by making PLMs "character-aware." By processing characters and subwords in parallel and allowing them to interact deeply, CharBERT maintains the semantic strengths of subword units while gaining the fine-grained structural understanding of character-level modeling.

Architecture and Methodology

CharBERT's core innovation is its dual-channel architecture, which processes subword tokens and character sequences simultaneously.

Character Encoder and Interaction

Unlike previous attempts that used simple CNNs for character input, CharBERT utilizes a bidirectional Gated Recurrent Unit (GRU) to construct contextual character embeddings. This allows the model to capture dependencies both within and across subword boundaries.

The "heart" of the architecture is the Heterogeneous Interaction (HI) Module. Instead of fusing character information only at the input layer, CharBERT performs fusion after every Transformer block. This module uses a CNN-based layer to fuse subword and character representations, which are then split back into their respective channels via residual connections. This deep fusion ensures that both channels inform each other throughout the model's depth.

The dual-channel architecture of CharBERT featuring the Heterogeneous Interaction module.

Pre-training Objectives

CharBERT is pre-trained using two primary objectives:

  1. Masked Language Modeling (MLM): The standard BERT objective applied to the subword channel to maintain lexical and syntactic understanding.
  2. Noisy Language Modeling (NLM): A novel unsupervised task designed to train the character channel. The model is presented with corrupted words (e.g., "song" becomes "sng" via character dropping, adding, or swapping) and must recover the original whole word from the noisy character sequence. This task acts as a powerful regularizer, making the model naturally resistant to noise.

Experimental Setup

The model was pre-trained on the English Wikipedia corpus. Evaluation was conducted across a wide range of tasks:

  • Question Answering: SQuAD 1.1 and 2.0.
  • Text Classification: GLUE benchmarks (CoLA, MRPC, QQP, QNLI).
  • Sequence Labeling: CoNLL-2003 for Named Entity Recognition (NER) and Penn Treebank for POS tagging.
  • Adversarial Robustness: The authors created "Attack" versions of QNLI, NER, and SQuAD 2.0 by introducing four types of character-level noise to test the model's resilience to typos.

Key Results and Discussion

CharBERT consistently outperformed base models like BERT and RoBERTa across all standard benchmarks. For instance, on SQuAD 1.1, CharBERT achieved an F1 score of 89.9, surpassing BERT-base's 88.5.

Robustness to Adversarial Attacks

The most significant gains were observed on the adversarial "Attack" datasets. While standard BERT's performance plummeted when faced with typos, CharBERT remained remarkably stable. On the QNLI-Attack set, CharBERT maintained an accuracy of 80.1%, whereas BERT dropped to 63.4%. This highlights the effectiveness of the NLM task and the dual-channel fusion in building robust representations.

Performance comparison on original and adversarial (Attack) datasets.

Insights on Subword Splitting

Analysis revealed that BERT performs significantly worse on words split into multiple subwords. CharBERT's character channel effectively "re-assembles" these fragments, leading to superior representations for complex or rare vocabulary. Interestingly, while CharBERT's embeddings are more sensitive to character changes, it uses this sensitivity to correctly identify the underlying word rather than being misled by the noise.

Conclusion

CharBERT demonstrates that integrating character-level information through a deep-fusion, dual-channel architecture significantly enhances both the performance and robustness of pre-trained language models. The addition of the Noisy Language Modeling task provides a principled way to handle real-world text noise. Future work will explore extending this architecture to morphologically rich languages and defending against higher-level adversarial attacks.

Summary updated

BibTeX
@inproceedings{ma2020charbert,
  author = {Wentao Ma and Yiming Cui and Chenglei Si and Ting Liu and Shijin Wang and Guoping Hu},
  title = {{CharBERT: Character-aware Pre-trained Language Model}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.coling-main.4},
}
Figure