Toucan: Token-Aware Character Level Language Modeling

William Fleshman, Benjamin Van DurmearXiv 2023

TL;DR

This paper introduces Toucan, a novel "token-aware" character-level language model that significantly speeds up character generation by learning to decode entire tokens at once, rather than character by character. Toucan achieves this by augmenting existing character-level transformer architectures, demonstrating substantial speedups without sacrificing language modeling performance and offering a more flexible tokenization approach compared to traditional methods like BPE and WordPiece.

What Problem Does This Paper Address?

Modern language models (LMs) typically rely on tokenizers to break text into fixed-size units (tokens) before feeding them into the model. While efficient, this process can be suboptimal as tokenizers and LMs are often trained separately, leading to a misalignment of objectives. On the other hand, character-level LMs avoid this tokenization issue by processing text character by character. However, this approach leads to much longer sequences, which, due to the quadratic complexity of transformer architectures, results in significant computational inefficiency during training and inference. Previous attempts to address this by pooling character representations into fixed-length "patches" still struggle with the variable nature of language units like words and phrases. This paper tackles the challenge of achieving the efficiency of token-based models while retaining the flexibility and directness of character-level models, specifically focusing on improving the decoding efficiency.

Methods

The core contribution is Toucan, an augmentation to character-level Hourglass Transformers (Nawrot et al., 2022) that makes them "token-aware" during decoding. The Hourglass Transformer already uses a dynamic pooling mechanism to group character sequences into tokens. Toucan builds upon this by modifying the decoding process:

  • Token-Aware Decoding: Instead of generating characters one by one and re-processing the entire sequence through the model for each character, Toucan learns to generate an entire token. This is achieved by injecting learned "end-of-token" (EOT) vectors into the sequence and training the decoder to predict an EOT symbol. Once an EOT is predicted, the model moves on to generate the next token.
  • Residual Connection Adjustment: The residual connection from the tokenizer is moved to the embedding layer, further decoupling the decoder from the tokenizer and allowing it to generate tokens more independently.
  • Dynamic Tokenization: Toucan utilizes a boundary predictor (specifically, a gumbel-sigmoid approach) to learn token segmentation end-to-end, controlled by a user-defined compression prior (shortening factor, SF). This allows for unsupervised learning of tokenization boundaries.

Datasets

The paper uses the following datasets:

  • text8: A standard benchmark for language modeling.
  • English wiki40b: A large-scale dataset for language modeling.

The authors replicate experiments from Nawrot et al. (2023) and follow their exact training and evaluation procedures, implying the use of their preprocessed versions of these datasets.

Key Insights and Ideas

  • Decoding Efficiency is Key: The primary insight is that significant speedups can be achieved by optimizing the decoding process for character-level models, rather than just the training or the tokenization itself.
  • Learned Tokenization is Flexible: Toucan's learned tokenization is more flexible than fixed methods like BPE and WordPiece. It can identify tokens that are not present in the training data and tends to segment based on natural linguistic boundaries like spaces, suffixes, and word roots.
  • Trade-off Between Compression and Performance: While increasing the tokenization compression rate (shortening factor) leads to faster generation, it can negatively impact language modeling performance. The paper explores this trade-off, finding that extreme compression is detrimental.

Key Results

  • Speedup: Toucan achieves over 2x faster character decoding compared to the baseline Hourglass Transformer. Figure 3 shows that as the number of tokens increases, Toucan's speed advantage grows significantly, as it only uses the last two layers for token completion.
  • Language Modeling Performance: The modifications in Toucan have minimal impact on language modeling performance. Table 4 shows comparable bits-per-character (BPC) and bits-per-token (BPT) scores between the baseline and Toucan, with Toucan even showing slightly better BPC on wiki40b.
  • Tokenization Characteristics: Toucan's learned tokenizers produce a greater amount of longer sequences tokenized as single items compared to BPE and WordPiece, especially at higher shortening factors. Figure 5 and 6 illustrate these distributions. Table 2 shows that Toucan's top tokens are often short phrases, distinct from BPE/WP.

Limitations and Future Work

  • Limitations:
    • The paper acknowledges that the bits-per-character comparison is "biased in our favor" because Toucan's vocabulary includes an additional end-of-token character.
  • Models trained at the highest compression rates performed poorly and were omitted from further comparisons, suggesting a limit to how much compression can be applied without significant performance degradation.
  • Future Work:
    • The paper implicitly suggests further exploration of the trade-off between compression and language modeling performance.
  • The flexibility of Toucan's learned tokenization, which can handle unseen tokens, opens avenues for research into more robust and adaptive language modeling.
  • The availability of their code and project at https://nlp.jhu.edu/nuggets/ invites further research and application of their method.

Summary updated

BibTeX
@misc{fleshman2023toucan,
  author = {William Fleshman and Benjamin Van Durme},
  title = {{Toucan: Token-Aware Character Level Language Modeling}},
  year = {2023},
  eprint = {2311.08620},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.08620},
}
Figure