Label Supervised LLaMA Finetuning

Zongxi Li, Xianming Li, Yuzhang Liu, Haoran Xie, Jing Li, Fu Lee Wang, Qing Li, Xiaoqin ZhongarXiv 2023 · DOI

Abstract

Large Language Models (LLMs) are typically optimized for generative tasks using causal masking. However, this architecture often underperforms on discriminative tasks like text classification and Named Entity Recognition (NER) compared to bidirectional encoders like BERT. This paper introduces Label Supervised LLaMA (LS-LLaMA) and its unmasked variant (LS-unLLaMA). By extracting latent representations for label projection and removing the causal mask during finetuning, LS-LLaMA transforms decoder-only models into high-performance classifiers. Experimental results show that a 7B parameter LS-unLLaMA can outperform models ten times its size and surpass established bidirectional baselines.

Introduction

While LLMs like LLaMA excel at open-ended generation, they face challenges in discriminative settings. Current industry standards often rely on instruction-tuning, which prompts the model to generate a label. This approach is inefficient for closed label spaces and suffers from the inherent limitations of the causal mask, which prevents tokens from attending to subsequent context. This is particularly detrimental for token-level tasks like NER. LS-LLaMA addresses these issues by leveraging the model's internal latent states and enabling bidirectional information flow.

Methods

The proposed framework consists of two primary modifications to the standard LLaMA architecture:

  1. LS-LLaMA (Label Supervised LLaMA): Instead of generative output, the model uses the latent vector from the final decoder layer. This vector is mapped to a specific label space via a linear layer and trained using cross-entropy loss.
  2. LS-unLLaMA (Unmasked LLaMA): The causal mask, typically used to ensure autoregressive generation, is removed during the finetuning phase. This allows the model to function as a bidirectional encoder, where each token can attend to the entire sequence.
Comparison of standard LLaMA, LS-LLaMA, and LS-unLLaMA architectures.

To maintain computational efficiency, both variants utilize Low-Rank Adaptation (LoRA), enabling finetuning on consumer-grade hardware such as an NVIDIA RTX 4090.

Attention Mechanisms

The shift from LS-LLaMA to LS-unLLaMA represents a fundamental change in how the model processes context. In LS-LLaMA, the causal mask remains, restricting information flow to a forward-only direction. In LS-unLLaMA, the removal of this mask "replenishes" the bidirectional context necessary for complex semantic understanding.

Visualization of causal-masked vs. unmasked self-attention in LS-LLaMA and LS-unLLaMA.

Experimental Results

The models were evaluated across multiclass text classification (SST2, SST5, AGNews), multilingual classification (Amazon Reviews), and NER (CoNNL2003, OntoNotes).

Key findings include:

  • Superior Classification: LS-LLaMA-2-7B achieved 62.31% accuracy on SST5, outperforming RoBERTa-Large (59.64%).
  • NER Breakthrough: LS-unLLaMA reached an F1 score of 93.19% on CoNNL2003, setting a new state-of-the-art for LLM-based NER.
  • Efficiency and Scale: A finetuned 7B model significantly outperformed a 175B GPT-3 model in few-shot settings, demonstrating that specialized label supervision is more effective than raw scale for discriminative tasks.
  • Multilingual Gains: The approach showed a four to sixfold improvement over zero-shot baselines in multilingual contexts.

Discussion and Limitations

The study reveals that the causal mask is not a permanent constraint; discarding it during task-specific finetuning unlocks latent semantic knowledge. However, unmasking requires sufficient training data to allow the model to adapt to bidirectional dependencies. Interestingly, scaling to 13B parameters did not always yield gains, likely due to overfitting on smaller datasets.

Conclusion

LS-LLaMA demonstrates that decoder-only LLMs can be repurposed as powerful bidirectional encoders. By moving beyond generative prompting to direct label supervision and unmasking, researchers can achieve state-of-the-art performance on discriminative tasks with relatively small, efficient models.

Summary updated

BibTeX
@misc{li2023label,
  author = {Zongxi Li and Xianming Li and Yuzhang Liu and Haoran Xie and Jing Li and Fu Lee Wang and Qing Li and Xiaoqin Zhong},
  title = {{Label Supervised LLaMA Finetuning}},
  year = {2023},
  eprint = {2310.01208},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.01208},
}
Figure