Adapting Decoder-Based Language Models for Diverse Encoder Downstream Tasks

Paul Suganthan, Fedor Moiseev, Le Yan, Junru Wu, Jianmo Ni, Jay Han, Imed Zitouni, Enrique Alfonseca, Xuanhui Wang, Zhe DongarXiv 2025

Abstract

Decoder-based transformers, while revolutionizing language modeling and scaling to immense sizes, have not completely overtaken encoder-heavy architectures in natural language processing. Specifically, encoder-only models remain dominant in tasks like classification, regression, and ranking. This is primarily due to the inherent structure of decoder-based models, which limits their direct applicability to these tasks. In this paper, we introduce Gemma Encoder, adapting the powerful Gemma decoder model to an encoder architecture, thereby unlocking its potential for a wider range of non-generative applications. To optimize the adaptation from decoder to encoder, we systematically analyze various pooling strategies, attention mechanisms, and hyperparameters (e.g., dropout rate). Furthermore, we benchmark Gemma Encoder against established approaches on the GLUE benchmarks, and MS MARCO ranking benchmark, demonstrating its effectiveness and versatility.

Introduction

In the current generative AI landscape, decoder-only architectures like GPT-4 and Gemma have set the standard for text generation. However, for discriminative tasks—such as sentiment classification, numerical score prediction (regression), or document ranking—encoder-only models like BERT continue to be preferred.

The primary hurdle is that decoder-only models are "causal," meaning they are trained to predict the next token based only on preceding context. This unidirectional structure prevents the model from forming a holistic, bidirectional understanding of a sequence, which is critical for encoder-centric tasks. This research explores whether the massive knowledge embedded in a pre-trained decoder can be effectively repurposed into a high-performance encoder.

Methods: The Gemma Encoder Adaptation

The authors introduce Gemma Encoder, a novel adaptation of the Gemma-2 (2B and 9B) models. The transformation involves three primary strategic modifications:

  1. Bidirectional Attention: The standard causal masking is replaced with bidirectional masking. This allows every token in a sequence to attend to every other token, fostering a more comprehensive representation of the input.
  2. Task-Specific Pooling: To convert a sequence of embeddings into a single fixed-length vector for downstream tasks, several strategies were evaluated, including First-K/Last-K token selection, Mean Pooling (averaging all representations), and Attention Pooling (a learnable mechanism to weight token importance).
  3. Re-introducing Dropout: While modern LLMs often omit dropout during pre-training due to the scale of data, downstream tasks typically involve smaller datasets. The researchers found that re-introducing a 10% dropout rate during fine-tuning was essential for preventing overfitting.
Overview of pooling strategies and the general architecture for adapting the decoder to an encoder-style task.

Key Insights

The Necessity of Bidirectional Context

The most impactful change was enabling bidirectional attention. Even though the model was pre-trained as a causal decoder, allowing it to see the full context during fine-tuning led to dramatic performance gains across all benchmarks.

The Role of Dropout in Generalization

While LLMs are typically trained without dropout, the transition to smaller, supervised datasets requires regularization. Experimental results showed that a dropout fraction of 0.10 consistently yielded the best performance on the GLUE average score for both the 2B and 9B variants.

The impact of dropout fraction on GLUE average performance, showing a clear peak at 0.10 for both model sizes.

Pooling Flexibility

Interestingly, when bidirectional attention is active, the specific choice of pooling (e.g., Mean vs. Last-token) has a negligible impact on performance. However, in causal settings, Last-token pooling remains the only viable choice as it is the only representation that has processed the entire sequence.

Results and Performance

Gemma Encoder demonstrates that generative pre-training provides a world-class foundation for discriminative tasks:

  • GLUE Benchmarks: The Gemma-2 9B Encoder achieved an average score of 90.9, outperforming the significantly larger T5-xxl (6.5B) (90.5) and established baselines like BERT-large.
  • Ranking Excellence: On the MS MARCO benchmark, Gemma-2 9B reached an NDCG@10 of 0.5148, surpassing RankT5-XL (0.5035), despite the latter being specialized for ranking tasks.
  • Efficiency: The 2B variant remained highly competitive, often matching or exceeding the performance of T5 models with much higher parameter counts.

Conclusion

The Gemma Encoder adaptation proves that decoder-only models can be successfully "flipped" into encoders with minimal architectural changes. While bidirectional attention and dropout are critical for this transition, the model's performance suggests that the knowledge gained during generative pre-training is highly transferable to discriminative applications. Future work will explore these models in even more diverse settings, such as dense retrieval and multi-modal embeddings.

Summary updated

BibTeX
@misc{suganthan2025adapting,
  author = {Paul Suganthan and Fedor Moiseev and Le Yan and Junru Wu and Jianmo Ni and Jay Han and Imed Zitouni and Enrique Alfonseca and Xuanhui Wang and Zhe Dong},
  title = {{Adapting Decoder-Based Language Models for Diverse Encoder Downstream Tasks}},
  year = {2025},
  eprint = {2503.02656},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.02656},
}
Figure